UNPKG

@dbp-topics/sublibrary

Version:

[GitLab Repository](https://github.com/digital-blueprint/sublibrary-app) | [npmjs package](https://www.npmjs.com/package/@dbp-topics/sublibrary) | [Unpkg CDN](https://unpkg.com/browse/@dbp-topics/sublibrary/) | [Sublibrary Bundle](https://gitlab.tugraz.at

471 lines (467 loc) 18 kB
let _ = t => t, _t, _t2, _t3, _t4; function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /*! * License: LGPL-2.1-or-later * Dependencies: */ import { s as e, j as t, L as i, c as n, a as o, b as r } from "./shared/library-select.cb305ad9.es.js"; import { S as a, m as l, M as s, i as c, g as d, a as u, b as h, c as b, d as g, y as p, o as f, e as m } from "./shared/_commonjsHelpers.01af1198.es.js"; import { D as y } from "./shared/data-table-view.228afe55.es.js"; e(window, t); class v extends a(i) { constructor() { super(), this._i18n = n(), this.auth = {}, this.lang = this._i18n.language, this.entryPointUrl = "", this.personId = "", this.person = null, this.books = [], this.sublibraryIri = "", this.abortController = null, this.locationIdentifier = "", this.locationIdentifiers = [], this.locationIdentifierSelectId = "dbp-sublibrary-book-list-location-identifier-select-" + l(24), this.$locationIdentifierSelect = null, this.inventoryYear = "", this.inventoryYears = [], this.inventoryYearSelectId = "dbp-sublibrary-book-list-inventory-year-select-" + l(24), this.$inventoryYearSelect = null; let e = new Date(); e.setDate(e.getDate() - 1), this.analyticsUpdateDate = e.toLocaleDateString(this.lang); } static get scopedElements() { return { "dbp-library-select": o, "dbp-data-table-view": y, "dbp-mini-spinner": s }; } $(e) { return t(this._(e)); } static get properties() { return _extends({}, super.properties, { lang: { type: String }, entryPointUrl: { type: String, attribute: "entry-point-url" }, sublibraryIri: { type: String, attribute: "sublibrary-iri", reflect: !0 }, books: { type: Object, attribute: !1 }, locationIdentifiers: { type: Array, attribute: !1 }, locationIdentifier: { type: String, attribute: !1 }, inventoryYears: { type: Array, attribute: !1 }, inventoryYear: { type: String, attribute: !1 }, analyticsUpdateDate: { type: Object, attribute: !1 }, auth: { type: Object } }); } loginCallback() { super.loginCallback(), this.loadTable(); } connectedCallback() { super.connectedCallback(), this.updateComplete.then(() => { this.initLocationIdentifierSelect(), this.initInventoryYearSelect(); this._(this.getScopedTagName("dbp-data-table-view")).setCSSStyle("\n table.dataTable tbody tr.odd {\n background-color: var(--dbp-background);\n }\n "), this.loadTable(); }); } update(e) { e.forEach((e, t) => { switch (t) { case "lang": this._i18n.changeLanguage(this.lang), this.updateLocationIdentifierSelect(), this.buildTable(!1); break; case "sublibraryIri": this.loadTable(); break; case "locationIdentifiers": this.updateLocationIdentifierSelect(); break; case "locationIdentifier": case "inventoryYear": this.buildTable(!1); break; case "inventoryYears": this.updateInventoryYearSelect(); } }), super.update(e); } updateLocationIdentifierSelect() { this.initLocationIdentifierSelect(); } updateInventoryYearSelect() { this.initInventoryYearSelect(); } disconnectedCallback() { null !== this.abortController && this.abortController.abort(), super.disconnectedCallback(); } loadTable() { const e = this, t = e.$("#book-list-block"), i = e.$("#no-books-block"); if (t.hide(), i.hide(), !this.isLoggedIn()) return; if ("" === this.sublibraryIri) return; const n = this.sublibraryIri.split("/"), o = n[n.length - 1], r = this.entryPointUrl + "/sublibrary/book-offers?perPage=9999999&sublibrary=" + o, a = e.$("#books-loading"); a.show(), null !== this.abortController && this.abortController.abort(), this.abortController = new AbortController(); const l = this.abortController.signal; fetch(r, { headers: { "Content-Type": "application/ld+json", Authorization: "Bearer " + this.auth.token }, signal: l }).then(e => { if (!e.ok) throw e; if (e.headers.has("x-analytics-update-date")) { const t = new Date(e.headers.get("x-analytics-update-date")); this.analyticsUpdateDate = t.toLocaleDateString(this.lang) + " " + t.toLocaleTimeString(this.lang); } return e.json(); }).then(t => { e.books = t["hydra:member"], e.buildTable(), a.hide(); }).catch(t => { e.handleFetchError(t, e._i18n.t("book-list.error-load-books")), null === this.abortController && a.hide(); }); } buildTable(e = !0) { const t = this, i = this.$("#book-list-block"), n = this.$("#no-books-block"); let o = [], r = []; if (this.books.length > 0) { const _n = this._("#book-books-1"); if (null !== _n) { const _i = [{ title: this._i18n.t("book-list.book-title") }, { title: this._i18n.t("book-list.book-author") }, { title: this._i18n.t("book-list.book-publication-year") }, { title: this._i18n.t("book-list.book-publisher") }, { title: this._i18n.t("book-list.book-availability-date") }, null, { title: this._i18n.t("book-list.book-barcode") }, { title: this._i18n.t("book-list.book-location-identifier") }, { title: this._i18n.t("book-list.book-description") }], a = [{ targets: [4], orderData: [5] }, { targets: [5], visible: !1 }], l = []; this.books.forEach(function (i) { const n = new Date(i.availabilityStarts), a = null !== i.availabilityStarts ? n.getFullYear().toString() : ""; if (!("" !== t.locationIdentifier && t.locationIdentifier !== i.locationIdentifier || "" !== t.inventoryYear && t.inventoryYear !== a)) { const e = new Date(i.book.datePublished), t = [i.book.title, i.book.author, null !== i.book.datePublished ? e.getFullYear() : "", i.book.publisher, null !== i.availabilityStarts ? n.toLocaleDateString("de-AT") : "", i.availabilityStarts, i.barcode, i.locationIdentifier, i.description]; l.push(t); } e && ("" === i.locationIdentifier || o.includes(i.locationIdentifier) || o.push(i.locationIdentifier), "" === a || r.includes(a) || r.push(a)); }), _n.set_columns(_i).set_columnDefs(a).set_datatable(l); } i.show(); } else n.show(); e && (this.locationIdentifiers = o.sort(), this.locationIdentifier = "", null !== this.$locationIdentifierSelect && this.$locationIdentifierSelect.val(""), this.inventoryYears = r.sort().reverse(), this.inventoryYear = "", null !== this.$inventoryYearSelect && this.$inventoryYearSelect.val("")); } onLanguageChanged(e) { this.lang = e.detail.lang; } locationIdentifierSelect2IsInitialized() { return null !== this.$locationIdentifierSelect && this.$locationIdentifierSelect.hasClass("select2-hidden-accessible"); } initLocationIdentifierSelect() { let e = this; this.$locationIdentifierSelect = this.$("#" + this.locationIdentifierSelectId), this.locationIdentifierSelect2IsInitialized() && this.$locationIdentifierSelect.select2("destroy"), this.$locationIdentifierSelect.select2({ width: "100%", allowClear: !0, language: "de" === this.lang ? { errorLoading: function () { return "Die Ergebnisse konnten nicht geladen werden."; }, inputTooLong: function (e) { return "Bitte " + (e.input.length - e.maximum) + " Zeichen weniger eingeben"; }, inputTooShort: function (e) { return "Bitte " + (e.minimum - e.input.length) + " Zeichen mehr eingeben"; }, loadingMore: function () { return "Lade mehr Ergebnisse…"; }, maximumSelected: function (e) { var t = "Sie können nur " + e.maximum + " Eintr"; return 1 === e.maximum ? t += "ag" : t += "äge", t += " auswählen"; }, noResults: function () { return "Keine Übereinstimmungen gefunden"; }, searching: function () { return "Suche…"; }, removeAllItems: function () { return "Auswahl aufheben"; } } : { errorLoading: function () { return "The results could not be loaded."; }, inputTooLong: function (e) { var t = e.input.length - e.maximum, i = "Please delete " + t + " character"; return 1 != t && (i += "s"), i; }, inputTooShort: function (e) { return "Please enter " + (e.minimum - e.input.length) + " or more characters"; }, loadingMore: function () { return "Loading more results…"; }, maximumSelected: function (e) { var t = "You can only select " + e.maximum + " item"; return 1 != e.maximum && (t += "s"), t; }, noResults: function () { return "No results found"; }, searching: function () { return "Searching…"; }, removeAllItems: function () { return "Remove selection"; } }, placeholder: this._i18n.t("book-list.location-identifier-select-placeholder"), dropdownParent: this.$("#location-identifier-select-dropdown") }).on("select2:select", function (t) { e.locationIdentifier = t.params.data.id; }).on("select2:clear", function () { e.locationIdentifier = ""; }).on("select2:open", function () { e.$("#location-identifier-select-dropdown .select2-search__field").blur(() => { setTimeout(() => { e.$locationIdentifierSelect.select2("close"); }, 250); }); }); } inventoryYearSelect2IsInitialized() { return null !== this.$inventoryYearSelect && this.$inventoryYearSelect.hasClass("select2-hidden-accessible"); } initInventoryYearSelect() { let e = this; this.$inventoryYearSelect = this.$("#" + this.inventoryYearSelectId), this.inventoryYearSelect2IsInitialized() && this.$inventoryYearSelect.select2("destroy"), this.$inventoryYearSelect.select2({ width: "100%", allowClear: !0, language: "de" === this.lang ? { errorLoading: function () { return "Die Ergebnisse konnten nicht geladen werden."; }, inputTooLong: function (e) { return "Bitte " + (e.input.length - e.maximum) + " Zeichen weniger eingeben"; }, inputTooShort: function (e) { return "Bitte " + (e.minimum - e.input.length) + " Zeichen mehr eingeben"; }, loadingMore: function () { return "Lade mehr Ergebnisse…"; }, maximumSelected: function (e) { var t = "Sie können nur " + e.maximum + " Eintr"; return 1 === e.maximum ? t += "ag" : t += "äge", t += " auswählen"; }, noResults: function () { return "Keine Übereinstimmungen gefunden"; }, searching: function () { return "Suche…"; }, removeAllItems: function () { return "Auswahl aufheben"; } } : { errorLoading: function () { return "The results could not be loaded."; }, inputTooLong: function (e) { var t = e.input.length - e.maximum, i = "Please delete " + t + " character"; return 1 != t && (i += "s"), i; }, inputTooShort: function (e) { return "Please enter " + (e.minimum - e.input.length) + " or more characters"; }, loadingMore: function () { return "Loading more results…"; }, maximumSelected: function (e) { var t = "You can only select " + e.maximum + " item"; return 1 != e.maximum && (t += "s"), t; }, noResults: function () { return "No results found"; }, searching: function () { return "Searching…"; }, removeAllItems: function () { return "Remove selection"; } }, placeholder: this._i18n.t("book-list.inventory-year-select-placeholder"), dropdownParent: this.$("#inventory-year-select-dropdown") }).on("select2:select", function (t) { e.inventoryYear = t.params.data.id; }).on("select2:clear", function () { e.inventoryYear = ""; }).on("select2:open", function () { e.$("#inventory-year-select-dropdown .select2-search__field").blur(() => { setTimeout(() => { e.$inventoryYearSelect.select2("close"); }, 250); }); }); } static get styles() { return c(_t || (_t = _` ${0} ${0} ${0} ${0} .hidden { display: none; } #book-list-block, #no-books-block { display: none; } form, table { width: 100%; } #no-books-block { font-weight: bold; } `), d(), u(), h(), b()); } onSublibraryChanged(e) { this.sublibraryIri = e.detail.value; } render() { let e = []; this.locationIdentifiers.forEach(t => { e.push(p(_t2 || (_t2 = _`<option value="${0}">${0}</option>`), t, t)); }); let t = []; this.inventoryYears.forEach(e => { t.push(p(_t3 || (_t3 = _`<option value="${0}">${0}</option>`), e, e)); }); const i = g(r), n = this._i18n; return p(_t4 || (_t4 = _` <link rel="stylesheet" href="${0}" /> <form class="${0}"> <div class="field"> ${0}: ${0} </div> <div class="field"> <label class="label">${0}</label> <div class="control"> <dbp-library-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth" value="${0}" @change="${0}"></dbp-library-select> </div> </div> <dbp-mini-spinner id="books-loading" text="${0}" style="font-size: 2em; display: none;"></dbp-mini-spinner> <div id="book-list-block"> <div class="field"> <label class="label">${0}</label> <div class="control"> <select id="${0}"> <option value=""></option> ${0} </select> <div id="location-identifier-select-dropdown"></div> </div> </div> <div class="field"> <label class="label">${0}</label> <div class="control"> <select id="${0}"> <option value=""></option> ${0} </select> <div id="inventory-year-select-dropdown"></div> </div> </div> <div class="field"> <label class="label">${0}</label> <div class="control"> <dbp-data-table-view searching paging exportable export-name="${0}" subscribe="lang:lang" id="book-books-1"></dbp-data-table-view> </div> </div> </div> <div id="no-books-block">${0}</div> </form> <div class="notification is-warning ${0}"> ${0} </div> <div class="notification is-danger ${0}"> ${0} </div> <div class="${0}"> <dbp-mini-spinner></dbp-mini-spinner> </div> `), i, f({ hidden: !this.isLoggedIn() || !this.hasLibraryPermissions() || this.isLoading() }), n.t("book-list.current-state"), this.analyticsUpdateDate, n.t("organization-select.label"), this.sublibraryIri, this.onSublibraryChanged, n.t("book-list.mini-spinner-text"), n.t("book-list.book-location-identifier"), this.locationIdentifierSelectId, e, n.t("book-list.book-inventory-year"), this.inventoryYearSelectId, t, n.t("book-list.books"), n.t("book-list.export-name", { organizationCode: this.getOrganizationCode() }), n.t("book-list.no-books"), f({ hidden: this.isLoggedIn() || this.isLoading() }), n.t("error-login-message"), f({ hidden: this.hasLibraryPermissions() || !this.isLoggedIn() || this.isLoading() }), n.t("error-permission-message"), f({ hidden: !this.isLoading() })); } } m("dbp-sublibrary-book-list", v); //# sourceMappingURL=dbp-sublibrary-book-list.js.map