Commit b61e7000 authored by oussamasic's avatar oussamasic Committed by vitam-prg
Browse files

correct referential applications creation button issue

parent d26c990e
......@@ -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>
......
......@@ -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;
}
}
......@@ -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>