Bug 29234: Further clean Z3950 Tests
[srvgit] / koha-tmpl / intranet-tmpl / prog / js / vue / components / ERM / EHoldingsEBSCOResourcesShow.vue
1 <template>
2     <div v-if="!initialized">{{ $__("Loading") }}</div>
3     <div v-else-if="resource" id="eholdings_resources_show">
4         <h2>
5             {{ $__("Resource #%s").format(resource.resource_id) }}
6             <span v-if="!updating_is_selected">
7                 <a
8                     v-if="!resource.is_selected"
9                     class="btn btn-default btn-xs"
10                     role="button"
11                     @click="add_to_holdings"
12                     ><font-awesome-icon icon="plus" />
13                     {{ $__("Add title to holdings") }}</a
14                 >
15                 <a
16                     v-else
17                     class="btn btn-default btn-xs"
18                     role="button"
19                     id="remove-from-holdings"
20                     @click="remove_from_holdings"
21                     ><font-awesome-icon icon="minus" />
22                     {{ $__("Remove title from holdings") }}</a
23                 > </span
24             ><span v-else><font-awesome-icon icon="spinner" /></span>
25         </h2>
26         <div>
27             <fieldset class="rows">
28                 <legend>{{ $__("Resource information") }}</legend>
29                 <ol>
30                     <li v-if="resource.resource_id">
31                         <label>{{ $__("Resource identifier") }}:</label>
32                         <span>
33                             {{ resource.resource_id }}
34                         </span>
35                     </li>
36                     <li>
37                         <label>{{ $__("Publication title") }}:</label>
38                         <span
39                             ><router-link
40                                 :to="`/cgi-bin/koha/erm/eholdings/ebsco/titles/${resource.title_id}`"
41                                 >{{
42                                     resource.title.publication_title
43                                 }}</router-link
44                             ></span
45                         >
46                     </li>
47                     <li>
48                         <label>{{ $__("Publisher name") }}:</label>
49                         <span>
50                             {{ resource.title.publisher_name }}
51                         </span>
52                     </li>
53                     <li>
54                         <label>{{ $__("Publication type") }}:</label>
55                         <span>
56                             {{ resource.title.publication_type }}
57                         </span>
58                     </li>
59                     <li v-if="resource.title.print_identifier">
60                         <label>{{ $__("Print-format identifier") }}:</label>
61                         <span>
62                             {{ resource.title.print_identifier }}
63                         </span>
64                     </li>
65                     <li v-if="resource.title.online_identifier">
66                         <label>{{ $__("Online-format identifier") }}:</label>
67                         <span>
68                             {{ resource.title.online_identifier }}
69                         </span>
70                     </li>
71                 </ol>
72             </fieldset>
73
74             <fieldset class="rows">
75                 <ol>
76                     <li>
77                         <label>{{ $__("Package") }}:</label>
78                         <span
79                             ><router-link
80                                 :to="`/cgi-bin/koha/erm/eholdings/ebsco/packages/${resource.package_id}`"
81                                 >{{ resource.package.name }}</router-link
82                             ></span
83                         >
84                     </li>
85
86                     <li>
87                         <label>{{ $__("Vendor") }}:</label>
88                         <span v-if="resource.vendor">
89                             {{ resource.vendor.name }}
90                         </span>
91                     </li>
92                     <li v-if="resource.package.content_type">
93                         <label>{{ $__("Package content type") }}:</label>
94                         <span>{{ resource.package.content_type }}</span>
95                     </li>
96                 </ol>
97             </fieldset>
98
99             <fieldset class="rows">
100                 <legend>Resource settings</legend>
101                 <ol>
102                     <li>
103                         <label>{{ $__("Coverage dates") }}:</label>
104                         <span
105                             >{{ format_date(resource.started_on) }}-{{
106                                 format_date(resource.ended_on)
107                             }}</span
108                         >
109                     </li>
110                 </ol>
111             </fieldset>
112         </div>
113     </div>
114 </template>
115
116 <script>
117 import { inject } from "vue"
118 import { storeToRefs } from "pinia"
119 import { APIClient } from "../../fetch/api-client.js"
120
121 export default {
122     setup() {
123         const format_date = $date
124
125         const vendorStore = inject("vendorStore")
126         const { vendors } = storeToRefs(vendorStore)
127         return {
128             format_date,
129             vendors,
130         }
131     },
132     data() {
133         return {
134             resource: {
135                 resource_id: null,
136                 title_id: null,
137                 package_id: null,
138                 started_on: "",
139                 ended_on: "",
140                 proxy: "",
141                 title: {},
142                 package: {},
143             },
144             initialized: false,
145             updating_is_selected: false,
146         }
147     },
148
149     beforeRouteEnter(to, from, next) {
150         next(vm => {
151             vm.getResource(to.params.resource_id)
152         })
153     },
154     beforeRouteUpdate(to, from) {
155         this.resource = this.getResource(to.params.resource_id)
156     },
157     methods: {
158         getResource(resource_id) {
159             const client = APIClient.erm
160             client.EBSCOResources.get(resource_id).then(
161                 resource => {
162                     this.resource = resource
163                     this.initialized = true
164                     this.updating_is_selected = false
165                 },
166                 error => {}
167             )
168         },
169         edit_selected(is_selected) {
170             this.updating_is_selected = true
171             const client = APIClient.erm
172             client.EBSCOResources.patch(this.resource.resource_id, {
173                 is_selected,
174             }).then(
175                 result => {
176                     // Refresh the page. We should not need that actually.
177                     this.getResource(this.resource.resource_id)
178                 },
179                 error => {}
180             )
181         },
182         add_to_holdings() {
183             this.edit_selected(true)
184         },
185         remove_from_holdings() {
186             this.edit_selected(false)
187         },
188     },
189     name: "EHoldingsEBSCOResourcesShow",
190 }
191 </script>
192 <style scoped>
193 fieldset.rows label {
194     width: 25rem;
195 }
196 </style>