argos/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.compon...

85 lines
2.6 KiB
TypeScript
Raw Normal View History

import { Component, Inject } from '@angular/core';
2020-07-09 17:27:15 +02:00
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
2020-07-09 17:27:15 +02:00
import { DmpUploadDialogue } from '../listing/upload-dialogue/dmp-upload-dialogue.component';
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
import { TranslateService } from '@ngx-translate/core';
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { takeUntil } from 'rxjs/operators';
import { BaseComponent } from '@common/base/base.component';
@Component({
selector: 'app-start-new-dmp',
templateUrl: './start-new-dmp-dialog.component.html',
styleUrls: ['./start-new-dmp-dialog.component.scss']
})
2020-07-09 17:27:15 +02:00
export class StartNewDmpDialogComponent extends BaseComponent {
public isDialog: boolean = false;
constructor(
public dialogRef: MatDialogRef<StartNewDmpDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
2020-07-09 17:27:15 +02:00
private router: Router,
public dialog: MatDialog,
private uiNotificationService: UiNotificationService,
private language: TranslateService,
private dmpService: DmpService
) {
2020-07-09 17:27:15 +02:00
super();
this.isDialog = data.isDialog;
}
cancel() {
this.dialogRef.close();
}
send() {
this.dialogRef.close(this.data);
}
close() {
this.dialogRef.close(false);
}
startWizard() {
this.router.navigate(['/plans/new']);
this.close();
}
2020-07-09 17:27:15 +02:00
uploadFile(event) {
const dialogRef = this.dialog.open(DmpUploadDialogue, {
2020-09-28 14:44:32 +02:00
width: '528px',
2020-07-09 17:27:15 +02:00
data: {
fileList: FileList,
success: Boolean,
dmpTitle: String
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result && result.success) {
2020-09-28 14:44:32 +02:00
this.dmpService.uploadXml(result.fileList[0], result.dmpTitle, result.dmpProfiles)
2020-07-09 17:27:15 +02:00
.pipe(takeUntil(this._destroyed))
.subscribe(
(complete) => {
this.onCallbackImportComplete();
this.dialog.closeAll();
},
(error) => this.onCallbackImportFail(error.error)
);
2020-07-09 17:27:15 +02:00
}
});
}
private onCallbackImportComplete() {
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-UPLOAD.UPLOAD-SUCCESS'), SnackBarNotificationLevel.Success);
this.router.navigate(['/reload']).then(() => this.router.navigate(['/plans']));
// this.router.navigate(['/reload']).then(() => this.isPublic ? this.router.navigate(['/explore-plans']) : this.router.navigate(['/plans']));
}
private onCallbackImportFail(error: any) {
this.uiNotificationService.snackBarNotification(error.message, SnackBarNotificationLevel.Error);
}
}