<div id="package_search" class="residentsearch">
<form action="/cgi-bin/koha/erm/eholdings/local/packages" method="get">
- <label class="tip" for="package_filter">Package search:</label>
- <input class="head-searchbox" type="text" name="q" id="package_filter" size="40" />
+ <label class="tip" for="package_name_filter">Package search:</label>
+ <input class="head-searchbox" type="text" name="package_name" id="package_name_filter" size="40" />
<input type="submit" value="OK" class="submit" />
</form>
</div>
<div id="title_search" class="residentsearch">
<form action="/cgi-bin/koha/erm/eholdings/local/titles" method="get">
<label class="tip" for="title_filter">Title search:</label>
- <input class="head-searchbox" type="text" name="q" id="title_filter" size="40" />
+ <input class="head-searchbox" type="text" name="publication_title" id="title_filter" size="40" />
<input type="submit" value="OK" class="submit" />
</form>
</div>
:value="$t('Submit')"
/>
</fieldset>
- <div id="package_list_result" style="display: none">
- <table id="package_list"></table>
+
+ <!-- We need to display the table element to initiate DataTable -->
+ <div
+ id="package_list_result"
+ :style="show_table ? 'display: block' : 'display: none'"
+ >
+ <div
+ v-if="
+ local_count_packages !== undefined &&
+ local_count_packages !== null
+ "
+ >
+ <router-link
+ :to="local_packages_url"
+ >
+ {{
+ $t("{count} packages found locally", {
+ count: local_count_packages,
+ })
+ }}</router-link
+ >
+ </div>
+ <div id="package_list_result">
+ <table id="package_list"></table>
+ </div>
</div>
</div>
</template>
import { useVendorStore } from "../../stores/vendors"
import { useAVStore } from "../../stores/authorised_values"
import { storeToRefs } from "pinia"
+import { fetchCountLocalPackages } from './../../fetch'
export default {
setup() {
av_package_types,
av_package_content_types,
get_lib_from_av,
+ erm_providers,
}
},
data: function () {
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()
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']
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: [
{
$t("Please enter a search term")
}}</span>
</fieldset>
- <div id="title_list_result" style="display: none">
- <table id="title_list"></table>
+
+ <!-- We need to display the table element to initiate DataTable -->
+ <div
+ id="title_list_result"
+ :style="show_table ? 'display: block' : 'display: none'"
+ >
+ <div
+ v-if="
+ local_count_titles !== undefined &&
+ local_count_titles !== null
+ "
+ >
+ <router-link :to="local_titles_url">
+ {{
+ $t("{count} titles found locally", {
+ count: local_count_titles,
+ })
+ }}</router-link
+ >
+ </div>
+ <div id="title_list_result">
+ <table id="title_list"></table>
+ </div>
</div>
</div>
</template>
import { useVendorStore } from "../../stores/vendors"
import { useAVStore } from "../../stores/authorised_values"
import { storeToRefs } from "pinia"
+import { fetchCountLocalTitles } from "./../../fetch"
export default {
setup() {
vendors,
av_title_publication_types,
get_lib_from_av,
+ erm_providers,
}
},
data: function () {
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()
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
}
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']
return filters.publication_title || ""
},
publication_type: function () {
- return filters.content_type_search || ""
+ return filters.publication_type || ""
},
selection_type: function () {
return filters.selection_type || ""
packages: [],
initialized: false,
filters: {
- package_name: this.$route.query.q || "",
+ package_name: this.$route.query.package_name || "",
+ content_type: this.$route.query.content_type || "",
},
}
},
},
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"),
$("#" + 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 },
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,
}
},
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"),
<div v-else>
{{
$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"
)
}}
</div>
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;
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;