From c9fcfcd598c2439bb6b96732d83fed0259856269 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 Jul 2022 14:52:11 +0200 Subject: [PATCH] Bug 32030: Display the number of local packages and titles matching the search Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../prog/en/includes/erm-search.inc | 6 +- .../ERM/EHoldingsEBSCOPackagesList.vue | 66 ++++++++++++++++--- .../ERM/EHoldingsEBSCOTitlesList.vue | 64 +++++++++++++++--- .../ERM/EHoldingsLocalPackagesList.vue | 17 ++++- .../ERM/EHoldingsLocalTitlesList.vue | 10 ++- .../prog/js/vue/components/ERM/ERMMain.vue | 2 +- koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js | 49 ++++++++++++++ 7 files changed, 190 insertions(+), 24 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/erm-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/erm-search.inc index 31fe999a99..761e067559 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/erm-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/erm-search.inc @@ -12,8 +12,8 @@ @@ -21,7 +21,7 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue index 899cd226a5..25e2a957d3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue @@ -32,8 +32,31 @@ :value="$t('Submit')" /> - @@ -43,6 +66,7 @@ import { createVNode, render } from 'vue' import { useVendorStore } from "../../stores/vendors" import { useAVStore } from "../../stores/authorised_values" import { storeToRefs } from "pinia" +import { fetchCountLocalPackages } from './../../fetch' export default { setup() { @@ -58,6 +82,7 @@ export default { av_package_types, av_package_content_types, get_lib_from_av, + erm_providers, } }, data: function () { @@ -65,12 +90,17 @@ export default { packages: [], initialized: true, filters: { - package_name: this.$route.query.q || "", - content_type: "", - selection_type: "", + package_name: this.$route.query.package_name || "", + content_type: this.$route.query.content_type || "", + selection_type: this.$route.query.selection_type || "", }, + show_table: false, + local_count_packages: null, } }, + computed: { + local_packages_url() { return this.build_url("/cgi-bin/koha/erm/eholdings/local/packages") }, + }, beforeRouteEnter(to, from, next) { next(vm => { vm.build_datatable() @@ -80,14 +110,34 @@ export default { show_package: function (package_id) { this.$router.push("/cgi-bin/koha/erm/eholdings/ebsco/packages/" + package_id) }, - filter_table: function () { - $("#package_list_result").show() + build_url_params: function () { + return Object.entries(this.filters) + .map(([k, v]) => v ? k + "=" + v : undefined) + .filter(e => e !== undefined) + .join('&') + }, + build_url: function (base_url) { + let params = this.build_url_params() + return base_url + (params.length ? '?' + params : '') + }, + filter_table: async function () { + let new_route = this.build_url("/cgi-bin/koha/erm/eholdings/ebsco/packages") + this.$router.push(new_route) + this.show_table = true + this.local_count_packages = null $("#package_list").DataTable().draw() + if (this.erm_providers.includes('local')) { + this.local_count_packages = await fetchCountLocalPackages(this.filters) + } }, build_datatable: function () { let show_package = this.show_package let get_lib_from_av = this.get_lib_from_av + if (!this.show_table) { + this.show_table = this.build_url_params().length ? true : false + } let filters = this.filters + let show_table = this.show_table window['vendors'] = this.vendors.map(e => { e['_id'] = e['id'] @@ -125,7 +175,7 @@ export default { ordering: false, dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>', aLengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]], - deferLoading: true, + deferLoading: show_table ? false : true, autoWidth: false, columns: [ { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue index 6eab9908ec..cae6d63599 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue @@ -38,8 +38,29 @@ $t("Please enter a search term") }} - @@ -49,6 +70,7 @@ import { createVNode, render } from 'vue' import { useVendorStore } from "../../stores/vendors" import { useAVStore } from "../../stores/authorised_values" import { storeToRefs } from "pinia" +import { fetchCountLocalTitles } from "./../../fetch" export default { setup() { @@ -63,6 +85,7 @@ export default { vendors, av_title_publication_types, get_lib_from_av, + erm_providers, } }, data: function () { @@ -70,13 +93,18 @@ export default { titles: [], initialized: true, filters: { - publication_title: this.$route.query.q || "", - publication_type: "", - selection_type: "", + publication_title: this.$route.query.publication_title || "", + publication_type: this.$route.query.publication_type || "", + selection_type: this.$route.query.selection_type || "", }, cannot_search: false, + show_table: false, + local_count_titles: null, } }, + computed: { + local_titles_url() { return this.build_url("/cgi-bin/koha/erm/eholdings/local/titles") }, + }, beforeRouteEnter(to, from, next) { next(vm => { vm.build_datatable() @@ -86,11 +114,27 @@ export default { show_title: function (title_id) { this.$router.push("/cgi-bin/koha/erm/eholdings/ebsco/titles/" + title_id) }, - filter_table: function () { + build_url_params: function () { + return Object.entries(this.filters) + .map(([k, v]) => v ? k + "=" + v : undefined) + .filter(e => e !== undefined) + .join('&') + }, + build_url: function (base_url) { + let params = this.build_url_params() + return base_url + (params.length ? '?' + params : '') + }, + filter_table: async function () { if (this.filters.publication_title.length) { this.cannot_search = false - $("#title_list_result").show() + let new_route = this.build_url("/cgi-bin/koha/erm/eholdings/ebsco/titles") + this.$router.push(new_route) + this.show_table = true + this.local_count_titles = null $("#title_list").DataTable().draw() + if (this.erm_providers.includes('local')) { + this.local_count_titles = await fetchCountLocalTitles(this.filters) + } } else { this.cannot_search = true } @@ -98,7 +142,11 @@ export default { build_datatable: function () { let show_title = this.show_title let get_lib_from_av = this.get_lib_from_av + if (!this.show_table) { + this.show_table = this.build_url_params().length ? true : false + } let filters = this.filters + let show_table = this.show_table window['vendors'] = this.vendors.map(e => { e['_id'] = e['id'] @@ -120,7 +168,7 @@ export default { return filters.publication_title || "" }, publication_type: function () { - return filters.content_type_search || "" + return filters.publication_type || "" }, selection_type: function () { return filters.selection_type || "" diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue index 49b2fe9425..94a9c9f742 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue @@ -42,7 +42,8 @@ export default { packages: [], initialized: false, filters: { - package_name: this.$route.query.q || "", + package_name: this.$route.query.package_name || "", + content_type: this.$route.query.content_type || "", }, } }, @@ -95,8 +96,15 @@ export default { }, embed: ['resources+count', 'vendor.name'], order: [[0, "asc"]], - search: { search: filters.package_name }, autoWidth: false, + searchCols: [ + { search: filters.package_name }, + null, + null, + { search: filters.content_type }, + null, + null, + ], columns: [ { title: __("Name"), @@ -200,6 +208,11 @@ export default { $("#" + table_id).find("thead th").eq(3).attr('data-filter', 'av_package_content_types') } }, eholdings_packages_table_settings, 1) + + if (filters.package_name) { + //$("#package_list").DataTable().column(0).search(filters.package_name).draw() + } + //myTable.column(0).search(control_id).column(1).search(sample_id).draw(); }, }, components: { Toolbar }, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue index ffe6c0dd5c..e2c68416e8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue @@ -41,7 +41,8 @@ export default { titles: [], initialized: false, filters: { - publication_title: this.$route.query.q || "", + publication_title: this.$route.query.publication_title || "", + publication_type: this.$route.query.publication_type || "", }, cannot_search: false, } @@ -94,8 +95,13 @@ export default { }, embed: ["resources.package"], order: [[0, "asc"]], - search: { search: filters.publication_title }, autoWidth: false, + searchCols: [ + { search: filters.publication_title }, + null, + { search: filters.publication_type }, + null, + ], columns: [ { title: __("Title"), diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/ERMMain.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/ERMMain.vue index 7a58caef47..f00550753f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/ERMMain.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/ERMMain.vue @@ -109,7 +109,7 @@
{{ $t( - "The E-Resource management module is disabled. Turn on 'ERMModule' to use it." + "The E-Resource management module is disabled, turn on 'ERMModule' to use it" ) }}
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js index 6818526fd2..f578f6f2ae 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js @@ -207,6 +207,30 @@ export const fetchEBSCOPackages = function () { return _fetchPackages(apiUrl); }; +export const fetchCountLocalPackages = async function (filters) { + const q = { + "me.name": { like: "%" + filters.package_name + "%" }, + ...(filters.content_type + ? { "me.content_type": filters.content_type } + : {}), + }; + + const params = { + _page: 1, + _per_page: 1, + q: JSON.stringify(q), + }; + let count_local_packages; + var apiUrl = "/api/v1/erm/eholdings/local/packages"; + await fetch(apiUrl + "?" + new URLSearchParams(params)) + //.then(checkError) + .then( + (response) => + (count_local_packages = response.headers.get("X-Total-Count")) + ); + return count_local_packages; +}; + export const _fetchTitle = async function (apiUrl, title_id) { if (!title_id) return; let title; @@ -258,6 +282,31 @@ 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 } + : {}), + }; + const params = { + _page: 1, + _per_page: 1, + q: JSON.stringify(q), + }; + let count_local_titles; + var apiUrl = "/api/v1/erm/eholdings/local/titles"; + await fetch(apiUrl + "?" + new URLSearchParams(params)) + //.then(checkError) + .then( + (response) => + (count_local_titles = response.headers.get("X-Total-Count")) + ); + return count_local_titles; +}; + export const _fetchResource = async function (apiUrl, resource_id) { if (!resource_id) return; let resource; -- 2.39.5