Merge branch '2-creer-un-systeme-de-gestion-des-erreurs-centralise-dans-le-frontend-angular' into 'master'

Resolve "Créer un système de gestion des erreurs centralisé dans le frontend Angular"

Closes #2

See merge request color-recipes-explorer/frontend!5
This commit is contained in:
William Nolin 2021-03-09 21:16:35 +00:00
commit 267bf28065
3 changed files with 9 additions and 4 deletions

View File

@ -46,8 +46,8 @@
<th mat-header-cell *matHeaderCellDef>Produit</th>
<td mat-cell *matCellDef="let mixMaterial">
<mat-form-field *ngIf="materials">
<mat-select [(ngModel)]="mixMaterial.materialId">
<mat-option *ngFor="let material of materials"
<mat-select #select [(ngModel)]="mixMaterial.materialId" [value]="mixMaterial.materialId">
<mat-option *ngFor="let material of getAvailableMaterials(select)"
[value]="material.id">{{material.name}}</mat-option>
</mat-select>
</mat-form-field>
@ -99,7 +99,7 @@
</ng-template>
<cre-confirm-box
*ngIf="editionMode"
*ngIf="editionMode && mix"
#deleteConfirmBox
message="Voulez-vous vraiment supprimer le mélange {{mix.mixType.name}} de la recette {{recipe.company.name}} - {{recipe.name}}"
(confirm)="delete()">

View File

@ -16,6 +16,7 @@ import {ConfirmBoxComponent} from '../../../shared/components/confirm-box/confir
import {AccountService} from '../../../accounts/services/account.service'
import {EmployeePermission} from '../../../shared/model/employee'
import {ErrorService} from '../../../shared/service/error.service'
import {MatSelect} from '@angular/material/select'
@Component({
selector: 'cre-mix-editor',
@ -131,6 +132,10 @@ export class MixEditorComponent extends SubscribingComponent {
return id ? this.materials.filter(m => m.id === id)[0] : null
}
getAvailableMaterials(selector: MatSelect): Material[] {
return this.materials.filter(m => selector.value === m.id || this.mixMaterials.filter(mm => mm.materialId === m.id).length === 0)
}
get canDeleteMix() {
return this.accountService.hasPermission(EmployeePermission.REMOVE_RECIPE)
}

View File

@ -97,7 +97,7 @@ export class EditComponent extends ErrorHandlingComponent {
}
get idControl(): FormControl {
this._idControl = this.lazyControl(this._idControl, () => new FormControl(this.employee.id, Validators.compose([Validators.required, Validators.pattern(new RegExp('^[0-9]+$')), Validators.min(0)])))
this._idControl = this.lazyControl(this._idControl, () => new FormControl({value: this.employee.id, disabled: true}, Validators.compose([Validators.required, Validators.pattern(new RegExp('^[0-9]+$')), Validators.min(0)])))
return this._idControl
}