diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.html new file mode 100644 index 000000000..5fb58d9ef --- /dev/null +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.html @@ -0,0 +1,21 @@ +
+
+ + + + + + {{getErrorMessage()}} + +
+
+
+
+ +
+
+ +
+
+
diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.scss b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.scss new file mode 100644 index 000000000..30b14f9a7 --- /dev/null +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.scss @@ -0,0 +1,6 @@ +.confirmation-message { + padding-bottom: 20px; +} +.dataset-copy-dialog { + width: 350px; +} diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.ts new file mode 100644 index 000000000..63b4f4cd4 --- /dev/null +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component.ts @@ -0,0 +1,88 @@ +import { Component } from "@angular/core"; +import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material"; +import { SingleAutoCompleteConfiguration } from "../../../../library/auto-complete/single/single-auto-complete-configuration"; +import { Observable } from "rxjs"; +import { DataTableRequest } from "../../../../core/model/data-table/data-table-request"; +import { DmpCriteria } from "../../../../core/query/dmp/dmp-criteria"; +import { DmpListingModel } from "../../../../core/model/dmp/dmp-listing"; +import { DmpService } from "../../../../core/services/dmp/dmp.service"; +import { Inject } from "@angular/core"; +import { DmpModel } from "../../../../core/model/dmp/dmp"; +import { TranslateService } from "@ngx-translate/core"; + +@Component({ + selector: 'dataset-copy-dialogue-component', + templateUrl: 'dataset-copy-dialogue.component.html', + styleUrls: ['./dataset-copy-dialogue.component.scss'], +}) +export class DatasetCopyDialogueComponent { + + dmpAutoCompleteConfiguration: SingleAutoCompleteConfiguration; + dmpModel: DmpModel; + + constructor( + public dialogRef: MatDialogRef, + public dmpService: DmpService, + public language: TranslateService, + @Inject(MAT_DIALOG_DATA) public data: any + ) { } + + ngOnInit() { + this.dmpAutoCompleteConfiguration = { + filterFn: this.searchDmp.bind(this), + initialItems: (extraData) => this.searchDmp(''), + displayFn: (item) => item['label'], + titleFn: (item) => item['label'] + }; + } + + cancel() { + this.dialogRef.close(this.data); + } + + confirm() { + this.datasetProfileValidate().subscribe(x => { + if (this.data.datasetProfileExist) { + this.dialogRef.close(this.data); + } + else if (!this.data.datasetProfileExist) { + this.data.formControl.setErrors({'incorrect': true}); + console.log(this.data.formControl.invalid); + } + }); + } + + searchDmp(query: string): Observable { + const fields: Array = new Array(); + fields.push('asc'); + const dmpDataTableRequest: DataTableRequest = new DataTableRequest(0, null, { fields: fields }); + dmpDataTableRequest.criteria = new DmpCriteria(); + dmpDataTableRequest.criteria.like = query; + return this.dmpService.getPaged(dmpDataTableRequest, "autocomplete").map(x => x.data); + } + + datasetProfileValidate() { + return this.dmpService.getSingle(this.data.formControl.value.id).map(result => result as DmpModel) + .map(result => { + this.dmpModel = result + this.dmpModel.profiles.forEach((element) => { + if (element.id == this.data.datasetProfileId) { + this.data.datasetProfileExist = true; + } + }) + }); + } + + getErrorMessage() { + return this.language.instant('DATASET-WIZARD.DIALOGUE.ERROR-MESSAGE'); + } + + hasValidDatasetProfile() { + if (this.data.datasetProfileExist) { + return true; + } + else { + return false; + } + } +} diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html index 67575a798..8fb4cbf6b 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html @@ -2,11 +2,22 @@

{{ 'DATASET-WIZARD.TITLE.NEW' | translate }}

-

{{datasetWizardModel?.label}} {{ 'GENERAL.NAMES.DATASET' | translate }} - - {{ 'GENERAL.STATUSES.EDIT' | translate }}

-

{{'GENERAL.STATUSES.FINALISED' - | translate }}

+

{{datasetWizardModel?.label}} {{ 'GENERAL.NAMES.DATASET' | translate }} + + - {{ 'GENERAL.STATUSES.EDIT' | translate }} +

+

{{'GENERAL.STATUSES.FINALISED' | translate }}

+
+ + + + +
- - + + + class="saveAndFinalizeButton" (click)="saveFinalize();" type="button">{{ 'DATASET-WIZARD.ACTIONS.SAVE-AND-FINALISE' | translate }} - @@ -58,8 +66,9 @@
-
+
+ +
@@ -73,8 +82,9 @@
-
+
+ +
@@ -88,8 +98,9 @@ [datasetProfileId]="formGroup.get('profile').value">
-
+
+ +
diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index 39170e736..40bdcbeb4 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -27,6 +27,8 @@ import { DatasetWizardEditorModel } from './dataset-wizard-editor.model'; import { SnackBarNotificationLevel, UiNotificationService } from '../../../core/services/notification/ui-notification-service'; import { ConfirmationDialogComponent } from '../../../library/confirmation-dialog/confirmation-dialog.component'; import { DataTableRequest } from '../../../core/model/data-table/data-table-request'; +import { DatasetCopyDialogueComponent } from './dataset-copy-dialogue/dataset-copy-dialogue.component'; +import { FormControl } from '@angular/forms'; @Component({ selector: 'app-dataset-wizard-component', @@ -45,16 +47,13 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr datasetWizardModel: DatasetWizardEditorModel; isNew = true; + isCopy = false; formGroup: FormGroup; datasetProfileDefinitionModel: DatasetDescriptionFormEditorModel; availableProfiles: DatasetProfileModel[] = []; itemId: string; isLinear = false; - firstStepFormGroup: FormGroup; - secondFormGroup: FormGroup; - - constructor( private datasetWizardService: DatasetWizardService, @@ -114,9 +113,11 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr }; const params = this.route.snapshot.params; + const queryParams = this.route.snapshot.queryParams; this.itemId = params['id']; const dmpId = params['dmpId']; - if (this.itemId != null) { + const newDmpId = queryParams['newDmpId']; + if (this.itemId != null && newDmpId == null) { this.isNew = false; this.datasetWizardService.getSingle(this.itemId) .pipe(takeUntil(this._destroyed)) @@ -183,7 +184,52 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr }]); }); }); - } else { + } else if (newDmpId != null) { + this.isNew = false; + this.isCopy = true; + this.datasetWizardService.getSingle(this.itemId) + .pipe(takeUntil(this._destroyed)) + .subscribe(data => { + this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); + this.formGroup = this.datasetWizardModel.buildForm(); + this.formGroup.get('id').setValue(null); + this.dmpService.getSingle(newDmpId).map(data => data as DmpModel) + .pipe(takeUntil(this._destroyed)) + .subscribe(data => { + setTimeout(() => { + this.datasetWizardModel.dmp = data; + this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp); + + this.loadDatasetProfiles(); + this.breadCrumbs = Observable.of([ + { + parentComponentName: null, + label: 'Datasets', + url: '/datasets', + notFoundResolver: [ + { + parentComponentName: null, + label: this.datasetWizardModel.dmp.project.label, + url: '/projects/edit/' + this.datasetWizardModel.dmp.project.id + }, + { + parentComponentName: null, + label: this.datasetWizardModel.dmp.label, + url: '/plans/edit/' + this.datasetWizardModel.dmp.id, + }] + }]); + }); + }); + this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; + if (this.datasetWizardModel.status === 1) { + this.formGroup.disable(); + this.viewOnly = true; + } + // if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP. + this.loadDatasetProfiles(); + }); + } + else { this.datasetWizardModel = new DatasetWizardEditorModel(); this.formGroup = this.datasetWizardModel.buildForm(); this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; @@ -251,7 +297,6 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr } } - formSubmit(): void { if (!this.isFormValid()) { return; } this.onSubmit(); @@ -327,7 +372,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr downloadDOCX(): void { this.datasetWizardService.downloadDOCX(this.itemId) - .pipe(takeUntil(this._destroyed)) + .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], { type: 'application/msword' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); @@ -416,10 +461,34 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr this.datasetWizardService.delete(id) .pipe(takeUntil(this._destroyed)) .subscribe( - complete => { this.onCallbackSuccess(); this.router.navigateByUrl('/datasets')}, + complete => { this.onCallbackSuccess(); this.router.navigateByUrl('/datasets') }, error => this.onCallbackError(error) ); } }); } + + openDmpSearchDialogue() { + const formControl = new FormControl(); + const dialogRef = this.dialog.open(DatasetCopyDialogueComponent, { + data: { + formControl: formControl, + datasetId: this.formGroup.value.id, + datasetProfileId: this.formGroup.value.profile, + datasetProfileExist: false, + confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'), + cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL') + } + }); + + dialogRef.afterClosed().pipe(takeUntil(this._destroyed)) + .subscribe(result => { + if (result && result.datasetProfileExist) { + console.log("I came out of the dialogue with result"); + console.log(result.formControl); + const newDmpId = result.formControl.value.id + this.router.navigate(['/datasets/copy/' + result.datasetId], { queryParams: { newDmpId: newDmpId } }); + } + }); + } } diff --git a/dmp-frontend/src/app/ui/dataset/dataset.module.ts b/dmp-frontend/src/app/ui/dataset/dataset.module.ts index d83b0c9ee..75fb68ef1 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset.module.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset.module.ts @@ -16,6 +16,7 @@ import { DatasetExternalServiceDialogEditorComponent } from './dataset-wizard/ex import { DatasetRoutingModule } from './dataset.routing'; import { DatasetCriteriaComponent } from './listing/criteria/dataset-criteria.component'; import { DatasetListingComponent } from './listing/dataset-listing.component'; +import { DatasetCopyDialogueComponent } from './dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component'; @NgModule({ imports: [ @@ -37,13 +38,15 @@ import { DatasetListingComponent } from './listing/dataset-listing.component'; DatasetExternalDataRepositoryDialogEditorComponent, DatasetExternalDatasetDialogEditorComponent, DatasetExternalRegistryDialogEditorComponent, - DatasetExternalServiceDialogEditorComponent + DatasetExternalServiceDialogEditorComponent, + DatasetCopyDialogueComponent ], entryComponents: [ DatasetExternalDataRepositoryDialogEditorComponent, DatasetExternalDatasetDialogEditorComponent, DatasetExternalRegistryDialogEditorComponent, - DatasetExternalServiceDialogEditorComponent + DatasetExternalServiceDialogEditorComponent, + DatasetCopyDialogueComponent ] }) export class DatasetModule { } diff --git a/dmp-frontend/src/app/ui/dataset/dataset.routing.ts b/dmp-frontend/src/app/ui/dataset/dataset.routing.ts index 3afd5859d..0b9f91566 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset.routing.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset.routing.ts @@ -53,6 +53,11 @@ const routes: Routes = [ data: { breadcrumb: true }, + }, + + { + path: 'copy/:id', + component: DatasetWizardComponent, } ]; @@ -60,4 +65,4 @@ const routes: Routes = [ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) -export class DatasetRoutingModule { } \ No newline at end of file +export class DatasetRoutingModule { } diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index 2af6d968b..0feb06388 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -256,7 +256,8 @@ "SAVE-AND-FINALISE": "Save and Finalise", "DOWNLOAD-PDF": "Download PDF", "DOWNLOAD-XML": "Download XML", - "DOWNLOAD-DOCX": "Download DOCX" + "DOWNLOAD-DOCX": "Download DOCX", + "COPY-DATASET": "Copy Dataset" }, "UPLOAD": { "UPLOAD-XML": "Import", @@ -264,6 +265,12 @@ "UPLOAD-XML-NAME": "Name Of Dataset Profile", "UPLOAD-XML-IMPORT": "File", "UPLOAD-XML-FILE-CANCEL": "Cancel" + }, + "DIALOGUE": { + "DMP-SEARCH": { + "PLACEHOLDER": "Search DMP" + }, + "ERROR-MESSAGE": "This DMP does not contain this Dataset Profile" } }, "DATASET-LISTING": {