Skip to content

Commit

Permalink
Merge pull request #81 from SpeciesFileGroup/development
Browse files Browse the repository at this point in the history
Add status panel
  • Loading branch information
José Luis Pereira authored and GitHub committed Jun 6, 2023
2 parents 4b1dba9 + c729963 commit 5c7b927
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<PanelNomenlcatureCitations :list="citations" />
<PanelNomenclatureReferences :list="sources" />
<PanelNomenlcatureCitations :list="store.catalog.timeline" />
<PanelNomenclatureReferences :list="store.catalog.sources" />
</template>

<script setup>
import { ref, watch } from 'vue'
import { useOtuStore } from '@/modules/otus/store/store'
import PanelNomenlcatureCitations from './PanelNomenclatureCitations.vue'
import PanelNomenclatureReferences from './PanelNomenclatureReferences.vue'
import TaxonWorks from '../../../services/TaxonWorks'
const props = defineProps({
otuId: {
Expand All @@ -31,20 +31,5 @@ const props = defineProps({
}
})
const citations = ref([])
const sources = ref([])
watch(
() => props.taxonId,
async () => {
if (!props.taxonId) {
return
}
const { data } = await TaxonWorks.getTaxonNameCitations(props.taxonId)
citations.value = data.timeline
sources.value = data.sources
},
{ immediate: true }
)
const store = useOtuStore()
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<li class="border-b border-base-muted p-3 px-5">
<span
class="break-all block"
:title="reference.cached"
v-html="reference.cached"
:title="reference"
v-html="reference"
/>
</li>
</template>
Expand Down
53 changes: 53 additions & 0 deletions src/modules/otus/components/Panel/PanelStats/PanelStats.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<VCard>
<VCardHeader class="flex justify-between">
<h2 class="text-md">Stats</h2>
</VCardHeader>
<VCardContent class="text-sm">
<div>
<p>
Taxa:
<span class="capitalize">
{{ store.catalog.stats.taxa }}
</span>
</p>
</div>
<div>
<p>
Names:
<span class="capitalize">
{{ store.catalog.stats.names }}
</span>
</p>
</div>
</VCardContent>
</VCard>
</template>

<script setup>
import { useOtuStore } from '@/modules/otus/store/store'
const props = defineProps({
otuId: {
type: [Number, String],
required: true
},
taxonId: {
type: [Number, String],
required: true
},
taxon: {
type: Object,
default: undefined
},
otu: {
type: Object,
default: undefined
}
})
const store = useOtuStore()
</script>
4 changes: 3 additions & 1 deletion src/modules/otus/constants/overviewLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -24,6 +25,7 @@ export const overviewLayout = {
right: [
{ component: PanelMap },
{ component: PanelDescendants },
{ component: PanelContent }
{ component: PanelContent },
{ component: PanelStats }
]
}
4 changes: 4 additions & 0 deletions src/modules/otus/services/TaxonWorks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
1 change: 1 addition & 0 deletions src/modules/otus/store/actions/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './loadCatalog'
export * from './loadDistribution'
25 changes: 25 additions & 0 deletions src/modules/otus/store/actions/loadCatalog.js
Original file line number Diff line number Diff line change
@@ -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, `<a href="${url}">${url}</a>`)
)
}
}
}
18 changes: 11 additions & 7 deletions src/modules/otus/store/store.js
Original file line number Diff line number Diff line change
@@ -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: () => {
Expand All @@ -12,6 +12,11 @@ export const useOtuStore = defineStore('otuStore', {
geojson: null,
errorMessage: null,
currentShapeTypes: []
},
catalog: {
sources: [],
stats: {},
timeline: []
}
}
},
Expand All @@ -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) {
Expand All @@ -44,6 +47,7 @@ export const useOtuStore = defineStore('otuStore', {
this.images = (await TaxonWorks.getOtuImages(otuId, params)).data
},

...actionLoadDistribution
...actionLoadDistribution,
...actionLoadCatalog
}
})

0 comments on commit 5c7b927

Please sign in to comment.