UNPKG

@rero/rero-ils-ui

Version:

User interface for RERO integrated library system (RERO ILS).

2 lines (1 loc) 25.1 kB
import{D as rt,Fa as nt,I as st,L as v,Rd as at,Sc as f,Ud as ct,Xd as pt,Zc as ot,_c as D,a as it,be as ut,e as I,pc as L,ud as g,ve as lt,ye as k}from"./chunk-DMPOHDCX.js";import{$ as J,Ab as tt,Ca as N,D as V,I as M,Ja as W,K as P,O as X,T as Z,a as E,aa as $,ba as F,fa as h,j as K,ka as G,la as c,m as H,n as Y,q as z,qd as et,s as S,w as u,y as Q}from"./chunk-GDWQHTGO.js";var l=function(i){return i.CREATED="CREATED",i.PENDING="PENDING",i.ITEM_ON_LOAN="ITEM_ON_LOAN",i.ITEM_RETURNED="ITEM_RETURNED",i.ITEM_IN_TRANSIT_FOR_PICKUP="ITEM_IN_TRANSIT_FOR_PICKUP",i.ITEM_IN_TRANSIT_TO_HOUSE="ITEM_IN_TRANSIT_TO_HOUSE",i.ITEM_AT_DESK="ITEM_AT_DESK",i.CANCELLED="CANCELLED",i}(l||{});var C=class i{constructor(s){Object.assign(this,s),this.request_expire_date=i._convertToDate(this.request_expire_date),this.start_date=i._convertToDate(this.start_date),this.end_date=i._convertToDate(this.end_date),this.transaction_date=i._convertToDate(this.transaction_date)}static _convertToDate(s){return s?f.fromISO(s):null}get dueDate(){switch(this.state){case l.PENDING:return this.request_expire_date;case l.ITEM_ON_LOAN:return this.end_date;default:return null}}get expired(){return this.dueDate?this.dueDate<f.now():!1}};var b=function(i){return i.GENERAL="general_note",i.STAFF="staff_note",i.CHECKIN="checkin_note",i.CHECKOUT="checkout_note",i.BINDING="binding_note",i.PROVENANCE="provenance_note",i.CONDITION="condition_note",i.PATRIMONIAL="patrimonial_note",i.ACQUISITION="acquisition_note",i.API="api",i}(b||{}),_=function(i){return i.checkout="checkout",i.checkin="checkin",i.request="request",i.lose="lose",i.receive="receive",i.return_missing="return_missing",i.extend_loan="extend_loan",i.validate="validate",i.no="no",i}(_||{});var Et=function(i){return i.STANDARD="standard",i.ISSUE="issue",i}(Et||{}),O=class{static{this.PUBLIC_NOTE_TYPES=[b.GENERAL,b.BINDING,b.PROVENANCE,b.CONDITION,b.PATRIMONIAL]}constructor(s){this.actions=[],Object.assign(this,s),s.pending_loans&&(this.pending_loans=s.pending_loans.map(t=>new C(t))),this.actions!==void 0&&this.actions.unshift(_.no)}setLoan(s){this.loan=new C(s)}set currentAction(s){this._currentAction=s}get currentAction(){return this._currentAction?this._currentAction:_.no}isActionLoan(){return this.currentAction===_.checkout}isActionReturn(){return this.currentAction===_.checkin}requestedPosition(s){return!s||!this.pending_loans?0:this.pending_loans.findIndex(t=>t.patron_pid===s.patronLibrarian.pid)+1}get hasRequests(){return this.pending_loans&&this.pending_loans.length>0}getNote(s){if(this.notes==null)return null;let t=this.notes.filter(e=>e.type===s);return t?t[0]:null}};var Ut=(()=>{class i{constructor(){this.httpClient=c(v),this.userService=c(k),this.recordService=c(g),this.apiService=c(D)}getByPidFromEs(t){return this.recordService.getRecords("items",`pid:${t}`,1,1,void 0,void 0,ct.reroJsonheaders).pipe(u(e=>e.hits.hits[0]))}getRequestedLoans(t){let r=`${this.apiService.getEndpointByType("item")}/requested_loans/${t}`;return this.httpClient.get(r).pipe(u(n=>n.hits),u(n=>this.recordService.totalHits(n.total)===0?[]:n.hits),u(n=>n.map(a=>{let{item:o}=a;return a.loan&&(o.loan=a.loan),o})))}doValidateRequest(t,e){let n=`${this.apiService.getEndpointByType("item")}/validate_request`;return this.httpClient.post(n,{item_pid:t.pid,pid:t.loan.pid,transaction_library_pid:e,transaction_user_pid:this.userService.user.patronLibrarian.pid}).pipe(u(a=>{let o=a.metadata;return o.loan=a.action_applied.validate,o}))}getItem(t,e){let n=`${this.apiService.getEndpointByType("item")}/barcode/${t}`;return e&&(n+=`?patron.patron_pid=${e}`),this.httpClient.get(n).pipe(u(a=>{let o=new O(a.metadata.item);return a.metadata.loan&&o.setLoan(a.metadata.loan),o}),P(a=>{switch(a.status){case 404:throw new Error("Item not found");default:throw a}}))}checkin(t,e){let r=this.apiService.getEndpointByType("item");return this.httpClient.post(`${r}/checkin`,{item_barcode:t,transaction_library_pid:e,transaction_user_pid:this.userService.user.patronLibrarian.pid}).pipe(u(n=>{let a=new O(n.metadata),o=Object.keys(n.action_applied),p;return a.action_applied=n.action_applied,o.forEach(d=>{(d==="checkin"||d==="receive")&&(a.actionDone=_[d])}),n.action_applied[_.checkin]&&(p=n.action_applied[_.checkin]),n.action_applied[_.receive]&&(p=n.action_applied[_.receive]),n.action_applied[_.validate]&&(p=n.action_applied[_.validate]),p!=null&&a.setLoan(p),a}),P(n=>{if(n.status===404)return S(null);throw n}))}doAction(t,e,r,n,a){let o=this.apiService.getEndpointByType("item"),p=t.currentAction,d=`${o}/${p}`,m={item_pid:t.pid,transaction_library_pid:e,transaction_user_pid:r};n&&p===_.checkout&&(m.patron_pid=n,a&&"endDate"in a&&(m.end_date=a.endDate)),t.loan&&(m.pid=t.loan.pid);let T={};if(a&&"overrideBlocking"in a){let y="override_blocking";T[y]=!0}return this.httpClient.post(d,m,{params:T}).pipe(u(y=>{let j=new O(y.metadata);return j.setLoan(y.action_applied[p]),j.actionDone=p,j}))}getPickupLocations(t){let r=`${this.apiService.getEndpointByType("item")}/${t}/pickup_locations`;return this.httpClient.get(r).pipe(u(n=>n.locations),P(n=>{if(n.status===404)return S(null)}))}canRequest(t,e,r){let n=new st;e!=null&&(n=n.set("library_pid",e)),r!=null&&(n=n.set("patron_barcode",r));let a=this.apiService.getEndpointByType("item");return this.httpClient.get(`${a}/${t}/can_request`,{params:n})}needCallout(t,e){if(e=e||"warning",e==="warning"){if(t.actionDone&&t.actionDone===_.checkin)return t.status===ut.IN_TRANSIT||t.pending_loans?.length>0||t.getNote(b.CHECKIN)!=null;if(t.actionDone&&t.actionDone===_.checkout)return t.getNote(b.CHECKOUT)!=null}return!1}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var dt=class i{constructor(){this.recordService=c(g),this.httpClient=c(v),this.userService=c(k),this.translateService=c(L),this.confirmationService=c(nt)}static{this.borrowStatuses=[l.ITEM_ON_LOAN]}static{this.requestStatuses=[l.ITEM_AT_DESK,l.PENDING,l.ITEM_IN_TRANSIT_FOR_PICKUP]}borrowedBy$(s){return this.loans$(s,i.borrowStatuses).pipe(u(t=>t.hits.hits))}requestedBy$(s){return this.loans$(s,i.requestStatuses).pipe(u(t=>t.hits.hits))}canCancelRequest(s){return[l.PENDING,l.ITEM_IN_TRANSIT_FOR_PICKUP,l.ITEM_AT_DESK].some(t=>t===s.metadata.state)}cancelLoan(s,t,e){return this.httpClient.post("/api/item/cancel_item_request",{item_pid:s,pid:t,transaction_library_pid:e,transaction_user_pid:this.userService.user.patrons[0].pid}).pipe(u(n=>{let a=n.metadata;return a.loan=n.action_applied.cancel,a}))}canUpdateRequestPickupLocation(s){return[l.PENDING,l.ITEM_IN_TRANSIT_FOR_PICKUP].some(t=>t===s.metadata.state)}updateLoanPickupLocation(s,t){return this.httpClient.post("/api/item/update_loan_pickup_location",{pid:s,pickup_location_pid:t})}getCirculationPolicy(s){let t=`/api/loan/${s}/circulation_policy`;return this.httpClient.get(t)}cancelRequestDialog(s,t,e){let r={target:s.target,icon:"fa fa-exclamation-triangle",header:this.translateService.instant("Cancel request"),message:this.translateService.instant("Do you really want to cancel the request?"),acceptLabel:this.translateService.instant("Yes"),rejectLabel:this.translateService.instant("No")};t&&(r.accept=t),e&&(r.reject=e),this.confirmationService.confirm(r)}loans$(s,t){let e=`item_pid.value:${s}`;if(t!==void 0){let r=t.join(" OR state:");e+=` AND (state:${r})`}return this.recordService.getRecords("loans",e,1,100,[],void 0,void 0,"created")}static{this.\u0275fac=function(t){return new(t||i)}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}};var R=function(i){return i.PENDING="pending",i.VALIDATED="validated",i.DENIED="denied",i.CLOSED="closed",i}(R||{});function Jt(i){switch(i){case"error":return"error";case"warning":return"warn";case"debug":return"secondary";default:return"info"}}function Wt(i){switch(i){case R.PENDING:case l.PENDING:return"warn";case R.VALIDATED:case l.ITEM_AT_DESK:return"success";case R.DENIED:return"danger";case l.ITEM_ON_LOAN:case l.ITEM_RETURNED:return"info";default:return"secondary"}}var oe=(()=>{class i{constructor(){this.httpClient=c(v),this.apiService=c(D),this.recordService=c(g)}addFee(t){return this.httpClient.post(this.apiService.getEndpointByType("patron_transactions/"),t)}getActiveFeesByItemPid(t){let e=`item.pid:${t} AND total_amount:>0`;return this.recordService.getRecords("patron_transactions",e).pipe(u(r=>r.hits.hits))}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var B=function(i){return i.monday="monday",i.tuesday="tuesday",i.wednesday="wednesday",i.thursday="thursday",i.friday="friday",i.saturday="saturday",i.sunday="sunday",i}(B||{});var ht=class i{get closedDays(){return this.opening_hours.filter(s=>!s.is_open).map(s=>i.convertDayToWeekDay(s.day)).filter(s=>s!==null)}constructor(s){this.$schema=null,this.pid=null,this.name=null,this.email=null,this.address=null,this.code=null,this.communication_language=null,this.opening_hours=[],this._initOpeningHours(),s&&this.update(s),this.exception_dates||(this.exception_dates=[]),this.exception_dates=this.exception_dates.map(t=>{if(t.repeat)for(;i.isExceptionDateOver(t,!1);)t=i._incrementExceptionDate(t);return t}),this.exception_dates=this.exception_dates.sort((t,e)=>f.fromISO(e.start_date)-f.fromISO(t.start_date))}update(s){Object.assign(this,s),this._cleanOpeningHours(),this._reorderOpeningHours(),this._cleanAcquisitionSettings()}static isExceptionDateOver(s,t=!0){return s.repeat&&t?!1:(s.end_date?f.fromISO(s.end_date):f.fromISO(s.start_date))<f.now()}_initOpeningHours(){let s=Object.keys(B);for(let t=0;t<7;t++)this.opening_hours.push({day:s[t],is_open:!1,times:[]})}_cleanOpeningHours(){this.opening_hours.forEach(s=>{let t=[];s.times.map(e=>{e.start_time!=="00:00"&&e.end_time!=="00:00"&&t.push(e)}),s.is_open=t.length!==0,s.times=t})}_reorderOpeningHours(){this.opening_hours.forEach(s=>{s.times.length>1&&s.times.sort((t,e)=>f.fromFormat(t.start_time,"HH:mm").diff(f.fromFormat(e.start_time,"HH:mm")))})}static _incrementExceptionDate(s){if(!s.repeat)throw new Error("Unable to increment not repeatable exception date.");let t={daily:"days",weekly:"weeks",monthly:"months",yearly:"years"},e=Object.hasOwn(t,s.repeat.period)?t[s.repeat.period]:"days";return typeof s.start_date=="string"&&(s.start_date=f.fromFormat(s.start_date,"yyyy-LL-dd")),s.start_date=s.start_date.plus({[e]:s.repeat.interval}).toISODate(),s.end_date&&(typeof s.end_date=="string"&&(s.end_date=f.fromFormat(s.end_date,"yyyy-LL-dd")),s.end_date=s.end_date.plus({[e]:s.repeat.interval}).toISODate()),s}_cleanAcquisitionSettings(){this.acquisition_settings&&(Object.keys(this.acquisition_settings).forEach(s=>{let t=this.acquisition_settings[s];Object.keys(t).length==1&&t.address&&Object.keys(t.address).length==1&&t.address.country&&delete this.acquisition_settings[s]}),Object.keys(this.acquisition_settings).length===0&&delete this.acquisition_settings),this.serial_acquisition_settings&&(Object.keys(this.serial_acquisition_settings).forEach(s=>{let t=this.serial_acquisition_settings[s];Object.keys(t).length==1&&t.address&&Object.keys(t.address).length==1&&t.address.country&&delete this.serial_acquisition_settings[s]}),Object.keys(this.serial_acquisition_settings).length===0&&delete this.serial_acquisition_settings)}static convertDayToWeekDay(s){let t={sunday:I.Sunday,monday:I.Monday,tuesday:I.Tuesday,wednesday:I.Wednesday,thursday:I.Thursday,friday:I.Friday,saturday:I.Saturday};return s.toLowerCase()in t?t[s.toLowerCase()]:null}};var _t=function(i){return i.OPEN="open",i.CLOSED="closed",i}(_t||{}),St=function(i){return i.FEE="fee",i.PAYMENT="payment",i.DISPUTE="dispute",i.CANCEL="cancel",i}(St||{}),mt=class{constructor(s){this.status=_t.OPEN,this.total_amount=0,this.events=[],this.note=null,this.document=null,this.library=null,this.loan=null,this.patron=null,Object.assign(this,s)}get_events(){return this.events.sort((s,t)=>{let e=f.fromISO(s.creation_date);return f.fromISO(t.creation_date).diff(e)})}},ft=class{constructor(s){this.creation_date=null,this.amount=0,Object.assign(this,s)}};var Ie=(()=>{class i{constructor(){this.httpClient=c(v),this.apiService=c(D),this.recordService=c(g),this.currentPatron=new Y(void 0)}get currentPatron$(){return this.currentPatron.asObservable()}getPatron(t){return this.recordService.getRecords("patrons",`barcode:${t}`,1,1).pipe(J(e=>{switch(this.recordService.totalHits(e.hits.total)){case 0:{this.currentPatron.next(void 0);break}case 1:{let r=e.hits.hits[0].metadata;this.currentPatron.next(r);break}default:throw new Error("too much results")}return this.currentPatron.asObservable()}))}getPatronByPid(t){return this.recordService.getRecord("patrons",t).pipe(u(e=>e.metadata))}getItems(t,e){e===void 0&&(e="-transaction_date");let n=`${this.apiService.getEndpointByType("item")}/loans/${t}?sort=${e}`;return this.httpClient.get(n).pipe(u(a=>a.hits),u(a=>this.recordService.totalHits(a.total)===0?[]:a.hits),u(a=>a.map(o=>this._buildItem(o))))}getItem(t){return this.httpClient.get(`/api/item/barcode/${t}`).pipe(u(e=>this._buildItem(e.metadata)))}_buildItem(t){let e=new O(t.item);return t.loan&&e.setLoan(t.loan),e}getItemsRequested(t){return this.getLoans(`patron_pid:${t} AND (state:PENDING OR state:ITEM_IN_TRANSIT_FOR_PICKUP)`)}getItemsPickup(t){return this.getLoans(`patron_pid:${t} AND state:ITEM_AT_DESK`)}getHistory(t,e,r){e=e||Math.round(6*365/12),r=r||0;let a=[l.CANCELLED,l.ITEM_IN_TRANSIT_TO_HOUSE,l.ITEM_RETURNED].map(p=>`state:${p}`).join(" OR "),o=`patron_pid:${t} AND (${a}) end_date:[now-${e}d/d TO now-${r}d/d]`;return this.getLoans(o,"duedate")}getCirculationInformations(t){let e=[this.apiService.getEndpointByType("patrons"),t,"circulation_informations"].join("/");return this.httpClient.get(e)}getOverduePreview(t){let e=[this.apiService.getEndpointByType("patrons"),t,"overdues","preview"].join("/");return this.httpClient.get(e).pipe(u(r=>r.map(n=>({fees:n.fees,loan:new C(n.loan)}))))}getLoans(t,e){return this.recordService.getRecords("loans",t,1,g.MAX_REST_RESULTS_SIZE,[],{},{Accept:"application/rero+json"},e).pipe(u(r=>r.hits),u(r=>this.recordService.totalHits(r.total)===0?[]:r.hits))}getFormattedName(t){return[t.last_name||null,t.first_name||null].filter(e=>e!==null).map(e=>e.trim()).join(", ")}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();function bt(i){return Array.isArray(i)?i:[i]}function w(){return["Mac","iPhone","iPad"].some(s=>navigator.userAgent.includes(s))?"apple":"pc"}function q(i,s){let t={up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function e(r){return s==="pc"&&r==="meta"&&(r="control"),r in t&&(r=t[r]),r}return i.toLowerCase().split(">").map(r=>r.split(".").map(e).join(".")).join(">")}var pi=(()=>{class i{constructor(t,e){this.eventManager=t,this.document=e,this.hotkeys=new Map,this.dispose=new H,this.defaults={trigger:"keydown",allowIn:[],element:this.document.documentElement,group:void 0,description:void 0,showInHelpMenu:!0,preventDefault:!0},this.callbacks=[],this.sequenceMaps=new Map,this.sequenceDebounce=250,this._isActive=W(!0),this.isActive=et(()=>this._isActive())}getHotkeys(){let t=Array.from(this.sequenceMaps.values()).map(e=>[e.hotkeyMap].reduce((r,n)=>[...n.values()],[])).reduce((e,r)=>r,[]).map(e=>e.hotkey);return Array.from(this.hotkeys.values()).concat(t)}getShortcuts(){let t=this.getHotkeys(),e=[];for(let r of t){if(!r.showInHelpMenu)continue;let n=e.find(o=>o.group===r.group);n||(n={group:r.group,hotkeys:[]},e.push(n));let a=q(r.keys,w());n.hotkeys.push({keys:a,description:r.description})}return e}addSequenceShortcut(t){let e=(o,p)=>{let d="";return V(o,p).pipe(F(m=>d=`${d}${d?">":""}${m.ctrlKey?"control.":""}${m.altKey?"alt.":""}${m.shiftKey?"shift.":""}${m.key}`),X(this.sequenceDebounce),Q(()=>{let m=d;d="";let T=this.sequenceMaps.get(o);if(T.hotkeyMap.has(m)){let y=T.hotkeyMap.get(m);return y.subject.next(y.hotkey),S(y.hotkey)}else return z}))},r=E(E({},this.defaults),t),n=q(r.keys,w());return(()=>{let o={subject:new H,hotkey:r},p=r.global?this.document.documentElement:r.element;if(this.sequenceMaps.has(p)){let d=this.sequenceMaps.get(p);if(d.hotkeyMap.has(n))return console.error("Duplicated shortcut"),S(null);d.hotkeyMap.set(n,o)}else{let d=e(p,r.trigger),y={subscription:d.subscribe(),observer:d,hotkeyMap:new Map([[n,o]])};this.sequenceMaps.set(p,y)}return o.subject.asObservable()})().pipe($(this.dispose.pipe(M(o=>o===n))),M(o=>!this.targetIsExcluded(o.allowIn)),M(o=>this._isActive()),F(o=>{this.callbacks.forEach(p=>p(o,n,o.element))}),Z(()=>this.removeShortcuts(n)))}addShortcut(t){let e=E(E({},this.defaults),t),r=q(e.keys,w());if(this.hotkeys.has(r))return console.error("Duplicated shortcut"),S(null);this.hotkeys.set(r,e);let n=`${e.trigger}.${r}`;return new K(a=>{let o=d=>{let m=this.hotkeys.get(r);this.targetIsExcluded(m.allowIn)||(e.preventDefault&&d.preventDefault(),this._isActive()&&(this.callbacks.forEach(y=>y(d,r,m.element)),a.next(d)))},p=this.eventManager.addEventListener(e.global?this.document.documentElement:e.element,n,o);return()=>{this.hotkeys.delete(r),p()}}).pipe(M(()=>this._isActive()),$(this.dispose.pipe(M(a=>a===r))))}removeShortcuts(t){bt(t).map(r=>q(r,w())).forEach(r=>{this.hotkeys.delete(r),this.dispose.next(r),this.sequenceMaps.forEach((n,a)=>{let o=n.hotkeyMap.get(r);o&&(o.subject.observers.filter(p=>!p.closed).forEach(p=>p.unsubscribe()),n.hotkeyMap.delete(r)),n.hotkeyMap.size===0&&(n.subscription.unsubscribe(),this.sequenceMaps.delete(a))})})}setSequenceDebounce(t){this.sequenceDebounce=t}onShortcut(t){return this.callbacks.push(t),()=>this.callbacks=this.callbacks.filter(e=>e!==t)}registerHelpModal(t,e=""){this.addShortcut({keys:e||"shift.?",showInHelpMenu:!1,preventDefault:!1}).subscribe(r=>{!(/^(input|textarea|select)$/i.test(document.activeElement.nodeName)||r.target.isContentEditable)&&this.hotkeys.size&&t()})}targetIsExcluded(t){let e=this.document.activeElement,r=e.nodeName,n=e.isContentEditable,a=["INPUT","SELECT","TEXTAREA"].includes(r)||n;if(a&&t?.length){for(let o of t)if(e.nodeName===o||o==="CONTENTEDITABLE"&&n){a=!1;break}}return a}pause(){this._isActive.set(!1)}resume(){this._isActive.set(!0)}static{this.\u0275fac=function(e){return new(e||i)(G(rt),G(it))}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var yt={shift:"&#8679;",backspace:"&#9003;",tab:"&#8677;",space:"&#9251;",left:"&#8592;",right:"&#8594;",up:"&#8593;",down:"&#8595;",enter:"&#8996;"},It={meta:"&#8984;",altleft:"&#8997;",control:"&#8963;",escape:"&#9099;"},kt={control:"Ctrl",altleft:"Alt",escape:"Esc"},ui=(()=>{class i{constructor(){let t=w();this.symbols=this.getPlatformSymbols(t)}transform(t,e=" + ",r=" then ",n={}){return t?t.split(">").map(a=>a.split(".").map(o=>o.toLowerCase()).map(o=>n[o]||this.symbols[o]||o).join(e)).join(r):""}getPlatformSymbols(t){return t==="apple"?E(E({},yt),It):E(E({},yt),kt)}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275pipe=tt({name:"hotkeysShortcut",type:i,pure:!0})}}return i})();var U={APP:{ACQUISITION:{MENU:"app-acquisition-menu",ACCOUNT:"app-acquisition-account",BUDGET:"app-acquisition-budget",LATE_ISSUE:"app-acquisition-late-issue",ORDER:"app-acquisition-order",VENDOR:"app-acquisition-vendor"},ADMIN:{MENU:"app-admin-menu",CIRCULATION_POLICY:"app-admin-circulation-policy",ITEM_TYPE:"app-admin-item-type",LIBRARY:"app-admin-library",MIGRATION:"app-admin-migration",MY_LIBRARY:"app-admin-my-library",MY_ORGANISATION:"app-admin-organisation",PATRON_TYPE:"app-admin-patron-type",PERMISSION:"app-admin-permission",TEMPLATE:"app-admin-template"},CATALOG:{MENU:"app-catalog-menu",DOCUMENT:"app-catalog-document",DOCUMENT_ADD:"app-catalog-document-add",DOCUMENT_LIST:"app-catalog-document-list",ENTITY:"app-catalog-entity",IMPORT:"app-catalog-import"},REPORT_MONITORING:{MENU:"app-report-monitoring-menu",FEE:"app-report-monitoring-fee",INVENTORY:"app-report-monitoring-inventory",STAT_CONFIG:"app-report-monitoring-stat-config"},USER:{MENU:"app-user-services",CIRCULATION:"app-user-services-circulation",COLLECTION:"app-user-collection",CURRENT_LOANS:"app-user-current-loans",ILL:"app-user-ill",REQUEST:"app-user-request",USERS:"app-user-users"}},LIBRARY_MENU:"library-menu",USER:{MENU:"user-user",HELP:"user-help",LANGUAGE:"user-language",LOGOUT:"user-logout",PUBLIC_INTERFACE:"user-public-interface"}};var x=(()=>{class i{constructor(){this.localStorage=c(at)}static{this.STORAGE_KEY="menu_library"}has(){return this.localStorage.has(i.STORAGE_KEY)}get(){return this.localStorage.get(i.STORAGE_KEY)}save(t){this.localStorage.set(i.STORAGE_KEY,t)}remove(){this.localStorage.remove(i.STORAGE_KEY)}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var gt=(()=>{class i{constructor(){this.userService=c(k),this.librarySwitchStorageService=c(x),this.switchEvent=new N}get switch$(){return this.switchEvent.asObservable()}switch(t){this.librarySwitchStorageService.save({userId:this.userService.user.id,currentLibrary:t.pid,libraryName:t.name}),this.userService.user.currentLibrary=t.pid,this.switchEvent.emit(t)}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var vt=(()=>{class i{constructor(){this.recordService=c(g)}static{this.resource="libraries"}findByLibrariesPidAndOrderBy$(t,e="name"){return this.query("pid:"+t.join(" OR pid:"),e)}query(t,e="name"){return this.recordService.getRecords(i.resource,t,1,g.MAX_REST_RESULTS_SIZE,void 0,void 0,void 0,e)}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var xi=(()=>{class i{constructor(){this.userService=c(k),this.libraryApiService=c(vt),this.libraryService=c(gt),this.librarySwitchDataStorage=c(x),this.translateService=c(L),this.configService=c(ot),this.httpClient=c(v),this.permissionsService=c(lt),this.libraryKeys=["library","owner_library","owning_library"],this.logoutEvent=new N,this.onChange=new N,this.applicationMenuItems=[]}get logout$(){return this.logoutEvent.asObservable()}get onChange$(){return this.onChange.asObservable()}set appMenuItems(t){this.applicationMenuItems=t}get appMenuItems(){return this.applicationMenuItems}generateMenuLanguages(){let t=[],e=this.translateService.currentLang;return this.configService.languages.map(r=>{t.push({label:this.translateService.instant(`ui_language_${r}`),translateLabel:`ui_language_${r}`,id:`lang-${r}`,styleClass:e===r?"ui:font-bold":"",command:()=>this.httpClient.post("/language",{lang:r}).subscribe(()=>this.translateService.use(r))})}),t=t.sort((r,n)=>r.label.localeCompare(n.label)),t}generateMenuLibrary$(){let{currentLibrary:t}=this.userService.user,e=this.userService.user.patronLibrarian.libraries.map(r=>r.pid);return e.length===0?S(void 0):this.libraryApiService.findByLibrariesPidAndOrderBy$(e).pipe(u(r=>r.hits.total.value>0?r.hits.hits:[]),u(r=>{let n;if(!this.librarySwitchDataStorage.has())n=r.find(o=>o.metadata.pid===t);else{let o=this.librarySwitchDataStorage.get();n=r.find(p=>p.metadata.pid===o.currentLibrary),n||(n=r.find(p=>p.metadata.pid===t))}let a={label:n.metadata.code,icon:"fa fa-random",id:U.LIBRARY_MENU,items:[]};return r.sort((o,p)=>o.metadata.code.localeCompare(p.metadata.code)).map(o=>a.items.push({label:`[${o.metadata.code}] ${o.metadata.name}`,code:o.metadata.code,pid:o.metadata.pid,styleClass:o.metadata.pid===n.metadata.pid?"ui:font-bold":"",command:()=>this.libraryService.switch({pid:o.metadata.pid,code:o.metadata.code,name:o.metadata.name})})),{menu:a,libraryActive:{pid:n.metadata.pid,code:n.metadata.code,name:n.metadata.name}}}))}generateAppMenu(t){let e=this.processMenuApp(t).filter(r=>r);return this.appMenuItems=e,e}updateLibraryLink(t){let e=this.appMenuItems.find(n=>n.id===U.APP.ADMIN.MENU).items.find(n=>n.id===U.APP.ADMIN.MY_LIBRARY),r=[...e.routerLink];r[4]=t.pid,e.routerLink=r,this.updateLibraryQueryParams(t)}updateLibraryQueryParams(t){this.updateQueryParams(this.appMenuItems,t)}logout(){this.logoutEvent.emit(!0)}processMenuApp(t){return t.map(e=>{let r=!0;if(e.access&&(r=this.permissionsService.canAccess(e.access.permissions,e.access.operator||pt.OR)),!!r)return delete e.access,!e.url&&!e.routerLink&&e.items&&(e.items=this.processMenuApp(e.items).filter(n=>n)),e})}updateQueryParams(t,e){return t.map(r=>{r.queryParams&&(r.queryParams=this.processQueryParams(r.queryParams,e)),r.items&&(r.items=this.updateQueryParams(r.items,e))}),t}processQueryParams(t,e){return Object.keys(t).forEach(r=>{this.libraryKeys.includes(r)&&(t[r]=e.pid)}),t}static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();export{U as a,x as b,gt as c,xi as d,l as e,C as f,b as g,_ as h,Et as i,O as j,Ut as k,dt as l,Jt as m,Wt as n,oe as o,B as p,ht as q,_t as r,St as s,mt as t,ft as u,Ie as v,pi as w,ui as x};