@sankhyalabs/sankhyablocks 10.1.0-dev.1 → 10.1.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{ConfigStorage-5a73e979.js → ConfigStorage-b29e31be.js} +2 -2
- package/dist/cjs/{DataFetcher-eeb3b0b7.js → DataFetcher-ed9d97ea.js} +1 -1
- package/dist/cjs/{ISave-861e9d6d.js → ISave-81eb2fbc.js} +4 -4
- package/dist/cjs/{SnkFormConfigManager-8d4fded8.js → SnkFormConfigManager-6838389c.js} +2 -2
- package/dist/cjs/{SnkMultiSelectionListDataSource-3b93f6a6.js → SnkMultiSelectionListDataSource-1e804147.js} +4 -4
- package/dist/cjs/{auth-fetcher-8d8acd69.js → auth-fetcher-cc28d847.js} +1 -1
- package/dist/cjs/{dataunit-fetcher-1cea0695.js → dataunit-fetcher-ab1cc071.js} +1 -1
- package/dist/cjs/{form-config-fetcher-f347f884.js → form-config-fetcher-f0897eb5.js} +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/pesquisa-grid_2.cjs.entry.js +4 -4
- package/dist/cjs/sankhyablocks.cjs.js +1 -1
- package/dist/cjs/snk-actions-button_9.cjs.entry.js +14 -7
- package/dist/cjs/snk-application.cjs.entry.js +81 -69
- package/dist/cjs/snk-attach.cjs.entry.js +5 -5
- package/dist/cjs/snk-crud.cjs.entry.js +90 -6
- package/dist/cjs/snk-data-exporter.cjs.entry.js +5 -5
- package/dist/cjs/{snk-data-unit-de248308.js → snk-data-unit-68992932.js} +2 -2
- package/dist/cjs/snk-data-unit.cjs.entry.js +3 -3
- package/dist/cjs/snk-detail-view.cjs.entry.js +7 -7
- package/dist/cjs/snk-filter-bar_4.cjs.entry.js +3 -3
- package/dist/cjs/snk-filter-modal-item.cjs.entry.js +3 -3
- package/dist/cjs/snk-form-view.cjs.entry.js +2 -6
- package/dist/cjs/snk-form_2.cjs.entry.js +4 -4
- package/dist/cjs/snk-grid.cjs.entry.js +8 -7
- package/dist/cjs/{snk-guides-viewer-4ec3e7e1.js → snk-guides-viewer-8b841753.js} +6 -6
- package/dist/cjs/snk-guides-viewer.cjs.entry.js +7 -7
- package/dist/cjs/snk-personalized-filter.cjs.entry.js +3 -3
- package/dist/cjs/snk-pesquisa.cjs.entry.js +17 -5
- package/dist/cjs/snk-simple-crud.cjs.entry.js +7 -7
- package/dist/cjs/snk-taskbar.cjs.entry.js +8 -4
- package/dist/collection/components/snk-application/search-strategy/exec-prepared-search-advaced-mode.js +27 -0
- package/dist/collection/components/snk-application/search-strategy/exec-prepared-search-plus.js +5 -25
- package/dist/collection/components/snk-application/snk-application.js +87 -44
- package/dist/collection/components/snk-crud/snk-crud.js +106 -2
- package/dist/collection/components/snk-crud/subcomponents/snk-form-view.js +2 -6
- package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.js +1 -1
- package/dist/collection/components/snk-grid/snk-grid.js +20 -1
- package/dist/collection/components/snk-layout-form-config/snk-layout-form-config.js +9 -2
- package/dist/collection/components/snk-pesquisa/snk-pesquisa.css +5 -1
- package/dist/collection/components/snk-pesquisa/snk-pesquisa.js +47 -0
- package/dist/collection/components/snk-taskbar/snk-taskbar.js +29 -4
- package/dist/collection/lib/http/data-fetcher/fetchers/pesquisa-fetcher.js +3 -3
- package/dist/collection/lib/message/resources/pt-br/snk-pesquisa.msg.js +1 -1
- package/dist/components/DataFetcher.js +1 -1
- package/dist/components/ISave.js +3 -3
- package/dist/components/snk-application2.js +76 -63
- package/dist/components/snk-crud.js +88 -1
- package/dist/components/snk-detail-view2.js +1 -1
- package/dist/components/snk-form-view2.js +2 -6
- package/dist/components/snk-grid2.js +3 -1
- package/dist/components/snk-layout-form-config2.js +9 -2
- package/dist/components/snk-pesquisa2.js +15 -2
- package/dist/components/snk-taskbar2.js +9 -4
- package/dist/esm/{ConfigStorage-568dc227.js → ConfigStorage-13d80e36.js} +2 -2
- package/dist/esm/{DataFetcher-743feb3b.js → DataFetcher-f4ccd9f3.js} +1 -1
- package/dist/esm/{ISave-345481c1.js → ISave-288fa9df.js} +4 -4
- package/dist/esm/{SnkFormConfigManager-d61df0c8.js → SnkFormConfigManager-3ee2937b.js} +2 -2
- package/dist/esm/{SnkMultiSelectionListDataSource-ca8d7a09.js → SnkMultiSelectionListDataSource-5d3a93f2.js} +4 -4
- package/dist/esm/{auth-fetcher-c353127d.js → auth-fetcher-59ab0c67.js} +1 -1
- package/dist/esm/{dataunit-fetcher-7f2c61ca.js → dataunit-fetcher-c4f9f222.js} +1 -1
- package/dist/esm/{form-config-fetcher-898d2dd1.js → form-config-fetcher-6a00fe9e.js} +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/pesquisa-grid_2.entry.js +4 -4
- package/dist/esm/sankhyablocks.js +1 -1
- package/dist/esm/snk-actions-button_9.entry.js +14 -7
- package/dist/esm/snk-application.entry.js +81 -69
- package/dist/esm/snk-attach.entry.js +5 -5
- package/dist/esm/snk-crud.entry.js +90 -6
- package/dist/esm/snk-data-exporter.entry.js +5 -5
- package/dist/esm/{snk-data-unit-60b338c5.js → snk-data-unit-0edeb967.js} +2 -2
- package/dist/esm/snk-data-unit.entry.js +3 -3
- package/dist/esm/snk-detail-view.entry.js +7 -7
- package/dist/esm/snk-filter-bar_4.entry.js +3 -3
- package/dist/esm/snk-filter-modal-item.entry.js +3 -3
- package/dist/esm/snk-form-view.entry.js +2 -6
- package/dist/esm/snk-form_2.entry.js +4 -4
- package/dist/esm/snk-grid.entry.js +8 -7
- package/dist/esm/{snk-guides-viewer-339e10b3.js → snk-guides-viewer-9cd4d20f.js} +6 -6
- package/dist/esm/snk-guides-viewer.entry.js +7 -7
- package/dist/esm/snk-personalized-filter.entry.js +3 -3
- package/dist/esm/snk-pesquisa.entry.js +17 -5
- package/dist/esm/snk-simple-crud.entry.js +7 -7
- package/dist/esm/snk-taskbar.entry.js +8 -4
- package/dist/sankhyablocks/{p-9fe91526.js → p-0e279e7a.js} +1 -1
- package/dist/sankhyablocks/{p-9b6d4950.entry.js → p-1858c023.entry.js} +1 -1
- package/dist/sankhyablocks/{p-1d585081.js → p-1c2971e4.js} +1 -1
- package/dist/sankhyablocks/{p-27005fac.entry.js → p-26e0f63c.entry.js} +1 -1
- package/dist/sankhyablocks/{p-bb0de89c.entry.js → p-34df7eca.entry.js} +1 -1
- package/dist/sankhyablocks/p-34f447ba.entry.js +1 -0
- package/dist/sankhyablocks/{p-bd203e8d.entry.js → p-38e56b68.entry.js} +1 -1
- package/dist/sankhyablocks/{p-1649f51e.entry.js → p-3abeeefa.entry.js} +1 -1
- package/dist/sankhyablocks/{p-144da1d1.entry.js → p-3d021bef.entry.js} +1 -1
- package/dist/sankhyablocks/{p-e64958ba.entry.js → p-44939a0e.entry.js} +1 -1
- package/dist/sankhyablocks/{p-88ed2793.js → p-5304753a.js} +2 -2
- package/dist/sankhyablocks/{p-e8c49c12.js → p-53599b26.js} +2 -2
- package/dist/sankhyablocks/p-557368df.entry.js +1 -0
- package/dist/sankhyablocks/p-583151c5.entry.js +1 -0
- package/dist/sankhyablocks/{p-1f8cb438.entry.js → p-6180de07.entry.js} +1 -1
- package/dist/sankhyablocks/{p-1788d191.js → p-78ff8734.js} +1 -1
- package/dist/sankhyablocks/{p-e6b1c769.entry.js → p-80014119.entry.js} +1 -1
- package/dist/sankhyablocks/{p-af9d79e0.entry.js → p-8a88690f.entry.js} +1 -1
- package/dist/sankhyablocks/{p-7fc46290.js → p-9317942f.js} +1 -1
- package/dist/sankhyablocks/p-a2ed1ebd.entry.js +1 -0
- package/dist/sankhyablocks/{p-0cf9aa38.js → p-a644a956.js} +1 -1
- package/dist/sankhyablocks/p-ae108ffd.entry.js +11 -0
- package/dist/sankhyablocks/{p-9f2cdaab.entry.js → p-b4322b87.entry.js} +1 -1
- package/dist/sankhyablocks/p-b7e891cc.entry.js +1 -0
- package/dist/sankhyablocks/{p-6d241415.js → p-bb2f5f38.js} +1 -1
- package/dist/sankhyablocks/{p-626b7a17.js → p-d9c54991.js} +1 -1
- package/dist/sankhyablocks/{p-c90f337a.entry.js → p-e9021f79.entry.js} +1 -1
- package/dist/sankhyablocks/{p-59b8f277.js → p-f15478a1.js} +1 -1
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/dist/types/components/snk-application/search-strategy/exec-prepared-search-advaced-mode.d.ts +5 -0
- package/dist/types/components/snk-application/snk-application.d.ts +9 -0
- package/dist/types/components/snk-crud/snk-crud.d.ts +12 -0
- package/dist/types/components/snk-grid/snk-grid.d.ts +4 -0
- package/dist/types/components/snk-layout-form-config/snk-layout-form-config.d.ts +2 -2
- package/dist/types/components/snk-pesquisa/snk-pesquisa.d.ts +9 -0
- package/dist/types/components/snk-taskbar/snk-taskbar.d.ts +6 -1
- package/dist/types/components.d.ts +39 -0
- package/dist/types/lib/http/data-fetcher/fetchers/pesquisa-fetcher.d.ts +1 -0
- package/package.json +1 -1
- package/dist/sankhyablocks/p-2c86cfab.entry.js +0 -1
- package/dist/sankhyablocks/p-4759912d.entry.js +0 -1
- package/dist/sankhyablocks/p-56948f00.entry.js +0 -11
- package/dist/sankhyablocks/p-95c71f5e.entry.js +0 -1
- package/dist/sankhyablocks/p-aae4258d.entry.js +0 -1
- package/dist/sankhyablocks/p-f25c50f7.entry.js +0 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import{ObjectUtils as t,DataUnit as e,DataUnitInMemoryLoader as n,ApplicationContext as r,StringUtils as a,UserInterface as i,DataUnitStorage as o,DataType as s,ChangeOperation as c}from"@sankhyalabs/core";import{D as l,S as u,d}from"./p-6d241415.js";import{DISTINCT_FILTER_NAME_PREFIX as m}from"@sankhyalabs/ezui/dist/collection/utils/constants";import{DataUnitTransient as h}from"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{ColumnFilterManager as f}from"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import p from"@sankhyalabs/core/dist/utils/SortingUtils";import{R as g}from"./p-688dcb4c.js";class _{constructor(t){this._list=[],this._listCopy=[],this._listLastUpdate=0,this._listCopyLastUpdate=0,this._equalsFunction=t}async load(t,e,n,r){let a=[].concat(this._list);null!=t&&(a=this._list.filter((e=>t(e)))),null!=e&&(a=a.sort(e));const i=a.length;if(null!=r){const t=n||0;a=a.slice(t,r?t+r:a.length)}return Promise.resolve({result:a,count:i})}async distict(t){const e=[];let n=!1;for(const r of this._list){const a=t(r);null!=a&&(null!=a.value?e.push(a):n=!0)}return n&&e.push({key:"",value:null}),Promise.resolve(new Map(e.map((t=>[t.key,t.value]))))}async push(t){this.updateList([...this._list,...t])}async clear(){this.updateList([])}async delete(t){const e=this._list.filter((e=>{for(const n of t)if(this._equalsFunction(e,n))return!1;return!0}));this.updateList(e)}async update(t){const e=this._list.map((e=>{const n=t.find((t=>this._equalsFunction(e,t)));return null==n?e:n}));this.updateList(e)}async insert(t,e){const n=this._list.indexOf(t);if(-1==n)return void this.push(e);const r=this._list.slice(0,n).concat(e).concat(this._list.slice(n));this.updateList(r)}isOperating(){return!0}async isEmpty(){return Promise.resolve(0===this._list.length)}async count(){return Promise.resolve(this._list.length)}getFromCache(){return this._listLastUpdate>this._listCopyLastUpdate&&(this._listCopyLastUpdate=this._listLastUpdate,this._listCopy=t.copy(this._list)),this._listCopy}updateList(t){this._list=t,this._listLastUpdate=Date.now()}}class v{static setLoadingStatus(t,e){this._loadingStatus.set(t.name,e)}static isCacheEnabled(t){return!0}static cacheRecords(t,e,n,r){v.setLoadingStatus(t,r),v.isCacheEnabled(t)?this.getRepository(t).push(e):n&&this._repositories.delete(t.name)}static getSortingFunction(t,e){return p.getSortingFunction(t,e)}static async getDistinct(t,e,n=!1){if(!v.isCacheEnabled(t))return Promise.resolve(f.compileDistinct(e,t));let r;const a=t.getLastLoadRequest();if(null!=a){const n=f.getColumnFilters(a.filters,e);r=f.getFilterFunction(t,Array.from(n.values()))}return new Promise(((a,i)=>{v.getRepository(t).distict((a=>{if(null!=r&&!r(a))return;const i=a[e];if(null==i)return{key:null,value:null};let o=null!=i.value?i.value:i;return(null==i?void 0:i.label)&&n?{key:null==i?void 0:i.label,value:t.getFormattedValue(e,o)}:{key:t.getFormattedValue(e,i),value:o}})).then((t=>{a(null!=t?Array.from(t.entries()).map((([t,e])=>({label:t,value:e,check:!0}))):void 0)})).catch((t=>i(t)))}))}static async loadData(t,n,r){try{if(v.isCacheEnabled(t)){if(["EZ_GRID_LOADING_SOURCE",e.CHANGING_PAGE_LOADING_SOURCE,e.ALL_RECORDS_SELECTION_SOURCE].includes(n.source)&&!await v.getRepository(t).isEmpty())return v.loadFromCache(t,n);v.getRepository(t).clear().catch((()=>{}))}return r(t,n)}catch(t){return console.error(t),Promise.reject(t)}}static insertRecords(t,e,n){v.isCacheEnabled(t)&&v.getRepository(t).insert(e,n)}static updateRecords(t,e){v.isCacheEnabled(t)&&v.getRepository(t).update(e)}static removeRecords(t,e){v.isCacheEnabled(t)&&v.getRepository(t).delete(e)}static async countRecords(t){return v.isCacheEnabled(t)?v.getRepository(t).count():Promise.resolve(0)}static getRepository(t){const e=t.name;return v._repositories.has(e)||v._repositories.set(e,new _(((t,e)=>t.__record__id__===e.__record__id__))),v._repositories.get(e)}static async loadFromCache(t,e){return new Promise(((n,r)=>{const a=f.getColumnFilters(e.filters,""),{limit:i,offset:o,sort:s}=e;v.getRepository(t).load(f.getFilterFunction(t,Array.from(a.values())),v.getSortingFunction(t,s),o,i).then((e=>{const r=v._loadingStatus.get(t.name),{count:a,result:s}=e,c=0==a?0:o+1,l=o+Math.min(s.length,i);n({records:s,paginationInfo:{count:a,currentPage:o/i,firstRecord:c,lastRecord:l,hasMore:r||l<a,total:r?void 0:a}})})).catch((t=>r(t)))}))}static getCachedRecords(t){return v.getRepository(t).getFromCache()}}v._repositories=new Map,v._loadingStatus=new Map;class b{constructor(t,e,r){this._dataUnitInMemoryLoader=new n(t,e,r)}get dataUnit(){return this._dataUnitInMemoryLoader.dataUnit}get records(){return this._dataUnitInMemoryLoader.records}set records(t){this._dataUnitInMemoryLoader.records=t}get metadata(){return this._dataUnitInMemoryLoader.metadata}set metadata(t){this._dataUnitInMemoryLoader.metadata=t}removeLoader(t,e){return this._dataUnitInMemoryLoader.removeLoader(t,e)}static getConvertedValue(t,e,r){return n.getConvertedValue(t,e,r)}}function y(t,e){var n,r;return void 0!==(null===(n=t[e])||void 0===n?void 0:n.value)?null===(r=t[e])||void 0===r?void 0:r.value:t[e]}b.IN_MEMORY_DATA_UNIT_NAME=n.IN_MEMORY_DATA_UNIT_NAME;class D{canSlice(){return!1}processSortingSide(t,e,n){var r;const a=[],o=[];if(null!=t.sort){if(0===n.length)return{localSorting:t.sort,serverSorting:[]};for(const n of t.sort){const t=e.getField(n.field);"true"===(null===(r=null==t?void 0:t.properties)||void 0===r?void 0:r.calculated)||(null==t?void 0:t.userInterface)===i.LONGTEXT?a.push(n):o.push(n)}}return{localSorting:a,serverSorting:o}}async load(t,e,n){var r,a;if(null==t.metadata)return Promise.resolve({records:[],loadingInfo:n});try{const i=null!==(a=null===(r=e.filters)||void 0===r?void 0:r.filter((t=>!t.name.startsWith("FILTRO_COLUNA_"))))&&void 0!==a?a:[],{localSorting:o,serverSorting:s}=this.processSortingSide(e,t,i),c=this.getFieldsList(t),u="DatasetSP.loadRecords",d=this.buildRequestBody(u,c,t,e,n,s,i),m=n.quiet?{urlParams:{quietMode:"true"}}:void 0,{result:h,pagerID:f,askRowsLimit:p}=await l.get().callServiceBroker(u,d,m),g=this.processRecords(t,c,h),_=null!=f,v=n.count+g.length,b=t.hasNewRecord(),y=o.length>0,D=!_&&y;return D&&b&&t.setWaitingToReload(!0),Promise.resolve({records:g,loadingInfo:Object.assign(Object.assign({},n),{pagerId:f,loadingInProgress:_,total:_?void 0:v,count:v,needReload:D&&!b,askRowsLimit:p,hasLocalSorting:y})})}catch(t){return console.error(t),Promise.reject(t)}}async loadRowMetadata(t,e,n,r={}){try{const a="DatasetSP.loadRowMetadata",i=await this.buildRequestBodyLoadRowMetadata({snkDataUnit:t,fieldName:e,metadataName:n,serviceName:a,updatedFields:r});return await l.get().callServiceBroker(a,i)}catch(t){return console.error(t),Promise.reject(t)}}async buildRequestBodyLoadRowMetadata({snkDataUnit:t,serviceName:e,fieldName:n,metadataName:r,updatedFields:a}){const i=t.dataUnit,o=O.parseDataUnitName(i.name).entityName,s=(await t.getSelectedRecordsIDsInfo()).reduce(((t,e)=>(t[e.name]=e.value,t)),{}),c=i.getSelectedRecord(),l=i.metadata.fields.filter((({standAlone:t,name:e})=>!t&&!e.includes("."))).map((({name:t})=>t)),u=l.reduce(((t,e,n)=>{const r=y(c,e),i=y(a,e);return t[n]=void 0!==i?i:r,t}),{});return JSON.stringify({serviceName:e,requestBody:{dataSetID:i.dataUnitId,entityName:o,standAlone:!1,metadataName:r,fieldName:n,fields:l,record:{pk:s,oldPk:s,values:u}}})}getFieldsList(t){let e=["__record__id__","__record__label__"];return t.metadata.fields.forEach((t=>{t.standAlone||(e=e.concat(this.getFieldNames(t)))})),e}getStandAloneFieldsList(t){let e={};return t.metadata.fields.forEach((t=>{t.standAlone&&(e=Object.assign(Object.assign({},e),{[t.name]:{fieldType:t.dataType,userType:t.userInterface}}))})),e}getFieldNames(t){const e=this.getSearchDescriptionField(t);return null==e?t.name:[t.name,e]}buildRequestBody(t,e,n,r,a,i,o){const s=n.dataUnitId,c=O.parseDataUnitName(n.name).entityName,l=!(!r.limit&&!r.offset),u={serviceName:t,requestBody:{dataSetID:s,fields:e,entityName:c,pageNumber:a.pageNumber,totalRecordsCount:a.count,pagerID:a.pagerId,standAlone:!1,standAloneFieldsMD:Object.assign({__record__id__:{fieldType:"S",userType:"P"},__record__label__:{fieldType:"S",userType:"P"}},this.getStandAloneFieldsList(n)),tryJoinedFields:!0,parallelLoader:l,crudListener:`br.com.sankhya.bff.${this.getModuleName()}.BFFDataUnitDatasetAdapter`,txProperties:this.getTxProperties(n,r,i,o),useDefaultRowsLimit:!1}};return JSON.stringify(u)}getModuleName(){return r.getContextValue("__SNK__APPLICATION__").getModuleName().replace("-bff","")}getTxProperties(t,e,n,r){const a={"__DATA_UNIT_ADAPTER__[dataUnitName]":t.name};0!==r.length&&(a["__DATA_UNIT_ADAPTER__[criteria]"]=JSON.stringify(r)),null!=n&&0!==n.length&&(a["__DATA_UNIT_ADAPTER__[sorting]"]=JSON.stringify(n)),null!=e.parentRecordId&&(a["__DATA_UNIT_ADAPTER__[parentRecordId]"]=e.parentRecordId);const i=t.getGlobalLoaderProps();return null==i||0===i.size||Array.from(i.entries()).forEach((([t,e])=>{a[t]=e})),a}processRecords(t,e,n){return n.map((n=>{const r={__record__id__:n[0],__record__label__:n[1],__record__metadata__:n[n.length-1]._rmd};return t.metadata.fields.forEach((t=>{r[t.name]=this.buildFieldValue(t,e,n)})),r}))}buildFieldValue(t,e,n){const r=e.indexOf(t.name);if(r<0)return null;const o=n[r];if(a.isEmpty(o))return null;const s=this.getSearchDescriptionField(t);if(null!=s){const t=e.indexOf(s);if(t>=0)return{value:o,label:n[t]}}return t.userInterface===i.SEARCH?isNaN(Number(o))?o:Number(o):b.getConvertedValue(t,o)}getSearchDescriptionField(t){if(![i.SEARCH,i.SEARCHPLUS].includes(t.userInterface))return;if(!t.properties)return;const{ENTITYNAME:e,mergedFrom:n,DESCRIPTIONFIELD:r}=t.properties;return a.isEmpty(r)?void 0:null!=n?`${n}.${e}.${r}`:`${e}.${r}`}}var P;!function(t){t.CANCEL="CANCEL",t.CONTINUE="CONTINUE",t.LOAD_ALL="LOAD_ALL"}(P||(P={}));class R{constructor(){}static async debounce(t,e){const n=t.name;R._debouncingTimeouts[n]&&(clearTimeout(R._debouncingTimeouts[n]),delete R._debouncingTimeouts[n]),R._debouncingTimeouts[n]=setTimeout((()=>{delete R._debouncingTimeouts[n],e()}),100)}static async loadData(t,e){return new Promise(((n,r)=>{R.debounce(t,(()=>{v.loadData(t,e,this.loadFromServer).then((t=>n(t))).catch((t=>r(t)))}))}))}static getCachedRecords(t){return v.getCachedRecords(t)}static async loadFromServer(t,e,n){try{n=R.registryLoading(t,n);const r=await R.callLoader(t,e,n);if(null==r)return;const a=r.records,i=R.buildPaginationInfo(a.length,e,r.loadingInfo),o=null==i?a:a.slice(0,i.lastRecord);return Promise.resolve({records:o,paginationInfo:i})}catch(t){return console.error(t),Promise.reject(t)}}static async callLoader(t,e,n,r){null==r&&(r=new D);const a=await r.load(t,e,n),i=a.loadingInfo;if(R.isOldRequest(t,i))return Promise.resolve(void 0);if(this.handleCache(r,i,t,a.records),t.cancelPagination)return this.handlePaginationCanceled(t,a);if(this.canFinishPagination(t,i))return Promise.resolve(a);const o=Object.assign(Object.assign({},e),{offset:i.count});let s=this.buildNewLoadingInfo(i);if(this.canProceedPagination(i))return this.recallLoader(t,o,s,r,a);const c=await async function(){return new Promise((t=>{const e=new u,{checkboxContainer:n,checkbox:r}=function(t){const e=document.createElement("div");e.style.marginBottom="14px",e.style.display="flex",e.style.alignItems="center";const{checkbox:n,checkboxLabel:r}=function(t){const e=document.createElement("input");e.type="checkbox",e.id="loadAll";const n=document.createElement("label");return n.htmlFor="loadAll",n.textContent=null==t?void 0:t.getMessage("dataUnitDataLoaderHelper.checkbox.loadAll"),n.style.marginLeft="5px",{checkbox:e,checkboxLabel:n}}(t);return e.appendChild(n),e.appendChild(r),{checkboxContainer:e,checkbox:n}}(e),a=function(t,e,n){const r=document.createElement("ez-popup");return r.opened=!0,r.size="x-small",r.ezTitle=null==n?void 0:n.getMessage("dataUnitDataLoaderHelper.pagination.title"),r.heightMode="auto",r.addEventListener("ezClosePopup",(()=>{document.body.removeChild(r),t(e.checked?P.LOAD_ALL:P.CONTINUE)}),{once:!0}),r.addEventListener("ezPopupAction",(()=>{document.body.removeChild(r),t(P.CANCEL)}),{once:!0}),r}(t,r,e),i=function(){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.fontFamily="var(--font-pattern, Roboto)",t.style.fontSize="var(--text--medium)",t}(),o=function(){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="row",t.style.justifyContent="end",t.style.gap="5px",t}();i.appendChild(n),i.appendChild(function(t){const e=document.createElement("div"),n=document.createElement("p"),r=document.createElement("p"),a=document.createElement("p");return a.style.fontWeight="var(--text-weight--large, 600)",n.textContent=null==t?void 0:t.getMessage("dataUnitDataLoaderHelper.pagination.line1"),r.textContent=null==t?void 0:t.getMessage("dataUnitDataLoaderHelper.pagination.line2"),a.textContent=null==t?void 0:t.getMessage("dataUnitDataLoaderHelper.pagination.line3"),e.appendChild(n),e.appendChild(r),e.appendChild(a),e}(e)),o.appendChild(function(t,e,n,r){const a=document.createElement("ez-button");return a.label=null==r?void 0:r.getMessage("dataUnitDataLoaderHelper.buttons.continue"),a.size="medium",a.onclick=()=>{document.body.removeChild(t),n(e.checked?P.LOAD_ALL:P.CONTINUE)},a}(a,r,t,e)),o.appendChild(function(t,e,n){const r=document.createElement("ez-button");return r.label=null==n?void 0:n.getMessage("dataUnitDataLoaderHelper.buttons.cancel"),r.size="medium",r.classList.add("ez-button--primary"),r.onclick=()=>{document.body.removeChild(t),e(P.CANCEL)},r}(a,t,e)),i.appendChild(o),a.appendChild(i),document.body.appendChild(a)}))}();return c===P.CANCEL?this.handlePaginationCanceled(t,a):(c===P.LOAD_ALL&&(s=Object.assign(Object.assign({},s),{loadAllRecords:!0})),s=Object.assign(Object.assign({},s),{lastRowLimitAsked:s.count}),this.recallLoader(t,o,s,r,a))}static buildNewLoadingInfo(t){return Object.assign(Object.assign({},t),{pageNumber:(t.pageNumber||0)+1,quiet:!0})}static handleCache(t,e,n,r){const a=!t.canSlice()||0===e.count;v.cacheRecords(n,r,a,e.loadingInProgress)}static recallLoader(t,e,n,r,a){return this.callLoader(t,e,n,r).then((e=>R.afterLoadingPage(t,e.loadingInfo))).catch((t=>console.error(t))),Promise.resolve(a)}static canFinishPagination(t,e){return!v.isCacheEnabled(t)||!e.loadingInProgress}static canProceedPagination(t){const{count:e,askRowsLimit:n,loadAllRecords:r,lastRowLimitAsked:a}=t;if(r)return!0;if(!e||!n)return!0;const i=Number(n);return e<i||e<i+(a||0)}static handlePaginationCanceled(t,e){t.cancelPagination=!1;let n=e.loadingInfo;return n=Object.assign(Object.assign({},n),{total:n.count,loadingInProgress:!1,pagerId:void 0,needReload:n.hasLocalSorting}),Promise.resolve({records:e.records,loadingInfo:n})}static afterLoadingPage(t,e){v.setLoadingStatus(t,e.loadingInProgress);const n=t.getPaginationInfo();if(null==n)return;const r=e.count;e.loadingInProgress?t.updatePagination(Object.assign(Object.assign({},n),{count:r,loadingInProgress:!0})):e.needReload?t.gotoPage(0):t.updatePagination(Object.assign(Object.assign({},n),{total:r,count:r,loadingInProgress:!1}))}static registryLoading(t,e){return null==e&&(e={requestTime:(new Date).getTime(),count:0}),R._requestTimeByDataUnit.set(t.name,e.requestTime),e}static isOldRequest(t,e){return R._requestTimeByDataUnit.get(t.name)>e.requestTime}static buildPaginationInfo(t,e,n){let{limit:r,offset:a}=e;if(!r)return;1===n.pageNumber&&(a=0);const{total:i,count:o,loadingInProgress:s,askRowsLimit:c}=n,l=0===o||0===t?0:a+1,u=a+Math.min(t,r);return{total:i,count:o,lastRecord:u,firstRecord:l,currentPage:a/r,hasMore:u<o||s,askRowsLimit:c}}}R._requestTimeByDataUnit=new Map,R._debouncingTimeouts={};const N=/dd:\/\/([^/]+)\/([^/?]+)/;class O{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchDataUnit",d.gql`query($name: String!) {
|
1
|
+
import{ObjectUtils as t,DataUnit as e,DataUnitInMemoryLoader as n,ApplicationContext as r,StringUtils as a,UserInterface as i,DataUnitStorage as o,DataType as s,ChangeOperation as c}from"@sankhyalabs/core";import{D as l,S as u,d}from"./p-bb2f5f38.js";import{DISTINCT_FILTER_NAME_PREFIX as m}from"@sankhyalabs/ezui/dist/collection/utils/constants";import{DataUnitTransient as h}from"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{ColumnFilterManager as f}from"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import p from"@sankhyalabs/core/dist/utils/SortingUtils";import{R as g}from"./p-688dcb4c.js";class _{constructor(t){this._list=[],this._listCopy=[],this._listLastUpdate=0,this._listCopyLastUpdate=0,this._equalsFunction=t}async load(t,e,n,r){let a=[].concat(this._list);null!=t&&(a=this._list.filter((e=>t(e)))),null!=e&&(a=a.sort(e));const i=a.length;if(null!=r){const t=n||0;a=a.slice(t,r?t+r:a.length)}return Promise.resolve({result:a,count:i})}async distict(t){const e=[];let n=!1;for(const r of this._list){const a=t(r);null!=a&&(null!=a.value?e.push(a):n=!0)}return n&&e.push({key:"",value:null}),Promise.resolve(new Map(e.map((t=>[t.key,t.value]))))}async push(t){this.updateList([...this._list,...t])}async clear(){this.updateList([])}async delete(t){const e=this._list.filter((e=>{for(const n of t)if(this._equalsFunction(e,n))return!1;return!0}));this.updateList(e)}async update(t){const e=this._list.map((e=>{const n=t.find((t=>this._equalsFunction(e,t)));return null==n?e:n}));this.updateList(e)}async insert(t,e){const n=this._list.indexOf(t);if(-1==n)return void this.push(e);const r=this._list.slice(0,n).concat(e).concat(this._list.slice(n));this.updateList(r)}isOperating(){return!0}async isEmpty(){return Promise.resolve(0===this._list.length)}async count(){return Promise.resolve(this._list.length)}getFromCache(){return this._listLastUpdate>this._listCopyLastUpdate&&(this._listCopyLastUpdate=this._listLastUpdate,this._listCopy=t.copy(this._list)),this._listCopy}updateList(t){this._list=t,this._listLastUpdate=Date.now()}}class b{static setLoadingStatus(t,e){this._loadingStatus.set(t.name,e)}static isCacheEnabled(t){return!0}static cacheRecords(t,e,n,r){b.setLoadingStatus(t,r),b.isCacheEnabled(t)?this.getRepository(t).push(e):n&&this._repositories.delete(t.name)}static getSortingFunction(t,e){return p.getSortingFunction(t,e)}static async getDistinct(t,e,n=!1){if(!b.isCacheEnabled(t))return Promise.resolve(f.compileDistinct(e,t));let r;const a=t.getLastLoadRequest();if(null!=a){const n=f.getColumnFilters(a.filters,e);r=f.getFilterFunction(t,Array.from(n.values()))}return new Promise(((a,i)=>{b.getRepository(t).distict((a=>{if(null!=r&&!r(a))return;const i=a[e];if(null==i)return{key:null,value:null};let o=null!=i.value?i.value:i;return(null==i?void 0:i.label)&&n?{key:null==i?void 0:i.label,value:t.getFormattedValue(e,o)}:{key:t.getFormattedValue(e,i),value:o}})).then((t=>{a(null!=t?Array.from(t.entries()).map((([t,e])=>({label:t,value:e,check:!0}))):void 0)})).catch((t=>i(t)))}))}static async loadData(t,n,r){try{if(b.isCacheEnabled(t)){if(["EZ_GRID_LOADING_SOURCE",e.CHANGING_PAGE_LOADING_SOURCE,e.ALL_RECORDS_SELECTION_SOURCE].includes(n.source)&&!await b.getRepository(t).isEmpty())return b.loadFromCache(t,n);b.getRepository(t).clear().catch((()=>{}))}return r(t,n)}catch(t){return console.error(t),Promise.reject(t)}}static insertRecords(t,e,n){b.isCacheEnabled(t)&&b.getRepository(t).insert(e,n)}static updateRecords(t,e){b.isCacheEnabled(t)&&b.getRepository(t).update(e)}static removeRecords(t,e){b.isCacheEnabled(t)&&b.getRepository(t).delete(e)}static async countRecords(t){return b.isCacheEnabled(t)?b.getRepository(t).count():Promise.resolve(0)}static getRepository(t){const e=t.name;return b._repositories.has(e)||b._repositories.set(e,new _(((t,e)=>t.__record__id__===e.__record__id__))),b._repositories.get(e)}static async loadFromCache(t,e){return new Promise(((n,r)=>{const a=f.getColumnFilters(e.filters,""),{limit:i,offset:o,sort:s}=e;b.getRepository(t).load(f.getFilterFunction(t,Array.from(a.values())),b.getSortingFunction(t,s),o,i).then((e=>{const r=b._loadingStatus.get(t.name),{count:a,result:s}=e,c=0==a?0:o+1,l=o+Math.min(s.length,i);n({records:s,paginationInfo:{count:a,currentPage:o/i,firstRecord:c,lastRecord:l,hasMore:r||l<a,total:r?void 0:a}})})).catch((t=>r(t)))}))}static getCachedRecords(t){return b.getRepository(t).getFromCache()}}b._repositories=new Map,b._loadingStatus=new Map;class v{constructor(t,e,r){this._dataUnitInMemoryLoader=new n(t,e,r)}get dataUnit(){return this._dataUnitInMemoryLoader.dataUnit}get records(){return this._dataUnitInMemoryLoader.records}set records(t){this._dataUnitInMemoryLoader.records=t}get metadata(){return this._dataUnitInMemoryLoader.metadata}set metadata(t){this._dataUnitInMemoryLoader.metadata=t}removeLoader(t,e){return this._dataUnitInMemoryLoader.removeLoader(t,e)}static getConvertedValue(t,e,r){return n.getConvertedValue(t,e,r)}}function y(t,e){var n,r;return void 0!==(null===(n=t[e])||void 0===n?void 0:n.value)?null===(r=t[e])||void 0===r?void 0:r.value:t[e]}v.IN_MEMORY_DATA_UNIT_NAME=n.IN_MEMORY_DATA_UNIT_NAME;class D{canSlice(){return!1}processSortingSide(t,e,n){var r;const a=[],o=[];if(null!=t.sort){if(0===n.length)return{localSorting:t.sort,serverSorting:[]};for(const n of t.sort){const t=e.getField(n.field);"true"===(null===(r=null==t?void 0:t.properties)||void 0===r?void 0:r.calculated)||(null==t?void 0:t.userInterface)===i.LONGTEXT?a.push(n):o.push(n)}}return{localSorting:a,serverSorting:o}}async load(t,e,n){var r,a;if(null==t.metadata)return Promise.resolve({records:[],loadingInfo:n});try{const i=null!==(a=null===(r=e.filters)||void 0===r?void 0:r.filter((t=>!t.name.startsWith("FILTRO_COLUNA_"))))&&void 0!==a?a:[],{localSorting:o,serverSorting:s}=this.processSortingSide(e,t,i),c=this.getFieldsList(t),u="DatasetSP.loadRecords",d=this.buildRequestBody(u,c,t,e,n,s,i),m=n.quiet?{urlParams:{quietMode:"true"}}:void 0,{result:h,pagerID:f,askRowsLimit:p}=await l.get().callServiceBroker(u,d,m),g=this.processRecords(t,c,h),_=null!=f,b=n.count+g.length,v=t.hasNewRecord(),y=o.length>0,D=!_&&y;return D&&v&&t.setWaitingToReload(!0),Promise.resolve({records:g,loadingInfo:Object.assign(Object.assign({},n),{pagerId:f,loadingInProgress:_,total:_?void 0:b,count:b,needReload:D&&!v,askRowsLimit:p,hasLocalSorting:y})})}catch(t){return console.error(t),Promise.reject(t)}}async loadRowMetadata(t,e,n,r={}){try{const a="DatasetSP.loadRowMetadata",i=await this.buildRequestBodyLoadRowMetadata({snkDataUnit:t,fieldName:e,metadataName:n,serviceName:a,updatedFields:r});return await l.get().callServiceBroker(a,i)}catch(t){return console.error(t),Promise.reject(t)}}async buildRequestBodyLoadRowMetadata({snkDataUnit:t,serviceName:e,fieldName:n,metadataName:r,updatedFields:a}){const i=t.dataUnit,o=O.parseDataUnitName(i.name).entityName,s=(await t.getSelectedRecordsIDsInfo()).reduce(((t,e)=>(t[e.name]=e.value,t)),{}),c=i.getSelectedRecord(),l=i.metadata.fields.filter((({standAlone:t,name:e})=>!t&&!e.includes("."))).map((({name:t})=>t)),u=l.reduce(((t,e,n)=>{const r=y(c,e),i=y(a,e);return t[n]=void 0!==i?i:r,t}),{});return JSON.stringify({serviceName:e,requestBody:{dataSetID:i.dataUnitId,entityName:o,standAlone:!1,metadataName:r,fieldName:n,fields:l,record:{pk:s,oldPk:s,values:u}}})}getFieldsList(t){let e=["__record__id__","__record__label__"];return t.metadata.fields.forEach((t=>{t.standAlone||(e=e.concat(this.getFieldNames(t)))})),e}getStandAloneFieldsList(t){let e={};return t.metadata.fields.forEach((t=>{t.standAlone&&(e=Object.assign(Object.assign({},e),{[t.name]:{fieldType:t.dataType,userType:t.userInterface}}))})),e}getFieldNames(t){const e=this.getSearchDescriptionField(t);return null==e?t.name:[t.name,e]}buildRequestBody(t,e,n,r,a,i,o){const s=n.dataUnitId,c=O.parseDataUnitName(n.name).entityName,l=!(!r.limit&&!r.offset),u={serviceName:t,requestBody:{dataSetID:s,fields:e,entityName:c,pageNumber:a.pageNumber,totalRecordsCount:a.count,pagerID:a.pagerId,standAlone:!1,standAloneFieldsMD:Object.assign({__record__id__:{fieldType:"S",userType:"P"},__record__label__:{fieldType:"S",userType:"P"}},this.getStandAloneFieldsList(n)),tryJoinedFields:!0,parallelLoader:l,crudListener:`br.com.sankhya.bff.${this.getModuleName()}.BFFDataUnitDatasetAdapter`,txProperties:this.getTxProperties(n,r,i,o),useDefaultRowsLimit:!1}};return JSON.stringify(u)}getModuleName(){return r.getContextValue("__SNK__APPLICATION__").getModuleName().replace("-bff","")}getTxProperties(t,e,n,r){const a={"__DATA_UNIT_ADAPTER__[dataUnitName]":t.name};0!==r.length&&(a["__DATA_UNIT_ADAPTER__[criteria]"]=JSON.stringify(r)),null!=n&&0!==n.length&&(a["__DATA_UNIT_ADAPTER__[sorting]"]=JSON.stringify(n)),null!=e.parentRecordId&&(a["__DATA_UNIT_ADAPTER__[parentRecordId]"]=e.parentRecordId);const i=t.getGlobalLoaderProps();return null==i||0===i.size||Array.from(i.entries()).forEach((([t,e])=>{a[t]=e})),a}processRecords(t,e,n){return n.map((n=>{const r={__record__id__:n[0],__record__label__:n[1],__record__metadata__:n[n.length-1]._rmd};return t.metadata.fields.forEach((t=>{r[t.name]=this.buildFieldValue(t,e,n)})),r}))}buildFieldValue(t,e,n){const r=e.indexOf(t.name);if(r<0)return null;const o=n[r];if(a.isEmpty(o))return null;const s=this.getSearchDescriptionField(t);if(null!=s){const t=e.indexOf(s);if(t>=0)return{value:o,label:n[t]}}return t.userInterface===i.SEARCH?isNaN(Number(o))?o:Number(o):v.getConvertedValue(t,o)}getSearchDescriptionField(t){if(![i.SEARCH,i.SEARCHPLUS].includes(t.userInterface))return;if(!t.properties)return;const{ENTITYNAME:e,mergedFrom:n,DESCRIPTIONFIELD:r}=t.properties;return a.isEmpty(r)?void 0:null!=n?`${n}.${e}.${r}`:`${e}.${r}`}}var P;!function(t){t.CANCEL="CANCEL",t.CONTINUE="CONTINUE",t.LOAD_ALL="LOAD_ALL"}(P||(P={}));class R{constructor(){}static async debounce(t,e){const n=t.name;R._debouncingTimeouts[n]&&(clearTimeout(R._debouncingTimeouts[n]),delete R._debouncingTimeouts[n]),R._debouncingTimeouts[n]=setTimeout((()=>{delete R._debouncingTimeouts[n],e()}),100)}static async loadData(t,e){return new Promise(((n,r)=>{R.debounce(t,(()=>{b.loadData(t,e,this.loadFromServer).then((t=>n(t))).catch((t=>r(t)))}))}))}static getCachedRecords(t){return b.getCachedRecords(t)}static async loadFromServer(t,e,n){try{n=R.registryLoading(t,n);const r=await R.callLoader(t,e,n);if(null==r)return;const a=r.records,i=R.buildPaginationInfo(a.length,e,r.loadingInfo),o=null==i?a:a.slice(0,i.lastRecord);return Promise.resolve({records:o,paginationInfo:i})}catch(t){return console.error(t),Promise.reject(t)}}static async callLoader(t,e,n,r){null==r&&(r=new D);const a=await r.load(t,e,n),i=a.loadingInfo;if(R.isOldRequest(t,i))return Promise.resolve(void 0);if(this.handleCache(r,i,t,a.records),t.cancelPagination)return this.handlePaginationCanceled(t,a);if(this.canFinishPagination(t,i))return Promise.resolve(a);const o=Object.assign(Object.assign({},e),{offset:i.count});let s=this.buildNewLoadingInfo(i);if(this.canProceedPagination(i))return this.recallLoader(t,o,s,r,a);const c=await async function(){return new Promise((t=>{const e=new u,{checkboxContainer:n,checkbox:r}=function(t){const e=document.createElement("div");e.style.marginBottom="14px",e.style.display="flex",e.style.alignItems="center";const{checkbox:n,checkboxLabel:r}=function(t){const e=document.createElement("input");e.type="checkbox",e.id="loadAll";const n=document.createElement("label");return n.htmlFor="loadAll",n.textContent=null==t?void 0:t.getMessage("dataUnitDataLoaderHelper.checkbox.loadAll"),n.style.marginLeft="5px",{checkbox:e,checkboxLabel:n}}(t);return e.appendChild(n),e.appendChild(r),{checkboxContainer:e,checkbox:n}}(e),a=function(t,e,n){const r=document.createElement("ez-popup");return r.opened=!0,r.size="x-small",r.ezTitle=null==n?void 0:n.getMessage("dataUnitDataLoaderHelper.pagination.title"),r.heightMode="auto",r.addEventListener("ezClosePopup",(()=>{document.body.removeChild(r),t(e.checked?P.LOAD_ALL:P.CONTINUE)}),{once:!0}),r.addEventListener("ezPopupAction",(()=>{document.body.removeChild(r),t(P.CANCEL)}),{once:!0}),r}(t,r,e),i=function(){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.fontFamily="var(--font-pattern, Roboto)",t.style.fontSize="var(--text--medium)",t}(),o=function(){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="row",t.style.justifyContent="end",t.style.gap="5px",t}();i.appendChild(n),i.appendChild(function(t){const e=document.createElement("div"),n=document.createElement("p"),r=document.createElement("p"),a=document.createElement("p");return a.style.fontWeight="var(--text-weight--large, 600)",n.textContent=null==t?void 0:t.getMessage("dataUnitDataLoaderHelper.pagination.line1"),r.textContent=null==t?void 0:t.getMessage("dataUnitDataLoaderHelper.pagination.line2"),a.textContent=null==t?void 0:t.getMessage("dataUnitDataLoaderHelper.pagination.line3"),e.appendChild(n),e.appendChild(r),e.appendChild(a),e}(e)),o.appendChild(function(t,e,n,r){const a=document.createElement("ez-button");return a.label=null==r?void 0:r.getMessage("dataUnitDataLoaderHelper.buttons.continue"),a.size="medium",a.onclick=()=>{document.body.removeChild(t),n(e.checked?P.LOAD_ALL:P.CONTINUE)},a}(a,r,t,e)),o.appendChild(function(t,e,n){const r=document.createElement("ez-button");return r.label=null==n?void 0:n.getMessage("dataUnitDataLoaderHelper.buttons.cancel"),r.size="medium",r.classList.add("ez-button--primary"),r.onclick=()=>{document.body.removeChild(t),e(P.CANCEL)},r}(a,t,e)),i.appendChild(o),a.appendChild(i),document.body.appendChild(a)}))}();return c===P.CANCEL?this.handlePaginationCanceled(t,a):(c===P.LOAD_ALL&&(s=Object.assign(Object.assign({},s),{loadAllRecords:!0})),s=Object.assign(Object.assign({},s),{lastRowLimitAsked:s.count}),this.recallLoader(t,o,s,r,a))}static buildNewLoadingInfo(t){return Object.assign(Object.assign({},t),{pageNumber:(t.pageNumber||0)+1,quiet:!0})}static handleCache(t,e,n,r){const a=!t.canSlice()||0===e.count;b.cacheRecords(n,r,a,e.loadingInProgress)}static recallLoader(t,e,n,r,a){return this.callLoader(t,e,n,r).then((e=>R.afterLoadingPage(t,e.loadingInfo))).catch((t=>console.error(t))),Promise.resolve(a)}static canFinishPagination(t,e){return!b.isCacheEnabled(t)||!e.loadingInProgress}static canProceedPagination(t){const{count:e,askRowsLimit:n,loadAllRecords:r,lastRowLimitAsked:a}=t;if(r)return!0;if(!e||!n)return!0;const i=Number(n);return e<i||e<i+(a||0)}static handlePaginationCanceled(t,e){t.cancelPagination=!1;let n=e.loadingInfo;return n=Object.assign(Object.assign({},n),{total:n.count,loadingInProgress:!1,pagerId:void 0,needReload:n.hasLocalSorting}),Promise.resolve({records:e.records,loadingInfo:n})}static afterLoadingPage(t,e){b.setLoadingStatus(t,e.loadingInProgress);const n=t.getPaginationInfo();if(null==n)return;const r=e.count;e.loadingInProgress?t.updatePagination(Object.assign(Object.assign({},n),{count:r,loadingInProgress:!0})):e.needReload?t.gotoPage(0):t.updatePagination(Object.assign(Object.assign({},n),{total:r,count:r,loadingInProgress:!1}))}static registryLoading(t,e){return null==e&&(e={requestTime:(new Date).getTime(),count:0}),R._requestTimeByDataUnit.set(t.name,e.requestTime),e}static isOldRequest(t,e){return R._requestTimeByDataUnit.get(t.name)>e.requestTime}static buildPaginationInfo(t,e,n){let{limit:r,offset:a}=e;if(!r)return;1===n.pageNumber&&(a=0);const{total:i,count:o,loadingInProgress:s,askRowsLimit:c}=n,l=0===o||0===t?0:a+1,u=a+Math.min(t,r);return{total:i,count:o,lastRecord:u,firstRecord:l,currentPage:a/r,hasMore:u<o||s,askRowsLimit:c}}}R._requestTimeByDataUnit=new Map,R._debouncingTimeouts={};const N=/dd:\/\/([^/]+)\/([^/?]+)/;class O{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchDataUnit",d.gql`query($name: String!) {
|
2
2
|
$queryAlias$: fetchDataUnit(name: $name){
|
3
3
|
name
|
4
4
|
fields{
|
@@ -57,4 +57,4 @@ import{ObjectUtils as t,DataUnit as e,DataUnitInMemoryLoader as n,ApplicationCon
|
|
57
57
|
}
|
58
58
|
}`),this.templateByQuery.set("fetchDistinctColumn",d.gql`query($dataUnit: String!, $fieldName: String!, $argument: String, $filters: [InputFilter], $parentRecordId: String) {
|
59
59
|
$queryAlias$: selectDistinct(dataUnit: $dataUnit, fieldName: $fieldName, argument: $argument, filters: $filters, parentRecordId: $parentRecordId)
|
60
|
-
}`)}static parseDataUnitName(t){if(null==t)return;const e=N.exec(t);return e?{entityName:e[1],resourceID:e[2]}:void 0}getDataUnit(t,n,r,a){null==
|
60
|
+
}`)}static parseDataUnitName(t){if(null==t)return;const e=N.exec(t);return e?{entityName:e[1],resourceID:e[2]}:void 0}getDataUnit(t,n,r,a){null==b.applicationResourceID&&g.getResourceID().then((t=>b.applicationResourceID=t));const i=`dd://${t}/${n}${a?"/"+a:""}`,o=null!=r?r.getChildDataunit(i):new e(i);return o.metadataLoader=t=>this.loadMetadata(t),o.dataLoader=(t,e)=>R.loadData(t,e),o.saveLoader=(t,e)=>this.saveData(o,e),o.removeLoader=(t,e)=>this.removeRecords(t,e),o.recordLoader=(t,e)=>this.loadRecord(t,e),o.allRecordsLoader=t=>R.getCachedRecords(t),o}loadMetadata(t){return new Promise(((e,n)=>{l.get().callGraphQL({values:{name:t.name},query:this.templateByQuery.get("fetchDataUnit")}).then((t=>{var n;const r={name:t.name,label:t.name,children:[...t.children],fields:[]};null===(n=t.fields)||void 0===n||n.forEach((t=>{let e;Array.isArray(t.properties)&&(e={},t.calculated&&(e.gridHeaderTooltip="Campos calculados não podem ser ordenados"),t.properties.forEach((t=>e[t.name]=t.value))),r.fields.push(Object.assign(Object.assign({},t),{properties:e}))})),r.fields.sort(((t,e)=>t.order-e.order)),e(r)})).catch((t=>{n(t)}))}))}loadSelectDistinct(t,e,n){const{parentRecordId:r,filters:a}=t.getLastLoadRequest()||{},i=a.filter((t=>t.name!==`${m}${e}`)),o={dataUnit:t.name,argument:n,fieldName:e,parentRecordId:r,filters:i};return new Promise(((t,e)=>{l.get().callGraphQL({values:o,query:this.templateByQuery.get("fetchDistinctColumn")}).then((e=>{t(e)})).catch((t=>{e(t)}))}))}addTransientProperties(t,e){const n=t.getGlobalLoaderProps();return null==n||0===n.size||(null==e&&(e={}),Array.from(n.entries()).forEach((([t,n])=>{e[`transient.${t}`]=n}))),e}getUpdatingFields(t,e){if(null==e)return;const n=Object.assign({},e);return Object.keys(n).forEach((e=>{const r=t.getField(e);null!=r&&r.standAlone&&delete n[e]})),this.addTransientProperties(t,n)}saveData(t,e){const n=[],r=[],a=e.map((e=>{const{dataUnit:a,record:i,operation:l}=e,u=o.get(a),d=this.getUpdatingFields(u,e.updatingFields);let m;null!=d&&(m=Object.entries(d).map((([t,e])=>{const n=u.getField(t);return{fieldName:t,dataType:n?n.dataType:s.TEXT,value:u.valueToString(t,e)}}))),a===t.name&&(l===c.INSERT||l===c.COPY?r.push(i.__record__id__):n.push(i.__record__id__));const h={dataUnit:a,fields:m,operation:l,recordId:i.__record__id__};return e.sourceId&&(h.sourceId=e.sourceId),i.__parent__record__id__&&(h.parentRecordId=i.__parent__record__id__),h}));return new Promise(((e,i)=>{const s=a.map((t=>function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]])}return n}(t,[])));l.get().callGraphQL({values:{changes:s},query:this.templateByQuery.get("saveData")}).then((a=>{const i=[];null==a||a.forEach((e=>{const n={__record__id__:e.id,__record__label__:e.label,__owner__dataunit__name__:e.ownerDataUnitName},r=o.get(n.__owner__dataunit__name__)||t;e.oldId&&(n.__old__id__=e.oldId),e.fields.forEach((({name:t,value:e})=>{var a;const i=null===(a=null==r?void 0:r.valueFromString)||void 0===a?void 0:a.call(r,t,e);n[t]=void 0!==i?i:e})),i.push(n)})),this.updateCache(t,i,n,r),e(i)})).catch((t=>{i(t)}))}))}updateCache(t,e,n,r){const a=new Map(e.map((t=>[t.__old__id__||t.__record__id__,t]))),i=r.map((t=>{const e=Object.assign({},a.get(t));return delete e.__old__id__,e}));i.length>0&&b.insertRecords(t,t.records[0],i);const o=n.map((t=>Object.assign({},a.get(t))));b.updateRecords(t,o)}getTransientInfo(t,e){const{records:n}=t.getSelectionInfo();return Object.entries(n.filter((t=>t.__record__id__==e))[0]).filter((([t])=>t.startsWith(h.DATA_UNIT_TRANSIENT_PREFIX_NAME))).map((([t,e])=>({fieldName:t,value:e,dataType:s.TEXT})))}removeRecords(t,e){const n=e.map((e=>({dataUnit:t.name,operation:c.DELETE,recordId:e,fields:this.getTransientInfo(t,e)})));return new Promise(((r,a)=>{l.get().callGraphQL({values:{changes:n},query:this.templateByQuery.get("saveData")}).then((()=>{b.removeRecords(t,t.records.filter((t=>e.includes(t.__record__id__)))),r(e)})).catch((t=>{a(t)}))}))}loadRecord(t,e){return new Promise(((n,r)=>{l.get().callGraphQL({values:{recordID:e,dataunit:t.name},query:this.templateByQuery.get("fetchDataRecord")}).then((e=>{const r=[];e.record.forEach((e=>{const n={__record__id__:e.id,__record__label__:e.label};e.fields.forEach((({name:e,value:r})=>{n[e]=t.valueFromString(e,r)})),r.push(n)})),n(r)})).catch((t=>{r(t)}))}))}}export{O as D,v as I,b as P,D as a,y as g}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import{UserInterface as e,DataType as t,ApplicationContext as n,ErrorException as i}from"@sankhyalabs/core";import{d as o,D as r}from"./p-
|
1
|
+
import{UserInterface as e,DataType as t,ApplicationContext as n,ErrorException as i}from"@sankhyalabs/core";import{d as o,D as r}from"./p-bb2f5f38.js";function a(e){const t=(n=e.fieldsMetadata)&&n.length?n.map((e=>({name:e.fieldName,label:e.description,dataType:u(e.type),userInterface:l(e),properties:s(e)}))):[];var n;return{label:e.entityDescription,name:e.descriptionField,fields:t}}function s(e){const t={};return t.options=function(e){const t=e.options;if(!t)return;const n=[];return Object.keys(t).forEach((e=>{n.push({label:e,value:t[e]})})),n}(e),t.mask=function(e){const t=e.uiType;return t?String(t).toLowerCase():void 0}(e),t}function l(t){const n=t.options;return n&&Object.keys(n).length>0?e.OPTIONSELECTOR:"D"===t.type?e.DATE:"H"===t.type?e.DATETIME:"T"===t.type?e.TIME:"I"===t.type?e.INTEGERNUMBER:void 0}function u(e){switch(e){case"F":case"I":return t.NUMBER;case"D":case"H":return t.DATE;case"B":return t.OBJECT;default:return t.TEXT}}function c(e){return Object.assign({id:e.codigo,label:`${e.caminho} - ${e.descricao}`,bold:"N"===e.analitico,props:{analitico:"S"===e.analitico}},e.no&&{children:e.no.map(c)})}var d,v,f;!function(e){e[e.GRID=0]="GRID",e[e.CARDS=1]="CARDS",e[e.TREE=2]="TREE"}(d||(d={}));class m{constructor(){this._defaultPageSize=100,this._templateByQuery=new Map,this._searchListenersByDataUnit=new Map,this.buldTemplates()}buldTemplates(){this._templateByQuery.set("search",o.gql`query($entityName: String! $argument: String $criteria: InputSearchCriteria $options: InputSearchOptions) {
|
2
2
|
$queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria options: $options){
|
3
3
|
value
|
4
4
|
label
|
5
5
|
}
|
6
|
-
}`)}loadSearchOptions(e,n,i,o){var a;const s=(null==n?void 0:n.toString().trim())||void 0;n=isNaN(Number(s))&&s?`%${s}`:s,null==i||i.params.forEach((e=>{e.dataType===t.OBJECT&&(e.value=JSON.stringify(e.value))}));const l=this.applySearchListener(v.beforeSearch,e,n,i,o),u={argument:(null==l?void 0:l.argument)||n,entityName:e,criteria:(null==l?void 0:l.criteria)||i,options:(null==l?void 0:l.searchOptions)||o};return u.options&&(null===(a=u.options)||void 0===a||delete a.dataUnitId),new Promise(((e,t)=>{r.get().callGraphQL({values:u,query:this._templateByQuery.get("search")}).then((t=>{e(t)})).catch((e=>{t(e)}))}))}buildDescriptionCacheKey(e,t){return`${e}__${t}`}async loadByCode(e,t,n,i){const o=this.buildDescriptionCacheKey(e,t),r=m.DESCRIPTIONS_BY_CODE[o];if(r)return Promise.resolve(r);const a=await this.loadAdvancedSearch(e,void 0,n,i,t);return m.DESCRIPTIONS_BY_CODE[o]=a,a}loadAdvancedSearch(e,o,a,s,l){var u,c,d,f,m;const
|
6
|
+
}`)}loadSearchOptions(e,n,i,o){var a;const s=(null==n?void 0:n.toString().trim())||void 0;n=isNaN(Number(s))&&s?`%${s}`:s,null==i||i.params.forEach((e=>{e.dataType===t.OBJECT&&(e.value=JSON.stringify(e.value))}));const l=this.applySearchListener(v.beforeSearch,e,n,i,o),u={argument:(null==l?void 0:l.argument)||n,entityName:e,criteria:(null==l?void 0:l.criteria)||i,options:(null==l?void 0:l.searchOptions)||o};return u.options&&(null===(a=u.options)||void 0===a||delete a.dataUnitId),new Promise(((e,t)=>{r.get().callGraphQL({values:u,query:this._templateByQuery.get("search")}).then((t=>{e(t)})).catch((e=>{t(e)}))}))}buildDescriptionCacheKey(e,t){return`${e}__${t}`}async loadByCode(e,t,n,i){const o=this.buildDescriptionCacheKey(e,t),r=m.DESCRIPTIONS_BY_CODE[o];if(r)return Promise.resolve(r);const a=await this.loadAdvancedSearch(e,void 0,n,i,t);return m.DESCRIPTIONS_BY_CODE[o]=a,a}loadAdvancedSearch(e,o,a,s,l){var u,c,d,f,m,p;const h=this.applySearchListener(v.beforeSearch,e,o,a,s),N={argument:(null==h?void 0:h.argument)||o,criteria:(null==h?void 0:h.criteria)||a,searchOptions:Object.assign(Object.assign({},s),null==h?void 0:h.searchOptions)},S={query:{$:null===(u=N.criteria)||void 0===u?void 0:u.expression}};(null===(d=null===(c=N.criteria)||void 0===c?void 0:c.params)||void 0===d?void 0:d.length)>0&&(S.params={param:N.criteria.params.map((e=>{let o=e.value;if("string"==typeof o){const e=/CTX\{([^}]+)\}/.exec(o);e&&(o=n.getContextValue(`__SNK__APPLICATION__FILTER__CONTEXT(${e[1]})__`))}if(e.dataType===t.NUMBER&&void 0===o)throw new i("Falha detectada",`O campo ${e.name} deve ser informado.`);let r=e.dataType;return r===t.OBJECT?(o=o.value,r="S"):r=g(e.dataType),{$:o,type:r}}))});const y=null!=s?Object.assign(Object.assign({},null==N?void 0:N.searchOptions),{pkFieldName:s.codeFieldName,label:s.descriptionFieldName,fieldName:s.codeFieldName,useDescriptionOptions:!1,enableRowsCounter:!0,limit:s.limit}):void 0,O={serviceName:"PesquisaSP.getSuggestion",requestBody:{criteria:Object.assign({entityName:e,compacted:!1,ignoreEntityCriteria:null!==(f=null==y?void 0:y.ignoreEntityCriteria)&&void 0!==f&&f,limit:null!==(m=null==y?void 0:y.limit)&&void 0!==m?m:this._defaultPageSize,orderByDesc:!1,externalCriteria:S,localEntityName:null===(p=N.searchOptions)||void 0===p?void 0:p.rootEntity},{options:y}),clientEventList:{clientEvent:[]}}};null==l?O.requestBody.criteria.query={$:o}:O.requestBody.criteria.pk={$:l};const b={urlParams:{quietMode:!0}};return new Promise(((e,t)=>{r.get().callServiceBroker("PesquisaSP.getSuggestion",JSON.stringify(O),b).then((t=>e(t))).catch((e=>t(e)))}))}addSearchListener(e,t,n){var i;const o=this._searchListenersByDataUnit.get(t)||[],r=o.find((t=>t.entity===e));if(r){for(const e of Object.keys(n))if(e in r.listener){if((null===(i=r.listener[e])||void 0===i?void 0:i.toString())===n[e].toString())continue;r.listener[e]=n[e]}}else this._searchListenersByDataUnit.set(t,[...o,{entity:e,listener:n}]);return()=>{const n=o.filter((t=>t.entity!==e));n.length?this._searchListenersByDataUnit.set(t,n):this._searchListenersByDataUnit.delete(t)}}applySearchListener(e,t,n,i,o){var r;const a=null==o?void 0:o.dataUnitId;if(!a)return;const s=null===(r=this._searchListenersByDataUnit.get(a))||void 0===r?void 0:r.find((({entity:e})=>e===t));if(!s)return;const{listener:l}=s;return e in l?l[e]({argument:n,criteria:i,searchOptions:o}):void 0}async loadPresentationConfig(e){var t,n;let i=function(e){return{config:{chave:`PesquisaContent:${e}`,tipo:"T"}}}(e);const o=await r.get().callServiceBroker("SystemUtilsSP.getConf",JSON.stringify(i));return null!==(n=null===(t=null==o?void 0:o.config)||void 0===t?void 0:t.lastUsedMode)&&void 0!==n?n:"list"}async savePresentationConfig(e,t){let n=function(e,t){return{config:{lastUsedMode:t,chave:`PesquisaContent:${e}`,tipo:"T"}}}(e,t);await r.get().callServiceBroker("SystemUtilsSP.saveConf",JSON.stringify(n))}async loadPesquisaGridConfig(e){const t=function(e){return{gridConfig:{configName:`GrdCfgHtml5:grdcfg.dynaform.pesquisa.${e}`}}}(e);return function(e){var t,n;const i=[],o=null!==(n=null===(t=null==e?void 0:e.gridConfig)||void 0===t?void 0:t.field)&&void 0!==n?n:{};if(Object.keys(o).forEach((e=>i.push(o[e]))),i.length)return{columns:i}}(await r.get().callServiceBroker("GridConfig.getGridConfigFromJson",JSON.stringify(t)))}async savePesquisaGridConfig(e,t){const n=function(e,t){const n={};return null==t||t.forEach(((e,t)=>n[`field${t}`]=e)),{gridConfig:{compactMode:!0,configName:`GrdCfgHtml5:grdcfg.dynaform.pesquisa.${e}`,field:n}}}(e,t);await r.get().callServiceBroker("GridConfig.saveGridConfigFromJSON",JSON.stringify(n))}async loadTree(e,t,n,i){const o=this.buildLoadTreeRequestBody(e,t,n,i);return(null!==(s=null===(a=(await r.get().callServiceBroker("Pesquisa.getStructuredData",JSON.stringify(o))).arvore)||void 0===a?void 0:a.no)&&void 0!==s?s:[]).map(c);var a,s}buildLoadTreeRequestBody(e,t,n,i){var o,r;const a=this.applySearchListener(v.beforeSearch,e,t,n,i),s=null!==(o=null==a?void 0:a.searchOptions)&&void 0!==o?o:i,l=null==s?void 0:s.rootEntity,u=null==s?void 0:s.codeFieldName,c=null===(r=null==a?void 0:a.criteria)||void 0===r?void 0:r.expression,d=this.buildParams(a),f={nome:e,nomeInstanciaLocal:l,codeFieldName:u};return c&&(f.criterioLiteral={expressao:{$:c},parametro:d}),{instancia:f}}buildParams(e){var t,n;let i=null!==(n=null===(t=null==e?void 0:e.criteria)||void 0===t?void 0:t.params)&&void 0!==n?n:[];return i=i.map((e=>Object.assign(Object.assign({},e),{tipo:g(e.dataType),$:e.value}))),i}}function g(e){switch(e){case t.NUMBER:return"I";case t.DATE:return"D";default:return"S"}}m.DESCRIPTIONS_BY_CODE={},function(e){e.beforeSearch="beforeSearch"}(v||(v={})),function(e){e.LINK_AND_FILE_AT_THE_SAME_TIME="LINK_AND_FILE_AT_THE_SAME_TIME",e.ANY_LINK_OR_FILE_FILLED="ANY_LINK_OR_FILE_FILLED",e.UNKNOWN="UNKNOWN",e.DESCRIPTION_CANNOT_BE_CHANGED="DESCRIPTION_CANNOT_BE_CHANGED"}(f||(f={}));export{m as P,f as S,d as a,a as b}
|
@@ -0,0 +1 @@
|
|
1
|
+
import{r as t,c as s,h as i,H as e,g as a}from"./p-d8d8169b.js";import{Action as h,LockManager as n,LockManagerOperation as r,SilentException as o,StringUtils as l,ApplicationContext as d,OVERFLOWED_CLASS_NAME as v,OverflowWatcher as u,OverflowDirection as c,ElementIDUtils as k}from"@sankhyalabs/core";import{A as m}from"./p-dc36cfbf.js";import{T as b,V as p,A as T,b as f,a as g}from"./p-b987e15d.js";import{P as w}from"./p-0f3698af.js";import"./p-55798617.js";const A=class{constructor(i){t(this,i),this.actionClick=s(this,"actionClick",7),this.taskbarSaveLocker=s(this,"taskbarSaveLocker",7),this.taskbarSaveUnlocker=s(this,"taskbarSaveUnlocker",7),this.TASKBAR_ITEM_ID_PREFIX="TASKBAR_ITEM_",this.TASKBAR_CUSTOM_ELEMENTS_CONTAINER_CLASS_NAME="taskbar-custom-elements-container",this.NOT_OVERFLOW_ELEMENTS=["moreOptions","dataExporter_snkDataExporter","actionsButton_snkActionsButton"],this.TASKBAR_CUSTOM_ELEMENTS="taskbar-custom-elements-container",this.TASKBAR_ADDITIONAL_SLOT_CONTAINER_CLASS_NAME="taskbar-additional-slot-container",this.TASKBAR_ADDITIONAL_SLOT="taskbar-additional-slot-container",this._titleKeyByElement={[b.UPDATE_MULTIPLE]:"snkTaskbar.titleUpdateMultiple",[b.UPDATE]:"snkTaskbar.titleUpdate",[b.PREVIOUS]:"snkTaskbar.titlePrevious",[b.NEXT]:"snkTaskbar.titleNext",[b.REFRESH]:"snkTaskbar.titleRefresh",[b.CLONE]:"snkTaskbar.titleClone",[b.REMOVE]:"snkTaskbar.titleRemove",[b.MORE_OPTIONS]:"snkTaskbar.titleMoreOptions",[b.INSERT]:"snkTaskbar.titleInsert",[b.CANCEL]:"snkTaskbar.titleCancel",[b.SAVE]:"snkTaskbar.titleSave",[b.GRID_MODE]:"snkTaskbar.titleGridMode",[b.FORM_MODE]:"snkTaskbar.titleFormMode",[b.CONFIGURATOR]:"snkTaskbar.titleConfigurator",[b.ATTACH]:"snkTaskbar.titleAttach"},this.onSaveEvent=t=>{switch(t.type){case h.FIELD_INVALIDATED:case h.INVALIDATE_CLEAN:case h.DATA_SAVED:case h.SAVING_ERROR:case h.SAVING_CANCELED:this._isWaitingForSave=!1;break;case h.SAVING_DATA:this._isWaitingForSave=!0}},this._permissions=void 0,this._overFlowedElements=[],this._customElements=void 0,this._customElementsId=void 0,this._slotContainer=void 0,this._hiddenActionsList=[],this._lastWidth=void 0,this._hasToUpdateOverFlow=!1,this._isWaitingForSave=!1,this.alignRigth=!1,this.customSlotId="TASKBAR_CUSTOM_ELEMENTS",this.additionalSlotId="TASKBAR_ADDITIONAL_SLOT",this.customContainerId=void 0,this.overflowStrategy="hiddenItems",this.configName=void 0,this.resourceID=void 0,this.buttons=void 0,this.customButtons=void 0,this.actionsList=void 0,this.actionsSettingsList=void 0,this.primaryButton=void 0,this.disabledButtons=void 0,this.dataUnit=void 0,this.presentationMode=w.PRIMARY,this.messagesBuilder=void 0}handleCustomSlotElementsLoaded(t){this.hasToSearchCustomElements(t)&&this.getCustomElements(!0)}handleTaskbarSaveLocker(){!0!==this._isWaitingForSave&&(this._isWaitingForSave=!0)}handleTaskbarSaveUnlocker(){!0===this._isWaitingForSave&&(this._isWaitingForSave=!1)}hasToSearchCustomElements(t){return this.customSlotId===t.detail&&!this._slotContainer}observeButtons(){this._definitions=void 0,requestAnimationFrame((()=>{requestAnimationFrame((()=>{var t;return null===(t=this._overFlowWatcher)||void 0===t?void 0:t.forceUpdate()}))}))}observeDisabledButtons(){var t;null===(t=this._overFlowWatcher)||void 0===t||t.forceUpdate()}observeLastWidth(t,s){0===s&&0!==t&&(this._hasToUpdateOverFlow=!0)}observeIsWaitingForSave(t,s){1==t&&0==s&&this.taskbarSaveLocker.emit(),0==t&&1==s&&this.taskbarSaveUnlocker.emit()}elementsFromString(t){const s=[];return null==t||t.split(",").forEach((t=>{t=t.trim(),(p[t]||this.isAllowed(t))&&s.push(t.trim())})),s}isAllowed(t){return t===T.CONFIGURATOR?!!this._permissions&&(this._permissions.isSup||this._permissions[m.CONFIG_GRID]||this._permissions[m.CONFIG]):!T[t]||!!this._permissions&&(this._permissions.isSup||this._permissions[t])}getTitle(t){var s;let i;return i=this.isAllowed(t)?this._titleKeyByElement[t]:"snkTaskbar.forbidden",i?null===(s=this.messagesBuilder)||void 0===s?void 0:s.getMessage(i,{}):""}elementClick(t){n.whenResolve(this._element,r.TASKBAR_CLICK).then((()=>{if(this.dataUnit)switch(t){case b.PREVIOUS:this.dataUnit.previousRecord();break;case b.NEXT:this.dataUnit.nextRecord();break;case b.REFRESH:this.dataUnit.loadData();break;case b.CLONE:this.dataUnit.copySelected();break;case b.REMOVE:this.dataUnit.removeSelectedRecords();break;case b.INSERT:this.dataUnit.addRecord();break;case b.CANCEL:this.dataUnit.cancelEdition();break;case b.SAVE:this._isWaitingForSave||(this._isWaitingForSave=!0,this.dataUnit.saveData().catch((t=>{if(!(t instanceof o))throw t})).finally((()=>{this._isWaitingForSave=!1})))}this.isEnabled(t)&&this.actionClick.emit(t)}))}isEnabled(t){return!(!this.isAllowed(t)||this.disabledButtons&&this.disabledButtons.includes(t))}validatePresentationMode(){Object.values(w).includes(this.presentationMode)||(this.presentationMode=w.PRIMARY)}getElement(t,s){let i=s===this.primaryButton?"ez-button--primary ":"";t>1&&(i+="ez-padding-left--medium");const e=b[s.toString()],a=this._element.dataset.exporterStoreKey||this.configName;return e?f(s,i,this.getIdElemBtnNative(s),(t=>this.getTitle(t)),(t=>this.elementClick(t)),(t=>this.isEnabled(t)),s!==b.CONFIGURATOR?this.buildDynamicActionsList():this.buildActionsSettingsList(),a,this.presentationMode):g(s,i,this.getIdElemBtnCustom(s),(t=>this.elementClick(t)),(t=>this.isEnabled(t)))}buildDynamicActionsList(){var t;return this._hiddenActionsList.length?[...null!==(t=this.actionsList)&&void 0!==t?t:[],...this._hiddenActionsList]:this.actionsList}buildActionsSettingsList(){return this.actionsSettingsList}getIdElemBtnNative(t){return l.toCamelCase(t)}getIdElemBtnCustom(t){return l.toCamelCase(t.name)}isDivider(t){var s;return void 0!==t&&(null===(s=t.t)||void 0===s?void 0:s["data-taskbar-divider"])}removeEmpty(t){let s;return t.filter((t=>!(null==t||this.isDivider(s)&&this.isDivider(t)||(s=t,0))))}appendCustomElementsInTaskbar(){this._customElementsId.forEach((t=>{const s=t.replace(this.TASKBAR_ITEM_ID_PREFIX,""),i=this._customElements.get(s),e=this._element.querySelector(`#${t}`);e?null==e||e.appendChild(i):this.unlinkCustomElementFromTaskbar(i)}))}addCustomElementContainer(t){var s;const e=`${this.TASKBAR_ITEM_ID_PREFIX}${t}`;return this._customElementsId.includes(e)||(this._customElementsId.push(e),null===(s=this._overFlowWatcher)||void 0===s||s.addNotOverFlowElement(e)),i("span",{class:"ez-padding-left--medium",key:e,id:e})}getCustomElements(t){var s,i;this._customElementsId=[],this._customElements=new Map,this._slotContainer=this.buildSlotContainer(t),Array.from(null!==(i=null===(s=this._slotContainer)||void 0===s?void 0:s.children)&&void 0!==i?i:[]).forEach((t=>this._customElements.set(t.id,t)))}buildSlotContainer(t){let s;if(this.customContainerId){const t=document.querySelector(`#${this.customContainerId}`);s=null==t?void 0:t.querySelector(`#${this.customSlotId}`)}else s=this._element.querySelector(`#${this.customSlotId}`);return t&&!s&&(s=document.querySelector(`#${this.customSlotId}`)),s}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__"),this._application?this._application.getAllAccess(this.resourceID).then((t=>this._permissions=t)):this._permissions={},this.getCustomElements()}componentWillRender(){this.handleDefinitions(),this.validatePresentationMode(),this.updateOverFlowIfNeeded()}handleDefinitions(){null==this._definitions&&this._permissions&&(this._definitions=this.elementsFromString(this.buttons))}updateOverFlowIfNeeded(){this._hasToUpdateOverFlow&&(requestAnimationFrame((()=>{var t;return null===(t=this._overFlowWatcher)||void 0===t?void 0:t.forceUpdate()})),this._hasToUpdateOverFlow=!1)}handleOverFlow(t){const s=t.filter((t=>!this.hasToIgnoreOverFlow(t)));this.resetOverFlowedElements(),this.doOverFlowElements(s)}resetOverFlowedElements(){this._overFlowedElements.forEach((t=>{t.classList.remove(v)})),this._hiddenActionsList=[],this._overFlowedElements=[]}doOverFlowElements(t){t.forEach((t=>{t.classList.add(v),this._overFlowedElements.push(t),this.addItemToActionList(t)}))}addItemToActionList(t){const s=this.getTaskbarElementName(t);if(s&&this.isEnabled(s)&&this.isAllowed(s)){const i={value:s,label:this.getTaskbarElementLabel(t),iconName:this.getTaskbarElementIcon(t)};this._hiddenActionsList.push(i)}}getTaskbarElementName(t){var s;return null!==(s=t.getAttribute("data-taskbar-element"))&&void 0!==s?s:""}getTaskbarElementIcon(t){var s;return null!==(s=t.getAttribute("data-taskbar-icon"))&&void 0!==s?s:""}getTaskbarElementLabel(t){var s;return null!==(s=t.getAttribute("data-taskbar-label"))&&void 0!==s?s:""}hasToIgnoreOverFlow(t){return t.classList.contains(this.TASKBAR_CUSTOM_ELEMENTS_CONTAINER_CLASS_NAME)||t.classList.contains(this.TASKBAR_ADDITIONAL_SLOT_CONTAINER_CLASS_NAME)}handleOverFlowStrategy(){"hiddenItems"===this.overflowStrategy&&(this._overFlowWatcher=new u(this.buildOverFlowWatcherParams()))}buildOverFlowWatcherParams(){return{element:this._element,callback:this.handleOverFlow.bind(this),overFlowDirection:c.HORIZONTAL,notOverFlow:this.NOT_OVERFLOW_ELEMENTS}}componentDidLoad(){k.addIDInfo(this._element,null,{dataUnit:this.dataUnit}),this.handleOverFlowStrategy(),this.dataUnit.subscribe(this.onSaveEvent)}componentDidRender(){this.appendCustomElementsInTaskbar(),this.updateLastWidth()}updateLastWidth(){this._lastWidth=this._element.getBoundingClientRect().width}disconnectedCallback(){var t,s;null===(t=this.dataUnit)||void 0===t||t.unsubscribe(this.onSaveEvent),this.unlinkAllCustomElements(),null===(s=this._overFlowWatcher)||void 0===s||s.destroy()}unlinkAllCustomElements(){var t;null===(t=this._customElementsId)||void 0===t||t.forEach((t=>{const s=t.replace(this.TASKBAR_ITEM_ID_PREFIX,""),i=this._customElements.get(s);this.unlinkCustomElementFromTaskbar(i)}))}unlinkCustomElementFromTaskbar(t){this._slotContainer.appendChild(t)}render(){var t,s;if(void 0===this._definitions)return;let a=0;return i(e,{class:this.getHostClasses()},this.removeEmpty(this._definitions.map((t=>{var s,e;return a++,b[t]?this.getElement(a,b[t]):(null===(s=this.customButtons)||void 0===s?void 0:s.has(t))?this.getElement(a,this.customButtons.get(t)):this._customElements.has(t)?this.addCustomElementContainer(t):(null===(e=this._overFlowWatcher)||void 0===e||e.addNotOverFlowElement(t),i("slot",{name:t}))}))),i("div",{id:this.TASKBAR_CUSTOM_ELEMENTS,class:this.TASKBAR_CUSTOM_ELEMENTS_CONTAINER_CLASS_NAME},i("slot",{name:this.customSlotId}),null===(t=this._overFlowWatcher)||void 0===t?void 0:t.addNotOverFlowElement(this.TASKBAR_CUSTOM_ELEMENTS)),i("div",{id:this.TASKBAR_ADDITIONAL_SLOT,class:this.TASKBAR_ADDITIONAL_SLOT_CONTAINER_CLASS_NAME},i("slot",{name:this.additionalSlotId}),null===(s=this._overFlowWatcher)||void 0===s?void 0:s.addNotOverFlowElement(this.TASKBAR_ADDITIONAL_SLOT)))}getHostClasses(){return"hiddenItems"!==this.overflowStrategy?"no-wrap":"full-width "+(this.alignRigth?"align-right":"")}get _element(){return a(this)}static get watchers(){return{buttons:["observeButtons"],disabledButtons:["observeDisabledButtons"],_lastWidth:["observeLastWidth"],_isWaitingForSave:["observeIsWaitingForSave"]}}};A.style=".sc-snk-taskbar-h{display:flex;flex-wrap:wrap}.no-wrap.sc-snk-taskbar-h{flex-wrap:nowrap}.full-width.sc-snk-taskbar-h{width:100%}.align-right.sc-snk-taskbar-h{justify-content:flex-end}.overflowed.sc-snk-taskbar{display:none}";export{A as snk_taskbar}
|
@@ -0,0 +1 @@
|
|
1
|
+
export{S as snk_guides_viewer}from"./p-0e279e7a.js";import"./p-d8d8169b.js";import"@sankhyalabs/core";import"@sankhyalabs/core/dist/dataunit/DataUnit";import"@sankhyalabs/ezui/dist/collection/utils";import"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-bb2f5f38.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-53599b26.js";import"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"./p-5304753a.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-ff1990ad.js";import"./p-9317942f.js";import"./p-9019a32f.js";import"./p-a644a956.js";import"./p-78ff8734.js";import"./p-b987e15d.js";import"./p-55798617.js";import"./p-1a0caadb.js";
|
@@ -1 +1 @@
|
|
1
|
-
import{r as i,c as t,h as e,F as s,H as n}from"./p-d8d8169b.js";import{StringUtils as l,ObjectUtils as a,ApplicationContext as r,ElementIDUtils as o}from"@sankhyalabs/core";import{P as h}from"./p-988afe78.js";import{P as d,C as c}from"./p-1788d191.js";import{ApplicationUtils as f}from"@sankhyalabs/ezui/dist/collection/utils";import{a as p,D as z}from"./p-84345e7a.js";import{s as u}from"./p-55798617.js";import"./p-ff1990ad.js";import"./p-7fc46290.js";import"./p-6d241415.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const m=class{constructor(e){i(this,e),this.ezCancel=t(this,"ezCancel",7),this.ezSave=t(this,"ezSave",7),this.ezAfterSave=t(this,"ezAfterSave",7),this._personalizedFilterFetcher=new d,this._filterMetadataStorage=new Map,this._dataSourceFetcher={fetchData:async i=>{let t=null==i?void 0:i.uri;if(l.isEmpty(t)&&(t=this.entityUri),!this._filterMetadataStorage.has(t)){const i=await this._personalizedFilterFetcher.loadFields(t);this._filterMetadataStorage.set(t,i)}return this._filterMetadataStorage.get(t)}},this._filterAssistentMode=!0,this._filterAssistent=void 0,this.messagesBuilder=void 0,this.entityUri=void 0,this.filterId=void 0,this.configName=void 0,this.resourceID=void 0,this.isDefaultFilter=!1}async createPersonalizedFilter(){const i={name:"",active:!0,expression:"",parameters:[],assistent:{id:l.generateUUID(),items:[{id:l.generateUUID(),entityName:"",fieldName:"",description:"",fieldLabel:this.getMessage("snkPersonalizedFilter.info.labelDefaultValue"),type:void 0,expression:void 0,operand:void 0,paramVariable:!1,value:void 0,systemConfig:null,userConfig:null}],childrenGroups:[],operand:p.AND}};this.isDefaultFilter&&this.buildDataDefaultFilter(i),this._originalFilterAssistent=a.copy(i),this._filterAssistent=a.copy(i)}loadFilter(i,t){null!=i&&t!=i&&null!=this.resourceID&&(i!==z.id?c.loadPersonalizedFilter(i,this.resourceID,this.configName).then((i=>{const t=this.applyDefaultValues(i);this._filterAssistent=t,this._originalFilterAssistent=a.copy(t),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})):c.loadDefaultFilter(i,this.resourceID,this.configName).then((i=>{const t=this.applyDefaultValues(i);this._filterAssistent=t,this._originalFilterAssistent=a.copy(t),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})))}componentWillLoad(){var i;null==u.get(`filterFieldsDataSource.${this.entityUri}`)&&u.set(`filterFieldsDataSource.${this.entityUri}`,this._dataSourceFetcher),this.messagesBuilder||(this._application=r.getContextValue("__SNK__APPLICATION__"),this.messagesBuilder=null===(i=this._application)||void 0===i?void 0:i.messagesBuilder),this.loadFilter(this.filterId,void 0)}componentDidRender(){var i;null===(i=this._viewStackRef)||void 0===i||i.show(this._filterAssistentMode?0:1),this._elButtonMode&&this._elButtonMode.setAttribute(o.DATA_ELEMENT_ID_ATTRIBUTE_NAME,o.getInternalIDInfo(this._filterAssistentMode?"advancedMode_ezButton":"assistentMode_ezButton"))}buildDataDefaultFilter(i){i.name=z.name,i.id=z.id}getMessage(i,t){return this._application.messagesBuilder.getMessage(i,t)}async saveFilter(){let i;i=this.isDefaultFilter?await c.saveDefaultFilter(this._filterAssistent,this.resourceID,this.configName):await c.savePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName),this._elButtonSave.enabled=!1,f.info(this.getMessage(`snkPersonalizedFilter.${this._filterAssistent.id?"confirmEdit":"confirmSave"}.title`),{iconName:"check"});const t=Object.assign(Object.assign({},i),this._filterAssistent);t.parameters=h.buildVariableParameters(this._filterAssistent.assistent),this._originalFilterAssistent=a.copy(t),this._filterAssistent=a.copy(t),this.ezAfterSave.emit()}removeFilter(){c.removePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName)}hasChangesToSave(){return JSON.stringify(this._filterAssistent)===JSON.stringify(this._originalFilterAssistent)}async handleSave(){if(this._filterAssistentMode){if(!h.validateFields(this._filterAssistent.assistent)||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));this.saveAssistentMode()}else{if(!this._filterAssistent.expression||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));if(!await this.validateExpressionBeforeSaving())return;this.saveAdvancedMode()}}saveAssistentMode(){const{assistent:i,expression:t}=this._filterAssistent,e=i?h.buildGroupExpression(i):t;this._filterAssistent.expression=e,this.ezSave.emit(e),this.saveFilter()}saveAdvancedMode(){this._originalFilterAssistent.expression!==this._filterAssistent.expression&&this._filterAssistent.assistent?f.confirm(this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.description")).then((i=>{i&&this.saveAndTransformToAdvancedMode()})):this._filterAssistent.assistent?this.saveAssistentMode():this.saveAndTransformToAdvancedMode()}saveAndTransformToAdvancedMode(){this._filterAssistent.assistent=void 0,this.ezSave.emit(this._filterAssistent.expression),this.saveFilter()}async validateExpressionBeforeSaving(){const{valid:i,message:t=""}=await this._personalizedFilterFetcher.validatePersonalizedFilter(this.entityUri,this._filterAssistent.expression);return i||this._application.error(this.getMessage("snkPersonalizedFilter.errorValidation.title"),t.replace(/.*Exception: /,"")),i}handleCancel(){if(this.hasChangesToSave())return this.ezCancel.emit();f.confirm(this.getMessage("snkPersonalizedFilter.confirmCancel.title"),this.getMessage("snkPersonalizedFilter.confirmCancel.description")).then((i=>{var t;i&&(this._filterAssistent=a.copy(null!==(t=this._originalFilterAssistent)&&void 0!==t?t:{}),this.ezCancel.emit(),this._elButtonSave.enabled=!1)}))}handleTitleChange(i){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{name:i}),this._elButtonSave.enabled=!this.hasChangesToSave()}applyDefaultValues(i){return this.addLabelToItems(i),this.addFilterGroupCondition(i),i}addFilterGroupCondition(i){i.assistent&&!i.assistent.operand&&(i.assistent.operand=p.AND)}addLabelToItems(i){i.assistent&&i.assistent.items&&i.assistent.items.length>0&&i.assistent.items.forEach((t=>{if(null==t.fieldLabel){const e=(i.parameters||[]).find((i=>i.fieldName===t.fieldName));e&&(t.fieldLabel=e.label)}}))}handleExpressionChangeAdvancedMode(i){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:i}),this._elButtonSave.enabled=!this.hasChangesToSave()}handleChangeFilterAssistentMode(i){this._elButtonSave.enabled=!this.hasChangesToSave(),this._filterAssistent=Object.assign({},i)}selectField(i){if(!("name"in i))return;const t=this.buildExpression(i.entityName,i.name,i.entityPath);this._elAdvancedMode.querySelector("ez-text-area").appendTextToSelection(t)}buildExpression(i,t,e){return e.length>0&&e.shift(),e.length>0?`${e.join("->")}->${t}`:`${i}.${t}`}onAddField(i){this._elAdvancedMode.querySelector("ez-text-area").setFocus(),i.setBlur(),this._elFilterFieldSearch&&this._elFilterFieldSearch.show(i,{horizontalGap:0,verticalGap:12,fromRight:!0})}renderButtonAddField(){if(!this._filterAssistentMode)return e(s,null,e("ez-button",{class:"snk-personalized-filter__button-mode",label:this.getMessage("snkPersonalizedFilter.info.addField"),enabled:!0,onClick:i=>this.onAddField(i.target)},e("ez-icon",{class:"ez-padding-right--small",slot:"leftIcon",iconName:"plus"})),e("snk-filter-field-search",{class:"ez-padding-left--medium",ref:i=>this._elFilterFieldSearch=i,onEzSelectFilterItem:i=>this.selectField(i.detail),fieldsDataSource:this._dataSourceFetcher}))}buildContainerPersonalizedFilter(){return e("ez-view-stack",{ref:i=>this._viewStackRef=i},e("stack-item",null,this._filterAssistentMode&&e("snk-filter-assistent-mode",{filterAssistent:this._filterAssistent,messagesBuilder:this.messagesBuilder,filterId:this.filterId,entityUri:this.entityUri,application:this._application,onEzChangeFilter:i=>this.handleChangeFilterAssistentMode(i.detail),isDefaultFilter:this.isDefaultFilter})),e("stack-item",null,e("snk-filter-advanced-mode",{ref:i=>this._elAdvancedMode=i,filterAssistent:this._filterAssistent,application:this._application,onEzExpressionChange:i=>this.handleExpressionChangeAdvancedMode(i.detail)})))}handleModeChange(){var i,t;if(this._filterAssistentMode)f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.description")).then((i=>{if(i&&(this._filterAssistentMode=!this._filterAssistentMode,!this.hasChangesToSave())){const i=h.buildGroupExpression(this._filterAssistent.assistent);this._filterAssistent.expression=i,this._elButtonSave.enabled=!this.hasChangesToSave()}}));else if((null===(i=this._filterAssistent)||void 0===i?void 0:i.expression)===(null===(t=this._originalFilterAssistent)||void 0===t?void 0:t.expression))this._filterAssistentMode=!this._filterAssistentMode;else{const i=this._filterAssistent.expression,t=h.buildGroupExpression(this._filterAssistent.assistent);i!==t?f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.description")).then((i=>{i&&(this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:t}),this._filterAssistentMode=!this._filterAssistentMode)})):this._filterAssistentMode=!this._filterAssistentMode}}buildTitle(){return this.getMessage(this.isDefaultFilter&&!this.filterId?"snkPersonalizedFilter.info.titleCreateDefault":this.isDefaultFilter&&this.filterId?"snkPersonalizedFilter.info.titleEditDefault":this.filterId?"snkPersonalizedFilter.info.titleEdit":"snkPersonalizedFilter.info.titleAdd")}render(){var i,t,s,l;if((null===(i=this._filterAssistent)||void 0===i?void 0:i.assistent)||!this._filterAssistentMode)return e(n,null,e("div",{class:"snk-personalized-filter"},e("div",null,e("snk-simple-bar",{label:this.buildTitle(),onExit:()=>this.handleCancel()},e("div",{class:"snk-personalized-filter__header-actions",slot:"rightSlot"},e("ez-button",{size:"small",label:this.getMessage("snkPersonalizedFilter.info.labelCancel"),onClick:()=>this.handleCancel()}),e("ez-button",{size:"small",ref:i=>this._elButtonSave=i,enabled:!1,class:"ez-button--primary",label:this.getMessage("snkPersonalizedFilter.info.labelSave"),onClick:this.handleSave.bind(this)})))),e("div",{class:"ez-box ez-margin-bottom--medium ez-box__main"},e("div",{class:"ez-box__container"},e("div",{class:"ez-flex ez-flex--column ez-size-width--full"},e("div",{class:"ez-flex"},e("ez-tooltip",{message:this.getMessage("snkPersonalizedFilter.info.textInputDisabled"),active:this.isDefaultFilter},e("ez-text-input",{class:"ez-padding-right--medium",label:this.getMessage("snkPersonalizedFilter.info.labelNameFilter"),value:null===(t=this._filterAssistent)||void 0===t?void 0:t.name,onEzChange:i=>this.handleTitleChange(i.detail),enabled:!this.isDefaultFilter})),this.renderButtonAddField(),e("ez-button",{ref:i=>this._elButtonMode=i,class:"snk-personalized-filter__button-mode",label:this.getMessage(this._filterAssistentMode?"snkPersonalizedFilter.info.activeModeAdvanced":"snkPersonalizedFilter.info.activeModeAssistent"),onClick:()=>this.handleModeChange(),"data-tooltip":this._filterAssistentMode||(null===(s=this._filterAssistent)||void 0===s?void 0:s.assistent)?void 0:this.getMessage("snkPersonalizedFilter.info.tooltipDisabledAssistentMode"),"data-flow":"bottom",enabled:!this._filterAssistent.name||Boolean(this._filterAssistentMode||(null===(l=this._filterAssistent)||void 0===l?void 0:l.assistent))})),this.buildContainerPersonalizedFilter())))))}static get watchers(){return{filterId:["loadFilter"]}}};m.style=".sc-snk-personalized-filter-h{display:flex;height:100%;padding:var(--space--large, 24px);--snk-personalized-filter--width:100%;--snk-personalized-filter--height:100%;--snk-personalized-filter--background-color-line:var(--color--disable-secondary);--snk-personalized-filter--margin-line:var(--border--radius-medium, 12px)}.snk-personalized-filter.sc-snk-personalized-filter{height:var(--snk-personalized-filter--width);width:var(--snk-personalized-filter--height)}.snk-personalized-filter__header-actions.sc-snk-personalized-filter{display:flex;gap:var(--space--medium)}.snk-personalized-filter__group.sc-snk-personalized-filter{flex:1}.snk-personalized-filter__expression-input--line.sc-snk-personalized-filter{width:100%;height:2px;background-color:var(--snk-personalized-filter--background-color-line);margin-top:var(--snk-personalized-filter--margin-line);margin-bottom:var(--snk-personalized-filter--margin-line)}.ez-box__main.sc-snk-personalized-filter{height:90%}.snk-personalized-filter__button-mode.sc-snk-personalized-filter{height:35px}";export{m as snk_personalized_filter}
|
1
|
+
import{r as i,c as t,h as e,F as s,H as n}from"./p-d8d8169b.js";import{StringUtils as l,ObjectUtils as a,ApplicationContext as r,ElementIDUtils as o}from"@sankhyalabs/core";import{P as h}from"./p-988afe78.js";import{P as d,C as c}from"./p-78ff8734.js";import{ApplicationUtils as f}from"@sankhyalabs/ezui/dist/collection/utils";import{a as p,D as z}from"./p-84345e7a.js";import{s as u}from"./p-55798617.js";import"./p-ff1990ad.js";import"./p-9317942f.js";import"./p-bb2f5f38.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const m=class{constructor(e){i(this,e),this.ezCancel=t(this,"ezCancel",7),this.ezSave=t(this,"ezSave",7),this.ezAfterSave=t(this,"ezAfterSave",7),this._personalizedFilterFetcher=new d,this._filterMetadataStorage=new Map,this._dataSourceFetcher={fetchData:async i=>{let t=null==i?void 0:i.uri;if(l.isEmpty(t)&&(t=this.entityUri),!this._filterMetadataStorage.has(t)){const i=await this._personalizedFilterFetcher.loadFields(t);this._filterMetadataStorage.set(t,i)}return this._filterMetadataStorage.get(t)}},this._filterAssistentMode=!0,this._filterAssistent=void 0,this.messagesBuilder=void 0,this.entityUri=void 0,this.filterId=void 0,this.configName=void 0,this.resourceID=void 0,this.isDefaultFilter=!1}async createPersonalizedFilter(){const i={name:"",active:!0,expression:"",parameters:[],assistent:{id:l.generateUUID(),items:[{id:l.generateUUID(),entityName:"",fieldName:"",description:"",fieldLabel:this.getMessage("snkPersonalizedFilter.info.labelDefaultValue"),type:void 0,expression:void 0,operand:void 0,paramVariable:!1,value:void 0,systemConfig:null,userConfig:null}],childrenGroups:[],operand:p.AND}};this.isDefaultFilter&&this.buildDataDefaultFilter(i),this._originalFilterAssistent=a.copy(i),this._filterAssistent=a.copy(i)}loadFilter(i,t){null!=i&&t!=i&&null!=this.resourceID&&(i!==z.id?c.loadPersonalizedFilter(i,this.resourceID,this.configName).then((i=>{const t=this.applyDefaultValues(i);this._filterAssistent=t,this._originalFilterAssistent=a.copy(t),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})):c.loadDefaultFilter(i,this.resourceID,this.configName).then((i=>{const t=this.applyDefaultValues(i);this._filterAssistent=t,this._originalFilterAssistent=a.copy(t),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})))}componentWillLoad(){var i;null==u.get(`filterFieldsDataSource.${this.entityUri}`)&&u.set(`filterFieldsDataSource.${this.entityUri}`,this._dataSourceFetcher),this.messagesBuilder||(this._application=r.getContextValue("__SNK__APPLICATION__"),this.messagesBuilder=null===(i=this._application)||void 0===i?void 0:i.messagesBuilder),this.loadFilter(this.filterId,void 0)}componentDidRender(){var i;null===(i=this._viewStackRef)||void 0===i||i.show(this._filterAssistentMode?0:1),this._elButtonMode&&this._elButtonMode.setAttribute(o.DATA_ELEMENT_ID_ATTRIBUTE_NAME,o.getInternalIDInfo(this._filterAssistentMode?"advancedMode_ezButton":"assistentMode_ezButton"))}buildDataDefaultFilter(i){i.name=z.name,i.id=z.id}getMessage(i,t){return this._application.messagesBuilder.getMessage(i,t)}async saveFilter(){let i;i=this.isDefaultFilter?await c.saveDefaultFilter(this._filterAssistent,this.resourceID,this.configName):await c.savePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName),this._elButtonSave.enabled=!1,f.info(this.getMessage(`snkPersonalizedFilter.${this._filterAssistent.id?"confirmEdit":"confirmSave"}.title`),{iconName:"check"});const t=Object.assign(Object.assign({},i),this._filterAssistent);t.parameters=h.buildVariableParameters(this._filterAssistent.assistent),this._originalFilterAssistent=a.copy(t),this._filterAssistent=a.copy(t),this.ezAfterSave.emit()}removeFilter(){c.removePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName)}hasChangesToSave(){return JSON.stringify(this._filterAssistent)===JSON.stringify(this._originalFilterAssistent)}async handleSave(){if(this._filterAssistentMode){if(!h.validateFields(this._filterAssistent.assistent)||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));this.saveAssistentMode()}else{if(!this._filterAssistent.expression||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));if(!await this.validateExpressionBeforeSaving())return;this.saveAdvancedMode()}}saveAssistentMode(){const{assistent:i,expression:t}=this._filterAssistent,e=i?h.buildGroupExpression(i):t;this._filterAssistent.expression=e,this.ezSave.emit(e),this.saveFilter()}saveAdvancedMode(){this._originalFilterAssistent.expression!==this._filterAssistent.expression&&this._filterAssistent.assistent?f.confirm(this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.description")).then((i=>{i&&this.saveAndTransformToAdvancedMode()})):this._filterAssistent.assistent?this.saveAssistentMode():this.saveAndTransformToAdvancedMode()}saveAndTransformToAdvancedMode(){this._filterAssistent.assistent=void 0,this.ezSave.emit(this._filterAssistent.expression),this.saveFilter()}async validateExpressionBeforeSaving(){const{valid:i,message:t=""}=await this._personalizedFilterFetcher.validatePersonalizedFilter(this.entityUri,this._filterAssistent.expression);return i||this._application.error(this.getMessage("snkPersonalizedFilter.errorValidation.title"),t.replace(/.*Exception: /,"")),i}handleCancel(){if(this.hasChangesToSave())return this.ezCancel.emit();f.confirm(this.getMessage("snkPersonalizedFilter.confirmCancel.title"),this.getMessage("snkPersonalizedFilter.confirmCancel.description")).then((i=>{var t;i&&(this._filterAssistent=a.copy(null!==(t=this._originalFilterAssistent)&&void 0!==t?t:{}),this.ezCancel.emit(),this._elButtonSave.enabled=!1)}))}handleTitleChange(i){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{name:i}),this._elButtonSave.enabled=!this.hasChangesToSave()}applyDefaultValues(i){return this.addLabelToItems(i),this.addFilterGroupCondition(i),i}addFilterGroupCondition(i){i.assistent&&!i.assistent.operand&&(i.assistent.operand=p.AND)}addLabelToItems(i){i.assistent&&i.assistent.items&&i.assistent.items.length>0&&i.assistent.items.forEach((t=>{if(null==t.fieldLabel){const e=(i.parameters||[]).find((i=>i.fieldName===t.fieldName));e&&(t.fieldLabel=e.label)}}))}handleExpressionChangeAdvancedMode(i){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:i}),this._elButtonSave.enabled=!this.hasChangesToSave()}handleChangeFilterAssistentMode(i){this._elButtonSave.enabled=!this.hasChangesToSave(),this._filterAssistent=Object.assign({},i)}selectField(i){if(!("name"in i))return;const t=this.buildExpression(i.entityName,i.name,i.entityPath);this._elAdvancedMode.querySelector("ez-text-area").appendTextToSelection(t)}buildExpression(i,t,e){return e.length>0&&e.shift(),e.length>0?`${e.join("->")}->${t}`:`${i}.${t}`}onAddField(i){this._elAdvancedMode.querySelector("ez-text-area").setFocus(),i.setBlur(),this._elFilterFieldSearch&&this._elFilterFieldSearch.show(i,{horizontalGap:0,verticalGap:12,fromRight:!0})}renderButtonAddField(){if(!this._filterAssistentMode)return e(s,null,e("ez-button",{class:"snk-personalized-filter__button-mode",label:this.getMessage("snkPersonalizedFilter.info.addField"),enabled:!0,onClick:i=>this.onAddField(i.target)},e("ez-icon",{class:"ez-padding-right--small",slot:"leftIcon",iconName:"plus"})),e("snk-filter-field-search",{class:"ez-padding-left--medium",ref:i=>this._elFilterFieldSearch=i,onEzSelectFilterItem:i=>this.selectField(i.detail),fieldsDataSource:this._dataSourceFetcher}))}buildContainerPersonalizedFilter(){return e("ez-view-stack",{ref:i=>this._viewStackRef=i},e("stack-item",null,this._filterAssistentMode&&e("snk-filter-assistent-mode",{filterAssistent:this._filterAssistent,messagesBuilder:this.messagesBuilder,filterId:this.filterId,entityUri:this.entityUri,application:this._application,onEzChangeFilter:i=>this.handleChangeFilterAssistentMode(i.detail),isDefaultFilter:this.isDefaultFilter})),e("stack-item",null,e("snk-filter-advanced-mode",{ref:i=>this._elAdvancedMode=i,filterAssistent:this._filterAssistent,application:this._application,onEzExpressionChange:i=>this.handleExpressionChangeAdvancedMode(i.detail)})))}handleModeChange(){var i,t;if(this._filterAssistentMode)f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.description")).then((i=>{if(i&&(this._filterAssistentMode=!this._filterAssistentMode,!this.hasChangesToSave())){const i=h.buildGroupExpression(this._filterAssistent.assistent);this._filterAssistent.expression=i,this._elButtonSave.enabled=!this.hasChangesToSave()}}));else if((null===(i=this._filterAssistent)||void 0===i?void 0:i.expression)===(null===(t=this._originalFilterAssistent)||void 0===t?void 0:t.expression))this._filterAssistentMode=!this._filterAssistentMode;else{const i=this._filterAssistent.expression,t=h.buildGroupExpression(this._filterAssistent.assistent);i!==t?f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.description")).then((i=>{i&&(this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:t}),this._filterAssistentMode=!this._filterAssistentMode)})):this._filterAssistentMode=!this._filterAssistentMode}}buildTitle(){return this.getMessage(this.isDefaultFilter&&!this.filterId?"snkPersonalizedFilter.info.titleCreateDefault":this.isDefaultFilter&&this.filterId?"snkPersonalizedFilter.info.titleEditDefault":this.filterId?"snkPersonalizedFilter.info.titleEdit":"snkPersonalizedFilter.info.titleAdd")}render(){var i,t,s,l;if((null===(i=this._filterAssistent)||void 0===i?void 0:i.assistent)||!this._filterAssistentMode)return e(n,null,e("div",{class:"snk-personalized-filter"},e("div",null,e("snk-simple-bar",{label:this.buildTitle(),onExit:()=>this.handleCancel()},e("div",{class:"snk-personalized-filter__header-actions",slot:"rightSlot"},e("ez-button",{size:"small",label:this.getMessage("snkPersonalizedFilter.info.labelCancel"),onClick:()=>this.handleCancel()}),e("ez-button",{size:"small",ref:i=>this._elButtonSave=i,enabled:!1,class:"ez-button--primary",label:this.getMessage("snkPersonalizedFilter.info.labelSave"),onClick:this.handleSave.bind(this)})))),e("div",{class:"ez-box ez-margin-bottom--medium ez-box__main"},e("div",{class:"ez-box__container"},e("div",{class:"ez-flex ez-flex--column ez-size-width--full"},e("div",{class:"ez-flex"},e("ez-tooltip",{message:this.getMessage("snkPersonalizedFilter.info.textInputDisabled"),active:this.isDefaultFilter},e("ez-text-input",{class:"ez-padding-right--medium",label:this.getMessage("snkPersonalizedFilter.info.labelNameFilter"),value:null===(t=this._filterAssistent)||void 0===t?void 0:t.name,onEzChange:i=>this.handleTitleChange(i.detail),enabled:!this.isDefaultFilter})),this.renderButtonAddField(),e("ez-button",{ref:i=>this._elButtonMode=i,class:"snk-personalized-filter__button-mode",label:this.getMessage(this._filterAssistentMode?"snkPersonalizedFilter.info.activeModeAdvanced":"snkPersonalizedFilter.info.activeModeAssistent"),onClick:()=>this.handleModeChange(),"data-tooltip":this._filterAssistentMode||(null===(s=this._filterAssistent)||void 0===s?void 0:s.assistent)?void 0:this.getMessage("snkPersonalizedFilter.info.tooltipDisabledAssistentMode"),"data-flow":"bottom",enabled:!this._filterAssistent.name||Boolean(this._filterAssistentMode||(null===(l=this._filterAssistent)||void 0===l?void 0:l.assistent))})),this.buildContainerPersonalizedFilter())))))}static get watchers(){return{filterId:["loadFilter"]}}};m.style=".sc-snk-personalized-filter-h{display:flex;height:100%;padding:var(--space--large, 24px);--snk-personalized-filter--width:100%;--snk-personalized-filter--height:100%;--snk-personalized-filter--background-color-line:var(--color--disable-secondary);--snk-personalized-filter--margin-line:var(--border--radius-medium, 12px)}.snk-personalized-filter.sc-snk-personalized-filter{height:var(--snk-personalized-filter--width);width:var(--snk-personalized-filter--height)}.snk-personalized-filter__header-actions.sc-snk-personalized-filter{display:flex;gap:var(--space--medium)}.snk-personalized-filter__group.sc-snk-personalized-filter{flex:1}.snk-personalized-filter__expression-input--line.sc-snk-personalized-filter{width:100%;height:2px;background-color:var(--snk-personalized-filter--background-color-line);margin-top:var(--snk-personalized-filter--margin-line);margin-bottom:var(--snk-personalized-filter--margin-line)}.ez-box__main.sc-snk-personalized-filter{height:90%}.snk-personalized-filter__button-mode.sc-snk-personalized-filter{height:35px}";export{m as snk_personalized_filter}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{R as e,F as t}from"./p-
|
1
|
+
import{R as e,F as t}from"./p-9317942f.js";import{D as i,d as s}from"./p-bb2f5f38.js";import{F as r}from"./p-ff1990ad.js";import{ObjectUtils as a}from"@sankhyalabs/core";var n;function l(e,t){if(null==e)return e;if(e instanceof Date)return e.toISOString();if("object"==typeof e){if(e instanceof Array)return e.map((e=>l(r.MULTI_LIST===t?function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(i[s[r]]=e[s[r]])}return i}(e,["label"]):e)));{const i=Object.assign({},e);return Object.keys(e).forEach((s=>{void 0!==e[s]?i[s]=l(e[s],t):delete i[s]})),i}}return e}class o{constructor(){this.DEFAULT_RESOURCE="_default",this.templateByQuery=new Map,this.buildTemplates()}resolveURI(e,t,i){let s="filter-assistent-config://"+e;return t&&(s+="."+t),i&&(s+=this.DEFAULT_RESOURCE),s}resolveLegacyConfigName(e,t){if(!e)return"";let i=`?legacyResourceID=${e}`;return t&&(i+=this.DEFAULT_RESOURCE),i}buildTemplates(){this.templateByQuery.set("fetchFilterFields",s.gql`
|
2
2
|
query($name: String!) {
|
3
3
|
$queryAlias$: fetchFilterFields(name: $name){
|
4
4
|
currentLink {
|
@@ -1 +1 @@
|
|
1
|
-
import{r as t,c as s,h as i,H as e,F as a}from"./p-d8d8169b.js";import{I as o}from"./p-
|
1
|
+
import{r as t,c as s,h as i,H as e,F as a}from"./p-d8d8169b.js";import{I as o}from"./p-5304753a.js";import"./p-bb2f5f38.js";import{P as r}from"./p-53599b26.js";import"@sankhyalabs/core";import"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ff1990ad.js";import"./p-9317942f.js";import"./p-9019a32f.js";import{ApplicationUtils as n}from"@sankhyalabs/ezui/dist/collection/utils";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-8d884fab.js";const h=class{constructor(i){t(this,i),this.pesquisaGridSelectItem=s(this,"pesquisaGridSelectItem",7),this._pesquisaFetcher=new r,this.metadata=void 0,this.dataSource=[],this.pkField=void 0,this.descriptionField=void 0,this.entityName=void 0,this.shouldLoadConfig=!1,this._gridConfig=void 0,this._inMemoryLoader=void 0,this._dataunit=void 0}observeDataSource(t){this._inMemoryLoader&&this._dataunit&&t&&(this._inMemoryLoader.records=[...t])}observeMetadata(){this.initializeDataUnit()}async observeShouldLoadConfig(t){t&&!this._gridConfig&&await this.loadGridConfig()}async loadGridConfig(){this._gridConfig=await this._pesquisaFetcher.loadPesquisaGridConfig(this.entityName)}initializeDataUnit(){var t;this.metadata&&!this._dataunit&&(this._inMemoryLoader=new o(this.metadata,null!==(t=this.dataSource)&&void 0!==t?t:[]),this._dataunit=this._inMemoryLoader.dataUnit,this._dataunit.pageSize=0)}handleDbClick(t){this.pesquisaGridSelectItem.emit({value:t[this.pkField],label:t[this.descriptionField]})}async handleConfigChanged({detail:t}){var s;const i=null!==(s=null==t?void 0:t.columns)&&void 0!==s?s:[];await this._pesquisaFetcher.savePesquisaGridConfig(this.entityName,i)}render(){if(this.metadata&&this._dataunit)return i(e,null,i("ez-grid",{dataUnit:this._dataunit,config:this._gridConfig,mode:"simple",autoFocus:!1,onEzDoubleClick:({detail:t})=>this.handleDbClick(t),onConfigChange:async t=>this.handleConfigChanged(t)}))}static get watchers(){return{dataSource:["observeDataSource"],metadata:["observeMetadata"],shouldLoadConfig:["observeShouldLoadConfig"]}}};h.style=".sc-pesquisa-grid-h{background:var(--background--xlight, #FFF);overflow-x:auto}ez-grid.sc-pesquisa-grid{--ez-grid__container--shadow:none;--ez-grid__header--shadow:none}";const l=class{constructor(i){t(this,i),this.pesquisaTreeSelectItem=s(this,"pesquisaTreeSelectItem",7),this.treeLoader=void 0,this.argument=void 0,this.allowsNonAnalytic=!1,this.shouldLoadTree=!1,this.messagesBuilder=void 0,this.items=[]}async applyFilter(){await this._tree.applyFilter(this.argument)}async observeShouldLoadTree(t){!t||this.items.length>0||await this.loadTree()}async loadTree(){if(!this.shouldLoadTree)return;if(!this.treeLoader||"function"!=typeof this.treeLoader)return;const t=await this.treeLoader((this.argument||"").trim());this.items=[...t]}expandOrCloseAllItems(t,s){return t.map((t=>Object.assign(Object.assign({},t),{expanded:s,children:t.children?this.expandOrCloseAllItems(t.children,s):void 0})))}handleExpandAll(){this.items=[...this.expandOrCloseAllItems(this.items,!0)]}handleCloseAll(){this.items=[...this.expandOrCloseAllItems(this.items,!1)]}handleDbClick(t){var s;if(this.allowsNonAnalytic||(null===(s=t.props)||void 0===s?void 0:s.analitico))this.pesquisaTreeSelectItem.emit({value:t.id,label:t.label});else{const t=this.getMessage("snkPesquisa.tree.errorTitle"),s=this.getMessage("snkPesquisa.tree.nonAnalyticError");n.error(t,s)}}renderEmptyMessage(){return i("div",{class:"ez-flex ez-flex--justify-center ez-flex--align-items-center ez-margin--large ez-text ez-text--xlarge ez-text--secondary"},i("span",null,this.getMessage("snkPesquisa.tree.emptyMessage")))}getMessage(t,s){return this.messagesBuilder.getMessage(t,s)}render(){var t;return i(e,null,(null===(t=this.items)||void 0===t?void 0:t.length)?i(a,null,i("div",{class:"actions-container"},i("ez-button",{size:"small",mode:"icon",class:"ez-margin-right--small",iconName:"show-list",title:this.getMessage("snkPesquisa.tree.expandButton"),onClick:()=>this.handleExpandAll()}),i("ez-button",{size:"small",mode:"icon",iconName:"hide-list",title:this.getMessage("snkPesquisa.tree.collapseButton"),onClick:()=>this.handleCloseAll()})),i("ez-tree",{ref:t=>this._tree=t,onEzDbClickItem:({detail:t})=>this.handleDbClick(t),items:this.items})):this.renderEmptyMessage())}static get watchers(){return{shouldLoadTree:["observeShouldLoadTree"]}}};l.style=".sc-pesquisa-tree-h{--snk-pesquisa--tree__action-container--top:var(--space--sm);--snk-pesquisa--tree__action-container--right:var(--space--small);--snk-pesquisa--tree__min-height:var(--space--extra-large);background:var(--background--xlight, #FFF);position:relative;min-height:var(--snk-pesquisa--tree__min-height);height:100%;display:block;overflow-y:auto}.sc-pesquisa-tree-h:hover .actions-container.sc-pesquisa-tree{display:flex}.actions-container.sc-pesquisa-tree{flex-direction:row;position:absolute;top:var(--snk-pesquisa--tree__action-container--top);right:var(--snk-pesquisa--tree__action-container--right);display:none}";export{h as pesquisa_grid,l as pesquisa_tree}
|
@@ -1 +1 @@
|
|
1
|
-
import{r as i,c as t,h as s,F as e,g as r}from"./p-d8d8169b.js";import{KeyboardManager as a,Action as n,ElementIDUtils as o,ApplicationContext as d,StringUtils as h}from"@sankhyalabs/core";import{SelectionMode as l}from"@sankhyalabs/core/dist/dataunit/DataUnit";import{buildFieldSearch as c}from"@sankhyalabs/ezui/dist/collection/utils";import"./p-6d241415.js";import"./p-e8c49c12.js";import{C as u,S as g,a as m,R as k,b as v,c as p}from"./p-59b8f277.js";import{P as f,E as T}from"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-88ed2793.js";import"./p-ff1990ad.js";import"./p-7fc46290.js";import"./p-9019a32f.js";import{C as b}from"./p-1788d191.js";import{s as C}from"./p-55798617.js";import{g as E}from"./p-7dd49d15.js";import{v as R}from"./p-76e66fd9.js";import{T as O}from"./p-b987e15d.js";import{T as _}from"./p-1a0caadb.js";import"./p-8d884fab.js";import"./p-8f3f2306.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class I extends u{getFilters(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getAppliedFilters()}getOrders(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getSort()}getResourceURI(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.name}getSelectedNumber(){return this.dataUnit.getSelectionInfo().length}getTotalRecords(){var i,t,s;const{total:e}=(null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo())||{};return null!=e?e:null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.records)||void 0===s?void 0:s.length}getSelectedIDs(){return E(this.dataUnit)}getOffset(){return this.getExporterOffset(this.getPaginationInfo())}getPageSize(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.pageSize}getExportLimit(){return 5e3}getRecordID(){var i,t,s;return null===(s=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.records)||void 0===t?void 0:t[0])||void 0===s?void 0:s.__record__id__}getPaginationInfo(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo()}getExporterOffset(i){if(null==i)return;const t=i.firstRecord;return t>0?t-1:t}}const S=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this.componentReady=t(this,"componentReady",7),this._customEditors=new Map,this._customRenders=new Map,this._keyboardManager=new a,this._topTaskbarProcessor=new _({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.singleTaskbar":[],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()],"snkGridTopTaskbar.finish_edition.secondary":[],"snkGridTopTaskbar.finish_edition.singleTaskbar":[]}),this._headerTaskbarProcessor=new _({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.selected":this.getGridHeaderSelectedBtns(),"snkGridHeaderTaskbar.detail.unselected":["REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.singleTaskbar.detail.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","FORM_MODE","CONFIGURATOR","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()]}),this.dataUnitInterceptor={interceptAction:async i=>i.type===n.METADATA_LOADED?await this.interceptMetadataLoaded(i):i.type===n.LOADING_DATA?await this.interceptLoadData(i):i},this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this._showSnkFilterBar=!0,this._enableContinuousInsert=!1,this.columnFilterDataSource=new g,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.configName=void 0,this.filterBarTitle=void 0,this.resourceID=void 0,this.selectionToastConfig=void 0,this.actionsList=void 0,this.isDetail=void 0,this.taskbarManager=void 0,this.statusResolver=void 0,this.multipleSelection=void 0,this.presentationMode=f.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.recordsValidator=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.gridHeaderCustomSlotId="GRID_HEADER_CUSTOM_ELEMENTS",this.topTaskbarCustomSlotId="GRID_TASKBAR_CUSTOM_ELEMENTS",this.disablePersonalizedFilter=void 0,this.gridLegacyConfigName=void 0,this.filterBarLegacyConfigName=void 0,this.autoLoad=void 0,this.autoFocus=!0,this.enableGridInsert=!1,this.outlineMode=!1,this.suppressHorizontalScroll=!1,this.strategyExporter=T.SERVER_SIDE,this.useSearchColumn=!0,this.multipleEditionEnabled=!0,this.paginationCounterMode="auto",this.suppressCheckboxColumn=void 0,this.suppressFilterColumn=!1,this.compact=void 0,this.filterCustomConfig=void 0,this.filterCustomConfigInterceptor=void 0}getGridHeaderSelectedBtns(){const i=[O.UPDATE,O.CLONE,O.REMOVE,O.MORE_OPTIONS,O.DIVIDER,O.ATTACH,O.FORM_MODE,O.CONFIGURATOR,O.REFRESH,O.DATA_EXPORTER,O.ACTIONS_BUTTON];return this.multipleEditionEnabled&&i.unshift(O.UPDATE_MULTIPLE),i}async refreshColumnFilterDataSource(){await this._grid.refreshColumnFilterDataSource()}reloadConfig(){this.loadConfig()}async showConfig(){null!=this._grid&&this.openGridConfig()}async hideConfig(){null!=this._grid&&this.closeGridConfig()}async setConfig(i){this.setGridConfig(i)}async reloadFilterBar(){var i;null===(i=this._snkFilterBar)||void 0===i||i.reload()}async getFilterBar(){return this._snkFilterBar}async addCustomEditor(i,t,s){if(this._grid)return void this._grid.addCustomEditor(i,t,s);const e=new Map(this._customEditors);e.set(i,{customEditor:t,detailContext:s}),this._customEditors=e}async addGridCustomRender(i,t,s){if(this._grid)return void this._grid.addGridCustomRender(i,t,s);const e=new Map(this._customRenders);e.set(i,{customRender:t,detailContext:s}),this._customRenders=e}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFocus(){this._grid.setFocus()}async handleClick(i){var t;if(this.hasToBlockEvent(i)){if(i.preventDefault(),i.stopPropagation(),!await this._dataUnit.cancelEdition())return;const s=new i.constructor(i.type,i);null===(t=i.target)||void 0===t||t.dispatchEvent(s)}this._grid&&!this._grid.contains(i.target)&&this._grid.stopEdit()}hasToBlockEvent(i){var t;return(null===(t=this._snkFilterBar)||void 0===t?void 0:t.contains(i.target))&&this.enableGridInsert&&this._dataUnit.hasNewRecord()}async handleGridLegacyConfigName(i,t){i&&i!==t&&(this.addGridLegacyConfigName(),this.loadConfig())}handleAddFormMode(){return this.enableGridInsert?O.FORM_MODE:""}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,m.assertDefaultSorting(this._gridConfig,this._dataUnit)}fixColumNameCharset(i){try{return decodeURIComponent(escape(i))}catch(t){return i}}normalizeGridConfig(i){if(!i)return i;const t=i.columns.map((i=>Object.assign(Object.assign({},i),{name:this.fixColumNameCharset(i.name)})));return Object.assign(Object.assign({},i),{columns:t})}loadConfig(){b.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(this.normalizeGridConfig(i))})).catch((i=>{console.warn(i)}))}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&b.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}hasCalculatedFields(i){let t=!1;return i.forEach((i=>{var s;"true"===(null===(s=this._dataUnit.getField(i).properties)||void 0===s?void 0:s.calculated)&&(t=!0)})),t}gridConfigChangeHandler(i){const t=this.normalizeGridConfig(i.detail);b.saveGridConfig(t,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=this.normalizeGridConfig(i.detail);this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async hasToForceClientSideExporter(){if(!this._grid)return!1;const i=(await this._grid.getAppliedColumnFilters()).map((i=>i.name.replace("FILTRO_COLUNA_","")));return this.hasCalculatedFields(i)}async dataExporterProviderStore(){const i=await this.hasToForceClientSideExporter()||this.strategyExporter===T.CLIENT_SIDE?new p(this._dataUnit,this._grid):new I(this._dataUnit,this._grid);C.set("exporterProviders",Object.assign(Object.assign({},C.get("exporterProviders")),{[this.configName]:i}))}addElementID(){o.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}loadGridCustomFormatters(i){i&&this._grid&&i.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&this.addCustomValueFormatter(i.name,this._rmPrecisionCustomValueFormatter)}))}async interceptMetadataLoaded(i){return this.loadGridCustomFormatters(i.payload.fields),i}async interceptLoadData(i){var t;if(R(null===(t=this._snkFilterBar)||void 0===t?void 0:t.filterConfig))return i;{const i=this.messagesBuilder.getMessage("snkGrid.requiredFiltersNotFilled.title",{}),t=this.messagesBuilder.getMessage("snkGrid.requiredFiltersNotFilled.message",{});await this._application.error(i,t)}}finishLoading(){this._dataUnit.addInterceptor(this.dataUnitInterceptor),m.assertDefaultSorting(this._gridConfig,this._dataUnit),this.addElementID(),null!=this.columnFilterDataSource&&(this.columnFilterDataSource.setApplication(this._application),this.columnFilterDataSource.setDataUnit(this._dataUnit))}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t.customRender,t.detailContext),this._customRenders.delete(i)}setCustomEditors(){if(this._grid)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t.customEditor,t.detailContext),this._customEditors.delete(i)}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__");let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataUnit?this.finishLoading():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail,this.finishLoading()})),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this)),this._snkDataUnit.addEventListener("cancelEdition",(()=>{var i;(null===(i=this._dataState)||void 0===i?void 0:i.recordsIsEmpty)&&this._dataUnit.clearSelection()}));break}i=i.parentElement}this._rmPrecisionCustomValueFormatter=new k,this.addGridLegacyConfigName(),this.loadConfig(),this._continuousInsertUtils=new v(this._application,this.resourceID,this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidRender(){var i,t;this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.loadGridCustomFormatters(null===(t=null===(i=this._dataUnit)||void 0===i?void 0:i.metadata)||void 0===t?void 0:t.fields),this.setCustomRenders(),this.setCustomEditors()}async handleDataStateChange(i){this._dataState=i.detail,this._rmPrecisionCustomValueFormatter.setDataState(this._dataState)}getHeaderDisabledButtons(){var i;const t=[];return(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo)&&(this._dataState.selectionInfo.length>1&&t.push(O.CLONE,O.ATTACH,O.UPDATE),this._dataState.selectionInfo.isAllRecords()&&t.push(O.REMOVE)),t}getInvisibleButtons(){var i,t;let s=[];return this._dataUnit&&0!==this._dataUnit.records.length||s.push(O.DATA_EXPORTER),(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo.mode)===l.ALL_RECORDS&&s.push(O.ACTIONS_BUTTON),1===(null===(t=this._dataState)||void 0===t?void 0:t.selectionInfo.length)&&s.push(O.UPDATE_MULTIPLE),s}componentWillRender(){const i=this.getInvisibleButtons();this._headerTaskbarProcessor.process(this.getHeaderTaskbarId(),this.taskbarManager,this._dataState,this.getHeaderDisabledButtons(),i),this._topTaskbarProcessor.process(this.getTopTaskBarId(),this.taskbarManager,this._dataState,void 0,i),this.dataExporterProviderStore()}getHeaderTaskbarId(){var i,t;const s=this._dataState&&!!(null===(i=this._dataState.selectionInfo)||void 0===i?void 0:i.length),e={primary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",secondary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",singleTaskbar:this.isDetail?"snkGridHeaderTaskbar.singleTaskbar.detail":"snkGridHeaderTaskbar.singleTaskbar"}[this.presentationMode];let r=s?`${e}.selected`:`${e}.unselected`;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)&&this.presentationMode===f.SINGLE_TASKBAR&&(r="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),r}getTopTaskBarId(){var i;const t={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[this.presentationMode];return(null===(i=this._dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${t}`:`snkGridTopTaskbar.regular${t}`}getPrimaryButton(){return{primary:"INSERT",secondary:"",singleTaskbar:"INSERT"}[this.presentationMode]}getColumnSearch(i){return null!=this._columnSearch||(this._columnSearch=c(i,(({argument:i})=>new Promise((t=>{this._grid.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(i=>{null!=i&&this._grid.locateColumn(i.value)}))),this._columnSearch}getActionsList(){const i=[];if(this.enableGridInsert&&i.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return i;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const t=this.getTopTaskBarId();return i.concat(this.taskbarManager.getMoreOptions(t,this.configName,this._dataState,this.actionsList))}return i.concat(this.actionsList)}getActionsSettingsList(){return[{value:h.generateUUID(),label:this.messagesBuilder.getMessage("snkGrid.findColumn",{}),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getColumnSearch(t)}]}handleFilterConfigUpdated(i){this._showSnkFilterBar=!!i.length&&(1!==i.length||"PERSONALIZED_FILTER_GROUP"!==i[0].id||i[0].groupedItems.length>0)}getGridHeaderButtons(){return this.isGridInsertActive()?O.MORE_OPTIONS:this._headerTaskbarProcessor.buttons}isGridInsertActive(){return this.enableGridInsert&&this._dataUnit.hasNewRecord()}render(){if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large ez-box--no-outline",tabindex:"0"},s("div",{class:"snk-grid__header ez-margin-bottom--extra-small"},this._showSnkFilterBar&&s(e,null,s("snk-filter-bar",{ref:i=>this._snkFilterBar=i,title:this.filterBarTitle,dataUnit:this._dataUnit,"data-element-id":"gridFilter",class:"snk-grid__filter-bar ez-align--top",configName:this.configName,messagesBuilder:this.messagesBuilder,resourceID:this.resourceID,onConfigUpdated:i=>this.handleFilterConfigUpdated(i.detail),disablePersonalizedFilter:this.disablePersonalizedFilter,filterBarLegacyConfigName:this.filterBarLegacyConfigName,autoLoad:this.autoLoad,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,filterCustomConfig:this.filterCustomConfig,filterCustomConfigInterceptor:this.filterCustomConfigInterceptor}),s("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider"})),s("snk-taskbar",{class:"ez-padding-left--medium ez-padding-top--extra-small","data-element-id":"grid_top",key:"topTaskbar",configName:this.configName,dataUnit:this._dataUnit,messagesBuilder:this.messagesBuilder,buttons:this._topTaskbarProcessor.buttons,disabledButtons:this._topTaskbarProcessor.disabledButtons,customButtons:this._topTaskbarProcessor.customButtons,primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.topTaskbarCustomSlotId,overflowStrategy:"none",actionsSettingsList:this.getActionsSettingsList()},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===f.SECONDARY?"snk-grid-container__without-shadow ":"")+"snk-grid__table","data-element-id":"embedded",dataUnit:this._dataUnit,key:"grid-"+this._snkDataUnit.entityName,config:this._gridConfig,onConfigChange:i=>{this.gridConfigChangeHandler(i)},onEzColumnFilterChanged:async()=>await this.dataExporterProviderStore(),onEzDoubleClick:i=>this.gridDoubleClick.emit(i.detail),statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,columnfilterDataSource:this.columnFilterDataSource,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,recordsValidator:this.recordsValidator,canEdit:this.canEdit,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this._enableContinuousInsert,enableLockManagerTaskbarClick:this.enableLockManagerTaskbarClick,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,outlineMode:this.outlineMode,useSearchColumn:this.useSearchColumn,suppressHorizontalScroll:this.suppressHorizontalScroll,paginationCounterMode:this.paginationCounterMode,suppressCheckboxColumn:this.suppressCheckboxColumn,suppressFilterColumn:this.suppressFilterColumn,compact:this.compact},s("snk-taskbar",{id:"teste",dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this.getGridHeaderButtons(),presentationMode:this.presentationMode,disabledButtons:this._headerTaskbarProcessor.disabledButtons,customButtons:this._headerTaskbarProcessor.customButtons,slot:"leftButtons",actionsList:this.getActionsList(),primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.gridHeaderCustomSlotId,actionsSettingsList:this.getActionsSettingsList()},s("slot",{name:this.gridHeaderCustomSlotId}))),s("div",{class:"ez-col ez-col--sd-12 snk-grid-container__footer"},s("slot",{name:"SnkGridFooter"})),s("ez-popup",{size:"medium",heightMode:"auto",useHeader:!1,opened:this._popUpGridConfig,onEzClosePopup:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(o.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return r(this)}static get watchers(){return{gridLegacyConfigName:["handleGridLegacyConfigName"]}}};S.style=".sc-snk-grid-h{--snk-grid-min-height:300px;--snk-grid-padding:var(--space--small)}.snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%;padding:var(--snk-grid-padding);outline:none}.snk-grid__header.sc-snk-grid{width:100%;display:flex;flex-wrap:nowrap;justify-content:flex-end}.snk-grid__filter-bar.sc-snk-grid{width:100%}.snk-grid__header-divider.sc-snk-grid{margin-bottom:var(--space--medium)}.snk-grid__table.sc-snk-grid{min-height:var(--snk-grid-min-height)}.snk-grid-container__without-shadow.sc-snk-grid{--ezgrid__container--shadow:unset}.snk-grid-container__footer.sc-snk-grid{background-color:var(--background--xlight, #FFF);border-radius:0 0 var(--border--radius-medium) var(--border--radius-medium);box-shadow:var(--shadow--small)}";export{S as snk_grid}
|
1
|
+
import{r as i,c as t,h as s,F as e,g as r}from"./p-d8d8169b.js";import{KeyboardManager as a,Action as n,ElementIDUtils as o,ApplicationContext as d,StringUtils as h}from"@sankhyalabs/core";import{SelectionMode as l}from"@sankhyalabs/core/dist/dataunit/DataUnit";import{buildFieldSearch as c}from"@sankhyalabs/ezui/dist/collection/utils";import"./p-bb2f5f38.js";import"./p-53599b26.js";import{C as u,S as g,a as m,R as k,b as v,c as p}from"./p-f15478a1.js";import{P as f,E as T}from"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-5304753a.js";import"./p-ff1990ad.js";import"./p-9317942f.js";import"./p-9019a32f.js";import{C as b}from"./p-78ff8734.js";import{s as C}from"./p-55798617.js";import{g as E}from"./p-7dd49d15.js";import{v as R}from"./p-76e66fd9.js";import{T as _}from"./p-b987e15d.js";import{T as O}from"./p-1a0caadb.js";import"./p-8d884fab.js";import"./p-8f3f2306.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class I extends u{getFilters(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getAppliedFilters()}getOrders(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getSort()}getResourceURI(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.name}getSelectedNumber(){return this.dataUnit.getSelectionInfo().length}getTotalRecords(){var i,t,s;const{total:e}=(null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo())||{};return null!=e?e:null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.records)||void 0===s?void 0:s.length}getSelectedIDs(){return E(this.dataUnit)}getOffset(){return this.getExporterOffset(this.getPaginationInfo())}getPageSize(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.pageSize}getExportLimit(){return 5e3}getRecordID(){var i,t,s;return null===(s=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.records)||void 0===t?void 0:t[0])||void 0===s?void 0:s.__record__id__}getPaginationInfo(){var i;return null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo()}getExporterOffset(i){if(null==i)return;const t=i.firstRecord;return t>0?t-1:t}}const S=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this.componentReady=t(this,"componentReady",7),this._customEditors=new Map,this._customRenders=new Map,this._keyboardManager=new a,this._topTaskbarProcessor=new O({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.singleTaskbar":[],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()],"snkGridTopTaskbar.finish_edition.secondary":[],"snkGridTopTaskbar.finish_edition.singleTaskbar":[]}),this._headerTaskbarProcessor=new O({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.selected":this.getGridHeaderSelectedBtns(),"snkGridHeaderTaskbar.detail.unselected":["REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","FORM_MODE","CONFIGURATOR","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.singleTaskbar.detail.unselected":["INSERT","FORM_MODE","CONFIGURATOR","REFRESH","MORE_OPTIONS"],"snkGridHeaderTaskbar.singleTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","FORM_MODE","CONFIGURATOR","REFRESH"],"snkGridHeaderTaskbar.singleTaskbar.finish_edition":["CANCEL","SAVE",this.handleAddFormMode()]}),this.dataUnitInterceptor={interceptAction:async i=>i.type===n.METADATA_LOADED?await this.interceptMetadataLoaded(i):i.type===n.LOADING_DATA?await this.interceptLoadData(i):i},this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this._showSnkFilterBar=!0,this._enableContinuousInsert=!1,this.columnFilterDataSource=new g,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.configName=void 0,this.filterBarTitle=void 0,this.resourceID=void 0,this.selectionToastConfig=void 0,this.actionsList=void 0,this.isDetail=void 0,this.taskbarManager=void 0,this.statusResolver=void 0,this.multipleSelection=void 0,this.presentationMode=f.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.recordsValidator=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.gridHeaderCustomSlotId="GRID_HEADER_CUSTOM_ELEMENTS",this.gridHeaderDynamicSearchSlotId="GRID_HEADER_DYNAMIC_SEARCH",this.topTaskbarCustomSlotId="GRID_TASKBAR_CUSTOM_ELEMENTS",this.disablePersonalizedFilter=void 0,this.gridLegacyConfigName=void 0,this.filterBarLegacyConfigName=void 0,this.autoLoad=void 0,this.autoFocus=!0,this.enableGridInsert=!1,this.outlineMode=!1,this.suppressHorizontalScroll=!1,this.strategyExporter=T.SERVER_SIDE,this.useSearchColumn=!0,this.multipleEditionEnabled=!0,this.paginationCounterMode="auto",this.suppressCheckboxColumn=void 0,this.suppressFilterColumn=!1,this.compact=void 0,this.filterCustomConfig=void 0,this.filterCustomConfigInterceptor=void 0}getGridHeaderSelectedBtns(){const i=[_.UPDATE,_.CLONE,_.REMOVE,_.MORE_OPTIONS,_.DIVIDER,_.ATTACH,_.FORM_MODE,_.CONFIGURATOR,_.REFRESH,_.DATA_EXPORTER,_.ACTIONS_BUTTON];return this.multipleEditionEnabled&&i.unshift(_.UPDATE_MULTIPLE),i}async refreshColumnFilterDataSource(){await this._grid.refreshColumnFilterDataSource()}reloadConfig(){this.loadConfig()}async showConfig(){null!=this._grid&&this.openGridConfig()}async hideConfig(){null!=this._grid&&this.closeGridConfig()}async setConfig(i){this.setGridConfig(i)}async reloadFilterBar(){var i;null===(i=this._snkFilterBar)||void 0===i||i.reload()}async getFilterBar(){return this._snkFilterBar}async addCustomEditor(i,t,s){if(this._grid)return void this._grid.addCustomEditor(i,t,s);const e=new Map(this._customEditors);e.set(i,{customEditor:t,detailContext:s}),this._customEditors=e}async addGridCustomRender(i,t,s){if(this._grid)return void this._grid.addGridCustomRender(i,t,s);const e=new Map(this._customRenders);e.set(i,{customRender:t,detailContext:s}),this._customRenders=e}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFocus(){this._grid.setFocus()}async handleClick(i){var t;if(this.hasToBlockEvent(i)){if(i.preventDefault(),i.stopPropagation(),!await this._dataUnit.cancelEdition())return;const s=new i.constructor(i.type,i);null===(t=i.target)||void 0===t||t.dispatchEvent(s)}this._grid&&!this._grid.contains(i.target)&&this._grid.stopEdit()}hasToBlockEvent(i){var t;return(null===(t=this._snkFilterBar)||void 0===t?void 0:t.contains(i.target))&&this.enableGridInsert&&this._dataUnit.hasNewRecord()}async handleGridLegacyConfigName(i,t){i&&i!==t&&(this.addGridLegacyConfigName(),this.loadConfig())}handleAddFormMode(){return this.enableGridInsert?_.FORM_MODE:""}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,m.assertDefaultSorting(this._gridConfig,this._dataUnit)}fixColumNameCharset(i){try{return decodeURIComponent(escape(i))}catch(t){return i}}normalizeGridConfig(i){if(!i)return i;const t=i.columns.map((i=>Object.assign(Object.assign({},i),{name:this.fixColumNameCharset(i.name)})));return Object.assign(Object.assign({},i),{columns:t})}loadConfig(){b.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(this.normalizeGridConfig(i))})).catch((i=>{console.warn(i)}))}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&b.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}hasCalculatedFields(i){let t=!1;return i.forEach((i=>{var s;"true"===(null===(s=this._dataUnit.getField(i).properties)||void 0===s?void 0:s.calculated)&&(t=!0)})),t}gridConfigChangeHandler(i){const t=this.normalizeGridConfig(i.detail);b.saveGridConfig(t,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=this.normalizeGridConfig(i.detail);this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async hasToForceClientSideExporter(){if(!this._grid)return!1;const i=(await this._grid.getAppliedColumnFilters()).map((i=>i.name.replace("FILTRO_COLUNA_","")));return this.hasCalculatedFields(i)}async dataExporterProviderStore(){const i=await this.hasToForceClientSideExporter()||this.strategyExporter===T.CLIENT_SIDE?new p(this._dataUnit,this._grid):new I(this._dataUnit,this._grid);C.set("exporterProviders",Object.assign(Object.assign({},C.get("exporterProviders")),{[this.configName]:i}))}addElementID(){o.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}loadGridCustomFormatters(i){i&&this._grid&&i.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&this.addCustomValueFormatter(i.name,this._rmPrecisionCustomValueFormatter)}))}async interceptMetadataLoaded(i){return this.loadGridCustomFormatters(i.payload.fields),i}async interceptLoadData(i){var t;if(R(null===(t=this._snkFilterBar)||void 0===t?void 0:t.filterConfig))return i;{const i=this.messagesBuilder.getMessage("snkGrid.requiredFiltersNotFilled.title",{}),t=this.messagesBuilder.getMessage("snkGrid.requiredFiltersNotFilled.message",{});await this._application.error(i,t)}}finishLoading(){this._dataUnit.addInterceptor(this.dataUnitInterceptor),m.assertDefaultSorting(this._gridConfig,this._dataUnit),this.addElementID(),null!=this.columnFilterDataSource&&(this.columnFilterDataSource.setApplication(this._application),this.columnFilterDataSource.setDataUnit(this._dataUnit))}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t.customRender,t.detailContext),this._customRenders.delete(i)}setCustomEditors(){if(this._grid)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t.customEditor,t.detailContext),this._customEditors.delete(i)}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__");let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataUnit?this.finishLoading():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail,this.finishLoading()})),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this)),this._snkDataUnit.addEventListener("cancelEdition",(()=>{var i;(null===(i=this._dataState)||void 0===i?void 0:i.recordsIsEmpty)&&this._dataUnit.clearSelection()}));break}i=i.parentElement}this._rmPrecisionCustomValueFormatter=new k,this.addGridLegacyConfigName(),this.loadConfig(),this._continuousInsertUtils=new v(this._application,this.resourceID,this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidRender(){var i,t;this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.loadGridCustomFormatters(null===(t=null===(i=this._dataUnit)||void 0===i?void 0:i.metadata)||void 0===t?void 0:t.fields),this.setCustomRenders(),this.setCustomEditors()}async handleDataStateChange(i){this._dataState=i.detail,this._rmPrecisionCustomValueFormatter.setDataState(this._dataState)}getHeaderDisabledButtons(){var i;const t=[];return(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo)&&(this._dataState.selectionInfo.length>1&&t.push(_.CLONE,_.ATTACH,_.UPDATE),this._dataState.selectionInfo.isAllRecords()&&t.push(_.REMOVE)),t}getInvisibleButtons(){var i,t;let s=[];return this._dataUnit&&0!==this._dataUnit.records.length||s.push(_.DATA_EXPORTER),(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo.mode)===l.ALL_RECORDS&&s.push(_.ACTIONS_BUTTON),1===(null===(t=this._dataState)||void 0===t?void 0:t.selectionInfo.length)&&s.push(_.UPDATE_MULTIPLE),s}componentWillRender(){const i=this.getInvisibleButtons();this._headerTaskbarProcessor.process(this.getHeaderTaskbarId(),this.taskbarManager,this._dataState,this.getHeaderDisabledButtons(),i),this._topTaskbarProcessor.process(this.getTopTaskBarId(),this.taskbarManager,this._dataState,void 0,i),this.dataExporterProviderStore()}getHeaderTaskbarId(){var i,t;const s=this._dataState&&!!(null===(i=this._dataState.selectionInfo)||void 0===i?void 0:i.length),e={primary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",secondary:this.isDetail?"snkGridHeaderTaskbar.detail":"snkGridHeaderTaskbar",singleTaskbar:this.isDetail?"snkGridHeaderTaskbar.singleTaskbar.detail":"snkGridHeaderTaskbar.singleTaskbar"}[this.presentationMode];let r=s?`${e}.selected`:`${e}.unselected`;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)&&this.presentationMode===f.SINGLE_TASKBAR&&(r="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),r}getTopTaskBarId(){var i;const t={primary:"",secondary:".secondary",singleTaskbar:".singleTaskbar"}[this.presentationMode];return(null===(i=this._dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${t}`:`snkGridTopTaskbar.regular${t}`}getPrimaryButton(){return{primary:"INSERT",secondary:"",singleTaskbar:"INSERT"}[this.presentationMode]}getColumnSearch(i){return null!=this._columnSearch||(this._columnSearch=c(i,(({argument:i})=>new Promise((t=>{this._grid.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(i=>{null!=i&&this._grid.locateColumn(i.value)}))),this._columnSearch}getActionsList(){const i=[];if(this.enableGridInsert&&i.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return i;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const t=this.getTopTaskBarId();return i.concat(this.taskbarManager.getMoreOptions(t,this.configName,this._dataState,this.actionsList))}return i.concat(this.actionsList)}getActionsSettingsList(){return[{value:h.generateUUID(),label:this.messagesBuilder.getMessage("snkGrid.findColumn",{}),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getColumnSearch(t)}]}handleFilterConfigUpdated(i){this._showSnkFilterBar=!!i.length&&(1!==i.length||"PERSONALIZED_FILTER_GROUP"!==i[0].id||i[0].groupedItems.length>0)}getGridHeaderButtons(){return this.isGridInsertActive()?_.MORE_OPTIONS:this._headerTaskbarProcessor.buttons}isGridInsertActive(){return this.enableGridInsert&&this._dataUnit.hasNewRecord()}render(){if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large ez-box--no-outline",tabindex:"0"},s("div",{class:"snk-grid__header ez-margin-bottom--extra-small"},this._showSnkFilterBar&&s(e,null,s("snk-filter-bar",{ref:i=>this._snkFilterBar=i,title:this.filterBarTitle,dataUnit:this._dataUnit,"data-element-id":"gridFilter",class:"snk-grid__filter-bar ez-align--top",configName:this.configName,messagesBuilder:this.messagesBuilder,resourceID:this.resourceID,onConfigUpdated:i=>this.handleFilterConfigUpdated(i.detail),disablePersonalizedFilter:this.disablePersonalizedFilter,filterBarLegacyConfigName:this.filterBarLegacyConfigName,autoLoad:this.autoLoad,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,filterCustomConfig:this.filterCustomConfig,filterCustomConfigInterceptor:this.filterCustomConfigInterceptor}),s("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider"})),s("snk-taskbar",{class:"ez-padding-left--medium ez-padding-top--extra-small","data-element-id":"grid_top",key:"topTaskbar",configName:this.configName,dataUnit:this._dataUnit,messagesBuilder:this.messagesBuilder,buttons:this._topTaskbarProcessor.buttons,disabledButtons:this._topTaskbarProcessor.disabledButtons,customButtons:this._topTaskbarProcessor.customButtons,primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.topTaskbarCustomSlotId,overflowStrategy:"none",actionsSettingsList:this.getActionsSettingsList()},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===f.SECONDARY?"snk-grid-container__without-shadow ":"")+"snk-grid__table","data-element-id":"embedded",dataUnit:this._dataUnit,key:"grid-"+this._snkDataUnit.entityName,config:this._gridConfig,onConfigChange:i=>{this.gridConfigChangeHandler(i)},onEzColumnFilterChanged:async()=>await this.dataExporterProviderStore(),onEzDoubleClick:i=>this.gridDoubleClick.emit(i.detail),statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,columnfilterDataSource:this.columnFilterDataSource,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,recordsValidator:this.recordsValidator,canEdit:this.canEdit,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this._enableContinuousInsert,enableLockManagerTaskbarClick:this.enableLockManagerTaskbarClick,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,outlineMode:this.outlineMode,useSearchColumn:this.useSearchColumn,suppressHorizontalScroll:this.suppressHorizontalScroll,paginationCounterMode:this.paginationCounterMode,suppressCheckboxColumn:this.suppressCheckboxColumn,suppressFilterColumn:this.suppressFilterColumn,compact:this.compact},s("snk-taskbar",{id:"teste",dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this.getGridHeaderButtons(),presentationMode:this.presentationMode,disabledButtons:this._headerTaskbarProcessor.disabledButtons,customButtons:this._headerTaskbarProcessor.customButtons,slot:"leftButtons",actionsList:this.getActionsList(),primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.gridHeaderCustomSlotId,additionalSlotId:this.gridHeaderDynamicSearchSlotId,actionsSettingsList:this.getActionsSettingsList()},s("slot",{name:this.gridHeaderCustomSlotId}),s("slot",{name:this.gridHeaderDynamicSearchSlotId}))),s("div",{class:"ez-col ez-col--sd-12 snk-grid-container__footer"},s("slot",{name:"SnkGridFooter"})),s("ez-popup",{size:"medium",heightMode:"auto",useHeader:!1,opened:this._popUpGridConfig,onEzClosePopup:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(o.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return r(this)}static get watchers(){return{gridLegacyConfigName:["handleGridLegacyConfigName"]}}};S.style=".sc-snk-grid-h{--snk-grid-min-height:300px;--snk-grid-padding:var(--space--small)}.snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%;padding:var(--snk-grid-padding);outline:none}.snk-grid__header.sc-snk-grid{width:100%;display:flex;flex-wrap:nowrap;justify-content:flex-end}.snk-grid__filter-bar.sc-snk-grid{width:100%}.snk-grid__header-divider.sc-snk-grid{margin-bottom:var(--space--medium)}.snk-grid__table.sc-snk-grid{min-height:var(--snk-grid-min-height)}.snk-grid-container__without-shadow.sc-snk-grid{--ezgrid__container--shadow:unset}.snk-grid-container__footer.sc-snk-grid{background-color:var(--background--xlight, #FFF);border-radius:0 0 var(--border--radius-medium) var(--border--radius-medium);box-shadow:var(--shadow--small)}";export{S as snk_grid}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{d as e,D as t}from"./p-
|
1
|
+
import{d as e,D as t}from"./p-bb2f5f38.js";import{ObjectUtils as n}from"@sankhyalabs/core";class o{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchResource",e.gql`query($name: String!) {
|
2
2
|
$queryAlias$: fetchResource(name: $name){
|
3
3
|
resource
|
4
4
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
import{r as t,c as i,h as s,H as e,g as h}from"./p-d8d8169b.js";import{Action as n,StringUtils as a,ElementIDUtils as o,ApplicationContext as r,KeyboardManager as d}from"@sankhyalabs/core";import"./p-bb2f5f38.js";import"./p-53599b26.js";import{P as c,E as l}from"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-5304753a.js";import"./p-ff1990ad.js";import"./p-9317942f.js";import{V as u}from"./p-9019a32f.js";import{A as m}from"./p-1c2971e4.js";import{S as f}from"./p-cad964b5.js";import{T as p}from"./p-b987e15d.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-55798617.js";const g=class{constructor(s){t(this,s),this.actionClick=i(this,"actionClick",7),this.configuratorSave=i(this,"configuratorSave",7),this.configuratorCancel=i(this,"configuratorCancel",7),this.formItemsReady=i(this,"formItemsReady",7),this.viewModeChanged=i(this,"viewModeChanged",7),this.numberingConfigChanged=i(this,"numberingConfigChanged",7),this._viewHistory=[],this._customEditors=new Map,this._customRenders=new Map,this.loadEntitySuggestions=async t=>{var i;const s=null!==(i=null==t?void 0:t.argument)&&void 0!==i?i:"",e=(null==t?void 0:t.mode)||"PREDICTIVE";if(!s||0===s.trim().length)return[];try{this._showMoreOnSearch=!1;const t=this._snkDataUnit.entityName;return"PREDICTIVE"===e?await this.handlePredictiveSearch(s,t):await this._application.executePreparedSearch(e,s,this.buildSearchOptions(t))}catch(t){return console.error("Erro ao carregar sugestões de entidades:",t),[]}},this.searchEntitySelect=async t=>{if(this._entityPKField&&t)try{const i=[{name:this._entityPKField,value:t.value}];await this.refreshDataUnitByPk(i)}catch(t){console.error("Erro ao selecionar entidade:",t)}},this.dataUnitInterceptor={interceptAction:t=>(t.type===n.DATA_SAVED&&(t=this.interceptDataSaved(t)),t)},this._dataUnit=void 0,this._dataState=void 0,this.attachmentRegisterKey=void 0,this._currentViewMode=u.GRID,this._canEdit=void 0,this._resourceID=void 0,this.customContainerId=`SNK-CRUD-CUSTOM-CONTAINER-${a.generateUUID()}`,this.numberingConfig=void 0,this._showMoreOnSearch=!1,this._entityPKField=void 0,this.enableLockManagerLoadingComp=!1,this.enableLockManagerTaskbarClick=!1,this.configName=void 0,this.filterBarTitle=void 0,this.selectionToastConfig=void 0,this.showActionButtons=!1,this.actionsList=void 0,this.taskbarManager=void 0,this.recordsValidator=void 0,this.statusResolver=void 0,this.multipleSelection=!0,this.presentationMode=c.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.gridLegacyConfigName=void 0,this.filterBarLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.disablePersonalizedFilter=void 0,this.autoLoad=void 0,this.autoFocus=!0,this.enableGridInsert=!1,this.domainMessagesBuilder=void 0,this.ignoreReadOnlyFormFields=void 0,this.setCustomFormTitle=void 0,this.strategyExporter=l.SERVER_SIDE,this.layoutFormConfig=!0,this.multipleEditionEnabled=!0,this.paginationCounterMode="auto",this.showEntitySearch=!0,this.disableNumberingConfig=!1}async goToView(t){this.executeAction(t)}async openConfigurator(){var t;null===(t=this._snkConfigurator)||void 0===t||t.open()}async closeConfigurator(){var t;null===(t=this._snkConfigurator)||void 0===t||t.close()}async reloadFilterBar(){var t;null===(t=this._snkGrid)||void 0===t||t.reloadFilterBar()}async getFilterBar(){return await this._snkGrid.getFilterBar()}async addCustomEditor(t,i){if(this._guidesViewer&&this._snkGrid)return this._guidesViewer.addCustomEditor(t,i),void this._snkGrid.addCustomEditor(t,i);const s=new Map(this._customEditors);s.set(t,i),this._customEditors=s}async addGridCustomRender(t,i){if(this._snkGrid)return void this._snkGrid.addGridCustomRender(t,i);const s=new Map(this._customRenders);s.set(t,i),this._customRenders=s}async addCustomValueFormatter(t,i){this._snkGrid.addCustomValueFormatter(t,i)}async removeCustomValueFormatter(t){this._snkGrid.removeCustomValueFormatter(t)}async setFieldProp(t,i,s){await this._guidesViewer.setFieldProp(t,i,s)}async getNumberingConfig(){return this.numberingConfig}async updateNumberingConfig(t){this.numberingConfig=t,this.applyNumberingConfigToFields()}currentViewModeWatcher(t){this._viewHistory=[...this._viewHistory.slice(-1),t]}async gridToForm(t=!1){this._backToGrid=!t&&await this._viewStack.getSelectedIndex()===u.GRID,this.setViewMode(u.FORM)}async executeAction(t){switch(t){case p.GRID_MODE:return this.setViewMode(u.GRID);case p.FORM_MODE:case p.UPDATE:return this.gridToForm(t!==p.UPDATE);case p.UPDATE_MULTIPLE:return this._dataUnit.isMultipleEdition=!0,this.setViewMode(u.FORM);case p.CONFIGURATOR:return this._snkConfigurator.open();case p.ATTACH:return this.setViewMode(u.ATTACHMENT)}}backView(){const t=this._viewHistory.at(-2)||u.GRID;this.setViewMode(t)}setViewMode(t){this._viewStack.show(t),this._currentViewMode=t,t===u.GRID?(this._dataUnit.isMultipleEdition=!1,this._snkGrid.setFocus()):t===u.FORM&&this._guidesViewer.setFocus(),this.viewModeChanged.emit(t)}openConfig(t){this._snkConfigurator.close(),t===u.GRID?this._snkGrid.showConfig():t===u.FORM&&this._guidesViewer.showFormConfig()}addDataElementID(){o.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}insertionModeHandler(){this.enableGridInsert||this.gridToForm()}cancelHandler(){this._backToGrid&&this.setViewMode(u.GRID)}async getAttachmentRegisterKey(){if(this._snkDataUnit)return(await this._snkDataUnit.getSelectedRecordsIDsInfo()).map((({value:t})=>t)).join("_")}setCustomRenders(){if(this._snkGrid)for(const[t,i]of this._customRenders)this._snkGrid.addGridCustomRender(t,i),this._customRenders.delete(t)}setCustomEditors(){if(this._snkGrid&&this._guidesViewer)for(const[t,i]of this._customEditors)this._guidesViewer.addCustomEditor(t,i),this._snkGrid.addCustomEditor(t,i),this._customEditors.delete(t)}componentDidRender(){this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this._application=r.getContextValue("__SNK__APPLICATION__");let t=this._element.parentElement;for(this._application.hasAccess(m.UPDATE,this._resourceID).then((t=>this._canEdit=t));t;){if("SNK-DATA-UNIT"===t.tagName.toUpperCase()){this._snkDataUnit=t,this._snkDataUnit.addEventListener("insertionMode",(()=>this.insertionModeHandler())),this._snkDataUnit.addEventListener("cancelEdition",(()=>this.cancelHandler())),this._snkDataUnit.domainMessagesBuilder=this.domainMessagesBuilder,this._dataUnit=this._snkDataUnit.dataUnit,this._dataState=this._snkDataUnit.dataState,this._dataUnit?this.initDataUnit():this._snkDataUnit.addEventListener("dataUnitReady",(t=>{this._dataUnit=t.detail,this.initDataUnit()})),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this));break}t=t.parentElement}this.configName||(this.configName=this._application.configName)}componentDidLoad(){this.initKeyboardManager()}disconnectedCallback(){var t;this.removeShortcuts(),null===(t=this._dataUnit)||void 0===t||t.removeInterceptor(this.dataUnitInterceptor)}async handleDataStateChange(t){var i;this._dataState=t.detail,void 0!==this._dataState.selectedRecord&&(this.attachmentRegisterKey=await this.getAttachmentRegisterKey());const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const t of s||[]){if(!t)continue;const s=null===(i=this._dataState.rowMetadata)||void 0===i?void 0:i.getProp("rm_precision",t);(s||0===s)&&(await this.setFieldProp(t,"precision",s),await this.setFieldProp(t,"prettyPrecision",s))}}async initKeyboardManager(){this._keyboardManager=new d({propagate:!1,element:this._element});const t=this._dataUnit||await this._snkDataUnit.getDataUnit();async function i(){const i=document.activeElement,s=i==document.body;s||i.blur(),await t.saveData(),s||null==i.setFocus?s||i.focus():i.setFocus()}this._keyboardManager&&this._keyboardManager.bind("F6",this.toggleView.bind(this),{description:this.getMessage("snkCrud.shortcuts.toggleView"),element:this._element}).bind("F7",i.bind(this),{description:this.getMessage("snkCrud.shortcuts.saveData"),element:this._element}).bind("ctrl + \\",i.bind(this),{description:this.getMessage("snkCrud.shortcuts.addRecord"),element:this._element}).bind("F8",async function(){t.hasNewRecord()||t.addRecord()}.bind(this),{description:this.getMessage("snkCrud.shortcuts.addRecord"),element:this._element}).bind("F9",t.removeSelectedRecords.bind(t),{description:this.getMessage("snkCrud.shortcuts.removeRecord"),element:this._element}).bind("ctrl + F9",t.removeSelectedRecords.bind(t),{description:this.getMessage("snkCrud.shortcuts.removeRecord"),element:this._element}).bind("F5",(async()=>{const i=await this._viewStack.getSelectedIndex();u.GRID===i&&t.loadData()}),{description:this.getMessage("snkCrud.shortcuts.refreshData"),element:this._element}).bind("Escape",(()=>{t.isDirty()&&t.cancelEdition()}),{debounceTime:1e3,description:this.getMessage("snkCrud.shortcuts.cancelAction"),element:this._element})}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}async removeShortcuts(){var t;null===(t=this._keyboardManager)||void 0===t||t.unbindAllShortcutKeys()}async handlePredictiveSearch(t,i){var s,e;const h=await this._application.executePreparedSearchWithFullResponse(t,this.buildSearchOptions(i,5));return this._showMoreOnSearch=null!==(s=null==h?void 0:h.hasMore)&&void 0!==s&&s,this._entityPKField=null==h?void 0:h.pkField,null!==(e=null==h?void 0:h.data)&&void 0!==e?e:[]}async refreshDataUnitByPk(t){try{const i={term:"",filter:{name:"",params:[],expression:`(${t[0].name} = ${t[0].value})`}};await this._dataUnit.loadData(i),1===this._dataUnit.records.length&&(this._dataUnit.selectFirst(),this.gridToForm(!0))}catch(t){console.error("Erro ao atualizar dataset:",t)}}buildSearchOptions(t,i){return{entity:t,entityDescription:t,executeOnOpen:!0,searchOptions:{localEntityName:t,limit:i}}}async toggleView(){const t=await this._viewStack.getSelectedIndex();this.setViewMode(u.GRID===t?u.FORM:u.GRID)}getLastRecordSaved(t){var i;return(null===(i=t.payload)||void 0===i?void 0:i.records.length)?t.payload.records[t.payload.records.length-1]:null}async saveNumberingConfig(){const t={entityName:this._snkDataUnit.entityName,isAutoNum:this.numberingConfig.isAutoNumbering,numInicial:this.numberingConfig.initialNumber};await this._servicesNumberingConfig.saveConfig(t)}updateNumberingConfigAfterInsert(t){var i,s;if(!(null===(i=t.payload)||void 0===i?void 0:i.changes.length)||this.disableNumberingConfig||!(null===(s=this.numberingConfig)||void 0===s?void 0:s.isAutoNumbering)||!this._fieldAutoNum)return t;if(!t.payload.changes.some((t=>"INSERT"===t.operation||"COPY"===t.operation)))return t;const e=this.getLastRecordSaved(t);if(e&&e.hasOwnProperty(this._fieldAutoNum)){const t=Number(e[this._fieldAutoNum]);this.numberingConfig.initialNumber=t,this.saveNumberingConfig()}else this.numberingConfig.initialNumber=this.numberingConfig.initialNumber+1;return this.numberingConfigChanged.emit(this.numberingConfig),t}interceptDataSaved(t){return this.updateNumberingConfigAfterInsert(t),t}onDataUnitReady(){var t;null===(t=this._dataUnit)||void 0===t||t.addInterceptor(this.dataUnitInterceptor),this.loadNumberingConfig()}async initDataUnit(){this.addDataElementID(),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),null==this._resourceID&&(this._resourceID=this._snkDataUnit.resourceID,null==this._resourceID&&(this._resourceID=await this._application.getResourceID())),this.onDataUnitReady()}async loadNumberingConfig(){if(!this.numberingConfig&&this._snkDataUnit&&this._snkDataUnit.entityName&&!this.disableNumberingConfig){this._servicesNumberingConfig||(this._servicesNumberingConfig=new f(this._application,this._resourceID));try{this.numberingConfig=await this._servicesNumberingConfig.getConfig(this._snkDataUnit.entityName),this.getFieldAutoNum(),this.applyNumberingConfigToFields()}catch(t){console.error("Error loading numbering config in snk-crud:",t),this.numberingConfig={isAutoNumbering:!1,initialNumber:null}}}}getFieldAutoNum(){if(this._fieldAutoNum)return;const t=this._dataUnit.metadata.fields.find((t=>{var i;return"true"===(null===(i=t.properties)||void 0===i?void 0:i.isAutoNumField)}));this._fieldAutoNum=(null==t?void 0:t.name)||null}async applyNumberingConfigToFields(){if(!this.numberingConfig||!this._snkDataUnit||!this._fieldAutoNum)return;const t=this._dataUnit.getField(this._fieldAutoNum);t.readOnly=this.numberingConfig.isAutoNumbering,t.required=!this.numberingConfig.isAutoNumbering}handleConfiguratorEvent(t,i){if(t.stopImmediatePropagation(),"SAVE"===i)return this._guidesViewer.reloadGuides(),void this.configuratorSave.emit();this.configuratorCancel.emit()}renderDynamicSearch(t){var i;if(this.showEntitySearch&&!0!==(null===(i=this._dataState)||void 0===i?void 0:i.insertionMode))return s("div",{slot:t,class:"entity-search-container",style:{position:"relative",display:"inline-block",marginLeft:"10px",minWidth:"200px"}},s("ez-search",{label:"Buscar registros",optionLoader:this.loadEntitySuggestions,onEzChange:t=>this.searchEntitySelect(t.detail),mode:"slim",showMore:this._showMoreOnSearch,suppressEmptyOption:!0,suppressInputPersist:!0}))}render(){if(null!=this._resourceID)return this._snkDataUnit.ignoreSaveMessage=this._currentViewMode===u.GRID&&!this.enableGridInsert,s(e,null,s("ez-view-stack",{ref:t=>this._viewStack=t,"data-element-id":"crud"},s("stack-item",{class:"ez-flex ez-flex--column ez-size-height--full ez-size-width--full ez-padding--medium"},s("snk-grid",{ref:t=>this._snkGrid=t,class:"ez-flex ez-flex--column ez-size-height--full ez-size-width--full",filterBarTitle:this.filterBarTitle,"data-element-id":"crud_grid",configName:this.configName,onGridDoubleClick:()=>this.gridToForm(!0),taskbarManager:this.taskbarManager,onActionClick:t=>this.executeAction(t.detail),messagesBuilder:this.messagesBuilder,actionsList:this.actionsList,statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,presentationMode:this.presentationMode,recordsValidator:this.recordsValidator,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,canEdit:this._canEdit,resourceID:this._resourceID,disablePersonalizedFilter:this.disablePersonalizedFilter,gridLegacyConfigName:this.gridLegacyConfigName,filterBarLegacyConfigName:this.filterBarLegacyConfigName,autoLoad:this.autoLoad,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableLockManagerTaskbarClick:this.enableLockManagerTaskbarClick,enableLockManagerLoadingComp:this.enableLockManagerLoadingComp,strategyExporter:this.strategyExporter,multipleEditionEnabled:this.multipleEditionEnabled,paginationCounterMode:this.paginationCounterMode},s("slot",{name:"GRID_TASKBAR_CUSTOM_ELEMENTS"}),s("slot",{name:"GRID_HEADER_CUSTOM_ELEMENTS"}),s("slot",{name:"SnkGridHeader"}),s("slot",{name:"SnkGridFooter"}),s("slot",{name:"SnkGridTaskBar"}),this.renderDynamicSearch("GRID_HEADER_DYNAMIC_SEARCH"))),s("stack-item",null,s("snk-guides-viewer",{ref:t=>this._guidesViewer=t,entityPath:this._snkDataUnit.entityName,messagesBuilder:this.messagesBuilder,onExit:()=>this.setViewMode(u.GRID),dataState:this._dataState,dataUnit:this._dataUnit,actionsList:this.actionsList,taskbarManager:this.taskbarManager,configName:this.configName,onActionClick:t=>this.executeAction(t.detail),presentationMode:this.presentationMode,"data-element-id":"crud_form",canEdit:this._canEdit,recordsValidator:this.recordsValidator,resourceID:this._resourceID,detailTaskbarCustomContainerId:this.customContainerId,formLegacyConfigName:this.formLegacyConfigName,enableGridInsert:this.enableGridInsert,getCustomTitle:this.setCustomFormTitle,ignoreReadOnlyFormFields:this.ignoreReadOnlyFormFields},s("slot",{name:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS"}),this.renderDynamicSearch("GUIDES_VIEWER_DYNAMIC_SEARCH"),s("slot",{name:"SnkFormTaskBar"}))),s("stack-item",{tabIndex:"0"},s("snk-attach",{registerKey:this.attachmentRegisterKey,messagesBuilder:this.messagesBuilder,entityName:this._snkDataUnit.entityName,onBack:this.backView.bind(this)})),s("snk-configurator",{ref:t=>this._snkConfigurator=t,entityName:this._snkDataUnit.entityName,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:t=>this.setViewMode(t.detail),onOpenConfig:t=>this.openConfig(t.detail),showActionButtons:this.showActionButtons,onSave:t=>this.handleConfiguratorEvent(t,"SAVE"),onCancel:t=>this.handleConfiguratorEvent(t,"CANCEL"),resourceID:this._resourceID,customContainerId:this.customContainerId,layoutFormConfig:this.layoutFormConfig})),s("div",{id:`${this.customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}),s("slot",{name:"DETAIL_GRID_HEADER_CUSTOM_ELEMENTS"}),s("slot",{name:"DETAIL_GRID_TASKBAR_CUSTOM_ELEMENTS"}),s("slot",{name:"DETAIL_TASKBAR_CUSTOM_ELEMENTS"})))}get _element(){return h(this)}static get watchers(){return{_currentViewMode:["currentViewModeWatcher"]}}};g.style=".sc-snk-crud-h{display:flex;flex-direction:column;height:100%;width:100%}";export{g as snk_crud}
|
@@ -1 +1 @@
|
|
1
|
-
import{C as t}from"./p-
|
1
|
+
import{C as t}from"./p-78ff8734.js";import{ObjectUtils as i,StringUtils as e}from"@sankhyalabs/core";import{F as s}from"./p-9317942f.js";import{a as r}from"./p-9019a32f.js";class n{constructor(t,i,e,s){this._resourceID=i,this._configName=t,this._onConfigChange=e,this._dataUnit=s}addFormLegacyConfig(i){this._configName&&t.addFormLegacyConfig(this._configName,i)}async loadConfig(){return new Promise((i=>{t.loadFormConfig(this._configName,this._resourceID).then((t=>{t=this.buildFormMetadataUITabs(t),this.setConfig(t),i(t)})).catch((t=>{console.warn(t)}))}))}getEmptyConfig(){return this.buildFormMetadataUITabs({fields:[],emptyConfig:!0},!0)}saveConfig(e){const s=i.copy(e);return new Promise((i=>{t.saveFormConfig(e,this._configName,this._resourceID).then((t=>{this.setConfig(Object.assign(Object.assign({},s),t)),i(Object.assign(Object.assign({},s),t))}))}))}saveCardState(i,e,s){return new Promise((r=>{var n;const l=(null===(n=this._config)||void 0===n?void 0:n.cardsState)||new Map,o=l.get(i);l.set(i,"fixed"===s?this.updateFixSequence(Object.assign(Object.assign({},o),{fixed:e.fixed}),l):Object.assign(Object.assign({},o),{[s]:e[s]})),t.saveCardState(l,this._configName,this._resourceID).then((t=>{this._config=Object.assign(Object.assign({},this._config),{cardsState:l}),r(t)}))}))}updateFixSequence(t,i){let e=-1;return Array.from(i.values()).forEach((i=>{i.fixed||delete t.fixSequence,null!=i.fixSequence&&(e=Math.max(e,i.fixSequence))})),t.fixed?t.fixSequence=e+1:delete t.fixSequence,t}hasConfig(t){var i;const e=null!=t?t:this._config;return!(!e||!(null===(i=e.fields)||void 0===i?void 0:i.length))}getFieldsList(t,i=!1){var e;const s=null===(e=this._config)||void 0===e?void 0:e.fields;return this.hasConfig()&&!i?s.map((({label:t,name:i,readOnly:e,visible:s,required:r,tab:n,group:l})=>{var o;if(null==t){const t=null===(o=this._dataUnit)||void 0===o?void 0:o.getField(i);if(!t)return;return Object.assign(Object.assign({},t),{name:null!=i?i:t.name,readOnly:null!=e?e:t.readOnly,visible:null!=s?s:t.visible,required:null!=r?r:t.required,tab:n,group:l})}return{name:i,label:t,readOnly:e,visible:s,required:r,tab:n,group:l}})).filter((i=>this.isFieldVisible(i,t))):this._dataUnit?this._dataUnit.metadata.fields.filter((i=>this.isFieldVisible(i,t))).map((({label:t,name:i,readOnly:e,visible:s,required:r,properties:n})=>({label:t,name:i,readOnly:e,visible:s,required:r,tab:null==n?void 0:n.UITabName}))):[]}isFieldVisible(t,i){if(void 0===t||!1===t.visible)return!1;if(null==i)return!0;const s=e.replaceAccentuatedCharsLower((t.label||t.name).toLocaleLowerCase()),r=e.replaceAccentuatedCharsLower(i.toLocaleLowerCase());return s.includes(r)}getFormConfig(t,i,e=!1){let s=this.getFieldsList(void 0,e);return i&&(s=s.filter((i=>{if(t){const e=t.getField(i.name);if(e&&e.readOnly)return!1}return!i.readOnly}))),Object.assign(Object.assign({},this._config),{fields:s})}setConfig(t){this.isLoaded=!0;const{cardsState:i,summary:e,defaultVars:s}=this._config||{};this._config=Object.assign({},t),i&&(this._config.cardsState=i),e&&(this._config.summary=e),s&&(this._config.defaultVars=s),this._onConfigChange&&this._onConfigChange(Object.assign({},this._config))}getConfig(t,i){return this.getFormConfig(t,i)}getFormConfigFetcher(){return null==this._formConfigFetcher&&(this._formConfigFetcher=new s),this._formConfigFetcher}async fetchUserAvailableConfigs(){return null!=this._configName?Promise.resolve(void 0):this.getFormConfigFetcher().fetchUserAvailableConfigs(this._configName,this._resourceID)}async fetchLegacyConfig(){return this.getFormConfigFetcher().fetchLegacyConfig(this._configName,this._resourceID)}async fetchDefaultConfig(){return this.getFormConfigFetcher().fetchDefaultConfig(this._configName,this._resourceID)}parseObjectList(t){return t?Array.isArray(t)?t:[t]:[]}buildFormMetadataUITabs(t,i=!1){var e;const s=this.hasConfig(t);if(!i&&(!this._dataUnit||s))return t;(t=this.getFormConfig(this._dataUnit,!1,!0)).tabs=this.parseObjectList(t.tabs),t.emptyConfig=!1,t.defaultConfiguration=!0;const n=this._dataUnit.metadata.fields;for(const i of n){const s=t.fields.find((t=>t.name===i.name)),n=null===(e=i.properties)||void 0===e?void 0:e.UITabName;n&&n!==r.main&&(t.tabs.some((t=>t.label===n))||t.tabs.push({label:n,name:n,order:0,visible:!0}),s&&(s.tab=n))}return t}}export{n as S}
|