123 lines
5.1 KiB
TypeScript
123 lines
5.1 KiB
TypeScript
import { Component, Inject, OnInit } from '@angular/core';
|
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
import { DepositConfigurationStatus } from '@app/core/common/enum/deposit-configuration-status';
|
|
import { DepositConfigurationModel } from '@app/core/model/deposit/deposit-configuration';
|
|
import { DmpOverviewModel } from '@app/core/model/dmp/dmp-overview';
|
|
import { DepositRepositoriesService } from '@app/core/services/deposit-repositories/deposit-repositories.service';
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
import { Oauth2DialogService } from '@app/ui/misc/oauth2-dialog/service/oauth2-dialog.service';
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
|
import { MultipleChoiceDialogComponent } from '@common/modules/multiple-choice-dialog/multiple-choice-dialog.component';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
@Component({
|
|
selector: 'app-dmp-deposit-dialog',
|
|
templateUrl: './dmp-deposit-dialog.component.html',
|
|
styleUrls: ['./dmp-deposit-dialog.component.scss']
|
|
})
|
|
export class DmpDepositDialogComponent extends BaseComponent implements OnInit {
|
|
|
|
inputRepos: DepositConfigurationModel[];
|
|
outputRepos: string[];
|
|
dmp: DmpOverviewModel;
|
|
|
|
constructor(
|
|
private dmpService: DmpService,
|
|
private depositRepositoriesService: DepositRepositoriesService,
|
|
public dialogRef: MatDialogRef<DmpDepositDialogComponent>,
|
|
private dialog: MatDialog,
|
|
private language: TranslateService,
|
|
private uiNotificationService: UiNotificationService,
|
|
private oauth2DialogService: Oauth2DialogService,
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
) {
|
|
super();
|
|
this.inputRepos = data['depositRepos'][0];
|
|
this.dmp = data['depositRepos'][1];
|
|
this.outputRepos = [];
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
onSubmit() {
|
|
this.dialogRef.close(this.outputRepos);
|
|
}
|
|
|
|
close() {
|
|
this.dialogRef.close(this.outputRepos);
|
|
}
|
|
|
|
deposit(repo: DepositConfigurationModel) {
|
|
|
|
if(repo.depositAccountStatus == DepositConfigurationStatus.BothSystemAndUser){
|
|
|
|
const dialogRef = this.dialog.open(MultipleChoiceDialogComponent, {
|
|
maxWidth: '600px',
|
|
restoreFocus: false,
|
|
data: {
|
|
message: 'Which account would you like to use?',//this.language.instant('GENERAL.ERRORS.HTTP-REQUEST-ERROR'),
|
|
titles: ['Login with ' + repo.repositoryId/*this.language.instant('DMP-OVERVIEW.MULTIPLE-DIALOG.ZENODO-LOGIN')*/, this.language.instant('DMP-OVERVIEW.MULTIPLE-DIALOG.USE-DEFAULT')]
|
|
}
|
|
});
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
switch (result) {
|
|
case 0:
|
|
this.showOauth2Dialog('https://sandbox.zenodo.org/oauth/authorize'+ '?client_id=' + repo.repositoryLoginClientId
|
|
+ '&response_type=code&scope=deposit:write+deposit:actions+user:email&state=astate&redirect_uri='
|
|
+ 'http://localhost:4200/login/external/zenodo', repo, this.dmp);
|
|
break;
|
|
case 1:
|
|
this.depositRepositoriesService.createDoi(repo.repositoryId, this.dmp.id, null)
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(doi =>{
|
|
this.onDOICallbackSuccess();
|
|
this.outputRepos.push(doi);
|
|
}, error => this.onDeleteCallbackError(error));
|
|
break;
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
onDOICallbackSuccess(): void {
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DMP-EDITOR.SNACK-BAR.SUCCESSFUL-DOI'), SnackBarNotificationLevel.Success);
|
|
}
|
|
|
|
onDeleteCallbackError(error) {
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? this.language.instant(error.error.message) : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
|
}
|
|
|
|
showOauth2Dialog(url: string, repo: DepositConfigurationModel, dmp: DmpOverviewModel) {
|
|
this.oauth2DialogService.login(url)
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(result => {
|
|
if (result !== undefined) {
|
|
if (result.oauthCode !== undefined && result.oauthCode !== null) {
|
|
this.depositRepositoriesService.getAccessToken(repo.repositoryId, result.oauthCode)
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(token => {
|
|
this.depositRepositoriesService.createDoi(repo.repositoryId, dmp.id, token)
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(doi =>{
|
|
this.onDOICallbackSuccess();
|
|
this.outputRepos.push(doi);
|
|
}, error => this.onDeleteCallbackError(error));
|
|
});
|
|
// this.userService.registerDOIToken(result.oauthCode, this.configurationService.app + 'oauth2')
|
|
// .pipe(takeUntil(this._destroyed))
|
|
// .subscribe(() => {
|
|
// this.hasDOIToken = true;
|
|
// this.showConfirmationDOIDialog(dmp);
|
|
// });
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|