Deactivate Guard on dataset template editor

This commit is contained in:
Kristian Ntavidi 2021-07-23 17:03:29 +03:00
parent 1be8e8e8f9
commit 06961c0254
9 changed files with 33 additions and 15 deletions

View File

@ -30,7 +30,7 @@ export class CanDeactivateGuard extends BaseComponent implements CanDeactivate<C
warning: this.language.instant('GENERAL.CONFIRMATION-DIALOG.LEAVE-WARNING'), warning: this.language.instant('GENERAL.CONFIRMATION-DIALOG.LEAVE-WARNING'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'), cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.LEAVE'), confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.LEAVE'),
icon: 'error_outline' // icon: 'error_outline'
} }
}); });
return dialogRef.afterClosed().pipe(map(x => x ? true : false)); return dialogRef.afterClosed().pipe(map(x => x ? true : false));

View File

@ -5,6 +5,7 @@ import { DatasetProfileListingComponent } from './listing/dataset-profile-listin
import { AdminAuthGuard } from '@app/core/admin-auth-guard.service'; import { AdminAuthGuard } from '@app/core/admin-auth-guard.service';
import { AppRole } from '@app/core/common/enum/app-role'; import { AppRole } from '@app/core/common/enum/app-role';
import { SpecialAuthGuard } from '@app/core/special-auth-guard.service'; import { SpecialAuthGuard } from '@app/core/special-auth-guard.service';
import { CanDeactivateGuard } from '@app/library/deactivate/can-deactivate.guard';
const routes: Routes = [ const routes: Routes = [
{ {
@ -16,7 +17,8 @@ const routes: Routes = [
permissions: [AppRole.Admin, AppRole.DatasetTemplateEditor] permissions: [AppRole.Admin, AppRole.DatasetTemplateEditor]
} }
}, },
canActivate: [SpecialAuthGuard] canActivate: [SpecialAuthGuard],
canDeactivate:[CanDeactivateGuard]
}, },
{ {
path: ':id', path: ':id',
@ -27,7 +29,8 @@ const routes: Routes = [
permissions: [AppRole.Admin, AppRole.DatasetTemplateEditor] permissions: [AppRole.Admin, AppRole.DatasetTemplateEditor]
} }
}, },
canActivate: [SpecialAuthGuard] canActivate: [SpecialAuthGuard],
canDeactivate:[CanDeactivateGuard]
}, },
{ {
path: 'clone/:cloneid', path: 'clone/:cloneid',
@ -38,7 +41,8 @@ const routes: Routes = [
permissions: [AppRole.Admin, AppRole.DatasetTemplateEditor] permissions: [AppRole.Admin, AppRole.DatasetTemplateEditor]
} }
}, },
canActivate: [SpecialAuthGuard] canActivate: [SpecialAuthGuard],
canDeactivate:[CanDeactivateGuard]
}, },
{ {
path: 'newversion/:newversionid', path: 'newversion/:newversionid',
@ -49,7 +53,8 @@ const routes: Routes = [
permissions: [AppRole.Admin, AppRole.DatasetTemplateEditor] permissions: [AppRole.Admin, AppRole.DatasetTemplateEditor]
} }
}, },
canActivate: [SpecialAuthGuard] canActivate: [SpecialAuthGuard],
canDeactivate:[CanDeactivateGuard]
}, },
{ {
path: 'versions/:groupId', path: 'versions/:groupId',

View File

@ -83,7 +83,7 @@ export const GENERAL_ANIMATIONS = [
transition(":enter", [style({opacity:0}), animate('1000ms 800ms ease', style({'opacity':1}))]), transition(":enter", [style({opacity:0}), animate('1000ms 800ms ease', style({'opacity':1}))]),
]), ]),
trigger('fade-in-fast',[ trigger('fade-in-fast',[
transition(":enter", [style({opacity:0}), animate('1000ms 200ms ease', style({'opacity':1}))]), transition(":enter", [style({opacity:0}), animate('800ms 100ms ease', style({'opacity':1}))]),
]), ]),

View File

@ -364,7 +364,8 @@ export class DatasetProfileEditorCompositeFieldComponent extends BaseComponent i
fieldsForm.controls.forEach((field, idx)=>{ fieldsForm.controls.forEach((field, idx)=>{
field.get('ordinal').setValue(idx); field.get('ordinal').setValue(idx);
field.updateValueAndValidity(); field.updateValueAndValidity();
}) });
this.form.markAsDirty();//deactivate guard
} }
getFieldTile(formGroup: FormGroup, index: number) { getFieldTile(formGroup: FormGroup, index: number) {

View File

@ -794,7 +794,7 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements
validationsControl.setValue(validations.filter(validator=> validator != ValidationType.Required)); validationsControl.setValue(validations.filter(validator=> validator != ValidationType.Required));
validationsControl.updateValueAndValidity(); validationsControl.updateValueAndValidity();
} }
this.form.markAsDirty();//deactivate guard
} }
get isRequired(){ get isRequired(){

View File

@ -42,6 +42,7 @@ export class DatasetProfileEditorRuleComponent implements OnInit {
deleteRule(index) { deleteRule(index) {
this.form.removeAt(index); this.form.removeAt(index);
this.form.markAsDirty();//deactivate guard
} }
ngOnInit(): void { ngOnInit(): void {

View File

@ -44,6 +44,7 @@ import { GENERAL_ANIMATIONS, STEPPER_ANIMATIONS } from './animations/animations'
import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type'; import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type';
import { UserService } from '@app/core/services/user/user.service'; import { UserService } from '@app/core/services/user/user.service';
import { MatInput } from '@angular/material'; import { MatInput } from '@angular/material';
import { CheckDeactivateBaseComponent } from '@app/library/deactivate/deactivate.component';
const skipDisable: any[] = require('../../../../../assets/resources/skipDisable.json'); const skipDisable: any[] = require('../../../../../assets/resources/skipDisable.json');
@ -55,7 +56,10 @@ const skipDisable: any[] = require('../../../../../assets/resources/skipDisable.
animations:[...STEPPER_ANIMATIONS, ...GENERAL_ANIMATIONS], animations:[...STEPPER_ANIMATIONS, ...GENERAL_ANIMATIONS],
providers:[VisibilityRulesService] providers:[VisibilityRulesService]
}) })
export class DatasetProfileEditorComponent extends BaseComponent implements OnInit { export class DatasetProfileEditorComponent extends CheckDeactivateBaseComponent implements OnInit {
canDeactivate(): boolean {
return !this.form.dirty;
}
isNew = true; isNew = true;
isNewVersion = false; isNewVersion = false;
@ -425,6 +429,7 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
this.datasetProfileService.updateForm(this.datasetProfileId, data) this.datasetProfileService.updateForm(this.datasetProfileId, data)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(() => { .subscribe(() => {
this.form.markAsPristine();//deactivate guard
this.router.navigate(['/dataset-profiles']); this.router.navigate(['/dataset-profiles']);
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success); this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success);
},error=> this.onCallbackError(error)); },error=> this.onCallbackError(error));
@ -434,6 +439,7 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
this.datasetProfileService.newVersion(this.newVersionId, data) this.datasetProfileService.newVersion(this.newVersionId, data)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(() => { .subscribe(() => {
this.form.markAsPristine();//deactivate guard
this.router.navigate(['/dataset-profiles']); this.router.navigate(['/dataset-profiles']);
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success); this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success);
}, },
@ -447,6 +453,7 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
this.datasetProfileService.createForm(data) this.datasetProfileService.createForm(data)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(() => { .subscribe(() => {
this.form.markAsPristine();//deactivate guard
this.router.navigate(['/dataset-profiles']); this.router.navigate(['/dataset-profiles']);
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success); this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.FEEDBACK-MESSAGES.SAVE-SUCCESS'), SnackBarNotificationLevel.Success);
}, error=> this.onCallbackError(error)); }, error=> this.onCallbackError(error));
@ -1183,7 +1190,8 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
//in case selectedtocentrhy is child of the removed element //in case selectedtocentrhy is child of the removed element
this.refreshToCEntries(); // this.refreshToCEntries();
this.onDataNeedsRefresh();
this.form.updateValueAndValidity(); this.form.updateValueAndValidity();
} }
@ -1572,6 +1580,7 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
this.displayItem(this._findTocEntryById(params.draggedItemId, tocentries)); this.displayItem(this._findTocEntryById(params.draggedItemId, tocentries));
} }
} }
this.form.markAsDirty();
} }
cloneFieldSet(fieldset: FormGroup){ cloneFieldSet(fieldset: FormGroup){
@ -1944,6 +1953,7 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
email.value = ''; email.value = '';
this.userFormDisabled = false; this.userFormDisabled = false;
this.form.markAsDirty();
// email.focus(); // email.focus();
// this.inputUserState = 'triggered'; // this.inputUserState = 'triggered';

View File

@ -1,14 +1,14 @@
<div class="confirmation-dialog"> <div class="confirmation-dialog">
<div *ngIf="data.icon" class="row d-flex flex-row"> <div class="row d-flex flex-row" *ngIf="data.icon || data.warning">
<div class="col-auto close-btn justify-content-start"> <div class="col-auto close-btn justify-content-start" *ngIf="data.icon">
<mat-icon color="warn">{{ data.icon }}</mat-icon> <mat-icon color="warn">{{ data.icon }}</mat-icon>
</div> </div>
<div *ngIf="data.warning" class="col justify-content-center warn-text">{{ data.warning }}</div> <div *ngIf="data.warning" class="col justify-content-center warn-text"> <h5><strong>{{ data.warning }}</strong></h5></div>
<div class="col-auto close-btn justify-content-end" (click)="close()"> <div class="col-auto close-btn justify-content-end" (click)="close()">
<mat-icon>close</mat-icon> <mat-icon>close</mat-icon>
</div> </div>
</div> </div>
<div class="row justify-content-end mb-1" *ngIf="!data.icon"> <div class="row justify-content-end mb-1" *ngIf="!data.icon && !data.warning">
<div class="col-auto close-btn" (click)="close()"> <div class="col-auto close-btn" (click)="close()">
<mat-icon>close</mat-icon> <mat-icon>close</mat-icon>
</div> </div>

View File

@ -14,7 +14,8 @@
} }
.warn-text { .warn-text {
color: #f44336; // color: #f44336;
} }
.cancel { .cancel {