Skip to content

Commit

Permalink
Merge pull request #2007 from bcgov/feature/ALCS-2404
Browse files Browse the repository at this point in the history
Block the User from Entering the Code that is Already Taken
  • Loading branch information
Abradat authored Dec 11, 2024
2 parents 4c96f27 + d014100 commit 6f904c8
Show file tree
Hide file tree
Showing 37 changed files with 271 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Board</h4>
<mat-label>Code</mat-label>
<input [formControl]="code" required maxlength="4" minlength="4" matInput id="code" name="code" />
</mat-form-field>
<div *ngIf="form.get('code')?.hasError('codeExists')">
<app-error-message message="Code already in use, pick a different code."></app-error-message>
</div>
</div>

<div class="full-width">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { Component, Inject, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { FormBuilder, FormControl, FormGroup, NgModel, Validators } from '@angular/forms';
import { MatCheckboxChange } from '@angular/material/checkbox';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { AdminBoardManagementService } from '../../../../services/admin-board-management/admin-board-management.service';
Expand All @@ -10,6 +10,7 @@ import { BoardService } from '../../../../services/board/board.service';
import { CardStatusService } from '../../../../services/card/card-status/card-status.service';
import { CardType } from '../../../../shared/card/card.component';
import { BaseCodeDto } from '../../../../shared/dto/base.dto';
import { codeExistsValidator } from '../../../../shared/validators/code-exists-validator';

const DISABLED_CREATE_CARD_TYPES = [
CardType.APP,
Expand Down Expand Up @@ -60,6 +61,7 @@ export class BoardManagementDialogComponent implements OnInit {
public data: {
board: MinimalBoardDto | undefined;
cardTypes: BaseCodeDto[];
existingCodes: string[];
},
private dialogRef: MatDialogRef<BoardManagementDialogComponent>,
private cardStatusService: CardStatusService,
Expand All @@ -76,6 +78,8 @@ export class BoardManagementDialogComponent implements OnInit {
for (const type of this.cardTypes) {
this.cardTypeMap[type.code] = type.label;
}

this.code.addValidators(codeExistsValidator(this.data?.existingCodes ? this.data.existingCodes : []));
}

async loadBoard(code: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class BoardManagementComponent implements OnInit, OnDestroy {
height: '80%',
data: {
cardTypes: this.cardTypes,
existingCodes: this.boards.map((b) => b.code.toLowerCase()),
},
});
dialog.beforeClosed().subscribe(async (result) => {
Expand All @@ -62,6 +63,7 @@ export class BoardManagementComponent implements OnInit, OnDestroy {
data: {
board: boardDto,
cardTypes: this.cardTypes,
existingCodes: this.boards.map((b) => b.code.toLowerCase()),
},
});
dialog.beforeClosed().subscribe(async (result) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Column</h4>
matInput
id="code"
[(ngModel)]="code"
#codeModel="ngModel"
name="code"
/>
</mat-form-field>
</div>

<div *ngIf="isCodeExisiting(codeModel) && !isEdit" class="full-width code-error-message">
<app-error-message message="Code already in use, pick a different code."></app-error-message>
</div>
<div>
<mat-form-field class="label" appearance="outline">
<mat-label>Label</mat-label>
Expand All @@ -37,7 +40,7 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Column</h4>

<div class="split">
<div [matTooltip]="canDeleteReason" [matTooltipDisabled]="canDelete">
<button [disabled]="!canDelete" (click)='onDelete()' mat-stroked-button color="warn">Delete</button>
<button [disabled]="!canDelete" (click)="onDelete()" mat-stroked-button color="warn">Delete</button>
</div>
<div class="button-container">
<button mat-stroked-button color="primary" mat-dialog-close="false">Close</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
.mat-mdc-form-field {
width: 100%;
}

.code-error-message {
margin: -20px 0 -20px 0;
}

.code {
padding-top: 8px;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('CardStatusDialogComponent', () => {
imports: [ReactiveFormsModule, FormsModule],
declarations: [CardStatusDialogComponent],
providers: [
{ provide: MAT_DIALOG_DATA, useValue: undefined },
{ provide: MAT_DIALOG_DATA, useValue: { existingCodes: [] } },
{ provide: MatDialogRef, useValue: {} },
{
provide: CardStatusService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { CardStatusDto } from '../../../../services/application/application-code.dto';
import { CardStatusService } from '../../../../services/card/card-status/card-status.service';
import { NgModel } from '@angular/forms';
import { codeExistsDirectiveValidator } from '../../../../shared/validators/code-exists-validator';

@Component({
selector: 'app-decision-condition-types-dialog',
Expand All @@ -19,16 +21,20 @@ export class CardStatusDialogComponent implements OnInit {
canDeleteReason = '';

constructor(
@Inject(MAT_DIALOG_DATA) public data: CardStatusDto | undefined,
@Inject(MAT_DIALOG_DATA)
public data: {
cardStatus: CardStatusDto | undefined;
existingCodes: string[];
},
private dialogRef: MatDialogRef<CardStatusDialogComponent>,
private cardStatusService: CardStatusService
private cardStatusService: CardStatusService,
) {
if (data) {
this.description = data.description;
this.label = data.label;
this.code = data.code;
if (data.cardStatus) {
this.description = data.cardStatus.description;
this.label = data.cardStatus.label;
this.code = data.cardStatus.code;
}
this.isEdit = !!data;
this.isEdit = !!data.cardStatus;
}

async onSubmit() {
Expand Down Expand Up @@ -65,4 +71,8 @@ export class CardStatusDialogComponent implements OnInit {
await this.cardStatusService.delete(this.code);
this.dialogRef.close(true);
}

isCodeExisiting(model: NgModel) {
return codeExistsDirectiveValidator(model, this.data.existingCodes, this.code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CardStatusComponent implements OnInit {
constructor(
private cardStatusService: CardStatusService,
public dialog: MatDialog,
private confirmationDialogService: ConfirmationDialogService
private confirmationDialogService: ConfirmationDialogService,
) {}

ngOnInit(): void {
Expand All @@ -34,6 +34,7 @@ export class CardStatusComponent implements OnInit {
minWidth: '600px',
maxWidth: '800px',
width: '70%',
data: { existingCodes: this.cardStatusDtos.map((cs) => cs.code.toLowerCase()) },
});
dialog.beforeClosed().subscribe(async (result) => {
if (result) {
Expand All @@ -47,7 +48,7 @@ export class CardStatusComponent implements OnInit {
minWidth: '600px',
maxWidth: '800px',
width: '70%',
data: cardStatusDto,
data: { cardStatus: cardStatusDto, existingCodes: this.cardStatusDtos.map((cs) => cs.code.toLowerCase()) },
});
dialog.beforeClosed().subscribe(async (result) => {
if (result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} CEO Criterion</h4>
matInput
id="code"
[(ngModel)]="code"
#codeModel="ngModel"
name="code"
/>
</mat-form-field>
<div *ngIf="isCodeExisting(codeModel) && !isEdit">
<app-error-message message="Code already in use or deteled, pick a different code."></app-error-message>
</div>
</div>

<div class="full-width">
Expand All @@ -50,7 +54,7 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} CEO Criterion</h4>
mat-flat-button
color="primary"
type="submit"
[disabled]="!form.form.valid"
[disabled]="!form.form.valid || (isCodeExisting(codeModel) && !isEdit)"
>
Save
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
.mat-mdc-form-field {
width: 100%;
}

.code {
padding-top: 8px;
}

.number-input {
padding-top: 8px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('CeoCriterionDialogComponent', () => {
imports: [ReactiveFormsModule, FormsModule],
declarations: [CeoCriterionDialogComponent],
providers: [
{ provide: MAT_DIALOG_DATA, useValue: undefined },
{ provide: MAT_DIALOG_DATA, useValue: { existingCodes: [] } },
{ provide: MatDialogRef, useValue: {} },
{
provide: CeoCriterionService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { CeoCriterionDto } from '../../../../services/application/decision/application-decision-v2/application-decision.dto';
import { CeoCriterionService } from '../../../../services/ceo-criterion/ceo-criterion.service';
import { NgModel } from '@angular/forms';
import { CeoCriterionDto } from '../../../../services/application/decision/application-decision-v2/application-decision.dto';
import { codeExistsDirectiveValidator } from '../../../../shared/validators/code-exists-validator';

@Component({
selector: 'app-ceo-criterion-dialog',
Expand All @@ -18,17 +20,21 @@ export class CeoCriterionDialogComponent {
isEdit = false;

constructor(
@Inject(MAT_DIALOG_DATA) public data: CeoCriterionDto | undefined,
@Inject(MAT_DIALOG_DATA)
public data: {
ceoCriterion: CeoCriterionDto | undefined;
existingCodes: string[];
},
private dialogRef: MatDialogRef<CeoCriterionDialogComponent>,
private ceoCriterionService: CeoCriterionService,
) {
if (data) {
this.description = data.description;
this.label = data.label;
this.code = data.code;
this.number = data.number.toString();
if (data?.ceoCriterion) {
this.description = data.ceoCriterion.description;
this.label = data.ceoCriterion.label;
this.code = data.ceoCriterion.code;
this.number = data.ceoCriterion.number.toString();
}
this.isEdit = !!data;
this.isEdit = !!data?.ceoCriterion;
}

async onSubmit() {
Expand All @@ -53,4 +59,8 @@ export class CeoCriterionDialogComponent {
this.isLoading = false;
this.dialogRef.close(true);
}

isCodeExisting(model: NgModel) {
return codeExistsDirectiveValidator(model, this.data.existingCodes, this.code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class CeoCriterionComponent implements OnInit {
minWidth: '600px',
maxWidth: '800px',
width: '70%',
data: {
existingCodes: this.ceoCriterion.map((cc) => cc.code.toLocaleLowerCase()),
},
});
dialog.beforeClosed().subscribe(async (result) => {
if (result) {
Expand All @@ -49,7 +52,7 @@ export class CeoCriterionComponent implements OnInit {
minWidth: '600px',
maxWidth: '800px',
width: '70%',
data: ceoCriterion,
data: { ceoCriterion: ceoCriterion, existingCodes: this.ceoCriterion.map((cc) => cc.code) },
});
dialog.beforeClosed().subscribe(async (result) => {
if (result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Decision Condition Type</h4>
<mat-label>Code</mat-label>
<input required maxlength="4" minlength="4" matInput id="code" formControlName="code" name="code" />
</mat-form-field>
<div *ngIf="conditionTypeForm.get('code')?.hasError('codeExists')">
<app-error-message message="Code already in use or deteled, pick a different code."></app-error-message>
</div>
</div>

<div class="full-width">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ApplicationDecisionConditionTypesService } from '../../../../services/a
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { DecisionDialogDataInterface } from '../decision-dialog-data.interface';
import { NoticeofIntentDecisionConditionTypesService } from '../../../../services/notice-of-intent/notice-of-intent-decision-condition-types/notice-of-intent-decision-condition-types.service';
import { codeExistsValidator } from '../../../../shared/validators/code-exists-validator';

@Component({
selector: 'app-decision-condition-types-dialog',
Expand All @@ -34,7 +35,10 @@ export class DecisionConditionTypesDialogComponent {
Validators.required,
]),
label: new FormControl(this.data?.content?.label ? this.data.content.label : '', [Validators.required]),
code: new FormControl(this.data?.content?.code ? this.data.content.code : '', [Validators.required]),
code: new FormControl(this.data?.content?.code ? this.data.content.code : '', [
Validators.required,
codeExistsValidator(this.data?.existingCodes ? this.data.existingCodes : []),
]),
isActive: new FormControl<boolean>(this.data && this.data.content ? this.data.content.isActive : true, [
Validators.required,
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class DecisionConditionTypesComponent implements OnInit {
width: '70%',
data: {
service: this.service,
existingCodes: this.decisionConditionTypeDtos.map((dct) => dct.code),
},
});
dialog.beforeClosed().subscribe(async (result) => {
Expand All @@ -62,6 +63,7 @@ export class DecisionConditionTypesComponent implements OnInit {
data: {
service: this.service,
content: dto,
existingCodes: this.decisionConditionTypeDtos.map((dct) => dct.code),
},
});
dialog.beforeClosed().subscribe(async (result) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { NoticeofIntentDecisionConditionTypesService } from "../../../services/notice-of-intent/notice-of-intent-decision-condition-types/notice-of-intent-decision-condition-types.service";
import { ApplicationDecisionConditionTypesService } from "../../../services/application/application-decision-condition-types/application-decision-condition-types.service";
import { ApplicationDecisionConditionTypeDto } from "../../../services/application/decision/application-decision-v2/application-decision-v2.dto";
import { NoticeofIntentDecisionConditionTypesService } from '../../../services/notice-of-intent/notice-of-intent-decision-condition-types/notice-of-intent-decision-condition-types.service';
import { ApplicationDecisionConditionTypesService } from '../../../services/application/application-decision-condition-types/application-decision-condition-types.service';
import { ApplicationDecisionConditionTypeDto } from '../../../services/application/decision/application-decision-v2/application-decision-v2.dto';

export interface DecisionDialogDataInterface {
service: ApplicationDecisionConditionTypesService | NoticeofIntentDecisionConditionTypesService;
content: ApplicationDecisionConditionTypeDto;
existingCodes: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Decision Maker</h4>
matInput
id="code"
[(ngModel)]="code"
#codeModel="ngModel"
name="code"
/>
</mat-form-field>
</div>

<div *ngIf="isCodeExisiting(codeModel) && !isEdit" class="full-width code-error-message">
<app-error-message message="Code already in use or deteled, pick a different code."></app-error-message>
</div>
<div class="full-width">
<mat-form-field class="label" appearance="outline">
<mat-label>Label</mat-label>
Expand Down Expand Up @@ -51,7 +54,7 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Decision Maker</h4>
mat-flat-button
color="primary"
type="submit"
[disabled]="!form.form.valid"
[disabled]="!form.form.valid || (isCodeExisiting(codeModel) && !isEdit)"
>
Save
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
.mat-mdc-form-field {
width: 100%;
}

.code-error-message {
margin: -20px 0 -20px 0;
}

.code {
padding-top: 8px;
}
}
}
Loading

0 comments on commit 6f904c8

Please sign in to comment.