2020-07-09 12:45:19 +02:00
|
|
|
import { Component, Inject } from '@angular/core';
|
2020-07-09 17:27:15 +02:00
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog';
|
2020-07-09 12:45:19 +02:00
|
|
|
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';
|
2020-07-09 12:45:19 +02:00
|
|
|
|
|
|
|
@Component({
|
2020-09-29 17:20:00 +02:00
|
|
|
selector: 'app-start-new-dmp',
|
|
|
|
templateUrl: './start-new-dmp-dialog.component.html',
|
|
|
|
styleUrls: ['./start-new-dmp-dialog.component.scss']
|
2020-07-09 12:45:19 +02:00
|
|
|
})
|
2020-07-09 17:27:15 +02:00
|
|
|
export class StartNewDmpDialogComponent extends BaseComponent {
|
2020-07-09 12:45:19 +02:00
|
|
|
|
2020-09-29 17:20:00 +02:00
|
|
|
public isDialog: boolean = false;
|
2020-07-09 12:45:19 +02:00
|
|
|
|
|
|
|
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 12:45:19 +02:00
|
|
|
) {
|
2020-07-09 17:27:15 +02:00
|
|
|
super();
|
2020-07-09 12:45:19 +02:00
|
|
|
this.isDialog = data.isDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
send() {
|
|
|
|
this.dialogRef.close(this.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.dialogRef.close(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
startWizard() {
|
2020-08-25 16:59:54 +02:00
|
|
|
this.router.navigate(['/plans/new']);
|
2020-07-09 12:45:19 +02:00
|
|
|
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))
|
2020-09-29 17:20:00 +02:00
|
|
|
.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);
|
|
|
|
}
|
|
|
|
|
2020-07-09 12:45:19 +02:00
|
|
|
}
|