Bug 32468: Use fetchLocalTitleCount to know if local titles exist

We don't need to fetch 20 titles to know if there is at least one. We
should call fetchLocalTitleCount.

Note that this should be implemented for all 'List' views.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 6b19436f5f)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2022-12-15 08:17:16 +01:00 committed by Martin Renvoize
parent 0a309595ab
commit bc85ab60b0
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
3 changed files with 32 additions and 33 deletions

View File

@ -46,15 +46,13 @@
>
<div
v-if="
local_count_titles !== undefined &&
local_count_titles !== null
local_title_count !== undefined &&
local_title_count !== null
"
>
<router-link :to="local_titles_url">
{{
$__("%s titles found locally").format(
local_count_titles
)
$__("%s titles found locally").format(local_title_count)
}}</router-link
>
</div>
@ -68,7 +66,7 @@
<script>
import { inject, createVNode, render } from "vue"
import { storeToRefs } from "pinia"
import { fetchCountLocalTitles } from "./../../fetch"
import { fetchLocalTitleCount } from "./../../fetch"
import {
useDataTable,
build_url_params,
@ -106,7 +104,7 @@ export default {
},
cannot_search: false,
show_table: false,
local_count_titles: null,
local_title_count: null,
}
},
computed: {
@ -137,12 +135,12 @@ export default {
)
this.$router.push(new_route)
this.show_table = true
this.local_count_titles = null
this.local_title_count = null
$("#" + this.table_id)
.DataTable()
.draw()
if (this.erm_providers.includes("local")) {
this.local_count_titles = await fetchCountLocalTitles(
this.local_title_count = await fetchLocalTitleCount(
this.filters
)
}

View File

@ -1,14 +1,10 @@
<template>
<div>
<div v-if="!initialized">{{ $__("Loading") }}</div>
<div v-else-if="titles" id="titles_list">
<div v-else-if="title_count" id="titles_list">
<Toolbar />
<div
v-if="titles.length"
id="title_list_result"
class="page-section"
>
<table v-if="titles.length" :id="table_id"></table>
<div v-if="title_count" id="title_list_result" class="page-section">
<table v-if="title_count" :id="table_id"></table>
</div>
<div v-else-if="initialized" class="dialog message">
{{ $__("There are no titles defined") }}
@ -21,7 +17,7 @@
import Toolbar from "./EHoldingsLocalTitlesToolbar.vue"
import { inject, createVNode, render } from "vue"
import { storeToRefs } from "pinia"
import { fetchLocalTitles } from "../../fetch"
import { fetchLocalTitleCount } from "../../fetch"
import { useDataTable } from "../../composables/datatables"
export default {
@ -42,7 +38,7 @@ export default {
},
data: function () {
return {
titles: [],
title_count: undefined,
initialized: false,
filters: {
publication_title: this.$route.query.publication_title || "",
@ -53,13 +49,12 @@ export default {
},
beforeRouteEnter(to, from, next) {
next(vm => {
vm.getTitles().then(() => vm.build_datatable())
vm.getTitleCount().then(() => vm.build_datatable())
})
},
methods: {
async getTitles() {
const titles = await fetchLocalTitles()
this.titles = titles
async getTitleCount() {
this.title_count = await fetchLocalTitleCount()
this.initialized = true
},
show_title: function (title_id) {

View File

@ -290,19 +290,25 @@ export const fetchEBSCOTitles = function () {
return _fetchTitles(apiUrl);
};
export const fetchCountLocalTitles = async function (filters) {
const q = {
"me.publication_title": {
like: "%" + filters.publication_title + "%",
},
...(filters.publication_type
? { "me.publication_type": filters.publication_type }
: {}),
};
export const fetchLocalTitleCount = async function (filters) {
const q = filters
? {
...(filters.publication_title
? {
"me.publication_title": {
like: "%" + filters.publication_title + "%",
},
}
: {}),
...(filters.publication_type
? { "me.publication_type": filters.publication_type }
: {}),
}
: undefined;
const params = {
_page: 1,
_per_page: 1,
q: JSON.stringify(q),
...(q ? { q: JSON.stringify(q) } : {}),
};
let count_local_titles;
var apiUrl = "/api/v1/erm/eholdings/local/titles";
@ -367,7 +373,7 @@ export const fetchEBSCOResources = function () {
return _fetchResources(apiUrl);
};
export const checkError = function(response) {
export const checkError = function (response) {
if (response.status >= 200 && response.status <= 299) {
return response.json();
} else {