Skip to content

Commit

Permalink
inventory panel: remove CollectionObjects api results; relabel 'In th…
Browse files Browse the repository at this point in the history
…e Collection'
  • Loading branch information
wbbaker committed Aug 20, 2024
1 parent 673a511 commit 8c90e72
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
taxonomy &&
!taxonomy.nomenclatural_synonyms.length &&
!taxonomy.descendants.length
">
No descendants.
" >
No descendants of <span v-html="taxonomy.name"/>.
</p>
</AnimationOpacity>
</ul>
Expand Down
73 changes: 13 additions & 60 deletions src/modules/otus/components/Panel/PanelInventory/PanelInventory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,22 @@
<VCard>
<ClientOnly>
<VSpinner
v-if="isLoading.collectionObjects || isLoading.inventory"
v-if="isLoading"
logo-class="w-8 h-8"
legend=""
/>
</ClientOnly>
<VCardHeader class="flex justify-between">
<h2 class="text-md">
Inventory
<span v-if="Array.isArray(inventory)"> [{{inventory.length}}]</span>
In the Collection
<span v-if="Array.isArray(inventoryDWC)"> [{{ inventoryDWC.length }}]</span>
</h2>
<PanelDropdown panel-key="panel:inventory" />
</VCardHeader>
<VCardContent class="text-sm">
<details class="pb-4">
<summary class="cursor-pointer">
Collection Objects
<span v-if="Array.isArray(collectionObjects)"> [{{collectionObjects.length}}]</span>
</summary>
<p v-if="typeof collectionObjects === 'string'" v-html="collectionObjects"/>
<ul v-else class="tree ml-2">
<li v-for="collectionObject in collectionObjects" :key="collectionObject?.id">
<details>
<summary class="cursor-pointer">
{{ collectionObject.id }} — length {{JSON.stringify(collectionObject).length}}
</summary>
<ul class="m-2 ml-6 list-disc">
<li v-for="entry in Object.entries(collectionObject)" :key="entry[0]">
<em>{{ entry[0] }}:</em> {{ entry[1] }}
</li>
</ul>
<p v-html="JSON.stringify(collectionObject, null, 1)"/>
</details>
</li>
</ul>
</details>
<h3>Inventory</h3>
<p v-if="typeof inventory === 'string'" v-html="inventory"/>
<p v-if="typeof inventoryDWC === 'string'" v-html="inventoryDWC"/>
<ul v-else class="tree ml-2">
<li v-for="inventoryItem in inventory" :key="inventoryItem.id" class="mt-1">
<li v-for="inventoryItem in inventoryDWC" :key="inventoryItem.id" class="mt-1">
<details>
<summary class="cursor-pointer">
{{ makeInventoryLabel(inventoryItem) }}
Expand Down Expand Up @@ -79,9 +56,8 @@ const props = defineProps({
}
})
const collectionObjects = ref("Loading...")
const inventory = ref("Loading...")
const isLoading = ref({collectionObjects: false, inventory: false})
const inventoryDWC = ref("Loading...")
const isLoading = ref(false)
/** Based on taxonpages-orthoptera PanelSpecimentRecords. */
function makeInventoryLabel(item) {
Expand Down Expand Up @@ -133,41 +109,18 @@ watch(
() => props.otuId,
async () => {
if (!props.otuId) {
collectionObjects.value = 'No OTU specified.'
inventory.value = 'No OTU specified.'
inventoryDWC.value = 'No OTU specified.'
return
}
isLoading.value = {...isLoading.value, collectionObjects: true}
isLoading.value = true
useOtuPageRequest('panel:inventory', () =>
TaxonWorks.getCollectionObjects(props.otuId)
TaxonWorks.getOtuInventoryDarwinCore(props.otuId)
).then(({data}) => {
collectionObjects.value = data
console.log('CollectionObjects', data)
inventoryDWC.value = data
}).catch(
e => collectionObjects.value = `Error: ${e}`
).finally(() => isLoading.value = {...isLoading.value, collectionObjects: false})
},
{immediate: true}
)
watch(
() => props.otuId,
async () => {
if (!props.otuId) {
inventory.value = 'No OTU specified.'
return
}
isLoading.value = {...isLoading.value, inventory: true}
useOtuPageRequest('panel:inventory', () =>
TaxonWorks.getInventoryDarwinCore(props.otuId)
).then(({data}) => {
inventory.value = data
console.log('Inventory (Darwin Core)', data)
}).catch(
e => inventory.value = `Error: ${e}`
).finally(() => isLoading.value = {...isLoading.value, inventory: false})
e => inventoryDWC.value = `Error: ${e}`
).finally(() => isLoading.value = false)
},
{immediate: true}
)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/otus/services/TaxonWorks.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class TaxonWorks {
// return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}/dwc.json`, opt)
}

static getInventoryDarwinCore(otuId, opt) {
static getOtuInventoryDarwinCore(otuId, opt) {
return makeAPIRequest.get(`/otus/${otuId}/inventory/dwc.json`, opt)
}

Expand Down

0 comments on commit 8c90e72

Please sign in to comment.