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-644: display user-friendly app status on search page + moved appStatus out of features code #223

Merged
merged 1 commit into from
Sep 12, 2018
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
2 changes: 1 addition & 1 deletion src/app/search/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2 *ngIf="ranSearch && !searching && count > 0">
{{item.properties.TENURE_PURPOSE | titlecase}} / {{item.properties.TENURE_SUBPURPOSE | titlecase}}
</td>
<td>
{{item.properties.TENURE_STATUS | titlecase}}
{{item.app?.appStatus || (item.properties.TENURE_STATUS | titlecase) || 'Unknown'}}
</td>
<td class="actions">
<button class="btn btn-sm btn-primary" type="button"
Expand Down
70 changes: 29 additions & 41 deletions src/app/services/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,61 +101,53 @@ export class ApplicationService {

const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const promises: Array<Promise<any>> = [];

// replace \\n (JSON format) with newlines in each application
applications.forEach((application, i) => {
if (applications[i].description) {
applications[i].description = applications[i].description.replace(/\\n/g, '\n');
applications.forEach((application) => {
// replace \\n (JSON format) with newlines in each application
if (application.description) {
application.description = application.description.replace(/\\n/g, '\n');
}
if (applications[i].legalDescription) {
applications[i].legalDescription = applications[i].legalDescription.replace(/\\n/g, '\n');
if (application.legalDescription) {
application.legalDescription = application.legalDescription.replace(/\\n/g, '\n');
}
});

const promises: Array<Promise<any>> = [];
// user-friendly application status
application['appStatus'] = this.getStatusString(this.getStatusCode(application.status));

// FUTURE: get the organization here
// FUTURE: now get the organization

// now get the current comment period for each application
applications.forEach((application, i) => {
promises.push(this.commentPeriodService.getAllByApplicationId(applications[i]._id)
// NB: we don't get documents here

// now get the current comment period for each application
promises.push(this.commentPeriodService.getAllByApplicationId(application._id)
.toPromise()
.then(periods => {
const cp = this.commentPeriodService.getCurrent(periods);
applications[i].currentPeriod = cp;
// derive comment period status for display
applications[i]['cpStatus'] = this.commentPeriodService.getStatus(cp);
application.currentPeriod = cp;
// user-friendly comment period status
application['cpStatus'] = this.commentPeriodService.getStatus(cp);
// derive days remaining for display
// use moment to handle Daylight Saving Time changes
if (cp && this.commentPeriodService.isOpen(cp)) {
applications[i].currentPeriod['daysRemaining'] = moment(cp.endDate).diff(moment(today), 'days') + 1; // including today
application.currentPeriod['daysRemaining'] = moment(cp.endDate).diff(moment(today), 'days') + 1; // including today
}
})
);
});

// now get the number of pending comments for each application
applications.forEach((application, i) => {
promises.push(this.commentService.getAllByApplicationId(applications[i]._id)
// now get the number of pending comments for each application
promises.push(this.commentService.getAllByApplicationId(application._id)
.toPromise()
.then(comments => {
const pending = comments.filter(comment => this.commentService.isPending(comment));
applications[i]['numComments'] = pending.length.toString();
application['numComments'] = pending.length.toString();
})
);
});

// NOT NEEDED AT THIS TIME
// // now get the decision for each application
// applications.forEach((application, i) => {
// promises.push(this.decisionService.getByApplicationId(applications[i]._id)
// .toPromise()
// .then(decision => applications[i].decision = decision)
// );
// });
// NB: we don't get the decision here

// now get the referenced data (features) for each application
applications.forEach((application, i) => {
// TODO: we don't need to get the shapes (features) here... remove this code
// now get the referenced data (features) for each application
promises.push(this.featureService.getByApplicationId(application._id)
.toPromise()
.then(features => {
Expand All @@ -168,9 +160,6 @@ export class ApplicationService {
application.areaHectares += f['properties'].TENURE_AREA_IN_HECTARES;
}
});

// derive application status for display
application['appStatus'] = this.getStatusString(application.status);
})
);
});
Expand Down Expand Up @@ -238,6 +227,7 @@ export class ApplicationService {

const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const promises: Array<Promise<any>> = [];

// replace \\n (JSON format) with newlines
if (application.description) {
Expand All @@ -247,9 +237,10 @@ export class ApplicationService {
application.legalDescription = application.legalDescription.replace(/\\n/g, '\n');
}

const promises: Array<Promise<any>> = [];
// user-friendly application status
application['appStatus'] = this.getStatusString(this.getStatusCode(application.status));

// FUTURE: get the organization here
// FUTURE: now get the organization

// get the documents
promises.push(this.documentService.getAllByApplicationId(application._id)
Expand All @@ -263,7 +254,7 @@ export class ApplicationService {
.then(periods => {
const cp = this.commentPeriodService.getCurrent(periods);
application.currentPeriod = cp;
// derive comment period status for display
// user-friendly comment period status
application['cpStatus'] = this.commentPeriodService.getStatus(cp);
// derive days remaining for display
// use moment to handle Daylight Saving Time changes
Expand Down Expand Up @@ -300,9 +291,6 @@ export class ApplicationService {
application.areaHectares += f['properties'].TENURE_AREA_IN_HECTARES;
}
});

// derive application status for display
application['appStatus'] = this.getStatusString(application.status);
})
);

Expand Down