-
+ |
@@ -68,12 +70,16 @@ Crown Lands Applications in British Columbia
-->
Comment Period Status:
- {{commentPeriodService.getStatus(item.currentPeriod)}}
+ {{item.cpStatus}}
Comment Period Dates:
{{item.currentPeriod.startDate | date:'mediumDate'}} to {{item.currentPeriod.endDate | date:'mediumDate'}}
+
+ Comments Received:
+ {{item.numComments}}
+
Location:
{{item.location || '-'}}
diff --git a/src/app/applications/application-list/application-list.component.scss b/src/app/applications/application-list/application-list.component.scss
index 0504b270..8874e2ab 100644
--- a/src/app/applications/application-list/application-list.component.scss
+++ b/src/app/applications/application-list/application-list.component.scss
@@ -94,6 +94,9 @@
&__status-col {
width: 30%;
}
+ &__commenting-col {
+ display: none;
+ }
&__application-details {
&--links {
.btn {
@@ -113,16 +116,19 @@
// width: 20%;
}
&__cl_file-col {
- width: 15%;
+ width: 12.5%;
}
&__purpose-col {
- width: 27.5%;
+ width: 25%;
}
&__region-col {
- width: 17.5%;
+ width: 12.5%;
}
&__status-col {
- width: 20%;
+ width: 15%;
+ }
+ &__commenting-col {
+ width: 15%;
}
&__application-details {
font-size: 0.9375rem;
diff --git a/src/app/applications/application-list/application-list.component.ts b/src/app/applications/application-list/application-list.component.ts
index 1df221b6..16a6ded2 100644
--- a/src/app/applications/application-list/application-list.component.ts
+++ b/src/app/applications/application-list/application-list.component.ts
@@ -7,7 +7,6 @@ import * as _ from 'lodash';
import { Application } from 'app/models/application';
import { ApiService } from 'app/services/api';
-import { ApplicationService } from 'app/services/application.service';
import { CommentPeriodService } from 'app/services/commentperiod.service';
@Component({
@@ -34,8 +33,7 @@ export class ApplicationListComponent implements OnInit, OnDestroy {
private api: ApiService,
private route: ActivatedRoute,
private router: Router,
- private applicationService: ApplicationService,
- public commentPeriodService: CommentPeriodService // used in template
+ public commentPeriodService: CommentPeriodService
) { }
ngOnInit() {
@@ -70,7 +68,7 @@ export class ApplicationListComponent implements OnInit, OnDestroy {
this.ngUnsubscribe.complete();
}
- public sort(property) {
+ public sort(property: string) {
this.isDesc = !this.isDesc;
this.column = property;
this.direction = this.isDesc ? 1 : -1;
diff --git a/src/app/commenting/review-comments/comment-detail/comment-detail.component.ts b/src/app/commenting/review-comments/comment-detail/comment-detail.component.ts
index f301cc67..9ede46c6 100644
--- a/src/app/commenting/review-comments/comment-detail/comment-detail.component.ts
+++ b/src/app/commenting/review-comments/comment-detail/comment-detail.component.ts
@@ -1,4 +1,6 @@
-import { Component, Input, Output, OnChanges, SimpleChanges, EventEmitter } from '@angular/core';
+import { Component, OnChanges, OnDestroy, Input, Output, EventEmitter, SimpleChanges } from '@angular/core';
+import { Subject } from 'rxjs/Subject';
+import 'rxjs/add/operator/takeUntil';
import 'rxjs/add/operator/toPromise';
import { Comment } from 'app/models/comment';
@@ -19,13 +21,14 @@ interface SaveParameters {
styleUrls: ['./comment-detail.component.scss']
})
-export class CommentDetailComponent implements OnChanges {
+export class CommentDetailComponent implements OnChanges, OnDestroy {
@Input() comment: Comment;
@Output() commentChange = new EventEmitter();
public internalNotes: string; // working version
public networkMsg: string;
private documents: Array;
+ private ngUnsubscribe: Subject = new Subject();
constructor(
public api: ApiService, // used in template
@@ -34,17 +37,20 @@ export class CommentDetailComponent implements OnChanges {
) { }
ngOnChanges(changes: SimpleChanges) {
- if (changes.comment.currentValue) {
- // console.log('changes =', changes);
+ // console.log('changes.comment =', changes.comment);
+ // guard against null comment
+ if (changes.comment.currentValue) {
// save copy of notes for possible reset
this.internalNotes = this.comment.review.reviewerNotes;
// get the comment documents
- this.documentService.getAllByCommentId(this.comment._id).subscribe(
- (documents: Document[]) => this.documents = documents,
- error => console.log(error)
- );
+ this.documentService.getAllByCommentId(this.comment._id)
+ .takeUntil(this.ngUnsubscribe)
+ .subscribe(
+ (documents: Document[]) => this.documents = documents,
+ error => console.log(error)
+ );
}
}
@@ -122,4 +128,9 @@ export class CommentDetailComponent implements OnChanges {
this.networkMsg += reason;
});
}
+
+ ngOnDestroy() {
+ this.ngUnsubscribe.next();
+ this.ngUnsubscribe.complete();
+ }
}
diff --git a/src/app/pipes/order-by.pipe.ts b/src/app/pipes/order-by.pipe.ts
index 237f8c10..09aad452 100644
--- a/src/app/pipes/order-by.pipe.ts
+++ b/src/app/pipes/order-by.pipe.ts
@@ -40,7 +40,6 @@ export class OrderByPipe implements PipeTransform {
if (aCompare > bCompare) { return +args.direction; }
return 0;
});
-
}
// coalesce literals to a base value
diff --git a/src/app/search/search.component.ts b/src/app/search/search.component.ts
index adfcf283..97cb2562 100644
--- a/src/app/search/search.component.ts
+++ b/src/app/search/search.component.ts
@@ -1,10 +1,11 @@
import { Router, ActivatedRoute, Params } from '@angular/router';
-import * as _ from 'lodash';
import { ChangeDetectorRef, ChangeDetectionStrategy, Component, OnInit, OnDestroy } from '@angular/core';
import { trigger, state, style, transition, animate, keyframes } from '@angular/animations';
-import { Subscription } from 'rxjs/Subscription';
+import { Subject } from 'rxjs/Subject';
+import 'rxjs/add/operator/takeUntil';
import 'rxjs/add/operator/map';
import * as L from 'leaflet';
+import * as _ from 'lodash';
import { Application } from 'app/models/application';
import { Organization } from 'app/models/organization';
@@ -53,7 +54,7 @@ export class SearchComponent implements OnInit, OnDestroy {
tileLayers: L.TileLayer[];
baseMaps: {};
control: L.Control;
- private sub: Subscription;
+ private ngUnsubscribe: Subject = new Subject();
private maxZoom = { maxZoom: 17 };
constructor(
@@ -98,7 +99,7 @@ export class SearchComponent implements OnInit, OnDestroy {
});
this.map.setView(new L.LatLng(53.7267, -127.6476), 5);
- // Setup the controls
+ // set up the controls
this.baseMaps = {
'Ocean Base': Esri_OceanBasemap,
'Nat Geo World Map': Esri_NatGeoWorldMap,
@@ -111,32 +112,30 @@ export class SearchComponent implements OnInit, OnDestroy {
this.layers = [];
}
- this.sub = this.route.params.subscribe(
- (params: Params) => {
- /*
- TBD: Deal with meta search terms?
- this.params.type
- this.params.page
- this.params.limit
- */
- this.params = params;
- this.terms = new SearchTerms();
+ this.route.params
+ .takeUntil(this.ngUnsubscribe)
+ .subscribe(
+ (params: Params) => {
+ /*
+ TBD: Deal with meta search terms?
+ this.params.type
+ this.params.page
+ this.params.limit
+ */
+ this.params = params;
+ this.terms = new SearchTerms();
- if (this.params.clfile) {
- this.terms.clfile = this.params.clfile.split(',').join(' ');
- }
+ if (this.params.clfile) {
+ this.terms.clfile = this.params.clfile.split(',').join(' ');
+ }
- this._changeDetectionRef.detectChanges();
+ this._changeDetectionRef.detectChanges();
- if (!_.isEmpty(this.terms.getParams())) {
- this.doSearch(true);
+ if (!_.isEmpty(this.terms.getParams())) {
+ this.doSearch(true);
+ }
}
- }
- );
- }
-
- ngOnDestroy() {
- this.sub.unsubscribe();
+ );
}
importProject(item: any) {
@@ -157,7 +156,8 @@ export class SearchComponent implements OnInit, OnDestroy {
// add the application
// on success go to edit page
- this.applicationService.addApplication(item)
+ this.applicationService.add(item)
+ .takeUntil(this.ngUnsubscribe)
.subscribe(application => {
this.router.navigate(['/a', application._id]);
});
@@ -182,6 +182,7 @@ export class SearchComponent implements OnInit, OnDestroy {
}
this.searchService.getByCLFile(this.terms.clfile)
+ .takeUntil(this.ngUnsubscribe)
.subscribe(
data => {
this.loading = false;
@@ -282,4 +283,9 @@ export class SearchComponent implements OnInit, OnDestroy {
loadMore() {
this.doSearch(false);
}
+
+ ngOnDestroy() {
+ this.ngUnsubscribe.next();
+ this.ngUnsubscribe.complete();
+ }
}
diff --git a/src/app/services/application.service.ts b/src/app/services/application.service.ts
index 4d497e83..91a3cf5e 100644
--- a/src/app/services/application.service.ts
+++ b/src/app/services/application.service.ts
@@ -14,6 +14,7 @@ import { ApiService } from './api';
import { DocumentService } from './document.service';
import { OrganizationService } from './organization.service';
import { CommentPeriodService } from './commentperiod.service';
+import { CommentService } from './comment.service';
import { DecisionService } from './decision.service';
import { SearchService } from './search.service';
@@ -26,6 +27,7 @@ export class ApplicationService {
private documentService: DocumentService,
private organizationService: OrganizationService,
private commentPeriodService: CommentPeriodService,
+ private commentService: CommentService,
private decisionService: DecisionService,
private searchService: SearchService
) { }
@@ -55,6 +57,8 @@ export class ApplicationService {
if (applications[i].legalDescription) {
applications[i].legalDescription = applications[i].legalDescription.replace(/\\n/g, '\n');
}
+ // derive application status for app list display + sorting
+ applications[i]['appStatus'] = this.getStatus(applications[i]);
});
const promises: Array> = [];
@@ -72,7 +76,24 @@ export class ApplicationService {
applications.forEach((application, i) => {
promises.push(this.commentPeriodService.getAllByApplicationId(applications[i]._id)
.toPromise()
- .then(periods => applications[i].currentPeriod = this.commentPeriodService.getCurrent(periods)));
+ .then(periods => {
+ const cp = this.commentPeriodService.getCurrent(periods);
+ applications[i].currentPeriod = cp;
+ // derive comment period status for app list display + sorting
+ applications[i]['cpStatus'] = this.commentPeriodService.getStatus(cp);
+ })
+ );
+ });
+
+ // now get the number of pending comments for each application
+ applications.forEach((application, i) => {
+ promises.push(this.commentService.getAllByApplicationId(applications[i]._id)
+ .toPromise()
+ .then(comments => {
+ const pending = comments.filter(comment => this.commentService.isPending(comment));
+ applications[i]['numComments'] = pending.length.toString();
+ })
+ );
});
return Promise.all(promises).then(() => { return applications; });
@@ -219,7 +240,7 @@ export class ApplicationService {
}
// create new application
- addApplication(item: any): Observable {
+ add(item: any): Observable {
const app = new Application(item);
// boilerplate for new application
|