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({
|
|
|
|
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 {
|
2020-07-09 12:45:19 +02:00
|
|
|
|
|
|
|
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 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() {
|
|
|
|
this.router.navigate(['/quick-wizard']);
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
|
2020-07-09 17:27:15 +02:00
|
|
|
uploadFile(event) {
|
|
|
|
const dialogRef = this.dialog.open(DmpUploadDialogue, {
|
|
|
|
data: {
|
|
|
|
fileList: FileList,
|
|
|
|
success: Boolean,
|
|
|
|
dmpTitle: String
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result && result.success) {
|
|
|
|
this.dmpService.uploadXml(result.fileList, result.dmpTitle, result.dmpProfiles)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe((complete) => this.onCallbackImportComplete(),
|
|
|
|
(error) => this.onCallbackImportFail(error.error));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|