Skip to content

Commit 4d6f947

Browse files
committed
Add orcid API values to UI
1 parent c2c75ee commit 4d6f947

File tree

2 files changed

+62
-54
lines changed

2 files changed

+62
-54
lines changed

package-lock.json

Lines changed: 33 additions & 34 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
@@ -196,26 +196,6 @@ export default defineComponent({
196196
const orcidErrors = computed(() => {
197197
const orcidErrors = orcidQueries(props.index)
198198
.filter(byError(errors.value))
199-
if (orcidErrors.length === 0) {
200-
// If a valid orcid is found, look for data in the orcid API (maybe only if we do not have data already)
201-
const orcid = '0000-0001-8555-849X' // This should come from props.orcid
202-
const orcidEndpoint = 'https://pub.sandbox.orcid.org/v3.0/expanded-search/?q=orcid:' + orcid + '&rows=1'
203-
axios.get(orcidEndpoint,
204-
{
205-
data: {},
206-
headers: {
207-
'accept': 'application/vnd.orcid+json'
208-
}
209-
}).then(resp => {
210-
console.log('These values should be injected in the right places')
211-
console.log('email : ' + resp.data['expanded-result'][0]['email'][0])
212-
console.log('last-name : ' + resp.data['expanded-result'][0]['family-names'])
213-
console.log('first-name: ' + resp.data['expanded-result'][0]['given-names'])
214-
console.log('Institution: ' + resp.data['expanded-result'][0]['institution-name'])
215-
console.log('Orcid : ' + resp.data['expanded-result'][0]['orcid-id'])
216-
217-
})
218-
}
219199
return orcidErrors
220200
.map(query => query.replace.message)
221201
})
@@ -229,6 +209,35 @@ export default defineComponent({
229209
orcidErrors
230210
}
231211
},
212+
watch: {
213+
orcid(oldVal, newVal) {
214+
if (this.orcid.length === 37 && this.orcidErrors.length === 0) {
215+
// If a valid orcid is found, look for data in the orcid API (maybe only if we do not have data already)
216+
const orcidSearchApi = 'https://pub.orcid.org/v3.0/expanded-search/?q=orcid:';
217+
const orcidEndpoint = this.orcid.replace('https://orcid.org/', orcidSearchApi) + '&rows=1';
218+
// This is a test endpoint on Zenodo sandbox.
219+
// const orcidEndpoint = 'https://pub.sandbox.orcid.org/v3.0/expanded-search/?q=orcid:0000-0001-8555-849X&rows=1';
220+
221+
axios.interceptors.request.use((config) => {
222+
config.props = this;
223+
return config;
224+
});
225+
226+
void axios.get(orcidEndpoint,
227+
{
228+
data: {},
229+
headers: {
230+
accept: 'application/vnd.orcid+json'
231+
}
232+
}).then(resp => {
233+
resp.config.props.$emit('update', 'givenNames', resp.data['expanded-result'][0]['given-names']);
234+
resp.config.props.$emit('update', 'familyNames', resp.data['expanded-result'][0]['family-names']);
235+
resp.config.props.$emit('update', 'email', resp.data['expanded-result'][0].email[0]);
236+
resp.config.props.$emit('update', 'affiliation', resp.data['expanded-result'][0]['institution-name'][0]);
237+
})
238+
}
239+
}
240+
},
232241
emits: ['closePressed', 'removePressed', 'update']
233242
})
234243
</script>

0 commit comments

Comments
 (0)