Skip to content

Commit

Permalink
Merge pull request #1976 from bcgov/bugfix/ALCS-2373
Browse files Browse the repository at this point in the history
Fix residential clearing when it remains
  • Loading branch information
trslater authored Nov 13, 2024
2 parents 5c591fc + bcfc2e1 commit b010b59
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,

this.structuresSource = new MatTableDataSource(this.proposedStructures);

if (this.hasInput(structure.type)) {
if (this.structureChangeRequiresConfirmation(structure.type, newType)) {
this.confirmationDialogService
.openDialog({
title: 'Change Structure Type',
Expand Down Expand Up @@ -455,29 +455,29 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
this.form.markAsDirty();
}

private hasInput(type: STRUCTURE_TYPES | null) {
switch (type) {
case STRUCTURE_TYPES.FARM_STRUCTURE:
return !!(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value);

case STRUCTURE_TYPES.ACCESSORY_STRUCTURE:
return !!(
this.soilStructureResidentialUseReason.value || this.soilStructureResidentialAccessoryUseReason.value
);

case STRUCTURE_TYPES.OTHER_STRUCTURE:
return !!this.soilStructureOtherUseReason.value;

case STRUCTURE_TYPES.PRINCIPAL_RESIDENCE:
case STRUCTURE_TYPES.ADDITIONAL_RESIDENCE:
return !!this.soilStructureResidentialUseReason.value;

case null:
return false;

default:
return true;
}
private structureChangeRequiresConfirmation(
oldType: STRUCTURE_TYPES | null,
newType: STRUCTURE_TYPES | null,
): boolean {
const residentialTypes = [
STRUCTURE_TYPES.PRINCIPAL_RESIDENCE,
STRUCTURE_TYPES.ADDITIONAL_RESIDENCE,
STRUCTURE_TYPES.ACCESSORY_STRUCTURE,
];
const changingFromResidentialType = oldType && residentialTypes.includes(oldType);
const changingToResidentialType = newType && residentialTypes.includes(newType);

return !!(
oldType !== newType &&
((oldType &&
oldType === STRUCTURE_TYPES.FARM_STRUCTURE &&
(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value)) ||
(changingFromResidentialType && !changingToResidentialType && this.soilStructureResidentialUseReason.value) ||
(oldType &&
oldType === STRUCTURE_TYPES.ACCESSORY_STRUCTURE &&
this.soilStructureResidentialAccessoryUseReason.value) ||
(oldType && oldType === STRUCTURE_TYPES.OTHER_STRUCTURE && this.soilStructureOtherUseReason.value))
);
}

private setStructureTypeInput(structure: FormProposedStructure, newType: STRUCTURE_TYPES) {
Expand All @@ -502,9 +502,10 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,

updateStructureTypeFields() {
// Remove

if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] === 0) {
this.soilStructureFarmUseReason.reset();
this.soilStructureFarmUseReason.removeValidators([Validators.required]);
this.soilAgriParcelActivity.reset();
this.soilAgriParcelActivity.removeValidators([Validators.required]);
}

Expand All @@ -513,24 +514,25 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
this.structureTypeCounts[STRUCTURE_TYPES.ADDITIONAL_RESIDENCE] === 0 &&
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0
) {
this.soilStructureResidentialUseReason.reset();
this.soilStructureResidentialUseReason.removeValidators([Validators.required]);
}

if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
this.soilStructureResidentialAccessoryUseReason.reset();
this.soilStructureResidentialAccessoryUseReason.removeValidators([Validators.required]);
}

if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
this.soilStructureOtherUseReason.reset();
this.soilStructureOtherUseReason.removeValidators([Validators.required]);
}

// Add

if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] > 0) {
this.soilStructureFarmUseReason.setValidators([Validators.required]);
this.soilStructureFarmUseReason.reset();
this.soilAgriParcelActivity.setValidators([Validators.required]);
this.soilAgriParcelActivity.reset();
}

if (
Expand All @@ -539,17 +541,14 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0
) {
this.soilStructureResidentialUseReason.setValidators([Validators.required]);
this.soilStructureResidentialUseReason.reset();
}

if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0) {
this.soilStructureResidentialAccessoryUseReason.setValidators([Validators.required]);
this.soilStructureResidentialAccessoryUseReason.reset();
}

if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] > 0) {
this.soilStructureOtherUseReason.setValidators([Validators.required]);
this.soilStructureOtherUseReason.reset();
}
}

Expand Down Expand Up @@ -631,8 +630,8 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
this.structuresForm.removeControl(`${id}-area`);
this.structuresForm.markAsDirty();

this.updateStructureTypeFields();
this.updateStructureCounts(structureToDelete.type, null);
this.updateStructureTypeFields();
}

onStructureEdit(id: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,

this.structuresSource = new MatTableDataSource(this.proposedStructures);

if (this.hasInput(structure.type)) {
if (this.hasInput(structure.type, newType)) {
this.confirmationDialogService
.openDialog({
title: 'Change Structure Type',
Expand Down Expand Up @@ -382,29 +382,25 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
this.form.markAsDirty();
}

private hasInput(type: STRUCTURE_TYPES | null) {
switch (type) {
case STRUCTURE_TYPES.FARM_STRUCTURE:
return !!(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value);

case STRUCTURE_TYPES.ACCESSORY_STRUCTURE:
return !!(
this.soilStructureResidentialUseReason.value || this.soilStructureResidentialAccessoryUseReason.value
);

case STRUCTURE_TYPES.OTHER_STRUCTURE:
return !!this.soilStructureOtherUseReason.value;

case STRUCTURE_TYPES.PRINCIPAL_RESIDENCE:
case STRUCTURE_TYPES.ADDITIONAL_RESIDENCE:
return !!this.soilStructureResidentialUseReason.value;

case null:
return false;

default:
return true;
}
private hasInput(oldType: STRUCTURE_TYPES | null, newType: STRUCTURE_TYPES | null) {
const residentialTypes = [
STRUCTURE_TYPES.PRINCIPAL_RESIDENCE,
STRUCTURE_TYPES.ADDITIONAL_RESIDENCE,
STRUCTURE_TYPES.ACCESSORY_STRUCTURE,
];
const changingFromResidentialType = oldType && residentialTypes.includes(oldType);
const changingToResidentialType = newType && residentialTypes.includes(newType);

return !!(
(oldType &&
oldType === STRUCTURE_TYPES.FARM_STRUCTURE &&
(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value)) ||
(changingFromResidentialType && !changingToResidentialType && this.soilStructureResidentialUseReason.value) ||
(oldType &&
oldType === STRUCTURE_TYPES.ACCESSORY_STRUCTURE &&
this.soilStructureResidentialAccessoryUseReason.value) ||
(oldType && oldType === STRUCTURE_TYPES.OTHER_STRUCTURE && this.soilStructureOtherUseReason.value)
);
}

private setStructureTypeInput(structure: FormProposedStructure, newType: STRUCTURE_TYPES) {
Expand All @@ -431,7 +427,9 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
// Remove

if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] === 0) {
this.soilStructureFarmUseReason.reset();
this.soilStructureFarmUseReason.removeValidators([Validators.required]);
this.soilAgriParcelActivity.reset();
this.soilAgriParcelActivity.removeValidators([Validators.required]);
}

Expand All @@ -440,24 +438,25 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
this.structureTypeCounts[STRUCTURE_TYPES.ADDITIONAL_RESIDENCE] === 0 &&
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0
) {
this.soilStructureResidentialUseReason.reset();
this.soilStructureResidentialUseReason.removeValidators([Validators.required]);
}

if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
this.soilStructureResidentialAccessoryUseReason.reset();
this.soilStructureResidentialAccessoryUseReason.removeValidators([Validators.required]);
}

if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
this.soilStructureOtherUseReason.reset();
this.soilStructureOtherUseReason.removeValidators([Validators.required]);
}

// Add

if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] > 0) {
this.soilStructureFarmUseReason.setValidators([Validators.required]);
this.soilStructureFarmUseReason.reset();
this.soilAgriParcelActivity.setValidators([Validators.required]);
this.soilAgriParcelActivity.reset();
}

if (
Expand All @@ -466,17 +465,14 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0
) {
this.soilStructureResidentialUseReason.setValidators([Validators.required]);
this.soilStructureResidentialUseReason.reset();
}

if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0) {
this.soilStructureResidentialAccessoryUseReason.setValidators([Validators.required]);
this.soilStructureResidentialAccessoryUseReason.reset();
}

if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] > 0) {
this.soilStructureOtherUseReason.setValidators([Validators.required]);
this.soilStructureOtherUseReason.reset();
}
}

Expand Down Expand Up @@ -558,8 +554,8 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
this.structuresForm.removeControl(`${id}-area`);
this.structuresForm.markAsDirty();

this.updateStructureTypeFields();
this.updateStructureCounts(structureToDelete.type, null);
this.updateStructureTypeFields();
}

onStructureEdit(id: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
this.structuresForm.removeControl(`${id}-area`);
this.structuresForm.markAsDirty();

this.updateStructureTypeFields();
this.updateStructureCounts(structureToDelete.type, null);
this.updateStructureTypeFields();
}

onStructureEdit(id: string) {
Expand Down Expand Up @@ -456,7 +456,7 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,

this.structuresSource = new MatTableDataSource(this.proposedStructures);

if (this.hasInput(structure.type)) {
if (this.hasInput(structure.type, newType)) {
this.confirmationDialogService
.openDialog({
title: 'Change Structure Type',
Expand Down Expand Up @@ -491,29 +491,25 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
this.form.markAsDirty();
}

private hasInput(type: STRUCTURE_TYPES | null) {
switch (type) {
case STRUCTURE_TYPES.FARM_STRUCTURE:
return !!(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value);

case STRUCTURE_TYPES.ACCESSORY_STRUCTURE:
return !!(
this.soilStructureResidentialUseReason.value || this.soilStructureResidentialAccessoryUseReason.value
);

case STRUCTURE_TYPES.OTHER_STRUCTURE:
return !!this.soilStructureOtherUseReason.value;

case STRUCTURE_TYPES.PRINCIPAL_RESIDENCE:
case STRUCTURE_TYPES.ADDITIONAL_RESIDENCE:
return !!this.soilStructureResidentialUseReason.value;

case null:
return false;

default:
return true;
}
private hasInput(oldType: STRUCTURE_TYPES | null, newType: STRUCTURE_TYPES | null) {
const residentialTypes = [
STRUCTURE_TYPES.PRINCIPAL_RESIDENCE,
STRUCTURE_TYPES.ADDITIONAL_RESIDENCE,
STRUCTURE_TYPES.ACCESSORY_STRUCTURE,
];
const changingFromResidentialType = oldType && residentialTypes.includes(oldType);
const changingToResidentialType = newType && residentialTypes.includes(newType);

return !!(
(oldType &&
oldType === STRUCTURE_TYPES.FARM_STRUCTURE &&
(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value)) ||
(changingFromResidentialType && !changingToResidentialType && this.soilStructureResidentialUseReason.value) ||
(oldType &&
oldType === STRUCTURE_TYPES.ACCESSORY_STRUCTURE &&
this.soilStructureResidentialAccessoryUseReason.value) ||
(oldType && oldType === STRUCTURE_TYPES.OTHER_STRUCTURE && this.soilStructureOtherUseReason.value)
);
}

private setStructureTypeInput(structure: FormProposedStructure, newType: STRUCTURE_TYPES) {
Expand All @@ -540,7 +536,9 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
// Remove

if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] === 0) {
this.soilStructureFarmUseReason.reset();
this.soilStructureFarmUseReason.removeValidators([Validators.required]);
this.soilAgriParcelActivity.reset();
this.soilAgriParcelActivity.removeValidators([Validators.required]);
}

Expand All @@ -549,24 +547,25 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
this.structureTypeCounts[STRUCTURE_TYPES.ADDITIONAL_RESIDENCE] === 0 &&
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0
) {
this.soilStructureResidentialUseReason.reset();
this.soilStructureResidentialUseReason.removeValidators([Validators.required]);
}

if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
this.soilStructureResidentialAccessoryUseReason.reset();
this.soilStructureResidentialAccessoryUseReason.removeValidators([Validators.required]);
}

if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
this.soilStructureOtherUseReason.reset();
this.soilStructureOtherUseReason.removeValidators([Validators.required]);
}

// Add

if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] > 0) {
this.soilStructureFarmUseReason.setValidators([Validators.required]);
this.soilStructureFarmUseReason.reset();
this.soilAgriParcelActivity.setValidators([Validators.required]);
this.soilAgriParcelActivity.reset();
}

if (
Expand All @@ -575,17 +574,14 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0
) {
this.soilStructureResidentialUseReason.setValidators([Validators.required]);
this.soilStructureResidentialUseReason.reset();
}

if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0) {
this.soilStructureResidentialAccessoryUseReason.setValidators([Validators.required]);
this.soilStructureResidentialAccessoryUseReason.reset();
}

if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] > 0) {
this.soilStructureOtherUseReason.setValidators([Validators.required]);
this.soilStructureOtherUseReason.reset();
}
}

Expand Down

0 comments on commit b010b59

Please sign in to comment.