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..90cadf89a 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..09a731e0b 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,36 @@ -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'; +import { RecordUtils } from '../../../records/utils/record-utils'; @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(); + + public bcmiFlavour: any; public isPublished = false; - public factoryService: FactoryService; constructor( private router: Router, + public factoryService: FactoryService, + private logger: LoggerService, + protected recordUtils: RecordUtils, public changeDetectionRef: ChangeDetectorRef ) { super(); } ngOnInit() { + this.bcmiFlavour = this.rowData.flavours.find(flavour => flavour._schemaName.endsWith('BCMI')); this.isPublished = this.isRecordPublished(); this.changeDetectionRef.detectChanges(); } @@ -36,31 +47,132 @@ export class EnforcementActionsTableRowComponent extends TableRowComponent imple return 'court-convictions'; } } + 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 + async publish() { + if (!this.bcmiFlavour) { + const res = await this.createBcmiRecord(); + this.recordUtils.parseResForErrors(res); + + if (res && res[0] && res[0][0] && res[0][0].status === 'success') { + this.isPublished = true; + this.changeDetectionRef.detectChanges(); + } + } else { + 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(); + }); + } + + private async createBcmiRecord() { + const containerName = this.getSchemaContainer(this.rowData._schemaName); + + if (!containerName) { + alert('Failed to publish record.'); + return; + } + + const record = { + [`${this.rowData._schemaName}BCMI`]: { + addRole: 'public' + }, + _id: this.rowData._id + }; + + return this.factoryService.writeRecord(record, containerName, false); + } + + private getSchemaContainer(schemaName) { + switch (schemaName) { + case 'AdministrativePenalty': + return 'administrativePenalties'; + case 'CourtConviction': + return 'courtConvictions'; + default: + return null; + } } 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 @@
- +