diff --git a/src/app/form/structure-form/form.component.html b/src/app/form/structure-form/form.component.html index 5708572035137182328d49b6c83d14bb02c5002c..e4083fe484581cf696eabb9653ec2da47d968caf 100644 --- a/src/app/form/structure-form/form.component.html +++ b/src/app/form/structure-form/form.component.html @@ -957,7 +957,14 @@ fxLayoutAlign=" center" (click)="toggleEquipmentsServices(equipment)" > - <div class="titleCollapse">{{ equipment.module.text }}</div> + <div class="titleCollapse"> + <p [ngClass]="{ show: equipment.openned, hide: !equipment.openned }" class="no-margin"> + Ajouter des {{ equipment.module.text | lowercase }} + </p> + <p [ngClass]="{ show: !equipment.openned, hide: equipment.openned }" class="no-margin"> + Retirer les {{ equipment.module.text | lowercase }} + </p> + </div> <div class="logo"> <svg class="show" aria-hidden="true"> <use [attr.xlink:href]="'assets/form/sprite.svg#show'"></use> @@ -976,6 +983,7 @@ type="number" (input)="setValidationsForm()" formControlName="nbComputers" + min="0" class="form-input nbEquipment" /> <app-svg-icon @@ -998,6 +1006,7 @@ type="number" (input)="setValidationsForm()" formControlName="nbTablets" + min="0" class="form-input nbEquipment" /> <app-svg-icon @@ -1020,6 +1029,7 @@ type="number" (input)="setValidationsForm()" formControlName="nbPrinters" + min="0" class="form-input nbEquipment" /> <app-svg-icon @@ -1042,6 +1052,7 @@ type="number" (input)="setValidationsForm()" formControlName="nbNumericTerminal" + min="0" class="form-input nbEquipment" /> <app-svg-icon @@ -1064,6 +1075,7 @@ type="number" (input)="setValidationsForm()" formControlName="nbScanners" + min="0" class="form-input nbEquipment" /> <app-svg-icon diff --git a/src/app/form/structure-form/form.component.scss b/src/app/form/structure-form/form.component.scss index ee1d85d299abeb64441bbf5c0ddd7bfdcb55c8a5..986c73d073d548683a7ef9e3467c4df49f375f34 100644 --- a/src/app/form/structure-form/form.component.scss +++ b/src/app/form/structure-form/form.component.scss @@ -446,6 +446,9 @@ img { height: 100%; fill: $grey-1; } + } + .logo, + .titleCollapse { .hide { display: block; } diff --git a/src/app/form/structure-form/form.component.ts b/src/app/form/structure-form/form.component.ts index f6a90b9bb96165514e27e67d13c32093c955adcc..1fd107605fc18f9afae3123148ea80cb7ee8d273 100644 --- a/src/app/form/structure-form/form.component.ts +++ b/src/app/form/structure-form/form.component.ts @@ -294,24 +294,27 @@ export class FormComponent implements OnInit { socialAndProfessional: this.loadArrayForCheckbox(structure.socialAndProfessional, false), digitalCultureSecurity: this.loadArrayForCheckbox(structure.digitalCultureSecurity, false), nbComputers: new FormControl( - structure.equipmentsAndServices.includes('ordinateurs') ? structure.nbComputers : 1, - [Validators.required, Validators.pattern(CustomRegExp.NO_NULL_NUMBER)] + structure.equipmentsAndServices.includes('ordinateurs') ? structure.nbComputers : 0, + [Validators.required, Validators.pattern(CustomRegExp.NO_NEGATIVE_NUMBER), Validators.min(0)] ), - nbPrinters: new FormControl(structure.equipmentsAndServices.includes('imprimantes') ? structure.nbPrinters : 1, [ + nbPrinters: new FormControl(structure.equipmentsAndServices.includes('imprimantes') ? structure.nbPrinters : 0, [ Validators.required, - Validators.pattern(CustomRegExp.NO_NULL_NUMBER), + Validators.pattern(CustomRegExp.NO_NEGATIVE_NUMBER), + Validators.min(0), ]), - nbTablets: new FormControl(structure.equipmentsAndServices.includes('tablettes') ? structure.nbTablets : 1, [ + nbTablets: new FormControl(structure.equipmentsAndServices.includes('tablettes') ? structure.nbTablets : 0, [ Validators.required, - Validators.pattern(CustomRegExp.NO_NULL_NUMBER), + Validators.pattern(CustomRegExp.NO_NEGATIVE_NUMBER), + Validators.min(0), ]), nbNumericTerminal: new FormControl( - structure.equipmentsAndServices.includes('bornesNumeriques') ? structure.nbNumericTerminal : 1, - [Validators.required, Validators.pattern(CustomRegExp.NO_NULL_NUMBER)] + structure.equipmentsAndServices.includes('bornesNumeriques') ? structure.nbNumericTerminal : 0, + [Validators.required, Validators.pattern(CustomRegExp.NO_NEGATIVE_NUMBER), Validators.min(0)] ), - nbScanners: new FormControl(structure.equipmentsAndServices.includes('scanners') ? structure.nbScanners : 1, [ + nbScanners: new FormControl(structure.equipmentsAndServices.includes('scanners') ? structure.nbScanners : 0, [ Validators.required, - Validators.pattern(CustomRegExp.NO_NULL_NUMBER), + Validators.pattern(CustomRegExp.NO_NEGATIVE_NUMBER), + Validators.min(0), ]), freeWorkShop: new FormControl(structure.freeWorkShop, [Validators.required]), }); @@ -872,23 +875,23 @@ export class FormComponent implements OnInit { if (!equipment.openned) { switch (e.module.id) { case Equipment.computer: { - this.getStructureControl('nbComputers').setValue(1); + this.getStructureControl('nbComputers').setValue(0); break; } case Equipment.printer: { - this.getStructureControl('nbPrinters').setValue(1); + this.getStructureControl('nbPrinters').setValue(0); break; } case Equipment.tablet: { - this.getStructureControl('nbTablets').setValue(1); + this.getStructureControl('nbTablets').setValue(0); break; } case Equipment.bornes: { - this.getStructureControl('nbNumericTerminal').setValue(1); + this.getStructureControl('nbNumericTerminal').setValue(0); break; } case Equipment.scanner: { - this.getStructureControl('nbScanners').setValue(1); + this.getStructureControl('nbScanners').setValue(0); break; } } @@ -910,8 +913,17 @@ export class FormComponent implements OnInit { if (this.getStructureControl('freeWorkShop').value === null) { this.getStructureControl('freeWorkShop').setValue(false); } - const structure: Structure = this.structureForm.value; + let structure: Structure = this.structureForm.value; structure.hours = this.hoursForm.value; + // Remove equipments if value is 0 + structure.equipmentsAndServices = structure.equipmentsAndServices.filter((equipments) => { + if (equipments === 'ordinateurs' && structure.nbComputers === 0) return false; + if (equipments === 'tablettes' && structure.nbTablets === 0) return false; + if (equipments === 'scanners' && structure.nbScanners === 0) return false; + if (equipments === 'bornesNumeriques' && structure.nbNumericTerminal === 0) return false; + if (equipments === 'imprimantes' && structure.nbPrinters === 0) return false; + return true; + }); let user: User; // If edit mode, update setbystep if (this.isEditMode) { diff --git a/src/app/models/structure.model.ts b/src/app/models/structure.model.ts index 5fe14f20be3ac59b3a6c832a445e531ad4ca2b69..b6612172572afe1ce4090c0d90d3467680ea41c9 100644 --- a/src/app/models/structure.model.ts +++ b/src/app/models/structure.model.ts @@ -94,12 +94,21 @@ export class Structure { * Check if a structure has equipments */ public hasEquipments(): boolean { - if (this.equipmentsAndServices.length) { + if (this.equipmentsAndServices.length && this.hasNotOnlyEmptyEquipments()) { return true; } return false; } + /** + * Verify that a structure as not only equipments with 0 as value. This is mostly use for display. + * @returns {Boolean} validation + */ + public hasNotOnlyEmptyEquipments(): boolean { + if (this.nbComputers + this.nbPrinters + this.nbTablets + this.nbNumericTerminal + this.nbScanners > 0) return true; + return false; + } + /** * Check if a structure has pass Numeric label */ diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index f4b137831ed91a16ad78e0f20ee05c7a0be4a62e..e7d6537391ef54dd43e1f7eeb7c185d38e08750e 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -317,14 +317,21 @@ </div> <div fxLayout="column"> <p *ngFor="let equipement of filterOnlyEquipments(structure.equipmentsAndServices)" class="no-margin-bottom"> - {{ getEquipmentsLabel(equipement) }} - <span *ngIf="equipement == 'ordinateurs' && structure.nbComputers"> : {{ structure.nbComputers }}</span> - <span *ngIf="equipement == 'tablettes' && structure.nbTablets"> : {{ structure.nbTablets }}</span> + <span *ngIf="equipement == 'ordinateurs' && structure.nbComputers" + >{{ getEquipmentsLabel(equipement) }} : {{ structure.nbComputers }}</span + > + <span *ngIf="equipement == 'tablettes' && structure.nbTablets" + >{{ getEquipmentsLabel(equipement) }} : {{ structure.nbTablets }}</span + > <span *ngIf="equipement == 'bornesNumeriques' && structure.nbNumericTerminal"> - : {{ structure.nbNumericTerminal }}</span + {{ getEquipmentsLabel(equipement) }} : {{ structure.nbNumericTerminal }}</span + > + <span *ngIf="equipement == 'imprimantes' && structure.nbPrinters" + >{{ getEquipmentsLabel(equipement) }} : {{ structure.nbPrinters }}</span + > + <span *ngIf="equipement == 'scanners' && structure.nbScanners" + >{{ getEquipmentsLabel(equipement) }} : {{ structure.nbScanners }}</span > - <span *ngIf="equipement == 'imprimantes' && structure.nbPrinters"> : {{ structure.nbPrinters }}</span> - <span *ngIf="equipement == 'scanners' && structure.nbScanners"> : {{ structure.nbScanners }}</span> </p> </div> </div> diff --git a/src/app/utils/CustomRegExp.ts b/src/app/utils/CustomRegExp.ts index 1c88931310d16aa43457945ca0ec29fe08b4949b..6f5d4379933cd95004d181f8f888c312a9f68360 100644 --- a/src/app/utils/CustomRegExp.ts +++ b/src/app/utils/CustomRegExp.ts @@ -29,6 +29,7 @@ export class CustomRegExp { public static readonly TWITTER: string = '(twitter.com/.{1,})'; public static readonly INSTAGRAM: string = '(instagram.com/.{1,})'; public static readonly NO_NULL_NUMBER: string = '[1-9]{1}[0-9]*?'; + public static readonly NO_NEGATIVE_NUMBER: RegExp = /^\d+$/; /** * Validate a location request in search bar */