Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRC-693: model cleanup #310

Merged
merged 1 commit into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,68 +46,68 @@ <h2>Crown Lands Applications in British Columbia</h2>
</thead>

<tbody class="application-table__content">
<ng-template ngFor let-item [ngForOf]="applications | orderBy: {property: column, direction: direction}">
<tr *ngIf="showThisApp(item)">
<ng-template ngFor let-app [ngForOf]="applications | orderBy: {property: column, direction: direction}">
<tr *ngIf="showThisApp(app)">
<td class="accordion__collapse-item p-0" colspan="6">
<div class="accordion__collapse-header" role="tab">
<a role="button" class="accordion__collapse-header--column toggle collapsed" data-toggle="collapse" href="#accordCollapse{{item._id}}">
<a role="button" class="accordion__collapse-header--column toggle collapsed" data-toggle="collapse" href="#accordCollapse{{app._id}}">
<i class="material-icons open-icon">arrow_drop_down</i>
<i class="material-icons close-icon">arrow_drop_up</i>
</a>
<span class="accordion__collapse-header--column application-table__name-col">{{item.client || '-'}}</span>
<span class="accordion__collapse-header--column application-table__name-col">{{app.client || '-'}}</span>
<span class="accordion__collapse-header--column application-table__cl_file-col">
<a [routerLink]="['/a', item._id]">{{item['clFile'] || '-'}}</a>
<a [routerLink]="['/a', app._id]">{{app['clFile'] || '-'}}</a>
</span>
<span class="accordion__collapse-header--column application-table__purpose-col">{{item.purpose || '-'}} / {{item.subpurpose || '-'}}</span>
<span class="accordion__collapse-header--column application-table__region-col">{{item.region || '-'}}</span>
<span class="accordion__collapse-header--column application-table__status-col">{{item.appStatus || '-'}}</span>
<span class="accordion__collapse-header--column application-table__commenting-col">{{item.cpStatus}}</span>
<span class="accordion__collapse-header--column application-table__purpose-col">{{app.purpose || '-'}} / {{app.subpurpose || '-'}}</span>
<span class="accordion__collapse-header--column application-table__region-col">{{app.region || '-'}}</span>
<span class="accordion__collapse-header--column application-table__status-col">{{app.appStatus || '-'}}</span>
<span class="accordion__collapse-header--column application-table__commenting-col">{{app.cpStatus}}</span>
</div>

<div class="collapse" id="accordCollapse{{item._id}}" role="tabpanel">
<div class="collapse" id="accordCollapse{{app._id}}" role="tabpanel">
<div class="accordion__collapse-body">
<div class="application-table__application-details">
<ul class="nv-list application-table__application-details--list">
<!-- <li class="p-0">
<span class="name">Type / Subtype:</span>
<span class="value">{{item.type || '-'}} / {{item.subtype || '-'}}</span>
<span class="value">{{app.type || '-'}} / {{app.subtype || '-'}}</span>
</li> -->
<li class="p-0">
<span class="name">Comment Period Status:</span>
<span class="value">{{item.cpStatus}}</span>
<span class="value">{{app.cpStatus}}</span>
</li>
<li class="p-0" *ngIf="item.currentPeriod">
<li class="p-0" *ngIf="app.currentPeriod">
<span class="name">Comment Period Dates:</span>
<span class="value">{{item.currentPeriod.startDate | date:'mediumDate'}} to {{item.currentPeriod.endDate | date:'mediumDate'}}
<span *ngIf="item.currentPeriod['daysRemaining']">
&nbsp;({{item.currentPeriod['daysRemaining'] + (item.currentPeriod['daysRemaining'] === 1 ? ' day ' : ' days ') + 'remaining'}})
<span class="value">{{app.currentPeriod.startDate | date:'mediumDate'}} to {{app.currentPeriod.endDate | date:'mediumDate'}}
<span *ngIf="app.currentPeriod['daysRemaining']">
&nbsp;({{app.currentPeriod['daysRemaining'] + (app.currentPeriod['daysRemaining'] === 1 ? ' day ' : ' days ') + 'remaining'}})
</span>
</span>
</li>
<li class="p-0" *ngIf="item.currentPeriod">
<li class="p-0" *ngIf="app.currentPeriod">
<span class="name">Comments Received:</span>
<span class="value">{{item['numComments']}}</span>
<span class="value">{{app['numComments']}}</span>
</li>
<li class="p-0">
<span class="name">Location:</span>
<span class="value">{{item.location || '-'}}</span>
<span class="value">{{app.location || '-'}}</span>
</li>
<li class="p-0">
<span class="name">Description:</span>
<span class="value" [innerHTML]="(item.description | newlines) || '-'"></span>
<span class="value" [innerHTML]="(app.description | newlines) || '-'"></span>
</li>
</ul>

<div class="application-table__application-details--links">
<a class="btn content-btn slide-l-btn btn-sm" [routerLink]="['/a', item._id]">
<a class="btn content-btn slide-l-btn btn-sm" [routerLink]="['/a', app._id]">
<i class="material-icons">info_outline</i>
<span>Application Details</span>
</a>
<a class="btn content-btn slide-l-btn btn-sm" [routerLink]="['/comments', item._id]">
<a class="btn content-btn slide-l-btn btn-sm" [routerLink]="['/comments', app._id]">
<i class="material-icons">message</i>
<span>Review Comments</span>
</a>
<!-- <a class="btn content-btn slide-l-btn btn-sm float-right" [routerLink]="['/map', { application: item._id }]">
<!-- <a class="btn content-btn slide-l-btn btn-sm float-right" [routerLink]="['/map', { application: app._id }]">
<i class="material-icons">place</i>
<span>Show on Map</span>
</a> -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ export class ReviewCommentsComponent implements OnInit, OnDestroy {
const flatComments = comments.map(comment => {
// sanitize and flatten each comment object
delete comment._commentPeriod;
delete comment.commentAuthor.internal.tags;
delete comment.commentAuthor.tags;
delete comment.commentNumber;
delete comment.review.tags;
delete comment.tags;
// sanitize documents
comment.documents.forEach(document => {
delete document._id;
Expand All @@ -161,7 +157,6 @@ export class ReviewCommentsComponent implements OnInit, OnDestroy {
delete document.internalURL;
delete document.internalMime;
delete document.isDeleted;
delete document.tags;
});
// add necessary properties
// comment['client'] = this.application.client; // FUTURE
Expand Down
78 changes: 36 additions & 42 deletions src/app/models/application.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import { Document } from './document';
import * as _ from 'lodash';
import { CommentPeriod } from './commentperiod';
import { Decision } from './decision';
import { Document } from './document';
import { Feature } from './feature';
import * as _ from 'lodash';

class Internal {
notes: string;

constructor(obj?: any) {
this.notes = obj && obj.notes || null;
}
}

export class Application {
_id: string;

// the following are retrieved from the API
_id: string;
agency: string;
areaHectares: number;
businessUnit: string;
centroid: Array<number> = []; // [lng, lat]
cl_file: number;
client: string;
description: string = null;
internal: Internal;
legalDescription: string = null;
location: string;
name: string; // MAY BE OBSOLETE
publishDate: Date;
name: string;
publishDate: Date = null;
purpose: string;
status: string;
subpurpose: string;
Expand All @@ -43,38 +33,34 @@ export class Application {
isPublished = false; // depends on tags; see below

// associated data
documents: Array<Document> = [];
currentPeriod: CommentPeriod = null;
decision: Decision = null;
documents: Array<Document> = [];
features: Array<Feature> = [];

constructor(obj?: any) {
this._id = obj && obj._id || null;

this.agency = obj && obj.agency || null;
this.areaHectares = obj && obj.areaHectares || null;
this.businessUnit = obj && obj.businessUnit || null;
this.cl_file = obj && obj.cl_file || null;
this.client = obj && obj.client || null;
this.location = obj && obj.location || null;
this.name = obj && obj.name || null;
this.publishDate = obj && obj.publishDate || null;
this.purpose = obj && obj.purpose || null;
this.status = obj && obj.status || null;
this.subpurpose = obj && obj.subpurpose || null;
this.subtype = obj && obj.subtype || null;
this.tantalisID = obj && obj.tantalisID || null; // not zero
this.tenureStage = obj && obj.tenureStage || null;
this.type = obj && obj.type || null;

this.region = obj && obj.region || null;
this.appStatus = obj && obj.appStatus || null;
this.cpStatus = obj && obj.cpStatus || null;

this.currentPeriod = obj && obj.currentPeriod || null;
this.decision = obj && obj.decision || null;

this.internal = new Internal(obj && obj.internal || null);
this._id = obj && obj._id || null;
this.agency = obj && obj.agency || null;
this.areaHectares = obj && obj.areaHectares || null;
this.businessUnit = obj && obj.businessUnit || null;
this.cl_file = obj && obj.cl_file || null;
this.client = obj && obj.client || null;
this.location = obj && obj.location || null;
this.name = obj && obj.name || null;
this.purpose = obj && obj.purpose || null;
this.status = obj && obj.status || null;
this.subpurpose = obj && obj.subpurpose || null;
this.subtype = obj && obj.subtype || null;
this.tantalisID = obj && obj.tantalisID || null; // not zero
this.tenureStage = obj && obj.tenureStage || null;
this.type = obj && obj.type || null;
this.region = obj && obj.region || null;
this.appStatus = obj && obj.appStatus || null;
this.cpStatus = obj && obj.cpStatus || null;

if (obj && obj.publishDate) {
this.publishDate = new Date(obj.publishDate);
}

// replace \\n (JSON format) with newlines
if (obj && obj.description) {
Expand All @@ -91,6 +77,14 @@ export class Application {
}
}

if (obj && obj.currentPeriod) {
this.currentPeriod = new CommentPeriod(obj.currentPeriod);
}

if (obj && obj.decision) {
this.decision = new Decision(obj.decision);
}

// copy documents
if (obj && obj.documents) {
for (const doc of obj.documents) {
Expand Down
27 changes: 15 additions & 12 deletions src/app/models/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Document } from './document';
class Internal {
email: string;
phone: string;
tags: Array<string>;

isPublished = false; // depends on tags; see below

Expand All @@ -31,7 +30,6 @@ class CommentAuthor {
location: string;
requestedAnonymous: boolean;
internal: Internal;
tags: Array<string>;

isPublished = false; // depends on tags; see below

Expand All @@ -42,7 +40,7 @@ class CommentAuthor {
this.location = obj && obj.location || null;
this.requestedAnonymous = obj && obj.requestedAnonymous || null;

this.internal = new Internal(obj && obj.internal || null);
this.internal = new Internal(obj && obj.internal || null); // must exist

// wrap isPublished around the tags we receive for this object
if (obj && obj.tags) {
Expand All @@ -59,20 +57,22 @@ class CommentAuthor {
class Review {
_reviewerId: string; // object id -> User
reviewerNotes: string = null;
reviewerDate: Date;
tags: Array<string>;
reviewerDate: Date = null;

isPublished = false; // depends on tags; see below

constructor(obj?: any) {
this._reviewerId = obj && obj._reviewerId || null;
this.reviewerDate = obj && obj.reviewerDate || null;
this._reviewerId = obj && obj._reviewerId || null;

// replace \\n (JSON format) with newlines
if (obj && obj.reviewerNotes) {
this.reviewerNotes = obj.reviewerNotes.replace(/\\n/g, '\n');
}

if (obj && obj.reviewerDate) {
this.reviewerDate = new Date(obj.reviewerDate);
}

// wrap isPublished around the tags we receive for this object
if (obj && obj.tags) {
for (const tag of obj.tags) {
Expand All @@ -93,10 +93,10 @@ export class Comment {
comment: string = null;
commentAuthor: CommentAuthor;
review: Review;
dateAdded: Date;
dateAdded: Date = null;
commentStatus: string;
tags: Array<string>;

// associated data
documents: Array<Document> = [];

isPublished = false; // depends on tags; see below
Expand All @@ -106,12 +106,15 @@ export class Comment {
this._addedBy = obj && obj._addedBy || null;
this._commentPeriod = obj && obj._commentPeriod || null;
this.commentNumber = obj && obj.commentNumber || 0;
this.dateAdded = obj && obj.dateAdded || null;
this.commentStatus = obj && obj.commentStatus || null;

this.commentAuthor = new CommentAuthor(obj && obj.commentAuthor || null);
if (obj && obj.dateAdded) {
this.dateAdded = new Date(obj.dateAdded);
}

this.commentAuthor = new CommentAuthor(obj && obj.commentAuthor || null); // must exist

this.review = new Review(obj && obj.review || null);
this.review = new Review(obj && obj.review || null); // must exist

// replace \\n (JSON format) with newlines
if (obj && obj.comment) {
Expand Down
35 changes: 10 additions & 25 deletions src/app/models/commentperiod.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
import * as _ from 'lodash';

class Internal {
notes: string;
_addedBy: string;

constructor(obj?: any) {
this.notes = obj && obj.notes || null;
this._addedBy = obj && obj._addedBy || null;
}
}

export class CommentPeriod {
_id: string;
_addedBy: string;
_application: string;
description: string = null;
code: string;
startDate: Date;
endDate: Date;
internal: Internal; // OBSOLETE BUT API V1 EXPECTS IT - REMOVE LATER
startDate: Date = null;
endDate: Date = null;

isPublished = false; // depends on tags; see below

constructor(obj?: any) {
this._id = obj && obj._id || null;
this._addedBy = obj && obj._addedBy || null;
this._application = obj && obj._application || null;
this.code = obj && obj.code || null;
this.startDate = obj && obj.startDate && new Date(obj.startDate) || null;
this.endDate = obj && obj.endDate && new Date(obj.endDate) || null;
this._id = obj && obj._id || null;
this._addedBy = obj && obj._addedBy || null;
this._application = obj && obj._application || null;

this.internal = new Internal(obj && obj.internal || null);
if (obj && obj.startDate) {
this.startDate = new Date(obj.startDate);
}

// replace \\n (JSON format) with newlines
if (obj && obj.description) {
this.description = obj.description.replace(/\\n/g, '\n');
if (obj && obj.endDate) {
this.endDate = new Date(obj.endDate);
}

// wrap isPublished around the tags we receive for this object
Expand Down
3 changes: 1 addition & 2 deletions src/app/models/decision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export class Decision {
_id: string;
_addedBy: string;
_application: string; // objectid -> Application
code: string;
name: string;
description: string = null;

// associated data
documents: Array<Document> = [];

isPublished = false; // depends on tags; see below
Expand All @@ -17,7 +17,6 @@ export class Decision {
this._id = obj && obj._id || null;
this._addedBy = obj && obj._addedBy || null;
this._application = obj && obj._application || null;
this.code = obj && obj.code || null;
this.name = obj && obj.name || null;

// replace \\n (JSON format) with newlines
Expand Down
1 change: 0 additions & 1 deletion src/app/models/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class Document {
internalURL: string;
isDeleted: boolean;
internalMime: string;
tags: Array<string>;

isPublished = false; // depends on tags; see below

Expand Down
Loading