'Start-new-dmp-dialog' completed

This commit is contained in:
gpapavgeri 2020-07-09 18:27:15 +03:00
parent dd0f158769
commit a7c814b0b4
2 changed files with 43 additions and 4 deletions

View File

@ -8,7 +8,7 @@
<h1 mat-dialog-title class="title">{{'NAV-BAR.START-NEW-DMP' | translate}}</h1>
<p class="text">{{'NAV-BAR.START-NEW-DMP-TXT' | translate}}</p>
<div class="actions">
<button type="button" class="normal-btn upload-btn d-flex flex-row align-items-center">
<button type="button" class="normal-btn upload-btn d-flex flex-row align-items-center" (click)="uploadFile($event)">
<mat-icon class="pr-2">file_upload</mat-icon>
{{ 'NAV-BAR.IMPORT-FROM-FILE' | translate }}
</button>

View File

@ -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<StartNewDmpDialogComponent>,
@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);
}
}