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

NRPT-749 Fixes to Enforcement Action components #873

Merged
merged 4 commits into from
Jul 12, 2021
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 @@ -30,7 +30,7 @@ export class EnforcementActionsResolver implements Resolve<Observable<object>> {
tableObject.pageSize,
tableObject.sortBy || '-dateAdded',
and,
false,
true,
{},
[]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<td scope="row" data-label="Record Name" class="col-5">{{ getAttributeValue('recordName')}}</td>
<td scope="row" data-label="Record Type" class="col-2">{{ getAttributeValue('recordType')}}</td>
<td scope="row" data-label="Date" class="col-2">{{(getAttributeValue('dateIssued') === '-') ? '-' :
(getAttributeValue('dateIssued') | date: 'mediumDate')}}</td>
<td scope="row" data-label="Record Name" class="col-5">{{ getAttributeValue('recordName') }}</td>
<td scope="row" data-label="Record Type" class="col-2">{{ getAttributeValue('recordType') }}</td>
<td scope="row" data-label="Date" class="col-2">
{{ getAttributeValue('dateIssued') === '-' ? '-' : (getAttributeValue('dateIssued') | date: 'mediumDate') }}
</td>

<td scope="row" data-label="Published State" class="col-2 d-flex">
<div *ngIf="isPublished; else unpublished">
Expand All @@ -18,8 +19,10 @@
<button mat-icon-button class="btn" [matMenuTriggerFor]="menu" title="More options" aria-label="More options menu">
<em class="material-icons">more_vert</em>
</button>
<mat-menu #menu='matMenu'>
<button mat-menu-item (click)="goToDetails()" title='View record details'>View Record Details</button>
<button mat-menu-item (click)="goToEdit()" title='Edit record'>Edit Record</button>
<mat-menu #menu="matMenu">
<button mat-menu-item (click)="goToDetails()" title="View record details">View Record Details</button>
<button mat-menu-item (click)="goToEdit()" title="Edit record">Edit Record</button>
<button mat-menu-item *ngIf="!isPublished" (click)="publish()" title="Publish">Publish</button>
<button mat-menu-item *ngIf="isPublished" (click)="unPublish()" title="Un-Publish">Un-Publish</button>
</mat-menu>
</td>
</td>
Original file line number Diff line number Diff line change
@@ -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<boolean> = new Subject<boolean>();

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();
}
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h5>
placement="bottom-right">
<button class="btn btn-primary"
ngbDropdownToggle>
Add Record
Add a New Action
</button>
<div ngbDropdownMenu>
<button ngbDropdownItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h4 class="blue-header">{{ componentTitle }}</h4>
<h4>Basic Information</h4>
<div class="flex-container">
<div class="label-pair" *ngIf="myForm && myForm.controls.dateIssued">
<label for="dateIssued">Date Issued</label>
<label for="dateIssued">Date of Determination</label>
<lib-date-picker
[control]="myForm.controls.dateIssued"
[isValidate]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h4 class="grid-section-header-title-text blue-header">Shared Data [Master]</h4>
<span class="gird-item-value">{{ (data && data._master.author) || '-' }}</span>
</div>
<div class="grid-item__row">
<label class="grid-item-name">Date Issued</label>
<label class="grid-item-name">Date of Determination</label>
<span class="gird-item-value">{{ (data && data._master.dateIssued | date: 'mediumDate') || '-' }}</span>
</div>
<div class="grid-item__row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h4>Basic Information</h4>

<section>
<h4>Issued To</h4>
<app-entity-add-edit [formGroup]="this.myForm.controls.issuedTo"></app-entity-add-edit>
<app-entity-add-edit [formGroup]="this.myForm.controls.issuedTo" entityTypeLabel="Party"></app-entity-add-edit>
</section>

<section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h4 class="grid-section-header-title-text blue-header">Shared Data [Master]</h4>
<span class="gird-item-value">{{ (data && data._master.author) || '-' }}</span>
</div>
<div class="grid-item__row">
<label class="grid-item-name">Date Issued</label>
<label class="grid-item-name">Date of Judgement</label>
<span class="gird-item-value">{{ (data && data._master.dateIssued | date: 'mediumDate') || '-' }}</span>
</div>
<div class="grid-item__row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*ngIf="mainRoute === 'mines'">
<span>
<a [ngClass]="{ active: mainRoute === 'mines' && currentMenu === 'enforcement-actions' }"
class="dropdown-btn"
class="mines-menu"
[routerLink]="['mines', 'enforcement-actions']">
<em class="material-icons mr-3 mines-menu-icon">description</em>
Enforcement Actions
</a>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Add/Edit* -->
<div class="flex-container">
<div class="label-pair">
<label for="type">Entity Type</label>
<label for="type">{{ entityTypeLabel }}</label>
<select name="type" id="type" formControlName="type" class="form-control" (change)="updateUI()">
<option *ngFor="let entityType of entityTypes" [ngValue]="entityType">
{{ entityType }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ENTITY_TYPE } from '../../models/master/common-models/entity';
})
export class EntityAddEditComponent implements OnInit, OnChanges {
@Input() formGroup: FormGroup;
@Input() entityTypeLabel = 'Entity Type';

public loading = true;

Expand Down
3 changes: 2 additions & 1 deletion api/src/models/master/administrativePenalty.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ module.exports = require('../../utils/model-schema-generator')(
sourceDateUpdated: { type: Date, default: null },
sourceSystemRef: { type: String, default: 'nrpti' },
isNrcedPublished: { type: Boolean, default: false, index: true },
isLngPublished: { type: Boolean, default: false, index: true }
isLngPublished: { type: Boolean, default: false, index: true },
isBcmiPublished: { type: Boolean, default: false, index: true }
},
'nrpti'
);
3 changes: 2 additions & 1 deletion api/src/models/master/courtConviction.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ module.exports = require('../../utils/model-schema-generator')(
sourceDateUpdated: { type: Date, default: null },
sourceSystemRef: { type: String, default: 'nrpti' },
isNrcedPublished: { type: Boolean, default: false, index: true },
isLngPublished: { type: Boolean, default: false, index: true }
isLngPublished: { type: Boolean, default: false, index: true },
isBcmiPublished: { type: Boolean, default: false, index: true }
},
'nrpti'
);