From c69e0cf9727a4c5fac4be7be0a074d864680cd16 Mon Sep 17 00:00:00 2001 From: jlpereira Date: Mon, 8 May 2023 18:20:47 -0300 Subject: [PATCH 01/13] Fix Skeleton component --- src/components/VSkeleton.global.vue | 9 ++++----- src/modules/otus/views/Index.vue | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/VSkeleton.global.vue b/src/components/VSkeleton.global.vue index 3bf6622..4ebaa1f 100644 --- a/src/components/VSkeleton.global.vue +++ b/src/components/VSkeleton.global.vue @@ -1,7 +1,7 @@ diff --git a/src/modules/otus/components/Panel/PanelStats/PanelStats.vue b/src/modules/otus/components/Panel/PanelStats/PanelStats.vue new file mode 100644 index 0000000..6e2921e --- /dev/null +++ b/src/modules/otus/components/Panel/PanelStats/PanelStats.vue @@ -0,0 +1,53 @@ + + + diff --git a/src/modules/otus/constants/overviewLayout.js b/src/modules/otus/constants/overviewLayout.js index cf6e74b..49dc2fd 100644 --- a/src/modules/otus/constants/overviewLayout.js +++ b/src/modules/otus/constants/overviewLayout.js @@ -6,6 +6,7 @@ import PanelNomenclature from '../components/Panel/PanelNomenclature/PanelNomenc import PanelMap from '../components/Panel/PanelMap/PanelMap.vue' import PanelDescendants from '../components/Panel/PanelDescendants/Descendants.vue' import PanelContent from '../components/Panel/PanelContent/PanelContent.vue' +import PanelStats from '../components/Panel/PanelStats/PanelStats.vue' export const overviewLayout = { left: [ @@ -24,6 +25,7 @@ export const overviewLayout = { right: [ { component: PanelMap }, { component: PanelDescendants }, - { component: PanelContent } + { component: PanelContent }, + { component: PanelStats } ] } diff --git a/src/modules/otus/services/TaxonWorks.js b/src/modules/otus/services/TaxonWorks.js index 5a1aaca..f0cb21e 100644 --- a/src/modules/otus/services/TaxonWorks.js +++ b/src/modules/otus/services/TaxonWorks.js @@ -55,6 +55,10 @@ export default class TaxonWorks { return makeAPIRequest.get(`/otus/${otuId}/inventory/distribution.geojson`) } + static getCachedMap(cachedId) { + return makeAPIRequest.get(`/cached_maps/${cachedId}`) + } + static getOtuContent(otuId) { return makeAPIRequest.get(`/otus/${otuId}/inventory/content`, { extend: ['depiction'] diff --git a/src/modules/otus/store/actions/index.js b/src/modules/otus/store/actions/index.js index a6a10e4..29a98ab 100644 --- a/src/modules/otus/store/actions/index.js +++ b/src/modules/otus/store/actions/index.js @@ -1 +1,2 @@ +export * from './loadCatalog' export * from './loadDistribution' diff --git a/src/modules/otus/store/actions/loadCatalog.js b/src/modules/otus/store/actions/loadCatalog.js new file mode 100644 index 0000000..db851b9 --- /dev/null +++ b/src/modules/otus/store/actions/loadCatalog.js @@ -0,0 +1,25 @@ +import TaxonWorks from '../../services/TaxonWorks' + +function parseStats(obj) { + return Object.entries(obj) + .filter(([_, count]) => count) + .map((item) => item.join(': ')) + .join('; ') +} + +export const actionLoadCatalog = { + async loadCatalog(taxonId) { + const { data } = await TaxonWorks.getTaxonNameCitations(taxonId) + + this.catalog = { + ...data, + stats: { + taxa: parseStats(data.stats.taxa), + names: parseStats(data.stats.names) + }, + sources: data.sources.map(({ cached, url }) => + cached.replace(url, `${url}`) + ) + } + } +} diff --git a/src/modules/otus/store/store.js b/src/modules/otus/store/store.js index 033ad33..b3fdb93 100644 --- a/src/modules/otus/store/store.js +++ b/src/modules/otus/store/store.js @@ -1,6 +1,6 @@ import { defineStore } from 'pinia' import TaxonWorks from '../services/TaxonWorks' -import { actionLoadDistribution } from './actions' +import { actionLoadDistribution, actionLoadCatalog } from './actions' export const useOtuStore = defineStore('otuStore', { state: () => { @@ -12,6 +12,11 @@ export const useOtuStore = defineStore('otuStore', { geojson: null, errorMessage: null, currentShapeTypes: [] + }, + catalog: { + sources: [], + stats: {}, + timeline: [] } } }, @@ -28,11 +33,9 @@ export const useOtuStore = defineStore('otuStore', { }, async loadInit(otuId) { - const otu = (await TaxonWorks.getOtu(otuId)).data - const taxon = (await TaxonWorks.summary(otu.taxon_name_id)).data - - this.otu = otu - this.taxon = taxon + await this.loadOtu(otuId) + await this.loadTaxon(this.otu.taxon_name_id) + await this.loadCatalog(this.otu.taxon_name_id) }, async loadImages(otuId) { @@ -44,6 +47,7 @@ export const useOtuStore = defineStore('otuStore', { this.images = (await TaxonWorks.getOtuImages(otuId, params)).data }, - ...actionLoadDistribution + ...actionLoadDistribution, + ...actionLoadCatalog } }) From 20bfa72ac0b91aca645ea7d2463c4f29a41f8660 Mon Sep 17 00:00:00 2001 From: jlpereira Date: Wed, 7 Jun 2023 12:04:27 -0300 Subject: [PATCH 13/13] Add DwC download --- src/components/Icon/IconDownload.global.vue | 15 +++++++++++ src/modules/otus/components/DWCDownload.vue | 30 +++++++++++++++++++++ src/modules/otus/services/TaxonWorks.js | 4 +++ src/modules/otus/utils/files.js | 29 ++++++++++++++++++++ src/modules/otus/utils/index.js | 1 + src/modules/otus/views/Index.vue | 9 ++++++- 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/components/Icon/IconDownload.global.vue create mode 100644 src/modules/otus/components/DWCDownload.vue create mode 100644 src/modules/otus/utils/files.js diff --git a/src/components/Icon/IconDownload.global.vue b/src/components/Icon/IconDownload.global.vue new file mode 100644 index 0000000..0099b27 --- /dev/null +++ b/src/components/Icon/IconDownload.global.vue @@ -0,0 +1,15 @@ + diff --git a/src/modules/otus/components/DWCDownload.vue b/src/modules/otus/components/DWCDownload.vue new file mode 100644 index 0000000..86864f8 --- /dev/null +++ b/src/modules/otus/components/DWCDownload.vue @@ -0,0 +1,30 @@ + + + diff --git a/src/modules/otus/services/TaxonWorks.js b/src/modules/otus/services/TaxonWorks.js index f0cb21e..601759b 100644 --- a/src/modules/otus/services/TaxonWorks.js +++ b/src/modules/otus/services/TaxonWorks.js @@ -64,4 +64,8 @@ export default class TaxonWorks { extend: ['depiction'] }) } + + static getDwC(otuId) { + return makeAPIRequest.get(`/otus/${otuId}/inventory/dwc`) + } } diff --git a/src/modules/otus/utils/files.js b/src/modules/otus/utils/files.js new file mode 100644 index 0000000..449b666 --- /dev/null +++ b/src/modules/otus/utils/files.js @@ -0,0 +1,29 @@ +function downloadTextFile(text, fileType, fileName) { + const blob = new Blob([text], { type: fileType }) + const a = document.createElement('a') + + a.download = fileName + a.href = URL.createObjectURL(blob) + a.dataset.downloadurl = [fileType, a.download, a.href].join(':') + a.style.display = 'none' + document.body.appendChild(a) + a.click() + document.body.removeChild(a) + setTimeout(() => { + URL.revokeObjectURL(a.href) + }, 1500) +} + +function blobToArrayBuffer(blob) { + return new Promise((resolve, reject) => { + const reader = new FileReader() + + reader.addEventListener('loadend', (_) => { + resolve(reader.result) + }) + reader.addEventListener('error', reject) + reader.readAsArrayBuffer(blob) + }) +} + +export { blobToArrayBuffer, downloadTextFile } diff --git a/src/modules/otus/utils/index.js b/src/modules/otus/utils/index.js index 1094c15..9fe8130 100644 --- a/src/modules/otus/utils/index.js +++ b/src/modules/otus/utils/index.js @@ -1,3 +1,4 @@ +export * from './files' export * from './isRankGroup' export * from './makeGeoJSONFeature' export * from './removeDuplicateShapes' diff --git a/src/modules/otus/views/Index.vue b/src/modules/otus/views/Index.vue index 8686f3e..34cb26f 100644 --- a/src/modules/otus/views/Index.vue +++ b/src/modules/otus/views/Index.vue @@ -24,7 +24,7 @@ /> -
+
+
+ +