66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { Component, Inject } from '@angular/core';
|
|
import { UntypedFormGroup } from '@angular/forms';
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
import { CloneDmpPersist, Dmp } from '@app/core/model/dmp/dmp';
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
import { DmpCloneDialogEditorModel } from './dmp-clone-dialog.editor.model';
|
|
import { DmpEditorResolver } from '../dmp-editor-blueprint/dmp-editor.resolver';
|
|
|
|
@Component({
|
|
selector: 'app-dmp-clone-dialog',
|
|
templateUrl: './dmp-clone-dialog.component.html',
|
|
styleUrls: ['./dmp-clone-dialog.component.scss']
|
|
})
|
|
export class CloneDmpDialogComponent extends BaseComponent {
|
|
|
|
dmp: Dmp;
|
|
editorModel: DmpCloneDialogEditorModel;
|
|
formGroup: UntypedFormGroup;
|
|
|
|
constructor(
|
|
public dialogRef: MatDialogRef<CloneDmpDialogComponent>,
|
|
private dmpService: DmpService,
|
|
private uiNotificationService: UiNotificationService,
|
|
private language: TranslateService,
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
) {
|
|
super();
|
|
this.dmp = data.dmp;
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.editorModel = new DmpCloneDialogEditorModel().fromModel(this.data.dmp);
|
|
this.formGroup = this.editorModel.buildForm();
|
|
}
|
|
|
|
hasDescriptions() {
|
|
return this.dmp.descriptions?.length > 0;
|
|
}
|
|
|
|
close() {
|
|
this.dialogRef.close(null);
|
|
}
|
|
|
|
cancel() {
|
|
this.dialogRef.close(null);
|
|
}
|
|
|
|
confirm() {
|
|
if (!this.formGroup.valid) { return; }
|
|
const value: CloneDmpPersist = this.formGroup.value;
|
|
this.dmpService.clone(value, DmpEditorResolver.lookupFields()).pipe(takeUntil(this._destroyed)).subscribe(
|
|
dmp => this.dialogRef.close(dmp),
|
|
error => this.onCallbackError(error)
|
|
);
|
|
|
|
}
|
|
|
|
onCallbackError(error: any) {
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Error);
|
|
}
|
|
}
|