From b61e7000492e23d60ca9e507750a9375805fbc86 Mon Sep 17 00:00:00 2001 From: oussamasic <oussamazerouali42@gmail.com> Date: Tue, 23 Nov 2021 14:43:00 +0100 Subject: [PATCH] correct referential applications creation button issue --- .../access-contract-create.component.html | 207 ++++++++++-------- .../access-contract-create.component.ts | 98 +++++---- .../agency-create.component.html | 4 +- .../agency-create/agency-create.component.ts | 47 ++-- .../audit-create/audit-create.component.html | 92 +++++--- .../audit-create/audit-create.component.ts | 15 +- .../context-create.component.html | 2 +- .../context-create.component.ts | 76 +++---- .../file-format-create.component.html | 69 ++++-- .../file-format-create.component.ts | 42 ++-- .../ingest-contract-create.component.html | 4 +- .../ingest-contract-create.component.ts | 11 +- .../ontology-create.component.html | 3 +- .../ontology-create.component.ts | 59 ++--- .../probative-value-create.component.html | 48 ++-- .../probative-value-create.component.ts | 98 +++++---- .../rule-create/rule-create.component.html | 144 ++++++++---- .../rule/rule-create/rule-create.component.ts | 9 +- .../security-profile-create.component.html | 84 +++++-- .../security-profile-create.component.ts | 48 ++-- .../referential/src/assets/i18n/en.json | 3 +- .../referential/src/assets/i18n/fr.json | 3 +- 22 files changed, 700 insertions(+), 466 deletions(-) diff --git a/ui/ui-frontend/projects/referential/src/app/access-contract/access-contract-create/access-contract-create.component.html b/ui/ui-frontend/projects/referential/src/app/access-contract/access-contract-create/access-contract-create.component.html index d710c4926..3dbefba6a 100644 --- a/ui/ui-frontend/projects/referential/src/app/access-contract/access-contract-create/access-contract-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/access-contract/access-contract-create/access-contract-create.component.html @@ -3,8 +3,7 @@ </div> <form [formGroup]="form" (ngSubmit)="onSubmit()" (keydown.enter)="$event.preventDefault()"> - <vitamui-common-stepper (selectionChange)="stepIndex=$event.selectedIndex"> - + <vitamui-common-stepper (selectionChange)="stepIndex = $event.selectedIndex"> <cdk-step> <div class="content"> <h4 i18n="Create accessContract title@@accessContractCreateTitle1">Création d'un contrat d'accès</h4> @@ -15,30 +14,44 @@ </div> <div class="d-flex"> - <vitamui-common-input formControlName="name" minlength="2" maxlength="100" required placeholder="Nom" - i18n-placeholder="Name@@profileGroupCreateNamePlaceholder"> + <vitamui-common-input + formControlName="name" + minlength="2" + maxlength="100" + required + placeholder="Nom" + i18n-placeholder="Name@@profileGroupCreateNamePlaceholder" + > <ng-container *ngIf="form.get('name')?.touched"> <vitamui-common-input-error *ngIf="!!form.get('name')?.errors?.required" - >{{'COMMON.REQUIRED' | translate} - }</vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('name')?.errors?.nameExists" - i18n="Name exists error hint@@formErrorNameExists">Nom déjà utilisé + >{{ 'COMMON.REQUIRED' | translate }} + </vitamui-common-input-error> + <vitamui-common-input-error *ngIf="!!form?.get('name')?.errors?.nameExists" i18n="Name exists error hint@@formErrorNameExists" + >Nom déjà utilisé </vitamui-common-input-error> </ng-container> </vitamui-common-input> </div> <div class="d-flex" *ngIf="isSlaveMode"> - <vitamui-common-input formControlName="identifier" minlength="2" maxlength="100" required - placeholder="Identifiant" - i18n-placeholder="Identifier@@ingectContractCreateIdentifierPlaceholder"> + <vitamui-common-input + formControlName="identifier" + minlength="2" + maxlength="100" + required + placeholder="Identifiant" + i18n-placeholder="Identifier@@ingectContractCreateIdentifierPlaceholder" + > <ng-container *ngIf="form.get('identifier')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('identifier')?.errors?.required" - i18n="Required field error hint@@formErrorRequiredField">Champ requis + <vitamui-common-input-error + *ngIf="!!form.get('identifier')?.errors?.required" + i18n="Required field error hint@@formErrorRequiredField" + >Champ requis </vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('identifier')?.errors?.identifierExists" - i18n="Name exists error hint@@formErrorIdentifierExists">Identifiant déjà - utilisé + <vitamui-common-input-error + *ngIf="!!form?.get('identifier')?.errors?.identifierExists" + i18n="Name exists error hint@@formErrorIdentifierExists" + >Identifiant déjà utilisé </vitamui-common-input-error> </ng-container> </vitamui-common-input> @@ -48,45 +61,46 @@ </vitamui-common-textarea> <div class="form-group"> - <vitamui-common-slide-toggle [formControl]="accessLogControl" - checked="form.controls.accessLog.value === 'ACTIVE'"> + <vitamui-common-slide-toggle [formControl]="accessLogControl" checked="form.controls.accessLog.value === 'ACTIVE'"> Journalisation des accès <span *ngIf="!form.controls.accessLog.value">in</span>actif </vitamui-common-slide-toggle> - <i class="material-icons" matTooltip="Droit d'enregistrer les accès sur les objets" - matTooltipClass="vitamui-tooltip">info</i> + <i class="material-icons" matTooltip="Droit d'enregistrer les accès sur les objets" matTooltipClass="vitamui-tooltip">info</i> </div> <div class="form-group"> - <vitamui-common-slide-toggle [formControl]="ruleFilter">Autoriser le filtrage sur les règles de gestion + <vitamui-common-slide-toggle [formControl]="ruleFilter" + >Autoriser le filtrage sur les règles de gestion </vitamui-common-slide-toggle> - <i class="material-icons" matTooltip="Filtrer les accès en fonction des règles de gestion arrivé à échéance" - matTooltipClass="vitamui-tooltip">info</i> + <i + class="material-icons" + matTooltip="Filtrer les accès en fonction des règles de gestion arrivé à échéance" + matTooltipClass="vitamui-tooltip" + >info</i + > </div> <div class="form-group select-group-info" *ngIf="ruleFilter.value === true"> - <mat-form-field class="vitamui-mat-select"> - <mat-select formControlName="ruleCategoryToFilter" placeholder="Sélectionnez les règles" - i18n-placeholder="Application@@profilesFormApplicationPlaceholder" - panelclass="vitamui-mat-select" - multiple required> - <mat-option *ngFor='let rule of rules' [value]="rule.key">{{rule.label}}</mat-option> + <mat-select + formControlName="ruleCategoryToFilter" + placeholder="Sélectionnez les règles" + i18n-placeholder="Application@@profilesFormApplicationPlaceholder" + panelclass="vitamui-mat-select" + multiple + required + > + <mat-option *ngFor="let rule of rules" [value]="rule.key">{{ rule.label }}</mat-option> </mat-select> <div class="select-arrow"> <i class="material-icons">keyboard_arrow_down</i> </div> </mat-form-field> - <i class="material-icons" matTooltip="Choisir les règles de gestion" - matTooltipClass="vitamui-tooltip">info</i> + <i class="material-icons" matTooltip="Choisir les règles de gestion" matTooltipClass="vitamui-tooltip">info</i> </div> <div class="actions"> - <button type="button" class="btn primary" cdkStepperNext [disabled]="firstStepInvalid()" - >{{'COMMON.NEXT' | translate}} - </button> - <button type="button" class="btn cancel" (click)="onCancel()" - >{{'COMMON.UNDO' | translate}} - </button> + <button type="button" class="btn primary" cdkStepperNext [disabled]="firstStepInvalid()">{{ 'COMMON.NEXT' | translate }}</button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> </div> </cdk-step> @@ -97,72 +111,75 @@ <h5 i18n="Create accessContract title@@accessContractCreateTitle3">Services producteurs et usages</h5> <div class="form-group"> - <vitamui-common-slide-toggle formControlName="everyOriginatingAgency">Tous les services producteurs - </vitamui-common-slide-toggle> - <i class="material-icons" matTooltip="Service producteur associé au contrat et accédant aux archives" - matTooltipClass="vitamui-tooltip">info</i> + <vitamui-common-slide-toggle formControlName="everyOriginatingAgency">Tous les services producteurs </vitamui-common-slide-toggle> + <i + class="material-icons" + matTooltip="Service producteur associé au contrat et accédant aux archives" + matTooltipClass="vitamui-tooltip" + >info</i + > </div> <!-- FIXME: Hide if oa filter is on --> <div class="form-group" *ngIf="form.controls.everyOriginatingAgency.value === false"> <mat-form-field class="vitamui-mat-select"> - <mat-select formControlName="originatingAgencies" placeholder="Sélectionnez les services producteurs" - i18n-placeholder="Application@@profilesFormApplicationPlaceholder" - panelclass="vitamui-mat-select" - multiple required> - <mat-option *ngFor='let originatingAgencie of originatingAgencies' [value]="originatingAgencie.key"> - {{originatingAgencie.label}} + <mat-select + formControlName="originatingAgencies" + placeholder="Sélectionnez les services producteurs" + i18n-placeholder="Application@@profilesFormApplicationPlaceholder" + panelclass="vitamui-mat-select" + multiple + required + > + <mat-option *ngFor="let originatingAgencie of originatingAgencies" [value]="originatingAgencie.key"> + {{ originatingAgencie.label }} </mat-option> </mat-select> <div class="select-arrow"> <i class="material-icons">keyboard_arrow_down</i> </div> </mat-form-field> - <i class="material-icons" matTooltip="Choisir de un à plusieurs services producteur" - matTooltipClass="vitamui-tooltip">info</i> + <i class="material-icons" matTooltip="Choisir de un à plusieurs services producteur" matTooltipClass="vitamui-tooltip">info</i> </div> <div class="form-group"> - <vitamui-common-slide-toggle formControlName="everyDataObjectVersion">Tous les usages - </vitamui-common-slide-toggle> - <i class="material-icons" matTooltip="Usage auquel donne droit le contrat d'accès" - matTooltipClass="vitamui-tooltip">info</i> + <vitamui-common-slide-toggle formControlName="everyDataObjectVersion">Tous les usages </vitamui-common-slide-toggle> + <i class="material-icons" matTooltip="Usage auquel donne droit le contrat d'accès" matTooltipClass="vitamui-tooltip">info</i> </div> <!-- FIXME: Hide if usage filter is on (Check usecase) --> <div class="form-group" *ngIf="form.controls.everyDataObjectVersion.value === false"> <mat-form-field class="vitamui-mat-select"> - <mat-select formControlName="dataObjectVersion" placeholder="Sélectionnez les usages" - i18n-placeholder="Application@@profilesFormApplicationPlaceholder" - panelclass="vitamui-mat-select" - multiple required> - <mat-option *ngFor='let usage of usages' [value]="usage.key"> - {{usage.label}} + <mat-select + formControlName="dataObjectVersion" + placeholder="Sélectionnez les usages" + i18n-placeholder="Application@@profilesFormApplicationPlaceholder" + panelclass="vitamui-mat-select" + multiple + required + > + <mat-option *ngFor="let usage of usages" [value]="usage.key"> + {{ usage.label }} </mat-option> </mat-select> <div class="select-arrow"> <i class="material-icons">keyboard_arrow_down</i> </div> </mat-form-field> - <i class="material-icons" matTooltip="Choisir de un à plusieurs usages" - matTooltipClass="vitamui-tooltip">info</i> - + <i class="material-icons" matTooltip="Choisir de un à plusieurs usages" matTooltipClass="vitamui-tooltip">info</i> </div> <div class="actions"> - <button type="button" class="btn primary" cdkStepperNext [disabled]="secondStepInvalid()" - >{{'COMMON.NEXT' | translate}} - </button> - <button type="button" class="btn cancel" (click)="onCancel()" - >{{'COMMON.UNDO' | translate}} - </button> + <button type="button" class="btn primary" cdkStepperNext [disabled]="secondStepInvalid()">{{ 'COMMON.NEXT' | translate }}</button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> <button type="button" class="back" cdkStepperPrevious> <i class="material-icons">arrow_back</i> - <ng-container><span - class="underline">{{'COMMON.BACK' | translate}}</span></ng-container> + <ng-container + ><span class="underline">{{ 'COMMON.BACK' | translate }}</span></ng-container + > </button> </div> </cdk-step> @@ -173,31 +190,26 @@ <h5 i18n="Create accessContract title@@accessContractCreateTitle4">Droits d'écritures</h5> <div class="form-group"> - <vitamui-common-slide-toggle formControlName="writingPermission">Droits d'écriture - </vitamui-common-slide-toggle> - <i class="material-icons" matTooltip="Donner des droits en écriture sur les archives" - matTooltipClass="vitamui-tooltip">info</i> + <vitamui-common-slide-toggle formControlName="writingPermission">Droits d'écriture </vitamui-common-slide-toggle> + <i class="material-icons" matTooltip="Donner des droits en écriture sur les archives" matTooltipClass="vitamui-tooltip">info</i> </div> <!-- FIXME: Hide if WritingPermission is off --> <div class="form-group" *ngIf="form.controls.writingPermission.value === true"> - <vitamui-common-slide-toggle formControlName="writingRestrictedDesc">Restriction de modification aux - métadonnées de description + <vitamui-common-slide-toggle formControlName="writingRestrictedDesc" + >Restriction de modification aux métadonnées de description </vitamui-common-slide-toggle> </div> <div class="actions"> - <button type="button" class="btn primary" cdkStepperNext [disabled]="secondStepInvalid()" - >{{'COMMON.NEXT' | translate}} - </button> - <button type="button" class="btn cancel" (click)="onCancel()" - >{{'COMMON.UNDO' | translate}} - </button> + <button type="button" class="btn primary" cdkStepperNext [disabled]="secondStepInvalid()">{{ 'COMMON.NEXT' | translate }}</button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> <button type="button" class="back" cdkStepperPrevious> <i class="material-icons">arrow_back</i> - <ng-container><span - class="underline">{{'COMMON.BACK' | translate}}</span></ng-container> + <ng-container + ><span class="underline">{{ 'COMMON.BACK' | translate }}</span></ng-container + > </button> </div> </cdk-step> @@ -209,27 +221,30 @@ <div class="form-group"> <vitamui-common-slide-toggle [formControl]="allNodes">Toutes les positions</vitamui-common-slide-toggle> - <i class="material-icons" matTooltip="Choix des positions auxquelles on souhaite donner accès en consultation" - matTooltipClass="vitamui-tooltip">info</i> + <i + class="material-icons" + matTooltip="Choix des positions auxquelles on souhaite donner accès en consultation" + matTooltipClass="vitamui-tooltip" + >info</i + > </div> <div class="form-group" *ngIf="allNodes.value === false && !!accessContractSelect.value"> - <vitamui-library-filing-plan [formControl]="selectNodesControl" - [tenantIdentifier]="tenantIdentifier" - [accessContract]="accessContractSelect.value" - [mode]="FILLING_PLAN_MODE.BOTH" + <vitamui-library-filing-plan + [formControl]="selectNodesControl" + [tenantIdentifier]="tenantIdentifier" + [accessContract]="accessContractSelect.value" + [mode]="FILLING_PLAN_MODE.BOTH" ></vitamui-library-filing-plan> </div> - <button type="submit" class="btn primary" [disabled]="lastStepInvalid()" - >{{'COMMON.SUBMIT' | translate}} - </button> - <button type="button" class="btn cancel" (click)="onCancel()" - >{{'COMMON.UNDO' | translate}} + <button type="submit" class="btn primary" [disabled]="lastStepInvalid() || isDisabledButton"> + {{ 'COMMON.SUBMIT' | translate }} </button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> <button type="button" class="back" cdkStepperPrevious> <i class="material-icons">arrow_back</i> - <ng-container>{{'COMMON.BACK' | translate}}</ng-container> + <ng-container>{{ 'COMMON.BACK' | translate }}</ng-container> </button> </div> </cdk-step> diff --git a/ui/ui-frontend/projects/referential/src/app/access-contract/access-contract-create/access-contract-create.component.ts b/ui/ui-frontend/projects/referential/src/app/access-contract/access-contract-create/access-contract-create.component.ts index 6b777291a..fdaa7932a 100644 --- a/ui/ui-frontend/projects/referential/src/app/access-contract/access-contract-create/access-contract-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/access-contract/access-contract-create/access-contract-create.component.ts @@ -36,26 +36,24 @@ */ import { Component, Inject, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import '@angular/localize/init'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; +import { AccessContract, FilingPlanMode } from 'projects/vitamui-library/src/public-api'; import { Subscription } from 'rxjs'; import { ConfirmDialogService, ExternalParameters, ExternalParametersService, Option } from 'ui-frontend-common'; - -import { AccessContract, FilingPlanMode } from 'projects/vitamui-library/src/public-api'; import { AgencyService } from '../../agency/agency.service'; -import { AccessContractCreateValidators } from './access-contract-create.validators'; -import '@angular/localize/init'; import { AccessContractService } from '../access-contract.service'; +import { AccessContractCreateValidators } from './access-contract-create.validators'; const PROGRESS_BAR_MULTIPLICATOR = 100; @Component({ selector: 'app-access-contract-create', templateUrl: './access-contract-create.component.html', - styleUrls: ['./access-contract-create.component.scss'] + styleUrls: ['./access-contract-create.component.scss'], }) export class AccessContractCreateComponent implements OnInit, OnDestroy { - @Input() tenantIdentifier: number; @Input() isSlaveMode: boolean; @@ -86,8 +84,7 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy { private confirmDialogService: ConfirmDialogService, private externalParameterService: ExternalParametersService, private snackBar: MatSnackBar - ) { - } + ) {} statusControl = new FormControl(false); accessLogControl = new FormControl(true); @@ -98,14 +95,16 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy { originatingAgencies: Option[] = []; + isDisabledButton = false; + // FIXME: Get list from common var ? rules: Option[] = [ - { key: 'StorageRule', label: 'Durée d\'utilité courante', info: '' }, + { key: 'StorageRule', label: "Durée d'utilité courante", info: '' }, { key: 'ReuseRule', label: 'Durée de réutilisation', info: '' }, { key: 'ClassificationRule', label: 'Durée de classification', info: '' }, { key: 'DisseminationRule', label: 'Délai de diffusion', info: '' }, - { key: 'AccessRule', label: 'Durée d\'utilité administrative', info: '' }, - { key: 'AppraisalRule', label: 'Délai de communicabilité', info: '' } + { key: 'AccessRule', label: "Durée d'utilité administrative", info: '' }, + { key: 'AppraisalRule', label: 'Délai de communicabilité', info: '' }, ]; // FIXME: Get list from common var ? @@ -114,28 +113,29 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy { { key: 'Dissemination', label: 'Copies de diffusion', info: '' }, { key: 'Thumbnail', label: 'Vignettes', info: '' }, { key: 'TextContent', label: 'Contenu textuel', info: '' }, - { key: 'PhysicalMaster', label: 'Archives physiques', info: '' } + { key: 'PhysicalMaster', label: 'Archives physiques', info: '' }, ]; ngOnInit() { - - this.externalParameterService.getUserExternalParameters().subscribe(parameters => { + this.externalParameterService.getUserExternalParameters().subscribe((parameters) => { const accessContratId: string = parameters.get(ExternalParameters.PARAM_ACCESS_CONTRACT); if (accessContratId && accessContratId.length > 0) { this.accessContractSelect.setValue(accessContratId); } else { this.snackBar.open( - $localize`:access contrat not set message@@accessContratNotSetErrorMessage:Aucun contrat d'accès n'est associé à l'utiisateur`, - null, { + $localize`:access contrat not set message@@accessContratNotSetErrorMessage:Aucun contrat d'accès n'est associé à l'utiisateur`, + null, + { panelClass: 'vitamui-snack-bar', - duration: 10000 - }); + duration: 10000, + } + ); } }); - this.agencyService.getAll().subscribe(agencies => - this.originatingAgencies = agencies.map(x => ({ label: x.name, key: x.identifier })) - ); + this.agencyService + .getAll() + .subscribe((agencies) => (this.originatingAgencies = agencies.map((x) => ({ label: x.name, key: x.identifier })))); this.form = this.formBuilder.group({ identifier: [null, Validators.required, this.accessContractCreateValidators.uniqueIdentifier()], @@ -154,18 +154,18 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy { writingRestrictedDesc: [true], /* <- step 4 -> */ rootUnits: [[], Validators.required], - excludedRootUnits: [[]] + excludedRootUnits: [[]], }); this.statusControl.valueChanges.subscribe((value) => { - this.form.controls.status.setValue(value = (value === false) ? 'INACTIVE' : 'ACTIVE'); + this.form.controls.status.setValue((value = value === false ? 'INACTIVE' : 'ACTIVE')); }); this.accessLogControl.valueChanges.subscribe((value) => { - this.form.controls.accessLog.setValue(value = (value === false) ? 'INACTIVE' : 'ACTIVE'); + this.form.controls.accessLog.setValue((value = value === false ? 'INACTIVE' : 'ACTIVE')); }); - this.selectNodesControl.valueChanges.subscribe((value: { included: string[], excluded: string[] }) => { + this.selectNodesControl.valueChanges.subscribe((value: { included: string[]; excluded: string[] }) => { this.form.controls.rootUnits.setValue(value.included); this.form.controls.excludedRootUnits.setValue(value.excluded); }); @@ -193,44 +193,60 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy { onSubmit() { if (this.lastStepInvalid()) { + this.isDisabledButton = true; return; } + this.isDisabledButton = true; const accessContract = this.form.value as AccessContract; - accessContract.status === 'ACTIVE' ? accessContract.activationDate = new Date().toISOString() : accessContract.deactivationDate = new Date().toISOString(); + accessContract.status === 'ACTIVE' + ? (accessContract.activationDate = new Date().toISOString()) + : (accessContract.deactivationDate = new Date().toISOString()); this.accessContractService.create(accessContract).subscribe( () => { + this.isDisabledButton = false; this.dialogRef.close(true); }, (error) => { this.dialogRef.close(false); console.error(error); - }); + } + ); } firstStepInvalid(): boolean { - return this.form.get('name').invalid || this.form.get('name').pending || - this.form.get('description').invalid || this.form.get('description').pending || - this.form.get('status').invalid || this.form.get('status').pending || - this.form.get('accessLog').invalid || this.form.get('accessLog').pending || - (this.ruleFilter.value === true && (this.form.get('ruleCategoryToFilter').invalid || this.form.get('ruleCategoryToFilter').pending)); + return ( + this.form.get('identifier').invalid || + this.form.get('identifier').pending || + this.form.get('name').invalid || + this.form.get('name').pending || + this.form.get('description').invalid || + this.form.get('description').pending || + this.form.get('status').invalid || + this.form.get('status').pending || + this.form.get('accessLog').invalid || + this.form.get('accessLog').pending || + (this.ruleFilter.value === true && (this.form.get('ruleCategoryToFilter').invalid || this.form.get('ruleCategoryToFilter').pending)) + ); } secondStepInvalid(): boolean { - return (this.form.get('everyOriginatingAgency').value === false && - (this.form.get('originatingAgencies').invalid || - this.form.get('originatingAgencies').pending)) || + return ( + (this.form.get('everyOriginatingAgency').value === false && + (this.form.get('originatingAgencies').invalid || this.form.get('originatingAgencies').pending)) || (this.form.get('everyDataObjectVersion').value === false && - (this.form.get('dataObjectVersion').invalid || - this.form.get('dataObjectVersion').pending)); + (this.form.get('dataObjectVersion').invalid || this.form.get('dataObjectVersion').pending)) + ); } lastStepInvalid(): boolean { - return this.allNodes.invalid || this.allNodes.pending || - (this.allNodes.value === false && (this.form.controls.rootUnits.invalid || this.form.controls.rootUnits.value.length === 0)); + return ( + this.allNodes.invalid || + this.allNodes.pending || + (this.allNodes.value === false && (this.form.controls.rootUnits.invalid || this.form.controls.rootUnits.value.length === 0)) + ); } get stepProgress() { return ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR; } - } diff --git a/ui/ui-frontend/projects/referential/src/app/agency/agency-create/agency-create.component.html b/ui/ui-frontend/projects/referential/src/app/agency/agency-create/agency-create.component.html index bb75180f2..0e8f6a7c4 100644 --- a/ui/ui-frontend/projects/referential/src/app/agency/agency-create/agency-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/agency/agency-create/agency-create.component.html @@ -54,8 +54,8 @@ </vitamui-common-input> </div> <div class="btn-container"> - <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid">{{'COMMON.SUBMIT' | translate}}</button> - <button type="button" class="btn primary" [disabled]="form.pending || form.invalid" (click)="onSubmitAndCreate()" i18n="Finish agency creation button@@agencyCreateFinishButton">Terminer et créer un nouveau service agent</button> + <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid || isDisabledButton">{{'COMMON.SUBMIT' | translate}}</button> + <button type="button" class="btn primary" [disabled]="form.pending || form.invalid || isDisabledButton" (click)="onSubmitAndCreate()" i18n="Finish agency creation button@@agencyCreateFinishButton">Terminer et créer un nouveau service agent</button> <button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button> </div> </div> diff --git a/ui/ui-frontend/projects/referential/src/app/agency/agency-create/agency-create.component.ts b/ui/ui-frontend/projects/referential/src/app/agency/agency-create/agency-create.component.ts index 4c8285d9f..bc39137c9 100644 --- a/ui/ui-frontend/projects/referential/src/app/agency/agency-create/agency-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/agency/agency-create/agency-create.component.ts @@ -34,24 +34,22 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -import {Subscription} from 'rxjs'; -import {ConfirmDialogService} from 'ui-frontend-common'; - -import {Component, Inject, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; -import {AgencyService} from '../agency.service'; -import {AgencyCreateValidators} from './agency-create.validators'; +import { Component, Inject, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { Subscription } from 'rxjs'; +import { ConfirmDialogService } from 'ui-frontend-common'; +import { AgencyService } from '../agency.service'; +import { AgencyCreateValidators } from './agency-create.validators'; const PROGRESS_BAR_MULTIPLICATOR = 100; @Component({ selector: 'app-agency-create', templateUrl: './agency-create.component.html', - styleUrls: ['./agency-create.component.scss'] + styleUrls: ['./agency-create.component.scss'], }) export class AgencyCreateComponent implements OnInit, OnDestroy { - form: FormGroup; stepIndex = 0; hasCustomGraphicIdentity = false; @@ -64,8 +62,9 @@ export class AgencyCreateComponent implements OnInit, OnDestroy { // Make sure to update this value whenever you add or remove a step from the template. private stepCount = 1; private keyPressSubscription: Subscription; + isDisabledButton = false; - @ViewChild('fileSearch', {static: false}) fileSearch: any; + @ViewChild('fileSearch', { static: false }) fileSearch: any; constructor( public dialogRef: MatDialogRef<AgencyCreateComponent>, @@ -74,14 +73,13 @@ export class AgencyCreateComponent implements OnInit, OnDestroy { private confirmDialogService: ConfirmDialogService, private agencyService: AgencyService, private agencyCreateValidators: AgencyCreateValidators - ) { - } + ) {} ngOnInit() { this.form = this.formBuilder.group({ name: [null, Validators.required], identifier: [null, Validators.required, this.agencyCreateValidators.uniqueIdentifier()], - description: [null] + description: [null], }); this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel()); @@ -101,32 +99,37 @@ export class AgencyCreateComponent implements OnInit, OnDestroy { onSubmit() { if (this.form.invalid) { + this.isDisabledButton = true; return; } - // TODO : Create ! + this.isDisabledButton = true; this.agencyService.create(this.form.value).subscribe( () => { - this.dialogRef.close({success: true, action: 'none'}); + this.isDisabledButton = false; + this.dialogRef.close({ success: true, action: 'none' }); }, (error: any) => { - this.dialogRef.close({success: false, action: 'none'}); + this.dialogRef.close({ success: false, action: 'none' }); console.error(error); - }); + } + ); } onSubmitAndCreate() { + this.isDisabledButton = true; this.agencyService.create(this.form.value).subscribe( () => { - this.dialogRef.close({success: true, action: 'restart'}); + this.isDisabledButton = false; + this.dialogRef.close({ success: true, action: 'restart' }); }, (error: any) => { - this.dialogRef.close({success: false, action: 'restart'}); + this.dialogRef.close({ success: false, action: 'restart' }); console.error(error); - }); + } + ); } get stepProgress() { return ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR; } - } diff --git a/ui/ui-frontend/projects/referential/src/app/audit/audit-create/audit-create.component.html b/ui/ui-frontend/projects/referential/src/app/audit/audit-create/audit-create.component.html index 475b3beef..965d64199 100644 --- a/ui/ui-frontend/projects/referential/src/app/audit/audit-create/audit-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/audit/audit-create/audit-create.component.html @@ -4,7 +4,6 @@ <form [formGroup]="form" (ngSubmit)="onSubmit()" (keydown.enter)="$event.preventDefault()"> <vitamui-common-stepper> - <cdk-step> <div class="content"> <h5>Lancement d'un audit</h5> @@ -25,40 +24,56 @@ <div class="form-group" *ngIf="form.value.auditActions === 'AUDIT_FILE_RECTIFICATION'"> <div class="row"> <div class="col-8 form-control"> - <vitamui-common-input class="field-evidenceAudit" formControlName="evidenceAudit" + <vitamui-common-input + class="field-evidenceAudit" + formControlName="evidenceAudit" placeholder="Identifiant d'audit de cohérence" - i18n-placeholder="evidenceAudit@@auditCreateEvidenceAudit" required> + i18n-placeholder="evidenceAudit@@auditCreateEvidenceAudit" + required + > <ng-container *ngIf="form.get('evidenceAudit')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('evidenceAudit')?.errors?.required" - i18n="Required field error hint@@formErrorRequiredField">Champ requis</vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('evidenceAudit')?.errors?.invalidEvidenceAuditId" - i18n="Identfier exists error hint@@formErrorIdentifierExists">L'identifiant d'audit de cohérence saisi - n'existe pas + <vitamui-common-input-error + *ngIf="!!form.get('evidenceAudit')?.errors?.required" + i18n="Required field error hint@@formErrorRequiredField" + >Champ requis</vitamui-common-input-error + > + <vitamui-common-input-error + *ngIf="!!form?.get('evidenceAudit')?.errors?.invalidEvidenceAuditId" + i18n="Identfier exists error hint@@formErrorIdentifierExists" + >L'identifiant d'audit de cohérence saisi n'existe pas </vitamui-common-input-error> </ng-container> </vitamui-common-input> - </div> </div> </div> - <div class="form-group" - *ngIf="form.value.auditActions !== 'AUDIT_FILE_CONSISTENCY' && form.value.auditActions !== 'AUDIT_FILE_RECTIFICATION'"> + <div + class="form-group" + *ngIf="form.value.auditActions !== 'AUDIT_FILE_CONSISTENCY' && form.value.auditActions !== 'AUDIT_FILE_RECTIFICATION'" + > <div class="row"> <div class="col-8 form-control"> - <vitamui-common-slide-toggle [formControl]="allServices">Tous les services producteurs - </vitamui-common-slide-toggle> + <vitamui-common-slide-toggle [formControl]="allServices">Tous les services producteurs </vitamui-common-slide-toggle> </div> <div class="col-8 form-control"> - <mat-form-field class="vitamui-mat-select" - *ngIf="allServices.value === false && accessionRegisterSummaries && ( - form.value.auditActions === 'AUDIT_FILE_EXISTING' || - form.value.auditActions === 'AUDIT_FILE_INTEGRITY')"> - <mat-select formControlName="objectId" placeholder="Selectionnez le service producteur" - panelclass="vitamui-mat-select" required> - <mat-option *ngFor='let accession of accessionRegisterSummaries' [value]="accession.originatingAgency"> - {{accession.originatingAgency}} + <mat-form-field + class="vitamui-mat-select" + *ngIf=" + allServices.value === false && + accessionRegisterSummaries && + (form.value.auditActions === 'AUDIT_FILE_EXISTING' || form.value.auditActions === 'AUDIT_FILE_INTEGRITY') + " + > + <mat-select + formControlName="objectId" + placeholder="Selectionnez le service producteur" + panelclass="vitamui-mat-select" + required + > + <mat-option *ngFor="let accession of accessionRegisterSummaries" [value]="accession.originatingAgency"> + {{ accession.originatingAgency }} </mat-option> </mat-select> <div class="select-arrow"> @@ -73,17 +88,26 @@ <div class="form-group" *ngIf="form.value.auditActions === 'AUDIT_FILE_CONSISTENCY'"> <div class="row"> <div class="col-8 form-control"> - <vitamui-common-slide-toggle [formControl]="allNodes">Tous les noeuds de rattachement - </vitamui-common-slide-toggle> + <vitamui-common-slide-toggle [formControl]="allNodes">Tous les noeuds de rattachement </vitamui-common-slide-toggle> </div> </div> </div> <div class="btn-container"> - <button type="button" class="btn primary" cdkStepperNext *ngIf="!this.allNodes.value" [disabled]="!isStepValid()">{{'COMMON.NEXT' | translate}}</button> + <button + type="button" + class="btn primary" + cdkStepperNext + *ngIf="!this.allNodes.value" + [disabled]="!isStepValid() || isDisabledButton" + > + {{ 'COMMON.NEXT' | translate }} + </button> - <button type="submit" class="btn primary" *ngIf="this.allNodes.value" [disabled]="!isStepValid()">{{'COMMON.SUBMIT' | translate}}</button> + <button type="submit" class="btn primary" *ngIf="this.allNodes.value" [disabled]="!isStepValid() || isDisabledButton"> + {{ 'COMMON.SUBMIT' | translate }} + </button> - <button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> </div> </cdk-step> @@ -91,20 +115,24 @@ <cdk-step> <div class="content"> <h5>Lancement d'un audit</h5> - <h4> Noeud de rattachement (SIP) </h4> + <h4>Noeud de rattachement (SIP)</h4> <div class="form-group"> - <vitamui-library-filing-plan [formControl]="selectedNodes" [tenantIdentifier]="tenantIdentifier" - [accessContract]="accessContractId" [mode]="FILLING_PLAN_MODE_INCLUDE"> + <vitamui-library-filing-plan + [formControl]="selectedNodes" + [tenantIdentifier]="tenantIdentifier" + [accessContract]="accessContractId" + [mode]="FILLING_PLAN_MODE_INCLUDE" + > </vitamui-library-filing-plan> </div> <div class="actions"> - <button type="submit" class="btn primary">{{'COMMON.SUBMIT' | translate}}</button> - <button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button> + <button type="submit" class="btn primary">{{ 'COMMON.SUBMIT' | translate }}</button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> <button type="button" class="back" cdkStepperPrevious> <i class="material-icons">arrow_back</i> - <ng-container>{{'COMMON.BACK' | translate}}</ng-container> + <ng-container>{{ 'COMMON.BACK' | translate }}</ng-container> </button> </div> </cdk-step> diff --git a/ui/ui-frontend/projects/referential/src/app/audit/audit-create/audit-create.component.ts b/ui/ui-frontend/projects/referential/src/app/audit/audit-create/audit-create.component.ts index 7a2ba8563..afb80c7e3 100644 --- a/ui/ui-frontend/projects/referential/src/app/audit/audit-create/audit-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/audit/audit-create/audit-create.component.ts @@ -37,22 +37,21 @@ import { HttpHeaders } from '@angular/common/http'; import { Component, Inject, Input, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import '@angular/localize/init'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { MatSnackBar } from '@angular/material/snack-bar'; import { FilingPlanMode } from 'projects/vitamui-library/src/public-api'; import { Subscription } from 'rxjs'; import { AccessionRegisterSummary, ConfirmDialogService, - StartupService, - ExternalParametersService, ExternalParameters, + ExternalParametersService, + StartupService, } from 'ui-frontend-common'; - import { AccessContractService } from '../../access-contract/access-contract.service'; import { AuditService } from '../audit.service'; import { AuditCreateValidators } from './audit-create-validator'; -import { MatSnackBar } from '@angular/material/snack-bar'; -import '@angular/localize/init'; const PROGRESS_BAR_MULTIPLICATOR = 100; @@ -75,6 +74,7 @@ export class AuditCreateComponent implements OnInit { accessContractId: string = null; accessionRegisterSummaries: AccessionRegisterSummary[]; + isDisabledButton = false; // stepCount is the total number of steps and is used to calculate the advancement of the progress bar. // We could get the number of steps using ViewChildren(StepComponent) but this triggers a @@ -217,11 +217,14 @@ export class AuditCreateComponent implements OnInit { onSubmit() { if (this.form.invalid) { + this.isDisabledButton = true; return; } + this.isDisabledButton = true; this.auditService.create(this.form.value, new HttpHeaders({ 'X-Access-Contract-Id': this.accessContractId })).subscribe( () => { + this.isDisabledButton = false; this.dialogRef.close({ success: true, action: 'none' }); }, (error: any) => { diff --git a/ui/ui-frontend/projects/referential/src/app/context/context-create/context-create.component.html b/ui/ui-frontend/projects/referential/src/app/context/context-create/context-create.component.html index b7f941a74..48c2caae9 100644 --- a/ui/ui-frontend/projects/referential/src/app/context/context-create/context-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/context/context-create/context-create.component.html @@ -97,7 +97,7 @@ </ng-container> </div> - <button type="submit" class="btn primary" [disabled]="lastStepInvalid()" + <button type="submit" class="btn primary" [disabled]="lastStepInvalid() || isDisabledButton" i18n="Finish context creation button@@contextCreateFinishButton">Terminer</button> <button type="button" class="btn cancel" (click)="onCancel()" i18n="Cancel context creation@@contextCreateCancelButton">Annuler</button> diff --git a/ui/ui-frontend/projects/referential/src/app/context/context-create/context-create.component.ts b/ui/ui-frontend/projects/referential/src/app/context/context-create/context-create.component.ts index b398d21d4..ab22ce926 100644 --- a/ui/ui-frontend/projects/referential/src/app/context/context-create/context-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/context/context-create/context-create.component.ts @@ -34,32 +34,30 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -import {Subscription} from 'rxjs'; -import {ConfirmDialogService, Option} from 'ui-frontend-common'; - -import {Component, Inject, Input, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms'; -import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; -import {SecurityProfileService} from '../../security-profile/security-profile.service'; -import {ContextService} from '../context.service'; -import {ContextCreateValidators} from './context-create.validators'; +import { Component, Inject, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { Subscription } from 'rxjs'; +import { ConfirmDialogService, Option } from 'ui-frontend-common'; import { Context } from '../../../../../vitamui-library/src/lib/models/context'; +import { SecurityProfileService } from '../../security-profile/security-profile.service'; +import { ContextService } from '../context.service'; +import { ContextCreateValidators } from './context-create.validators'; const PROGRESS_BAR_MULTIPLICATOR = 100; @Component({ selector: 'app-context-create', templateUrl: './context-create.component.html', - styleUrls: ['./context-create.component.scss'] + styleUrls: ['./context-create.component.scss'], }) export class ContextCreateComponent implements OnInit, OnDestroy { - @Input() isSlaveMode: boolean; form: FormGroup; statusControl = new FormControl(false); stepIndex = 0; - accessContractInfo: {code: string, name: string, companyName: string} = {code: '', name: '', companyName: ''}; + accessContractInfo: { code: string; name: string; companyName: string } = { code: '', name: '', companyName: '' }; hasCustomGraphicIdentity = false; hasError = true; message: string; @@ -71,8 +69,9 @@ export class ContextCreateComponent implements OnInit, OnDestroy { // Make sure to update this value whenever you add or remove a step from the template. private stepCount = 2; private keyPressSubscription: Subscription; + isDisabledButton = false; - @ViewChild('fileSearch', {static: false}) fileSearch: any; + @ViewChild('fileSearch', { static: false }) fileSearch: any; securityProfiles: Option[] = []; @@ -84,8 +83,7 @@ export class ContextCreateComponent implements OnInit, OnDestroy { private contextService: ContextService, private contextCreateValidators: ContextCreateValidators, private securityProfileService: SecurityProfileService - ) { - } + ) {} ngOnInit() { this.form = this.formBuilder.group({ @@ -94,7 +92,7 @@ export class ContextCreateComponent implements OnInit, OnDestroy { identifier: [null, Validators.required, this.contextCreateValidators.uniqueIdentifier()], securityProfile: [null, Validators.required], enableControl: [false], - permissions: [[{tenant: null, accessContracts: [], ingestContracts: []}], null, null] + permissions: [[{ tenant: null, accessContracts: [], ingestContracts: [] }], null, null], }); this.form.controls.name.valueChanges.subscribe((value) => { @@ -104,7 +102,7 @@ export class ContextCreateComponent implements OnInit, OnDestroy { }); this.statusControl.valueChanges.subscribe((value) => { - this.form.controls.status.setValue(value = (value === false) ? 'INACTIVE' : 'ACTIVE'); + this.form.controls.status.setValue((value = value === false ? 'INACTIVE' : 'ACTIVE')); }); // Add or remove controls on the permissions @@ -117,9 +115,8 @@ export class ContextCreateComponent implements OnInit, OnDestroy { this.form.controls.permissions.updateValueAndValidity(this.form.controls.permissions.value); }); - this.securityProfileService.getAll().subscribe( - securityProfiles => { - this.securityProfiles = securityProfiles.map(x => ({label: x.name, key: x.identifier})); + this.securityProfileService.getAll().subscribe((securityProfiles) => { + this.securityProfiles = securityProfiles.map((x) => ({ label: x.name, key: x.identifier })); }); this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel()); @@ -139,26 +136,37 @@ export class ContextCreateComponent implements OnInit, OnDestroy { onSubmit() { if (this.form.invalid) { + this.isDisabledButton = true; return; } - + this.isDisabledButton = true; const context = this.form.value as Context; - context.status === 'ACTIVE' ? context.activationDate = new Date().toISOString() : context.deactivationDate = new Date().toISOString(); + context.status === 'ACTIVE' + ? (context.activationDate = new Date().toISOString()) + : (context.deactivationDate = new Date().toISOString()); this.contextService.create(context).subscribe( () => { - this.dialogRef.close({success: true, action: 'none'}); + this.isDisabledButton = false; + this.dialogRef.close({ success: true, action: 'none' }); }, (error: any) => { - this.dialogRef.close({success: false, action: 'none'}); + this.dialogRef.close({ success: false, action: 'none' }); console.error(error); - }); + } + ); } firstStepInvalid() { - return this.form.get('name').invalid || this.form.get('name').pending || - this.form.get('status').invalid || this.form.get('status').pending || - this.form.get('enableControl').invalid || this.form.get('enableControl').pending || - this.form.get('securityProfile').invalid || this.form.get('securityProfile').pending; + return ( + this.form.get('name').invalid || + this.form.get('name').pending || + this.form.get('status').invalid || + this.form.get('status').pending || + this.form.get('enableControl').invalid || + this.form.get('enableControl').pending || + this.form.get('securityProfile').invalid || + this.form.get('securityProfile').pending + ); } lastStepInvalid() { @@ -182,14 +190,6 @@ export class ContextCreateComponent implements OnInit, OnDestroy { } get stepProgress() { - let stepProgress: number; - // For the first step, check if the controls are enabled and if the second step is available or not - if (this.stepIndex === 0 && this.form.controls.enableControl.value === true) { - stepProgress = ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR; - } else { - stepProgress = PROGRESS_BAR_MULTIPLICATOR; - } - return stepProgress; + return ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR; } - } diff --git a/ui/ui-frontend/projects/referential/src/app/file-format/file-format-create/file-format-create.component.html b/ui/ui-frontend/projects/referential/src/app/file-format/file-format-create/file-format-create.component.html index bf252ec8b..a19f57e7f 100644 --- a/ui/ui-frontend/projects/referential/src/app/file-format/file-format-create/file-format-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/file-format/file-format-create/file-format-create.component.html @@ -3,8 +3,7 @@ </div> <form [formGroup]="form" (ngSubmit)="onSubmit()"> - <vitamui-common-stepper (selectionChange)="stepIndex=$event.selectedIndex"> - + <vitamui-common-stepper (selectionChange)="stepIndex = $event.selectedIndex"> <cdk-step> <div class="content"> <h2 i18n="Create fileFormat title@@fileFormatCreateTitle1">Création d'un format</h2> @@ -15,16 +14,29 @@ <vitamui-common-input class="field-puid" formControlName="puid" - minlength="2" maxlength="100" + minlength="2" + maxlength="100" required - placeholder="External PUID" i18n-placeholder="puid@@fileformatCreatePuidPlaceholder" + placeholder="External PUID" + i18n-placeholder="puid@@fileformatCreatePuidPlaceholder" > <ng-container *ngIf="form.get('puid')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('puid')?.errors?.required" >{{'COMMON.REQUIRED' | translate}}</vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('puid')?.errors?.puidExists" i18n="Identfier exists error hint@@formErrorIdentifierExists">PUID déjà utilisé</vitamui-common-input-error> + <vitamui-common-input-error *ngIf="!!form.get('puid')?.errors?.required">{{ + 'COMMON.REQUIRED' | translate + }}</vitamui-common-input-error> + <vitamui-common-input-error + *ngIf="!!form?.get('puid')?.errors?.puidExists" + i18n="Identfier exists error hint@@formErrorIdentifierExists" + >PUID déjà utilisé</vitamui-common-input-error + > </ng-container> </vitamui-common-input> - <i class="material-icons field-tooltip select-tooltip" matTooltip="Identifiant du nouveau format ajouté" matTooltipClass="vitamui-tooltip">info</i> + <i + class="material-icons field-tooltip select-tooltip" + matTooltip="Identifiant du nouveau format ajouté" + matTooltipClass="vitamui-tooltip" + >info</i + > </div> <div class="d-flex"> @@ -32,13 +44,19 @@ <vitamui-common-input class="field-name" formControlName="name" - minlength="2" maxlength="100" + minlength="2" + maxlength="100" required - placeholder="Nom" i18n-placeholder="Name@@fileFormatCreateNamePlaceholder" + placeholder="Nom" + i18n-placeholder="Name@@fileFormatCreateNamePlaceholder" > <ng-container *ngIf="form.get('name')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('name')?.errors?.required" >{{'COMMON.REQUIRED' | translate}}</vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('name')?.errors?.nameExists" i18n="Name exists error hint@@formErrorNameExists">Nom déjà utilisé</vitamui-common-input-error> + <vitamui-common-input-error *ngIf="!!form.get('name')?.errors?.required">{{ + 'COMMON.REQUIRED' | translate + }}</vitamui-common-input-error> + <vitamui-common-input-error *ngIf="!!form?.get('name')?.errors?.nameExists" i18n="Name exists error hint@@formErrorNameExists" + >Nom déjà utilisé</vitamui-common-input-error + > </ng-container> </vitamui-common-input> <i class="material-icons field-tooltip select-tooltip" matTooltip="Format du fichier" matTooltipClass="vitamui-tooltip">info</i> @@ -49,9 +67,16 @@ <vitamui-common-input class="field-mimeType" formControlName="mimeType" - placeholder="Type MIME" i18n-placeholder="mimeType@@fileFormatCreateMimeTypePlaceholder"> + placeholder="Type MIME" + i18n-placeholder="mimeType@@fileFormatCreateMimeTypePlaceholder" + > </vitamui-common-input> - <i class="material-icons field-tooltip select-tooltip" matTooltip="Correspond à un format de fichier fourni par le registre PRONOM. Peut être vide" matTooltipClass="vitamui-tooltip">info</i> + <i + class="material-icons field-tooltip select-tooltip" + matTooltip="Correspond à un format de fichier fourni par le registre PRONOM. Peut être vide" + matTooltipClass="vitamui-tooltip" + >info</i + > </div> <div class="d-flex"> @@ -60,8 +85,12 @@ class="field-version" formControlName="version" required - placeholder="Version" i18n-placeholder="Version@@fileFormatCreateVersionPlaceholder"> - <vitamui-common-input-error *ngIf="form.get('version')?.touched && form.get('version')?.hasError('required')" >{{'COMMON.REQUIRED' | translate}}</vitamui-common-input-error> + placeholder="Version" + i18n-placeholder="Version@@fileFormatCreateVersionPlaceholder" + > + <vitamui-common-input-error *ngIf="form.get('version')?.touched && form.get('version')?.hasError('required')">{{ + 'COMMON.REQUIRED' | translate + }}</vitamui-common-input-error> </vitamui-common-input> </div> @@ -70,12 +99,16 @@ <vitamui-common-input class="field-extensions" formControlName="extensions" - placeholder="Extension" i18n-placeholder="Extension@@fileFormatCreateExtensionsPlaceholder"> + placeholder="Extension" + i18n-placeholder="Extension@@fileFormatCreateExtensionsPlaceholder" + > </vitamui-common-input> </div> - <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid || isCreationPending">{{'COMMON.SUBMIT' | translate}}</button> - <button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button> + <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid || isCreationPending || isDisabledButton"> + {{ 'COMMON.SUBMIT' | translate }} + </button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> </cdk-step> </vitamui-common-stepper> diff --git a/ui/ui-frontend/projects/referential/src/app/file-format/file-format-create/file-format-create.component.ts b/ui/ui-frontend/projects/referential/src/app/file-format/file-format-create/file-format-create.component.ts index cb1e67fa3..079ef2957 100644 --- a/ui/ui-frontend/projects/referential/src/app/file-format/file-format-create/file-format-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/file-format/file-format-create/file-format-create.component.ts @@ -34,32 +34,31 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -import {Component, Inject, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; -import {FILE_FORMAT_EXTERNAL_PREFIX, FileFormat} from 'projects/vitamui-library/src/public-api'; -import {Subscription} from 'rxjs'; -import {ConfirmDialogService} from 'ui-frontend-common'; - -import {FileFormatService} from '../file-format.service'; -import {FileFormatCreateValidators} from './file-format-create.validators'; +import { Component, Inject, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { FileFormat, FILE_FORMAT_EXTERNAL_PREFIX } from 'projects/vitamui-library/src/public-api'; +import { Subscription } from 'rxjs'; +import { ConfirmDialogService } from 'ui-frontend-common'; +import { FileFormatService } from '../file-format.service'; +import { FileFormatCreateValidators } from './file-format-create.validators'; const PROGRESS_BAR_MULTIPLICATOR = 100; @Component({ selector: 'app-file-format-create', templateUrl: './file-format-create.component.html', - styleUrls: ['./file-format-create.component.scss'] + styleUrls: ['./file-format-create.component.scss'], }) export class FileFormatCreateComponent implements OnInit, OnDestroy { - form: FormGroup; stepIndex = 0; - accessContractInfo: { code: string, name: string, companyName: string } = {code: '', name: '', companyName: ''}; + accessContractInfo: { code: string; name: string; companyName: string } = { code: '', name: '', companyName: '' }; hasCustomGraphicIdentity = false; hasError = true; message: string; isCreationPending = false; + isDisabledButton = false; // stepCount is the total number of steps and is used to calculate the advancement of the progress bar. // We could get the number of steps using ViewChildren(StepComponent) but this triggers a @@ -68,7 +67,7 @@ export class FileFormatCreateComponent implements OnInit, OnDestroy { private stepCount = 1; private keyPressSubscription: Subscription; - @ViewChild('fileSearch', {static: false}) fileSearch: any; + @ViewChild('fileSearch', { static: false }) fileSearch: any; constructor( public dialogRef: MatDialogRef<FileFormatCreateComponent>, @@ -77,8 +76,7 @@ export class FileFormatCreateComponent implements OnInit, OnDestroy { private confirmDialogService: ConfirmDialogService, private agencyService: FileFormatService, private fileFormatCreateValidators: FileFormatCreateValidators - ) { - } + ) {} ngOnInit() { this.form = this.formBuilder.group({ @@ -86,7 +84,7 @@ export class FileFormatCreateComponent implements OnInit, OnDestroy { puid: [null, Validators.required, this.fileFormatCreateValidators.uniquePuid()], version: [null, Validators.required], mimeType: [null], - extensions: [null] + extensions: [null], }); this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel()); @@ -106,9 +104,10 @@ export class FileFormatCreateComponent implements OnInit, OnDestroy { onSubmit() { if (this.form.invalid) { + this.isDisabledButton = true; return; } - + this.isDisabledButton = true; const format: FileFormat = this.form.value; format.puid = FILE_FORMAT_EXTERNAL_PREFIX + this.form.value.puid; if (this.form.value.extensions) { @@ -120,16 +119,17 @@ export class FileFormatCreateComponent implements OnInit, OnDestroy { this.isCreationPending = true; this.agencyService.create(format).subscribe( () => { - this.dialogRef.close({success: true}); + this.isDisabledButton = false; + this.dialogRef.close({ success: true }); }, (error: any) => { - this.dialogRef.close({success: false}); + this.dialogRef.close({ success: false }); console.error(error); - }); + } + ); } get stepProgress() { return ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR; } - } diff --git a/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.html b/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.html index c5aa95542..f1497b995 100644 --- a/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.html @@ -382,7 +382,9 @@ ></vitamui-library-filing-plan> </div> <div class="actions"> - <button type="submit" class="btn primary" [disabled]="seventhStepInvalid()">{{ 'COMMON.SUBMIT' | translate }}</button> + <button type="submit" class="btn primary" [disabled]="seventhStepInvalid() || isDisabledButton"> + {{ 'COMMON.SUBMIT' | translate }} + </button> <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> <button type="button" class="back" cdkStepperPrevious> diff --git a/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.ts b/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.ts index c2803647b..ecf271e88 100644 --- a/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.ts @@ -37,18 +37,17 @@ import { HttpHeaders, HttpParams } from '@angular/common/http'; import { Component, Inject, Input, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import '@angular/localize/init'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; import { FileFormat, FilingPlanMode, IngestContract } from 'projects/vitamui-library/src/public-api'; import { Subscription } from 'rxjs'; -import { ConfirmDialogService, Option, ExternalParametersService, ExternalParameters } from 'ui-frontend-common'; - +import { ConfirmDialogService, ExternalParameters, ExternalParametersService, Option } from 'ui-frontend-common'; import { ArchiveProfileApiService } from '../../core/api/archive-profile-api.service'; import { ManagementContractApiService } from '../../core/api/management-contract-api.service'; import { FileFormatService } from '../../file-format/file-format.service'; import { IngestContractService } from '../ingest-contract.service'; import { IngestContractCreateValidators } from './ingest-contract-create.validators'; -import '@angular/localize/init'; const PROGRESS_BAR_MULTIPLICATOR = 100; @@ -97,6 +96,7 @@ export class IngestContractCreateComponent implements OnInit, OnDestroy { formatTypeList: FileFormat[]; managementContracts: any[]; archiveProfiles: any[]; + isDisabledButton = false; usages: Option[] = [ { key: 'BinaryMaster', label: 'Original numérique', info: '' }, @@ -211,13 +211,14 @@ export class IngestContractCreateComponent implements OnInit, OnDestroy { } onSubmit() { - /*if (this.form.invalid) { return; }*/ + this.isDisabledButton = true; const ingestContract = this.form.value as IngestContract; ingestContract.status === 'ACTIVE' ? (ingestContract.activationDate = new Date().toISOString()) : (ingestContract.deactivationDate = new Date().toISOString()); this.ingestContractService.create(ingestContract).subscribe( () => { + this.isDisabledButton = false; this.dialogRef.close(true); }, (error) => { diff --git a/ui/ui-frontend/projects/referential/src/app/ontology/ontology-create/ontology-create.component.html b/ui/ui-frontend/projects/referential/src/app/ontology/ontology-create/ontology-create.component.html index ac3f89812..cd8218828 100644 --- a/ui/ui-frontend/projects/referential/src/app/ontology/ontology-create/ontology-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/ontology/ontology-create/ontology-create.component.html @@ -79,7 +79,8 @@ </div> </div> <div class="btn-container"> - <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid">{{'COMMON.SUBMIT' | translate}}</button> + + <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid || isDisabledButton">{{'COMMON.SUBMIT' | translate}}</button> <button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button> </div> </div> diff --git a/ui/ui-frontend/projects/referential/src/app/ontology/ontology-create/ontology-create.component.ts b/ui/ui-frontend/projects/referential/src/app/ontology/ontology-create/ontology-create.component.ts index 2056f657b..49f5e7e98 100644 --- a/ui/ui-frontend/projects/referential/src/app/ontology/ontology-create/ontology-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/ontology/ontology-create/ontology-create.component.ts @@ -34,30 +34,29 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -import {Component, Inject, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; -import {Subscription} from 'rxjs'; -import {ConfirmDialogService, Option} from 'ui-frontend-common'; - -import {OntologyService} from '../ontology.service'; -import {OntologyCreateValidators} from './ontology-create.validators'; +import { Component, Inject, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { Subscription } from 'rxjs'; +import { ConfirmDialogService, Option } from 'ui-frontend-common'; +import { OntologyService } from '../ontology.service'; +import { OntologyCreateValidators } from './ontology-create.validators'; const PROGRESS_BAR_MULTIPLICATOR = 100; @Component({ selector: 'app-ontology-create', templateUrl: './ontology-create.component.html', - styleUrls: ['./ontology-create.component.scss'] + styleUrls: ['./ontology-create.component.scss'], }) export class OntologyCreateComponent implements OnInit, OnDestroy { - form: FormGroup; stepIndex = 0; - accessContractInfo: { code: string, name: string, companyName: string } = {code: '', name: '', companyName: ''}; + accessContractInfo: { code: string; name: string; companyName: string } = { code: '', name: '', companyName: '' }; hasCustomGraphicIdentity = false; hasError = true; message: string; + isDisabledButton = false; // stepCount is the total number of steps and is used to calculate the advancement of the progress bar. // We could get the number of steps using ViewChildren(StepComponent) but this triggers a @@ -68,22 +67,22 @@ export class OntologyCreateComponent implements OnInit, OnDestroy { // FIXME: Get list from common var ? types: Option[] = [ - {key: 'DATE', label: 'Date', info: ''}, - {key: 'TEXT', label: 'Texte', info: ''}, - {key: 'KEYWORD', label: 'Mot clé', info: ''}, - {key: 'BOOLEAN', label: 'Boolean', info: ''}, - {key: 'LONG', label: 'Long', info: ''}, - {key: 'DOUBLE', label: 'Double', info: ''}, - {key: 'ENUM', label: 'Énumérer', info: ''}, - {key: 'GEO_POINT', label: 'Point Géographique', info: ''} + { key: 'DATE', label: 'Date', info: '' }, + { key: 'TEXT', label: 'Texte', info: '' }, + { key: 'KEYWORD', label: 'Mot clé', info: '' }, + { key: 'BOOLEAN', label: 'Boolean', info: '' }, + { key: 'LONG', label: 'Long', info: '' }, + { key: 'DOUBLE', label: 'Double', info: '' }, + { key: 'ENUM', label: 'Énumérer', info: '' }, + { key: 'GEO_POINT', label: 'Point Géographique', info: '' }, ]; collections: Option[] = [ - {key: 'Unit', label: 'Unité Archivistique', info: ''}, - {key: 'ObjectGroup', label: 'Groupe d\'objet', info: ''} + { key: 'Unit', label: 'Unité Archivistique', info: '' }, + { key: 'ObjectGroup', label: "Groupe d'objet", info: '' }, ]; - @ViewChild('fileSearch', {static: false}) fileSearch: any; + @ViewChild('fileSearch', { static: false }) fileSearch: any; constructor( public dialogRef: MatDialogRef<OntologyCreateComponent>, @@ -92,8 +91,7 @@ export class OntologyCreateComponent implements OnInit, OnDestroy { private confirmDialogService: ConfirmDialogService, private ontologyService: OntologyService, private ontologyCreateValidator: OntologyCreateValidators - ) { - } + ) {} ngOnInit() { this.form = this.formBuilder.group({ @@ -102,7 +100,7 @@ export class OntologyCreateComponent implements OnInit, OnDestroy { type: [null, Validators.required], collections: [null], description: [null], - origin: ['INTERNAL'] + origin: ['INTERNAL'], }); this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel()); @@ -122,20 +120,23 @@ export class OntologyCreateComponent implements OnInit, OnDestroy { onSubmit() { if (this.form.invalid) { + this.isDisabledButton = true; return; } + this.isDisabledButton = true; this.ontologyService.create(this.form.value).subscribe( () => { - this.dialogRef.close({success: true, action: 'none'}); + this.isDisabledButton = false; + this.dialogRef.close({ success: true, action: 'none' }); }, (error: any) => { - this.dialogRef.close({success: false, action: 'none'}); + this.dialogRef.close({ success: false, action: 'none' }); console.error(error); - }); + } + ); } get stepProgress() { return ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR; } - } diff --git a/ui/ui-frontend/projects/referential/src/app/probative-value/probative-value-create/probative-value-create.component.html b/ui/ui-frontend/projects/referential/src/app/probative-value/probative-value-create/probative-value-create.component.html index 088b7e6a5..26f38055d 100644 --- a/ui/ui-frontend/projects/referential/src/app/probative-value/probative-value-create/probative-value-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/probative-value/probative-value-create/probative-value-create.component.html @@ -4,29 +4,32 @@ <form [formGroup]="form" (ngSubmit)="onSubmit()" (keydown.enter)="$event.preventDefault()"> <vitamui-common-stepper> - <cdk-step> - <div class="content"> <h5>Relevé de valeur probante</h5> <h4>Unités archivistiques</h4> <div class="d-flex"> - <vitamui-common-input formControlName="unitId" minlength="36" maxlength="36" required placeholder="Identifiant" - i18n-placeholder="UnitId@@probativeValueCreateIdentifierPlaceholder"> + <vitamui-common-input + formControlName="unitId" + minlength="36" + maxlength="36" + required + placeholder="Identifiant" + i18n-placeholder="UnitId@@probativeValueCreateIdentifierPlaceholder" + > <ng-container *ngIf="form.get('unitId')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('unitId')?.errors?.required" - >{{'COMMON.REQUIRED' | translate}}</vitamui-common-input-error> - <ng-container *ngIf="form.get('unitId')?.errors?.minlength" > + <vitamui-common-input-error *ngIf="!!form.get('unitId')?.errors?.required">{{ + 'COMMON.REQUIRED' | translate + }}</vitamui-common-input-error> + <ng-container *ngIf="form.get('unitId')?.errors?.minlength"> <ng-template #minlengthErrorTemplate let-minlength="minlength"> <vitamui-common-input-error i18n="Minlength field error hint@@formErrorMinlengthField"> Le champ doit contenir au moins {{ minlength.requiredLength }} caractères </vitamui-common-input-error> </ng-template> - <ng-container *ngTemplateOutlet="minlengthErrorTemplate;context:form.get('unitId').errors"> - </ng-container> + <ng-container *ngTemplateOutlet="minlengthErrorTemplate; context: form.get('unitId').errors"> </ng-container> </ng-container> - </ng-container> </vitamui-common-input> </div> @@ -34,9 +37,8 @@ <div class="form-group"> <div class="col-8 form-control"> <mat-form-field class="vitamui-mat-select"> - <mat-select formControlName="usage" placeholder="Selectionner un usage" - panelclass="vitamui-mat-select" required> - <mat-option *ngFor='let usage of usages' [value]="usage.key">{{usage.label}}</mat-option> + <mat-select formControlName="usage" placeholder="Selectionner un usage" panelclass="vitamui-mat-select" required> + <mat-option *ngFor="let usage of usages" [value]="usage.key">{{ usage.label }}</mat-option> </mat-select> <div class="select-arrow"> <i class="material-icons">keyboard_arrow_up</i> @@ -47,20 +49,26 @@ </div> <div class="d-flex"> - <vitamui-common-input formControlName="version" min="0" required placeholder="Version" - type="number" i18n-placeholder="Version@@probativeValueCreateVersionPlaceholder"> + <vitamui-common-input + formControlName="version" + min="0" + required + placeholder="Version" + type="number" + i18n-placeholder="Version@@probativeValueCreateVersionPlaceholder" + > <ng-container *ngIf="form.get('version')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('version')?.errors?.required" - >{{'COMMON.REQUIRED' | translate}}</vitamui-common-input-error> + <vitamui-common-input-error *ngIf="!!form.get('version')?.errors?.required">{{ + 'COMMON.REQUIRED' | translate + }}</vitamui-common-input-error> </ng-container> </vitamui-common-input> </div> <div class="actions"> - <button type="submit" class="btn primary" [disabled]="form.invalid">{{'COMMON.SUBMIT' | translate}}</button> - <button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button> + <button type="submit" class="btn primary" [disabled]="form.invalid || isDisabledButton">{{ 'COMMON.SUBMIT' | translate }}</button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> - </div> </cdk-step> </vitamui-common-stepper> diff --git a/ui/ui-frontend/projects/referential/src/app/probative-value/probative-value-create/probative-value-create.component.ts b/ui/ui-frontend/projects/referential/src/app/probative-value/probative-value-create/probative-value-create.component.ts index 66755c652..a2ee5c818 100644 --- a/ui/ui-frontend/projects/referential/src/app/probative-value/probative-value-create/probative-value-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/probative-value/probative-value-create/probative-value-create.component.ts @@ -35,23 +35,23 @@ * knowledge of the CeCILL-C license and that you accept its terms. */ /* tslint:disable:object-literal-key-quotes quotemark */ -import {HttpHeaders} from '@angular/common/http'; -import {Component, Inject, OnInit} from '@angular/core'; -import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms'; -import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; -import {FilingPlanMode} from 'projects/vitamui-library/src/public-api'; -import {Subscription} from 'rxjs'; -import {ConfirmDialogService, Option, ExternalParametersService, ExternalParameters} from 'ui-frontend-common'; -import {ProbativeValueService} from '../probative-value.service'; -import {MatSnackBar} from '@angular/material/snack-bar'; +import { HttpHeaders } from '@angular/common/http'; +import { Component, Inject, OnInit } from '@angular/core'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import '@angular/localize/init'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { FilingPlanMode } from 'projects/vitamui-library/src/public-api'; +import { Subscription } from 'rxjs'; +import { ConfirmDialogService, ExternalParameters, ExternalParametersService, Option } from 'ui-frontend-common'; +import { ProbativeValueService } from '../probative-value.service'; const PROGRESS_BAR_MULTIPLICATOR = 100; @Component({ selector: 'app-probative-value-create', templateUrl: './probative-value-create.component.html', - styleUrls: ['./probative-value-create.component.scss'] + styleUrls: ['./probative-value-create.component.scss'], }) export class ProbativeValueCreateComponent implements OnInit { FILLING_PLAN_MODE_INCLUDE = FilingPlanMode.INCLUDE_ONLY; @@ -63,13 +63,14 @@ export class ProbativeValueCreateComponent implements OnInit { allNodes = new FormControl(true); selectedNodes = new FormControl(); accessContractId: string; + isDisabledButton = false; usages: Option[] = [ - {key: 'BinaryMaster', label: 'Archives numériques originales', info: ''}, - {key: 'Dissemination', label: 'Copies de diffusion', info: ''}, - {key: 'Thumbnail', label: 'Vignette', info: ''}, - {key: 'TextContent', label: 'Contenu textuel', info: ''}, - {key: 'PhysicalMaster', label: 'Archives physiques', info: ''} + { key: 'BinaryMaster', label: 'Archives numériques originales', info: '' }, + { key: 'Dissemination', label: 'Copies de diffusion', info: '' }, + { key: 'Thumbnail', label: 'Vignette', info: '' }, + { key: 'TextContent', label: 'Contenu textuel', info: '' }, + { key: 'PhysicalMaster', label: 'Archives physiques', info: '' }, ]; // stepCount is the total number of steps and is used to calculate the advancement of the progress bar. @@ -87,28 +88,29 @@ export class ProbativeValueCreateComponent implements OnInit { private probativeValueService: ProbativeValueService, private externalParameterService: ExternalParametersService, private snackBar: MatSnackBar - ) { - } + ) {} ngOnInit() { - this.externalParameterService.getUserExternalParameters().subscribe(parameters => { + this.externalParameterService.getUserExternalParameters().subscribe((parameters) => { const accessContratId: string = parameters.get(ExternalParameters.PARAM_ACCESS_CONTRACT); if (accessContratId && accessContratId.length > 0) { this.accessContractId = accessContratId; } else { this.snackBar.open( $localize`:access contrat not set message@@accessContratNotSetErrorMessage:Aucun contrat d'accès n'est associé à l'utiisateur`, - null, { + null, + { panelClass: 'vitamui-snack-bar', - duration: 10000 - }); + duration: 10000, + } + ); } }); this.form = this.formBuilder.group({ unitId: [null, Validators.required], usage: [null, Validators.required], - version: [null, Validators.required] + version: [null, Validators.required], }); this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel()); @@ -116,7 +118,7 @@ export class ProbativeValueCreateComponent implements OnInit { ngOnDestroy = () => { this.keyPressSubscription.unsubscribe(); - } + }; onCancel() { if (this.form.dirty) { @@ -128,19 +130,23 @@ export class ProbativeValueCreateComponent implements OnInit { onSubmit() { if (this.form.invalid) { + this.isDisabledButton = true; return; } + this.isDisabledButton = true; - this.probativeValueService.create( - this.createDsl(this.form.value), - new HttpHeaders({'X-Access-Contract-Id': this.accessContractId}) - ).subscribe( - () => { - this.dialogRef.close({success: true, action: 'none'}); - }, - () => { - this.dialogRef.close({success: false, action: 'none'}); - }); + this.probativeValueService + .create(this.createDsl(this.form.value), new HttpHeaders({ 'X-Access-Contract-Id': this.accessContractId })) + .subscribe( + () => { + this.isDisabledButton = false; + + this.dialogRef.close({ success: true, action: 'none' }); + }, + () => { + this.dialogRef.close({ success: false, action: 'none' }); + } + ); } get stepProgress() { @@ -148,23 +154,23 @@ export class ProbativeValueCreateComponent implements OnInit { } createDsl(values: any) { return { - "dslQuery": { - "$query": [ + dslQuery: { + $query: [ { - "$or": [ + $or: [ { - "$in": { - "#id": [values.unitId] - } - } - ] - } + $in: { + '#id': [values.unitId], + }, + }, + ], + }, ], - "$filter": {}, - "$projection": {} + $filter: {}, + $projection: {}, }, - "usage": values.usage, - "version": values.version + usage: values.usage, + version: values.version, }; } } diff --git a/ui/ui-frontend/projects/referential/src/app/rule/rule-create/rule-create.component.html b/ui/ui-frontend/projects/referential/src/app/rule/rule-create/rule-create.component.html index 51fd402e7..46d5227f9 100644 --- a/ui/ui-frontend/projects/referential/src/app/rule/rule-create/rule-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/rule/rule-create/rule-create.component.html @@ -3,37 +3,59 @@ </div> <form [formGroup]="form" (ngSubmit)="onSubmit()"> - <vitamui-common-stepper (selectionChange)="stepIndex=$event.selectedIndex"> - + <vitamui-common-stepper (selectionChange)="stepIndex = $event.selectedIndex"> <cdk-step> <div class="content"> <h2 i18n="Create rule title@@ruleCreateTitle1">Création d'une règle de gestion</h2> <h3 i18n="Create rule title@@ruleCreateTitle2">Informations</h3> <div class="row"> <div class="col-8 form-control"> - <vitamui-common-input class="field-ruleId" formControlName="ruleId" minlength="2" maxlength="100" required - placeholder="Identifiant" i18n-placeholder="Identifier@@ruleCreateRuleIdPlaceholder"> + <vitamui-common-input + class="field-ruleId" + formControlName="ruleId" + minlength="2" + maxlength="100" + required + placeholder="Identifiant" + i18n-placeholder="Identifier@@ruleCreateRuleIdPlaceholder" + > <ng-container *ngIf="form.get('ruleId')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('ruleId')?.errors?.required" - i18n="Required field error hint@@formErrorRequiredField">Champ requis</vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('ruleId')?.errors?.ruleIdExists" - i18n="Identfier exists error hint@@formErrorIdentifierExists">Identifiant déjà utilisé + <vitamui-common-input-error + *ngIf="!!form.get('ruleId')?.errors?.required" + i18n="Required field error hint@@formErrorRequiredField" + >Champ requis</vitamui-common-input-error + > + <vitamui-common-input-error + *ngIf="!!form?.get('ruleId')?.errors?.ruleIdExists" + i18n="Identfier exists error hint@@formErrorIdentifierExists" + >Identifiant déjà utilisé </vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('ruleId')?.errors?.ruleIdPattern" - i18n="Identfier pattern error hint@@formErrorIdentifierPattern">Identifiant non conforme + <vitamui-common-input-error + *ngIf="!!form?.get('ruleId')?.errors?.ruleIdPattern" + i18n="Identfier pattern error hint@@formErrorIdentifierPattern" + >Identifiant non conforme </vitamui-common-input-error> </ng-container> </vitamui-common-input> </div> - <i class="material-icons field-tooltip select-tooltip" matTooltip="L'identifiant est unique par type de règle. + <i + class="material-icons field-tooltip select-tooltip" + matTooltip="L'identifiant est unique par type de règle. Il ne doit pas comprendre d'espace ou de caractère accentué" - matTooltipClass="vitamui-tooltip">info</i> + matTooltipClass="vitamui-tooltip" + >info</i + > <div class="col-8 form-control"> <mat-form-field class="vitamui-mat-select"> - <mat-select formControlName="ruleType" placeholder="Type de règle" panelclass="vitamui-mat-select" - required="required" i18n-placeholder="Identifier@@ruleCreateRuleTypePlaceholder"> - <mat-option *ngFor='let ruleType of ruleTypes' [value]="ruleType.key">{{ruleType.label}}</mat-option> + <mat-select + formControlName="ruleType" + placeholder="Type de règle" + panelclass="vitamui-mat-select" + required="required" + i18n-placeholder="Identifier@@ruleCreateRuleTypePlaceholder" + > + <mat-option *ngFor="let ruleType of ruleTypes" [value]="ruleType.key">{{ ruleType.label }}</mat-option> </mat-select> <div class="select-arrow"> <i class="material-icons">keyboard_arrow_up</i> @@ -41,19 +63,34 @@ </div> </mat-form-field> </div> - <i class="material-icons field-tooltip select-tooltip" matTooltip="StorageRule : Durée d’utilité courante + <i + class="material-icons field-tooltip select-tooltip" + matTooltip="StorageRule : Durée d’utilité courante AppraisalRule : Durée d’utilité administrative AccessRule : Délai de communicabilité ReuseRule: Durée de réutilisation DisseminationRule : Délai de diffusion - ClassificationRule : Durée de classification" matTooltipClass="vitamui-tooltip">info</i> + ClassificationRule : Durée de classification" + matTooltipClass="vitamui-tooltip" + >info</i + > <div class="col-8 form-control"> - <vitamui-common-input class="field-ruleValue" formControlName="ruleValue" minlength="2" maxlength="100" - required placeholder="Intitulé de la règle" i18n-placeholder="Identifier@@ruleCreateRuleValuePlaceholder"> + <vitamui-common-input + class="field-ruleValue" + formControlName="ruleValue" + minlength="2" + maxlength="100" + required + placeholder="Intitulé de la règle" + i18n-placeholder="Identifier@@ruleCreateRuleValuePlaceholder" + > <ng-container *ngIf="form.get('ruleValue')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('ruleValue')?.errors?.required" - i18n="Required field error hint@@formErrorRequiredField">Champ requis</vitamui-common-input-error> + <vitamui-common-input-error + *ngIf="!!form.get('ruleValue')?.errors?.required" + i18n="Required field error hint@@formErrorRequiredField" + >Champ requis</vitamui-common-input-error + > </ng-container> </vitamui-common-input> </div> @@ -61,44 +98,71 @@ <div class="col-12 form-control"> <vitamui-common-textarea formControlName="ruleDescription" required placeholder="Description" [rows]="1"> <ng-container *ngIf="form.get('ruleDescription')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('ruleDescription')?.errors?.required" - i18n="Required field error hint@@formErrorRequiredField">Champ requis</vitamui-common-input-error> + <vitamui-common-input-error + *ngIf="!!form.get('ruleDescription')?.errors?.required" + i18n="Required field error hint@@formErrorRequiredField" + >Champ requis</vitamui-common-input-error + > </ng-container> </vitamui-common-textarea> </div> <div class="col-8 form-control d-flex"> - <vitamui-common-input class="field-ruleDuration" formControlName="ruleDuration" pattern="[0-9]*" - maxlength="3" required placeholder="Durée" i18n-placeholder="Identifier@@ruleCreateRuleValuePlaceholder"> + <vitamui-common-input + class="field-ruleDuration" + formControlName="ruleDuration" + pattern="[0-9]*" + maxlength="3" + required + placeholder="Durée" + i18n-placeholder="Identifier@@ruleCreateRuleValuePlaceholder" + > <ng-container *ngIf="form.get('ruleDuration')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('ruleDuration')?.errors?.required" - i18n="Required field error hint@@formErrorRequiredField">Champ requis</vitamui-common-input-error> + <vitamui-common-input-error + *ngIf="!!form.get('ruleDuration')?.errors?.required" + i18n="Required field error hint@@formErrorRequiredField" + >Champ requis</vitamui-common-input-error + > </ng-container> </vitamui-common-input> <mat-form-field class="vitamui-mat-select"> - <mat-select formControlName="ruleMeasurement" placeholder="Unité de mesure" - panelclass="vitamui-mat-select" required="required" - i18n-placeholder="Identifier@@ruleCreateRuleMeasurementPlaceholder"> - <mat-option *ngFor='let ruleMeasurement of ruleMeasurements' [value]="ruleMeasurement.key"> - {{ruleMeasurement.label}}</mat-option> + <mat-select + formControlName="ruleMeasurement" + placeholder="Unité de mesure" + panelclass="vitamui-mat-select" + required="required" + i18n-placeholder="Identifier@@ruleCreateRuleMeasurementPlaceholder" + > + <mat-option *ngFor="let ruleMeasurement of ruleMeasurements" [value]="ruleMeasurement.key"> + {{ ruleMeasurement.label }}</mat-option + > </mat-select> <div class="select-arrow"> <i class="material-icons">keyboard_arrow_up</i> <i class="material-icons">keyboard_arrow_down</i> </div> </mat-form-field> - <i class="material-icons field-tooltip select-tooltip" matTooltip="Jour + <i + class="material-icons field-tooltip select-tooltip" + matTooltip="Jour Mois - Année" matTooltipClass="vitamui-tooltip">info</i> + Année" + matTooltipClass="vitamui-tooltip" + >info</i + > </div> - </div> - <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid" - i18n="Finish rule creation button@@ruleCreateFinishButton">Terminer</button> - <button type="button" class="btn cancel" (click)="onCancel()" - i18n="Cancel rule creation@@ruleCreateCancelButton">Annuler</button> + <button + type="submit" + class="btn primary" + [disabled]="form.pending || form.invalid || isDisabledButton" + i18n="Finish rule creation button@@ruleCreateFinishButton" + > + Terminer + </button> + <button type="button" class="btn cancel" (click)="onCancel()" i18n="Cancel rule creation@@ruleCreateCancelButton">Annuler</button> </div> </cdk-step> </vitamui-common-stepper> -</form> \ No newline at end of file +</form> diff --git a/ui/ui-frontend/projects/referential/src/app/rule/rule-create/rule-create.component.ts b/ui/ui-frontend/projects/referential/src/app/rule/rule-create/rule-create.component.ts index ff196ab60..15c38d37a 100644 --- a/ui/ui-frontend/projects/referential/src/app/rule/rule-create/rule-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/rule/rule-create/rule-create.component.ts @@ -47,7 +47,7 @@ const PROGRESS_BAR_MULTIPLICATOR = 100; @Component({ selector: 'app-rule-create', templateUrl: './rule-create.component.html', - styleUrls: ['./rule-create.component.scss'] + styleUrls: ['./rule-create.component.scss'], }) export class RuleCreateComponent implements OnInit, OnDestroy { form: FormGroup; @@ -65,6 +65,7 @@ export class RuleCreateComponent implements OnInit, OnDestroy { ruleTypes = RULE_TYPES; ruleMeasurements = RULE_MEASUREMENTS; + isDisabledButton = false; @ViewChild('fileSearch', { static: false }) fileSearch: any; tenantIdentifier: number; @@ -85,7 +86,7 @@ export class RuleCreateComponent implements OnInit, OnDestroy { ruleValue: [null, Validators.required], ruleDescription: [null, Validators.required], ruleDuration: [null, Validators.required], - ruleMeasurement: [null, Validators.required] + ruleMeasurement: [null, Validators.required], }); this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel()); @@ -105,13 +106,17 @@ export class RuleCreateComponent implements OnInit, OnDestroy { onSubmit() { if (this.form.invalid) { + this.isDisabledButton = true; return; } const format: Rule = this.form.value; + this.isDisabledButton = true; this.ruleService.create(format).subscribe( () => { + this.isDisabledButton = false; + this.dialogRef.close({ success: true }); }, (error: any) => { diff --git a/ui/ui-frontend/projects/referential/src/app/security-profile/security-profile-create/security-profile-create.component.html b/ui/ui-frontend/projects/referential/src/app/security-profile/security-profile-create/security-profile-create.component.html index f0a845ae5..ac0f4789c 100644 --- a/ui/ui-frontend/projects/referential/src/app/security-profile/security-profile-create/security-profile-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/security-profile/security-profile-create/security-profile-create.component.html @@ -3,32 +3,52 @@ </div> <form [formGroup]="form" (ngSubmit)="onSubmit()"> - <vitamui-common-stepper (selectionChange)="stepIndex=$event.selectedIndex"> - + <vitamui-common-stepper (selectionChange)="stepIndex = $event.selectedIndex"> <cdk-step> <div class="content"> <h4 i18n="Create securityProfile title@@securityProfileCreateTitle1">Création d'un profil de sécurité</h4> <h5 i18n="Create securityProfile title@@securityProfileCreateTitle2">Informations</h5> <div class="d-flex"> - <vitamui-common-input formControlName="name" minlength="2" maxlength="100" required - placeholder="Nom" i18n-placeholder="Name@@profileGroupCreateNamePlaceholder"> + <vitamui-common-input + formControlName="name" + minlength="2" + maxlength="100" + required + placeholder="Nom" + i18n-placeholder="Name@@profileGroupCreateNamePlaceholder" + > <ng-container *ngIf="form.get('name')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('name')?.errors?.required" - >{{'COMMON.REQUIRED' | translate}}</vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('name')?.errors?.nameExists" - i18n="Name exists error hint@@formErrorNameExists">Nom déjà utilisé</vitamui-common-input-error> + <vitamui-common-input-error *ngIf="!!form.get('name')?.errors?.required">{{ + 'COMMON.REQUIRED' | translate + }}</vitamui-common-input-error> + <vitamui-common-input-error *ngIf="!!form?.get('name')?.errors?.nameExists" i18n="Name exists error hint@@formErrorNameExists" + >Nom déjà utilisé</vitamui-common-input-error + > </ng-container> </vitamui-common-input> </div> <div class="d-flex" *ngIf="isSlaveMode"> - <vitamui-common-input formControlName="identifier" minlength="2" maxlength="100" required placeholder="Identifiant" i18n-placeholder="Identifier@@contextCreateIdentifierPlaceholder"> + <vitamui-common-input + formControlName="identifier" + minlength="2" + maxlength="100" + required + placeholder="Identifiant" + i18n-placeholder="Identifier@@contextCreateIdentifierPlaceholder" + > <ng-container *ngIf="form.get('identifier')?.touched"> - <vitamui-common-input-error *ngIf="!!form.get('identifier')?.errors?.required" - i18n="Required field error hint@@formErrorRequiredField">Champ requis</vitamui-common-input-error> - <vitamui-common-input-error *ngIf="!!form?.get('identifier')?.errors?.identifierExists" - i18n="Name exists error hint@@formErrorIdentifierExists">Identifiant déjà utilisé</vitamui-common-input-error> + <vitamui-common-input-error + *ngIf="!!form.get('identifier')?.errors?.required" + i18n="Required field error hint@@formErrorRequiredField" + >Champ requis</vitamui-common-input-error + > + <vitamui-common-input-error + *ngIf="!!form?.get('identifier')?.errors?.identifierExists" + i18n="Name exists error hint@@formErrorIdentifierExists" + >Identifiant déjà utilisé</vitamui-common-input-error + > </ng-container> </vitamui-common-input> </div> @@ -37,13 +57,33 @@ <vitamui-common-slide-toggle formControlName="fullAccess"> <span *ngIf="!form.controls.fullAccess.value">Gérer</span><span *ngIf="form.controls.fullAccess.value">Tous</span> les accès </vitamui-common-slide-toggle> - <i class="material-icons field-tooltip" matTooltip="Droits auquels le profil de sécurité donne accès" matTooltipClass="vitamui-tooltip">info</i> + <i + class="material-icons field-tooltip" + matTooltip="Droits auquels le profil de sécurité donne accès" + matTooltipClass="vitamui-tooltip" + >info</i + > </div> <div class="btn-container"> - <button type="button" class="btn primary" cdkStepperNext [disabled]="firstStepInvalid()" *ngIf="!form.value.fullAccess">{{'COMMON.NEXT' | translate}}</button> - <button type="button" class="btn primary" (click)="finishAfterFirstStep()" *ngIf="form.value.fullAccess" - [disabled]="form.pending || form.invalid">{{'COMMON.SUBMIT' | translate}}</button> - <button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button> + <button + type="button" + class="btn primary" + cdkStepperNext + [disabled]="firstStepInvalid() || isDisabledButton" + *ngIf="!form.value.fullAccess" + > + {{ 'COMMON.NEXT' | translate }} + </button> + <button + type="button" + class="btn primary" + (click)="finishAfterFirstStep()" + *ngIf="form.value.fullAccess" + [disabled]="form.pending || form.invalid || isDisabledButton" + > + {{ 'COMMON.SUBMIT' | translate }} + </button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> </div> </cdk-step> @@ -56,12 +96,14 @@ <app-security-profile-edit-permission formControlName="permissions"></app-security-profile-edit-permission> <div class="actions"> - <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid">{{'COMMON.SUBMIT' | translate}}</button> - <button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button> + <button type="submit" class="btn primary" [disabled]="form.pending || form.invalid || isDisabledButton"> + {{ 'COMMON.SUBMIT' | translate }} + </button> + <button type="button" class="btn cancel" (click)="onCancel()">{{ 'COMMON.UNDO' | translate }}</button> </div> <button type="button" class="back" cdkStepperPrevious> <i class="material-icons">arrow_back</i> - <ng-container>{{'COMMON.BACK' | translate}}</ng-container> + <ng-container>{{ 'COMMON.BACK' | translate }}</ng-container> </button> </div> </cdk-step> diff --git a/ui/ui-frontend/projects/referential/src/app/security-profile/security-profile-create/security-profile-create.component.ts b/ui/ui-frontend/projects/referential/src/app/security-profile/security-profile-create/security-profile-create.component.ts index ee622c261..03e530c3b 100644 --- a/ui/ui-frontend/projects/referential/src/app/security-profile/security-profile-create/security-profile-create.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/security-profile/security-profile-create/security-profile-create.component.ts @@ -34,29 +34,27 @@ * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ -import {Subscription} from 'rxjs'; -import {ConfirmDialogService} from 'ui-frontend-common'; - -import {Component, Inject, OnDestroy, OnInit, ViewChild, Input} from '@angular/core'; -import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; -import {SecurityProfileService} from '../security-profile.service'; -import {SecurityProfileCreateValidators} from './security-profile-create.validators'; +import { Component, Inject, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { Subscription } from 'rxjs'; +import { ConfirmDialogService } from 'ui-frontend-common'; +import { SecurityProfileService } from '../security-profile.service'; +import { SecurityProfileCreateValidators } from './security-profile-create.validators'; const PROGRESS_BAR_MULTIPLICATOR = 100; @Component({ selector: 'app-security-profile-create', templateUrl: './security-profile-create.component.html', - styleUrls: ['./security-profile-create.component.scss'] + styleUrls: ['./security-profile-create.component.scss'], }) export class SecurityProfileCreateComponent implements OnInit, OnDestroy { - @Input() isSlaveMode: boolean; form: FormGroup; - stepIndex = 0; - accessContractInfo: { code: string, name: string, companyName: string } = {code: '', name: '', companyName: ''}; + stepIndex = 1; + accessContractInfo: { code: string; name: string; companyName: string } = { code: '', name: '', companyName: '' }; hasCustomGraphicIdentity = false; hasError = true; message: string; @@ -67,8 +65,9 @@ export class SecurityProfileCreateComponent implements OnInit, OnDestroy { // Make sure to update this value whenever you add or remove a step from the template. private stepCount = 2; private keyPressSubscription: Subscription; + isDisabledButton = false; - @ViewChild('fileSearch', {static: false}) fileSearch: any; + @ViewChild('fileSearch', { static: false }) fileSearch: any; constructor( public dialogRef: MatDialogRef<SecurityProfileCreateComponent>, @@ -77,8 +76,7 @@ export class SecurityProfileCreateComponent implements OnInit, OnDestroy { private confirmDialogService: ConfirmDialogService, private securityProfileService: SecurityProfileService, private securityProfileCreateValidators: SecurityProfileCreateValidators - ) { - } + ) {} ngOnInit() { this.form = this.formBuilder.group({ @@ -116,26 +114,32 @@ export class SecurityProfileCreateComponent implements OnInit, OnDestroy { onSubmit() { if (this.form.invalid) { + this.isDisabledButton = true; return; } - // TODO : Create ! + this.isDisabledButton = true; this.securityProfileService.create(this.form.value).subscribe( () => { - this.dialogRef.close({success: true, action: 'none'}); + this.isDisabledButton = false; + this.dialogRef.close({ success: true, action: 'none' }); }, (error: any) => { - this.dialogRef.close({success: false, action: 'none'}); + this.dialogRef.close({ success: false, action: 'none' }); console.error(error); - }); + } + ); } firstStepInvalid(): boolean { - return this.form.get('name').invalid || this.form.get('name').pending || - this.form.get('fullAccess').invalid || this.form.get('fullAccess').pending; + return ( + this.form.get('name').invalid || + this.form.get('name').pending || + this.form.get('fullAccess').invalid || + this.form.get('fullAccess').pending + ); } get stepProgress() { return ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR; } - } diff --git a/ui/ui-frontend/projects/referential/src/assets/i18n/en.json b/ui/ui-frontend/projects/referential/src/assets/i18n/en.json index d87e2fc79..5b92e9f88 100644 --- a/ui/ui-frontend/projects/referential/src/assets/i18n/en.json +++ b/ui/ui-frontend/projects/referential/src/assets/i18n/en.json @@ -3,7 +3,8 @@ "CANCEL": "Cancel", "SUBMIT": "Confirm", "UPDATE": "Update", - "APPLY_UPDATE": "Apply changes" + "APPLY_UPDATE": "Apply changes", + "REQUIRED" : "Required field" }, "LOGBOOK_OPERATION_LIST": { "NO_RESULTS" : "End of results", diff --git a/ui/ui-frontend/projects/referential/src/assets/i18n/fr.json b/ui/ui-frontend/projects/referential/src/assets/i18n/fr.json index b5158a6e4..a2253f0ad 100644 --- a/ui/ui-frontend/projects/referential/src/assets/i18n/fr.json +++ b/ui/ui-frontend/projects/referential/src/assets/i18n/fr.json @@ -3,7 +3,8 @@ "CANCEL": "Annuler", "SUBMIT": "Confirmer", "UPDATE": "Modifier", - "APPLY_UPDATE": "Appliquer les modifications " + "APPLY_UPDATE": "Appliquer les modifications ", + "REQUIRED" : "Champ requis" }, "LOGBOOK_OPERATION_LIST": { "NO_RESULTS" : "Fin des résultats", -- GitLab