diff --git a/deposit/deposit-file/deposit-file.component.ts b/deposit/deposit-file/deposit-file.component.ts index 800c8345..121655df 100644 --- a/deposit/deposit-file/deposit-file.component.ts +++ b/deposit/deposit-file/deposit-file.component.ts @@ -12,65 +12,73 @@ declare var UIkit: any; @Component({ selector: 'deposition', template: ` -
-
-
- Authorize OpenAIRE to deposit files in your Zenodo account. +
+ The session with Zenodo will be valid for {{(userTokens.zenodoDuration/3600) <24?(userTokens.zenodoDuration/3600) + (userTokens.zenodoDuration == '3600'?' hour':' hours'): (userTokens.zenodoDuration/(3600 * 24)) + ' days'}} +
+
+
You have already upload the following files:
+ +
+
+
{{record.depositDate}} View + in Zenodo + +
+
{{record.filenames.join(', ')}} +
+
- - Authorize -
- -
- - +
+
+
+ Use basic metadata (title, description, type) of this record to upload a file in Zenodo. +
+
- - - Upload a file to deposit - + + + Upload a file to deposit +
- -
-
This is for testing
- - +
+ + + +
+
Your file has been uploaded in Zenodo in draft mode. You can view the record + here, edit and publish it. +
The preserved DOI is {{space.metadata.prereserve_doi.doi}}.
+ + Undo: This will delete your deposited file in zenodo. + +
+
{{errorMessage}}
+
+ + +
+ +
+
+
Your file has been deposited in Zenodo with the main metadata of this record. You can view the new record here, edit and publish it.
The preserved DOI is {{space.metadata.prereserve_doi.doi}}.
- - Undo: This will delete your deposited file in zenodo. -
-
{{errorMessage}}
-
- - -
- -
-
- - - -
Your file has been deposited in Zenodo with the main metadata of this record. You can view the new record - here, edit and publish it. -
-
The preserved DOI is {{space.metadata.prereserve_doi.doi}}.
-
-
-
+ + + ` }) @@ -79,7 +87,8 @@ export class DepositionComponent { properties = properties; @Input() result: ResultLandingInfo; - authorizeUrl = this.properties.zenodoDepositAPI + "oauth/authorize?response_type=code&client_id=" + + authorizeUrl = this.properties.zenodoDepositAPI + + /* "oauth/authorize?response_type=code&client_id=" +*/ "oauth/authorize?response_type=token&client_id=" + this.properties.zenodoDepositClientId + "&scope=deposit%3Awrite+deposit%3Aactions&state=step1&redirect_uri=" + encodeURIComponent(this.properties.zenodoDepositRedirectURI); @@ -95,6 +104,8 @@ export class DepositionComponent { public code: string = ""; public gotToken: boolean = false; public space = null; + public mongoRecord = null; + public prevMongoRecords = null; public window: any; user//: User; userTokens; @@ -124,20 +135,8 @@ export class DepositionComponent { } else { this.authorized = false; } - // })); - /* this.subscriptions.push(this.route.queryParams.subscribe(params => { - if (params['code']) { - this.code = params['code']; - localStorage.setItem('deposit_code', this.code); - } else if (localStorage.getItem('deposit_code')) { - this.code = localStorage.getItem('deposit_code'); - } - // if(this.code){ - // this.authorized = true; - // } - this.gotToken = false; + this.getPrevUploads(); - }));*/ } ngOnDestroy() { @@ -159,7 +158,6 @@ export class DepositionComponent { } authorize() { - console.log(this.authorizeUrl) this.window = window.open(this.authorizeUrl, '_blank', 'location=yes,height=700,width=540,left=500,top=100,scrollbars=yes,status=yes'); // this.requestGrant = false; @@ -168,16 +166,17 @@ export class DepositionComponent { let self = this; window.onmessage = function (ev) { if (ev.isTrusted && ev.origin == location.origin) { + console.log(ev.data) let user = { - id: self.user.id, + _id: self.user.id, firstName: self.user.firstname, lastName: self.user.lastname, email: self.user.email, zenodoToken: ev.data['access_token'], zenodoDuration: ev.data['expires_in'], - zenodoRefresh: ev.data['refresh_token'], + zenodoRefresh: ev.data['refresh_token']?ev.data['refresh_token']:"", zenodoUserId: ev.data['user']['id'], - code: ev.data['code'] + code: ev.data['code']?ev.data['code']:"" }; @@ -185,6 +184,9 @@ export class DepositionComponent { if (res) { self.authorized = true; self.userTokens = res; + if (self.filesToUpload) { + self.start(); + } } }) } @@ -204,42 +206,10 @@ export class DepositionComponent { this.grantModal.cancel(); } - // the following method uses client ID and client Secret, which are sessitive data. - // Our API should return the response, without revealing the call to ORCID. - /*public getToken() { - this.showLoading = true; - console.log(this.code) - - this._http.get(properties.utilsService + "/deposit/getToken?code=" + this.code).subscribe(res => { - console.log(res) - localStorage.setItem('deposit_token', res['access_token']); - localStorage.setItem('deposit_refresh', res['refresh_token']); - }) - - } - - public getTokenByRefresh() { - this.showLoading = true; - console.log(this.code, localStorage.getItem('deposit_refresh')) - - this._http.get(properties.utilsService + "/deposit/getToken?refresh_token=" + localStorage.getItem('deposit_refresh')).subscribe(res => { - console.log(res) - localStorage.setItem('deposit_token', res['access_token']); - localStorage.setItem('deposit_refresh', res['refresh_token']); - }) - - }*/ - public getInfo(func) { if (this.userTokens.zenodoToken) { - - /* this._http.get("http://localhost:8000/deposit/info?token=" + localStorage.getItem('deposit_token')).subscribe(res => { - console.log(res) - - })*/ this._http.get(this.properties.zenodoDepositAPI + "api/deposit/depositions?access_token=" + this.userTokens.zenodoToken).subscribe(res => { console.log(res) - alert(res) if (func) { func(); } @@ -263,25 +233,27 @@ export class DepositionComponent { this.space = null; this.errorMessage = null; this.showLoading = true; - console.log(this.userTokens.zenodoToken) if (this.userTokens.zenodoToken) { let record = this.resultInfoToZenodoRecord(); - console.log(record) this._http.post(this.properties.zenodoDepositAPI + "api/deposit/depositions?access_token=" + this.userTokens.zenodoToken, { - "metadata": record /*, "submitted": true*/ }).subscribe(res => { - console.log(res) this.space = res; // this.meta(); console.log(res) - this.depositFile(); + // for(let file of this.filesToUpload) { + // this.depositFile(file); + // } + this.depositFile(this.filesToUpload[0]); + this.saveRecord(record, this.filesToUpload, this.space); + this.filesToUpload = []; }, error => { console.error(error.message) - this.errorMessage = error.message; - this.showLoading = false; + // this.errorMessage = error.message; + // this.showLoading = false; + this.authorize(); }) } } @@ -294,9 +266,9 @@ export class DepositionComponent { creators: [], description: this.result.description } - if (this.result.resultType == 'publication' && this.result.types[0]) { - record['publication_type'] = this.result.types[0]; - } + /* if (this.result.resultType == 'publication' && this.result.types[0]) { + record['publication_type'] = this.result.types[0]; + }*/ for (let author of this.result.authors) { record.creators.push({name: author.fullName, orcid: author.orcid}) } @@ -309,24 +281,22 @@ export class DepositionComponent { // this.errorMessage = "There is no selected file to upload."; return; } - this.start(); + if (this.authorized) { + // if(valid?) { + this.start(); + // } + } else { + this.authorize(); + } } - depositFile() { - + depositFile(file) { const formData: FormData = new FormData(); - formData.append('file', this.filesToUpload[0]); - const fileName = this.filesToUpload[0].name; // Replace with file name - + formData.append('file', file); + const fileName = file.name; // Replace with file name let url = `${this.space.links.bucket}/${fileName}`; - - const data = { - name: fileName, - ...formData - }; - const headers = new HttpHeaders({ 'Content-type': 'application/octet-stream' }); @@ -356,12 +326,49 @@ export class DepositionComponent { }*/ } + saveRecord(record, files, res) { + let mongoRecord = { + + aaiId: this.user.id, + title: record.title, + description: record.description, + type: record["upload_type"], + date: record.publication_date, + authors: [], + filenames: [], + pids: [], + openAIREId: this.result.relcanId, + recordId: this.space.record_id, + ownerId: this.userTokens.zenodoUserId + }; + for (let file of files) { + mongoRecord.filenames.push(file.name) + } + for (let pidtype of this.result.identifiers.keys()) { + for (let pid of this.result.identifiers.get(pidtype)) { + if (mongoRecord.pids.indexOf(pid) == -1) { + mongoRecord.pids.push(pid) + } + } + } + for (let author of record.creators) { + mongoRecord.authors.push({name: author.name, orcid: author.orcid ? author.orcid : ""}) + } + this._http.post(this.properties.depositAPI + "deposit/record/save", mongoRecord).subscribe(res => { + console.log(res) + this.mongoRecord = res; + }) + + } + deleteSpace() { this._http.delete(this.properties.zenodoDepositAPI + "api/deposit/depositions/" + this.space.id + "?access_token=" + this.userTokens.zenodoToken, ).subscribe(res => { console.log(res) this.space = null; + this._http.delete(this.properties.depositAPI + "deposit/record/delete?id=" + this.mongoRecord._id).subscribe(res => { + }) }, error => { console.error(error.message) UIkit.notification({ @@ -393,4 +400,18 @@ export class DepositionComponent { }) } + + getPrevUploads() { + let pids = []; + for (let pidtype of this.result.identifiers.keys()) { + for (let pid of this.result.identifiers.get(pidtype)) { + if (pids.indexOf(pid) == -1) { + pids.push(pid) + } + } + } + this._http.get(this.properties.depositAPI + "deposit/record/get?aaiId=" + this.user.id + (pids.length > 0 ? "&pid=" + pids.join("&pid=") : "") + "&openaireId=" + this.result.relcanId).subscribe(res => { + this.prevMongoRecords = res; + }) + } } diff --git a/deposit/deposit-file/deposit-file.module.ts b/deposit/deposit-file/deposit-file.module.ts index 76806ba2..e1925450 100644 --- a/deposit/deposit-file/deposit-file.module.ts +++ b/deposit/deposit-file/deposit-file.module.ts @@ -3,12 +3,14 @@ import {CommonModule} from '@angular/common'; import {DepositionComponent} from "./deposit-file.component"; import {AlertModalModule} from "../../utils/modal/alertModal.module"; import {LoadingModule} from "../../utils/loading/loading.module"; +import {IconsModule} from "../../utils/icons/icons.module"; @NgModule({ imports: [ CommonModule, AlertModalModule, LoadingModule, + IconsModule, ], declarations: [ DepositionComponent diff --git a/deposit/deposit-grant-redirect/deposit.component.ts b/deposit/deposit-grant-redirect/deposit.component.ts index 214cfb77..45e67681 100644 --- a/deposit/deposit-grant-redirect/deposit.component.ts +++ b/deposit/deposit-grant-redirect/deposit.component.ts @@ -46,7 +46,7 @@ export class DepositComponent { this.updateDescription(description); this.updateUrl( properties.domain + properties.baseLink + this.route.url); - this.subscriptions.push(this.route.queryParams.subscribe(params => { + /*this.subscriptions.push(this.route.queryParams.subscribe(params => { this.gotToken = false; this.code = params['code']; if (this.code) { @@ -54,7 +54,25 @@ export class DepositComponent { } else { this.message = "No code provided to authorize OpenAIRE to deposit in your Zenodo account. Please try again!" } - })); + }));*/ + this.route.fragment.subscribe((fragment: string | null) => { + console.log(fragment) + let res = {}; + //access_token=2qULnkWIsZf6XLUgnbASgcC6zhNt18&expires_in=5184000&token_type=Bearer&scope=deposit:write+deposit:actions&state=step1&user={'id':+'12352'} + let splits = fragment.split("&"); + for(let split of splits){ + if(split.split('=')[0] == 'access_token'){ + res['access_token'] = split.split('=')[1] + } + if(split.split('=')[0] == 'expires_in'){ + res['expires_in'] = split.split('=')[1] + } + if(split.split('=')[0] == 'user'){ + res['user'] = split.split('=')[1] + } + } + this.closeModal(res); + }); } ngOnDestroy() { @@ -70,15 +88,7 @@ export class DepositComponent { this._http.get(this.properties.depositAPI + "deposit/zenodo/getTokenByCode?code=" + this.code).subscribe(res => { console.log(res) res["code"] = this.code - this.message = "
Thank you for authorizing OpenAIRE to use your Zenodo account for deposit!
" + - "
This window will automatically close and you will be ready to deposit.
"; - if(window && window.opener) { - window.opener.postMessage(res,"*"); - window.close(); - } - setTimeout(() => { - this.message += "
If this window does not close automatically, please close it and continue!
"; - }, 3000); + this.closeModal(res); }, error =>{ console.log(error) this.message = error.message @@ -86,7 +96,17 @@ export class DepositComponent { } - + closeModal(res){ + this.message = "
Thank you for authorizing OpenAIRE to use your Zenodo account for deposit!
" + + "
This window will automatically close and you will be ready to deposit.
"; + if(window && window.opener) { + window.opener.postMessage(res,"*"); + window.close(); + } + setTimeout(() => { + this.message += "
If this window does not close automatically, please close it and continue!
"; + }, 3000); + } private updateTitle(title: string) { this._title.setTitle(title); this._meta.updateTag({content: title}, "property='og:title'"); diff --git a/landingPages/result/resultLanding.component.html b/landingPages/result/resultLanding.component.html index d1c019f7..4b49dc5b 100644 --- a/landingPages/result/resultLanding.component.html +++ b/landingPages/result/resultLanding.component.html @@ -77,7 +77,7 @@
- diff --git a/utils/entity-actions/entity-actions.component.ts b/utils/entity-actions/entity-actions.component.ts index fa904194..e81c2b8b 100644 --- a/utils/entity-actions/entity-actions.component.ts +++ b/utils/entity-actions/entity-actions.component.ts @@ -35,22 +35,22 @@ import {EnvProperties} from "../properties/env-properties"; Cite
-
+
- Deposit + Upload a file
- +
Embed
-
@@ -93,32 +90,8 @@ import {EnvProperties} from "../properties/env-properties"; - -
-
-
- - - Find a repository to deposit or publish your research in Open Access - -
-
-
OR
-
- - - Upload a file in Zenodo - - -
-
-
- Back - -
+ + ` })