@rero/rero-ils-ui
Version:
User interface for RERO integrated library system (RERO ILS).
2 lines (1 loc) • 16.7 kB
JavaScript
import{a as Ce}from"./chunk-JHKYMKED.js";import{a as _e,c as Te}from"./chunk-DWADVSH7.js";import{a as ve,b as ye}from"./chunk-LRFB5ZDQ.js";import{a as $,b as q}from"./chunk-FCC5WNRC.js";import{a as V}from"./chunk-BR2J44KJ.js";import{a as Se}from"./chunk-CGU6MK6Q.js";import{R as P,j as T,k as ge}from"./chunk-4GRLSOJZ.js";import{B as pe,Db as me,Eb as G,Ja as I,Oa as de,Tb as B,Wa as L,ec as ue,fc as he,mc as fe,n as ee,o as te,w as ce,x as le}from"./chunk-MTJX6JRK.js";import{a as _,c as k}from"./chunk-GQ5FIRIY.js";import{k as w}from"./chunk-4A4J5SA3.js";import{f as ie,h as oe,m as re,t as ae,x as ne,y as se}from"./chunk-L5BLWZD6.js";import{W as x}from"./chunk-4MYHQLZQ.js";import{ta as Z}from"./chunk-FRI676LD.js";import{Aa as X,Db as N,Fa as F,Hc as J,Vb as S,Vc as K,Xb as v,Z as z,ac as p,bc as c,cc as l,da as U,dc as A,dd as b,ed as R,gb as g,ia as a,kc as C,m as E,oa as h,pa as f,pd as M,r as y,rc as d,sc as u,v as O,w as Y,yb as m,zd as W}from"./chunk-3WD6XLXL.js";var H=(()=>{class o extends de{constructor(){super(...arguments),this.cdr=a(W),this.editorService=a(Ce),this.translateService=a(_),this.route=a(x),this.recordService=a(L),this.messageService=a(Z),this.canDeactivate=!1,this.model={}}importFromExternalSource(e,i){this.editorService.getRecordFromExternal(e,i).subscribe(t=>{t?(this.model=t.metadata,this.cdr.markForCheck()):this.messageService.add({severity:"warn",summary:this.translateService.instant("Import"),detail:this.translateService.instant("Does not exists on the remote server!"),life:I.MESSAGE_LIFE})})}duplicateRecord(e,i){this.recordService.getRecord(e,i).subscribe(t=>{t?(delete t.metadata.pid,delete t.metadata.harvested,this.model=t.metadata,this.cdr.markForCheck(),this.messageService.add({severity:"success",summary:this.translateService.instant("Duplicate"),detail:this.translateService.instant("Document duplicated"),life:I.MESSAGE_LIFE})):this.messageService.add({severity:"warn",summary:this.translateService.instant("Duplicate"),detail:this.translateService.instant("This document does not exists!"),life:I.MESSAGE_LIFE})})}loadingChanged(e){e===!1&&Y([this.route.params,this.route.queryParams]).subscribe(([i,t])=>{t.pid&&(t.source&&t.source!=="templates"&&this.importFromExternalSource(t.source,t.pid),t.type&&this.duplicateRecord(t.type,t.pid))})}static{this.\u0275fac=(()=>{let e;return function(t){return(e||(e=F(o)))(t||o)}})()}static{this.\u0275cmp=m({type:o,selectors:[["admin-document-editor"]],features:[N],decls:1,vars:1,consts:[[3,"loadingChange","canDeactivateChange","model"]],template:function(i,t){i&1&&(c(0,"ng-core-editor",0),d("loadingChange",function(s){return t.loadingChanged(s)})("canDeactivateChange",function(s){return t.canDeactivateChanged(s)}),l()),i&2&&p("model",t.model)},dependencies:[fe],encapsulation:2,changeDetection:0})}}return o})();var D=(()=>{class o{constructor(){this.documentApiService=a(ve),this.fieldOptions=[],this.fieldsSearchType={}}static{this.SEARCH_TYPE_CONTAINS="contains"}static{this.SEARCH_TYPE_CONTAINS_PHRASE="phrase"}static{this.OPERATOR_AND="AND"}static{this.OPERATOR_OR="OR"}static{this.OPERATOR_NOT="AND NOT"}load(){return this.fieldData!==void 0?y(void 0):this.documentApiService.getAdvancedSearchConfig().pipe(z(e=>this.process(e)))}getOperators(){return[{label:"and",value:o.OPERATOR_AND},{label:"or",value:o.OPERATOR_OR},{label:"and not",value:o.OPERATOR_NOT}]}fieldMapping(e){if(!this.fieldMappingMap.has(e))throw new SyntaxError(`Field mapping does not exist (${e})`);return this.fieldMappingMap.get(e)}getFieldsConfig(){return this.fieldOptions}getFieldsData(){return this.fieldData}getFieldsSearchType(){return this.fieldsSearchType}generateQueryByModel(e){let i=[],t=this.protectStar(this.fieldMapping(e.field)),n=this.protectTerm(e.term,e.searchType);return i.push(`${t}:${n}`),e.search.forEach(s=>{s.term&&(i.push(s.operator),t=this.protectStar(this.fieldMapping(s.field)),n=this.protectTerm(s.term,s.searchType),i.push(`${t}:${n}`))}),i.join(" ")}process(e){this.fieldData=e.fieldsData;let i=[];e.fieldsConfig.forEach(t=>{t?.options?.search_type&&(this.fieldsSearchType[t.value]=t.options.search_type),i.push([t.value,t.field]),this.fieldOptions.push({label:t.label,value:t.value})}),this.fieldMappingMap=new Map(i)}protectStar(e){return e.replace(/\.\*/g,".\\*")}protectTerm(e,i){return i===o.SEARCH_TYPE_CONTAINS_PHRASE?`"${e.replace(/"/g,'\\"')}"`:`(${e.replace(/\(/g,"\\(").replace(/\)/g,"\\)")})`}static{this.\u0275fac=function(i){return new(i||o)}}static{this.\u0275prov=U({token:o,factory:o.\u0275fac,providedIn:"root"})}}return o})();function be(o,r){if(o&1){let e=C();c(0,"form",1),d("ngSubmit",function(){h(e);let t=u();return f(t.submit())}),A(1,"formly-form",2),c(2,"div",3)(3,"p-button",4),b(4,"translate"),d("onClick",function(){h(e);let t=u();return f(t.clear())}),l(),A(5,"p-button",5),b(6,"translate"),l()()}if(o&2){let e=u();p("formGroup",e.form),g(),p("model",e.model)("fields",e.fieldsConfig)("options",e.options)("form",e.form),g(2),p("label",R(4,8,"Clear")),g(2),p("disabled",!e.form.valid)("label",R(6,10,"Search"))}}var De=(()=>{class o{static{this.LOCALE_STORAGE_NAME="advancedSearch"}static{this.LOCALE_STORAGE_EXPIRED_IN_SECONDS=600}constructor(){this.dynamicDialogRef=a(ee),this.route=a(x),this.localeStorage=a(me),this.translateService=a(_),this.advancedSearchService=a(D),this.formBuilder=a(ce),this.configurationLoaded=X(!1),this.fieldsSearchTypeConfig={},this.form=new oe({}),this.options={},this.fieldsConfig=[],this.fieldHook=(i,t)=>{let n=i.form.get(t);this.initField(i,n.value),n.valueChanges.subscribe(s=>{this.initField(i,s),i.formControl.setValue(null)})},this.fieldSearchTypeHook=(i,t)=>{let n=i.form.get(t);this.initFieldSearchType(i,n.value),n.valueChanges.subscribe(s=>{this.initFieldSearchType(i,s)})};let{q:e}=this.route.snapshot.queryParams;this.initModel(),this.advancedSearchService.load().subscribe(()=>{this.initializeFieldConfig(),this.loadOrResetStorage(e),this.configurationLoaded.set(!0)})}close(){this.dynamicDialogRef.close()}clear(){this.initModel(),this.localeStorage.remove(o.LOCALE_STORAGE_NAME)}submit(){this.localeStorage.set(o.LOCALE_STORAGE_NAME,this.model),this.dynamicDialogRef.close(this.generateQueryByModel(this.model))}initModel(){this.model={field:"title",term:"",searchType:D.SEARCH_TYPE_CONTAINS,search:[{operator:D.OPERATOR_AND,field:"title",term:"",searchType:D.SEARCH_TYPE_CONTAINS}]}}loadOrResetStorage(e){if(this.localeStorage.has(o.LOCALE_STORAGE_NAME))if(this.localeStorage.isExpired(o.LOCALE_STORAGE_NAME,o.LOCALE_STORAGE_EXPIRED_IN_SECONDS))this.localeStorage.remove(o.LOCALE_STORAGE_NAME);else{let i=this.localeStorage.get(o.LOCALE_STORAGE_NAME);e===this.generateQueryByModel(i)?this.model=i:this.localeStorage.remove(o.LOCALE_STORAGE_NAME)}}initField(e,i){Object.keys(this.fieldDataConfig).some(t=>t===i)?(e.props.group=!1,e.props.translated=!1,e.props.minItemsToDisplaySearch=10,e.props.sort=!0,e.props.placeholder=this.translateService.instant("Select\u2026"),e.props.sortOrder="asc",e.props.class="ui:w-full",e.props.styleClass="ui:w-full",e.props.filter=!0,e.props.required=!0,e.type="select",e.props.options.next(this.fieldDataConfig[i])):(e.type="input",e.props.translated=!1,e.props.placeholder=void 0,e.props.class=void 0,e.props.styleClass=void 0),this.formBuilder.build(e)}initFieldSearchType(e,i){if(Object.keys(this.fieldsSearchTypeConfig).some(t=>t===i)){e.props.sort=!1,e.props.disabled=this.fieldsSearchTypeConfig[i].length<2,e.props.options.next(this.fieldsSearchTypeConfig[i]);let t=this.fieldsSearchTypeConfig[i][0].value;(!e.formControl.value||e.formControl.value&&t!==e.formControl.value)&&e.formControl.setValue(t)}}generateQueryByModel(e){return this.advancedSearchService.generateQueryByModel(e)}initializeFieldConfig(){this.fieldDataConfig=this.advancedSearchService.getFieldsData(),this.fieldsSearchTypeConfig=this.advancedSearchService.getFieldsSearchType(),this.fieldsConfig=[{fieldGroupClassName:"ui:grid ui:grid-cols-12 ui:gap-4",fieldGroup:[{fieldGroupClassName:"ui:grid ui:grid-cols-12 ui:gap-4",className:"ui:col-span-11",fieldGroup:[{className:"ui:col-span-6",type:"select",key:"field",props:{sort:!1,hideLabel:!0,hideLabelSelectOption:!0,required:!0,minItemsToDisplaySearch:999,options:this.advancedSearchService.getFieldsConfig(),appendTo:"body"}},{className:"ui:col-span-2",type:"select",key:"searchType",defaultValue:!1,props:{required:!0,hideLabelSelectOption:!0,options:new E([]),appendTo:"body"},hooks:{onInit:e=>this.fieldSearchTypeHook(e,"field")}},{className:"ui:col-span-4",type:"custom-field",key:"term",props:{required:!0,options:new E([]),appendTo:"body"},hooks:{onInit:e=>this.fieldHook(e,"field")}}]}]},{key:"search",type:"repeat",props:{maxItems:4,minItems:1},fieldArray:{fieldGroup:[{fieldGroupClassName:"ui:grid ui:grid-cols-12 ui:gap-4",fieldGroup:[{className:"ui:col-span-2",type:"select",key:"operator",defaultValue:D.OPERATOR_AND,props:{hideLabel:!0,required:!0,options:this.advancedSearchService.getOperators(),appendTo:"body"}},{className:"ui:col-span-4",type:"select",key:"field",props:{sort:!1,hideLabel:!0,hideLabelSelectOption:!0,required:!0,minItemsToDisplaySearch:999,options:this.advancedSearchService.getFieldsConfig(),appendTo:"body"}},{className:"ui:col-span-2",type:"select",key:"searchType",defaultValue:!1,props:{required:!0,hideLabelSelectOption:!0,options:new E([]),appendTo:"body"},hooks:{onInit:e=>this.fieldSearchTypeHook(e,"field")}},{className:"ui:col-span-4",type:"custom-field",key:"term",props:{options:new E([]),appendTo:"body"},hooks:{onInit:e=>this.fieldHook(e,"field")}}]}]}}]}static{this.\u0275fac=function(i){return new(i||o)}}static{this.\u0275cmp=m({type:o,selectors:[["admin-document-advanced-search-form"]],decls:1,vars:1,consts:[[3,"formGroup"],[3,"ngSubmit","formGroup"],[3,"model","fields","options","form"],[1,"ui:flex","ui:gap-1","ui:justify-end","ui:mt-3"],["outlined","",3,"onClick","label"],["type","submit",3,"disabled","label"]],template:function(i,t){i&1&&S(0,be,7,12,"form",0),i&2&&v(t.configurationLoaded()?0:-1)},dependencies:[ne,re,ie,se,ae,pe,le,w,k],encapsulation:2,changeDetection:0})}}return o})();function Re(o,r){if(o&1){let e=C();c(0,"p-button",1),b(1,"translate"),d("onClick",function(){h(e);let t=u();return f(t.openModalBox())}),l()}o&2&&p("label",R(1,1,"Build advanced query"))}var Ee=(()=>{class o{constructor(){this.dialogService=a(te),this.translateService=a(_),this.store=a(B),this.isSimple=M(()=>!this.store.hasFilter("simple","0"))}openModalBox(){let e=this.dialogService.open(De,{modal:!0,width:"60vw",closable:!0,position:"top",header:this.translateService.instant("Build advanced query")});e&&e.onClose.subscribe(i=>{i&&this.store.updateQuery(i)})}static{this.\u0275fac=function(i){return new(i||o)}}static{this.\u0275cmp=m({type:o,selectors:[["admin-document-advanced-search"]],decls:1,vars:1,consts:[["outlined","","icon","fa fa-search","iconPos","right",3,"label"],["outlined","","icon","fa fa-search","iconPos","right",3,"onClick","label"]],template:function(i,t){i&1&&S(0,Re,2,3,"p-button",0),i&2&&v(t.isSimple()?-1:0)},dependencies:[w,k],encapsulation:2,changeDetection:0})}}return o})();function Oe(o,r){if(o&1){let e=C();c(0,"div",1)(1,"a",3),d("click",function(t){h(e);let n=u();return f(n.linkToGlobalDocuments(t))}),J(2," Expand to all organisations "),l()()}}function Fe(o,r){o&1&&A(0,"admin-document-advanced-search",2)}var Ae=(()=>{class o extends he{constructor(){super(...arguments),this.appStore=a(P),this.showLink=M(()=>this.store.total()===0&&this.store.q()&&this.store.aggregationsFilters().some(e=>e.key==="organisation"))}get isAdvancedSearchEnable(){return this.appStore.settings().documentAdvancedSearch&&this.store.hasFilter("simple","0")}linkToGlobalDocuments(e){e.preventDefault(),this.store.updatePage(1),this.store.removeFilter("organisation")}static{this.\u0275fac=(()=>{let e;return function(t){return(e||(e=F(o)))(t||o)}})()}static{this.\u0275cmp=m({type:o,selectors:[["admin-document-record-search"]],features:[K([B]),N],decls:3,vars:2,consts:[[1,"core:my-1"],[1,"ui:my-6"],["afterInputSearch",""],["href","#","translate","",3,"click"]],template:function(i,t){i&1&&(c(0,"ng-core-record-search",0),S(1,Oe,3,0,"div",1),S(2,Fe,1,0,"admin-document-advanced-search",2),l()),i&2&&(g(),v(t.showLink()?1:-1),g(),v(t.isAdvancedSearchEnable?2:-1))},dependencies:[ue,Ee],encapsulation:2,changeDetection:0})}}return o})();var It=()=>new Q().getTypesForOrg(),Lt=[{path:"",component:Ae,title:"Documents",canActivate:[V],data:{permissions:[T.DOC_ACCESS,T.DOC_SEARCH],operator:ge.AND}},{path:"detail/:pid",component:Te,title:"Document",canActivate:[q],data:{action:$.READ}},{path:"edit/:pid",component:H,title:"Document",canActivate:[q],canDeactivate:[G],data:{action:$.UPDATE}},{path:"new",component:H,title:"Document",canActivate:[V],canDeactivate:[G],data:{permissions:[T.DOC_CREATE]}},{path:"duplicate",component:H,title:"Document",canActivate:[V],canDeactivate:[G],data:{permissions:[T.DOC_CREATE]}}],Q=class extends Se{constructor(){super(...arguments),this.recordService=a(L),this.appStore=a(P),this.name="documents",this.recordType="documents"}getTypesForOrg(){let e=[{key:this.name,label:"Documents",editorSettings:{longMode:!0,template:{recordType:"templates",loadFromTemplate:!0,saveAsTemplate:!0}},component:ye,detailComponent:_e,searchFilters:[this.expertSearchFilter(),{label:"Search in full text",filter:"fulltext",value:"true",showIfQuery:!0},{label:"Show only:",filters:[{label:"Online resources",filter:"online",value:"true",showIfQuery:!0},{label:"Physical resources",filter:"not_online",value:"true",showIfQuery:!0}]}],canAdd:()=>y({can:this.routeToolService.appStore.canAccess(T.DOC_CREATE),message:""}),permissions:t=>this.routeToolService.permissions(t,this.recordType),processBucketName:t=>this.processBucketName(t),processFilterName:t=>this.processFilterName(t),preprocessRecordEditor:t=>(t=this.removeKey(t,"_text"),t=this.removeKey(t,"_draft"),t),postprocessRecordEditor:t=>(t.contribution&&t.contribution.map(n=>{n.entity.$ref&&n.entity.type&&delete n.entity.type}),t),aggregationsName:{online:"Online resources",not_online:"Physical resources",organisation:"Library",genreForm:"Genre, form",intendedAudience:"Intended audience",year:"Publication year",subject:"Subject",fiction_statement:"Fiction statement",acquisition:"Acquisition date"},showFacetsIfNoResults:!0,allowEmptySearch:!1,aggregationsOrder:["document_type","fiction_statement","organisation","language","year","author","subject","genreForm","intendedAudience","acquisition","status"],aggregationsExpand:()=>{let t=["document_type","fiction_statement"],{queryParams:n}=this.routeToolService.activatedRoute.snapshot;return(n.location||n.library)&&t.push("organisation"),t},aggregationsBucketSize:10,itemHeaders:{Accept:"application/rero+json, application/json"},listHeaders:{Accept:"application/rero+json, application/json"},sortOptions:[{label:"Relevance",value:"bestmatch",defaultQuery:!0},{label:"Date (newest)",value:"pub_date_new"},{label:"Date (oldest)",value:"pub_date_old"},{label:"Title",value:"title"}]},{key:"holdings",deleteMessage:()=>[this.routeToolService.translateService.instant("Do you really want to delete this record?"),this.routeToolService.translateService.instant("This will also delete all items and issues of the holdings.")],hideInTabs:!0},{key:"templates",preCreateRecord:t=>this._addDefaultValuesForTemplate(t),redirectUrl:t=>this.redirectUrl(t.metadata,"/records/templates/detail"),hideInTabs:!0}],i=this.appStore.organisation()?.pid;return i&&(e[0].defaultSearchInputFilters=[{key:"organisation",values:[i]}]),e}processFilterName(r){if(r.name)return y(r.name);switch(r.aggregationKey){case"language":return this.routeToolService.translateService.stream(`lang_${r.key}`);case"library":return this.recordService.getRecord("libraries",r.key).pipe(O(e=>e.metadata.name));case"location":return this.recordService.getRecord("locations",r.key).pipe(O(e=>e.metadata.name));case"organisation":return this.recordService.getRecord("organisations",r.key).pipe(O(e=>e.metadata.name));default:return this.routeToolService.translateService.stream(r.key)}}processBucketName(r){return r.name?y(r.name):r.aggregationKey==="language"?this.routeToolService.translateService.stream(`lang_${r.key}`):this.routeToolService.translateService.stream(r.key)}_addDefaultValuesForTemplate(r){return Object.hasOwn(r,"visibility")||(r.visibility="private"),r.organisation={$ref:this.routeToolService.apiService.getRefEndpoint("organisations",this.appStore.currentOrganisationPid())},r.creator={$ref:this.routeToolService.apiService.getRefEndpoint("patrons",this.appStore.user().patronLibrarian.pid)},r}};export{It as a,Lt as b};