From 2d3892f02bc2ea5e11ca286ca439c148e19f955e Mon Sep 17 00:00:00 2001 From: W Beecher Baker Date: Tue, 8 Oct 2024 14:27:27 -0400 Subject: [PATCH] get total count from API headers --- .../Panel/PanelSpecimens/PanelSpecimens.vue | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/modules/otus/components/Panel/PanelSpecimens/PanelSpecimens.vue b/src/modules/otus/components/Panel/PanelSpecimens/PanelSpecimens.vue index b0a870a..fc57250 100644 --- a/src/modules/otus/components/Panel/PanelSpecimens/PanelSpecimens.vue +++ b/src/modules/otus/components/Panel/PanelSpecimens/PanelSpecimens.vue @@ -11,21 +11,22 @@

{{ (void (isSinglePage = typeof total === 'number' && total < perPage && page === 1)) }} {{ (void (isLoaded = Array.isArray(inventoryDWC))) }} + {{ (void (dwcCount = isLoaded ? inventoryDWC.length : 0)) }} In the Collection

{{ void(showFirst = page > 1) }} {{ void(showPrev = page > 1) }} - {{ void(showNext = inventoryDWC.length === perPage) }} - {{ void(showLast = showNext && typeof total === 'number' && total > (page - 1) * perPage + inventoryDWC.length) }} + {{ void(showNext = dwcCount === perPage) }} + {{ void(showLast = showNext && typeof total === 'number' && total > (page - 1) * perPage + dwcCount) }} { @@ -124,12 +124,10 @@ watch( props.otuId, {per: perPage.value, page: page.value}, ) - ).then(({data}) => { + ).then(({data, headers}) => { + console.log({panel: "specimens", headers, data}) inventoryDWC.value = data - // if we've reached the end, so we know the total - if (Array.isArray(data) && data.length < perPage.value) { - total.value = (page.value - 1) * perPage.value + data.length - } + total.value = Number(headers['pagination-total']) }).catch( e => inventoryDWC.value = `Error loading Darwin Core: ${e}` ).finally(() => isLoading.value = {...isLoading.value, dwc: false}) @@ -137,7 +135,8 @@ watch( isLoading.value = {...isLoading.value, gallery: true} useOtuPageRequest('panel:gallery', () => TaxonWorks.getDescendantsImageGallery(props.otuId) - ).then(({data}) => { + ).then(({data, headers}) => { + console.log({panel: "gallery", headers, data}) inventoryGallery.value = data }).catch( e => console.error(`Error loading gallery: ${e}`)