Skip to content

Commit 6c12d77

Browse files
committed
Add orcid API values to UI
1 parent d5ea419 commit 6c12d77

File tree

2 files changed

+83
-42
lines changed

2 files changed

+83
-42
lines changed

package-lock.json

Lines changed: 54 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/AuthorCardEditing.vue

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,6 @@ export default defineComponent({
222222
const orcidErrors = computed(() => {
223223
const orcidErrors = orcidQueries(props.index)
224224
.filter(byError(errors.value))
225-
if (orcidErrors.length === 0) {
226-
// If a valid orcid is found, look for data in the orcid API (maybe only if we do not have data already)
227-
const orcid = '0000-0001-8555-849X' // This should come from props.orcid
228-
const orcidEndpoint = 'https://pub.sandbox.orcid.org/v3.0/expanded-search/?q=orcid:' + orcid + '&rows=1'
229-
axios.get(orcidEndpoint,
230-
{
231-
data: {},
232-
headers: {
233-
'accept': 'application/vnd.orcid+json'
234-
}
235-
}).then(resp => {
236-
console.log('These values should be injected in the right places')
237-
console.log('email : ' + resp.data['expanded-result'][0]['email'][0])
238-
console.log('last-name : ' + resp.data['expanded-result'][0]['family-names'])
239-
console.log('first-name: ' + resp.data['expanded-result'][0]['given-names'])
240-
console.log('Institution: ' + resp.data['expanded-result'][0]['institution-name'])
241-
console.log('Orcid : ' + resp.data['expanded-result'][0]['orcid-id'])
242-
243-
})
244-
}
245225
return orcidErrors
246226
.map(query => query.replace.message)
247227
})
@@ -255,6 +235,35 @@ export default defineComponent({
255235
orcidErrors
256236
}
257237
},
238+
watch: {
239+
orcid(oldVal, newVal) {
240+
if (this.orcid.length === 37 && this.orcidErrors.length === 0) {
241+
// If a valid orcid is found, look for data in the orcid API (maybe only if we do not have data already)
242+
const orcidSearchApi = 'https://pub.orcid.org/v3.0/expanded-search/?q=orcid:';
243+
const orcidEndpoint = this.orcid.replace('https://orcid.org/', orcidSearchApi) + '&rows=1';
244+
// This is a test endpoint on Zenodo sandbox.
245+
// const orcidEndpoint = 'https://pub.sandbox.orcid.org/v3.0/expanded-search/?q=orcid:0000-0001-8555-849X&rows=1';
246+
247+
axios.interceptors.request.use((config) => {
248+
config.props = this;
249+
return config;
250+
});
251+
252+
void axios.get(orcidEndpoint,
253+
{
254+
data: {},
255+
headers: {
256+
accept: 'application/vnd.orcid+json'
257+
}
258+
}).then(resp => {
259+
resp.config.props.$emit('update', 'givenNames', resp.data['expanded-result'][0]['given-names']);
260+
resp.config.props.$emit('update', 'familyNames', resp.data['expanded-result'][0]['family-names']);
261+
resp.config.props.$emit('update', 'email', resp.data['expanded-result'][0].email[0]);
262+
resp.config.props.$emit('update', 'affiliation', resp.data['expanded-result'][0]['institution-name'][0]);
263+
})
264+
}
265+
}
266+
},
258267
emits: ['closePressed', 'removePressed', 'update'],
259268
components: { SchemaGuideLink }
260269
})

0 commit comments

Comments
 (0)