Skip to content
Snippets Groups Projects
Commit 5bf884c1 authored by Benaissa BENARBIA's avatar Benaissa BENARBIA
Browse files

Revert "TULEAP-24200: Fix context creation steps, date and style"

This reverts commit 7191d1bdd92063974e899f5d0dba2c4a459734fa.
parent 115470d6
No related branches found
No related tags found
1 merge request!51Merge mis a jour vitam-ui
......@@ -21,7 +21,7 @@
i18n-placeholder="Name@@contextCreateNamePlaceholder">
<ng-container *ngIf="form.get('name')?.touched">
<vitamui-common-input-error *ngIf="!!form.get('name')?.errors?.required"
>{{'COMMON.REQUIRED' | translate}}</vitamui-common-input-error>
i18n="Required field error hint@@formErrorRequiredField">Champ requis</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>
......@@ -69,15 +69,10 @@
</div>
<div class="actions">
<button *ngIf="form?.controls.enableControl?.value === true"
type="button" class="btn primary" cdkStepperNext
[disabled]="firstStepInvalid()"
i18n="Next step button label@@contextCreateNextButton">{{'COMMON.NEXT' | translate}}</button>
<button *ngIf="form?.controls.enableControl?.value === false"
type="submit" class="btn primary"
[disabled]="firstStepInvalid()"
i18n="Finish context creation button@@contextCreateFinishButton">Terminer</button>
<button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button>
<button type="button" class="btn primary" cdkStepperNext [disabled]="firstStepInvalid()"
i18n="Next step button label@@contextCreateNextButton">Suivant</button>
<button type="button" class="btn cancel" (click)="onCancel()"
i18n="Cancel context creation@@contextCreateCancelButton">Annuler</button>
</div>
</div>
</cdk-step>
......@@ -102,14 +97,13 @@
</ng-container>
</div>
<div class="actions">
<button type="submit" class="btn primary" [disabled]="lastStepInvalid()"
i18n="Finish context creation button@@contextCreateFinishButton">{{'COMMON.SUBMIT' | translate}}</button>
<button type="button" class="btn cancel" (click)="onCancel()">{{'COMMON.UNDO' | translate}}</button>
</div>
<button type="submit" class="btn primary" [disabled]="lastStepInvalid()"
i18n="Finish context creation button@@contextCreateFinishButton">Terminer</button>
<button type="button" class="btn cancel" (click)="onCancel()"
i18n="Cancel context creation@@contextCreateCancelButton">Annuler</button>
<button type="button" class="back" cdkStepperPrevious>
<i class="material-icons">arrow_back</i>
<ng-container>{{'COMMON.BACK' | translate}}</ng-container>
<ng-container i18n="Previous step button label@@contextCreateBackButton">Retour</ng-container>
</button>
</div>
</cdk-step>
......
......@@ -34,48 +34,47 @@
* 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,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 {ContextPermission} from 'projects/vitamui-library/src/public-api';
import {Subscription} from 'rxjs';
import {AuthService,ConfirmDialogService,Option} from 'ui-frontend-common';
import {Context} from '../../../../../vitamui-library/src/lib/models/context';
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';
const PROGRESS_BAR_MULTIPLICATOR=100;
const PROGRESS_BAR_MULTIPLICATOR = 100;
@Component({
selector: 'app-context-create',
templateUrl: './context-create.component.html',
styleUrls: ['./context-create.component.scss']
})
export class ContextCreateComponent implements OnInit,OnDestroy {
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: ''};
hasCustomGraphicIdentity=false;
hasError=true;
statusControl = new FormControl(false);
stepIndex = 0;
accessContractInfo: {code: string, name: string, companyName: string} = {code: '', name: '', companyName: ''};
hasCustomGraphicIdentity = false;
hasError = true;
message: string;
isPermissionsOnMultipleOrganisations=false;
isPermissionsOnMultipleOrganisations = 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
// "Expression has changed after it was checked" error so we instead manually define the value.
// Make sure to update this value whenever you add or remove a step from the template.
private stepCount=2;
private stepCount = 2;
private keyPressSubscription: Subscription;
@ViewChild('fileSearch',{static: false}) fileSearch: any;
@ViewChild('fileSearch', {static: false}) fileSearch: any;
securityProfiles: Option[] = [];
securityProfiles: Option[]=[];
constructor(
public dialogRef: MatDialogRef<ContextCreateComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
......@@ -83,47 +82,36 @@ export class ContextCreateComponent implements OnInit,OnDestroy {
private confirmDialogService: ConfirmDialogService,
private contextService: ContextService,
private contextCreateValidators: ContextCreateValidators,
private securityProfileService: SecurityProfileService,
private authService: AuthService
private securityProfileService: SecurityProfileService
) {
}
ngOnInit() {
this.form=this.formBuilder.group({
this.form = this.formBuilder.group({
status: ['INACTIVE'],
name: [null,Validators.required,this.contextCreateValidators.uniqueName()],
identifier: [null,Validators.required,this.contextCreateValidators.uniqueIdentifier()],
securityProfile: [null,Validators.required],
name: [null, Validators.required, this.contextCreateValidators.uniqueName()],
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, this.contextCreateValidators.permissionInvalid()]
});
this.form.controls.name.valueChanges.subscribe((value) => {
if(!this.isSlaveMode) {
if (!this.isSlaveMode) {
this.form.controls.identifier.setValue(value);
}
});
this.statusControl.valueChanges.subscribe((value) => {
this.form.controls.status.setValue(value=(value===false)? 'INACTIVE':'ACTIVE');
});
// Add or remove controls on the permissions
this.form.controls.enableControl.valueChanges.subscribe((value) => {
if(value) {
this.form.controls.permissions.setAsyncValidators([this.contextCreateValidators.permissionInvalid()]);
} else {
this.form.controls.permissions.clearAsyncValidators();
}
this.form.controls.permissions.updateValueAndValidity(this.form.controls.permissions.value);
this.form.controls.status.setValue(value = (value === false) ? 'INACTIVE' : 'ACTIVE');
});
this.securityProfileService.getAll().subscribe(
securityProfiles => {
this.securityProfiles=securityProfiles.map(x => ({label: x.name,key: x.identifier}));
this.securityProfiles = securityProfiles.map(x => ({label: x.name, key: x.identifier}));
});
this.keyPressSubscription=this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel());
this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel());
}
ngOnDestroy() {
......@@ -131,7 +119,7 @@ export class ContextCreateComponent implements OnInit,OnDestroy {
}
onCancel() {
if(this.form.dirty) {
if (this.form.dirty) {
this.confirmDialogService.confirmBeforeClosing(this.dialogRef);
} else {
this.dialogRef.close();
......@@ -139,45 +127,25 @@ export class ContextCreateComponent implements OnInit,OnDestroy {
}
onSubmit() {
if(this.form.invalid) {
if (this.form.invalid) {
return;
}
let context=this.form.value as Context;
if(context.permissions.length==1) {
if(context.permissions[0].tenant==null) {
this.fillContextPermissions(context);
}
}
context.status==='ACTIVE'? context.activationDate=new Date().toISOString():context.deactivationDate=new Date().toISOString();
this.contextService.create(context).subscribe(
this.contextService.create(this.form.value).subscribe(
() => {
this.dialogRef.close({success: true,action: 'none'});
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);
});
}
fillContextPermissions(context: Context): Context {
const permission: ContextPermission={
tenant: this.authService.user.proofTenantIdentifier,
accessContracts: [],
ingestContracts: []
}
context.permissions.pop();
context.permissions.push(permission);
return context;
}
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() {
......@@ -185,15 +153,15 @@ export class ContextCreateComponent implements OnInit,OnDestroy {
}
onChangeOrganisations(organisations: string[]) {
this.isPermissionsOnMultipleOrganisations=false;
if(organisations&&organisations.length>1) {
let idx=0;
let organisationId: string=null;
while(idx<organisations.length&&!this.isPermissionsOnMultipleOrganisations) {
if(idx===0) {
organisationId=organisations[0];
} else if(organisations[idx]!=null&&organisations[idx]!==organisationId) {
this.isPermissionsOnMultipleOrganisations=true;
this.isPermissionsOnMultipleOrganisations = false;
if (organisations && organisations.length > 1) {
let idx = 0;
let organisationId: string = null;
while (idx < organisations.length && !this.isPermissionsOnMultipleOrganisations) {
if (idx === 0) {
organisationId = organisations[0];
} else if (organisations[idx] != null && organisations[idx] !== organisationId) {
this.isPermissionsOnMultipleOrganisations = true;
}
idx++;
}
......@@ -201,14 +169,7 @@ 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;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment