argos/dmp-frontend/src/app/ui/dmp/new-version-dialog/dmp-new-version-dialog.comp...

68 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-12-29 16:04:16 +01:00
import { Component, Inject } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Dmp, NewVersionDmpPersist } 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 { DmpNewVersionDialogEditorModel } from './dmp-new-version-dialog.editor.model';
import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.service';
2024-03-01 17:50:46 +01:00
import { DmpEditorResolver } from '../dmp-editor-blueprint/dmp-editor.resolver';
2023-12-29 16:04:16 +01:00
@Component({
selector: 'app-dmp-new-version-dialog',
templateUrl: './dmp-new-version-dialog.component.html',
styleUrls: ['./dmp-new-version-dialog.component.scss']
})
export class NewVersionDmpDialogComponent extends BaseComponent {
dmp: Dmp;
editorModel: DmpNewVersionDialogEditorModel;
formGroup: UntypedFormGroup;
constructor(
public dialogRef: MatDialogRef<NewVersionDmpDialogComponent>,
private dmpService: DmpService,
public dmpBlueprintService: DmpBlueprintService,
private uiNotificationService: UiNotificationService,
private language: TranslateService,
@Inject(MAT_DIALOG_DATA) public data: any
) {
super();
this.dmp = data.dmp;
}
ngOnInit() {
this.editorModel = new DmpNewVersionDialogEditorModel().fromModel(this.data.dmp);
this.formGroup = this.editorModel.buildForm();
}
hasDescriptions() {
2024-03-01 17:50:46 +01:00
return this.dmp.descriptions?.length > 0;
2023-12-29 16:04:16 +01:00
}
close() {
this.dialogRef.close(null);
}
cancel() {
this.dialogRef.close(null);
}
confirm() {
if (!this.formGroup.valid) { return; }
const value: NewVersionDmpPersist = this.formGroup.value;
2024-03-01 17:50:46 +01:00
this.dmpService.newVersion(value, DmpEditorResolver.lookupFields()).pipe(takeUntil(this._destroyed)).subscribe(
2023-12-29 16:04:16 +01:00
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);
}
}