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-977, PRC-942: expire date and logic #335

Merged
merged 2 commits into from
Jan 22, 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 @@ -10,14 +10,14 @@ <h1>Crown land File: {{application['clFile']}}</h1>
Edit
</button>
<button class="btn btn-primary" type="button"
*ngIf="application.isPublished === false"
*ngIf="!application.isPublished && !isRetired"
(click)="publishApplication()"
[disabled]="isPublishing">
<i class="spinner rotating" [hidden]="!isPublishing"></i>
<span>{{isPublishing ? 'Publishing' : 'Publish'}}</span>
</button>
<button class="btn btn-primary" type="button"
*ngIf="application.isPublished === true"
*ngIf="application.isPublished"
(click)="unPublishApplication()"
[disabled]="isUnpublishing">
<i class="spinner rotating" [hidden]="!isUnpublishing"></i>
Expand All @@ -38,9 +38,25 @@ <h1>Crown land File: {{application['clFile']}}</h1>

<div class="bottom-container" *ngIf="application">
<div class="container">
<ngb-alert type="primary" [dismissible]="false" *ngIf="application['retireDate'] && !isRetired">
<div class="alert-contents">
<i class="material-icons">warning</i>
<div class="alert-msg">
This application will be visible on the public website until {{application['retireDate'] | date:'longDate'}}.
</div>
</div>
</ngb-alert>
<ngb-alert type="warning" [dismissible]="false" *ngIf="application['retireDate'] && isRetired">
<div class="alert-contents">
<i class="material-icons">warning</i>
<div class="alert-msg">
This application was removed from the public website on {{application['retireDate'] | date:'longDate'}}.
</div>
</div>
</ngb-alert>

<div class="row">
<div class="col-md-8">

<section class="main-card">
<!-- Tabs -->
<ngb-tabset>
Expand Down Expand Up @@ -71,10 +87,6 @@ <h2>Details</h2>
<span class="name">Type / Subtype:</span>
<span class="value">{{application.type || '-'}} / {{application.subtype || '-'}}</span>
</li>
<li>
<span class="name">Status:</span>
<span class="value">{{application.appStatus || '-'}}</span>
</li>
<li>
<span class="name">Stage:</span>
<span class="value">{{application.tenureStage || '-'}}</span>
Expand Down Expand Up @@ -177,10 +189,19 @@ <h2>Geographic Shape Information ({{application.features.length}})</h2>
</ngb-tab>
</ngb-tabset>
</section>

</div>

<div class="col-md-4">
<div class="aside-card">
<h3 class="title">Application Status</h3>
<div class="body">
<div class="app-status">{{application.appStatus || '-'}}</div>
<div class="app-status__date text-muted" *ngIf="application.statusHistoryEffectiveDate">
Last updated on {{application.statusHistoryEffectiveDate | date:'longDate'}}
</div>
</div>
</div>

<div class="aside-card">
<h3 class="title">Comment Period Details</h3>
<div class="body" *ngIf="!application.currentPeriod">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,20 @@ section {
font-weight: 600;
}
}
}

.app-status {
font-weight: 700;
}

.app-status__date {
margin-top: 0.15rem;
}

.app-status__remove-date {
margin-top: 1rem;
}

ngb-alert {
margin-bottom: 1.5rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Subject } from 'rxjs/Subject';
import 'rxjs/add/operator/takeUntil';
import 'rxjs/add/operator/concat';
import { of } from 'rxjs';
import * as moment from 'moment-timezone';

import { ConfirmComponent } from 'app/confirm/confirm.component';
import { Application } from 'app/models/application';
Expand All @@ -27,6 +28,7 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
public isPublishing = false;
public isUnpublishing = false;
public isDeleting = false;
public isRetired = false;
public application: Application = null;
private snackBarRef: MatSnackBarRef<SimpleSnackBar> = null;
private ngUnsubscribe: Subject<boolean> = new Subject<boolean>();
Expand All @@ -52,6 +54,10 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
(data: { application: Application }) => {
if (data.application) {
this.application = data.application;
// set flag if retire date is in the past
if (this.application['retireDate']) {
this.isRetired = moment(this.application['retireDate']).isBefore();
}
} else {
alert('Uh-oh, couldn\'t load application');
// application not found --> navigate back to search
Expand Down
12 changes: 10 additions & 2 deletions src/app/applications/application-resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import * as _ from 'lodash';
import * as moment from 'moment';

import { ApplicationService } from 'app/services/application.service';
import { Application } from 'app/models/application';
Expand Down Expand Up @@ -31,8 +32,9 @@ export class ApplicationDetailResolver implements Resolve<Application> {
businessUnit: route.queryParamMap.get('businessUnit'),
cl_file: +route.queryParamMap.get('cl_file'), // NB: unary operator
tantalisID: +route.queryParamMap.get('tantalisID'), // NB: unary operator
legalDescription: route.queryParamMap.get('legalDescription'),
client: route.queryParamMap.get('client'),
legalDescription: route.queryParamMap.get('legalDescription')
statusHistoryEffectiveDate: route.queryParamMap.get('statusHistoryEffectiveDate')
});

// 7-digit CL File number for display
Expand All @@ -41,7 +43,8 @@ export class ApplicationDetailResolver implements Resolve<Application> {
}

// user-friendly application status
application.appStatus = this.applicationService.getLongStatusString(this.applicationService.getStatusCode(application.status));
const appStatusCode = this.applicationService.getStatusCode(application.status);
application.appStatus = this.applicationService.getLongStatusString(appStatusCode);

// derive region code
application.region = this.applicationService.getRegionCode(application.businessUnit);
Expand All @@ -52,6 +55,11 @@ export class ApplicationDetailResolver implements Resolve<Application> {
application['applicants'] = _.uniq(clients).join(', ');
}

// derive retire date
if (application.statusHistoryEffectiveDate && [this.applicationService.DECISION_APPROVED, this.applicationService.DECISION_NOT_APPROVED, this.applicationService.ABANDONED].includes(appStatusCode)) {
application['retireDate'] = moment(application.statusHistoryEffectiveDate).endOf('day').add(6, 'months');
}

return of(application);
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/models/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class Application {
tantalisID: number;
tenureStage: string;
type: string;
statusHistoryEffectiveDate: Date = null;

region: string; // region code derived from Business Unit
appStatus: string; // user-friendly application status
Expand Down Expand Up @@ -62,6 +63,10 @@ export class Application {
this.publishDate = new Date(obj.publishDate);
}

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

// replace \\n (JSON format) with newlines
if (obj && obj.description) {
this.description = obj.description.replace(/\\n/g, '\n');
Expand Down
41 changes: 26 additions & 15 deletions src/app/models/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export class SearchResults {
TENURE_SUBTYPE: string;
TENURE_TYPE: string;
areaHectares: number;
centroid: Array<number> = [];
centroid: Array<number> = []; // [lng, lat]
interestedParties: Array<InterestedParty> = [];
parcels: Array<Feature> = [];
statusHistoryEffectiveDate: Date = null;

constructor(search?: any, hostname?: any) {
this._id = search && search._id || null;
Expand All @@ -41,25 +42,28 @@ export class SearchResults {
this.status = search && search.status || null;
this.hostname = hostname;

this.CROWN_LANDS_FILE = search && search.CROWN_LANDS_FILE || null;
this.DISPOSITION_TRANSACTION_SID = search && search.DISPOSITION_TRANSACTION_SID || null;
this.RESPONSIBLE_BUSINESS_UNIT = search && search.RESPONSIBLE_BUSINESS_UNIT || null;
this.TENURE_LOCATION = search && search.TENURE_LOCATION || null;
this.TENURE_PURPOSE = search && search.TENURE_PURPOSE || null;
this.TENURE_STAGE = search && search.TENURE_STAGE || null;
this.TENURE_STATUS = search && search.TENURE_STATUS || null;
this.TENURE_SUBPURPOSE = search && search.TENURE_SUBPURPOSE || null;
this.TENURE_SUBTYPE = search && search.TENURE_SUBTYPE || null;
this.TENURE_TYPE = search && search.TENURE_TYPE || null;
this.TENURE_TYPE = search && search.TENURE_TYPE || null;
this.areaHectares = search && search.areaHectares || null;
this.centroid = search && search.centroid || null;
this.parcels = search && search.parcels || null;
this.CROWN_LANDS_FILE = search && search.CROWN_LANDS_FILE || null;
this.DISPOSITION_TRANSACTION_SID = search && search.DISPOSITION_TRANSACTION_SID || null;
this.RESPONSIBLE_BUSINESS_UNIT = search && search.RESPONSIBLE_BUSINESS_UNIT || null;
this.TENURE_LOCATION = search && search.TENURE_LOCATION || null;
this.TENURE_PURPOSE = search && search.TENURE_PURPOSE || null;
this.TENURE_STAGE = search && search.TENURE_STAGE || null;
this.TENURE_STATUS = search && search.TENURE_STATUS || null;
this.TENURE_SUBPURPOSE = search && search.TENURE_SUBPURPOSE || null;
this.TENURE_SUBTYPE = search && search.TENURE_SUBTYPE || null;
this.TENURE_TYPE = search && search.TENURE_TYPE || null;
this.TENURE_TYPE = search && search.TENURE_TYPE || null;
this.areaHectares = search && search.areaHectares || null;
this.parcels = search && search.parcels || null;

if (search && search.date) {
this.date = new Date(search.date);
}

if (search && search.statusHistoryEffectiveDate) {
this.statusHistoryEffectiveDate = new Date(search.statusHistoryEffectiveDate);
}

// copy features
if (search && search.features) {
for (const feature of search.features) {
Expand All @@ -80,6 +84,13 @@ export class SearchResults {
this.sidsFound.push(sid);
}
}

// copy centroid
if (search && search.centroid) {
for (const num of search.centroid) {
this.centroid.push(num);
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export class SearchComponent implements OnInit, OnDestroy {
cl_file: application.cl_file,
tantalisID: application.tantalisID,
legalDescription: application.legalDescription,
client: application.client
client: application.client,
statusHistoryEffectiveDate: application.statusHistoryEffectiveDate
};
// go to add-edit page
this.router.navigate(['/a', 0, 'edit'], { queryParams: params });
Expand Down
4 changes: 4 additions & 0 deletions src/app/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class ApiService {
'publishDate',
'purpose',
'status',
'statusHistoryEffectiveDate',
'subpurpose',
'subtype',
'tantalisID',
Expand Down Expand Up @@ -176,6 +177,7 @@ export class ApiService {
'publishDate',
'purpose',
'status',
'statusHistoryEffectiveDate',
'subpurpose',
'subtype',
'tantalisID',
Expand Down Expand Up @@ -214,6 +216,7 @@ export class ApiService {
'publishDate',
'purpose',
'status',
'statusHistoryEffectiveDate',
'subpurpose',
'subtype',
'tantalisID',
Expand All @@ -240,6 +243,7 @@ export class ApiService {
'publishDate',
'purpose',
'status',
'statusHistoryEffectiveDate',
'subpurpose',
'subtype',
'tantalisID',
Expand Down
8 changes: 7 additions & 1 deletion src/app/services/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ export class ApplicationService {
}

// user-friendly application status
application.appStatus = this.getLongStatusString(this.getStatusCode(application.status));
const appStatusCode = this.getStatusCode(application.status);
application.appStatus = this.getLongStatusString(appStatusCode);

// derive region code
application.region = this.getRegionCode(application.businessUnit);
Expand All @@ -203,6 +204,11 @@ export class ApplicationService {
application['applicants'] = _.uniq(clients).join(', ');
}

// derive retire date
if (application.statusHistoryEffectiveDate && [this.DECISION_APPROVED, this.DECISION_NOT_APPROVED, this.ABANDONED].includes(appStatusCode)) {
application['retireDate'] = moment(application.statusHistoryEffectiveDate).endOf('day').add(6, 'months');
}

// finally update the object and return
return application;
});
Expand Down
Loading