From a7c814b0b4e69dcd0ff1ad5f1f88a9c4a90204cd Mon Sep 17 00:00:00 2001 From: gpapavgeri Date: Thu, 9 Jul 2020 18:27:15 +0300 Subject: [PATCH] 'Start-new-dmp-dialog' completed --- .../start-new-dmp-dialog.component.html | 2 +- .../start-new-dmp-dialog.component.ts | 45 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component.html b/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component.html index 5b0c101a8..05749a473 100644 --- a/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component.html +++ b/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component.html @@ -8,7 +8,7 @@

{{'NAV-BAR.START-NEW-DMP' | translate}}

{{'NAV-BAR.START-NEW-DMP-TXT' | translate}}

- diff --git a/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component.ts b/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component.ts index d9a22912e..5ad72e5c3 100644 --- a/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component.ts +++ b/dmp-frontend/src/app/ui/dmp/start-new-dmp-dialogue/start-new-dmp-dialog.component.ts @@ -1,21 +1,32 @@ import { Component, Inject } from '@angular/core'; -import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog'; import { Router } from '@angular/router'; +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'] }) -export class StartNewDmpDialogComponent { +export class StartNewDmpDialogComponent extends BaseComponent { public isDialog: boolean = false; constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, - private router: Router + private router: Router, + public dialog: MatDialog, + private uiNotificationService: UiNotificationService, + private language: TranslateService, + private dmpService: DmpService ) { + super(); this.isDialog = data.isDialog; } @@ -36,4 +47,32 @@ export class StartNewDmpDialogComponent { this.close(); } + 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); + } + }