UNPKG

@digital-blueprint/sublibrary-app

Version:

[GitHub Repository](https://github.com/digital-blueprint/sublibrary-app) | [npmjs package](https://www.npmjs.com/package/@digital-blueprint/sublibrary-app) | [Unpkg CDN](https://unpkg.com/browse/@digital-blueprint/sublibrary-app/) | [Sublibrary Bundle](ht

115 lines (112 loc) 14.4 kB
let e=e=>e,t,n,r,i;function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?a(Object(n),!0).forEach(function(t){s(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function s(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e){var t=l(e,`string`);return typeof t==`symbol`?t:t+``}function l(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)} /*! * License: LGPL-2.1-or-later * Dependencies: * * @webcomponents/scoped-custom-element-registry: BSD-3-Clause * @dbp-toolkit/app-shell: LGPL-2.1-or-later * @dbp-toolkit/language-select: LGPL-2.1-or-later * @dbp-toolkit/auth: LGPL-2.1-or-later * lit-html: BSD-3-Clause * @dbp-toolkit/notification: LGPL-2.1-or-later * @dbp-toolkit/theme-switcher: LGPL-2.1-or-later * universal-router: MIT * @dbp-toolkit/matomo: LGPL-2.1-or-later */ import{a as u,d,i as f,n as p,r as m,s as h,t as g}from"./shared/library-select.DEl5HMBb.js";import{B as _,C as v,D as y,E as b,F as x,M as S,N as C,S as w,T,V as E,b as D,d as O}from"./shared/styles.Cw9eAWXA.js";import{t as k}from"./shared/src.BHFEA-pi.js";import{n as A}from"./shared/utils.Bvuc5ewV.js";var j=d(m(),1);function M(){return{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 e.maximum===1?t+=`ag`:t+=`äge`,t+=` auswählen`,t},noResults:function(){return`Keine Übereinstimmungen gefunden`},searching:function(){return`Suche…`},removeAllItems:function(){return`Auswahl aufheben`}}}function N(){return{errorLoading:function(){return`The results could not be loaded.`},inputTooLong:function(e){var t=e.input.length-e.maximum,n=`Please delete `+t+` character`;return t!=1&&(n+=`s`),n},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 e.maximum!=1&&(t+=`s`),t},noResults:function(){return`No results found`},searching:function(){return`Searching…`},removeAllItems:function(){return`Remove selection`}}}var P=d(f(),1);S(`dbp-sublibrary-book-list`,class extends b(u){constructor(){super(),this._i18n=h(),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-`+x(24),this.$locationIdentifierSelect=null,this.inventoryYear=``,this.inventoryYears=[],this.inventoryYearSelectId=`dbp-sublibrary-book-list-inventory-year-select-`+x(24),this.$inventoryYearSelect=null;let e=new Date;e.setDate(e.getDate()-1),this.analyticsUpdateDate=e.toLocaleDateString(this.lang),(0,j.default)(window,P.default)}static get scopedElements(){return{"dbp-library-select":g,"dbp-data-table-view":k,"dbp-mini-spinner":y}}$(e){return(0,P.default)(this._(e))}static get properties(){return o(o({},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._(`dbp-data-table-view`).setCSSStyle(` table.dataTable tbody tr.odd { background-color: var(--dbp-background); } `),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();break}}),super.update(e)}updateLocationIdentifierSelect(){this.initLocationIdentifierSelect()}updateInventoryYearSelect(){this.initInventoryYearSelect()}disconnectedCallback(){this.abortController!==null&&this.abortController.abort(),super.disconnectedCallback()}loadTable(){let e=this,t=e.$(`#book-list-block`),n=e.$(`#no-books-block`);if(t.hide(),n.hide(),!this.isLoggedIn()||this.sublibraryIri===``)return;let r=this.sublibraryIri.split(`/`),i=r[r.length-1],a=this.entryPointUrl+`/sublibrary/book-offers?perPage=9999999&sublibrary=`+i,o=e.$(`#books-loading`);o.show(),this.abortController!==null&&this.abortController.abort(),this.abortController=new AbortController;let s=this.abortController.signal;fetch(a,{headers:{"Content-Type":`application/ld+json`,Authorization:`Bearer `+this.auth.token},signal:s}).then(e=>{if(!e.ok)throw e;if(e.headers.has(`x-analytics-update-date`)){let 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(),o.hide()}).catch(t=>{e.handleFetchError(t,e._i18n.t(`book-list.error-load-books`)),this.abortController===null&&o.hide()})}buildTable(e=!0){let t=this,n=this.$(`#book-list-block`),r=this.$(`#no-books-block`),i=[],a=[];if(this.books.length>0){let r=this._(`#book-books-1`);if(r!==null){let n=[{title:this._i18n.t(`book-list.book-title`)},{title:this._i18n.t(`book-list.book-author`)},{title:this._i18n.t(`book-list.book-publication-date`)},null,{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`)}],o=[{targets:[2],orderData:[3]},{targets:[3],visible:!1},{targets:[5],orderData:[6]},{targets:[6],visible:!1}],s=[];this.books.forEach(function(n){let r=new Date(n.availabilityStarts),o=n.availabilityStarts===null?``:r.getFullYear().toString();if((t.locationIdentifier===``||t.locationIdentifier===n.locationIdentifier)&&(t.inventoryYear===``||t.inventoryYear===o)){let e=n.book.datePublished??``,t=A(e),i=[n.book.title,n.book.author,e,t,n.book.publisher,n.availabilityStarts===null?``:r.toLocaleDateString(`de-AT`),n.availabilityStarts,n.barcode,n.locationIdentifier,n.description];s.push(i)}e&&(n.locationIdentifier!==``&&!i.includes(n.locationIdentifier)&&i.push(n.locationIdentifier),o!==``&&!a.includes(o)&&a.push(o))}),r.set_columns(n).set_columnDefs(o).set_datatable(s)}n.show()}else r.show();e&&(this.locationIdentifiers=i.sort(),this.locationIdentifier=``,this.$locationIdentifierSelect!==null&&this.$locationIdentifierSelect.val(``),this.inventoryYears=a.sort().reverse(),this.inventoryYear=``,this.$inventoryYearSelect!==null&&this.$inventoryYearSelect.val(``))}onLanguageChanged(e){this.lang=e.detail.lang}locationIdentifierSelect2IsInitialized(){return this.$locationIdentifierSelect!==null&&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:this.lang===`de`?M():N(),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 this.$inventoryYearSelect!==null&&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:this.lang===`de`?M():N(),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 E(t||=e` ${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; } `,T(),D(),w(),v())}onSublibraryChanged(e){this.sublibraryIri=e.detail.value}_onLoginClicked(e){this.sendSetPropertyEvent(`requested-login-status`,`logged-in`),e.preventDefault()}render(){let t=[];this.locationIdentifiers.forEach(r=>{t.push(_(n||=e` <option value="${0}">${0}</option> `,r,r))});let a=[];this.inventoryYears.forEach(t=>{a.push(_(r||=e` <option value="${0}">${0}</option> `,t,t))});let o=C(p),s=this._i18n;return _(i||=e` <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} <a href="#" @click="${0}">${0}</a> </div> <div class="notification is-danger ${0}"> ${0} </div> <div class="${0}"> <dbp-mini-spinner></dbp-mini-spinner> </div> `,o,O({hidden:!this.isLoggedIn()||!this.hasLibraryPermissions()||this.isLoading()}),s.t(`book-list.current-state`),this.analyticsUpdateDate,s.t(`organization-select.label`),this.sublibraryIri,this.onSublibraryChanged,s.t(`book-list.mini-spinner-text`),s.t(`book-list.book-location-identifier`),this.locationIdentifierSelectId,t,s.t(`book-list.book-inventory-year`),this.inventoryYearSelectId,a,s.t(`book-list.books`),s.t(`book-list.export-name`,{organizationCode:this.getOrganizationCode()}),s.t(`book-list.no-books`),O({hidden:this.isLoggedIn()||this.isLoading()}),s.t(`error-login-message`),this._onLoginClicked,s.t(`error-login-link`),O({hidden:this.hasLibraryPermissions()||!this.isLoggedIn()||this.isLoading()}),s.t(`error-permission-message`),O({hidden:!this.isLoading()}))}}); //# sourceMappingURL=dbp-sublibrary-book-list.js.map