Skip to content

Commit

Permalink
flip order and hide COs by default
Browse files Browse the repository at this point in the history
  • Loading branch information
wbbaker committed Aug 6, 2024
1 parent 45b88a8 commit 673a511
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
67 changes: 41 additions & 26 deletions src/modules/otus/components/Panel/PanelInventory/PanelInventory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,35 @@
/>
</ClientOnly>
<VCardHeader class="flex justify-between">
<h2 class="text-md">Collection Objects</h2>
<h2 class="text-md">
Inventory
<span v-if="Array.isArray(inventory)"> [{{inventory.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"/>
<ul v-else class="tree ml-2">
Expand All @@ -21,12 +46,12 @@
{{ makeInventoryLabel(inventoryItem) }}
</summary>
<ul class="m-2 ml-6 list-disc">
<li v-for="detail in makeInventoryDetails(inventoryItem)" v-html="detail" :key="detail.id"/>
<li v-for="detail in makeInventoryDetails(inventoryItem)" v-html="detail" :key="detail?.id"/>
<li>
<details>
<summary class="cursor-pointer">Full Record</summary>
<summary class="cursor-pointer">Full Record ({{Object.keys(inventoryItem).length}} items)</summary>
<dl class="m-2 ml-6">
<template v-for="entry in Object.entries(inventoryItem)">
<template v-for="entry in Object.entries(inventoryItem)" :key="entry[0]">
<dt>{{ entry[0] }}</dt>
<dd class="ml-4 mb-2">{{ entry[1] }}</dd>
</template>
Expand All @@ -37,23 +62,6 @@
</details>
</li>
</ul>
<h3 class="pt-2">Collection Objects</h3>
<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>
{{ 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.id">
<em>{{ entry[0] }}:</em> {{ entry[1] }}
</li>
</ul>
<p v-html="JSON.stringify(collectionObject, null, 1)"/>
</details>
</li>
</ul>
</VCardContent>
</VCard>
</template>
Expand Down Expand Up @@ -89,11 +97,11 @@ function makeInventoryDetails(item) {
return [
makeInventoryCollectionDate(item),
item.recordedBy && `Recorded by ${item.recordedBy}`,
item.identifiedBy && `Identified by ${item.identifiedBy}, ${item.dateIdentified}`,
makeIdentifiedByDesccription(item),
item.georeferencedBy && `Georeferenced by ${item.georeferencedBy}${makeGeoreferenceUncertainty(item)}`,
// CollectionObject #1234
item.dwc_occurrence_object_id && `${item.dwc_occurrence_object_type} #${item.dwc_occurrence_object_id}`,
]
].filter(Boolean)
}
function makeLocationDescription(item) {
Expand All @@ -104,6 +112,13 @@ function makeLocationDescription(item) {
].filter(Boolean).join(", ")
}
function makeIdentifiedByDesccription(item) {
return [
item.identifiedBy && `Identified by ${item.identifiedBy}`,
item.dateIdentified,
].filter(Boolean).join(", ")
}
function makeInventoryCollectionDate(item) {
if (!item.year) return null
const date = new Date(item.year, item.month, item.day)
Expand All @@ -128,7 +143,7 @@ watch(
TaxonWorks.getCollectionObjects(props.otuId)
).then(({data}) => {
collectionObjects.value = data
console.log(data)
console.log('CollectionObjects', data)
}).catch(
e => collectionObjects.value = `Error: ${e}`
).finally(() => isLoading.value = {...isLoading.value, collectionObjects: false})
Expand All @@ -146,10 +161,10 @@ watch(
isLoading.value = {...isLoading.value, inventory: true}
useOtuPageRequest('panel:inventory', () =>
TaxonWorks.getInventory(props.otuId)
TaxonWorks.getInventoryDarwinCore(props.otuId)
).then(({data}) => {
inventory.value = data
console.log(data)
console.log('Inventory (Darwin Core)', data)
}).catch(
e => inventory.value = `Error: ${e}`
).finally(() => isLoading.value = {...isLoading.value, inventory: false})
Expand Down
7 changes: 4 additions & 3 deletions src/modules/otus/services/TaxonWorks.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ export default class TaxonWorks {
// Note that this could support multiple OTUs.
// The API takes a comma-separated list of OTU IDs.
static getCollectionObjects(otuId, opt) {
// See taxonworks/lib/collection_object/filter.rb Queries:CollectionObject:Filter for full list of options
return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}`, opt)
// See taxonworks/lib/collection_object/filter.rb Queries:CollectionObject:Filter for full list of options.
// However, none seems to change the result.
/*
@with_buffered_collecting_event = boolean_param(params, :with_buffered_collecting_event)
@with_buffered_determinations = boolean_param(params, :with_buffered_determinations)
@with_buffered_other_labels = boolean_param(params, :with_buffered_other_labels)
*/
// return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}&with_buffered_determination=true`, opt)
// return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}&descendants=true`, opt)
return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}`, opt)
// return makeAPIRequest.get(`/collection_objects?otu_id[]=${otuId}/dwc.json`, opt)
}

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

Expand Down

0 comments on commit 673a511

Please sign in to comment.