Skip to content

Commit

Permalink
list tags for each specimen
Browse files Browse the repository at this point in the history
  • Loading branch information
wbbaker committed Mar 13, 2025
1 parent 7e95d2b commit 6a8e831
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
:otu-id="otuId"
:images="getSpecimenImages(specimen)"
:notes="getNotes(specimen)"
:tags="getTags(specimen)"
/>
</li>
</ul>
Expand All @@ -95,7 +96,8 @@ const props = defineProps({
const inventoryDWC = ref("Loading...")
const inventoryGallery = ref(undefined)
const inventoryNotes = ref(undefined)
const isLoading = ref({dwc: false, gallery: false, notes: false})
const inventoryTags = ref(undefined)
const isLoading = ref({dwc: false, gallery: false, notes: false, tags: false})
const page = ref(1)
const perPage = ref(20)
const total = ref("???")
Expand All @@ -117,6 +119,13 @@ const getNotes = (specimen) => {
)
}
const getTags = (specimen) => {
return !inventoryTags.value ? [] : inventoryTags.value.filter(
// just the notes for this specimen
n => n.tag_object_id === specimen.dwc_occurrence_object_id
)
}
watch(
() => [props.otuId , page.value],
async () => {
Expand All @@ -136,15 +145,11 @@ watch(
inventoryDWC.value = data
total.value = Number(headers['pagination-total'])
// Nested API request: Get notes for all specimens
// Nested API requests: Get notes & tags for all specimens
const collectionObjectIds = data.map(s => s.dwc_occurrence_object_id)
useOtuPageRequest('panel:notes', () =>
TaxonWorks.getCollectionObjectsNotes(collectionObjectIds)
).then(({data}) => {
inventoryNotes.value = data
}).catch(
e => console.error(`Error loading notes: ${e}`)
).finally(() => isLoading.value = {...isLoading.value, notes: false})
isLoading.value = {...isLoading.value, notes: true, tags: true}
makeLoader('panel:notes', 'notes', TaxonWorks.getCollectionObjectsNotes, inventoryNotes)(collectionObjectIds)
makeLoader('panel:tags', 'tags', TaxonWorks.getCollectionObjectsTags, inventoryTags)(collectionObjectIds)
}).catch(
e => inventoryDWC.value = `Error loading Darwin Core: ${e}`
Expand All @@ -162,4 +167,22 @@ watch(
},
{immediate: true}
)
// Helper function to create a loader function for notes and tags
const makeLoader = (cacheKey, loadingKey, urlGenerator, localRef) => {
return async (collectionObjectIds) => {
try {
isLoading.value = {...isLoading.value, [loadingKey]: true}
const {data} = await useOtuPageRequest(cacheKey, () => urlGenerator(collectionObjectIds))
localRef.value = data
}
catch (e) {
console.error(`Error loading ${loadingKey}: ${e}`)
}
finally {
isLoading.value = {...isLoading.value, [loadingKey]: false}
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ For further reference see https://dwc.tdwg.org/terms/.
<li v-for="note in notes" :key="note.id" class="my-1 last:mb-0">
Note: {{ note.text }}
</li>
<li v-for="tag in tags" :key="tag.id" class="my-1 last:mb-0">
Tag: {{ tag.keyword?.name ?? "no name provided" }}
</li>
</ul>
</template>

Expand All @@ -39,6 +42,10 @@ const props = defineProps({
type: Array,
default: [],
},
tags: {
type: Array,
default: [],
},
})

function genusSpecies(specimen) {
Expand Down
12 changes: 12 additions & 0 deletions src/modules/otus/services/TaxonWorks.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ export default class TaxonWorks {
return makeAPIRequest.get(`/notes/`, processedOpt)
}

static getCollectionObjectsTags(collectionObjectIds, opt) {
const processedOpt = {
...opt,
params: {
...opt?.params,
note_object_type: "CollectionObject",
"tag_object_id[]": collectionObjectIds,
}
}
return makeAPIRequest.get(`/tags/`, processedOpt)
}

/** Load image info (thumbnail, etc) from a URL such as one in a Darwin Core 'associatedMedia' field. */
static getImageFromUrl(url, opt) {
// sanity check that this is the kind of URL we're looking for
Expand Down

0 comments on commit 6a8e831

Please sign in to comment.