From eb7a5571c43194caeb0fe7fe59221f0bed9d5de5 Mon Sep 17 00:00:00 2001 From: apapachristou Date: Tue, 8 Sep 2020 10:36:18 +0300 Subject: [PATCH] Edit template on dmp-dataset editor --- .../multiple-auto-complete.component.html | 4 +- .../dataset-editor-details.component.ts | 102 +++++++++--------- .../dataset-info/dataset-info.component.html | 2 +- .../dataset-info/dataset-info.component.ts | 27 ++++- .../ui/dmp/editor/dmp-editor.component.html | 6 +- .../ui/dmp/editor/dmp-editor.component.scss | 26 +---- .../app/ui/dmp/editor/dmp-editor.component.ts | 24 ++--- dmp-frontend/src/assets/i18n/de.json | 3 +- dmp-frontend/src/assets/i18n/en.json | 3 +- dmp-frontend/src/assets/i18n/es.json | 3 +- dmp-frontend/src/assets/i18n/gr.json | 3 +- dmp-frontend/src/assets/i18n/tr.json | 3 +- 12 files changed, 105 insertions(+), 101 deletions(-) diff --git a/dmp-frontend/src/app/library/auto-complete/multiple/multiple-auto-complete.component.html b/dmp-frontend/src/app/library/auto-complete/multiple/multiple-auto-complete.component.html index 931498c23..ae3805b29 100644 --- a/dmp-frontend/src/app/library/auto-complete/multiple/multiple-auto-complete.component.html +++ b/dmp-frontend/src/app/library/auto-complete/multiple/multiple-auto-complete.component.html @@ -3,9 +3,7 @@ - +
{{_displayFn(selectedItem)}}
cancel
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 a452dede1..1fef2771c 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 @@ -54,7 +54,7 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn // formGroup: FormGroup = null; datasetProfileDefinitionModel: DatasetDescriptionFormEditorModel; - availableProfiles: DatasetProfileModel[] = []; + // availableProfiles: DatasetProfileModel[] = []; // itemId: string; // publicId: string; // profileUpdateId: string; @@ -68,6 +68,7 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn @Input() dmpId: string; @Input() datasetId: string; @Input() isNewDataset: boolean; + @Input() availableProfiles: DatasetProfileModel[]; @Output() formChanged: EventEmitter = new EventEmitter(); readonly separatorKeysCodes: number[] = [ENTER, COMMA]; @@ -102,8 +103,10 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn this.datasetWizardModel = new DatasetWizardEditorModel(); this.registerFormListeners(); + if (this.isNewDataset) { + this.loadDatasetProfiles(); + } - // console.log(this.formGroup); 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))), @@ -112,56 +115,53 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn subtitleFn: (item) => item['description'] }; - if (!this.isNewDataset) { - this.loadDatasetProfiles(); - } - if (this.datasetId) { - this.datasetWizardService.getSingle(this.datasetId) - .pipe(takeUntil(this._destroyed)) - .subscribe(data => { - this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { - this.lockStatus = lockStatus; - this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); - this.needsUpdate(); - this.formGroup = this.datasetWizardModel.buildForm(); - this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; - if (this.datasetWizardModel.status === DatasetStatus.Finalized || lockStatus) { - this.formGroup.disable(); - this.viewOnly = true; - } - if (!lockStatus && !isNullOrUndefined(this.authService.current())) { - this.lock = new LockModel(data.id, this.authService.current()); + // if (this.datasetId) { + // this.datasetWizardService.getSingle(this.datasetId) + // .pipe(takeUntil(this._destroyed)) + // .subscribe(data => { + // this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { + // this.lockStatus = lockStatus; + // this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); + // this.needsUpdate(); + // this.formGroup = this.datasetWizardModel.buildForm(); + // this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; + // if (this.datasetWizardModel.status === DatasetStatus.Finalized || lockStatus) { + // this.formGroup.disable(); + // this.viewOnly = true; + // } + // if (!lockStatus && !isNullOrUndefined(this.authService.current())) { + // this.lock = new LockModel(data.id, this.authService.current()); - this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => { - this.lock.id = Guid.parse(result); - interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); - }); - } - // if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP. - this.loadDatasetProfiles(); - this.registerFormListeners(); - // this.availableProfiles = this.datasetWizardModel.dmp.profiles; + // this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => { + // this.lock.id = Guid.parse(result); + // interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); + // }); + // } + // // if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP. + // this.loadDatasetProfiles(); + // this.registerFormListeners(); + // // this.availableProfiles = this.datasetWizardModel.dmp.profiles; - this.onChanges(); - this.formChanged.emit(this.formGroup); - }) - }, - error => { - switch (error.status) { - case 403: - this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.MESSAGES.DATASET-NOT-ALLOWED'), SnackBarNotificationLevel.Error); - break; - case 404: - this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.MESSAGES.DATASET-NOT-FOUND'), SnackBarNotificationLevel.Error); - break; - default: - this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.ERRORS.HTTP-REQUEST-ERROR'), SnackBarNotificationLevel.Error); - } - this.router.navigate(['/datasets/']); - return observableOf(null); - }); - } + // this.onChanges(); + // this.formChanged.emit(this.formGroup); + // }) + // }, + // error => { + // switch (error.status) { + // case 403: + // this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.MESSAGES.DATASET-NOT-ALLOWED'), SnackBarNotificationLevel.Error); + // break; + // case 404: + // this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.MESSAGES.DATASET-NOT-FOUND'), SnackBarNotificationLevel.Error); + // break; + // default: + // this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.ERRORS.HTTP-REQUEST-ERROR'), SnackBarNotificationLevel.Error); + // } + // this.router.navigate(['/datasets/']); + // return observableOf(null); + // }); + // } } public dashboardTourDmp: GuidedTour = { @@ -205,7 +205,7 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn this.dmpValueChanged(x); }); - if (this.isNewDataset) { + // if (this.isNewDataset) { this.formGroup.get('profile').valueChanges .pipe(takeUntil(this._destroyed)) .subscribe(x => { @@ -213,7 +213,7 @@ export class DatasetEditorDetailsComponent extends BaseComponent implements OnIn this.datasetProfileValueChanged(x.id); } }); - } + // } } dmpValueChanged(dmp: DmpListingModel) { diff --git a/dmp-frontend/src/app/ui/dmp/editor/dataset-info/dataset-info.component.html b/dmp-frontend/src/app/ui/dmp/editor/dataset-info/dataset-info.component.html index 4ba005e03..8920ad1cb 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dataset-info/dataset-info.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/dataset-info/dataset-info.component.html @@ -13,7 +13,7 @@
- + {{formGroup.get('profiles').getError('backendError').message}} 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 e364e83cf..62c2c7e22 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 @@ -1,6 +1,6 @@ import { BaseComponent } from '@common/base/base.component'; import { OnInit, Component, Input, Output, EventEmitter } from '@angular/core'; -import { FormGroup } from '@angular/forms'; +import { FormGroup, FormArray } from '@angular/forms'; import { TranslateService } from '@ngx-translate/core'; import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration'; @@ -23,6 +23,7 @@ import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset- import { DatasetDescriptionFormEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model'; import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model'; import { DmpListingModel } from '@app/core/model/dmp/dmp-listing'; +import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service'; @Component({ selector: 'dataset-info', @@ -59,7 +60,8 @@ export class DatasetInfoComponent extends BaseComponent implements OnInit { private _service: DmpService, private dmpProfileService: DmpProfileService, private router: Router, - private route: ActivatedRoute + private route: ActivatedRoute, + private uiNotificationService: UiNotificationService ) { super(); } @@ -212,4 +214,25 @@ export class DatasetInfoComponent extends BaseComponent implements OnInit { }); } + onRemoveTemplate(event) { + let found = false; + const profiles = this.formGroup.get('profiles').value; + this.formGroup.get('datasets')['controls'].forEach(element => { + if (element.get('profile').value.id === event.id) { + found = true; + this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-REMOVE-TEMPLATE'), SnackBarNotificationLevel.Success); + } + }); + if (found) { + this.formGroup.get('profiles').setValue(profiles); + 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'] + }; + + } + } } 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 948d3122e..66e4f68da 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 @@ -92,9 +92,9 @@ -
diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.scss b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.scss index 3a6bd5122..a2239075e 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.scss +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.scss @@ -307,7 +307,7 @@ a:hover { font-size: 14px; } -.previous { +.previous, .add-dataset-btn { color: #212121; background: #f5f5f5 0% 0% no-repeat padding-box; box-shadow: 0px 3px 6px #1e202029; @@ -332,9 +332,9 @@ a:hover { cursor: pointer; } -.previous-disabled { +.previous-disabled, .add-dataset-btn-disabled { border: 1px solid #b5b5b5; - color: #b5b5b5; + color: #b5b5b5 !important; cursor: auto !important; } @@ -395,26 +395,6 @@ a:hover { list-style-type: none; } -.add-dataset-btn { - color: #212121; - background: #f5f5f5 0% 0% no-repeat padding-box; - box-shadow: 0px 3px 6px #1e202029; - border: 2px solid #212121; - font-weight: 500; - cursor: pointer; - border-radius: 30px; - opacity: 1; - width: 154px; - height: 40px; - display: -webkit-box; - display: flex; - -webkit-box-pack: center; - justify-content: center; - -webkit-box-align: center; - align-items: center; - font-size: 14px; -} - // ::ng-deep .mat-tab-labels { // justify-content: space-between; // } 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 24d28efcd..54918fb6c 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 @@ -378,11 +378,6 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC } } - datasetFormChanged(formGroup: FormGroup) { - // this.datasetFormGroup = formGroup; - // console.log(this.datasetFormGroup); - } - isAuthenticated() { return this.authService.current() != null; } @@ -715,17 +710,19 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC } addDataset() { - if (this.formGroup.get('datasets')) { - // const datasetWizardModel = { dmp: this.dmpModel }; - // const datasetWizardEditorModel = new DatasetWizardEditorModel().fromModel(datasetWizardModel); - // this.formGroup.get('datasets')['controls'].push(datasetWizardEditorModel.buildForm()); - this.formGroup.get('datasets')['controls'].push(new DatasetWizardEditorModel().buildForm()); - // console.log(this.formGroup.get('datasets')) - }; + if (!this.formGroup.get('datasets')) { + this.formGroup.addControl('datasets', new FormBuilder().array(new Array())); + } + this.formGroup.get('datasets')['controls'].push(new DatasetWizardEditorModel().buildForm()); + this.datasets = this.formGroup.get('datasets') as FormArray; this.step = this.stepsBeforeDatasets + this.formGroup.get('datasets')['controls'].length - 1; this.maxStep = this.maxStep + this.formGroup.get('datasets')['controls'].length - 1; } + hasProfile(): boolean { + return this.formGroup.get('profiles') && this.formGroup.get('profiles').value && this.formGroup.get('profiles').value.length > 0; + } + addDatasetOpenDialog(id: String) { const dialogRef = this.dialog.open(ConfirmationDialogComponent, { maxWidth: '500px', @@ -740,7 +737,8 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { if (result) { - this.router.navigate(['datasets/new/' + id]); + // this.router.navigate(['datasets/new/' + id]); + this.addDataset(); } else { id != null ? this.router.navigate(['/plans', 'edit', id]) : this.router.navigate(['/plans']); } diff --git a/dmp-frontend/src/assets/i18n/de.json b/dmp-frontend/src/assets/i18n/de.json index 7e729a835..5c4c57a9c 100644 --- a/dmp-frontend/src/assets/i18n/de.json +++ b/dmp-frontend/src/assets/i18n/de.json @@ -23,7 +23,8 @@ "UNSUCCESSFUL-DATASET-PROFILE-DELETE": "Diese Vorlage kann nicht gelöscht werden, da Datensatzbeschreibungen noch damit verbunden sind", "SUCCESSFUL-DELETE": "Erfolgreich gelöscht", "UNSUCCESSFUL-DELETE": "Löschen fehlgeschlagen", - "UNSUCCESSFUL-EMAIL-SEND": "E-Mail versenden fehlgeschlagen" + "UNSUCCESSFUL-EMAIL-SEND": "E-Mail versenden fehlgeschlagen", + "UNSUCCESSFUL-REMOVE-TEMPLATE": "Failed to remove template, one or more datasets of this DMP use this template" }, "ERRORS": { "HTTP-REQUEST-ERROR": "Ein unerwarteter Fehler ist aufgetreten" diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index d79fd2dd9..3c480e880 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -23,7 +23,8 @@ "UNSUCCESSFUL-DATASET-PROFILE-DELETE": "This template can not deleted, because Dataset Descriptions are associated with it", "SUCCESSFUL-DELETE": "Successful Delete", "UNSUCCESSFUL-DELETE": "Unsuccessful Delete", - "UNSUCCESSFUL-EMAIL-SEND": "Failed sending email" + "UNSUCCESSFUL-EMAIL-SEND": "Failed sending email", + "UNSUCCESSFUL-REMOVE-TEMPLATE": "Failed to remove template, one or more datasets of this DMP use this template" }, "ERRORS": { "HTTP-REQUEST-ERROR": "An Unexpected Error Has Occurred" diff --git a/dmp-frontend/src/assets/i18n/es.json b/dmp-frontend/src/assets/i18n/es.json index eefb98880..aa2754232 100644 --- a/dmp-frontend/src/assets/i18n/es.json +++ b/dmp-frontend/src/assets/i18n/es.json @@ -23,7 +23,8 @@ "SUCCESSFUL-DELETE": "Borrado correcto", "UNSUCCESSFUL-DATASET-PROFILE-DELETE": "Esta plantilla no se puede borrar, porque está asociada a descripciones del dataset", "UNSUCCESSFUL-DELETE": "Borrado fallido", - "UNSUCCESSFUL-EMAIL-SEND": "Fallo enviando el correo" + "UNSUCCESSFUL-EMAIL-SEND": "Fallo enviando el correo", + "UNSUCCESSFUL-REMOVE-TEMPLATE": "Failed to remove template, one or more datasets of this DMP use this template" }, "ERRORS": { "HTTP-REQUEST-ERROR": "Se ha producido un error inesperado" diff --git a/dmp-frontend/src/assets/i18n/gr.json b/dmp-frontend/src/assets/i18n/gr.json index 75371611c..687714158 100644 --- a/dmp-frontend/src/assets/i18n/gr.json +++ b/dmp-frontend/src/assets/i18n/gr.json @@ -23,7 +23,8 @@ "UNSUCCESSFUL-DATASET-PROFILE-DELETE": "Το template δεν μπορεί να διαγραφεί, επειδή οι περιγραφές των συνόλων δεδομένων σχετίζονται με αυτό", "SUCCESSFUL-DELETE": "Επιτυχής διαγραφή", "UNSUCCESSFUL-DELETE": "Αποτυχημένη διαγραφή", - "UNSUCCESSFUL-EMAIL-SEND": "Αποτυχία αποστολής email" + "UNSUCCESSFUL-EMAIL-SEND": "Αποτυχία αποστολής email", + "UNSUCCESSFUL-REMOVE-TEMPLATE": "Failed to remove template, one or more datasets of this DMP use this template" }, "ERRORS": { "HTTP-REQUEST-ERROR": "Παρουσιάστηκε μη αναμενόμενο σφάλμα" diff --git a/dmp-frontend/src/assets/i18n/tr.json b/dmp-frontend/src/assets/i18n/tr.json index 003cf85fc..68222507f 100644 --- a/dmp-frontend/src/assets/i18n/tr.json +++ b/dmp-frontend/src/assets/i18n/tr.json @@ -22,7 +22,8 @@ "SUCCESSFUL-DATASET-PROFILE-DELETE": "Silme Başarılı", "UNSUCCESSFUL-DATASET-PROFILE-DELETE": "Veri seti Tanımları ilişkilendirildiği için bu şablon silinemez", "UNSUCCESSFUL-DELETE": "Başarısız Silme", - "UNSUCCESSFUL-EMAIL-SEND": "E-posta gönderilemedi" + "UNSUCCESSFUL-EMAIL-SEND": "E-posta gönderilemedi", + "UNSUCCESSFUL-REMOVE-TEMPLATE": "Failed to remove template, one or more datasets of this DMP use this template" }, "ERRORS": { "HTTP-REQUEST-ERROR": "Beklenmeyen Bir Hata Oluştu"