From ad466570c1a500b454a88f7f3b9a1a7b7f2e9972 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 Jul 2022 11:52:49 +0200 Subject: [PATCH] Bug 32030: Simplify JS map for DT filters Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../js/vue/components/ERM/AgreementsList.vue | 45 +++++-------------- .../ERM/EHoldingsEBSCOPackageTitlesList.vue | 12 +++-- .../ERM/EHoldingsEBSCOPackagesList.vue | 17 +++---- .../ERM/EHoldingsLocalPackageTitlesList.vue | 12 ++--- .../ERM/EHoldingsLocalPackagesList.vue | 21 +++------ .../ERM/EHoldingsLocalTitlesList.vue | 10 ++--- .../js/vue/components/ERM/LicensesList.vue | 35 +++++---------- .../prog/js/vue/stores/authorised_values.js | 7 +++ 8 files changed, 56 insertions(+), 103 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue index 73a3411749..97bb058aa8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue @@ -24,16 +24,15 @@ export default { const { vendors } = storeToRefs(vendorStore) const AVStore = useAVStore() - const { av_agreement_statuses, av_agreement_closure_reasons, av_agreement_renewal_priorities } = storeToRefs(AVStore) + const { get_lib_from_av, map_av_dt_filter } = AVStore const table_id = "agreement_list" useDataTable(table_id) return { vendors, - av_agreement_statuses, - av_agreement_closure_reasons, - av_agreement_renewal_priorities, + get_lib_from_av, + map_av_dt_filter, table_id, } }, @@ -78,6 +77,8 @@ export default { let edit_agreement = this.edit_agreement let delete_agreement = this.delete_agreement let select_agreement = this.select_agreement + let get_lib_from_av = this.get_lib_from_av + let map_av_dt_filter = this.map_av_dt_filter let default_search = this.$route.query.q let actions = this.before_route_entered ? 'edit_delete' : 'select' let table_id = this.table_id @@ -91,33 +92,11 @@ export default { map[e.id] = e return map }, {}) - window['av_agreement_statuses'] = this.av_agreement_statuses.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) - let av_agreement_statuses_map = this.av_agreement_statuses.reduce((map, e) => { - map[e.authorised_value] = e - return map - }, {}) - window['av_agreement_closure_reasons'] = this.av_agreement_closure_reasons.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) - let av_agreement_closure_reasons_map = this.av_agreement_closure_reasons.reduce((map, e) => { - map[e.authorised_value] = e - return map - }, {}) - window['av_agreement_renewal_priorities'] = this.av_agreement_renewal_priorities.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e + let avs = ['av_agreement_statuses', 'av_agreement_closure_reasons', 'av_agreement_renewal_priorities'] + avs.forEach(function (av_cat) { + window[av_cat] = map_av_dt_filter(av_cat) }) - let av_agreement_renewal_priorities_map = this.av_agreement_renewal_priorities.reduce((map, e) => { - map[e.authorised_value] = e - return map - }, {}) + window['av_agreement_is_perpetual'] = [{ _id: 0, _str: _('No') }, { _id: 1, _str: _("Yes") }] const table = $("#" + table_id).kohaTable({ @@ -168,7 +147,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return escape_str(av_agreement_statuses_map[row.status].lib) + return escape_str(get_lib_from_av("av_agreement_statuses", row.status)) } }, { @@ -177,7 +156,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return row.closure_reason != undefined && row.closure_reason != "" ? escape_str(av_agreement_closure_reasons_map[row.closure_reason].lib) : "" + return escape_str(get_lib_from_av("av_agreement_closure_reasons", row.closure_reason)) } }, { @@ -195,7 +174,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return row.renewal_priority != undefined && row.renewal_priority != "" ? escape_str(av_agreement_renewal_priorities_map[row.renewal_priority].lib) : "" + return escape_str(get_lib_from_av("av_agreement_renewal_priorities", row.renewal_priority)) } }, { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageTitlesList.vue index f66a95a72d..2337af1d11 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageTitlesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageTitlesList.vue @@ -68,7 +68,7 @@ export default { setup() { const AVStore = useAVStore() const { av_title_publication_types } = storeToRefs(AVStore) - const { get_lib_from_av } = AVStore + const { get_lib_from_av, map_av_dt_filter } = AVStore const table_id = "title_list" useDataTable(table_id) @@ -76,6 +76,7 @@ export default { return { av_title_publication_types, get_lib_from_av, + map_av_dt_filter, table_id, } }, @@ -103,14 +104,11 @@ export default { let show_resource = this.show_resource let package_id = this.package_id let get_lib_from_av = this.get_lib_from_av + let map_av_dt_filter = this.map_av_dt_filter let filters = this.filters let table_id = this.table_id - window['av_title_publication_types'] = this.av_title_publication_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) + window['av_title_publication_types'] = map_av_dt_filter('av_title_publication_types') let additional_filters = { publication_title: function () { @@ -201,4 +199,4 @@ export default { #filters { margin: 0; } - \ No newline at end of file + 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 2afc8824d9..60ef522b20 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 @@ -74,7 +74,7 @@ export default { const AVStore = useAVStore() const { av_package_types, av_package_content_types } = storeToRefs(AVStore) - const { get_lib_from_av } = AVStore + const { get_lib_from_av, map_av_dt_filter } = AVStore const table_id = "package_list" useDataTable(table_id) @@ -84,6 +84,7 @@ export default { av_package_types, av_package_content_types, get_lib_from_av, + map_av_dt_filter, erm_providers, table_id, } @@ -136,6 +137,8 @@ export default { build_datatable: function () { let show_package = this.show_package let get_lib_from_av = this.get_lib_from_av + let map_av_dt_filter = this.map_av_dt_filter + if (!this.show_table) { this.show_table = this.build_url_params().length ? true : false } @@ -148,15 +151,9 @@ export default { e['_str'] = e['name'] return e }) - window['av_package_types'] = this.av_package_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) - window['av_package_content_types'] = this.av_package_content_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e + let avs = ['av_package_types', 'av_package_content_types'] + avs.forEach(function (av_cat) { + window[av_cat] = map_av_dt_filter(av_cat) }) let additional_filters = { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackageTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackageTitlesList.vue index c440c0a449..f5d809aae8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackageTitlesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackageTitlesList.vue @@ -13,15 +13,14 @@ import { useDataTable } from "../../composables/datatables" export default { setup() { const AVStore = useAVStore() - const { av_title_publication_types } = storeToRefs(AVStore) - const { get_lib_from_av } = AVStore + const { get_lib_from_av, map_av_dt_filter } = AVStore const table_id = "title_list" useDataTable(table_id) return { - av_title_publication_types, get_lib_from_av, + map_av_dt_filter, table_id, } }, @@ -37,13 +36,10 @@ export default { let show_resource = this.show_resource let package_id = this.package_id let get_lib_from_av = this.get_lib_from_av + let map_av_dt_filter = this.map_av_dt_filter let table_id = this.table_id - window['av_title_publication_types'] = this.av_title_publication_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) + window['av_title_publication_types'] = map_av_dt_filter('av_title_publication_types') $('#' + table_id).kohaTable({ ajax: { 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 49d2ef3d23..af742df32a 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 @@ -28,17 +28,15 @@ export default { const { vendors } = storeToRefs(vendorStore) const AVStore = useAVStore() - const { av_package_types, av_package_content_types } = storeToRefs(AVStore) - const { get_lib_from_av } = AVStore + const { get_lib_from_av, map_av_dt_filter } = AVStore const table_id = "package_list" useDataTable(table_id) return { vendors, - av_package_types, - av_package_content_types, get_lib_from_av, + map_av_dt_filter, table_id, } }, @@ -77,6 +75,7 @@ export default { let edit_package = this.edit_package let delete_package = this.delete_package let get_lib_from_av = this.get_lib_from_av + let map_av_dt_filter = this.map_av_dt_filter let filters = this.filters let table_id = this.table_id @@ -85,18 +84,12 @@ export default { e['_str'] = e['name'] return e }) - window['av_package_types'] = this.av_package_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) - window['av_package_content_types'] = this.av_package_content_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e + let avs = ['av_package_types', 'av_package_content_types'] + avs.forEach(function (av_cat) { + window[av_cat] = map_av_dt_filter(av_cat) }) - $('#'+table_id ).kohaTable({ + $('#' + table_id).kohaTable({ ajax: { url: "/api/v1/erm/eholdings/local/packages", }, 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 0f4efca02c..870c45431f 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 @@ -25,7 +25,7 @@ export default { setup() { const AVStore = useAVStore() const { av_title_publication_types } = storeToRefs(AVStore) - const { get_lib_from_av } = AVStore + const { get_lib_from_av, map_av_dt_filter } = AVStore const table_id = "title_list" useDataTable(table_id) @@ -33,6 +33,7 @@ export default { return { av_title_publication_types, get_lib_from_av, + map_av_dt_filter, table_id, } }, @@ -72,14 +73,11 @@ export default { let edit_title = this.edit_title let delete_title = this.delete_title let get_lib_from_av = this.get_lib_from_av + let map_av_dt_filter = this.map_av_dt_filter let filters = this.filters let table_id = this.table_id - window['av_title_publication_types'] = this.av_title_publication_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) + window['av_title_publication_types'] = map_av_dt_filter('av_title_publication_types') $('#' + table_id).kohaTable({ ajax: { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue index 0fb3efcb37..0e0196b7b1 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue @@ -20,17 +20,14 @@ import { useDataTable } from "../../composables/datatables" export default { setup() { const AVStore = useAVStore() - const { - av_license_types, - av_license_statuses, - } = storeToRefs(AVStore) + const { get_lib_from_av, map_av_dt_filter } = AVStore const table_id = "license_list" useDataTable(table_id) return { - av_license_types, - av_license_statuses, + get_lib_from_av, + map_av_dt_filter, table_id, } }, @@ -65,27 +62,15 @@ export default { let show_license = this.show_license let edit_license = this.edit_license let delete_license = this.delete_license + let get_lib_from_av = this.get_lib_from_av + let map_av_dt_filter = this.map_av_dt_filter let default_search = this.$route.query.q let table_id = this.table_id - window['av_license_types'] = this.av_license_types.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e + let avs = ['av_license_types', 'av_license_statuses'] + avs.forEach(function (av_cat) { + window[av_cat] = map_av_dt_filter(av_cat) }) - let av_license_types_map = this.av_license_types.reduce((map, e) => { - map[e.authorised_value] = e - return map - }, {}) - window['av_license_statuses'] = this.av_license_statuses.map(e => { - e['_id'] = e['authorised_value'] - e['_str'] = e['lib'] - return e - }) - let av_license_statuses_map = this.av_license_statuses.reduce((map, e) => { - map[e.authorised_value] = e - return map - }, {}) $('#' + table_id).kohaTable({ ajax: { @@ -125,7 +110,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return escape_str(av_license_types_map[row.type].lib) + return escape_str(get_lib_from_av("av_license_types", row.type)) } }, { @@ -134,7 +119,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return escape_str(av_license_statuses_map[row.status].lib) + return escape_str(get_lib_from_av("av_license_statuses", row.status)) } }, { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js index ca10ac3e53..681e08326e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised_values.js @@ -50,5 +50,12 @@ export const useAVStore = defineStore("authorised_values", { let o = this[arr_name].find((e) => e.authorised_value == av); return o ? o.lib : av; }, + map_av_dt_filter(arr_name) { + return this[arr_name].map((e) => { + e["_id"] = e["authorised_value"]; + e["_str"] = e["lib"]; + return e; + }); + }, }, }); -- 2.39.5