Bug 33066: Use KohaTable for EHoldingsEBSCOTitlesList

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-03-17 15:01:44 +01:00 committed by Tomas Cohen Arazi
parent e03cee38ca
commit f2b9a44b71
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -57,14 +57,19 @@
> >
</div> </div>
<div id="title_list_result" class="page-section"> <div id="title_list_result" class="page-section">
<table :id="table_id"></table> <KohaTable
v-if="show_table"
ref="table"
v-bind="tableOptions"
@show="doShow"
></KohaTable>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { inject, createVNode, render } from "vue" import { inject, ref, reactive } from "vue"
import { storeToRefs } from "pinia" import { storeToRefs } from "pinia"
import { APIClient } from "../../fetch/api-client.js" import { APIClient } from "../../fetch/api-client.js"
import { import {
@ -72,6 +77,7 @@ import {
build_url_params, build_url_params,
build_url, build_url,
} from "../../composables/datatables" } from "../../composables/datatables"
import KohaTable from "../KohaTable.vue"
export default { export default {
setup() { setup() {
@ -82,28 +88,63 @@ export default {
const { av_title_publication_types } = storeToRefs(AVStore) const { av_title_publication_types } = storeToRefs(AVStore)
const { get_lib_from_av } = AVStore const { get_lib_from_av } = AVStore
const table_id = "title_list" const table = ref()
useDataTable(table_id) const filters = reactive({
publication_title: "",
publication_type: "",
selection_type: "",
})
return { return {
vendors, vendors,
av_title_publication_types, av_title_publication_types,
get_lib_from_av, get_lib_from_av,
escape_str,
erm_providers, erm_providers,
table_id, table,
} }
}, },
data: function () { data: function () {
this.filters = {
publication_title: this.$route.query.publication_title || "",
publication_type: this.$route.query.publication_type || "",
selection_type: this.$route.query.selection_type || "",
}
let filters = this.filters
return { return {
titles: [], titles: [],
initialized: true, initialized: true,
filters: { tableOptions: {
publication_title: this.$route.query.publication_title || "", columns: this.getTableColumns(),
publication_type: this.$route.query.publication_type || "", url: "/api/v1/erm/eholdings/ebsco/titles",
selection_type: this.$route.query.selection_type || "", options: {
ordering: false,
dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>',
aLengthMenu: [
[10, 20, 50, 100],
[10, 20, 50, 100],
],
},
filters_options: {
1: () =>
this.map_av_dt_filter("av_title_publication_types"),
},
actions: { 0: ["show"] },
default_filters: {
publication_title: function () {
return filters.publication_title || ""
},
publication_type: function () {
return filters.publication_type || ""
},
selection_type: function () {
return filters.selection_type || ""
},
},
}, },
cannot_search: false, cannot_search: false,
show_table: false, show_table: build_url_params(filters).length ? true : false,
local_title_count: null, local_title_count: null,
} }
}, },
@ -115,15 +156,11 @@ export default {
) )
}, },
}, },
beforeRouteEnter(to, from, next) {
next(vm => {
vm.build_datatable()
})
},
methods: { methods: {
show_title: function (title_id) { doShow: function (title, dt, event) {
event.preventDefault()
this.$router.push( this.$router.push(
"/cgi-bin/koha/erm/eholdings/ebsco/titles/" + title_id "/cgi-bin/koha/erm/eholdings/ebsco/titles/" + title.title_id
) )
}, },
filter_table: async function () { filter_table: async function () {
@ -136,13 +173,16 @@ export default {
this.$router.push(new_route) this.$router.push(new_route)
this.show_table = true this.show_table = true
this.local_title_count = null this.local_title_count = null
$("#" + this.table_id)
.DataTable() if (this.$refs.table) {
.draw() this.$refs.table.redraw(
"/api/v1/erm/eholdings/ebsco/titles"
)
}
if (this.erm_providers.includes("local")) { if (this.erm_providers.includes("local")) {
const client = APIClient.erm const client = APIClient.erm
const q = filters const q = this.filters
? { ? {
...(this.filters.publication_title ...(this.filters.publication_title
? { ? {
@ -172,170 +212,87 @@ export default {
this.cannot_search = true this.cannot_search = true
} }
}, },
build_datatable: function () { getTableColumns: function () {
let show_title = this.show_title
let get_lib_from_av = this.get_lib_from_av let get_lib_from_av = this.get_lib_from_av
if (!this.show_table) { let escape_str = this.escape_str
this.show_table = build_url_params(this.filters).length return [
? true
: false
}
let filters = this.filters
let table_id = this.table_id
window["vendors"] = this.vendors.map(e => {
e["_id"] = e["id"]
e["_str"] = e["name"]
return e
})
let vendors_map = this.vendors.reduce((map, e) => {
map[e.id] = e
return map
}, {})
window["av_title_publication_types"] =
this.av_title_publication_types.map(e => {
e["_id"] = e["value"]
e["_str"] = e["description"]
return e
})
let additional_filters = {
publication_title: function () {
return filters.publication_title || ""
},
publication_type: function () {
return filters.publication_type || ""
},
selection_type: function () {
return filters.selection_type || ""
},
}
$("#" + table_id).kohaTable(
{ {
ajax: { title: __("Title"),
url: "/api/v1/erm/eholdings/ebsco/titles", data: "me.publication_title",
searchable: false,
orderable: false,
render: function (data, type, row, meta) {
let node =
'<a href="/cgi-bin/koha/erm/eholdings/ebsco/titles/' +
row.title_id +
'" class="show">' +
escape_str(
`${row.publication_title} (#${row.title_id})`
) +
"</a>"
if (row.is_selected) {
node +=
" " +
'<i class="fa fa-check-square-o" style="color: green; float: right;" title="' +
__("Is selected") +
'" />'
}
return node
}, },
ordering: false, },
dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>', {
aLengthMenu: [ title: __("Publisher name"),
[10, 20, 50, 100], data: "me.publisher_name",
[10, 20, 50, 100], searchable: false,
], orderable: false,
deferLoading: true, render: function (data, type, row, meta) {
autoWidth: false, return escape_str(row.publisher_name)
columns: [ },
{ },
title: __("Title"), {
data: "me.publication_title", title: __("Publication type"),
searchable: false, data: "publication_type",
orderable: false, searchable: false,
render: function (data, type, row, meta) { orderable: false,
// Rendering done in drawCallback render: function (data, type, row, meta) {
return "" return escape_str(
}, get_lib_from_av(
}, "av_title_publication_types",
{ row.publication_type
title: __("Publisher name"), )
data: "me.publisher_name",
searchable: false,
orderable: false,
render: function (data, type, row, meta) {
return escape_str(row.publisher_name)
},
},
{
title: __("Publication type"),
data: "publication_type",
searchable: false,
orderable: false,
render: function (data, type, row, meta) {
return escape_str(
get_lib_from_av(
"av_title_publication_types",
row.publication_type
)
)
},
},
{
title: __("Identifier"),
data: "print_identifier:online_identifier",
searchable: false,
orderable: false,
render: function (data, type, row, meta) {
let print_identifier = row.print_identifier
let online_identifier = row.online_identifier
return (
(print_identifier
? escape_str(
_("ISBN (Print): %s").format(
print_identifier
)
)
: "") +
(online_identifier
? escape_str(
_("ISBN (Online): %s").format(
online_identifier
)
)
: "")
)
},
},
],
drawCallback: function (settings) {
var api = new $.fn.dataTable.Api(settings)
if (!api.rows({ search: "applied" }).count()) return
$.each(
$(this).find("tbody tr td:first-child"),
function (index, e) {
let tr = $(this).parent()
let row = api.row(tr).data()
if (!row) return // Happen if the table is empty
let n = createVNode(
"a",
{
role: "button",
onClick: e => {
e.preventDefault()
show_title(row.title_id)
},
},
`${row.publication_title} (#${row.title_id})`
)
if (row.is_selected) {
n = createVNode("span", {}, [
n,
" ",
createVNode("i", {
class: "fa fa-check-square-o",
style: {
color: "green",
float: "right",
},
title: __("Is selected"),
}),
])
}
render(n, e)
}
) )
}, },
}, },
null, {
0, title: __("Identifier"),
additional_filters data: "print_identifier:online_identifier",
) searchable: false,
orderable: false,
if (filters.publication_title.length) { render: function (data, type, row, meta) {
this.filter_table() let print_identifier = row.print_identifier
} let online_identifier = row.online_identifier
return (
(print_identifier
? escape_str(
_("ISBN (Print): %s").format(
print_identifier
)
)
: "") +
(online_identifier
? escape_str(
_("ISBN (Online): %s").format(
online_identifier
)
)
: "")
)
},
},
]
}, },
}, },
components: { KohaTable },
name: "EHoldingsEBSCOTitlesList", name: "EHoldingsEBSCOTitlesList",
} }
</script> </script>