Skip to content

Commit

Permalink
Merge pull request #293 from severinbeauvais/PRC-788
Browse files Browse the repository at this point in the history
PRC-788: clean up api and services (see details)
  • Loading branch information
marklise authored Oct 30, 2018
2 parents 7f057bf + 9643562 commit 0a6848b
Show file tree
Hide file tree
Showing 29 changed files with 762 additions and 735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class ApplicationAsideComponent implements OnInit, OnChanges, OnDestroy {
public drawMap(app: Application) {
if (app.tantalisID) {
const self = this; // for closure function below
this.featureService.getByDTID(app.tantalisID)
this.featureService.getByTantalisId(app.tantalisID)
.takeUntil(this.ngUnsubscribe)
.subscribe(
features => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ <h2>Documents</h2>
<ul class="doc-list">
<li *ngFor="let doc of application.documents">
<span class="cell icon">
<i class="material-icons link" (click)="api.openFile(doc)">
<i class="material-icons link" (click)="api.openDocument(doc)">
insert_drive_file
</i>
</span>
<span class="cell name" [title]="doc.displayName || ''">
<span class="cell__txt-content">
<a (click)="api.openFile(doc)">{{doc.documentFileName}}</a>
<a (click)="api.openDocument(doc)">{{doc.documentFileName}}</a>
</span>
</span>
<span class="cell actions">
<button class="btn btn-icon" type="button" title="Download this document" (click)="api.downloadFile(doc)">
<button class="btn btn-icon" type="button" title="Download this document" (click)="api.downloadDocument(doc)">
<i class="material-icons">file_download</i>
</button>
</span>
Expand Down Expand Up @@ -204,7 +204,7 @@ <h3 class="title">Comment Period Details</h3>
<div class="btn-container">
<button class="cta-btn btn btn-sm btn-outline-primary" type="button"
[routerLink]="['/comments', application._id]">
Review Comments ({{application['numComments']}})
Review Comments<span *ngIf="application['numComments'] >= 0">&nbsp;({{application['numComments']}})</span>
</button>
</div>
</div>
Expand All @@ -220,17 +220,17 @@ <h3 class="title">Application Decision</h3>
<ul class="doc-list">
<li *ngFor="let doc of application.decision.documents">
<span class="cell icon">
<i class="material-icons link" (click)="api.openFile(doc)">
<i class="material-icons link" (click)="api.openDocument(doc)">
insert_drive_file
</i>
</span>
<span class="cell name" [title]="doc.displayName || ''">
<span class="cell__txt-content">
<a (click)="api.openFile(doc)">{{doc.documentFileName}}</a>
<a (click)="api.openDocument(doc)">{{doc.documentFileName}}</a>
</span>
</span>
<span class="cell actions">
<button class="btn btn-icon" title="Download this document" (click)="api.downloadFile(doc)">
<button class="btn btn-icon" title="Download this document" (click)="api.downloadDocument(doc)">
<i class="material-icons">file_download</i>
</button>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
() => { // onCompleted
this.snackBarRef = this.snackBar.open('Application published...', null, { duration: 2000 });
// reload all data
this.applicationService.getById(this.application._id, { getFeatures: true, getDocuments: true, getCurrentPeriod: true, getNumComments: true, getDecision: true })
this.applicationService.getById(this.application._id, { getFeatures: true, getDocuments: true, getCurrentPeriod: true, getDecision: true })
.takeUntil(this.ngUnsubscribe)
.subscribe(
application => {
Expand Down Expand Up @@ -328,7 +328,7 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
() => { // onCompleted
this.snackBarRef = this.snackBar.open('Application unpublished...', null, { duration: 2000 });
// reload all data
this.applicationService.getById(this.application._id, { getFeatures: true, getDocuments: true, getCurrentPeriod: true, getNumComments: true, getDecision: true })
this.applicationService.getById(this.application._id, { getFeatures: true, getDocuments: true, getCurrentPeriod: true, getDecision: true })
.takeUntil(this.ngUnsubscribe)
.subscribe(
application => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ApplicationListComponent implements OnInit, OnDestroy {
});

// get data
this.applicationService.getAll({ getCurrentPeriod: true, getNumComments: true })
this.applicationService.getAll({ getCurrentPeriod: true })
.takeUntil(this.ngUnsubscribe)
.subscribe(applications => {
this.loading = false;
Expand Down
16 changes: 11 additions & 5 deletions src/app/applications/application-resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ApplicationDetailResolver implements Resolve<Application> {

if (appId === '0') {
// create new application
const app = new Application({
const application = new Application({
purpose: route.queryParamMap.get('purpose'),
subpurpose: route.queryParamMap.get('subpurpose'),
type: route.queryParamMap.get('type'),
Expand All @@ -35,14 +35,20 @@ export class ApplicationDetailResolver implements Resolve<Application> {
});

// 7-digit CL File number for display
if (app.cl_file) {
app['clFile'] = app.cl_file.toString().padStart(7, '0');
if (application.cl_file) {
application['clFile'] = application.cl_file.toString().padStart(7, '0');
}

return of(app);
// user-friendly application status
application.appStatus = this.applicationService.getStatusString(this.applicationService.getStatusCode(application.status));

// derive region code
application.region = this.applicationService.getRegionCode(application.businessUnit);

return of(application);
}

// view/edit existing application
return this.applicationService.getById(appId, { getFeatures: true, getDocuments: true, getCurrentPeriod: true, getNumComments: true, getDecision: true });
return this.applicationService.getById(appId, { getFeatures: true, getDocuments: true, getCurrentPeriod: true, getDecision: true });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ export class SelectOrganizationComponent extends DialogComponent<DataModel, stri
}

ngOnInit() {
const self = this;
this.searchService.getClientsByDTID(this.dispositionId)
.subscribe(
data => {
_.each(data, function (i) {
self.clients.push(new Client(i));
// Pre-select the existing clients if they're in the list
// if (i._id === self.dispositionId) {
// self.selectedClients = i;
// }
});
clients => {
this.isLoading = false;
this.clients = clients;
},
error => {
this.isLoading = false;
console.log('error =', error);
this.api.ensureLoggedIn();
});
}
Expand Down
118 changes: 50 additions & 68 deletions src/app/commenting/review-comments/review-comments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import { forkJoin } from 'rxjs/observable/forkJoin';
import 'rxjs/add/operator/takeUntil';
import 'rxjs/add/operator/toPromise';
import * as moment from 'moment';
import * as _ from 'lodash';

Expand Down Expand Up @@ -104,7 +103,8 @@ export class ReviewCommentsComponent implements OnInit, OnDestroy {
if (this.application) { // safety check
this.loading = true;

this.commentService.getAllByApplicationId(this.application._id, this.pageNum - 1, this.PAGE_SIZE, this.sortBy)
// get a page of comments
this.commentService.getAllByApplicationId(this.application._id, this.pageNum - 1, this.PAGE_SIZE, this.sortBy, { getDocuments: true })
.takeUntil(this.ngUnsubscribe)
.subscribe(
comments => {
Expand Down Expand Up @@ -174,77 +174,59 @@ export class ReviewCommentsComponent implements OnInit, OnDestroy {

exportToExcel() {
// get all comments
this.commentService.getAllByApplicationId(this.application._id)
this.commentService.getAllByApplicationId(this.application._id, 0, 1000000, null, { getDocuments: true }) // max 1M records
.takeUntil(this.ngUnsubscribe)
.subscribe(
comments => {
const observables: Array<Observable<Comment>> = [];

// get full comments
comments.forEach(comment => {
observables.push(this.commentService.getById(comment._id, true));
// FUTURE: instead of flattening, copy to new 'export object' with user-friendly keys?
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;
delete document._addedBy;
delete document._application;
delete document._decision;
delete document._comment;
delete document.internalURL;
delete document.internalMime;
delete document.isDeleted;
delete document.tags;
});
// add necessary properties
// comment['client'] = this.application.client; // FUTURE
comment['cl_file'] = this.application['clFile'];
return this.flatten_fastest(comment);
});

// run all observables in parallel
forkJoin(observables)
.takeUntil(this.ngUnsubscribe)
.subscribe(
(allComments: Comment[]) => {
// FUTURE: instead of flattening, copy to new 'export object' with user-friendly keys?
const flatComments = allComments.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;
delete document._addedBy;
delete document._application;
delete document._decision;
delete document._comment;
delete document.internalURL;
delete document.internalMime;
delete document.isDeleted;
delete document.tags;
});
// add necessary properties
// comment['client'] = this.application.client; // FUTURE
comment['cl_file'] = this.application['clFile'];
return this.flatten_fastest(comment);
});

const excelFileName = 'comments-'
+ this.application.client.replace(/\s/g, '_')
+ moment(new Date()).format('-YYYYMMDD');
const columnOrder: Array<string> = [
'cl_file',
'_id',
'_addedBy',
'dateAdded',
'commentAuthor.contactName',
'commentAuthor.orgName',
'commentAuthor.location',
'commentAuthor.requestedAnonymous',
'commentAuthor.internal.email',
'commentAuthor.internal.phone',
'comment',
'review.reviewerDate',
'review.reviewerNotes',
'commentStatus',
'isPublished'
// document columns go here
];
this.excelService.exportAsExcelFile(flatComments, excelFileName, columnOrder);
},
error => {
// if 403, redir to login page
if (error && error.status === 403) { this.router.navigate(['/login']); }
this.alerts.push('Error exporting comments');
});
const excelFileName = 'comments-'
+ this.application.client.replace(/\s/g, '_')
+ moment(new Date()).format('-YYYYMMDD');
const columnOrder: Array<string> = [
'cl_file',
'_id',
'_addedBy',
'dateAdded',
'commentAuthor.contactName',
'commentAuthor.orgName',
'commentAuthor.location',
'commentAuthor.requestedAnonymous',
'commentAuthor.internal.email',
'commentAuthor.internal.phone',
'comment',
'review.reviewerDate',
'review.reviewerNotes',
'commentStatus',
'isPublished'
// document columns go here
];
this.excelService.exportAsExcelFile(flatComments, excelFileName, columnOrder);
},
error => {
console.log('error =', error);
Expand Down
71 changes: 36 additions & 35 deletions src/app/models/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,32 @@ export class Application {
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.internal = obj && obj.internal || new Internal();
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._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);

// replace \\n (JSON format) with newlines
if (obj && obj.description) {
Expand All @@ -85,33 +86,33 @@ export class Application {

// copy centroid
if (obj && obj.centroid) {
obj.centroid.forEach(num => {
for (const num of obj.centroid) {
this.centroid.push(num);
});
}
}

// copy documents
if (obj && obj.documents) {
obj.documents.forEach(doc => {
for (const doc of obj.documents) {
this.documents.push(doc);
});
}
}

// copy features
if (obj && obj.features) {
obj.features.forEach(feature => {
for (const feature of obj.features) {
this.features.push(feature);
});
}
}

// wrap isPublished around the tags we receive for this object
if (obj && obj.tags) {
const self = this;
_.each(obj.tags, function (tag) {
for (const tag of obj.tags) {
if (_.includes(tag, 'public')) {
self.isPublished = true;
this.isPublished = true;
break;
}
});
}
}
}
}
Loading

0 comments on commit 0a6848b

Please sign in to comment.