From db006d6ad2ff49622a29003a0a7ca0ec7901e051 Mon Sep 17 00:00:00 2001 From: apapachristou Date: Mon, 31 Aug 2020 02:43:11 +0300 Subject: [PATCH] Fixes bugs on discard buttons --- .../dataset-editor-details.component.ts | 22 ++++++++----- .../dataset-info/dataset-info.component.ts | 33 ++++++++++--------- .../ui/dmp/editor/dmp-editor.component.html | 4 +-- .../app/ui/dmp/editor/dmp-editor.component.ts | 21 +++++++++--- .../editor/main-info/main-info.component.html | 1 - 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/dmp-frontend/src/app/ui/dmp/editor/dataset-editor-details/dataset-editor-details.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dataset-editor-details/dataset-editor-details.component.ts index d8f58b7d5..80efe116f 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dataset-editor-details/dataset-editor-details.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dataset-editor-details/dataset-editor-details.component.ts @@ -64,6 +64,7 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn @Input() formGroup: FormGroup; @Input() dmpId: string; @Input() datasetId: string; + @Input() isNewDataset: boolean; @Output() formChanged: EventEmitter = new EventEmitter(); readonly separatorKeysCodes: number[] = [ENTER, COMMA]; @@ -96,7 +97,7 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn this.datasetWizardModel = new DatasetWizardEditorModel(); this.registerFormListeners(); - if (this.datasetId) { // never gets in here + if (this.datasetId) { this.datasetWizardService.getSingle(this.datasetId) .pipe(takeUntil(this._destroyed)) .subscribe(data => { @@ -161,9 +162,9 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn getDmpText(): string { return this.language.instant('DMP-LISTING.TEXT-INFO') + '\n\n' + - this.language.instant('DMP-LISTING.TEXT-INFO-QUESTION') + ' ' + - this.language.instant('DMP-LISTING.LINK-ZENODO') + ' ' + - this.language.instant('DMP-LISTING.GET-IDEA'); + this.language.instant('DMP-LISTING.TEXT-INFO-QUESTION') + ' ' + + this.language.instant('DMP-LISTING.LINK-ZENODO') + ' ' + + this.language.instant('DMP-LISTING.GET-IDEA'); } setDashboardTourDmp(label: string): void { @@ -184,11 +185,14 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn .subscribe(x => { this.dmpValueChanged(x); }); - this.formGroup.get('profile').valueChanges - .pipe(takeUntil(this._destroyed)) - .subscribe(x => { - this.datasetProfileValueChanged(x); - }); + + if (this.isNewDataset) { + this.formGroup.get('profile').valueChanges + .pipe(takeUntil(this._destroyed)) + .subscribe(x => { + this.datasetProfileValueChanged(x); + }); + } } dmpValueChanged(dmp: DmpListingModel) { diff --git a/dmp-frontend/src/app/ui/dmp/editor/dataset-info/dataset-info.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dataset-info/dataset-info.component.ts index 5b41d99fb..460ea8c83 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dataset-info/dataset-info.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dataset-info/dataset-info.component.ts @@ -85,20 +85,23 @@ export class DatasetInfoComponent extends BaseComponent implements OnInit { this.formGroup.get('extraProperties').get('publicDate').patchValue(new Date()); } - // this.datasetFormGroup.get('dmp').valueChanges.pipe(takeUntil(this._destroyed)) - this.formGroup.get('datasets')['controls'][0].get('dmp').valueChanges.pipe(takeUntil(this._destroyed)) - .subscribe(x => { - // this.registerFormListeners(); - this.loadDatasetProfiles(); - this.profilesAutoCompleteConfiguration = { - filterFn: this.filterProfiles.bind(this), - initialItems: (excludedItems: any[]) => this.filterProfiles('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), - displayFn: (item) => item['label'], - titleFn: (item) => item['label'], - subtitleFn: (item) => item['description'] - }; - this.onFormChanged.emit(); - }); + if (this.formGroup.get('datasets')['controls'][0]) { + this.formGroup.get('datasets')['controls'][0].get('dmp').valueChanges.pipe(takeUntil(this._destroyed)) + .subscribe(x => { + // this.registerFormListeners(); + if (this.formGroup.get('datasets')['controls'][0].get('dmp').value) { + this.loadDatasetProfiles(); + this.profilesAutoCompleteConfiguration = { + filterFn: this.filterProfiles.bind(this), + initialItems: (excludedItems: any[]) => this.filterProfiles('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), + displayFn: (item) => item['label'], + titleFn: (item) => item['label'], + subtitleFn: (item) => item['description'] + }; + this.onFormChanged.emit(); + } + }); + } } // Researchers @@ -132,7 +135,7 @@ export class DatasetInfoComponent extends BaseComponent implements OnInit { loadDatasetProfiles() { const datasetProfileRequestItem: RequestItem = new RequestItem(); datasetProfileRequestItem.criteria = new DatasetProfileCriteria(); - datasetProfileRequestItem.criteria.id = this.formGroup.get('datasets')['controls'][0].get('dmp').value.id; + this.formGroup.get('id').value ? datasetProfileRequestItem.criteria.id = this.formGroup.get('id').value : datasetProfileRequestItem.criteria.id = this.formGroup.get('datasets')['controls'][0].get('dmp').value.id; if (datasetProfileRequestItem.criteria.id) { this.datasetWizardService.getAvailableProfiles(datasetProfileRequestItem) .pipe(takeUntil(this._destroyed)) diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.html b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.html index ea77f7491..6aa571842 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.html @@ -82,7 +82,7 @@
  • {{'DMP-EDITOR.STEPPER.DATASET' | translate}}
    - check{{'TYPES.DATASET-STATUS.FINALISED' | translate}} + check{{'TYPES.DATASET-STATUS.FINALISED' | translate}}
    • {{ dataset.get('label').value }} (8)
    • {{ dataset.get('label').value }}
    • @@ -114,7 +114,7 @@
      - +
      diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts index e881e9ecc..d6be86b0b 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts @@ -63,6 +63,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC isPublic = false; isFinalized = false; hasChanges = false; + isDiscarded = false; isNewDataset = false; isUserOwner: boolean = true; @@ -164,6 +165,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.formGroup = this.dmp.buildForm(); this.datasets = this.formGroup.get('datasets') as FormArray; + this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue())); this.maxStep = this.formGroup.get('datasets') ? this.maxStep + this.formGroup.get('datasets').value.length - 1 : this.maxStep; @@ -279,8 +281,8 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.formGroup = this.dmp.buildForm(); this.datasets = this.formGroup.get('datasets') as FormArray; - this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue())); + // this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.get('datasets')['controls'][0].getRawValue())); this.maxStep = this.formGroup.get('datasets') ? this.maxStep + this.formGroup.get('datasets').value.length - 1 : this.maxStep; this.registerFormEventsForNewItem(); @@ -344,7 +346,9 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC } public formChanged() { - this.hasChanges = true; + if (!this.isDiscarded) { + this.hasChanges = true; + } } datasetFormChanged(formGroup: FormGroup) { @@ -732,12 +736,21 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC } public isDirty(): boolean { - return this.formGroup.dirty && this.hasChanges; + return this.formGroup.dirty && this.hasChanges; // do we need this.formGroup.dirty } public discardChanges() { - this.formGroup.patchValue(JSON.parse(JSON.stringify(this.formGroupRawValue))); + this.isDiscarded = true; this.hasChanges = false; + if (this.isNewDataset) { + this.formGroup.get('datasets')['controls'].forEach(element => { + element.removeControl('datasetProfileDefinition'); + }); + this.formGroup.reset(); + } else { + this.formGroup.patchValue(JSON.parse(JSON.stringify(this.formGroupRawValue))); + } + this.isDiscarded = false; } // advancedClicked() { diff --git a/dmp-frontend/src/app/ui/dmp/editor/main-info/main-info.component.html b/dmp-frontend/src/app/ui/dmp/editor/main-info/main-info.component.html index c3127df15..f2cf3b18d 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/main-info/main-info.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/main-info/main-info.component.html @@ -17,7 +17,6 @@ {{'GENERAL.VALIDATION.REQUIRED' | translate}} -