Bug 33606: Fix settings
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / vue / components / ERM / EHoldingsEBSCOTitlesList.vue
1 <template>
2     <div>
3         <fieldset>
4             {{ $__("Publication title") }}:
5             <input
6                 type="text"
7                 id="publication_title_filter"
8                 v-model="filters.publication_title"
9                 @keyup.enter="filter_table"
10             />
11             {{ $__("Publication type") }}:
12             <select
13                 id="publication_type_filter"
14                 v-model="filters.publication_type"
15             >
16                 <option value="">{{ $__("All") }}</option>
17                 <option
18                     v-for="type in av_title_publication_types"
19                     :key="type.value"
20                     :value="type.value"
21                 >
22                     {{ type.description }}
23                 </option>
24             </select>
25             {{ $__("Selection status") }}:
26             <select id="selection_type_filter" v-model="filters.selection_type">
27                 <option value="0">{{ $__("All") }}</option>
28                 <option value="1">{{ $__("Selected") }}</option>
29                 <option value="2">{{ $__("Not selected") }}</option>
30             </select>
31             <input
32                 @click="filter_table"
33                 id="filter_table"
34                 type="button"
35                 :value="$__('Submit')"
36             />
37             <span v-if="cannot_search">{{
38                 $__("Please enter a search term")
39             }}</span>
40         </fieldset>
41
42         <!-- We need to display the table element to initiate DataTable -->
43         <div
44             id="title_list_result"
45             :style="show_table ? 'display: block' : 'display: none'"
46         >
47             <div
48                 v-if="
49                     local_title_count !== undefined &&
50                     local_title_count !== null
51                 "
52             >
53                 <router-link :to="local_titles_url">
54                     {{
55                         $__("%s titles found locally").format(local_title_count)
56                     }}</router-link
57                 >
58             </div>
59             <div id="title_list_result" class="page-section">
60                 <KohaTable
61                     v-if="show_table"
62                     ref="table"
63                     v-bind="tableOptions"
64                     @show="doShow"
65                 ></KohaTable>
66             </div>
67         </div>
68     </div>
69 </template>
70
71 <script>
72 import { inject, ref, reactive } from "vue"
73 import { storeToRefs } from "pinia"
74 import { APIClient } from "../../fetch/api-client.js"
75 import { build_url_params, build_url } from "../../composables/datatables"
76 import KohaTable from "../KohaTable.vue"
77
78 export default {
79     setup() {
80         const vendorStore = inject("vendorStore")
81         const { vendors } = storeToRefs(vendorStore)
82
83         const AVStore = inject("AVStore")
84         const { av_title_publication_types } = storeToRefs(AVStore)
85         const { get_lib_from_av } = AVStore
86
87         const ERMStore = inject("ERMStore")
88         const { config } = ERMStore
89
90         const table = ref()
91         const filters = reactive({
92             publication_title: "",
93             publication_type: "",
94             selection_type: "",
95         })
96
97         return {
98             vendors,
99             av_title_publication_types,
100             get_lib_from_av,
101             escape_str,
102             config,
103             table,
104         }
105     },
106     data: function () {
107         this.filters = {
108             publication_title: this.$route.query.publication_title || "",
109             publication_type: this.$route.query.publication_type || "",
110             selection_type: this.$route.query.selection_type || "",
111         }
112         let filters = this.filters
113
114         return {
115             titles: [],
116             initialized: true,
117             tableOptions: {
118                 columns: this.getTableColumns(),
119                 url: "/api/v1/erm/eholdings/ebsco/titles",
120                 options: {
121                     ordering: false,
122                     dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>',
123                     aLengthMenu: [
124                         [10, 20, 50, 100],
125                         [10, 20, 50, 100],
126                     ],
127                 },
128                 filters_options: {
129                     1: () =>
130                         this.map_av_dt_filter("av_title_publication_types"),
131                 },
132                 actions: { 0: ["show"] },
133                 default_filters: {
134                     publication_title: function () {
135                         return filters.publication_title || ""
136                     },
137                     publication_type: function () {
138                         return filters.publication_type || ""
139                     },
140                     selection_type: function () {
141                         return filters.selection_type || ""
142                     },
143                 },
144             },
145             cannot_search: false,
146             show_table: build_url_params(filters).length ? true : false,
147             local_title_count: null,
148         }
149     },
150     computed: {
151         local_titles_url() {
152             let { href } = this.$router.resolve({
153                 name: "EHoldingsLocalTitlesList",
154             })
155             return build_url(href, this.filters)
156         },
157     },
158     methods: {
159         doShow: function ({ title_id }, dt, event) {
160             event.preventDefault()
161             this.$router.push({
162                 name: "EHoldingsEBSCOTitlesShow",
163                 params: { title_id },
164             })
165         },
166         filter_table: async function () {
167             if (this.filters.publication_title.length) {
168                 this.cannot_search = false
169                 let { href } = this.$router.resolve({
170                     name: "EHoldingsEBSCOTitlesList",
171                 })
172                 let new_route = build_url(href, this.filters)
173                 this.$router.push(new_route)
174                 this.show_table = true
175                 this.local_title_count = null
176
177                 if (this.$refs.table) {
178                     this.$refs.table.redraw(
179                         "/api/v1/erm/eholdings/ebsco/titles"
180                     )
181                 }
182                 if (this.config.settings.ERMProviders.includes("local")) {
183                     const client = APIClient.erm
184
185                     const q = this.filters
186                         ? {
187                               ...(this.filters.publication_title
188                                   ? {
189                                         "me.publication_title": {
190                                             like:
191                                                 "%" +
192                                                 this.filters.publication_title +
193                                                 "%",
194                                         },
195                                     }
196                                   : {}),
197                               ...(this.filters.publication_type
198                                   ? {
199                                         "me.publication_type":
200                                             this.filters.publication_type,
201                                     }
202                                   : {}),
203                           }
204                         : undefined
205
206                     client.localTitles.count(q).then(
207                         count => (this.local_title_count = count),
208                         error => {}
209                     )
210                 }
211             } else {
212                 this.cannot_search = true
213             }
214         },
215         getTableColumns: function () {
216             let get_lib_from_av = this.get_lib_from_av
217             let escape_str = this.escape_str
218             return [
219                 {
220                     title: __("Title"),
221                     data: "me.publication_title",
222                     searchable: false,
223                     orderable: false,
224                     render: function (data, type, row, meta) {
225                         let node =
226                             '<a href="/cgi-bin/koha/erm/eholdings/ebsco/titles/' +
227                             row.title_id +
228                             '" class="show">' +
229                             escape_str(
230                                 `${row.publication_title} (#${row.title_id})`
231                             ) +
232                             "</a>"
233                         if (row.is_selected) {
234                             node +=
235                                 " " +
236                                 '<i class="fa fa-check-square" style="color: green; float: right;" title="' +
237                                 __("Is selected") +
238                                 '" />'
239                         }
240                         return node
241                     },
242                 },
243                 {
244                     title: __("Publisher name"),
245                     data: "me.publisher_name",
246                     searchable: false,
247                     orderable: false,
248                     render: function (data, type, row, meta) {
249                         return escape_str(row.publisher_name)
250                     },
251                 },
252                 {
253                     title: __("Publication type"),
254                     data: "publication_type",
255                     searchable: false,
256                     orderable: false,
257                     render: function (data, type, row, meta) {
258                         return escape_str(
259                             get_lib_from_av(
260                                 "av_title_publication_types",
261                                 row.publication_type
262                             )
263                         )
264                     },
265                 },
266                 {
267                     title: __("Identifier"),
268                     data: "print_identifier:online_identifier",
269                     searchable: false,
270                     orderable: false,
271                     render: function (data, type, row, meta) {
272                         let print_identifier = row.print_identifier
273                         let online_identifier = row.online_identifier
274                         return (
275                             (print_identifier
276                                 ? escape_str(
277                                       _("ISBN (Print): %s").format(
278                                           print_identifier
279                                       )
280                                   )
281                                 : "") +
282                             (online_identifier
283                                 ? escape_str(
284                                       _("ISBN (Online): %s").format(
285                                           online_identifier
286                                       )
287                                   )
288                                 : "")
289                         )
290                     },
291                 },
292             ]
293         },
294     },
295     components: { KohaTable },
296     name: "EHoldingsEBSCOTitlesList",
297 }
298 </script>