@abi-software/map-utilities 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/map-utilities.js +3485 -3435
- package/dist/map-utilities.umd.cjs +57 -57
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/Tooltip/ExternalResourceCard.vue +117 -52
- package/src/components/utilities.js +5 -0
package/package.json
CHANGED
|
@@ -21,11 +21,33 @@
|
|
|
21
21
|
<li
|
|
22
22
|
v-for="reference of pubMedReferences"
|
|
23
23
|
:key="reference.id"
|
|
24
|
-
:class="{'loading': reference.citation && reference.citation[citationType] === ''}"
|
|
24
|
+
:class="{'loading': reference.citation && !reference.citation.error && reference.citation[citationType] === ''}"
|
|
25
25
|
>
|
|
26
|
-
<template v-if="reference.citation
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
<template v-if="reference.citation">
|
|
27
|
+
|
|
28
|
+
<!-- DOI Server Error -->
|
|
29
|
+
<template v-if="reference.citation.error?.ref === 'doi' && reference.citation.error?.type === citationType">
|
|
30
|
+
<span>Internal Server Error</span><br />
|
|
31
|
+
Sorry, something went wrong.<br />
|
|
32
|
+
The dataset citation generator (<a
|
|
33
|
+
:href="crosscite_host"
|
|
34
|
+
target="_blank"
|
|
35
|
+
>{{ crosscite_host }}</a>) encountered an internal error and was unable to complete your
|
|
36
|
+
request.<br />
|
|
37
|
+
Please come back later.
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<!-- PubMed Server Error -->
|
|
41
|
+
<template v-else-if="reference.citation.error?.ref === 'pubmed' && reference.citation.error?.type === citationType">
|
|
42
|
+
<span>Sorry, something went wrong.</span><br />
|
|
43
|
+
Please try again.
|
|
44
|
+
<span class="reload-button" @click="reloadCitation(reference)">Reload</span>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<template v-else>
|
|
48
|
+
<span v-html="reference.citation[citationType]"></span>
|
|
49
|
+
<CopyToClipboard :content="reference.citation[citationType]" />
|
|
50
|
+
</template>
|
|
29
51
|
</template>
|
|
30
52
|
</li>
|
|
31
53
|
|
|
@@ -44,8 +66,9 @@
|
|
|
44
66
|
|
|
45
67
|
<script>
|
|
46
68
|
import CopyToClipboard from '../CopyToClipboard/CopyToClipboard.vue';
|
|
69
|
+
import { delay } from '../utilities';
|
|
47
70
|
|
|
48
|
-
const CROSSCITE_API_HOST = 'https://citation.
|
|
71
|
+
const CROSSCITE_API_HOST = 'https://citation.doi.org';
|
|
49
72
|
const CITATION_OPTIONS = [
|
|
50
73
|
{
|
|
51
74
|
label: 'APA',
|
|
@@ -65,6 +88,7 @@ const CITATION_OPTIONS = [
|
|
|
65
88
|
},
|
|
66
89
|
];
|
|
67
90
|
const CITATION_DEFAULT = 'apa';
|
|
91
|
+
const LOADING_DELAY = 600;
|
|
68
92
|
|
|
69
93
|
export default {
|
|
70
94
|
name: "ExternalResourceCard",
|
|
@@ -82,6 +106,7 @@ export default {
|
|
|
82
106
|
referecesListContent: '',
|
|
83
107
|
citationOptions: CITATION_OPTIONS,
|
|
84
108
|
citationType: CITATION_DEFAULT,
|
|
109
|
+
crosscite_host: CROSSCITE_API_HOST,
|
|
85
110
|
}
|
|
86
111
|
},
|
|
87
112
|
watch: {
|
|
@@ -251,56 +276,90 @@ export default {
|
|
|
251
276
|
this.citationType = citationType;
|
|
252
277
|
this.getCitationText(citationType);
|
|
253
278
|
},
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const { title, pubdate, authors } = resultObj;
|
|
289
|
-
const authorNames = authors ? authors.map((author) => author.name) : [];
|
|
290
|
-
const formattedText = this.formatCopyReference({
|
|
291
|
-
title: title || '',
|
|
292
|
-
date: pubdate || '',
|
|
293
|
-
authors: authorNames,
|
|
294
|
-
url: `https://pubmed.ncbi.nlm.nih.gov/${id}`,
|
|
295
|
-
});
|
|
279
|
+
generateCitationText: function (reference, citationType) {
|
|
280
|
+
const { id, type, doi } = reference;
|
|
281
|
+
|
|
282
|
+
if (
|
|
283
|
+
!(reference.citation && reference.citation[citationType])
|
|
284
|
+
&& id
|
|
285
|
+
) {
|
|
286
|
+
reference.citation[citationType] = ''; // loading
|
|
287
|
+
reference.citation['error'] = null; // clear errors
|
|
288
|
+
|
|
289
|
+
if (type === 'doi' || doi) {
|
|
290
|
+
const doiID = type === 'doi' ? id : doi;
|
|
291
|
+
this.getCitationTextByDOI(doiID).then((text) => {
|
|
292
|
+
const formattedText = this.replaceLinkInText(text);
|
|
293
|
+
reference.citation[citationType] = formattedText;
|
|
294
|
+
this.updateCopyContents();
|
|
295
|
+
}).catch((error) => {
|
|
296
|
+
reference.citation['error'] = {
|
|
297
|
+
type: citationType,
|
|
298
|
+
ref: 'doi',
|
|
299
|
+
};
|
|
300
|
+
});
|
|
301
|
+
} else if (type === 'pmid') {
|
|
302
|
+
this.getDOIFromPubMedID(id).then((data) => {
|
|
303
|
+
if (data?.result) {
|
|
304
|
+
const resultObj = data.result[id];
|
|
305
|
+
const articleIDs = resultObj?.articleids || [];
|
|
306
|
+
const doiObj = articleIDs.find((item) => item.idtype === 'doi');
|
|
307
|
+
const doiID = doiObj?.value;
|
|
308
|
+
|
|
309
|
+
if (doiID) {
|
|
310
|
+
reference['doi'] = doiID;
|
|
311
|
+
this.getCitationTextByDOI(doiID).then((text) => {
|
|
312
|
+
const formattedText = this.replaceLinkInText(text);
|
|
296
313
|
reference.citation[citationType] = formattedText;
|
|
297
314
|
this.updateCopyContents();
|
|
298
|
-
}
|
|
315
|
+
}).catch((error) => {
|
|
316
|
+
reference.citation['error'] = {
|
|
317
|
+
type: citationType,
|
|
318
|
+
ref: 'doi',
|
|
319
|
+
};
|
|
320
|
+
});
|
|
321
|
+
} else {
|
|
322
|
+
// If there has no doi in PubMed
|
|
323
|
+
const { title, pubdate, authors } = resultObj;
|
|
324
|
+
const authorNames = authors ? authors.map((author) => author.name) : [];
|
|
325
|
+
const formattedText = this.formatCopyReference({
|
|
326
|
+
title: title || '',
|
|
327
|
+
date: pubdate || '',
|
|
328
|
+
authors: authorNames,
|
|
329
|
+
url: `https://pubmed.ncbi.nlm.nih.gov/${id}`,
|
|
330
|
+
});
|
|
331
|
+
reference.citation[citationType] = formattedText;
|
|
332
|
+
this.updateCopyContents();
|
|
299
333
|
}
|
|
300
|
-
}
|
|
334
|
+
}
|
|
335
|
+
}).catch((error) => {
|
|
336
|
+
reference.citation['error'] = {
|
|
337
|
+
type: citationType,
|
|
338
|
+
ref: 'pubmed',
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
getCitationText: function(citationType) {
|
|
345
|
+
async function generateCitationTextSequentially(that) {
|
|
346
|
+
for (let i = 0; i < that.pubMedReferences.length; i++) {
|
|
347
|
+
that.generateCitationText(that.pubMedReferences[i], citationType);
|
|
348
|
+
|
|
349
|
+
// add delay only for more than 3 items in the list
|
|
350
|
+
if (
|
|
351
|
+
that.pubMedReferences.length > 3 &&
|
|
352
|
+
i < that.pubMedReferences.length - 1
|
|
353
|
+
) {
|
|
354
|
+
await delay(LOADING_DELAY);
|
|
301
355
|
}
|
|
302
356
|
}
|
|
303
|
-
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
generateCitationTextSequentially(this);
|
|
360
|
+
},
|
|
361
|
+
reloadCitation: function (reference) {
|
|
362
|
+
this.generateCitationText(reference, this.citationType);
|
|
304
363
|
},
|
|
305
364
|
updateCopyContents: function () {
|
|
306
365
|
const citationTypeObj = this.citationOptions.find((item) => item.value === this.citationType);
|
|
@@ -360,7 +419,7 @@ export default {
|
|
|
360
419
|
return await this.fetchData(esearchAPI);
|
|
361
420
|
},
|
|
362
421
|
getCitationTextByDOI: async function (id) {
|
|
363
|
-
const citationAPI = `${
|
|
422
|
+
const citationAPI = `${this.crosscite_host}/format?doi=${id}&style=${this.citationType}&lang=en-US`;
|
|
364
423
|
return await this.fetchData(citationAPI, 'text');
|
|
365
424
|
},
|
|
366
425
|
getDOIFromPubMedID: async function (pubmedId) {
|
|
@@ -438,7 +497,7 @@ export default {
|
|
|
438
497
|
return await response.json();
|
|
439
498
|
}
|
|
440
499
|
} catch (error) {
|
|
441
|
-
|
|
500
|
+
throw new Error(error);
|
|
442
501
|
}
|
|
443
502
|
},
|
|
444
503
|
},
|
|
@@ -569,6 +628,12 @@ export default {
|
|
|
569
628
|
}
|
|
570
629
|
}
|
|
571
630
|
|
|
631
|
+
.reload-button {
|
|
632
|
+
color: $app-primary-color;
|
|
633
|
+
text-decoration: underline;
|
|
634
|
+
cursor: pointer;
|
|
635
|
+
}
|
|
636
|
+
|
|
572
637
|
@keyframes loadingAnimation {
|
|
573
638
|
0% {
|
|
574
639
|
background-position: -30vw 0;
|