From 95710c440e01c78b3bbd67cc567554d666c3f1ed Mon Sep 17 00:00:00 2001 From: Mojib Wali <44528277+mb-wali@users.noreply.github.com> Date: Tue, 16 Mar 2021 09:55:59 +0100 Subject: [PATCH] depositform: get doi from backend --- .../invenio_theme_tugraz/deposit/DoiMint.js | 106 +++++++++--------- invenio_theme_tugraz/webpack.py | 2 +- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/invenio_theme_tugraz/assets/semantic-ui/js/invenio_theme_tugraz/deposit/DoiMint.js b/invenio_theme_tugraz/assets/semantic-ui/js/invenio_theme_tugraz/deposit/DoiMint.js index 730677c..bc6782b 100644 --- a/invenio_theme_tugraz/assets/semantic-ui/js/invenio_theme_tugraz/deposit/DoiMint.js +++ b/invenio_theme_tugraz/assets/semantic-ui/js/invenio_theme_tugraz/deposit/DoiMint.js @@ -10,7 +10,7 @@ import { } from "semantic-ui-react"; import { FieldArray } from "formik"; -import { DoiRest, MapDatacite } from "datacite-rest"; +import { FetchDoi, MapDatacite } from "datacite-rest"; export class DoiMint extends Component { constructor(props) { @@ -47,65 +47,65 @@ export class DoiMint extends Component { // this should fetch a new doi var pushDoi = (form) => { // activate the loader - this.setState({ - showLoader: true, - }); + this.setState({ + showLoader: true, + }); - const url = this.configs.datacite_url; - const auth = { - username: this.configs.datacite_uname, - password: this.configs.datacite_pass, - }; + // get the prefix from backend const prefix = this.configs.datacite_prefix; - // get mapped DOI - const mapped = MapDatacite(this.metadata, this.record.id, prefix); + if (prefix !== null) { + // get mapped DOI + const mapped = MapDatacite(this.metadata, this.record.id, prefix); - const _doirest = new DoiRest(url); + const _fetchdoi = new FetchDoi("/getdoi"); - // Create a new DOI - _doirest - .create(mapped, auth, this.configs.datacite_password_iv) - .then((data) => { - // if there is an error - if (data.data.errors) { - this.setState({ - showLoader: false, - isError: true, - errorMsg: data.data.errors[0].title, - }); - // if credentials are wrong! - } else if (data.code == 405) { - this.setState({ - showLoader: false, - isError: true, - errorMsg: "Not configured!", - }); - } - // new doi is fetched - else { - // add new identifier - const _identifiers = [ - { - identifier: data.data.data.id, - scheme: "doi", - }, - ]; - // submit the value to the form - this.setState({ identifiers: _identifiers }); - form.setFieldValue("metadata.identifiers", this.state.identifiers); + // Create a new DOI + _fetchdoi + .create(mapped) + .then((data) => { + // if there is an error + if (data.data.errors) { + this.setState({ + showLoader: false, + isError: true, + errorMsg: data.data.errors[0].title, + }); + } + // new doi is fetched + else { + // add new identifier + const _identifiers = [ + { + identifier: data.data.data.data.id, + scheme: "doi", + }, + ]; + // submit the value to the form + this.setState({ identifiers: _identifiers }); + form.setFieldValue( + "metadata.identifiers", + this.state.identifiers + ); - this.is_doi = true; - // deactivate the loader - this.setState({ - showLoader: false, - doi_id: this.state.identifiers[0].identifier, - }); - } - }) - .catch((error) => { - console.log("error", error); + this.is_doi = true; + // deactivate the loader + this.setState({ + showLoader: false, + doi_id: this.state.identifiers[0].identifier, + }); + } + }) + .catch((error) => { + console.log("error", error); + }); + } else { + this.setState({ + showLoader: false, + isError: true, + errorMsg: "Not configured!", }); + } }; // get a link of dio diff --git a/invenio_theme_tugraz/webpack.py b/invenio_theme_tugraz/webpack.py index 97ef93a..77d7032 100644 --- a/invenio_theme_tugraz/webpack.py +++ b/invenio_theme_tugraz/webpack.py @@ -40,7 +40,7 @@ theme = WebpackThemeBundle( '@ckeditor/ckeditor5-react': '^2.1.0', # datacite - rest api plugin - 'datacite-rest': '^0.1.4', + 'datacite-rest': '^0.1.5', }, )