Skip to content

Commit a8c3cc9

Browse files
authored
ROF scheduled delete (#2214)
* Update the client to better handle listeners and awaits * Add a cleanup job instead of inline deletes
1 parent bc42be0 commit a8c3cc9

File tree

17 files changed

+472
-235
lines changed

17 files changed

+472
-235
lines changed

client/wfnews-war/src/main/angular/src/app/components/report-of-fire/review-page/rof-review-page.component.html

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
<div class="divider"></div>
55
<div *ngIf="reportOfFirePages">
66
<div *ngFor="let page of reportOfFirePages">
7-
<div *ngIf="page.id !== 'disclaimer-page' && page.id !== 'call-page' && !(page.id === 'location-page' && isOffLine)">
8-
<div class="rof-text-review-header" >
7+
<div
8+
*ngIf="page.id !== 'disclaimer-page' && page.id !== 'call-page' && !(page.id === 'location-page' && isOffLine)">
9+
<div class="rof-text-review-header">
910
{{page.title}}
1011
</div>
11-
<div *ngIf = "page.id !== 'location-page'">
12+
<div *ngIf="page.id !== 'location-page'">
1213
<div class="item">
1314
<div *ngIf="page.id === 'comments-page'">
14-
<div class="item-content" >
15+
<div class="item-content">
1516
<div class="text">Note</div>
1617
<div class="edit-icon">
1718
<mat-icon svgIcon="edit" (click)="edit(page.id)"></mat-icon>
@@ -28,13 +29,25 @@
2829
<mat-icon svgIcon="edit" (click)="edit(page.id)"></mat-icon>
2930
</div>
3031
</div>
31-
<div *ngIf = "page.id === 'photo-page' && reportOfFire.image1" class="images">
32-
<div *ngIf = "reportOfFire.image1 !== undefined && reportOfFire.image1.webPath !== undefined"><img alt="icon" class="image" [src]="reportOfFire.image1.webPath"></div>
33-
<div *ngIf = "reportOfFire.image1 !== undefined && reportOfFire.image1.dataUrl !== undefined"><img alt="icon" class="image" [src]="reportOfFire.image1.dataUrl"></div>
34-
<div *ngIf = "reportOfFire.image2 !== undefined && reportOfFire.image2.webPath !== undefined"><img alt="icon" class="image" [src]="reportOfFire.image2.webPath"></div>
35-
<div *ngIf = "reportOfFire.image2 !== undefined && reportOfFire.image2.dataUrl !== undefined"><img alt="icon" class="image" [src]="reportOfFire.image2.dataUrl"></div>
36-
<div *ngIf = "reportOfFire.image3 !== undefined && reportOfFire.image3.webPath !== undefined"><img alt="icon" class="image" [src]="reportOfFire.image3.webPath"></div>
37-
<div *ngIf = "reportOfFire.image3 !== undefined && reportOfFire.image3.dataUrl !== undefined"><img alt="icon" class="image" [src]="reportOfFire.image3.dataUrl"></div>
32+
<div *ngIf="page.id === 'photo-page' && reportOfFire.image1" class="images">
33+
<div *ngIf="reportOfFire.image1 !== undefined && reportOfFire.image1.webPath !== undefined">
34+
<img alt="icon" class="image" [src]="reportOfFire.image1.webPath">
35+
</div>
36+
<div *ngIf="reportOfFire.image1 !== undefined && reportOfFire.image1.dataUrl !== undefined">
37+
<img alt="icon" class="image" [src]="reportOfFire.image1.dataUrl">
38+
</div>
39+
<div *ngIf="reportOfFire.image2 !== undefined && reportOfFire.image2.webPath !== undefined">
40+
<img alt="icon" class="image" [src]="reportOfFire.image2.webPath">
41+
</div>
42+
<div *ngIf="reportOfFire.image2 !== undefined && reportOfFire.image2.dataUrl !== undefined">
43+
<img alt="icon" class="image" [src]="reportOfFire.image2.dataUrl">
44+
</div>
45+
<div *ngIf="reportOfFire.image3 !== undefined && reportOfFire.image3.webPath !== undefined">
46+
<img alt="icon" class="image" [src]="reportOfFire.image3.webPath">
47+
</div>
48+
<div *ngIf="reportOfFire.image3 !== undefined && reportOfFire.image3.dataUrl !== undefined">
49+
<img alt="icon" class="image" [src]="reportOfFire.image3.dataUrl">
50+
</div>
3851
</div>
3952
</div>
4053
<div *ngIf="twoPartsQuestions(page)" class="item">
@@ -46,20 +59,20 @@
4659
</div>
4760
</div>
4861
</div>
49-
<div *ngIf = "page.id === 'location-page' && !isOffLine" style="position: relative;">
62+
<div *ngIf="page.id === 'location-page' && !isOffLine" style="position: relative;">
5063
<button (click)="edit(page.id)" class="edit-button">
5164
<mat-icon svgIcon="edit"></mat-icon>
5265
Edit
5366
</button>
5467
<div *ngIf="!isOffLine" id="map" class="map-container">
68+
</div>
5569
</div>
5670
</div>
5771
</div>
58-
</div>
5972

60-
<div class="submit-button-row">
61-
<button mat-flat-button class="action-button" (click)="submitRof()">Submit Report
62-
<mat-icon svgIcon="send"></mat-icon>
63-
</button>
64-
</div>
65-
</div>
73+
<div class="submit-button-row">
74+
<button [disabled]="submitting" mat-flat-button class="action-button" (click)="submitRof()">Submit Report
75+
<mat-icon svgIcon="send"></mat-icon>
76+
</button>
77+
</div>
78+
</div>

client/wfnews-war/src/main/angular/src/app/components/report-of-fire/review-page/rof-review-page.component.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
import {
2-
Component,
3-
ChangeDetectionStrategy,
42
AfterViewInit,
3+
ChangeDetectionStrategy,
54
ChangeDetectorRef,
6-
OnInit,
5+
Component
76
} from '@angular/core';
8-
import { RoFPage } from '../rofPage';
9-
import { ReportOfFire } from '../reportOfFireModel';
10-
import ConfigJson from '../report-of-fire.config.json';
11-
import * as L from 'leaflet';
7+
import { MatSnackBar } from '@angular/material/snack-bar';
128
import { ReportOfFirePage } from '@app/components/report-of-fire/report-of-fire.component';
139
import { CommonUtilityService } from '@app/services/common-utility.service';
14-
import { MatSnackBar } from '@angular/material/snack-bar';
1510
import {
1611
ReportOfFireService,
1712
ReportOfFireType,
1813
} from '@app/services/report-of-fire-service';
19-
import { equalsIgnoreCase } from '../../../utils';
20-
import offlineMapJson from '../../../../assets/maps/british-columbia.json';
2114
import { SmkApi } from '@app/utils/smk';
15+
import * as L from 'leaflet';
2216
import { LatLng } from 'leaflet';
2317
import { v5 as uuidv5 } from 'uuid';
18+
import offlineMapJson from '../../../../assets/maps/british-columbia.json';
19+
import { equalsIgnoreCase } from '../../../utils';
20+
import ConfigJson from '../report-of-fire.config.json';
21+
import { ReportOfFire } from '../reportOfFireModel';
22+
import { RoFPage } from '../rofPage';
2423

2524
@Component({
2625
selector: 'rof-review-page',
@@ -34,6 +33,7 @@ export class RoFReviewPage extends RoFPage implements AfterViewInit {
3433
smkApi: SmkApi;
3534
isOffLine: boolean;
3635
currentLocation: any;
36+
submitting: boolean = false;
3737
public constructor(
3838
private reportOfFirePage: ReportOfFirePage,
3939
private commonUtilityService: CommonUtilityService,
@@ -79,7 +79,7 @@ export class RoFReviewPage extends RoFPage implements AfterViewInit {
7979
case 'contact-page':
8080
return this.reportOfFire.consentToCall
8181
? this.reportOfFire.consentToCall.charAt(0).toUpperCase() +
82-
this.reportOfFire.consentToCall.slice(1)
82+
this.reportOfFire.consentToCall.slice(1)
8383
: null;
8484
case 'location-page':
8585
return this.reportOfFire.fireLocation;
@@ -88,8 +88,8 @@ export class RoFReviewPage extends RoFPage implements AfterViewInit {
8888
case 'smoke-color-page':
8989
return this.reportOfFire.smokeColor
9090
? this.reportOfFire.smokeColor
91-
.map((item) => this.findLabelByValue(page.id, item))
92-
.join(', ')
91+
.map((item) => this.findLabelByValue(page.id, item))
92+
.join(', ')
9393
: null;
9494
case 'fire-size-page':
9595
return this.reportOfFire.fireSize
@@ -99,12 +99,12 @@ export class RoFReviewPage extends RoFPage implements AfterViewInit {
9999
//make the first letter of a string uppercase
100100
return this.reportOfFire.ifSignsOfResponse
101101
? this.reportOfFire.ifSignsOfResponse.charAt(0).toUpperCase() +
102-
this.reportOfFire.ifSignsOfResponse.slice(1)
102+
this.reportOfFire.ifSignsOfResponse.slice(1)
103103
: null;
104104
case 'visible-flame-page':
105105
return this.reportOfFire.visibleFlame
106106
? this.reportOfFire.visibleFlame.charAt(0).toUpperCase() +
107-
this.reportOfFire.visibleFlame.slice(1)
107+
this.reportOfFire.visibleFlame.slice(1)
108108
: null;
109109
case 'fire-spread-page':
110110
return this.reportOfFire.rateOfSpread
@@ -113,13 +113,13 @@ export class RoFReviewPage extends RoFPage implements AfterViewInit {
113113
case 'what-is-burning-page':
114114
return this.reportOfFire.burning
115115
? this.reportOfFire.burning
116-
.map((item) => this.findLabelByValue(page.id, item))
117-
.join(', ')
116+
.map((item) => this.findLabelByValue(page.id, item))
117+
.join(', ')
118118
: null;
119119
case 'infrastructure-details-page':
120120
return this.reportOfFire.ifAssetsAtRisk
121121
? this.reportOfFire.ifAssetsAtRisk.charAt(0).toUpperCase() +
122-
this.reportOfFire.ifAssetsAtRisk.slice(1)
122+
this.reportOfFire.ifAssetsAtRisk.slice(1)
123123
: null;
124124
case 'comments-page':
125125
return this.reportOfFire.otherInfo;
@@ -152,14 +152,14 @@ export class RoFReviewPage extends RoFPage implements AfterViewInit {
152152
case 'response-details-page':
153153
return this.reportOfFire.signsOfResponse
154154
? this.reportOfFire.signsOfResponse
155-
.map((item) => this.findLabelByValue(page.id, item))
156-
.join(', ')
155+
.map((item) => this.findLabelByValue(page.id, item))
156+
.join(', ')
157157
: null;
158158
case 'infrastructure-details-page':
159159
return this.reportOfFire.assetsAtRisk
160160
? this.reportOfFire.assetsAtRisk
161-
.map((item) => this.findLabelByValue(page.id, item))
162-
.join(', ')
161+
.map((item) => this.findLabelByValue(page.id, item))
162+
.join(', ')
163163
: null;
164164
}
165165
}
@@ -314,8 +314,8 @@ export class RoFReviewPage extends RoFPage implements AfterViewInit {
314314
const newLongitude =
315315
initialFirePoint.lng +
316316
(offSet * Math.sin(angleInRadians)) /
317-
((Math.PI * 6378137) / 180) /
318-
Math.cos((initialFirePoint.lat * Math.PI) / 180);
317+
((Math.PI * 6378137) / 180) /
318+
Math.cos((initialFirePoint.lat * Math.PI) / 180);
319319
const newFirePoint = [newLatitude, newLongitude];
320320

321321
latlngs.push(newFirePoint);
@@ -419,15 +419,22 @@ export class RoFReviewPage extends RoFPage implements AfterViewInit {
419419
submissionID: uniqueID
420420
};
421421

422+
if (this.submitting) {
423+
return;
424+
}
425+
426+
this.submitting = true;
427+
422428
try {
423-
this.reportOfFireService.saveReportOfFire(
429+
await this.reportOfFireService.saveReportOfFire(
424430
rofResource,
425431
this.reportOfFire.image1,
426432
this.reportOfFire.image2,
427433
this.reportOfFire.image3,
428434
);
429435
this.next();
430436
} catch (err) {
437+
this.submitting = false;
431438
this.snackbarService.open(
432439
'Failed to submit Report Of Fire: ' + JSON.stringify(err.message),
433440
'OK',

client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
import {
2-
Component,
32
ChangeDetectionStrategy,
43
ChangeDetectorRef,
4+
Component,
5+
OnDestroy,
56
OnInit,
67
} from '@angular/core';
7-
import { RoFPage } from '../rofPage';
8-
import { ReportOfFire } from '../reportOfFireModel';
98
import { MatDialog } from '@angular/material/dialog';
109
import { DialogLocationComponent } from '@app/components/report-of-fire/dialog-location/dialog-location.component';
11-
import { CommonUtilityService } from '@app/services/common-utility.service';
1210
import { ReportOfFirePage } from '@app/components/report-of-fire/report-of-fire.component';
11+
import { CommonUtilityService } from '@app/services/common-utility.service';
12+
import { ReportOfFireService } from '@app/services/report-of-fire-service';
1313
import { App } from '@capacitor/app';
14+
import { PluginListenerHandle } from '@capacitor/core';
1415
import { BackgroundTask } from '@capawesome/capacitor-background-task';
1516
import { Subscription, interval } from 'rxjs';
16-
import { ReportOfFireService } from '@app/services/report-of-fire-service';
17+
import { ReportOfFire } from '../reportOfFireModel';
18+
import { RoFPage } from '../rofPage';
1719

1820
@Component({
1921
selector: 'rof-title-page',
2022
templateUrl: './rof-title-page.component.html',
2123
styleUrls: ['./rof-title-page.component.scss'],
2224
changeDetection: ChangeDetectionStrategy.OnPush,
2325
})
24-
export class RoFTitlePage extends RoFPage implements OnInit {
26+
export class RoFTitlePage extends RoFPage implements OnInit, OnDestroy {
2527
public imageUrl: string;
2628
public closeButton: boolean;
2729
public messages: any;
2830
public offLineMessages: any;
2931
offLine = false;
3032
private intervalRef: Subscription;
33+
private appStateListener: PluginListenerHandle;
3134

3235
public constructor(
3336
protected dialog: MatDialog,
@@ -41,7 +44,9 @@ export class RoFTitlePage extends RoFPage implements OnInit {
4144

4245
ngOnInit(): void {
4346
if (this.reportOfFirePage.currentPage.instance.id === 'first-page') {
44-
App.removeAllListeners();
47+
if (this.appStateListener) {
48+
this.appStateListener.remove();
49+
}
4550
// run background task
4651
(async () => {
4752
await this.backgroundListener();
@@ -59,17 +64,20 @@ export class RoFTitlePage extends RoFPage implements OnInit {
5964
}
6065

6166
async backgroundListener() {
62-
App.addListener('appStateChange', async ({ isActive }) => {
67+
if (this.appStateListener) {
68+
this.appStateListener.remove();
69+
}
70+
this.appStateListener = await App.addListener('appStateChange', async ({ isActive }) => {
6371
if (isActive) {
6472
return;
6573
}
6674
// The app state has been changed to inactive.
6775
// Start the background task by calling `beforeExit`.
6876
const taskId = await BackgroundTask.beforeExit(async () => {
6977

70-
if(!this.intervalRef || this.intervalRef.closed) {
78+
if (!this.intervalRef || this.intervalRef.closed) {
7179
this.intervalRef = interval(30000).subscribe(async () => {
72-
if(await this.checkStoredRoF())
80+
if (await this.checkStoredRoF())
7381
this.unsubscribeInterval();
7482
});
7583
}
@@ -83,6 +91,13 @@ export class RoFTitlePage extends RoFPage implements OnInit {
8391
this.intervalRef?.unsubscribe();
8492
}
8593

94+
ngOnDestroy() {
95+
this.unsubscribeInterval();
96+
if (this.appStateListener) {
97+
this.appStateListener.remove();
98+
}
99+
}
100+
86101
openCallPage() {
87102
this.reportOfFirePage.selectPage('call-page', null, false);
88103
}

0 commit comments

Comments
 (0)