This commit is contained in:
Diamantis Tziotzios 2019-09-02 13:18:21 +03:00
commit 433c28c510
3 changed files with 34 additions and 23 deletions

View File

@ -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,6 +91,15 @@ export class DmpCloneComponent extends BaseComponent implements OnInit {
formSubmit(): void {
if (!this.isFormValid()) { return; }
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(
@ -97,6 +107,7 @@ export class DmpCloneComponent extends BaseComponent implements OnInit {
error => this.onCallbackError(error)
);
}
}
onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
@ -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 => {
(<any>this.dmp.validationErrorModel)[item] = (<any>validationErrorModel)[item];

View File

@ -28,7 +28,7 @@
<mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-FUNDER' | translate}}</span>
</div>
<div class="col-12 add-entity" *ngIf="!isCreateNewFunder" (click)="createFunder()">
<div class="col-12" [ngClass]="isNewVersion?'disabled-toggle':'add-entity'" *ngIf="!isCreateNewFunder" (click)="createFunder()">
<mat-icon>add</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.CREATE-NEW-FUNDER' | translate}}</span>
</div>
@ -110,7 +110,7 @@
<mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-PROJECT' | translate}}</span>
</div>
<div class="col-12 add-entity" *ngIf="!isCreateNewProject" (click)="createProject()">
<div class="col-12" [ngClass]="isNewVersion?'disabled-toggle':'add-entity'" *ngIf="!isCreateNewProject" (click)="createProject()">
<mat-icon>add</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.CREATE-NEW-PROJECT' | translate}}</span>
</div>

View File

@ -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();