Skip to content

Commit

Permalink
NRPT-813 fixing error preventing record add/edit (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronpettit authored Aug 24, 2021
1 parent a372cb4 commit 5c82e51
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,9 @@ export class AdministrativePenaltyAddEditComponent implements OnInit, OnDestroy
}

this.myForm.controls.location.dirty && (administrativePenalty['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
administrativePenalty['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(administrativePenalty['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!administrativePenalty['centroid'][0] || !administrativePenalty['centroid'][1]) {
administrativePenalty['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,12 @@ export class AdministrativeSanctionAddEditComponent implements OnInit, OnDestroy
}

this.myForm.controls.location.dirty && (administrativeSanction['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
administrativeSanction['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(administrativeSanction['centroid'] = [
this.myForm.controls.longitude.value,
this.myForm.controls.latitude.value
]);

// Properly unset centroid if lon/lat are deleted
if (!administrativeSanction['centroid'][0] || !administrativeSanction['centroid'][1]) {
administrativeSanction['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class AnnualReportAddEditComponent implements OnInit, OnDestroy {
* @returns {FormGroup[]} array of legislations FormGroup elements
* @memberof AnnualReportAddEditComponent
*/
getLegislationsFormGroups(): FormGroup[] {
getLegislationsFormGroups(): FormGroup[] {
if (!this.currentRecord || !this.currentRecord.legislation || !this.currentRecord.legislation.length) {
return [];
}
Expand Down Expand Up @@ -248,7 +248,7 @@ export class AnnualReportAddEditComponent implements OnInit, OnDestroy {
* @returns {object[]} array of legislations objects
* @memberof AnnualReportAddEditComponent
*/
parseLegislationsFormGroups(): object[] {
parseLegislationsFormGroups(): object[] {
const legislationsFormArray = this.myForm.get('legislations');

if (!legislationsFormArray || !legislationsFormArray.value || !legislationsFormArray.value.length) {
Expand Down Expand Up @@ -328,12 +328,9 @@ export class AnnualReportAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (annualReport['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
annualReport['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(annualReport['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!annualReport['centroid'][0] || !annualReport['centroid'][1]) {
annualReport['centroid'] = [];
}

// BCMI flavour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,9 @@ export class CertificateAmendmentAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (certificateAmendment['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
certificateAmendment['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(certificateAmendment['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!certificateAmendment['centroid'][0] || !certificateAmendment['centroid'][1]) {
certificateAmendment['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,9 @@ export class CertificateAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (certificate['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
certificate['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(certificate['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!certificate['centroid'][0] || !certificate['centroid'][1]) {
certificate['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ConstructionPlanAddEditComponent implements OnInit, OnDestroy {
private loadingScreenService: LoadingScreenService,
private utils: Utils,
private _changeDetectionRef: ChangeDetectorRef
) {}
) { }

ngOnInit() {
this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res: any) => {
Expand Down Expand Up @@ -211,12 +211,9 @@ export class ConstructionPlanAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (constructionPlan['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
constructionPlan['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(constructionPlan['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!constructionPlan['centroid'][0] || !constructionPlan['centroid'][1]) {
constructionPlan['centroid'] = [];
}

// LNG flavour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit, ChangeDetectorRef, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { FormGroup, FormControl, FormArray} from '@angular/forms';
import { FormGroup, FormControl, FormArray } from '@angular/forms';
import { Picklists, EpicProjectIds } from '../../../../../../common/src/app/utils/record-constants';
import { FactoryService } from '../../../services/factory.service';
import { Utils } from 'nrpti-angular-components';
Expand Down Expand Up @@ -367,12 +367,9 @@ export class CorrespondenceAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (correspondence['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
correspondence['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(correspondence['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!correspondence['centroid'][0] || !correspondence['centroid'][1]) {
correspondence['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CourtConvictionAddEditComponent implements OnInit, OnDestroy {
protected _changeDetectionRef: ChangeDetectorRef,
// @ts-ignore used by record-association component
protected storeService: StoreService
) {}
) { }

ngOnInit() {
this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res: any) => {
Expand Down Expand Up @@ -516,12 +516,9 @@ export class CourtConvictionAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (courtConviction['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
courtConviction['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(courtConviction['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!courtConviction['centroid'][0] || !courtConviction['centroid'][1]) {
courtConviction['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,9 @@ export class DamSafetyInspectionAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (damSafetyInspection['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
damSafetyInspection['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(damSafetyInspection['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!damSafetyInspection['centroid'][0] || !damSafetyInspection['centroid'][1]) {
damSafetyInspection['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class InspectionAddEditComponent implements OnInit, OnDestroy {
((this.nrcedFlavour && this.nrcedFlavour.summary) ||
(!this.nrcedFlavour && this.currentRecord.description))) ||
'',
disabled: !this.factoryService.isFlavourEditEnabled(flavourEditRequiredRoles.NRCED)
disabled: !this.factoryService.isFlavourEditEnabled(flavourEditRequiredRoles.NRCED)
}),
publishNrced: new FormControl({
value: (this.currentRecord && this.nrcedFlavour && this.nrcedFlavour.read.includes('public')) || false,
Expand All @@ -227,7 +227,7 @@ export class InspectionAddEditComponent implements OnInit, OnDestroy {
lngDescription: new FormControl({
value: (this.currentRecord &&
((this.lngFlavour && this.lngFlavour.description) || (!this.lngFlavour && this.currentRecord.description))) ||
'',
'',
disabled: !this.factoryService.isFlavourEditEnabled(flavourEditRequiredRoles.LNG)
}),
publishLng: new FormControl({
Expand Down Expand Up @@ -398,12 +398,9 @@ export class InspectionAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (inspection['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
inspection['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(inspection['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!inspection['centroid'][0] || !inspection['centroid'][1]) {
inspection['centroid'] = [];
}

this.myForm.controls.outcomeStatus.dirty &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ManagementPlanAddEditComponent implements OnInit, OnDestroy {
private loadingScreenService: LoadingScreenService,
private utils: Utils,
private _changeDetectionRef: ChangeDetectorRef
) {}
) { }

ngOnInit() {
this.route.data.pipe(takeUntil(this.ngUnsubscribe)).subscribe((res: any) => {
Expand Down Expand Up @@ -146,7 +146,7 @@ export class ManagementPlanAddEditComponent implements OnInit, OnDestroy {
// default to using the master description if the flavour record does not exist
(this.currentRecord &&
((this.lngFlavour && this.lngFlavour.description) || (!this.lngFlavour && this.currentRecord.description))) ||
''
''
),
publishLng: new FormControl({
value: (this.currentRecord && this.lngFlavour && this.lngFlavour.read.includes('public')) || false,
Expand Down Expand Up @@ -212,12 +212,9 @@ export class ManagementPlanAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (managementPlan['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
managementPlan['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(managementPlan['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!managementPlan['centroid'][0] || !managementPlan['centroid'][1]) {
managementPlan['centroid'] = [];
}

// LNG flavour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class OrderAddEditComponent implements OnInit, OnDestroy {
((this.nrcedFlavour && this.nrcedFlavour.summary) ||
(!this.nrcedFlavour && this.currentRecord.description))) ||
'',
disabled: !this.factoryService.isFlavourEditEnabled(flavourEditRequiredRoles.NRCED)
disabled: !this.factoryService.isFlavourEditEnabled(flavourEditRequiredRoles.NRCED)
}),
publishNrced: new FormControl({
value: (this.currentRecord && this.nrcedFlavour && this.nrcedFlavour.read.includes('public')) || false,
Expand Down Expand Up @@ -406,12 +406,9 @@ export class OrderAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (order['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
order['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(order['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!order['centroid'][0] || !order['centroid'][1]) {
order['centroid'] = [];
}

this.myForm.controls.outcomeStatus.dirty && (order['outcomeStatus'] = this.myForm.controls.outcomeStatus.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,9 @@ export class PermitAddEditComponent implements OnInit, OnDestroy {
(permit['issuingAgency'] = this.myForm.controls.issuingAgency.value);

this.myForm.controls.location.dirty && (permit['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
permit['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(permit['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!permit['centroid'][0] || !permit['centroid'][1]) {
permit['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class ReportAddEditComponent implements OnInit, OnDestroy {
* @returns {FormGroup[]} array of legislations FormGroup elements
* @memberof ReportAddEditComponent
*/
getLegislationsFormGroups(): FormGroup[] {
getLegislationsFormGroups(): FormGroup[] {
if (!this.currentRecord || !this.currentRecord.legislation || !this.currentRecord.legislation.length) {
return [];
}
Expand Down Expand Up @@ -369,12 +369,9 @@ export class ReportAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (report['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
report['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(report['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!report['centroid'][0] || !report['centroid'][1]) {
report['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,10 @@ export class RestorativeJusticeAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (restorativeJustice['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
restorativeJustice['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(restorativeJustice['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!restorativeJustice['centroid'][0] || !restorativeJustice['centroid'][1]) {
restorativeJustice['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
this.myForm.get('legislations').dirty && (restorativeJustice['legislation'] = this.parseLegislationsFormGroups());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,9 @@ export class SelfReportAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (selfReport['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
selfReport['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(selfReport['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!selfReport['centroid'][0] || !selfReport['centroid'][1]) {
selfReport['centroid'] = [];
}

// LNG flavour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,9 @@ export class TicketAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (ticket['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
ticket['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(ticket['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!ticket['centroid'][0] || !ticket['centroid'][1]) {
ticket['centroid'] = [];
}

// tslint:disable-next-line:max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,9 @@ export class WarningAddEditComponent implements OnInit, OnDestroy {
}

this.myForm.controls.location.dirty && (warning['location'] = this.myForm.controls.location.value);
(this.myForm.controls.latitude.dirty || this.myForm.controls.longitude.dirty) &&
warning['centroid'] = [];
if (this.myForm.controls.latitude.value && this.myForm.controls.longitude.value) {
(warning['centroid'] = [this.myForm.controls.longitude.value, this.myForm.controls.latitude.value]);

// Properly unset centroid if lon/lat are deleted
if (!warning['centroid'][0] || !warning['centroid'][1]) {
warning['centroid'] = [];
}

this.myForm.controls.outcomeStatus.dirty && (warning['outcomeStatus'] = this.myForm.controls.outcomeStatus.value);
Expand Down

0 comments on commit 5c82e51

Please sign in to comment.