Fixes bugs on discard buttons

This commit is contained in:
apapachristou 2020-08-31 02:43:11 +03:00
parent 7fd0692608
commit db006d6ad2
5 changed files with 50 additions and 31 deletions

View File

@ -64,6 +64,7 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn
@Input() formGroup: FormGroup; @Input() formGroup: FormGroup;
@Input() dmpId: string; @Input() dmpId: string;
@Input() datasetId: string; @Input() datasetId: string;
@Input() isNewDataset: boolean;
@Output() formChanged: EventEmitter<any> = new EventEmitter(); @Output() formChanged: EventEmitter<any> = new EventEmitter();
readonly separatorKeysCodes: number[] = [ENTER, COMMA]; readonly separatorKeysCodes: number[] = [ENTER, COMMA];
@ -96,7 +97,7 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn
this.datasetWizardModel = new DatasetWizardEditorModel(); this.datasetWizardModel = new DatasetWizardEditorModel();
this.registerFormListeners(); this.registerFormListeners();
if (this.datasetId) { // never gets in here if (this.datasetId) {
this.datasetWizardService.getSingle(this.datasetId) this.datasetWizardService.getSingle(this.datasetId)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(data => { .subscribe(data => {
@ -161,9 +162,9 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn
getDmpText(): string { getDmpText(): string {
return this.language.instant('DMP-LISTING.TEXT-INFO') + '\n\n' + return this.language.instant('DMP-LISTING.TEXT-INFO') + '\n\n' +
this.language.instant('DMP-LISTING.TEXT-INFO-QUESTION') + ' ' + this.language.instant('DMP-LISTING.TEXT-INFO-QUESTION') + ' ' +
this.language.instant('DMP-LISTING.LINK-ZENODO') + ' ' + this.language.instant('DMP-LISTING.LINK-ZENODO') + ' ' +
this.language.instant('DMP-LISTING.GET-IDEA'); this.language.instant('DMP-LISTING.GET-IDEA');
} }
setDashboardTourDmp(label: string): void { setDashboardTourDmp(label: string): void {
@ -184,11 +185,14 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn
.subscribe(x => { .subscribe(x => {
this.dmpValueChanged(x); this.dmpValueChanged(x);
}); });
this.formGroup.get('profile').valueChanges
.pipe(takeUntil(this._destroyed)) if (this.isNewDataset) {
.subscribe(x => { this.formGroup.get('profile').valueChanges
this.datasetProfileValueChanged(x); .pipe(takeUntil(this._destroyed))
}); .subscribe(x => {
this.datasetProfileValueChanged(x);
});
}
} }
dmpValueChanged(dmp: DmpListingModel) { dmpValueChanged(dmp: DmpListingModel) {

View File

@ -85,20 +85,23 @@ export class DatasetInfoComponent extends BaseComponent implements OnInit {
this.formGroup.get('extraProperties').get('publicDate').patchValue(new Date()); this.formGroup.get('extraProperties').get('publicDate').patchValue(new Date());
} }
// this.datasetFormGroup.get('dmp').valueChanges.pipe(takeUntil(this._destroyed)) if (this.formGroup.get('datasets')['controls'][0]) {
this.formGroup.get('datasets')['controls'][0].get('dmp').valueChanges.pipe(takeUntil(this._destroyed)) this.formGroup.get('datasets')['controls'][0].get('dmp').valueChanges.pipe(takeUntil(this._destroyed))
.subscribe(x => { .subscribe(x => {
// this.registerFormListeners(); // this.registerFormListeners();
this.loadDatasetProfiles(); if (this.formGroup.get('datasets')['controls'][0].get('dmp').value) {
this.profilesAutoCompleteConfiguration = { this.loadDatasetProfiles();
filterFn: this.filterProfiles.bind(this), this.profilesAutoCompleteConfiguration = {
initialItems: (excludedItems: any[]) => this.filterProfiles('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), filterFn: this.filterProfiles.bind(this),
displayFn: (item) => item['label'], initialItems: (excludedItems: any[]) => this.filterProfiles('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
titleFn: (item) => item['label'], displayFn: (item) => item['label'],
subtitleFn: (item) => item['description'] titleFn: (item) => item['label'],
}; subtitleFn: (item) => item['description']
this.onFormChanged.emit(); };
}); this.onFormChanged.emit();
}
});
}
} }
// Researchers // Researchers
@ -132,7 +135,7 @@ export class DatasetInfoComponent extends BaseComponent implements OnInit {
loadDatasetProfiles() { loadDatasetProfiles() {
const datasetProfileRequestItem: RequestItem<DatasetProfileCriteria> = new RequestItem(); const datasetProfileRequestItem: RequestItem<DatasetProfileCriteria> = new RequestItem();
datasetProfileRequestItem.criteria = new DatasetProfileCriteria(); 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) { if (datasetProfileRequestItem.criteria.id) {
this.datasetWizardService.getAvailableProfiles(datasetProfileRequestItem) this.datasetWizardService.getAvailableProfiles(datasetProfileRequestItem)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))

View File

@ -82,7 +82,7 @@
<li *ngFor="let dataset of datasets.controls; let i = index" (click)="changeStep(i + stepsBeforeDatasets, dataset)" [ngClass]="{'active-dataset': this.step === i + stepsBeforeDatasets}"> <li *ngFor="let dataset of datasets.controls; let i = index" (click)="changeStep(i + stepsBeforeDatasets, dataset)" [ngClass]="{'active-dataset': this.step === i + stepsBeforeDatasets}">
<div>{{'DMP-EDITOR.STEPPER.DATASET' | translate}}</div> <div>{{'DMP-EDITOR.STEPPER.DATASET' | translate}}</div>
<span *ngIf="dataset.value.status === 1" class="finalized-label"><mat-icon class="status-icon check-icon">check</mat-icon>{{'TYPES.DATASET-STATUS.FINALISED' | translate}}</span> <span *ngIf="dataset.get('status').value === 1" class="finalized-label"><mat-icon class="status-icon check-icon">check</mat-icon>{{'TYPES.DATASET-STATUS.FINALISED' | translate}}</span>
<ul class="dataset-list"> <ul class="dataset-list">
<li *ngIf="!isNewDataset" [ngClass]="{'active': this.step === i + stepsBeforeDatasets}">{{ dataset.get('label').value }} (8)</li> <li *ngIf="!isNewDataset" [ngClass]="{'active': this.step === i + stepsBeforeDatasets}">{{ dataset.get('label').value }} (8)</li>
<li *ngIf="isNewDataset" [ngClass]="{'active': this.step === i + stepsBeforeDatasets}">{{ dataset.get('label').value }}</li> <li *ngIf="isNewDataset" [ngClass]="{'active': this.step === i + stepsBeforeDatasets}">{{ dataset.get('label').value }}</li>
@ -114,7 +114,7 @@
<dataset-info *ngIf="isNewDataset" [hidden]="this.step !== 1" [formGroup]="formGroup" [dmp]="dmp" [isPublic]="isPublic" [isFinalized]="isFinalized || lockStatus" [isUserOwner]="isUserOwner" [isNewDataset]="isNewDataset" (onFormChanged)="formChanged()"></dataset-info> <dataset-info *ngIf="isNewDataset" [hidden]="this.step !== 1" [formGroup]="formGroup" [dmp]="dmp" [isPublic]="isPublic" [isFinalized]="isFinalized || lockStatus" [isUserOwner]="isUserOwner" [isNewDataset]="isNewDataset" (onFormChanged)="formChanged()"></dataset-info>
<div *ngFor="let dataset of datasets.controls; let i = index" [hidden]="this.step !== i + stepsBeforeDatasets"> <div *ngFor="let dataset of datasets.controls; let i = index" [hidden]="this.step !== i + stepsBeforeDatasets">
<dataset-editor-details [formGroup]="dataset" [dmpId]="formGroup.get('id').value" (formChanged)="datasetFormChanged($event)"></dataset-editor-details> <dataset-editor-details [formGroup]="dataset" [isNewDataset]="isNewDataset" [dmpId]="formGroup.get('id').value" (formChanged)="datasetFormChanged($event)"></dataset-editor-details>
</div> </div>
</div> </div>
</div> </div>

View File

@ -63,6 +63,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
isPublic = false; isPublic = false;
isFinalized = false; isFinalized = false;
hasChanges = false; hasChanges = false;
isDiscarded = false;
isNewDataset = false; isNewDataset = false;
isUserOwner: boolean = true; isUserOwner: boolean = true;
@ -164,6 +165,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
this.formGroup = this.dmp.buildForm(); this.formGroup = this.dmp.buildForm();
this.datasets = this.formGroup.get('datasets') as FormArray; 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.getRawValue()));
this.maxStep = this.formGroup.get('datasets') ? this.maxStep + this.formGroup.get('datasets').value.length - 1 : this.maxStep; 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.formGroup = this.dmp.buildForm();
this.datasets = this.formGroup.get('datasets') as FormArray; 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.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.maxStep = this.formGroup.get('datasets') ? this.maxStep + this.formGroup.get('datasets').value.length - 1 : this.maxStep;
this.registerFormEventsForNewItem(); this.registerFormEventsForNewItem();
@ -344,7 +346,9 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
} }
public formChanged() { public formChanged() {
this.hasChanges = true; if (!this.isDiscarded) {
this.hasChanges = true;
}
} }
datasetFormChanged(formGroup: FormGroup) { datasetFormChanged(formGroup: FormGroup) {
@ -732,12 +736,21 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
} }
public isDirty(): boolean { public isDirty(): boolean {
return this.formGroup.dirty && this.hasChanges; return this.formGroup.dirty && this.hasChanges; // do we need this.formGroup.dirty
} }
public discardChanges() { public discardChanges() {
this.formGroup.patchValue(JSON.parse(JSON.stringify(this.formGroupRawValue))); this.isDiscarded = true;
this.hasChanges = false; 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() { // advancedClicked() {

View File

@ -17,7 +17,6 @@
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> {{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field *ngIf="isNewDataset"> <mat-form-field *ngIf="isNewDataset">
<!-- <app-single-auto-complete [required]="true" [formControl]="this.datasetFormGroup.get('dmp')" placeholder="{{'DATASET-EDITOR.FIELDS.SELECT-DMP' | translate}}" [configuration]="dmpAutoCompleteConfiguration"></app-single-auto-complete> -->
<app-single-auto-complete [required]="true" [formControl]="this.formGroup.get('datasets')['controls'][0].get('dmp')" placeholder="{{'DATASET-EDITOR.FIELDS.SELECT-DMP' | translate}}" [configuration]="dmpAutoCompleteConfiguration"></app-single-auto-complete> <app-single-auto-complete [required]="true" [formControl]="this.formGroup.get('datasets')['controls'][0].get('dmp')" placeholder="{{'DATASET-EDITOR.FIELDS.SELECT-DMP' | translate}}" [configuration]="dmpAutoCompleteConfiguration"></app-single-auto-complete>
<!-- <app-single-auto-complete [required]="true" [formControl]="formGroup" placeholder="{{'DATASET-EDITOR.FIELDS.SELECT-DMP' | translate}}" [configuration]="dmpAutoCompleteConfiguration"> <!-- <app-single-auto-complete [required]="true" [formControl]="formGroup" placeholder="{{'DATASET-EDITOR.FIELDS.SELECT-DMP' | translate}}" [configuration]="dmpAutoCompleteConfiguration">
</app-single-auto-complete> --> </app-single-auto-complete> -->