Adds discard on dataset editor (1st commit)

This commit is contained in:
apapachristou 2020-09-18 18:51:42 +03:00
parent bcdaf144d2
commit e7db9ee664
3 changed files with 37 additions and 11 deletions

View File

@ -55,7 +55,7 @@
<div class="heading">1.5 {{'DATASET-EDITOR.FIELDS.PROFILE' | translate}}*</div> <div class="heading">1.5 {{'DATASET-EDITOR.FIELDS.PROFILE' | translate}}*</div>
<div class="profile-form"> <div class="profile-form">
<mat-form-field> <mat-form-field>
<mat-select placeholder="{{'DATASET-WIZARD.FIRST-STEP.PROFILE'| translate}}" [required]="true" [compareWith]="compareWith" [formControl]="formGroup.get('profile')"> <mat-select placeholder="{{'DATASET-WIZARD.FIRST-STEP.PROFILE'| translate}}" [required]="true" [compareWith]="compareWith" formControlName="profile">
<mat-option *ngFor="let profile of availableProfiles" [value]="profile"> <mat-option *ngFor="let profile of availableProfiles" [value]="profile">
{{profile.label}} {{profile.label}}
</mat-option> </mat-option>

View File

@ -76,8 +76,8 @@
</div> </div>
</div> </div>
<div class="col-auto form"> <div class="col-auto form">
<app-dataset-editor-component [hidden]="this.step !== 0" [formGroup]="formGroup" [dmpId]="formGroup.get('dmp').value.id" [availableProfiles]="formGroup.get('dmp').value.profiles" (formChanged)="formChanged()"></app-dataset-editor-component>
<app-dataset-description-form [hidden]="this.step === 0" *ngIf="formGroup && datasetWizardModel && datasetWizardModel.datasetProfileDefinition" [form]="this.formGroup.get('datasetProfileDefinition')" [visibilityRules]="datasetWizardModel.datasetProfileDefinition.rules" [datasetProfileId]="formGroup.get('profile').value" [linkToScroll]="linkToScroll"></app-dataset-description-form> <app-dataset-description-form [hidden]="this.step === 0" *ngIf="formGroup && datasetWizardModel && datasetWizardModel.datasetProfileDefinition" [form]="this.formGroup.get('datasetProfileDefinition')" [visibilityRules]="datasetWizardModel.datasetProfileDefinition.rules" [datasetProfileId]="formGroup.get('profile').value" [linkToScroll]="linkToScroll"></app-dataset-description-form>
<app-dataset-editor-component [hidden]="this.step !== 0" [formGroup]="formGroup" [dmpId]="formGroup.get('dmp').value.id" [availableProfiles]="formGroup.get('dmp').value.profiles"></app-dataset-editor-component>
</div> </div>
</div> </div>
</form> </form>

View File

@ -41,12 +41,7 @@ import { isNullOrUndefined } from 'util';
import { AuthService } from '@app/core/services/auth/auth.service'; import { AuthService } from '@app/core/services/auth/auth.service';
import { environment } from 'environments/environment'; import { environment } from 'environments/environment';
import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
import { SaveType } from '@app/core/common/enum/save-type';
enum SaveType {
close = 0,
addNew = 1
}
@Component({ @Component({
selector: 'app-dataset-wizard-component', selector: 'app-dataset-wizard-component',
@ -59,6 +54,9 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
viewOnly = false; viewOnly = false;
editMode = false; editMode = false;
publicMode = false; publicMode = false;
hasChanges = false;
isDiscarded = false;
formGroupRawValue: any;
DatasetStatus = DatasetStatus; DatasetStatus = DatasetStatus;
dmpAutoCompleteConfiguration: SingleAutoCompleteConfiguration; dmpAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
@ -156,6 +154,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
] ]
}]); }]);
this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup = this.datasetWizardModel.buildForm();
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
if (this.datasetWizardModel.status === DatasetStatus.Finalized || lockStatus) { if (this.datasetWizardModel.status === DatasetStatus.Finalized || lockStatus) {
this.formGroup.disable(); this.formGroup.disable();
@ -198,6 +197,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
setTimeout(() => { setTimeout(() => {
this.datasetWizardModel.dmp = data; this.datasetWizardModel.dmp = data;
this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup = this.datasetWizardModel.buildForm();
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
this.formGroup.get('dmp').disable(); this.formGroup.get('dmp').disable();
@ -241,6 +241,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
setTimeout(() => { setTimeout(() => {
this.datasetWizardModel.dmp = data; this.datasetWizardModel.dmp = data;
this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp); this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp);
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
this.loadDatasetProfiles(); this.loadDatasetProfiles();
this.breadCrumbs = observableOf([ this.breadCrumbs = observableOf([
@ -294,6 +295,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
if (data) { if (data) {
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup = this.datasetWizardModel.buildForm();
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
this.formGroup.disable(); this.formGroup.disable();
this.viewOnly = true; this.viewOnly = true;
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
@ -310,6 +312,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(data => { .subscribe(data => {
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
this.needsUpdate(); this.needsUpdate();
this.breadCrumbs = observableOf([ this.breadCrumbs = observableOf([
{ {
@ -342,6 +346,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
} else { } else {
this.datasetWizardModel = new DatasetWizardEditorModel(); this.datasetWizardModel = new DatasetWizardEditorModel();
this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup = this.datasetWizardModel.buildForm();
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
if (this.datasetWizardModel.status === DatasetStatus.Finalized) { if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
this.formGroup.disable(); this.formGroup.disable();
@ -359,6 +365,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
} }
!this.isNew ? this.maxStep = 1 : this.maxStep = 0; !this.isNew ? this.maxStep = 1 : this.maxStep = 0;
// this.route.params // this.route.params
// .pipe(takeUntil(this._destroyed)) // .pipe(takeUntil(this._destroyed))
// .subscribe((params: Params) => { // .subscribe((params: Params) => {
@ -376,7 +383,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
this.formGroup.get('profile').valueChanges this.formGroup.get('profile').valueChanges
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(x => { .subscribe(x => {
this.datasetProfileValueChanged(x.id); console.log(x)
if (x) { this.datasetProfileValueChanged(x.id); }
}); });
} }
@ -424,6 +432,12 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
} }
} }
public formChanged() {
if (!this.isDiscarded) {
this.hasChanges = true;
}
}
public cancel(): void { public cancel(): void {
if (!isNullOrUndefined(this.lock)) { if (!isNullOrUndefined(this.lock)) {
this.lockService.unlockTarget(this.datasetWizardModel.id).pipe(takeUntil(this._destroyed)).subscribe( this.lockService.unlockTarget(this.datasetWizardModel.id).pipe(takeUntil(this._destroyed)).subscribe(
@ -814,11 +828,23 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
} }
isDirty() { isDirty() {
return this.formGroup.dirty && this.hasChanges; // do we need this.formGroup.dirty
} }
discardChanges() { discardChanges() {
this.isDiscarded = true;
this.hasChanges = false;
if (this.isNew) {
console.log(this.formGroup);
Object.keys(this.formGroup['controls']).forEach((key: string) => {
if (key !== 'dmp') {
this.formGroup.get(key).reset();
}
});
} else {
this.formGroup.patchValue(JSON.parse(JSON.stringify(this.formGroupRawValue)));
}
this.isDiscarded = false;
} }
addDataset(dmpId: string) { addDataset(dmpId: string) {