@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/map-utilities",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "files": [
5
5
  "dist/*",
6
6
  "src/*",
@@ -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 && reference.citation[citationType]">
27
- <span v-html="reference.citation[citationType]"></span>
28
- <CopyToClipboard :content="reference.citation[citationType]" />
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.crosscite.org';
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
- getCitationText: function(citationType) {
255
- this.pubMedReferences.forEach((reference) => {
256
- const { id, type, doi } = reference;
257
-
258
- if (
259
- !(reference.citation && reference.citation[citationType])
260
- && id
261
- ) {
262
- reference.citation[citationType] = ''; // loading
263
-
264
- if (type === 'doi' || doi) {
265
- const doiID = type === 'doi' ? id : doi;
266
- this.getCitationTextByDOI(doiID).then((text) => {
267
- const formattedText = this.replaceLinkInText(text);
268
- reference.citation[citationType] = formattedText;
269
- this.updateCopyContents();
270
- });
271
- } else if (type === 'pmid') {
272
- this.getDOIFromPubMedID(id).then((data) => {
273
- if (data?.result) {
274
- const resultObj = data.result[id];
275
- const articleIDs = resultObj?.articleids || [];
276
- const doiObj = articleIDs.find((item) => item.idtype === 'doi');
277
- const doiID = doiObj?.value;
278
-
279
- if (doiID) {
280
- reference['doi'] = doiID;
281
- this.getCitationTextByDOI(doiID).then((text) => {
282
- const formattedText = this.replaceLinkInText(text);
283
- reference.citation[citationType] = formattedText;
284
- this.updateCopyContents();
285
- });
286
- } else {
287
- // If there has no doi in PubMed
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 = `${CROSSCITE_API_HOST}/format?doi=${id}&style=${this.citationType}&lang=en-US`;
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
- console.error(`Fetch data error: ${error}`);
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;
@@ -44,7 +44,12 @@ const xmlToJSON = (xmlText) => {
44
44
  return result;
45
45
  };
46
46
 
47
+ const delay = (ms) => {
48
+ return new Promise(resolve => setTimeout(resolve, ms));
49
+ };
50
+
47
51
  export {
48
52
  capitalise,
49
53
  xmlToJSON,
54
+ delay,
50
55
  };