Skip to content

Commit bd7f6bb

Browse files
committed
Add orcid API values to UI
1 parent ba28c53 commit bd7f6bb

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

0 commit comments

Comments
 (0)