Prevent accidental overwrite

This commit is contained in:
Zakary Timson 2019-02-06 21:53:35 -05:00
parent bff7ad6c2c
commit 61a5026dd2
2 changed files with 11 additions and 3 deletions

View File

@ -1,7 +1,8 @@
<mat-dialog-content>
<div class="mb-5">
<mat-form-field class="d-inline">
<input matInput placeholder="Formula Name" name="name" [(ngModel)]="name">
<input matInput placeholder="Formula Name" name="name" [(ngModel)]="name" (keyup)="checkExists($event.target.value)">
<mat-hint *ngIf="exists" class="text-danger">This formula already exists</mat-hint>
</mat-form-field>
<div class="text-right">
<mat-checkbox [(ngModel)]="approved">Approved</mat-checkbox>
@ -38,13 +39,13 @@
<div class="px-2">{{c.quantity | convertFromG: unit}} {{unit}}</div>
</div>
</div>
<div class="text-right m-2">
<div class="text-right m-2 mb-5">
<strong>Total Yield: </strong>{{total() | convertFromG: unit}} {{unit}}
</div>
</mat-dialog-content>
<mat-divider></mat-divider>
<mat-dialog-actions class="justify-content-end">
<button mat-button type="submit" form="createForm" (click)="submit()" [disabled]="components.length < 1 || !name">
<button mat-button type="submit" form="createForm" (click)="submit()" [disabled]="components.length < 1 || !name || exists">
<span *ngIf="data">Update</span>
<span *ngIf="!data">Create</span>
</button>

View File

@ -16,6 +16,7 @@ export class NewFormulaComponent {
component: string;
components: { component: Component; quantity: number }[] = [];
componentsList = [];
exists: boolean = false;
@LocalStorage({ defaultValue: 'kg', fieldName: 'newFormulaUnit' })
unit;
@ -42,6 +43,12 @@ export class NewFormulaComponent {
this.amount = null;
}
checkExists(name) {
this.store.formulas.subscribe(formulas => {
this.exists = !!formulas.find(f => f.id == name)
});
}
remove(i) {
this.components.splice(i, 1);
}