From 878885a436bbc0bbf535f1dc508f93edd1fb468b Mon Sep 17 00:00:00 2001 From: BcGovNeal <47604552+BcGovNeal@users.noreply.github.com> Date: Thu, 8 Jul 2021 15:13:37 -0700 Subject: [PATCH 1/3] Enforcement actions fixes --- .../enforcement-actions-resolver.ts | 2 +- ...forcement-actions-table-row.component.html | 19 ++-- ...enforcement-actions-table-row.component.ts | 99 ++++++++++++++++--- .../enforcement-actions.component.html | 2 +- ...nistrative-penalty-add-edit.component.html | 2 +- ...ministrative-penalty-detail.component.html | 2 +- ...-court-convictions-add-edit.component.html | 2 +- ...es-court-convictions-add-edit.component.ts | 2 + ...es-court-convictions-detail.component.html | 2 +- .../src/app/sidebar/sidebar.component.html | 3 +- .../entity-add-edit.component.html | 2 +- .../entity-add-edit.component.ts | 1 + .../models/master/administrativePenalty.js | 3 +- api/src/models/master/courtConviction.js | 3 +- 14 files changed, 114 insertions(+), 30 deletions(-) diff --git a/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-resolver.ts b/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-resolver.ts index 687203e44..070ee89b9 100644 --- a/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-resolver.ts +++ b/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-resolver.ts @@ -30,7 +30,7 @@ export class EnforcementActionsResolver implements Resolve> { tableObject.pageSize, tableObject.sortBy || '-dateAdded', and, - false, + true, {}, [] ); diff --git a/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-table/enforcement-actions-table-row/enforcement-actions-table-row.component.html b/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-table/enforcement-actions-table-row/enforcement-actions-table-row.component.html index 34da1d72c..f9af080d2 100644 --- a/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-table/enforcement-actions-table-row/enforcement-actions-table-row.component.html +++ b/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-table/enforcement-actions-table-row/enforcement-actions-table-row.component.html @@ -1,7 +1,8 @@ -{{ getAttributeValue('recordName')}} -{{ getAttributeValue('recordType')}} -{{(getAttributeValue('dateIssued') === '-') ? '-' : - (getAttributeValue('dateIssued') | date: 'mediumDate')}} +{{ getAttributeValue('recordName') }} +{{ getAttributeValue('recordType') }} + + {{ getAttributeValue('dateIssued') === '-' ? '-' : (getAttributeValue('dateIssued') | date: 'mediumDate') }} +
@@ -18,8 +19,10 @@ - - - + + + + + - \ No newline at end of file + diff --git a/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-table/enforcement-actions-table-row/enforcement-actions-table-row.component.ts b/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-table/enforcement-actions-table-row/enforcement-actions-table-row.component.ts index b0d8f80d8..6de27bdde 100644 --- a/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-table/enforcement-actions-table-row/enforcement-actions-table-row.component.ts +++ b/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions-table/enforcement-actions-table-row/enforcement-actions-table-row.component.ts @@ -1,25 +1,34 @@ -import { Component, HostListener, OnInit, ChangeDetectorRef } from '@angular/core'; +import { Component, HostListener, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core'; +import { takeUntil, catchError } from 'rxjs/operators'; import { Router } from '@angular/router'; +import { Subject, of } from 'rxjs'; + import { TableRowComponent } from 'nrpti-angular-components'; import { FactoryService } from '../../../services/factory.service'; +import { LoggerService } from 'nrpti-angular-components'; @Component({ selector: 'tr[app-enforcement-actions-table-row]', templateUrl: './enforcement-actions-table-row.component.html', styleUrls: ['./enforcement-actions-table-row.component.scss'] }) -export class EnforcementActionsTableRowComponent extends TableRowComponent implements OnInit { +export class EnforcementActionsTableRowComponent extends TableRowComponent implements OnInit, OnDestroy { + private ngUnsubscribe: Subject = new Subject(); + + private bcmiFlavour: any; public isPublished = false; - public factoryService: FactoryService; constructor( private router: Router, + public factoryService: FactoryService, + private logger: LoggerService, public changeDetectionRef: ChangeDetectorRef ) { super(); } ngOnInit() { + this.bcmiFlavour = this.rowData.flavours.find(flavour => flavour._schemaName.endsWith('BCMI')); this.isPublished = this.isRecordPublished(); this.changeDetectionRef.detectChanges(); } @@ -37,30 +46,96 @@ export class EnforcementActionsTableRowComponent extends TableRowComponent imple } } goToDetails() { - this.router.navigate( - ['mines', 'enforcement-actions', this.getSchemaRoute(this.rowData._schemaName), this.rowData._id] - ); + this.router.navigate([ + 'mines', + 'enforcement-actions', + this.getSchemaRoute(this.rowData._schemaName), + this.rowData._id + ]); } goToEdit() { - this.router.navigate( - ['mines', 'enforcement-actions', this.getSchemaRoute(this.rowData._schemaName), this.rowData._id, 'edit'] - ); + this.router.navigate([ + 'mines', + 'enforcement-actions', + this.getSchemaRoute(this.rowData._schemaName), + this.rowData._id, + 'edit' + ]); } publish() { - // to be implemented + if (!this.bcmiFlavour) { + alert('Failed to unpublish record. No BCMI record found.'); + return; + } + + this.factoryService + .publishRecord(this.bcmiFlavour) + .pipe( + takeUntil(this.ngUnsubscribe), + catchError(error => { + this.logger.log(`Publish error: ${error}`); + alert('Failed to publish record.'); + return of(null); + }) + ) + .subscribe(response => { + if (!response) { + return; + } + + if (response.code === 409) { + // object was already published + return; + } + + this.isPublished = true; + this.changeDetectionRef.detectChanges(); + }); } unPublish() { - // to be implemented + if (!this.bcmiFlavour) { + alert('Failed to unpublish record. No BCMI record found.'); + return; + } + + this.factoryService + .unPublishRecord(this.bcmiFlavour) + .pipe( + takeUntil(this.ngUnsubscribe), + catchError(error => { + this.logger.log(`Unpublish error: ${error}`); + alert('Failed to unpublish record.'); + return of(null); + }) + ) + .subscribe(response => { + if (!response) { + return; + } + + if (response.code === 409) { + // object was already unpublished + return; + } + + this.isPublished = false; + this.changeDetectionRef.detectChanges(); + }); } isRecordPublished(): boolean { - return this.rowData && this.rowData.read && this.rowData.read.includes('public'); + return this.rowData && this.rowData.read && this.rowData.isBcmiPublished; } @HostListener('click') onItemClicked() { this.goToDetails(); } + + ngOnDestroy() { + this.ngUnsubscribe.next(); + this.ngUnsubscribe.complete(); + } } diff --git a/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions.component.html b/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions.component.html index 508d79b3a..3f72c1037 100644 --- a/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions.component.html +++ b/angular/projects/admin-nrpti/src/app/enforcement-actions/enforcement-actions.component.html @@ -51,7 +51,7 @@
placement="bottom-right">

Basic Information

- + Shared Data [Master] {{ (data && data._master.author) || '-' }}
- + {{ (data && data._master.dateIssued | date: 'mediumDate') || '-' }}
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.html b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.html index df2c0cc93..e1cbdacbe 100644 --- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.html +++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.html @@ -85,7 +85,7 @@

Basic Information

Issued To

- +
diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.ts b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.ts index 67e6d7f5b..5d54e3915 100644 --- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.ts +++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-add-edit/mines-court-convictions-add-edit.component.ts @@ -127,6 +127,8 @@ export class MinesCourtConvictionsAddEditComponent extends CourtConvictionAddEdi const selectedMine = this.storeService.getItem('mines').find(mine => mine._sourceRefId === val); this.myForm.get('latitude').setValue(selectedMine.location.coordinates[1]); this.myForm.get('longitude').setValue(selectedMine.location.coordinates[0]); + this.myForm.controls.latitude.markAsDirty(); + this.myForm.controls.longitude.markAsDirty(); }); } diff --git a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-detail/mines-court-convictions-detail.component.html b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-detail/mines-court-convictions-detail.component.html index 7a1b43bb1..b62215db4 100644 --- a/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-detail/mines-court-convictions-detail.component.html +++ b/angular/projects/admin-nrpti/src/app/mines/mines-enforcement-actions/mines-court-convictions/mines-court-convictions-detail/mines-court-convictions-detail.component.html @@ -29,7 +29,7 @@

Shared Data [Master]

{{ (data && data._master.author) || '-' }}
- + {{ (data && data._master.dateIssued | date: 'mediumDate') || '-' }}
diff --git a/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html b/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html index 80ecf3a5b..167ee20d4 100644 --- a/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html +++ b/angular/projects/admin-nrpti/src/app/sidebar/sidebar.component.html @@ -15,8 +15,9 @@ *ngIf="mainRoute === 'mines'"> + description Enforcement Actions diff --git a/angular/projects/common/src/app/entity/entity-add-edit/entity-add-edit.component.html b/angular/projects/common/src/app/entity/entity-add-edit/entity-add-edit.component.html index 1af7f320e..1b72e55c2 100644 --- a/angular/projects/common/src/app/entity/entity-add-edit/entity-add-edit.component.html +++ b/angular/projects/common/src/app/entity/entity-add-edit/entity-add-edit.component.html @@ -2,7 +2,7 @@
- +