@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
299 lines (295 loc) • 10.8 kB
JavaScript
let _ = t => t,
_t,
_t2;
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:
*
* @dbp-toolkit/common: LGPL-2.1-or-later
* jquery: MIT
* select2: MIT
* @dbp-toolkit/resource-select: LGPL-2.1-or-later
* @babel/runtime: MIT
* i18next: MIT
* @lit/reactive-element: BSD-3-Clause
* lit-html: BSD-3-Clause
* lit-element: BSD-3-Clause
* @open-wc/dedupe-mixin: MIT
* @open-wc/scoped-elements: MIT
* datatables.net: MIT
* datatables.net-responsive: MIT
* datatables.net-responsive-dt: MIT
* datatables.net-dt: MIT
* jszip: (MIT OR GPL-3.0-or-later)
* datatables.net-buttons-dt: MIT
* datatables.net-buttons: MIT
* @dbp-toolkit/data-table-view: LGPL-2.1-or-later
* @dbp-toolkit/person-select: LGPL-2.1-or-later
*/
import { L as e, c as t, a as i, j as r } from "./shared/library-select.cb305ad9.es.js";
import { S as s, M as o, n as a, i as l, g as n, a as d, b, y as c, o as h, e as u } from "./shared/_commonjsHelpers.01af1198.es.js";
import { D as p } from "./shared/data-table-view.228afe55.es.js";
function g(e, t) {
return "active" === t ? e.t("order-list.status-name-active") : "cancelled" === t ? e.t("order-list.status-name-cancelled") : "closed" === t ? e.t("order-list.status-name-closed") : t;
}
class y extends s(e) {
constructor() {
super(), this.auth = {}, this._i18n = t(), this.lang = this._i18n.language, this.entryPointUrl = "", this.personId = "", this.person = null, this.books = [], this.sublibraryIri = "", this.abortController = null, this.openOnly = !1;
let e = new Date();
e.setDate(e.getDate() - 1), this.analyticsUpdateDate = e.toLocaleDateString(this.lang);
}
static get scopedElements() {
return {
"dbp-library-select": i,
"dbp-data-table-view": p,
"dbp-mini-spinner": o
};
}
$(e) {
return r(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
},
openOnly: {
type: Boolean,
attribute: !1
},
analyticsUpdateDate: {
type: Object,
attribute: !1
},
auth: {
type: Object
}
});
}
loginCallback() {
super.loginCallback(), this.loadTable();
}
connectedCallback() {
super.connectedCallback(), this.updateComplete.then(() => {
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.loadTable();
break;
case "sublibraryIri":
case "openOnly":
this.loadTable();
}
}), super.update(e);
}
disconnectedCallback() {
null !== this.abortController && this.abortController.abort(), super.disconnectedCallback();
}
loadTable() {
const e = this._i18n,
t = this,
i = t.$("#book-list-block"),
r = t.$("#no-books-block");
if (i.hide(), r.hide(), !this.isLoggedIn()) return;
if ("" === this.sublibraryIri) return;
const s = this.sublibraryIri.split("/"),
o = s[s.length - 1],
l = this.entryPointUrl + "/sublibrary/book-orders?perPage=9999999&sublibrary=" + o,
n = this.$("#books-loading");
n.show(), null !== this.abortController && this.abortController.abort(), this.abortController = new AbortController();
const d = this.abortController.signal;
console.assert(this.auth.token), fetch(l, {
headers: {
"Content-Type": "application/ld+json",
Authorization: "Bearer " + this.auth.token
},
signal: d
}).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(s => {
if (t.books = s["hydra:member"], t.books.length > 0) {
const r = t._("#book-books-1");
if (null !== r) {
const i = [{
title: e.t("book-list.book-title")
}, {
title: e.t("book-list.book-author")
}, {
title: e.t("book-list.book-isbn")
}, {
title: e.t("order-list.order-date")
}, null, {
title: e.t("order-list.order-number")
}, {
title: e.t("order-list.book-price")
}, null, {
title: e.t("order-list.order-status")
}, {
title: e.t("order-list.receiving -note")
}],
_s = [{
targets: [3],
orderData: [4]
}, {
targets: [4],
visible: !1
}, {
targets: [6],
orderData: [7]
}, {
targets: [7],
visible: !1
}],
o = [];
t.books.forEach(function (i) {
if (t.openOnly && "active" !== i.orderedItem.orderDelivery.deliveryStatus.eventStatus.name) return;
const r = new Date(i.orderDate);
let s = i.orderedItem.price > 0 ? a(e, i.orderedItem.price, {
style: "currency",
currency: i.orderedItem.priceCurrency
}) : "";
const l = [i.orderedItem.orderedItem.title, i.orderedItem.orderedItem.author, i.orderedItem.orderedItem.isbn, r.toLocaleDateString("de-AT"), i.orderDate, i.orderNumber, s, i.orderedItem.price, g(e, i.orderedItem.orderDelivery.deliveryStatus.eventStatus.name), i.receivingNote];
o.push(l);
}), r.set_columns(i).set_columnDefs(_s).set_datatable(o).on("draw", this.table_draw.bind(t)).draw();
}
i.show();
} else r.show();
n.hide();
}).catch(i => {
t.handleFetchError(i, e.t("order-list.error-load-orders")), n.hide();
});
}
onLanguageChanged(e) {
this.lang = e.detail.lang;
}
toggleOpenOnly() {
this.openOnly = !this.openOnly;
}
static get styles() {
return l(_t || (_t = _`
${0}
${0}
${0}
.hidden {
display: none;
}
#book-list-block,
#no-books-block {
display: none;
}
form,
table {
width: 100%;
}
#no-books-block {
font-weight: bold;
}
`), n(), d(), b());
}
onSublibraryChanged(e) {
this.sublibraryIri = e.detail.value;
}
table_draw() {
this.shadowRoot.querySelector("#book-books-1").columnReduce(7, function (e, t) {
let i = 0;
i = "string" == typeof e ? 1 * e.replace(",", ".").replace(" EUR", "") : 1 * e;
let r = 0;
return r = "string" == typeof t ? 1 * t.replace(",", ".").replace(" EUR", "") : 1 * t, i + r;
});
}
render() {
const e = this._i18n;
return c(_t2 || (_t2 = _`
<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}"
="${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">
<input type="checkbox" .checked=${0} =${0} .disabled=${0}>
${0}
</label>
</div>
-->
<div class="field">
<label class="label">${0}</label>
<div class="control">
<dbp-data-table-view
searching
paging
column-searching
default-order='[3, "desc"]'
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>
`), h({
hidden: !this.isLoggedIn() || !this.hasLibraryPermissions() || this.isLoading()
}), e.t("order-list.current-state"), this.analyticsUpdateDate, e.t("organization-select.label"), this.sublibraryIri, this.onSublibraryChanged, e.t("order-list.mini-spinner-text"), this.openOnly, this.toggleOpenOnly, this.overdueOnly, e.t("order-list.open-only"), e.t("book-list.books"), e.t("order-list.export-name", {
organizationCode: this.getOrganizationCode()
}), e.t("book-list.no-books"), h({
hidden: this.isLoggedIn() || this.isLoading()
}), e.t("error-login-message"), h({
hidden: this.hasLibraryPermissions() || !this.isLoggedIn() || this.isLoading()
}), e.t("error-permission-message"), h({
hidden: !this.isLoading()
}));
}
}
u("dbp-sublibrary-order-list", y);
//# sourceMappingURL=dbp-sublibrary-order-list.js.map