diff --git a/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.ts b/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.ts index 0ac94d15a..4629561db 100644 --- a/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.ts +++ b/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.ts @@ -14,6 +14,7 @@ import { UiNotificationService, SnackBarNotificationLevel } from '../../../core/ import { FunderFormModel } from '../editor/grant-tab/funder-form-model'; import { ProjectFormModel } from '../editor/grant-tab/project-form-model'; import { GrantTabModel } from '../editor/grant-tab/grant-tab-model'; +import { HttpErrorResponse } from '@angular/common/http'; @Component({ selector: 'app-dmp-clone', @@ -90,12 +91,22 @@ export class DmpCloneComponent extends BaseComponent implements OnInit { formSubmit(): void { if (!this.isFormValid()) { return; } - this.dmpService.clone(this.formGroup.getRawValue(), this.itemId) - .pipe(takeUntil(this._destroyed)) - .subscribe( - complete => this.onCallbackSuccess(), - error => this.onCallbackError(error) - ); + if (this.isNewVersion) { + this.dmpService.newVersion(this.formGroup.getRawValue(), this.itemId) + .pipe(takeUntil(this._destroyed)) + .subscribe( + complete => this.onCallbackSuccess(), + error => this.onCallbackErrorNewVersion(error) + ); + } + else { + this.dmpService.clone(this.formGroup.getRawValue(), this.itemId) + .pipe(takeUntil(this._destroyed)) + .subscribe( + complete => this.onCallbackSuccess(), + error => this.onCallbackError(error) + ); + } } onCallbackSuccess(): void { @@ -107,6 +118,10 @@ export class DmpCloneComponent extends BaseComponent implements OnInit { this.setErrorModel(error.error); } + onCallbackErrorNewVersion(errorResponse: HttpErrorResponse) { + this.uiNotificationService.snackBarNotification(errorResponse.error.message, SnackBarNotificationLevel.Error); + } + public setErrorModel(validationErrorModel: ValidationErrorModel) { Object.keys(validationErrorModel).forEach(item => { (this.dmp.validationErrorModel)[item] = (validationErrorModel)[item]; diff --git a/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.html b/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.html index 885fc22ab..4d3ce06f2 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.html @@ -28,7 +28,7 @@ settings_backup_restore {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-FUNDER' | translate}} -
+
add {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.CREATE-NEW-FUNDER' | translate}}
@@ -110,7 +110,7 @@ settings_backup_restore {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-PROJECT' | translate}}
-
+
add {{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.CREATE-NEW-PROJECT' | translate}}
diff --git a/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.ts b/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.ts index 3d0e071a5..4413c1f50 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/grant-tab/grant-tab.component.ts @@ -74,7 +74,7 @@ export class GrantTabComponent implements OnInit { this.isCreateNew = (this.grantformGroup.get('label').value != null && this.grantformGroup.get('label').value.length > 0); this.isCreateNewProject = (this.projectFormGroup.get('label').value != null && this.projectFormGroup.get('label').value.length > 0); this.isCreateNewFunder = (this.funderFormGroup.get('label').value != null && this.funderFormGroup.get('label').value.length > 0); - this.setValidators(); + this.setGrantValidators(); this.setProjectValidators(); this.setFunderValidators(); } @@ -106,33 +106,31 @@ export class GrantTabComponent implements OnInit { createGrant() { if (this.isNewVersion) { return }; this.isCreateNew = !this.isCreateNew; - this.setValidators(); + this.setGrantValidators(); } createProject() { + if (this.isNewVersion) { return }; this.isCreateNewProject = !this.isCreateNewProject; this.setProjectValidators(); } createFunder() { + if (this.isNewVersion) { return }; this.isCreateNewFunder = !this.isCreateNewFunder; this.setFunderValidators(); } - setValidators() { + setGrantValidators() { if (this.isCreateNew) { this.grantformGroup.get('existGrant').disable(); this.grantformGroup.get('label').enable(); this.grantformGroup.get('description').enable(); - } else if (this.isFinalized) { + } else if (this.isFinalized || this.isNewVersion) { this.grantformGroup.get('existGrant').disable(); this.grantformGroup.get('label').disable(); this.grantformGroup.get('description').disable(); - } - if (this.isNewVersion) { - this.grantformGroup.get('label').disable(); - } - else { + } else { this.grantformGroup.get('existGrant').enable(); this.grantformGroup.get('label').disable(); this.grantformGroup.get('label').reset(); @@ -146,12 +144,11 @@ export class GrantTabComponent implements OnInit { this.projectFormGroup.get('existProject').disable(); this.projectFormGroup.get('label').enable(); this.projectFormGroup.get('description').enable(); - } else if (this.isFinalized) { + } else if (this.isFinalized || this.isNewVersion) { this.projectFormGroup.get('existProject').disable(); this.projectFormGroup.get('label').disable(); this.projectFormGroup.get('description').disable(); - } - else { + } else { this.projectFormGroup.get('existProject').enable(); this.projectFormGroup.get('label').disable(); this.projectFormGroup.get('label').reset(); @@ -164,11 +161,10 @@ export class GrantTabComponent implements OnInit { if (this.isCreateNewFunder) { this.funderFormGroup.get('existFunder').disable(); this.funderFormGroup.get('label').enable(); - } else if (this.isFinalized) { + } else if (this.isFinalized || this.isNewVersion) { this.funderFormGroup.get('existFunder').disable(); this.funderFormGroup.get('label').disable(); - } - else { + } else { this.funderFormGroup.enable(); this.funderFormGroup.get('label').disable(); this.funderFormGroup.get('label').reset();