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

NOBUG fixing legislation autopopulate in record add/edit #891

Merged
merged 1 commit into from
Jul 27, 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 @@ -94,6 +94,7 @@ <h4>Contravention</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="true"
[recordType]="'AdministrativePenalty'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ <h4>Contravention</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="true"
[recordType]="'CourtConviction'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ <h4>Contravention</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="true"
[recordType]="'AdministrativePenalty'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'AdministrativeSanction'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'AnnualReport'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'CertificateAmendment'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'Certificate'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'Correspondence'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ <h4>Contravention</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="true"
[recordType]="'CourtConviction'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'DamSafetyInspection'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'Inspection'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'Order'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'Permit'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'Report'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h4>Contravention</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="true"
[recordType]="'RestorativeJustice'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'SelfReport'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h4>Contravention</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="true"
[recordType]="'Ticket'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h4>Legislation</h4>
[formArray]="this.myForm.controls.legislations"
[sourceSystemRef]="this.currentRecord && this.currentRecord.sourceSystemRef"
[hasOffence]="false"
[recordType]="'Warning'"
></app-legislation-list-add-edit>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Utils } from 'nrpti-angular-components';
export class LegislationAddEditComponent implements OnInit {
@Input() formGroup: FormGroup;
@Input() hasOffence: boolean;
@Input() recordType: string;

@Input() hideSection = false;
@Input() hideSubSection = false;
Expand Down Expand Up @@ -43,7 +44,7 @@ export class LegislationAddEditComponent implements OnInit {
constructor(
public utils: Utils,
protected _changeDetectionRef: ChangeDetectorRef
) {}
) { }

ngOnInit(): void {
if (this.formGroup.controls.act.value && this.formGroup.controls.regulation.value) {
Expand Down Expand Up @@ -94,14 +95,14 @@ export class LegislationAddEditComponent implements OnInit {
paragraph: this.formGroup.get('paragraph').value
});

if ( this.hasOffence ) {
if (this.hasOffence) {
this.formGroup.get('offence').setValue(
Picklists.getLegislationDescription('AdministrativePenalty', legislation)
Picklists.getLegislationDescription(this.recordType, legislation)
);
this.formGroup.get('offence').markAsDirty();
} else {
this.formGroup.get('legislationDescription').setValue(
Picklists.getLegislationDescription('AdministrativePenalty', legislation)
Picklists.getLegislationDescription(this.recordType, legislation)
);
this.formGroup.get('legislationDescription').markAsDirty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<app-legislation-add-edit
[formGroup]="formGroup"
[hasOffence]="hasOffence"
[recordType]="recordType"
></app-legislation-add-edit>
<button *ngIf="sourceSystemRef==='nrpti' && idx !== 0 && hasOffence" class="btn btn-outline-primary delete-btn" type="button" title="Delete this contravention" (click)="removeLegislation(idx)">
<i class="material-icons"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class LegislationListAddEditComponent implements OnInit {
@Input() formArray: FormArray;
@Input() sourceSystemRef: string;
@Input() hasOffence: boolean;
@Input() recordType: string;

ngOnInit(): void {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { FactoryService } from '../../../../admin-nrpti/src/app/services/factory.service';
import { StoreService} from 'nrpti-angular-components';
import { StoreService } from 'nrpti-angular-components';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { Utils } from 'nrpti-angular-components';
Expand Down Expand Up @@ -33,7 +33,7 @@ export class RecordAssociationEditComponent implements OnInit {
public factoryService: FactoryService,
private storeService: StoreService,
private utils: Utils
) {}
) { }

ngOnInit() {
this.storeService.stateChange.subscribe((state: object) => {
Expand All @@ -49,7 +49,7 @@ export class RecordAssociationEditComponent implements OnInit {
});
this.updateMineMeta();
this.subscribeToFormControlChanges();
}
}

private subscribeToFormControlChanges() {
const debouncedMineMeta = this.utils.debounced(500, () => this.updateMineMeta());
Expand All @@ -64,11 +64,15 @@ export class RecordAssociationEditComponent implements OnInit {
private updateMineMeta() {
const mineGuid = this.formGroup.get('mineGuid').value;
const unlistedMineType = this.formGroup.get('unlistedMineType').value;
let mine = null;

const mine = this.mines.filter( elem => {
if (elem._sourceRefId === mineGuid ) {
return elem;
} });
if (this.mines) {
mine = this.mines.filter(elem => {
if (elem._sourceRefId === mineGuid) {
return elem;
}
});
}

if (!mineGuid && !unlistedMineType) {
this.mineType = '';
Expand Down
21 changes: 11 additions & 10 deletions angular/projects/common/src/app/utils/record-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ export class Picklists {
* @memberof Picklists
* @returns {string[]} sorted array of acts
*/
public static getAllActs = function(): string[] {
public static getAllActs = function (): string[] {
return Object.keys(this.legislationActsMappedToRegulations).sort();
};

Expand All @@ -810,7 +810,7 @@ export class Picklists {
* @memberof Picklists
* @returns {string[]} sorted array of regulations
*/
public static getAllRegulations = function(): string[] {
public static getAllRegulations = function (): string[] {
const regulations = [];

Object.keys(this.legislationActsMappedToRegulations).forEach(act =>
Expand All @@ -834,7 +834,7 @@ export class Picklists {
* @memberof Picklists
* @returns {{ [key: string]: string[] }}
*/
public static getLegislationRegulationsMappedToActs = function(): { [key: string]: string[] } {
public static getLegislationRegulationsMappedToActs = function (): { [key: string]: string[] } {
const regulations = {};

Object.keys(this.legislationActsMappedToRegulations).forEach(act =>
Expand Down Expand Up @@ -2561,16 +2561,16 @@ export class Picklists {
description: 'Fail to implement a food safety plan'
},
c: {
description: 'Fail to keep records of monitoring activities or corrective actions'
description: 'Fail to keep records of monitoring activities or corrective actions'
},
d: {
description: 'Fail to keep food safety plan in a conspicuous location'
description: 'Fail to keep food safety plan in a conspicuous location'
},
e: {
description: 'Fail to make food safety plan available'
description: 'Fail to make food safety plan available'
},
f: {
description: 'Fail to review food safety plan annually or if required'
description: 'Fail to review food safety plan annually or if required'
},
},
'3': {
Expand Down Expand Up @@ -5119,8 +5119,9 @@ export class Picklists {
* @static
* @returns {string} legislation description or null
*/
public static getLegislationDescription = function(recordType: string, legislation: Legislation): string {
if (!recordType || !legislation || !legislation.act || !legislation.section) {
public static getLegislationDescription = function (recordType: string, legislation: Legislation): string {

if (!recordType || (!legislation && !legislation.act && !legislation.section)) {
return null;
}

Expand Down Expand Up @@ -5174,7 +5175,7 @@ export class Picklists {
* @param {string[]} paths properties to descend, in order, through the object.
* @returns the value found at the end of the path, or null
*/
public static traverseObject = function(obj: object, paths: string[]) {
public static traverseObject = function (obj: object, paths: string[]) {
if (!obj || !paths || !paths.length) {
return null;
}
Expand Down