@sankhyalabs/sankhyablocks 8.16.0-rc.3 → 8.16.0-rc.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/{ConfigStorage-a343e418.js → ConfigStorage-e49214c6.js} +2 -2
- package/dist/cjs/{DataFetcher-313debd8.js → DataFetcher-77729a93.js} +7 -2
- package/dist/cjs/{IExporterProvider-597949f9.js → IExporterProvider-10b7fed5.js} +4 -4
- package/dist/cjs/{SnkFormConfigManager-166cbd1f.js → SnkFormConfigManager-beebf47a.js} +2 -2
- package/dist/cjs/{SnkMessageBuilder-897ffd08.js → SnkMessageBuilder-cceebbae.js} +1 -1
- package/dist/cjs/{auth-fetcher-54f5ff9d.js → auth-fetcher-29bb791c.js} +1 -1
- package/dist/cjs/{dataunit-fetcher-688d3f05.js → dataunit-fetcher-d4873076.js} +1 -1
- package/dist/cjs/{form-config-fetcher-2dd00e5b.js → form-config-fetcher-feb08214.js} +1 -1
- package/dist/cjs/{pesquisa-fetcher-680e198f.js → pesquisa-fetcher-a1d0353f.js} +1 -1
- package/dist/cjs/snk-actions-button_4.cjs.entry.js +5 -5
- package/dist/cjs/snk-application.cjs.entry.js +7 -7
- package/dist/cjs/snk-attach.cjs.entry.js +5 -5
- package/dist/cjs/snk-crud.cjs.entry.js +5 -5
- package/dist/cjs/snk-data-exporter.cjs.entry.js +8 -8
- package/dist/cjs/{snk-data-unit-8fa7917a.js → snk-data-unit-8af43aa3.js} +2 -2
- package/dist/cjs/snk-data-unit.cjs.entry.js +4 -4
- package/dist/cjs/snk-detail-view.cjs.entry.js +8 -8
- package/dist/cjs/snk-exporter-email-sender.cjs.entry.js +1 -1
- package/dist/cjs/snk-filter-bar.cjs.entry.js +3 -3
- package/dist/cjs/snk-filter-modal-item.cjs.entry.js +3 -3
- package/dist/cjs/snk-form-config.cjs.entry.js +2 -2
- package/dist/cjs/snk-form.cjs.entry.js +4 -4
- package/dist/cjs/snk-grid.cjs.entry.js +6 -6
- package/dist/cjs/{snk-guides-viewer-bdc41281.js → snk-guides-viewer-69ec61af.js} +5 -5
- 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-simple-crud.cjs.entry.js +7 -7
- package/dist/collection/components/snk-data-exporter/exporter-email-sender/options-step.js +1 -1
- package/dist/collection/components/snk-data-exporter/structure/ItemBuilder.js +2 -2
- package/dist/collection/lib/http/data-fetcher/DataFetcher.js +8 -3
- package/dist/collection/lib/message/resources/snk-exporter.msg.js +1 -1
- package/dist/components/DataFetcher.js +8 -3
- package/dist/components/SnkMessageBuilder.js +1 -1
- package/dist/components/snk-data-exporter2.js +2 -2
- package/dist/components/snk-exporter-email-sender2.js +1 -1
- package/dist/esm/{ConfigStorage-3806514e.js → ConfigStorage-e476378d.js} +2 -2
- package/dist/esm/{DataFetcher-c1baf61d.js → DataFetcher-773a3e4b.js} +8 -3
- package/dist/esm/{IExporterProvider-63a188b6.js → IExporterProvider-d597f27d.js} +4 -4
- package/dist/esm/{SnkFormConfigManager-31b24066.js → SnkFormConfigManager-298cd647.js} +2 -2
- package/dist/esm/{SnkMessageBuilder-571462fb.js → SnkMessageBuilder-ae87b754.js} +1 -1
- package/dist/esm/{auth-fetcher-039abba3.js → auth-fetcher-a411f73c.js} +1 -1
- package/dist/esm/{dataunit-fetcher-264191b2.js → dataunit-fetcher-3d2ec959.js} +1 -1
- package/dist/esm/{form-config-fetcher-30fb808f.js → form-config-fetcher-e0382e5a.js} +1 -1
- package/dist/esm/{pesquisa-fetcher-03c8f919.js → pesquisa-fetcher-a87445a0.js} +1 -1
- package/dist/esm/snk-actions-button_4.entry.js +5 -5
- package/dist/esm/snk-application.entry.js +7 -7
- package/dist/esm/snk-attach.entry.js +5 -5
- package/dist/esm/snk-crud.entry.js +5 -5
- package/dist/esm/snk-data-exporter.entry.js +8 -8
- package/dist/esm/{snk-data-unit-f5cbe64b.js → snk-data-unit-008cb9aa.js} +2 -2
- package/dist/esm/snk-data-unit.entry.js +4 -4
- package/dist/esm/snk-detail-view.entry.js +8 -8
- package/dist/esm/snk-exporter-email-sender.entry.js +1 -1
- package/dist/esm/snk-filter-bar.entry.js +3 -3
- package/dist/esm/snk-filter-modal-item.entry.js +3 -3
- package/dist/esm/snk-form-config.entry.js +2 -2
- package/dist/esm/snk-form.entry.js +4 -4
- package/dist/esm/snk-grid.entry.js +6 -6
- package/dist/esm/{snk-guides-viewer-dda0fede.js → snk-guides-viewer-43f21b03.js} +5 -5
- package/dist/esm/snk-guides-viewer.entry.js +7 -7
- package/dist/esm/snk-personalized-filter.entry.js +3 -3
- package/dist/esm/snk-simple-crud.entry.js +7 -7
- package/dist/sankhyablocks/{p-fe79f83a.js → p-091ce761.js} +1 -1
- package/dist/sankhyablocks/{p-913a9979.js → p-0cd3c0a9.js} +1 -1
- package/dist/sankhyablocks/{p-7619bdb1.entry.js → p-162b9a59.entry.js} +2 -2
- package/dist/sankhyablocks/p-16a1dd18.entry.js +1 -0
- package/dist/sankhyablocks/{p-df5451c7.js → p-181975f1.js} +1 -1
- package/dist/sankhyablocks/{p-fa4d8cb4.js → p-1f35c795.js} +1 -1
- package/dist/sankhyablocks/{p-af8efd95.js → p-25f1fc39.js} +1 -1
- package/dist/sankhyablocks/{p-62ba211a.entry.js → p-2e9c764c.entry.js} +1 -1
- package/dist/sankhyablocks/{p-52920496.js → p-3287a6cc.js} +1 -1
- package/dist/sankhyablocks/p-3c50e9d4.entry.js +1 -0
- package/dist/sankhyablocks/{p-4e5e1313.entry.js → p-421bec84.entry.js} +1 -1
- package/dist/sankhyablocks/{p-7505da04.entry.js → p-42f7b05d.entry.js} +1 -1
- package/dist/sankhyablocks/{p-871aa14e.entry.js → p-46bb200a.entry.js} +1 -1
- package/dist/sankhyablocks/{p-b05d8893.entry.js → p-53412c1d.entry.js} +1 -1
- package/dist/sankhyablocks/p-594bc21d.js +1 -0
- package/dist/sankhyablocks/{p-2a408684.js → p-5f016aed.js} +1 -1
- package/dist/sankhyablocks/{p-d6e26ea8.entry.js → p-62f34e6f.entry.js} +1 -1
- package/dist/sankhyablocks/{p-7a85fd49.entry.js → p-65f8c11c.entry.js} +1 -1
- package/dist/sankhyablocks/{p-80042dc6.entry.js → p-684a2590.entry.js} +1 -1
- package/dist/sankhyablocks/{p-3a212712.js → p-76a65660.js} +1 -1
- package/dist/sankhyablocks/p-7b8f7242.entry.js +1 -0
- package/dist/sankhyablocks/p-7c4aabe2.js +1 -0
- package/dist/sankhyablocks/{p-6bb2f3e9.entry.js → p-89451692.entry.js} +1 -1
- package/dist/sankhyablocks/{p-450c60e4.entry.js → p-939e15d3.entry.js} +1 -1
- package/dist/sankhyablocks/{p-47db7e88.entry.js → p-9dfda04a.entry.js} +1 -1
- package/dist/sankhyablocks/{p-2c68b3ae.entry.js → p-bd008859.entry.js} +1 -1
- package/dist/sankhyablocks/{p-17def7cd.js → p-cc935517.js} +1 -1
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/package.json +2 -2
- package/dist/sankhyablocks/p-219f888d.entry.js +0 -1
- package/dist/sankhyablocks/p-75e674ed.entry.js +0 -1
- package/dist/sankhyablocks/p-7ef9c55c.js +0 -1
- package/dist/sankhyablocks/p-8c59edd7.entry.js +0 -1
- package/dist/sankhyablocks/p-dc7c9047.js +0 -1
@@ -1 +1 @@
|
|
1
|
-
import{r as i,c as t,h as s,F as e,g as a}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as n,ApplicationContext as d,StringUtils as o}from"@sankhyalabs/core";import{T as h}from"./p-7e7a7473.js";import{C as l}from"./p-52920496.js";import{P as c}from"./p-30cf616e.js";import{T as u,o as g,b as T}from"./p-c2495304.js";import{s as m}from"./p-6dc031de.js";import{C as k,S as E,a as f,R as v}from"./p-3a212712.js";import{SelectionMode as p}from"@sankhyalabs/core/dist/dataunit/DataUnit";import"./p-dc7c9047.js";import"./p-af8efd95.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-fe79f83a.js";import"./p-ff1990ad.js";import"./p-df5451c7.js";import{g as R}from"./p-9863d682.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class O extends k{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 R(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 b=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this._customEditors=new Map,this._customRenders=new Map,this._topTaskbarProcessor=new u({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.singleTaskbar":[],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE"],"snkGridTopTaskbar.finish_edition.secondary":[],"snkGridTopTaskbar.finish_edition.singleTaskbar":[]}),this._headerTaskbarProcessor=new u({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"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.dataUnitInterceptor={interceptAction:async i=>i.type===r.METADATA_LOADED?await this.interceptMetadataLoaded(i):i},this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this._showSnkFilterBar=!0,this.columnFilterDataSource=new E,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=c.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}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 findColumn(){await g(this._moreOptions,this._columnSearch)}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 handleGridLegacyConfigName(i,t){i&&i!==t&&(this.addGridLegacyConfigName(),this.loadConfig())}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,f.assertDefaultSorting(this._gridConfig,this._dataUnit)}loadConfig(){l.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(i)})).catch((i=>{console.warn(i)}))}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&l.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}gridConfigChangeHandler(i){l.saveGridConfig(i.detail,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){const i=new O(this._dataUnit,this._grid);m.set("exporterProviders",Object.assign(Object.assign({},m.get("exporterProviders")),{[this.configName]:i}))}addElementID(){n.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}finishLoading(){this._dataUnit.addInterceptor(this.dataUnitInterceptor),f.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 v,this.addGridLegacyConfigName(),this.loadConfig()}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.loadGridCustomFormatters(this._dataUnit.metadata.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(h.CLONE,"ATTACH"),this._dataState.selectionInfo.isAllRecords()&&t.push("REMOVE")),t}getInvisibleButtons(){let i=[];return this._dataUnit&&0!==this._dataUnit.records.length||i.push("DATA_EXPORTER"),this._dataState&&this._dataState.selectionInfo.mode===p.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}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 a=s?`${e}.selected`:`${e}.unselected`;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)&&this.presentationMode===c.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}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,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=T(t,(({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}))))}))}))),(t=>{null!=t&&(this._grid.locateColumn(t.value),i.hideActions())}))),this._columnSearch}getActionsList(){const i=[{value:o.generateUUID(),label:this.messagesBuilder.getMessage("snkGrid.findColumn",{}),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getColumnSearch(i,t)}];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)}handleFilterConfigUpdated(i){this._showSnkFilterBar=!!i.length&&(1!==i.length||"PERSONALIZED_FILTER_GROUP"!==i[0].id||i[0].groupedItems.length>0)}render(){if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large"},s("div",{class:"snk-grid__header ez-margin-bottom--medium"},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}),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","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"},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===c.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)},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},s("snk-taskbar",{id:"teste",dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this._headerTaskbarProcessor.buttons,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},s("slot",{name:this.gridHeaderCustomSlotId}))),s("div",{class:"ez-col ez-col--sd-12"},s("slot",{name:"SnkGridFooter"})),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._popUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(n.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return a(this)}static get watchers(){return{gridLegacyConfigName:["handleGridLegacyConfigName"]}}};b.style=".sc-snk-grid-h{--snk-grid-min-height:300px}.snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%}.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}";export{b as snk_grid}
|
1
|
+
import{r as i,c as t,h as s,F as e,g as a}from"./p-d2d301a6.js";import{Action as r,ElementIDUtils as n,ApplicationContext as d,StringUtils as o}from"@sankhyalabs/core";import{T as h}from"./p-7e7a7473.js";import{C as l}from"./p-3287a6cc.js";import{P as c}from"./p-30cf616e.js";import{T as u,o as g,b as T}from"./p-c2495304.js";import{s as m}from"./p-6dc031de.js";import{C as k,S as E,a as f,R as v}from"./p-76a65660.js";import{SelectionMode as p}from"@sankhyalabs/core/dist/dataunit/DataUnit";import"./p-594bc21d.js";import"./p-25f1fc39.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-091ce761.js";import"./p-ff1990ad.js";import"./p-181975f1.js";import{g as R}from"./p-9863d682.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";class O extends k{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 R(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 b=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this._customEditors=new Map,this._customRenders=new Map,this._topTaskbarProcessor=new u({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.singleTaskbar":[],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE"],"snkGridTopTaskbar.finish_edition.secondary":[],"snkGridTopTaskbar.finish_edition.singleTaskbar":[]}),this._headerTaskbarProcessor=new u({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON","MORE_OPTIONS"],"snkGridHeaderTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"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.dataUnitInterceptor={interceptAction:async i=>i.type===r.METADATA_LOADED?await this.interceptMetadataLoaded(i):i},this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this._showSnkFilterBar=!0,this.columnFilterDataSource=new E,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=c.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}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 findColumn(){await g(this._moreOptions,this._columnSearch)}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 handleGridLegacyConfigName(i,t){i&&i!==t&&(this.addGridLegacyConfigName(),this.loadConfig())}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,f.assertDefaultSorting(this._gridConfig,this._dataUnit)}loadConfig(){l.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(i)})).catch((i=>{console.warn(i)}))}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&l.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}gridConfigChangeHandler(i){l.saveGridConfig(i.detail,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){const i=new O(this._dataUnit,this._grid);m.set("exporterProviders",Object.assign(Object.assign({},m.get("exporterProviders")),{[this.configName]:i}))}addElementID(){n.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}finishLoading(){this._dataUnit.addInterceptor(this.dataUnitInterceptor),f.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 v,this.addGridLegacyConfigName(),this.loadConfig()}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.loadGridCustomFormatters(this._dataUnit.metadata.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(h.CLONE,"ATTACH"),this._dataState.selectionInfo.isAllRecords()&&t.push("REMOVE")),t}getInvisibleButtons(){let i=[];return this._dataUnit&&0!==this._dataUnit.records.length||i.push("DATA_EXPORTER"),this._dataState&&this._dataState.selectionInfo.mode===p.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}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 a=s?`${e}.selected`:`${e}.unselected`;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)&&this.presentationMode===c.SINGLE_TASKBAR&&(a="snkGridHeaderTaskbar.singleTaskbar.finish_edition"),a}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,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=T(t,(({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}))))}))}))),(t=>{null!=t&&(this._grid.locateColumn(t.value),i.hideActions())}))),this._columnSearch}getActionsList(){const i=[{value:o.generateUUID(),label:this.messagesBuilder.getMessage("snkGrid.findColumn",{}),disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this.getColumnSearch(i,t)}];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)}handleFilterConfigUpdated(i){this._showSnkFilterBar=!!i.length&&(1!==i.length||"PERSONALIZED_FILTER_GROUP"!==i[0].id||i[0].groupedItems.length>0)}render(){if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large"},s("div",{class:"snk-grid__header ez-margin-bottom--medium"},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}),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","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"},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===c.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)},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},s("snk-taskbar",{id:"teste",dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this._headerTaskbarProcessor.buttons,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},s("slot",{name:this.gridHeaderCustomSlotId}))),s("div",{class:"ez-col ez-col--sd-12"},s("slot",{name:"SnkGridFooter"})),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._popUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(n.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return a(this)}static get watchers(){return{gridLegacyConfigName:["handleGridLegacyConfigName"]}}};b.style=".sc-snk-grid-h{--snk-grid-min-height:300px}.snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%}.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}";export{b as snk_grid}
|
@@ -1 +1 @@
|
|
1
|
-
import{r as i,c as t,h as s,g as e}from"./p-d2d301a6.js";import{UserInterface as o,StringUtils as n,ApplicationContext as h,ObjectUtils as a,DataType as r,JSUtils as d,FloatingManager as l,ElementIDUtils as u}from"@sankhyalabs/core";import{CSSVarsUtils as c}from"@sankhyalabs/ezui/dist/collection/utils";import{d as m,S as v}from"./p-b0ef4383.js";import{T as f}from"./p-7e7a7473.js";import"./p-dc7c9047.js";import"./p-af8efd95.js";import{C as p,S as g,R as C,a as S}from"./p-3a212712.js";import{D as k,P as b}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{I as y}from"./p-fe79f83a.js";import"./p-ff1990ad.js";import{F as w}from"./p-df5451c7.js";import{T as E,b as _,o as T}from"./p-c2495304.js";import{C as I}from"./p-52920496.js";import{S as F}from"./p-2a408684.js";import{g as R}from"./p-9863d682.js";import{s as D}from"./p-6dc031de.js";import"./p-8d884fab.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";const z=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","MORE_OPTIONS"],O=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER","MORE_OPTIONS"];class M extends p{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 R(this.dataUnit)}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__}async getRecords(){if(0===this.dataUnit.records.length)return Promise.resolve([]);const i=this.dataUnit.getSelectionInfo(),t=i.isEmpty()||i.isAllRecords()?await i.getAllRecords():i.records;return Promise.resolve(null==t?[]:t)}getHiddenOptions(){return[k.EXPORT_BY_EMAIL,k.EXPORT_PDF_TO_EMAIL,k.EXPORT_XLS_TO_EMAIL,k.EXPORT_PAGE_TO_PDF,k.EXPORT_PAGE_TO_XLS]}formatValue(i,t){const{id:s,descriptionFrom:e}=t,n=i[e||s];if(null==n)return"";if(null!=e)return n.label;if(this.dataUnit.getField(s).userInterface===o.SEARCH)return n.value;if(t.customFormatter){const s=this.getColumnsState().find((i=>t.id===i.name));return t.customFormatter.format(n,s,i.__record__id__)}return this.dataUnit.getFormattedValue(s,n)}}const P=class{constructor(s){i(this,s),this.dataStateChange=t(this,"dataStateChange",3),this.dataUnitReady=t(this,"dataUnitReady",3),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this.configuratorSave=t(this,"configuratorSave",7),this.configuratorCancel=t(this,"configuratorCancel",7),this._multiSelectionListDataSource=new g,this._keyDownHandler=i=>this.keyDownListener(i),this._formConfigFetcher=new w,this._customEditors=new Map,this._customRenders=new Map,this._taskbarProcessor=new E({"snkSimpleCrudTaskbar.form_regular":this.getButtons(!1,[f.GRID_MODE]),"snkSimpleCrudTaskbar.grid_regular":this.getButtons(!1,[f.DATA_EXPORTER,f.FORM_MODE]),"snkSimpleCrudTaskbar.form_selected":this.getButtons(!0,[f.GRID_MODE]),"snkSimpleCrudTaskbar.grid_selected":this.getButtons(!0,[f.DATA_EXPORTER,f.FORM_MODE]),"snkSimpleCrudTaskbar.finish_edition":["CANCEL","SAVE"]}),this._showPopUpGridConfig=!1,this._showFormConfig=!1,this._currentViewMode=m.GRID,this._config=void 0,this._fieldToGetFocus=void 0,this._customContainerId=`SNK-SIMPLE-CRUD-CUSTOM-CONTAINER-${n.generateUUID()}`,this.dataState=void 0,this.dataUnit=void 0,this.entityName=void 0,this.mode=v.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this._formFields=[],this._fieldsProps=new Map,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.pageSize=150,this.resourceID=void 0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.actionsList=void 0,this.configName=void 0,this.showConfiguratorButtons=void 0,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.ignoreReadOnlyFormFields=!1,this.autoFocus=!0,this.domainMessagesBuilder=void 0,this.autoLoad=void 0}async addCustomEditor(i,t){if(this._grid&&this._form)return this._grid.addCustomEditor(i,t),void this._form.addCustomEditor(i,t);const s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async addGridCustomRender(i,t){if(this._grid)return void this._grid.addGridCustomRender(i,t);const s=new Map(this._customRenders);s.set(i,t),this._customRenders=s}handleResourceIDChanged(i,t){n.isEmpty(i)||i!==t&&(this.loadFormConfig(!0),this.loadGridConfig(!0))}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFieldProp(i,t,s){const e=new Map(this._fieldsProps),o=this._fieldsProps.get(i);e.set(i,Object.assign(Object.assign({},o),{[t]:s})),this._fieldsProps=e}getButtons(i,t){return this.addConfigButton(this.resolveInMemoryBtns(i?O:z).concat(t))}addConfigButton(i){return void 0===this.configName?i:i.concat(f.CONFIGURATOR)}get application(){return h.getContextValue("__SNK__APPLICATION__")}resolveInMemoryBtns(i){const t=[...i];return this.mode===v.IN_MEMORY&&t.splice(1,1),t}async goToView(i){this._currentViewMode=i,this._viewStack&&this._viewStack.show(i)}actionClickListener(i){const t=i.detail;t===f.CONFIGURATOR?this._snkConfigurator.open():t===f.GRID_MODE?this.goToView(m.GRID):t===f.FORM_MODE&&this.goToView(m.FORM),i.stopPropagation()}async onChangeEntityName(i){if(this.dataUnit)return;const t=h.getContextValue("__SNK__APPLICATION__");this.dataUnit=await t.getDataUnit(i,null,null,this.configName)}onModeChange(){this.mode==v.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(i,t){this.handleDataStateChange(i,t)}async observeFormLegacy(i,t){await this.handleUpdateFormLegacyConfig(i,t)}async observeGridLegacy(i,t){await this.handleUpdateGridLegacyConfig(i,t)}async handleDataStateChange(i,t){a.objectToString(t)!=a.objectToString(i)&&this.dataStateChange.emit(i),await this.processRmPrecision()}async processRmPrecision(){var i,t;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const e of s||[]){if(!e)continue;const s=null===(t=null===(i=this.dataState)||void 0===i?void 0:i.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",e);(s||0===s)&&(await this.setFieldProp(e,"precision",s),await this.setFieldProp(e,"prettyPrecision",s))}this._rmPrecisionCustomValueFormatter.setDataState(this.dataState)}async handleUpdateGridLegacyConfig(i,t){null!=i&&i!=t&&this._gridConfigAlreadyLoaded&&await this.loadGridConfig(!0)}async handleUpdateFormLegacyConfig(i,t){null!=i&&i!=t&&this._formConfigAlreadyLoaded&&this.loadFormConfig(!0)}openConfig(i){this._snkConfigurator.close(),i===m.GRID?this.openGridConfig():i===m.FORM&&this.openFormConfig()}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._showPopUpGridConfig=!0}))}async openFormConfig(){var i,t;if(this.formLegacyConfigName){const s=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.formConfigUnavaliable.title",void 0),e=null===(t=this.messagesBuilder)||void 0===t?void 0:t.getMessage("snkSimpleCrud.formConfigUnavaliable.message",void 0);await this.application.alert(s,e)}else this._showFormConfig=!0}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&I.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}loadGridConfig(i){if(void 0!==this.configName&&(null==this.gridConfig&&!this._gridConfigAlreadyLoaded||i))return this.addGridLegacyConfigName(),this._gridConfigAlreadyLoaded=!0,new Promise(((i,t)=>{I.loadGridConfig(this.configName,this.resolveResourceID()).then((t=>{this.setGridConfig(t),i()})).catch((i=>{t(i)}))}))}formConfigIsLoaded(){return null!=this.formConfig||this._formConfigAlreadyLoaded}async loadFormConfig(i=!1){if(void 0===this.configName)return;if(null==this._formConfigManager&&(this._formConfigManager=new F(this.configName,this.resolveResourceID()),this._formConfigManager.setConfig(this.formConfig)),this.formConfigIsLoaded()&&!i)return;this._formConfigAlreadyLoaded=!0;let t=await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);if(null!=t)return this._formConfigManager.setConfig(t),void this.setFormConfig(t);this.setFormConfig(await this._formConfigManager.loadConfig())}async componentWillRender(){this._resourceID=await this.application.getResourceID(),this.dataExporterProviderStore(),this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons()),void 0!==this.configName&&(null!=this.gridConfig||this._gridConfigAlreadyLoaded||(await this.addGridLegacyConfigName(),this.loadGridConfig(),this.loadFormConfig()))}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.addGridCustomValueFormattters(),this.setFieldsProps(),this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource(),this._rmPrecisionCustomValueFormatter=new C}componentDidLoad(){c.applyVarsGrid(this._element,this._grid)}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t),this._customRenders.delete(i)}setCustomEditors(){if(this._grid&&this._form)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t),this._form.addCustomEditor(i,t),this._customEditors.delete(i)}configDatasource(){this._multiSelectionListDataSource.setApplication(this.application),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}setFieldsProps(){if(this._form)for(const[i,t]of this._fieldsProps){for(const s in t)this._form.setFieldProp(i,s,t[s]);this._fieldsProps.delete(i)}}getTaskBarId(){var i,t;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkSimpleCrudTaskbar.finish_edition":(null===(t=this.dataState)||void 0===t?void 0:t.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&this.dataState.selectionInfo.length>0?this._currentViewMode===m.GRID?"snkSimpleCrudTaskbar.grid_selected":"snkSimpleCrudTaskbar.form_selected":this._currentViewMode===m.GRID?"snkSimpleCrudTaskbar.grid_regular":"snkSimpleCrudTaskbar.form_regular"}initInMemoryDataUnit(){this._inMemoryLoader=new y(this._metadata,void 0,{autoLoad:this.autoLoad}),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(i){return this._inMemoryLoader?this._inMemoryLoader.metadata=i:this.dataUnit&&(this.dataUnit.metadata=i),Promise.resolve()}setRecords(i){return this._inMemoryLoader?this._inMemoryLoader.records=i:this.dataUnit&&(this.dataUnit.records=i),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}async openConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.open()}async closeConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.close()}async updateConfig(){null==this._formConfigManager&&(this._formConfigManager=new F(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}processMetadata(){const i=this._element.querySelectorAll("snk-field-metadata"),t=[],s={fields:[],emptyConfig:!1};i.forEach((i=>{const e={name:i.getAttribute("name")||i.getAttribute("label"),label:i.getAttribute("label"),dataType:r[i.getAttribute("dataType")]||r.TEXT,userInterface:o[i.getAttribute("userInterface")]||o.SHORTTEXT,readOnly:"true"==i.getAttribute("readOnly"),required:"true"==i.getAttribute("required"),tab:i.getAttribute("tab")||void 0,visible:"false"!=i.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),t.push(e)})),t.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:t})}addGridCustomValueFormattters(){var i,t,s;const e=(null===(i=this._metadata)||void 0===i?void 0:i.fields)||(null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)||void 0===s?void 0:s.fields);if(!e)return;const o=[];e.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&!o.includes(i.name)&&o.push(i.name)})),o.forEach((i=>{this.addCustomValueFormatter(i,this._rmPrecisionCustomValueFormatter)}))}onDataStateChange(i){this.dataState=Object.assign({},i.detail)}getTaskBarDisabledButtons(){var i,t,s,e,o,n;const h=[];return(null===(i=this.dataState)||void 0===i?void 0:i.hasNext)||h.push(f.NEXT),(null===(t=this.dataState)||void 0===t?void 0:t.hasPrevious)||h.push(f.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&h.push(f.FORM_MODE),(null===(n=null===(o=this.dataState)||void 0===o?void 0:o.selectionInfo)||void 0===n?void 0:n.length)>1&&h.push(f.CLONE),h}handleCancelEdit(){var i;(null===(i=this.dataState)||void 0===i?void 0:i.recordsIsEmpty)&&(this.goToView(m.GRID),this.dataUnit.clearSelection())}handleConfiguratorEvent(i,t){i.stopImmediatePropagation(),"SAVE"!==t?this.configuratorCancel.emit():this.configuratorSave.emit()}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=_(t,(({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}))))}))}))),(t=>{var s;null!=t&&(this._grid.locateColumn(t.value),null===(s=i.hideActions)||void 0===s||s.call(i))}))),this._columnSearch}onSelectField(i,t){null!=i&&(this._fieldToGetFocus=i.value,t.hideActions())}getFieldSearch(i,t){return null!=this._fieldSearch||(this._moreOptions=i,i.addEventListener("ezPopoverOpen",(()=>this.findField())),this._fieldSearch=_(t,(({argument:i})=>this.fieldsOptionLoader(i)),(t=>this.onSelectField(t,i)))),this._fieldSearch}getFormFields(){var i,t;return null!==(t=null===(i=this.formConfig)||void 0===i?void 0:i.fields)&&void 0!==t?t:this._formFields}handleFormSetFields(i){a.equals(this._formFields,i)||(this._formFields=null!=i?i:[])}fieldsOptionLoader(i){const t=null==i?void 0:i.toLowerCase(),s=this.getFormFields().map((i=>{var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i.name)})).filter((i=>{var s,e;return(null===(s=i.name)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(e=i.label)||void 0===e?void 0:e.toLowerCase().includes(t))})).map((i=>({value:i.name,label:i.label})));return Promise.resolve(s)}getActionsList(){var i,t;const s=[{value:n.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.findColumn",void 0))&&void 0!==t?t:"Buscar",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this._currentViewMode===m.GRID?this.getColumnSearch(i,t):this.getFieldSearch(i,t)}];if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const i=this.getTopTaskBarId();return s.concat(this.taskbarManager.getMoreOptions(i,this.configName,this.dataState,this.actionsList))}return s.concat(this.actionsList)}getTopTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${b.PRIMARY}`:`snkGridTopTaskbar.regular${b.PRIMARY}`}async keyDownListener(i){i.ctrlKey&&null!=i.key&&"F"===i.key.toUpperCase()&&null!=this._element&&(d.isHiddenElement(this._element)||(l.closeAll(),this._currentViewMode===m.GRID?await this.findColumn():await this.findField(),i.preventDefault()))}async findField(){await this.openSeach(this._fieldSearch)}async findColumn(){await this.openSeach(this._columnSearch)}async openSeach(i){await T(this._moreOptions,i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}connectedCallback(){window.addEventListener("keydown",this._keyDownHandler,{capture:!0})}disconnectedCallback(){window.removeEventListener("keydown",this._keyDownHandler)}gridConfigChangeHandler(i){I.saveGridConfig(i.detail,this.configName,this.resolveResourceID()),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){if(null==this.dataUnit)return;if(null==this._grid)return;const i=new M(this.dataUnit,this._grid);D.set("exporterProviders",Object.assign(Object.assign({},D.get("exporterProviders")),{[this.getDataExporterStoreKey()]:i}))}getDataExporterStoreKey(){return`SnkSimpleCrudDataExporter:${null==this.configName?this.dataUnit.name:this.configName}`}setGridConfig(i){this.gridConfig=i,S.assertDefaultSorting(this.gridConfig,this.dataUnit)}setFormConfig(i,t){this.formConfig&&!t||(this.formConfig=i)}closeGridConfig(){this._showPopUpGridConfig=!1}closeFormConfig(){this._showFormConfig=!1}getPageSize(){return this.mode===v.IN_MEMORY?0:null==this.pageSize?150:this.pageSize}handleShowFormConfig(){return this._showFormConfig&&!this.formLegacyConfigName}resolveResourceID(){return n.isEmpty(this.resourceID)?this._resourceID:this.resourceID}getFormConfig(){var i;const t=null===(i=this._formConfigManager)||void 0===i?void 0:i.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return this.configName||t?t:this.formConfig}updateFormConfig(){const i=Object.assign(Object.assign({},this.formConfig),{fields:this.dataUnit.metadata.fields});this.setFormConfig(i,!0),null==this._formConfigManager&&(this._formConfigManager=new F(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}render(){var i;if(null!=this.dataUnit)return s("snk-data-unit",{ref:i=>this._snkDataUnit=i,class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:i=>this.onDataStateChange(i),onCancelEdition:this.handleCancelEdit.bind(this),pageSize:this.getPageSize(),onInsertionMode:()=>this.goToView(m.FORM),onDataUnitReady:i=>this.dataUnitReady.emit(i.detail),ignoreSaveMessage:this._currentViewMode===m.GRID,onMessagesBuilderUpdated:i=>this.messagesBuilder=i.detail,onDataUnitFieldsHidded:this.updateFormConfig.bind(this),domainMessagesBuilder:this.domainMessagesBuilder},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:"ez-box ez-box--shadow simple-crud__container-section"},s("snk-taskbar",{class:"ez-box ez-box--shadow ez-padding--medium",dataUnit:this.dataUnit,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-element-id":"grid_left",messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,actionsList:this.getActionsList(),disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,"data-exporter-store-key":this.getDataExporterStoreKey(),slot:"leftButtons",presentationMode:b.SECONDARY},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"})),s("ez-view-stack",{ref:i=>this._viewStack=i,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{class:"ez-margin-bottom--large",ref:i=>this._grid=i,dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(m.FORM),onConfigChange:i=>this.gridConfigChangeHandler(i),columnfilterDataSource:this.dataUnit.name&&this.dataUnit.name.includes(y.IN_MEMORY_DATA_UNIT_NAME)?void 0:this._multiSelectionListDataSource,useEnterLikeTab:this.useEnterLikeTab,autoFocus:this.autoFocus},s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,s("ez-form",{ref:i=>this._form=i,class:"ez-margin-top--large "+(this.handleShowFormConfig()?"simple-crud__form--hidden":""),dataUnit:this.dataUnit,config:this.getFormConfig(),fieldToFocus:this._fieldToGetFocus,onEzFormSetFields:i=>this.handleFormSetFields(i.detail),onEzFormRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this)}),this.handleShowFormConfig()&&s("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,configManager:this._formConfigManager,onConfigClose:()=>this.closeFormConfig()})),this.messagesBuilder&&s("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:i=>this.goToView(i.detail),onOpenConfig:i=>this.openConfig(i.detail),showActionButtons:this.showConfiguratorButtons,onSave:i=>this.handleConfiguratorEvent(i,"SAVE"),onCancel:i=>this.handleConfiguratorEvent(i,"CANCEL"),resourceID:this.resolveResourceID(),customContainerId:this._customContainerId})),s("div",{id:`${this._customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}))),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._showPopUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this.gridConfig,"data-element-id":this._element.getAttribute(u.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resolveResourceID()})))}get _element(){return e(this)}static get watchers(){return{resourceID:["handleResourceIDChanged"],entityName:["onChangeEntityName"],mode:["onModeChange"],dataState:["observeDataState"],formLegacyConfigName:["observeFormLegacy"],gridLegacyConfigName:["observeGridLegacy"]}}};P.style=".sc-snk-simple-crud-h{display:flex;height:100%;width:100%;--snk-simple-crud-grid--min-height:300px}.simple-crud__container.sc-snk-simple-crud{display:grid;grid-template-rows:auto 1fr;row-gap:12px;height:100%;width:100%}.simple-crud__container-section.sc-snk-simple-crud{flex-wrap:unset;flex-direction:column}.simple-crud__form--hidden.sc-snk-simple-crud{display:none}ez-grid.sc-snk-simple-crud{--ez-grid__container--shadow:none;--ez-grid--min-height:var(--snk-simple-crud-grid--min-height)}ez-form.sc-snk-simple-crud{min-height:300px}";export{P as snk_simple_crud}
|
1
|
+
import{r as i,c as t,h as s,g as e}from"./p-d2d301a6.js";import{UserInterface as o,StringUtils as n,ApplicationContext as h,ObjectUtils as a,DataType as r,JSUtils as d,FloatingManager as l,ElementIDUtils as u}from"@sankhyalabs/core";import{CSSVarsUtils as c}from"@sankhyalabs/ezui/dist/collection/utils";import{d as m,S as v}from"./p-b0ef4383.js";import{T as f}from"./p-7e7a7473.js";import"./p-594bc21d.js";import"./p-25f1fc39.js";import{C as p,S as g,R as C,a as S}from"./p-76a65660.js";import{D as k,P as b}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{I as y}from"./p-091ce761.js";import"./p-ff1990ad.js";import{F as w}from"./p-181975f1.js";import{T as E,b as _,o as T}from"./p-c2495304.js";import{C as I}from"./p-3287a6cc.js";import{S as F}from"./p-5f016aed.js";import{g as R}from"./p-9863d682.js";import{s as D}from"./p-6dc031de.js";import"./p-8d884fab.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";const z=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","MORE_OPTIONS"],O=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER","MORE_OPTIONS"];class M extends p{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 R(this.dataUnit)}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__}async getRecords(){if(0===this.dataUnit.records.length)return Promise.resolve([]);const i=this.dataUnit.getSelectionInfo(),t=i.isEmpty()||i.isAllRecords()?await i.getAllRecords():i.records;return Promise.resolve(null==t?[]:t)}getHiddenOptions(){return[k.EXPORT_BY_EMAIL,k.EXPORT_PDF_TO_EMAIL,k.EXPORT_XLS_TO_EMAIL,k.EXPORT_PAGE_TO_PDF,k.EXPORT_PAGE_TO_XLS]}formatValue(i,t){const{id:s,descriptionFrom:e}=t,n=i[e||s];if(null==n)return"";if(null!=e)return n.label;if(this.dataUnit.getField(s).userInterface===o.SEARCH)return n.value;if(t.customFormatter){const s=this.getColumnsState().find((i=>t.id===i.name));return t.customFormatter.format(n,s,i.__record__id__)}return this.dataUnit.getFormattedValue(s,n)}}const P=class{constructor(s){i(this,s),this.dataStateChange=t(this,"dataStateChange",3),this.dataUnitReady=t(this,"dataUnitReady",3),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this.configuratorSave=t(this,"configuratorSave",7),this.configuratorCancel=t(this,"configuratorCancel",7),this._multiSelectionListDataSource=new g,this._keyDownHandler=i=>this.keyDownListener(i),this._formConfigFetcher=new w,this._customEditors=new Map,this._customRenders=new Map,this._taskbarProcessor=new E({"snkSimpleCrudTaskbar.form_regular":this.getButtons(!1,[f.GRID_MODE]),"snkSimpleCrudTaskbar.grid_regular":this.getButtons(!1,[f.DATA_EXPORTER,f.FORM_MODE]),"snkSimpleCrudTaskbar.form_selected":this.getButtons(!0,[f.GRID_MODE]),"snkSimpleCrudTaskbar.grid_selected":this.getButtons(!0,[f.DATA_EXPORTER,f.FORM_MODE]),"snkSimpleCrudTaskbar.finish_edition":["CANCEL","SAVE"]}),this._showPopUpGridConfig=!1,this._showFormConfig=!1,this._currentViewMode=m.GRID,this._config=void 0,this._fieldToGetFocus=void 0,this._customContainerId=`SNK-SIMPLE-CRUD-CUSTOM-CONTAINER-${n.generateUUID()}`,this.dataState=void 0,this.dataUnit=void 0,this.entityName=void 0,this.mode=v.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this._formFields=[],this._fieldsProps=new Map,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.pageSize=150,this.resourceID=void 0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.actionsList=void 0,this.configName=void 0,this.showConfiguratorButtons=void 0,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.ignoreReadOnlyFormFields=!1,this.autoFocus=!0,this.domainMessagesBuilder=void 0,this.autoLoad=void 0}async addCustomEditor(i,t){if(this._grid&&this._form)return this._grid.addCustomEditor(i,t),void this._form.addCustomEditor(i,t);const s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async addGridCustomRender(i,t){if(this._grid)return void this._grid.addGridCustomRender(i,t);const s=new Map(this._customRenders);s.set(i,t),this._customRenders=s}handleResourceIDChanged(i,t){n.isEmpty(i)||i!==t&&(this.loadFormConfig(!0),this.loadGridConfig(!0))}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFieldProp(i,t,s){const e=new Map(this._fieldsProps),o=this._fieldsProps.get(i);e.set(i,Object.assign(Object.assign({},o),{[t]:s})),this._fieldsProps=e}getButtons(i,t){return this.addConfigButton(this.resolveInMemoryBtns(i?O:z).concat(t))}addConfigButton(i){return void 0===this.configName?i:i.concat(f.CONFIGURATOR)}get application(){return h.getContextValue("__SNK__APPLICATION__")}resolveInMemoryBtns(i){const t=[...i];return this.mode===v.IN_MEMORY&&t.splice(1,1),t}async goToView(i){this._currentViewMode=i,this._viewStack&&this._viewStack.show(i)}actionClickListener(i){const t=i.detail;t===f.CONFIGURATOR?this._snkConfigurator.open():t===f.GRID_MODE?this.goToView(m.GRID):t===f.FORM_MODE&&this.goToView(m.FORM),i.stopPropagation()}async onChangeEntityName(i){if(this.dataUnit)return;const t=h.getContextValue("__SNK__APPLICATION__");this.dataUnit=await t.getDataUnit(i,null,null,this.configName)}onModeChange(){this.mode==v.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(i,t){this.handleDataStateChange(i,t)}async observeFormLegacy(i,t){await this.handleUpdateFormLegacyConfig(i,t)}async observeGridLegacy(i,t){await this.handleUpdateGridLegacyConfig(i,t)}async handleDataStateChange(i,t){a.objectToString(t)!=a.objectToString(i)&&this.dataStateChange.emit(i),await this.processRmPrecision()}async processRmPrecision(){var i,t;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const e of s||[]){if(!e)continue;const s=null===(t=null===(i=this.dataState)||void 0===i?void 0:i.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",e);(s||0===s)&&(await this.setFieldProp(e,"precision",s),await this.setFieldProp(e,"prettyPrecision",s))}this._rmPrecisionCustomValueFormatter.setDataState(this.dataState)}async handleUpdateGridLegacyConfig(i,t){null!=i&&i!=t&&this._gridConfigAlreadyLoaded&&await this.loadGridConfig(!0)}async handleUpdateFormLegacyConfig(i,t){null!=i&&i!=t&&this._formConfigAlreadyLoaded&&this.loadFormConfig(!0)}openConfig(i){this._snkConfigurator.close(),i===m.GRID?this.openGridConfig():i===m.FORM&&this.openFormConfig()}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._showPopUpGridConfig=!0}))}async openFormConfig(){var i,t;if(this.formLegacyConfigName){const s=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.formConfigUnavaliable.title",void 0),e=null===(t=this.messagesBuilder)||void 0===t?void 0:t.getMessage("snkSimpleCrud.formConfigUnavaliable.message",void 0);await this.application.alert(s,e)}else this._showFormConfig=!0}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&I.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}loadGridConfig(i){if(void 0!==this.configName&&(null==this.gridConfig&&!this._gridConfigAlreadyLoaded||i))return this.addGridLegacyConfigName(),this._gridConfigAlreadyLoaded=!0,new Promise(((i,t)=>{I.loadGridConfig(this.configName,this.resolveResourceID()).then((t=>{this.setGridConfig(t),i()})).catch((i=>{t(i)}))}))}formConfigIsLoaded(){return null!=this.formConfig||this._formConfigAlreadyLoaded}async loadFormConfig(i=!1){if(void 0===this.configName)return;if(null==this._formConfigManager&&(this._formConfigManager=new F(this.configName,this.resolveResourceID()),this._formConfigManager.setConfig(this.formConfig)),this.formConfigIsLoaded()&&!i)return;this._formConfigAlreadyLoaded=!0;let t=await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);if(null!=t)return this._formConfigManager.setConfig(t),void this.setFormConfig(t);this.setFormConfig(await this._formConfigManager.loadConfig())}async componentWillRender(){this._resourceID=await this.application.getResourceID(),this.dataExporterProviderStore(),this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons()),void 0!==this.configName&&(null!=this.gridConfig||this._gridConfigAlreadyLoaded||(await this.addGridLegacyConfigName(),this.loadGridConfig(),this.loadFormConfig()))}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.addGridCustomValueFormattters(),this.setFieldsProps(),this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource(),this._rmPrecisionCustomValueFormatter=new C}componentDidLoad(){c.applyVarsGrid(this._element,this._grid)}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t),this._customRenders.delete(i)}setCustomEditors(){if(this._grid&&this._form)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t),this._form.addCustomEditor(i,t),this._customEditors.delete(i)}configDatasource(){this._multiSelectionListDataSource.setApplication(this.application),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}setFieldsProps(){if(this._form)for(const[i,t]of this._fieldsProps){for(const s in t)this._form.setFieldProp(i,s,t[s]);this._fieldsProps.delete(i)}}getTaskBarId(){var i,t;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkSimpleCrudTaskbar.finish_edition":(null===(t=this.dataState)||void 0===t?void 0:t.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&this.dataState.selectionInfo.length>0?this._currentViewMode===m.GRID?"snkSimpleCrudTaskbar.grid_selected":"snkSimpleCrudTaskbar.form_selected":this._currentViewMode===m.GRID?"snkSimpleCrudTaskbar.grid_regular":"snkSimpleCrudTaskbar.form_regular"}initInMemoryDataUnit(){this._inMemoryLoader=new y(this._metadata,void 0,{autoLoad:this.autoLoad}),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(i){return this._inMemoryLoader?this._inMemoryLoader.metadata=i:this.dataUnit&&(this.dataUnit.metadata=i),Promise.resolve()}setRecords(i){return this._inMemoryLoader?this._inMemoryLoader.records=i:this.dataUnit&&(this.dataUnit.records=i),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}async openConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.open()}async closeConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.close()}async updateConfig(){null==this._formConfigManager&&(this._formConfigManager=new F(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}processMetadata(){const i=this._element.querySelectorAll("snk-field-metadata"),t=[],s={fields:[],emptyConfig:!1};i.forEach((i=>{const e={name:i.getAttribute("name")||i.getAttribute("label"),label:i.getAttribute("label"),dataType:r[i.getAttribute("dataType")]||r.TEXT,userInterface:o[i.getAttribute("userInterface")]||o.SHORTTEXT,readOnly:"true"==i.getAttribute("readOnly"),required:"true"==i.getAttribute("required"),tab:i.getAttribute("tab")||void 0,visible:"false"!=i.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),t.push(e)})),t.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:t})}addGridCustomValueFormattters(){var i,t,s;const e=(null===(i=this._metadata)||void 0===i?void 0:i.fields)||(null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)||void 0===s?void 0:s.fields);if(!e)return;const o=[];e.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&!o.includes(i.name)&&o.push(i.name)})),o.forEach((i=>{this.addCustomValueFormatter(i,this._rmPrecisionCustomValueFormatter)}))}onDataStateChange(i){this.dataState=Object.assign({},i.detail)}getTaskBarDisabledButtons(){var i,t,s,e,o,n;const h=[];return(null===(i=this.dataState)||void 0===i?void 0:i.hasNext)||h.push(f.NEXT),(null===(t=this.dataState)||void 0===t?void 0:t.hasPrevious)||h.push(f.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&h.push(f.FORM_MODE),(null===(n=null===(o=this.dataState)||void 0===o?void 0:o.selectionInfo)||void 0===n?void 0:n.length)>1&&h.push(f.CLONE),h}handleCancelEdit(){var i;(null===(i=this.dataState)||void 0===i?void 0:i.recordsIsEmpty)&&(this.goToView(m.GRID),this.dataUnit.clearSelection())}handleConfiguratorEvent(i,t){i.stopImmediatePropagation(),"SAVE"!==t?this.configuratorCancel.emit():this.configuratorSave.emit()}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=_(t,(({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}))))}))}))),(t=>{var s;null!=t&&(this._grid.locateColumn(t.value),null===(s=i.hideActions)||void 0===s||s.call(i))}))),this._columnSearch}onSelectField(i,t){null!=i&&(this._fieldToGetFocus=i.value,t.hideActions())}getFieldSearch(i,t){return null!=this._fieldSearch||(this._moreOptions=i,i.addEventListener("ezPopoverOpen",(()=>this.findField())),this._fieldSearch=_(t,(({argument:i})=>this.fieldsOptionLoader(i)),(t=>this.onSelectField(t,i)))),this._fieldSearch}getFormFields(){var i,t;return null!==(t=null===(i=this.formConfig)||void 0===i?void 0:i.fields)&&void 0!==t?t:this._formFields}handleFormSetFields(i){a.equals(this._formFields,i)||(this._formFields=null!=i?i:[])}fieldsOptionLoader(i){const t=null==i?void 0:i.toLowerCase(),s=this.getFormFields().map((i=>{var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i.name)})).filter((i=>{var s,e;return(null===(s=i.name)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(e=i.label)||void 0===e?void 0:e.toLowerCase().includes(t))})).map((i=>({value:i.name,label:i.label})));return Promise.resolve(s)}getActionsList(){var i,t;const s=[{value:n.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.findColumn",void 0))&&void 0!==t?t:"Buscar",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this._currentViewMode===m.GRID?this.getColumnSearch(i,t):this.getFieldSearch(i,t)}];if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const i=this.getTopTaskBarId();return s.concat(this.taskbarManager.getMoreOptions(i,this.configName,this.dataState,this.actionsList))}return s.concat(this.actionsList)}getTopTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${b.PRIMARY}`:`snkGridTopTaskbar.regular${b.PRIMARY}`}async keyDownListener(i){i.ctrlKey&&null!=i.key&&"F"===i.key.toUpperCase()&&null!=this._element&&(d.isHiddenElement(this._element)||(l.closeAll(),this._currentViewMode===m.GRID?await this.findColumn():await this.findField(),i.preventDefault()))}async findField(){await this.openSeach(this._fieldSearch)}async findColumn(){await this.openSeach(this._columnSearch)}async openSeach(i){await T(this._moreOptions,i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}connectedCallback(){window.addEventListener("keydown",this._keyDownHandler,{capture:!0})}disconnectedCallback(){window.removeEventListener("keydown",this._keyDownHandler)}gridConfigChangeHandler(i){I.saveGridConfig(i.detail,this.configName,this.resolveResourceID()),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){if(null==this.dataUnit)return;if(null==this._grid)return;const i=new M(this.dataUnit,this._grid);D.set("exporterProviders",Object.assign(Object.assign({},D.get("exporterProviders")),{[this.getDataExporterStoreKey()]:i}))}getDataExporterStoreKey(){return`SnkSimpleCrudDataExporter:${null==this.configName?this.dataUnit.name:this.configName}`}setGridConfig(i){this.gridConfig=i,S.assertDefaultSorting(this.gridConfig,this.dataUnit)}setFormConfig(i,t){this.formConfig&&!t||(this.formConfig=i)}closeGridConfig(){this._showPopUpGridConfig=!1}closeFormConfig(){this._showFormConfig=!1}getPageSize(){return this.mode===v.IN_MEMORY?0:null==this.pageSize?150:this.pageSize}handleShowFormConfig(){return this._showFormConfig&&!this.formLegacyConfigName}resolveResourceID(){return n.isEmpty(this.resourceID)?this._resourceID:this.resourceID}getFormConfig(){var i;const t=null===(i=this._formConfigManager)||void 0===i?void 0:i.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return this.configName||t?t:this.formConfig}updateFormConfig(){const i=Object.assign(Object.assign({},this.formConfig),{fields:this.dataUnit.metadata.fields});this.setFormConfig(i,!0),null==this._formConfigManager&&(this._formConfigManager=new F(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}render(){var i;if(null!=this.dataUnit)return s("snk-data-unit",{ref:i=>this._snkDataUnit=i,class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:i=>this.onDataStateChange(i),onCancelEdition:this.handleCancelEdit.bind(this),pageSize:this.getPageSize(),onInsertionMode:()=>this.goToView(m.FORM),onDataUnitReady:i=>this.dataUnitReady.emit(i.detail),ignoreSaveMessage:this._currentViewMode===m.GRID,onMessagesBuilderUpdated:i=>this.messagesBuilder=i.detail,onDataUnitFieldsHidded:this.updateFormConfig.bind(this),domainMessagesBuilder:this.domainMessagesBuilder},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:"ez-box ez-box--shadow simple-crud__container-section"},s("snk-taskbar",{class:"ez-box ez-box--shadow ez-padding--medium",dataUnit:this.dataUnit,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-element-id":"grid_left",messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,actionsList:this.getActionsList(),disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,"data-exporter-store-key":this.getDataExporterStoreKey(),slot:"leftButtons",presentationMode:b.SECONDARY},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"})),s("ez-view-stack",{ref:i=>this._viewStack=i,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{class:"ez-margin-bottom--large",ref:i=>this._grid=i,dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(m.FORM),onConfigChange:i=>this.gridConfigChangeHandler(i),columnfilterDataSource:this.dataUnit.name&&this.dataUnit.name.includes(y.IN_MEMORY_DATA_UNIT_NAME)?void 0:this._multiSelectionListDataSource,useEnterLikeTab:this.useEnterLikeTab,autoFocus:this.autoFocus},s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,s("ez-form",{ref:i=>this._form=i,class:"ez-margin-top--large "+(this.handleShowFormConfig()?"simple-crud__form--hidden":""),dataUnit:this.dataUnit,config:this.getFormConfig(),fieldToFocus:this._fieldToGetFocus,onEzFormSetFields:i=>this.handleFormSetFields(i.detail),onEzFormRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this)}),this.handleShowFormConfig()&&s("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,configManager:this._formConfigManager,onConfigClose:()=>this.closeFormConfig()})),this.messagesBuilder&&s("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:i=>this.goToView(i.detail),onOpenConfig:i=>this.openConfig(i.detail),showActionButtons:this.showConfiguratorButtons,onSave:i=>this.handleConfiguratorEvent(i,"SAVE"),onCancel:i=>this.handleConfiguratorEvent(i,"CANCEL"),resourceID:this.resolveResourceID(),customContainerId:this._customContainerId})),s("div",{id:`${this._customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}))),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._showPopUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this.gridConfig,"data-element-id":this._element.getAttribute(u.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resolveResourceID()})))}get _element(){return e(this)}static get watchers(){return{resourceID:["handleResourceIDChanged"],entityName:["onChangeEntityName"],mode:["onModeChange"],dataState:["observeDataState"],formLegacyConfigName:["observeFormLegacy"],gridLegacyConfigName:["observeGridLegacy"]}}};P.style=".sc-snk-simple-crud-h{display:flex;height:100%;width:100%;--snk-simple-crud-grid--min-height:300px}.simple-crud__container.sc-snk-simple-crud{display:grid;grid-template-rows:auto 1fr;row-gap:12px;height:100%;width:100%}.simple-crud__container-section.sc-snk-simple-crud{flex-wrap:unset;flex-direction:column}.simple-crud__form--hidden.sc-snk-simple-crud{display:none}ez-grid.sc-snk-simple-crud{--ez-grid__container--shadow:none;--ez-grid--min-height:var(--snk-simple-crud-grid--min-height)}ez-form.sc-snk-simple-crud{min-height:300px}";export{P as snk_simple_crud}
|
@@ -1 +1 @@
|
|
1
|
-
import{D as t}from"./p-
|
1
|
+
import{D as t}from"./p-594bc21d.js";import"./p-25f1fc39.js";import{SortMode as i,ApplicationContext as e,UserInterface as s,DateUtils as r,ObjectUtils as a,NumberUtils as o,DataType as n}from"@sankhyalabs/core";import"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import{UserInterface as l}from"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{P as c}from"./p-091ce761.js";import"./p-ff1990ad.js";import"./p-181975f1.js";import d from"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";class u{static assertDefaultSorting(t,e){t&&e&&(e.defaultSorting=t.columns.filter((t=>null!=t.ascending)).sort(((t,i)=>t.orderIndex-i.orderIndex)).map((({name:t,ascending:s})=>{const{dataType:r}=e.getField(t);return{field:t,dataType:r,mode:s?i.ASC:i.DESC}})))}static find(i,s,r,a=!0,o,n){let l=[],c=[],d={},u=e.getContextValue("__SNK__APPLICATION__");if(s){if(!Array.isArray(s))throw new Error(u.messagesBuilder.getMessage("crudUtils.errorArray",null));s.forEach((t=>{l.push({name:t})}))}if(r)for(const t in r)r.hasOwnProperty(t)&&c.push({nome:t,valor:r[t]});o&&(d={expression:{$:o}});let h={requestBody:{entity:{name:i,criterio:c,fields:{field:l},literalCriteria:d,orderby:n}}};return new Promise((i=>{t.get().callServiceBroker("mge@crud.find",JSON.stringify(h)).then((t=>{var e;let s=null===(e=t.entidades)||void 0===e?void 0:e.entidade;if(null!=s){let t={fields:new Map};for(let i in s){let e=s[i];if(e.hasOwnProperty("$")&&t.fields.set(i,e.$),a)break}i(t)}else i(null)}))}))}}class h{setDataUnit(t){this._dataUnit=t}setApplication(t){this._application=t}formatLabel(t,i){const{userInterface:e}=this._dataUnit.getField(t);return e===s.DATETIME?r.formatDate(this._dataUnit.valueFromString(t,i)):String(this._dataUnit.getFormattedValue(t,i))}async getStaticOptions(t){return Promise.resolve(null==t?void 0:await c.getDistinct(this._dataUnit,t))}fetchData(t,i){return new Promise((e=>{this._application.executeSelectDistinct(this._dataUnit,i,t).then((t=>{e(t.map((t=>this._dataUnit.getField(i).userInterface===s.SEARCH?Object.assign(Object.assign({},JSON.parse(t)),{check:!0}):{value:t,label:this.formatLabel(i,t),check:!0})))}))}))}sortItems(t,i){return d.defaultSorterMultSelectionOption(this._dataUnit,t,i)}}class m{setGrid(t){this._grid||(this._grid=t,this.refreshSelectedRows())}setDataState(t){a.objectToString(t)!==a.objectToString(this._dataState)&&(this._dataState=t,this.refreshSelectedRows())}format(t,i,e){var s;if(!t)return t;const r=null===(s=this._dataState)||void 0===s?void 0:s.metadataByRow.get(e),a=null==r?void 0:r.getProp("rm_precision",i.name);return a||0===a?o.format(t,a,a):t}refreshSelectedRows(){var t;null===(t=this._grid)||void 0===t||t.refreshSelectedRows()}}class f{constructor(t,i){this.dataUnit=t,this.grid=i}async getColumnsMetadata(){var t;return this.columnsState=await(null===(t=this.grid)||void 0===t?void 0:t.getColumnsState())||[],await this.buildColumnsMetadata(this.columnsState)}getColumnsState(){return this.columnsState}async buildColumnsMetadata(t){var i,e;const s=[];for(const r of t){if(r.hidden&&"RECDESP"!==r.name)continue;const t=null===(i=this.dataUnit)||void 0===i?void 0:i.getField(r.name),a=await this.grid.getCustomValueFormatter(r.name);if(s.push({label:r.label,id:r.name,width:r.width,type:null==t?void 0:t.dataType,userInterface:null==t?void 0:t.userInterface,customFormatter:a}),null!=(null===(e=null==t?void 0:t.properties)||void 0===e?void 0:e.DESCRIPTIONFIELD)){const i=t.properties.mergedFrom;s.push({label:t.properties.DESCRIPTIONENTITY,id:`${i?i+".":""}${t.properties.ENTITYNAME}.${t.properties.DESCRIPTIONFIELD}`,width:r.width,type:n.TEXT,userInterface:l.LONGTEXT,descriptionFrom:t.name})}}return s||[]}}export{f as C,m as R,h as S,u as a}
|
@@ -0,0 +1 @@
|
|
1
|
+
export{S as snk_guides_viewer}from"./p-1f35c795.js";import"./p-d2d301a6.js";import"@sankhyalabs/core";import"./p-5f016aed.js";import"./p-3287a6cc.js";import"./p-181975f1.js";import"./p-594bc21d.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ff1990ad.js";import"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-c2495304.js";import"./p-7e7a7473.js";import"./p-30cf616e.js";import"./p-6dc031de.js";import"./p-b0ef4383.js";import"./p-25f1fc39.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"./p-091ce761.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"@sankhyalabs/core/dist/dataunit/DataUnit";
|
@@ -0,0 +1 @@
|
|
1
|
+
import{ApplicationContext as e}from"@sankhyalabs/core";const a={saveInfo:{clone:"Duplicação realizada!",insert:"Inclusão realizada!",update:"Alteração realizada!"},cancelInfo:{clone:"Duplicação descartada!",insert:"A inclusão foi descartada!",update:"A edição foi descartada!"},confirm:{cancel:"Cancelar",delete:"Excluir",yes:"Sim",no:"Não"},removeInfo:"Registro removido com sucesso!",cancelConfirmationTitle:"Aviso",cancelConfirmation:"As alterações realizadas serão descartadas<br/><br/><b>Você realmente gostaria de cancelar?",removeConfirmationTitle:"Aviso",removeConfirmation:"Deseja realmente excluir o registro atual?",forbidden:"Sem permissão",forbiddenUpdate:"Não é possível fazer alterações. Verifique as permissões de acesso.",forbiddenInsert:"Não é possível incluir. Verifique as permissões de acesso.",forbiddenClone:"Não é possível duplicar. Verifique as permissões de acesso.",forbiddenRemove:"Não é possível remover. Verifique as permissões de acesso.",removeAllConfirmation:"Os <strong>{{size}} registros selecionados</strong> serão excluídos.<br/><br/><strong>Você realmente gostaria de continuar?</strong>",removeAllInfo:"Os {{size}} registros foram removidos com sucesso!",fieldNameRequired:"É necessário informar o nome da coluna."},o={addFilter:"Adicionar filtro",pinFilter:"Fixar filtro",unpinFilter:"Desfixar filtro",removeFilter:"Remover filtro",cleanFilter:"Limpar",applyFilter:"Aplicar",findFilter:"Buscar filtros...",findField:"Buscar filtros...",modalFindFilter:"Buscar filtro",emptyFiltersList:"Não há filtros disponíveis",emptyAppliedFiltersList:"Não há filtros aplicados",customFilter:"Filtro personalizado",defaultFilter:"Filtro padrão",failToLoadConfig:"Falha ao buscar configuração de filtros",clearAllFilters:"Limpar todos os filtros",successfullyCleaned:"Filtro limpo com sucesso!",activeFilter:"{{ACTIVE_FILTERS}} filtro aplicado",activeFilters:"{{ACTIVE_FILTERS}} filtros aplicados",noActiveFilters:"Nenhum filtro aplicado",modalDefaultFilterTitle:"Filtro padrão",modalInfoTextEditDefault:"Use o layout antigo para editar o seu filtro padrão, em breve traremos uma nova experiência.",modalInfoTextCreateDefault:"Use o layout antigo para criar o seu filtro padrão, em breve traremos uma nova experiência.",modalPersonalizedFilterTitle:"Filtro personalizado",modalPersonalizedFilterSubTitle:"Gerencie seus filtros",modalInfoTextCreateEditPersonalized:"Use o layout antigo para criar ou editar filtros, em breve traremos uma nova experiência",modalInfoTextCreateFilter:"Criar filtro personalizado",modalInfoTextNoFilterRegister:"Você não possui filtros cadastrados.",modalOkButtonLabel:"Aplicar",modalCancelButtonLabel:"Limpar",binarySelectTooltip:"Exibindo registros",multiListToltip:"selecionado(a)s",onlyStartToltip:"A partir de",onlyEndToltip:"Até",fullPeriodTooltip:"Data de {{LABEL}}: {{START_LABEL}} até {{END_LABEL}}",labelStart:"Inicial",labelEnd:"Final",fullIntervalTooltip:"{{LABEL}}: {{START_LABEL}} até {{END_LABEL}}",filters:"Filtros",personalizedCount:"{{activeCount}} selecionado(s)",filterModal:{title:"Filtros",okButtonLabel:"Aplicar",cancelButtonLabel:"Limpar tudo",customFilters:"Filtros personalizados",quickFilters:"Filtros rápidos",validations:{notFullFilled:{title:"Filtro parcialmente preenchido",message:"Favor completar todas as informações do filtro."},notSaved:{title:"Atenção",message:"As alterações realizadas não serão aplicadas.<br/><br/><b>Deseja mesmo continuar?</b>"}}}},r={titleUpdate:"Editar",titlePrevious:"Anterior",titleNext:"Próximo",titleRefresh:"Atualizar",titleClone:"Duplicar",titleRemove:"Excluir",titleMoreOptions:"Mais Opções",titleInsert:"Cadastrar",titleCancel:"Cancelar",titleSave:"Salvar",titleGridMode:"Modo Grade",titleFormMode:"Modo Formulário",titleConfigurator:"Configurações",titleAttach:"Anexar",forbidden:"Permissão não liberada"},i={errorArray:"CrudUtils.find deve receber um array de fields, ou uma lista separada por virgula."},s={emailSenderTitle:"Enviar por email",emailSenderBackButton:"Voltar",emailSenderNextButton:"Avançar",emailSenderCancelButton:"Cancelar",emailSenderSendButton:"Enviar",emailSenderOptStep_subtitle:"Primeiro, escolha o formato do arquivo",emailSenderOptStep_lblFormat:"Formato:",emailSenderOptStep_formatPDF:"PDF (.pdf)",emailSenderOptStep_formatXLS:"Planilha (.xls)",emailSenderOptStep_export:"Exportar:",emailSenderOptStep_allData:"Toda a grade",emailSenderOptStep_currentPage:"Somente a página atual",emailSenderOptStep_someRecords:"{{SELECTION_COUNT}} linhas selecionadas",emailSenderOptStep_oneRecord:"Somente a linha selecionada",emailSenderInfoStep_subtitle:"Informações de email",emailSenderInfoStep_sendTo:"Enviar para",emailSenderInfoStep_subject:"Assunto",emailSenderInfoStep_message:"Mensagem"},t={title:{clone:"Duplicar registro",insert:"Cadastrar registro",update:"Alterar registro",clean:"{{ENTITY_NAME}}"},findColumn:"Buscar campos",goBackTitle:"Voltar"},l={findColumn:"Busca de colunas",formConfigUnavaliable:{title:"Aviso",message:'A opção "Configurar formulário" será disponibilizada em breve. Enquanto isso, acesse a configuração do fomulário através dos layouts anteriores, HTML5 ou Flex.'}},n={error:{title:"Erro na Exportação",message:"O usuário não possui permissão para exportar o arquivo."},message:{exportSuccess:"Exportado com sucesso!"}},d={newVersionPopup:{title:"Boas vindas à nova interface da tela {{screenName}}",info:"Com uma jornada mais moderna, simples e intuitiva, a performance aprimorada da nova interface impulsionará a sua produtividade.",okButton:"Quero experimentar!",cancelButton:"Voltar à interface anterior"}},c={label:{nameField:"Nome do Campo *",typeValueDefault:"Tipo de valor padrão *",valueDefault:"Valor Padrão",clearDuplicate:"Limpar ao Duplicar",requiredField:"Campo Obrigatório",protectedField:"Campo Protegido"},options:{valueFixed:"Valor Fixo",variable:"Variável"}},m={title:"Configuração do formulário",goBackTitle:"Voltar",applyConfig:"Aplicar configuração",availableFields:{title:"Campos disponíveis",labelNoFields:"Nenhum campo disponível",labelOneField:"1 campo disponível",labelAvailableFields:"Campos disponíveis",labelSearchField:"Procurar campo"},form:{subTitleInfo:"Inclua estes campos nos grupos ou deixe-os separados no topo do formulário!",labelDropField:"Arraste e solte um campo aqui",labelNewGroup:"Adicionar novo grupo",mainArea:"Área principal",tabGeneral:"Geral"},confirm:{title:"Aviso",deleteTab:"Você realmente deseja excluir a aba",cancel:"As alterações realizadas serão descartadas.<br/><br/><b>Gostaria de continuar?</b>",exit:"Ao sair as alterações serão descartadas.<br/><br/><b>Você realmente gostaria de sair?</b>",apply:"A <b>{0}</b> irá substituir a sua configuração {1}!<br/><br/><b>Deseja continuar?</b>",group:"Não é possível salvar as configurações com um grupo vazio!",labelCancel:"Cancelar",labelDelete:"Excluir"},alert:{titleGroupExists:"Já existe um grupo com título",infoValidTitle:"Por favor, digite um título válido.",inTab:"na aba"},info:{successfullyConfigSaved:"As configurações foram salvas com sucesso!"}},u={titleRemove:"Remover",titleConfigurations:"Configurações",titleAdd:"Adicionar"},p={labelRename:"Renomear",labelHide:"Ocultar",labelShow:"Exibir",labelDelete:"Excluir"},f={titleConfigurations:"Configurações",subTitleModeConfig:"Modo de visualização",labelConfigGrid:"Configurar grade",labelConfigForm:"Configurar formulário",labelGrid:"Grade",labelForm:"Formulário"},b={findColumn:"Busca de colunas"},v={gridConfiguration:"Configuração da Grade",columnVisibilityOrder:"Defina visibilidade e ordem das colunas.",sortingSequence:"Sequência da ordenação",findColumn:"Localizar coluna",cancel:"Cancelar",complete:"Concluir",tab:{columns:"Colunas",lineOrdering:"Ordenação das linhas"},info:{successfullyConfigSaved:"As configurações foram salvas com sucesso!"},confirm:{cancel:"Descartar",save:"Salvar",alert:"Aviso",msgCancel:"As alterações realizadas serão descartadas. Gostaria de salvar antes de sair?"},group:{visible:"Visíveis",hidden:"Ocultas"}},g={group:{export:{default:"Exportar para",multiSelected:"Exportar {0} linhas selecionadas",selectedLine:"Exportar somente 1 linha selecionada",title:"Exportar"},custom:"Personalizado"},label:{currentPage:"Somente a página atual",allRecords:"Todos os registros",spreadsheet:"Planilha",cube:"Cubo",sendByEmail:"Enviar por email"},message:{emailSuccess:"E-mail enviado com sucesso",exportError:"Falha ao exportar dados",unknownFailure:"O motivo da falha não pode ser identificado.",exportPermission:"O usuário não possui permissão para exportar o arquivo."},title:{error:"Erro",permission:"Falha detectada"},limitExceeded:{title:"Atenção",description:"Apenas os {{limit}} primeiros registros serão exportados. Deseja continuar?",subdescription:"Caso seja necessária uma quantidade maior de registros exportados, utilize o Extrator de Dados através de um Relatório Personalizado.",cancel:"Cancelar",continue:"Continuar"}},A={modalTitle:"Configuração de valor variável",labelSystemConfig:"Usar definições do sistema",labelUserConfig:"Usar definições personalizadas",labelInstance:"Categoria",labelField:"Campo",labelDescription:"Descrição (obrigatório) *",labelType:"Tipo (obrigatório) *",labelTypeValues:{date:"Data",text:"Texto",integer:"Número Inteiro",decimal:"Número com Decimal"},labelExpression:"Expressão",labelCancel:"Cancelar",labelSave:"Salvar"},C={searchLabel:"Buscar campo",fieldLabel:"Campos de {{link}}",linkLabel:"Categorias de {{link}}",groupEmpty:"Não há categorias para seleção",searchEmpty:"Nenhum resultado encontrado"},F={backTitle:"Voltar"},S={title:"Anexar arquivos",description:"Faça o upload dos arquivos ou informe links que deseja anexar ao título",attachHint:"Fazer download do arquivo",breadcrumbTitle:"Anexar",finishedMessage:"O anexo foi finalizado com sucesso",finish:"Finalizar",cancelConfirmation:{title:"Atenção",message:"As alterações realizadas não serão aplicadas.<br/><br/><b>Deseja mesmo continuar?</b>"},alertValidation:{fileAndLinkAtTheSameTime:{title:"Atenção",message:"Não é permitido inserir o arquivo e o link ao mesmo tempo."},anyLinkOrFileFilled:{title:"Atenção",message:'É necessário preencher o campo "Link" ou anexar um arquivo.'},descriptionCannotBeChanged:{title:"Atenção",message:"O campo 'Descrição' não pode ser alterado."}},taskbar:{titleDownload:"Fazer download",titleLink:"Abrir link"},attachMetadata:{lblCode:"Código",lblDescription:"Descrição",lblFileOrLink:"Arquivo / Link",lblUser:"Usuário",lblDate:"Data de alteração",lblFile:"Arquivo",lblSubTitle:"Clique para selecionar um arquivo"}},x={info:{titleEdit:"Editar filtro personalizado",titleAdd:"Criar filtro personalizado",titleCollapsible:"Expressão a ser aplicada (gerada pelo assistente)",labelSearchField:"Buscar campo",labelOperator:"Operador",labelValueVarible:"Valor variável",titleTooltip:"Ao ativar um valor variável, é possível inserir um valor diferente sempre que o filtro for aplicado",labelAddNewExpression:"Adicionar nova linha de expressão",labelDeleteExpression:"Remover expressão",labelDeleteItem:"Remover item",labelDisabledAddGroupButton:"Filtros Personalizados possuem um limite de {{LIMIT_GROUP_LEVEL}} Grupos de Condições e Valores",labelDisabledAddExpressionButton:"Preencha campos obrigatórios ou indique valores variáveis nas expressões do grupo antes de adicionar mais itens",labelCancel:"Cancelar",labelSave:"Salvar",labelNameFilter:"Nome do filtro",labelExpression:"Expressão",badgeVariable:"variável",noDataFound:"Nenhum filtro encontrado",condition:"Condição",addGroup:"Adicionar grupo",addField:"Adicionar campo",applyExpression:"Expressão a ser aplicada:",tooltipDisabledAssistentMode:"Expressão não suportada pelo assistente.",activeModeAdvanced:"Ativar modo avançado",activeModeAssistent:"Ativar modo assistente"},confirmExpression:{title:"Aviso",description:"As informações da condição serão descartadas.</br></br><b>Gostaria de continuar?</b>"},confirmGroup:{title:"Aviso",description:"As informações do Grupo e suas Condições serão descartadas.</br></br><b>Gostaria de continuar?</b>"},confirmCancel:{title:"Aviso",description:"As alterações realizadas serão descartadas.</br></br><b>Gostaria de continuar?</b>"},confirmChangeModeAssistent:{title:"Aviso",description:"Ao modificar a expressão, o modo assistente será desabilitado.</br></br><b>Gostaria de continuar?</b>"},confirmChangeModeAdvanced:{title:"Aviso",description:"Ao retornar ao modo assistente suas alterações serão perdidas.</br></br><b>Gostaria de continuar?</b>"},confirmSaveModeAdvanced:{title:"Aviso",description:"Ao modificar a expressão, o modo assistente será desabilitado.</br></br><b>Gostaria de continuar?</b>"},operador:{firstLevel:"A seleção será habilitada a partir da adição da segunda linha de regras.",and:"Será verdadeiro se todas as condições forem obedecidas.",or:"Será verdadeiro se qualquer uma das condições for obedecida."},error:{title:"Atenção",description:"Há pelo menos um campo obrigatório não preenchido."},errorValidation:{title:"Erro na expressão"},confirmSave:{title:"Filtro criado com sucesso!"},confirmEdit:{title:"Filtro atualizado com sucesso!"},deleteConfirm:{title:"Aviso",message:"Deseja realmente excluir o filtro '{{filterName}}'?"},listActions:{edit:"Editar",delete:"Excluir"},footerActions:{clear:"Limpar",create:"Criar filtro"}},h={selected:"Selecionados:"},E={title:{actions:"Ações",error:"Erro",warning:"Aviso"},action:{incorrectAction:'A ação "{{description}}" não pode ser executada porque ela não foi salva corretamente.',emptyParamName:"<b>Regra Personalizada:</b><br/><br/>É necessário informar o atributo 'paramName'",nonExistentType:"Tipo de ação não implementada: {{this.actionType}}"},launchScreen:{emptyField:'A ação "{{description}}" não pôde ser executada porque o campo "{{localFieldLabel}}" está vazio.'},form:{fillParams:"Informe os parâmetros"},clientEvent:{cancelMessage:"Caso queira cancelar, feche esta mensagem."},buttons:{apply:"Aplicar",cancel:"Cancelar",yes:"Sim",no:"Não"}},T={title:{warning:"Aviso",printerSelection:"Seleção de impressora",remotePrintersTab:"Impressoras remotas",localPrintersTab:"Impressoras locais"},subtitle:{document:"Documento:",jobs:"Trabalhos:"},message:{canceledPrint:"A impressão será cancelada. Deseja mesmo continuar?",noPrinters:"Não há impressoras para seleção",savePrinter:"Usar sempre esta seleção"},button:{print:"Imprimir",cancel:"Cancelar",yes:"Sim",no:"Não"}};class D{constructor(D){this._defaults={snkApplication:d,snkDataUnit:a,snkFormConfig:m,snkConfigOptions:c,snkTaskbar:r,snkFieldConfig:u,snkFilterBar:o,snkConfigurator:f,snkTabConfig:p,crudUtils:i,snkGrid:b,snkGridConfig:v,snkExporter:s,snkDataExporter:g,snkCrud:t,snkSimpleCrud:l,fileViewer:n,snkFilterParamConfig:A,snkFilterFieldSearch:C,snkSimpleBar:F,snkAttach:S,snkPersonalizedFilter:x,snkEntityList:h,snkActionsButton:E,snkPrintSelector:T},this._currentOperation=L.CLEAN,this._domainName=D,this._application=e.getContextValue("__SNK__APPLICATION__"),this.loadAppMessages().then((e=>{this._appMessages=e}),(e=>{console.info("O arquivo de mensagens personalizadas não foi encontrado no caminho /messages/appmessages",e)}))}set currentOperation(e){this._currentOperation=e}getMessage(e,a){if(null==e)return;var o=e.split(".");let r=this.resolveMessage(o,this.getDomainMessages());if(null==r&&(r=this.resolveMessage(o,this._defaults)),this.customMessageBuilder){const o=this.customMessageBuilder(e,r,a);r=o.message,a=o.params}return this.postProcess(r,a)}getDomainMessages(){if(this._appMessages)return this._domainName?this._appMessages[this._domainName]:this._appMessages.Global||this._appMessages}resolveMessage(e,a){if(null==a)return;const o=a[e[0]];return o?this.isOperationSensitive(o)?o[this._currentOperation]:1===e.length||null==o||"string"==typeof o?o:this.resolveMessage(e.slice(1),o):void 0}isOperationSensitive(e){return null!=e[L.CLONE]||null!=e[L.INSERT]||null!=e[L.UPDATE]||null!=e[L.CLEAN]}postProcess(e,a){if(e){const o=/(.*?)\{\{(.+?)\}\}/g;let r,i="",s=e;for(;null!==(r=o.exec(e));){const[o,t,l]=r,n=r.index+o.length;s=n<e.length?e.substring(n):"";let d=a?a[l]:void 0;null==d&&(d=""),i+=t+d}return i+s}return e}async loadAppMessages(){const e=await this._application.getApplicationPath();return(await import(`${e}/messages/appmessages.js`)).default}}var L;!function(e){e.CLONE="clone",e.INSERT="insert",e.UPDATE="update",e.CLEAN="clean"}(L||(L={}));export{L as O,D as S}
|
@@ -1 +1 @@
|
|
1
|
-
export{S as snk_data_unit}from"./p-
|
1
|
+
export{S as snk_data_unit}from"./p-cc935517.js";import"./p-d2d301a6.js";import"@sankhyalabs/core";import"@sankhyalabs/ezui/dist/collection/utils";import"./p-7c4aabe2.js";import"./p-091ce761.js";import"./p-594bc21d.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";import"./p-9863d682.js";import"@sankhyalabs/core/dist/dataunit/metadata/DataType";
|
@@ -1 +1 @@
|
|
1
|
-
import{r as i,c as o,h as n,H as t,g as s}from"./p-d2d301a6.js";import{S as e}from"./p-fa816fb2.js";import{ObjectUtils as l,ElementIDUtils as r,ArrayUtils as a,ApplicationContext as d}from"@sankhyalabs/core";import{ApplicationUtils as c,DialogType as f}from"@sankhyalabs/ezui/dist/collection/utils";import{C as h,a as g,T as u,A as m,D as v}from"./p-b0ef4383.js";import{U as b}from"./p-df5451c7.js";import{buildFormConfigFromDataUnit as p}from"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-dc7c9047.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const _="EZ-COLLAPSIBLE-BOX",z="fieldsWithoutGroupContainer",k="fieldsAvailableContainer",C="addNewGroupContainer",x=class{constructor(n){i(this,n),this.configChange=o(this,"configChange",7),this.configClose=o(this,"configClose",7),this._listEnabledFields=[],this._renderTimer=500,this._tabSelected=1,this._labelNewGroup="Novo grupo",this._mouseOnFieldConfig=!1,this._mouseOnConfigOptions=!1,this._editingTitleGroup=!1,this._newGroupBoxes=[],this._currentGroupBoxes=[],this._formFieldsStyle="ez-col ez-col--sd-12 ez-col--tb-4 ez-padding-right--small ez-padding-bottom--medium sc-snk-form-config",this._fieldsAvailableStyle="ez-col ez-col--sd-12 ez-col--tb-12 ez-margin-bottom--medium ez-margin-right--medium sc-snk-form-config",this._fieldFloatingStyle="form-config__field-config--dragged",this._sortableTimer=100,this._formConfigOptions=[],this._fieldConfigSelected=void 0,this._layoutFormConfig=void 0,this._fieldsAvailable=void 0,this._formConfig={},this._formConfigChanged=!1,this._optionFormConfigSelected=void 0,this._optionFormConfigChanged=!1,this._tempGroups=[],this.dataUnit=void 0,this.configManager=void 0,this.messagesBuilder=void 0}observeConfigManager(){this.loadConfig(this._sortableTimer)}loadFields(i=0){this._layoutFormConfig=[],i>0?setTimeout((()=>{this.buildFields()}),i):this.buildFields()}buildFields(){this.buildFormConfig(),this.buildAvailableFields()}loadFormConfig(i){var o;this._formConfig=this.getConfig(),this.loadFields(i),this.controlFieldConfig(),null!=(null===(o=this._filterFieldsAvailable)||void 0===o?void 0:o.value)&&(this._filterFieldsAvailable.value="")}getConfig(){let i=this.configManager.getConfig(this.dataUnit);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=p(this.dataUnit)),l.copy(i)}cancelChangeConfig(){!0===this._formConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((i=>{i&&(this._formConfigChanged=!1,this.resetChangeConfig())})):this.resetChangeConfig()}cancelChangeOptionConfig(){!0===this._optionFormConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((i=>{i&&(this._optionFormConfigChanged=!1,this.resetChangeOptionConfig())})):this.resetChangeOptionConfig()}resetChangeConfig(){this.loadFormConfig(this._sortableTimer),this.clearTempGroups()}resetChangeOptionConfig(){this._formConfigChanged=!1,this.loadConfig(this._sortableTimer),this.clearTempGroups()}getTabsToSave(){return this._layoutFormConfig.map(((i,o)=>({label:i.tab,order:o,visible:i.visible})))}getFieldsToSave(){const i=[];return this._formContainer.querySelectorAll("snk-field-config").forEach((o=>{const n=o.fieldConfig;if(null==n)return;const t={cleanOnCopy:n.cleanOnCopy||!1,group:n.group,label:n.label,name:n.name,required:n.required,readOnly:n.readOnly,tab:n.tab};null!=n.defaultValue&&(t.defaultValue=null==n.defaultValue.type?{type:v.fixed,value:n.defaultValue}:n.defaultValue),i.push(t)})),i}isDefaultConfiguration(){var i;return(null===(i=this._optionFormConfigSelected)||void 0===i?void 0:i.origin)===b.DEFAULT&&!0===this._optionFormConfigChanged&&!1===this._formConfigChanged}buildConfigToSave(){let i={};const o=this.isDefaultConfiguration();if(i=o?this.getConfig():l.copy(this._formConfig),!1===o){const o=this.getTabsToSave();(null==o?void 0:o.length)>0&&(i.tabs=o);const n=this.getFieldsToSave();(null==n?void 0:n.length)>0&&(i.fields=n)}return i.defaultConfiguration=o,i}saveConfig(){var i;(null===(i=this._tempGroups)||void 0===i?void 0:i.length)>0?c.alert(this.getMessage("snkFormConfig.confirm.title"),this.getMessage("snkFormConfig.confirm.group")):(this._formConfigChanged=!1,this._optionFormConfigChanged=!1,this.configManager.saveConfig(this.buildConfigToSave()).then((i=>{c.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"}),this.configChange.emit(i)})))}applyOptionConfig(){if(!0===this._optionFormConfigChanged&&null!=this._optionFormConfigSelected){const i=this._optionFormConfigSelected.name||"configuração selecionada",o=this._optionFormConfigSelected.origin===b.DEFAULT?"pessoal":"padrão",n=this.getMessage("snkFormConfig.confirm.apply").replace("{0}",i).replace("{1}",o);this.openConfirmDialog(n).then((i=>{i&&this.saveConfig()}))}else this.saveConfig()}controlFieldConfig(i){var o;this._fieldConfigSelected=null!=i?(null===(o=this._fieldConfigSelected)||void 0===o?void 0:o.name)===(null==i?void 0:i.name)?void 0:i:void 0}getFieldConfigStyle(i){var o;return this._formFieldsStyle+((null===(o=this._fieldConfigSelected)||void 0===o?void 0:o.name)===i.name?" form-config__field-config--selected":"")}getFieldsByGroup(i){var o;return(null===(o=i.fields)||void 0===o?void 0:o.length)?i.fields.map((i=>{var o,t;return n("div",{key:i.name,class:this.getFieldConfigStyle(i),"data-draggable-element":"field",onMouseDown:i=>this.controlMoveField(i)},n("snk-field-config",{messagesBuilder:this.messagesBuilder,onEzClickIcon:i=>{this.handleFieldConfigChange(i)},modeInsertion:!1,fieldConfig:i,dataUnit:this.dataUnit,isConfigActive:(null===(o=this._fieldConfigSelected)||void 0===o?void 0:o.name)===i.name,id:i.name,key:i.name}),(null===(t=this._fieldConfigSelected)||void 0===t?void 0:t.name)===i.name&&n("div",{class:"ez-flex form-config__config-options"},n("snk-config-options",{idConfig:i.name,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,fieldConfig:this._fieldConfigSelected,"data-element-id":this._element.getAttribute(r.DATA_ELEMENT_ID_ATTRIBUTE_NAME),onConfigOptionsChanged:i=>this.handleconfigOptionsChanged(i.detail)})))})):n("div",{class:"form-config__add-group-container"},n("div",{class:"form-config__add-group-content"},n("div",{class:"form-config__add-group-label"},n("label",{class:"ez-text ez-text--center ez-text--medium ez-text--primary ez-text--bold"},this.getMessage("snkFormConfig.form.labelDropField")))))}handleconfigOptionsChanged(i){var o;null===(o=this._formConfig.fields)||void 0===o||o.forEach((()=>{})),this._formConfigChanged=!0}closeFormConfig(){!0===this._formConfigChanged||!0===this._optionFormConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.exit")).then((i=>{i&&(this._formConfigChanged=!1,this.configClose.emit())})):this.configClose.emit()}openConfirmDialog(i="",o=this.getMessage("snkFormConfig.confirm.title")){return c.confirm(o,i)}controlMoveField(i){const o=null==i?void 0:i.target;null!=(null==o?void 0:o.closest('[data-draggable-element="field"]'))&&(this._mouseOnFieldConfig=!0,null!=(null==o?void 0:o.closest(".form-config__config-options"))||null!=(null==o?void 0:o.closest(".field-config__options"))?this._mouseOnConfigOptions=!0:!1===["minus","settings-inverted","chevron-up"].includes(null==o?void 0:o.iconName)&&this.controlFieldConfig())}controlStartDraggingField(i){var o,n,t;if(this._mouseOnConfigOptions)null==i||i.cancel(),this._mouseOnConfigOptions=!1;else{const s=null===(t=null===(n=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.dragEvent)||void 0===n?void 0:n.data)||void 0===t?void 0:t.sourceContainer;null!=s&&s.classList.add(this._fieldFloatingStyle)}}controlSortedDraggingField(i){var o,n,t,s,e,l,r,a;const d=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.oldContainer,c=null===(n=null==i?void 0:i.data)||void 0===n?void 0:n.newContainer,f=null===(e=null===(s=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.dragEvent)||void 0===s?void 0:s.data)||void 0===e?void 0:e.source,h=null===(a=null===(r=null===(l=null==i?void 0:i.data)||void 0===l?void 0:l.dragEvent)||void 0===r?void 0:r.data)||void 0===a?void 0:a.originalSource;null!=d&&null!=c&&null!=f&&null!=h&&(c.tagName!==_&&c.id!==z||d.id!==k?d.tagName!==_&&d.id!==z||c.id!==k||(f.className=this._fieldsAvailableStyle,f.querySelector("snk-field-config").modeInsertion=!0,h.className=this._fieldsAvailableStyle,h.querySelector("snk-field-config").modeInsertion=!0):(f.className=this._formFieldsStyle,f.querySelector("snk-field-config").modeInsertion=!1,h.className=this._formFieldsStyle,h.querySelector("snk-field-config").modeInsertion=!1))}isCancelDragAvailableField(i,o,n){var t,s;return null!=i&&null!=o&&null!=n&&(null===(t=n.data)||void 0===t?void 0:t.newIndex)!==(null===(s=n.data)||void 0===s?void 0:s.oldIndex)&&i.id===k&&o.id===i.id&&(n.cancel(),this._fieldsAvailable=[],setTimeout((()=>{this.buildAvailableFields()}),this._sortableTimer),!0)}isRemoveField(i,o,n){if(null==i||null==o||null==n)return!1;if((o.tagName===_||o.id===z)&&i.id===k){const i={detail:{field:n,type:m.remove}};return setTimeout((()=>{this.handleFieldConfigChange(i)}),this._renderTimer),!0}return!1}isAddOrMoveField(i,o,n,t){var s;return null!=i&&null!=o&&null!=n&&null!=t&&(t.newIndex!==t.oldIndex||o.dataset.groupName!==i.dataset.groupName||i.id===z&&o.id===k)&&(this.isFieldAvailable(i,o)&&(n.tab=null===(s=this._tabConfig)||void 0===s?void 0:s.selectedTab),n.group=i.dataset.groupName,setTimeout((()=>{i.id.includes(C)&&this.clearTempGroups(!0),this.updateFieldsToSave(o.dataset.groupName!==i.dataset.groupName||i.id===z&&o.id===k?this._sortableTimer:0)}),this._renderTimer),!0)}isFieldAvailable(i,o){return null!=i&&null!=o&&(i.tagName===_||i.id===z)&&o.id===k}controlStopDraggingField(i){var o,n,t,s,e,l;const r=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.oldContainer,a=null===(n=null==i?void 0:i.data)||void 0===n?void 0:n.newContainer;if(this.isCancelDragAvailableField(a,r,i))return;const d=null===(e=null===(s=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.dragEvent)||void 0===s?void 0:s.data)||void 0===e?void 0:e.originalSource,c=null===(l=null==d?void 0:d.querySelector("snk-field-config"))||void 0===l?void 0:l.fieldConfig;this.isRemoveField(a,r,c)||this.isAddOrMoveField(a,r,c,null==i?void 0:i.data)}updateFieldsToSave(i=0){const o=this.getFieldsToSave();(null==o?void 0:o.length)>0&&(this._formConfig.fields=o),this.loadFields(i),this._formConfigChanged=!0}controlSortableField(){null!=this._sortableContainer&&(this._sortableField&&this._sortableField.destroy(),this._sortableField=new e(this._sortableContainer.querySelectorAll('[data-draggable-parent="field"]'),{draggable:'[data-draggable-element="field"]',mirror:{constrainDimensions:!0},distance:h.dragStartDistance}),this._sortableField.on(g.dragStart,(i=>this.controlStartDraggingField(i))),this._sortableField.on(g.dragSorted,(i=>this.controlSortedDraggingField(i))),this._sortableField.on(g.dragStop,(i=>this.controlStopDraggingField(i))))}controlStartDraggingGroup(i){(this._mouseOnFieldConfig||this._editingTitleGroup)&&(null==i||i.cancel(),this._mouseOnFieldConfig=!1)}controlStopDraggingGroup(i){i.data.newIndex!==i.data.oldIndex&&setTimeout((()=>{this.updateFieldsToSave(this._sortableTimer)}),this._renderTimer)}controlSortableGroup(){null!=this._sortableContainer&&(this._sortableGroup&&this._sortableGroup.destroy(),this._sortableGroup=new e(this._sortableContainer.querySelectorAll('[data-draggable-parent="group"]'),{draggable:'[data-draggable-element="group"]',mirror:{constrainDimensions:!0},distance:h.dragStartDistance}),this._sortableGroup.on(g.dragStart,(i=>this.controlStartDraggingGroup(i))),this._sortableGroup.on(g.dragStop,(i=>this.controlStopDraggingGroup(i))))}loadUserConfig(){null!=this.configManager&&this.configManager.fetchUserAvailableConfigs().then((i=>{if(this._formConfigOptions=i,null==this._formConfigOptions)return;let o=null==this._formConfig||this._formConfig.defaultConfiguration;const n=i.find((i=>i.origin===(o?b.DEFAULT:b.USER)));this.setFormConfig(n)}))}setFormConfig(i){this._optionFormConfigSelected=i}controlSelectFormConfig(i){const o=null==i?void 0:i.detail,n=this._formConfigOptions.find((i=>i.origin===(null==o?void 0:o.value)));this.setFormConfig(n),this._optionFormConfigChanged=!0,this.loadConfigByUser()}changeTabOrder(i){const o=[],n=this._tabConfig.querySelectorAll(".tab-config__tab");this._tabSelected=i,n.forEach(((i,n)=>{var t;if(n){const s=null===(t=i.querySelector(".tab-config__tab-label"))||void 0===t?void 0:t.getAttribute("title");o.push({label:s,order:n-1})}})),this._layoutFormConfig.map((i=>{o.forEach((o=>{o.label===i.tab&&(o.visible=i.visible)}))})),o.length>0&&(this._formConfig.tabs=o,this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0)}async loadConfigByUser(){if(null==this.configManager)return;if(null==this._optionFormConfigSelected)return;let i;switch(this._optionFormConfigSelected.origin){case b.DEFAULT:case b.DEFAULT:i=await this.configManager.fetchDefaultConfig()}null!=i&&(this._formConfig=i,this._tabSelected=1,this.loadFields(this._sortableTimer),this.controlFieldConfig(),this.clearTempGroups())}loadConfig(i=0){this.loadFormConfig(i),this.loadUserConfig()}addNewGroup(){var i,o;const n=null===(i=this._tabConfig)||void 0===i?void 0:i.selectedTab;null==(null===(o=this._tempGroups)||void 0===o?void 0:o.find((i=>i.tab===n&&i.group.includes(this._labelNewGroup))))&&(this._tempGroups.push({tab:n,group:this.handleDuplicateGroups(this._labelNewGroup,this._tabConfig.selectedTab)}),this.loadFields(),this.controlFieldConfig(),this._formConfigChanged=!0)}clearTempGroups(i=!1){var o;(null===(o=this._tempGroups)||void 0===o?void 0:o.length)>0&&(this._tempGroups=i?this._tempGroups.filter((i=>i.tab!==this._tabConfig.selectedTab)):[])}removeGroup(i){null!=i?this._tempGroups=this._tempGroups.filter(((o,n)=>n!==i&&o.tab===this._tabConfig.selectedTab||o.tab!==this._tabConfig.selectedTab)):this.updateFieldsToSave(this._sortableTimer)}checkGroupExists(i,o,n=!1){var t,s,e;const l=null===(t=this._tabConfig)||void 0===t?void 0:t.selectedTab,r=null===(s=this._layoutFormConfig)||void 0===s?void 0:s.find((i=>i.tab===l)),a=null===(e=null==r?void 0:r.groups)||void 0===e?void 0:e.map((i=>{var o;return null===(o=i.group)||void 0===o?void 0:o.toLowerCase()}));if(null==a?void 0:a.includes(null==i?void 0:i.toLowerCase())){const t=this.getMessage("snkFormConfig.confirm.title"),s=`\n ${this.getMessage("snkFormConfig.alert.titleGroupExists")}\n <b>${i}</b>\n ${this.getMessage("snkFormConfig.alert.inTab")}\n <b>${l===u.main?this.getMessage("snkFormConfig.form.mainArea"):l}</b>.\n <br/><br/>\n ${this.getMessage("snkFormConfig.alert.infoValidTitle")}\n `;return c.alert(t,s).then((()=>{var i,t;n?null===(i=this._newGroupBoxes[o])||void 0===i||i.applyFocusTextEdit():null===(t=this._currentGroupBoxes[l][o])||void 0===t||t.applyFocusTextEdit()})),!1}return!0}saveEditLabelTempGroup(i,o){const{newValue:n}=i.detail;null!=this._newGroupBoxes&&null!=this._newGroupBoxes[o]&&(this._newGroupBoxes[o].dataset.groupName=n)}saveEditLabelGroup(i){var o;const{value:n,newValue:t}=i.detail;null===(o=this._formConfig.fields)||void 0===o||o.forEach((i=>{i.group===n&&(i.group=t)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}renderTempGroupByTab(i){return this._tempGroups.map(((o,t)=>{if(o.tab===i)return n("ez-collapsible-box",{ref:i=>this._newGroupBoxes[t]=i,id:`${C}-${t}`,editable:!0,removable:!0,"header-size":"large",label:o.group,"icon-placement":"left","data-group-name":o.group,"data-draggable-parent":"field",class:"form-config__add-group",onEzRemove:()=>this.removeGroup(t),onEzSaveEditLabel:i=>this.saveEditLabelTempGroup(i,t),onEzEditLabelMode:i=>this._editingTitleGroup=i.detail,conditionalSave:i=>this.checkGroupExists(i,t,!0)},this.getFieldsByGroup(o))}))}handleDuplicateGroups(i,o){var n;const t=this._layoutFormConfig[this._tabConfig.selectedIndex].groups.map((i=>i.group));return null!=t&&(null===(n=this._layoutFormConfig)||void 0===n||n.map((n=>{n.tab===o&&n.groups.some((o=>o.group===i))&&(i+=`${this.captureHighestValueTitle(t)}`)}))),i}captureHighestValueTitle(i){let o=[];return null==i||i.map((i=>{null!=i&&o.push(i.replace(/[^0-9]/g,""))})),Math.max.apply(null,o)>0?` (${Math.max.apply(null,o)+1})`:" (1)"}getLayoutFormConfig(){var i,o;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let n=[],t=[];for(const i of this._formConfig.fields)if(null==t.find((o=>i.name===o.name&&i.tab===o.tab))){t.push(i);const s=this.dataUnit.getField(i.name);if(null==s?void 0:s.visible){null!=i.label&&""!==i.label||(i.label=s.label),null!=i.tab&&""!==i.tab||(i.tab=this.getMessage("snkFormConfig.form.tabGeneral"));let t=n.find((o=>o.tab===i.tab));if(null==t){let s=null;if(null!=this._formConfig.tabs){const o=this._formConfig.tabs.filter((o=>o.label===i.tab));o.length>0&&(s=o[0].visible)}const e=(null===(o=i.tab)||void 0===o?void 0:o.label)||i.tab;t=null!==s?{tab:e,groups:[],visible:s}:{tab:e,groups:[],visible:!0},n.push(t)}const e=t.groups.find((o=>o.group===i.group));if(e)e.fields.push(i);else{const o={group:i.group,fields:[i]};void 0===i.group?t.groups.unshift(o):t.groups.push(o)}}}return n}configureTabs(i){var o;return null==(null===(o=this._formConfig)||void 0===o?void 0:o.tabs)?i:(null==i&&(i=[]),this._formConfig.tabs.map((o=>i.find((i=>{var n,t;return(null===(n=o.label)||void 0===n?void 0:n.toLowerCase())===(null===(t=i.tab)||void 0===t?void 0:t.toLowerCase())}))||{tab:o.label,groups:[],visible:o.visible})))}configureTabMain(i){return null==i&&(i=[]),null==i.find((i=>i.tab===u.main))&&i.unshift({tab:u.main,groups:[],visible:!0}),i}updateTabs(){const i=this.getTabsToSave();(null==i?void 0:i.length)>0&&(this._formConfig.tabs=i,1===i.length&&(this._tabSelected=0))}buildFormConfig(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let o=this.getLayoutFormConfig();o=this.configureTabs(o),o=this.configureTabMain(o),this._layoutFormConfig=o,this.updateTabs()}buildAvailableFields(){var i,o;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let n=[],t=this.dataUnit.metadata.fields;for(const i of this._formConfig.fields)n.push(i);const s=t.filter((({name:i,visible:o})=>!0===o&&!1===n.some((({name:o})=>o===i))));this._fieldsAvailable=s,this._listEnabledFields=s,null!=(null===(o=this._filterFieldsAvailable)||void 0===o?void 0:o.value)&&this.onFilterChange(this._filterFieldsAvailable.value)}changeTabSelected(i){this._tabSelected=i.index;const o=this._formContainer.querySelector("div#tab"+i.index);this._formContainer.querySelectorAll(".form-config__tab-content").forEach((i=>i.className="form-config__hide-content sc-snk-form-config")),o&&(o.className="form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium sc-snk-form-config")}onFilterChange(i){this._fieldsAvailable=a.applyStringFilter(i,this._listEnabledFields,!0,"label")}orderFieldsAvailable(i){return a.sortAlphabetically(i)}handleLabelCounter(i){const o=[this.getMessage("snkFormConfig.availableFields.labelNoFields"),this.getMessage("snkFormConfig.availableFields.labelOneField")];return i>1?`${i} ${this.getMessage("snkFormConfig.availableFields.labelAvailableFields")}`:o[i]}controlAddFieldConfig(i){var o;if(this._formConfigChanged=!1,null==i)return;null==this._formConfig.fields&&(this._formConfig.fields=[]);const n=this._formConfig.fields.filter((o=>o.name===i.name&&o.tab&&i.tab));n.length>0?n.forEach((o=>{o.name=i.name,o.label=i.label,o.required=i.required,o.readOnly=i.readOnly,o.group=i.group})):this._formConfig.fields.push({name:i.name,label:i.label,required:i.required,readOnly:i.readOnly,group:i.group,tab:null===(o=this._tabConfig)||void 0===o?void 0:o.selectedTab}),this.loadFields(),this.controlFieldConfig(),this._formConfigChanged=!0,this.resetSortables()}controlRemoveFieldConfig(i,o){var n;this._formConfigChanged=!1,null!=i&&(this._formConfig.fields=null===(n=this._formConfig.fields)||void 0===n?void 0:n.filter((o=>o.name!==i.name)),this.loadFields(o),this.controlFieldConfig(),this._formConfigChanged=!0,this.resetSortables())}resetSortables(){this.controlSortableField(),this.controlSortableGroup()}handleFieldConfigChange(i,o=0){const{field:n,type:t}=i.detail;t!==m.configuration?t!==m.remove?t!==m.add||this.controlAddFieldConfig(n):this.controlRemoveFieldConfig(n,o):this.controlFieldConfig(n)}changeTabLabel(i){var o,n;const{value:t,newValue:s}=i.detail.detail;null===(o=this._formConfig.fields)||void 0===o||o.forEach((i=>{i.tab===t&&(i.tab=s)})),null===(n=this._formConfig.tabs)||void 0===n||n.forEach((i=>{i.label===t&&(i.label=s)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}handleDeleteTab(i){let o={canClose:!1,labelCancel:this.getMessage("snkFormConfig.confirm.labelCancel"),labelConfirm:this.getMessage("snkFormConfig.confirm.labelDelete"),btnConfirmDanger:!1};const n=this.getMessage("snkFormConfig.confirm.title"),t=this.getMessage("snkFormConfig.confirm.deleteTab")+` <b>${i.detail.label}</b>?`;c.confirm(n,t,null,f.WARN,o).then((o=>{var n;o&&(this._formConfig.tabs=null===(n=this._formConfig.tabs)||void 0===n?void 0:n.filter((o=>o.label!==i.detail.label)),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0)}))}changeHideTab(i){var o;null===(o=this._formConfig.tabs)||void 0===o||o.forEach((o=>{o.label===i.detail.label&&(o.visible=!o.visible)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}handleCanStartDragTab(){var i,o;const n=this._layoutFormConfig.map((i=>i.tab));for(const o of n)null===(i=this._currentGroupBoxes[o])||void 0===i||i.map((i=>null==i?void 0:i.cancelEdition()));null===(o=this._newGroupBoxes)||void 0===o||o.map((i=>null==i?void 0:i.cancelEdition()))}getMessage(i,o){return this.messagesBuilder.getMessage(i,o)}componentDidRender(){this.controlSortableField(),this.controlSortableGroup()}async componentWillRender(){if(null==this.messagesBuilder){const i=d.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}componentWillLoad(){this.loadConfig()}componentDidLoad(){r.addIDInfo(this._element,null,{dataUnit:this.dataUnit})}render(){var i,o,s,e;return n(t,null,n("div",{class:"ez-row ez-padding--medium"},n("div",{class:"ez-col ez-col--sd-7 ez-col--tb-9 ez-align--middle"},n("ez-button",{mode:"icon",title:this.getMessage("snkFormConfig.goBackTitle"),iconName:"arrow_back",class:"ez-padding--small",size:"small",onClick:()=>this.closeFormConfig(),id:"formConfigToBack"}),n("h1",{class:"ez-title ez-title--primary ez-title--extra-large ez-padding--small"},this.getMessage("snkFormConfig.title")),this._formConfigOptions&&n("ez-actions-button",{class:"form-config__actions-button ez-margin-left--medium",value:null===(i=this._optionFormConfigSelected)||void 0===i?void 0:i.origin,showLabel:!0,displayIcon:"chevron-down",checkOption:!0,size:"small",actions:this._formConfigOptions.map((i=>({value:i.origin,label:i.name}))),onEzAction:i=>this.controlSelectFormConfig(i),id:"selectConfig"})),n("div",{class:"ez-col ez-col--sd-5 ez-col--tb-3 ez-align--middle ez-align--right"},!0===this._formConfigChanged&&!1===this._optionFormConfigChanged&&n("div",{class:"ez-row ez-align--middle ez-align--right"},n("ez-button",{label:"Cancelar",class:"ez-padding-left--medium",size:"small",onClick:()=>this.cancelChangeConfig()}),n("ez-button",{label:"Salvar",class:"ez-button--primary ez-padding-left--medium",size:"small",onClick:()=>this.saveConfig()},n("ez-icon",{class:"ez-margin-right--small",slot:"leftIcon",iconName:"save"}))),!0===this._optionFormConfigChanged&&n("div",{class:"ez-row ez-align--middle ez-align--right"},n("ez-button",{label:"Cancelar",class:"ez-padding-left--medium",size:"small",onClick:()=>this.cancelChangeOptionConfig()}),n("ez-button",{label:this.getMessage("snkFormConfig.applyConfig"),class:"ez-button--primary ez-padding-left--medium",size:"small",onClick:()=>this.applyOptionConfig()})))),n("div",{class:"ez-row ez-padding--medium",ref:i=>this._sortableContainer=i},n("div",{class:"form-config__tab-container ez-col ez-col--sd-9 ez-col--tb-9 ez-padding-right--medium"},(null===(o=this._layoutFormConfig)||void 0===o?void 0:o.length)>0&&n("section",{class:"ez-box__container",ref:i=>this._formContainer=i},n("snk-tab-config",{ref:i=>this._tabConfig=i,selectedIndex:this._tabSelected,messagesBuilder:this.messagesBuilder,onEzTabChange:i=>this.changeTabSelected(i.detail),onEzOrderChange:i=>this.changeTabOrder(i.detail),onEditionTitleTab:i=>this.changeTabLabel(i),onDeleteTab:i=>this.handleDeleteTab(i),onHideTab:i=>this.changeHideTab(i),onCanStartDrag:()=>this.handleCanStartDragTab(),tabItems:this._layoutFormConfig.map((i=>({tabKey:i.tab,label:i.tab,visible:i.visible})))}),this._layoutFormConfig.map(((i,o)=>n("div",{id:"tab"+o,"data-draggable-parent":"group",class:this._tabSelected===o?"form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium":"form-config__hide-content"},i.groups.map(((o,t)=>o.group?(null==this._currentGroupBoxes[i.tab]&&(this._currentGroupBoxes[i.tab]=[]),n("ez-collapsible-box",{ref:o=>this._currentGroupBoxes[i.tab][t]=o,editable:!0,removable:!0,"header-size":"large",label:o.group,"icon-placement":"left","data-group-name":o.group,"data-draggable-parent":"field","data-draggable-element":"group",onEzRemove:()=>this.removeGroup(),onEzSaveEditLabel:i=>this.saveEditLabelGroup(i),onEzEditLabelMode:i=>this._editingTitleGroup=i.detail,conditionalSave:i=>this.checkGroupExists(i,t)},this.getFieldsByGroup(o))):n("div",{class:"ez-flex ez-flex--column ez-size-width--full"},n("label",{class:"ez-text ez-text--secondary ez-margin-vertical--small"},this.getMessage("snkFormConfig.form.subTitleInfo")),n("div",{id:z,class:"ez-row","data-draggable-parent":"field"},this.getFieldsByGroup(o)),n("hr",{class:"ez-divider-horizontal ez-margin-vertical--medium"})))),this.renderTempGroupByTab(i.tab)))),n("div",{class:"form-config__btn-add-group ez-row"},n("div",{class:"form-config__btn-add-group-container ez-col ez-col--sd-12 ez-col--tb-12 ez-align--center"},n("ez-button",{label:this.getMessage("snkFormConfig.form.labelNewGroup"),class:"ez-padding-horizontal--small ez-button--primary",size:"small",onClick:()=>this.addNewGroup()},n("ez-icon",{class:"ez-margin-right--small",slot:"leftIcon",iconName:"plus"})))))),n("div",{class:"form-config__fields-available ez-col ez-col--sd-3 ez-col--tb-3"},n("section",{class:"ez-box__container ez-col ez-col--pn-12"},n("h1",{class:"ez-title ez-title--large ez-title--primary ez-padding-bottom--medium"},this.getMessage("snkFormConfig.availableFields.title")),n("ez-filter-input",{id:"searchFields",ref:i=>this._filterFieldsAvailable=i,label:this.getMessage("snkFormConfig.availableFields.labelSearchField"),onEzChange:i=>this.onFilterChange(i.detail)}),n("span",{class:"ez-box__label-counter ez-text ez-text--medium ez-text--primary ez-margin-bottom--medium"},this.handleLabelCounter(null===(s=this._fieldsAvailable)||void 0===s?void 0:s.length)),(null===(e=this._layoutFormConfig)||void 0===e?void 0:e.length)>0&&n("div",{id:k,class:"ez-row","data-draggable-parent":"field"},this.orderFieldsAvailable(this._fieldsAvailable).map((i=>n("div",{key:i.name,class:this._fieldsAvailableStyle,"data-draggable-element":"field",onMouseDown:i=>this.controlMoveField(i)},n("snk-field-config",{messagesBuilder:this.messagesBuilder,onEzClickIcon:i=>{this.handleFieldConfigChange(i)},dataUnit:this.dataUnit,fieldConfig:i,id:i.name})))))))))}get _element(){return s(this)}static get watchers(){return{configManager:["observeConfigManager"]}}};x.style=".sc-snk-form-config-h{--snk-form-config--z-index:var(--more-visible, 2);--snk-form-config--background-color:var(--background--xlight, #fff);--snk-form-config__icon--color:var(--text--disable, #AFB6C0);--snk-form-config__label-counter--font-weight:var(--text-weight--extra-small, 200);--snk-form-config__add-group-container--border-radius:var(--border--radius-medium, 12px);--snk-form-config__add-group-container--background-color:var(--background--medium, #d2dce9);--snk-form-config__add-group-container--padding:var(--space--small, 6px);--snk-form-config__add-group-content--border:2px dashed var(--color-strokes, #DCE0E8);--snk-form-config__add-group-content--border-radius:var(--border--radius-small, 6px);--snk-form-config__add-group-label--padding:var(--space--large, 24px);--snk-form-config__btn-add-group--padding:var(--space--large, 24px) var(--space--medium, 12px) 0;--snk-form-config__btn-add-group-container--padding:var(--space--medium, 12px);--snk-form-config__btn-add-group-container--border-radius:var(--border--radius-medium, 12px);--snk-form-config__btn-add-group-container--border:2px solid var(--color-strokes, #DCE0E8);--snk-form-config__btn-add-group-container--background-color:var(--background--body, #fafcff);display:flex;flex-direction:column;position:fixed;top:0;left:0;width:100%;height:100%;z-index:var(--snk-form-config--z-index);background-color:var(--snk-form-config--background-color)}.form-config__header-container.sc-snk-form-config{display:flex}.form-config__field-container.sc-snk-form-config{width:32%;padding:6px}.form-config__hide-content.sc-snk-form-config{display:none}ez-icon.sc-snk-form-config .left-icon.sc-snk-form-config{--ez-icon--color:var(--snk-form-config__icon--color)}.ez-box__label-counter.sc-snk-form-config{margin-top:-7px;font-weight:var(--snk-form-config__label-counter--font-weight)}.form-config__btn-options.sc-snk-form-config{--ez-button--min-width:300px;--ez-button--background-color:var(--snk-form-config--background-color)}[data-draggable-parent].sc-snk-form-config{position:relative}.form-config__field-config--selected.sc-snk-form-config{position:static}.form-config__field-config--dragged.sc-snk-form-config .draggable-mirror.sc-snk-form-config{z-index:var(--snk-form-config--z-index)}.form-config__config-options.sc-snk-form-config{position:relative;margin-top:-3px;min-width:100%;z-index:1}.form-config__tab-container.sc-snk-form-config,.form-config__fields-available.sc-snk-form-config{position:relative;height:100%;max-height:calc(100vh - 92px)}.form-config__tab-container.sc-snk-form-config .ez-box__container.sc-snk-form-config,.form-config__fields-available.sc-snk-form-config .ez-box__container.sc-snk-form-config{align-content:flex-start;height:100%}.form-config__fields-available.sc-snk-form-config [data-draggable-parent].sc-snk-form-config{align-content:flex-start;overflow-y:auto;height:100%;max-height:calc(100% - 122px)}.form-config__tab-content.sc-snk-form-config{align-content:flex-start;overflow-y:auto;height:auto;max-height:calc(100% - 128px)}[data-draggable-element].sc-snk-form-config{cursor:grab}.form-config__actions-button.sc-snk-form-config{--ez-actions-button__btn-action--min-width:235px}.form-config__add-group.sc-snk-form-config{position:relative;min-height:120px;margin-bottom:10px}.form-config__add-group-container.sc-snk-form-config{position:absolute;display:flex;flex-wrap:wrap;width:100%;box-sizing:border-box;border-radius:var(--snk-form-config__add-group-container--border-radius);background-color:var(--snk-form-config__add-group-container--background-color);padding:var(--snk-form-config__add-group-container--padding)}.form-config__add-group-content.sc-snk-form-config{width:100%;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;box-sizing:border-box;border:var(--snk-form-config__add-group-content--border);border-radius:var(--snk-form-config__add-group-content--border-radius)}.form-config__add-group-label.sc-snk-form-config{display:flex;justify-content:center;box-sizing:border-box;padding:var(--snk-form-config__add-group-label--padding)}.form-config__btn-add-group.sc-snk-form-config{position:relative;padding:var(--snk-form-config__btn-add-group--padding)}.form-config__btn-add-group-container.sc-snk-form-config{padding:var(--snk-form-config__btn-add-group-container--padding);border-radius:var(--snk-form-config__btn-add-group-container--border-radius);border:var(--snk-form-config__btn-add-group-container--border);background-color:var(--snk-form-config__btn-add-group-container--background-color)}ez-collapsible-box.draggable-mirror.sc-snk-form-config{display:table;background-color:var(--snk-form-config--background-color)}ez-collapsible-box.sc-snk-form-config{margin-bottom:10px}@media screen and (min-width: 480px){.form-config__field-config--selected.sc-snk-form-config .ez-flex.form-config__config-options.sc-snk-form-config{min-width:calc(300% + 12px)}.form-config__field-config--selected.sc-snk-form-config:nth-child(3n+2) .ez-flex.form-config__config-options.sc-snk-form-config{left:calc(100% / 1 * -1)}.form-config__field-config--selected.sc-snk-form-config:nth-child(3n+3) .ez-flex.form-config__config-options.sc-snk-form-config{left:calc(100% / 1 * -2)}}";export{x as snk_form_config}
|
1
|
+
import{r as i,c as o,h as n,H as t,g as s}from"./p-d2d301a6.js";import{S as e}from"./p-fa816fb2.js";import{ObjectUtils as l,ElementIDUtils as r,ArrayUtils as a,ApplicationContext as d}from"@sankhyalabs/core";import{ApplicationUtils as c,DialogType as f}from"@sankhyalabs/ezui/dist/collection/utils";import{C as h,a as g,T as u,A as m,D as v}from"./p-b0ef4383.js";import{U as b}from"./p-181975f1.js";import{buildFormConfigFromDataUnit as p}from"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-594bc21d.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const _="EZ-COLLAPSIBLE-BOX",z="fieldsWithoutGroupContainer",k="fieldsAvailableContainer",C="addNewGroupContainer",x=class{constructor(n){i(this,n),this.configChange=o(this,"configChange",7),this.configClose=o(this,"configClose",7),this._listEnabledFields=[],this._renderTimer=500,this._tabSelected=1,this._labelNewGroup="Novo grupo",this._mouseOnFieldConfig=!1,this._mouseOnConfigOptions=!1,this._editingTitleGroup=!1,this._newGroupBoxes=[],this._currentGroupBoxes=[],this._formFieldsStyle="ez-col ez-col--sd-12 ez-col--tb-4 ez-padding-right--small ez-padding-bottom--medium sc-snk-form-config",this._fieldsAvailableStyle="ez-col ez-col--sd-12 ez-col--tb-12 ez-margin-bottom--medium ez-margin-right--medium sc-snk-form-config",this._fieldFloatingStyle="form-config__field-config--dragged",this._sortableTimer=100,this._formConfigOptions=[],this._fieldConfigSelected=void 0,this._layoutFormConfig=void 0,this._fieldsAvailable=void 0,this._formConfig={},this._formConfigChanged=!1,this._optionFormConfigSelected=void 0,this._optionFormConfigChanged=!1,this._tempGroups=[],this.dataUnit=void 0,this.configManager=void 0,this.messagesBuilder=void 0}observeConfigManager(){this.loadConfig(this._sortableTimer)}loadFields(i=0){this._layoutFormConfig=[],i>0?setTimeout((()=>{this.buildFields()}),i):this.buildFields()}buildFields(){this.buildFormConfig(),this.buildAvailableFields()}loadFormConfig(i){var o;this._formConfig=this.getConfig(),this.loadFields(i),this.controlFieldConfig(),null!=(null===(o=this._filterFieldsAvailable)||void 0===o?void 0:o.value)&&(this._filterFieldsAvailable.value="")}getConfig(){let i=this.configManager.getConfig(this.dataUnit);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=p(this.dataUnit)),l.copy(i)}cancelChangeConfig(){!0===this._formConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((i=>{i&&(this._formConfigChanged=!1,this.resetChangeConfig())})):this.resetChangeConfig()}cancelChangeOptionConfig(){!0===this._optionFormConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.cancel")).then((i=>{i&&(this._optionFormConfigChanged=!1,this.resetChangeOptionConfig())})):this.resetChangeOptionConfig()}resetChangeConfig(){this.loadFormConfig(this._sortableTimer),this.clearTempGroups()}resetChangeOptionConfig(){this._formConfigChanged=!1,this.loadConfig(this._sortableTimer),this.clearTempGroups()}getTabsToSave(){return this._layoutFormConfig.map(((i,o)=>({label:i.tab,order:o,visible:i.visible})))}getFieldsToSave(){const i=[];return this._formContainer.querySelectorAll("snk-field-config").forEach((o=>{const n=o.fieldConfig;if(null==n)return;const t={cleanOnCopy:n.cleanOnCopy||!1,group:n.group,label:n.label,name:n.name,required:n.required,readOnly:n.readOnly,tab:n.tab};null!=n.defaultValue&&(t.defaultValue=null==n.defaultValue.type?{type:v.fixed,value:n.defaultValue}:n.defaultValue),i.push(t)})),i}isDefaultConfiguration(){var i;return(null===(i=this._optionFormConfigSelected)||void 0===i?void 0:i.origin)===b.DEFAULT&&!0===this._optionFormConfigChanged&&!1===this._formConfigChanged}buildConfigToSave(){let i={};const o=this.isDefaultConfiguration();if(i=o?this.getConfig():l.copy(this._formConfig),!1===o){const o=this.getTabsToSave();(null==o?void 0:o.length)>0&&(i.tabs=o);const n=this.getFieldsToSave();(null==n?void 0:n.length)>0&&(i.fields=n)}return i.defaultConfiguration=o,i}saveConfig(){var i;(null===(i=this._tempGroups)||void 0===i?void 0:i.length)>0?c.alert(this.getMessage("snkFormConfig.confirm.title"),this.getMessage("snkFormConfig.confirm.group")):(this._formConfigChanged=!1,this._optionFormConfigChanged=!1,this.configManager.saveConfig(this.buildConfigToSave()).then((i=>{c.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"}),this.configChange.emit(i)})))}applyOptionConfig(){if(!0===this._optionFormConfigChanged&&null!=this._optionFormConfigSelected){const i=this._optionFormConfigSelected.name||"configuração selecionada",o=this._optionFormConfigSelected.origin===b.DEFAULT?"pessoal":"padrão",n=this.getMessage("snkFormConfig.confirm.apply").replace("{0}",i).replace("{1}",o);this.openConfirmDialog(n).then((i=>{i&&this.saveConfig()}))}else this.saveConfig()}controlFieldConfig(i){var o;this._fieldConfigSelected=null!=i?(null===(o=this._fieldConfigSelected)||void 0===o?void 0:o.name)===(null==i?void 0:i.name)?void 0:i:void 0}getFieldConfigStyle(i){var o;return this._formFieldsStyle+((null===(o=this._fieldConfigSelected)||void 0===o?void 0:o.name)===i.name?" form-config__field-config--selected":"")}getFieldsByGroup(i){var o;return(null===(o=i.fields)||void 0===o?void 0:o.length)?i.fields.map((i=>{var o,t;return n("div",{key:i.name,class:this.getFieldConfigStyle(i),"data-draggable-element":"field",onMouseDown:i=>this.controlMoveField(i)},n("snk-field-config",{messagesBuilder:this.messagesBuilder,onEzClickIcon:i=>{this.handleFieldConfigChange(i)},modeInsertion:!1,fieldConfig:i,dataUnit:this.dataUnit,isConfigActive:(null===(o=this._fieldConfigSelected)||void 0===o?void 0:o.name)===i.name,id:i.name,key:i.name}),(null===(t=this._fieldConfigSelected)||void 0===t?void 0:t.name)===i.name&&n("div",{class:"ez-flex form-config__config-options"},n("snk-config-options",{idConfig:i.name,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,fieldConfig:this._fieldConfigSelected,"data-element-id":this._element.getAttribute(r.DATA_ELEMENT_ID_ATTRIBUTE_NAME),onConfigOptionsChanged:i=>this.handleconfigOptionsChanged(i.detail)})))})):n("div",{class:"form-config__add-group-container"},n("div",{class:"form-config__add-group-content"},n("div",{class:"form-config__add-group-label"},n("label",{class:"ez-text ez-text--center ez-text--medium ez-text--primary ez-text--bold"},this.getMessage("snkFormConfig.form.labelDropField")))))}handleconfigOptionsChanged(i){var o;null===(o=this._formConfig.fields)||void 0===o||o.forEach((()=>{})),this._formConfigChanged=!0}closeFormConfig(){!0===this._formConfigChanged||!0===this._optionFormConfigChanged?this.openConfirmDialog(this.getMessage("snkFormConfig.confirm.exit")).then((i=>{i&&(this._formConfigChanged=!1,this.configClose.emit())})):this.configClose.emit()}openConfirmDialog(i="",o=this.getMessage("snkFormConfig.confirm.title")){return c.confirm(o,i)}controlMoveField(i){const o=null==i?void 0:i.target;null!=(null==o?void 0:o.closest('[data-draggable-element="field"]'))&&(this._mouseOnFieldConfig=!0,null!=(null==o?void 0:o.closest(".form-config__config-options"))||null!=(null==o?void 0:o.closest(".field-config__options"))?this._mouseOnConfigOptions=!0:!1===["minus","settings-inverted","chevron-up"].includes(null==o?void 0:o.iconName)&&this.controlFieldConfig())}controlStartDraggingField(i){var o,n,t;if(this._mouseOnConfigOptions)null==i||i.cancel(),this._mouseOnConfigOptions=!1;else{const s=null===(t=null===(n=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.dragEvent)||void 0===n?void 0:n.data)||void 0===t?void 0:t.sourceContainer;null!=s&&s.classList.add(this._fieldFloatingStyle)}}controlSortedDraggingField(i){var o,n,t,s,e,l,r,a;const d=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.oldContainer,c=null===(n=null==i?void 0:i.data)||void 0===n?void 0:n.newContainer,f=null===(e=null===(s=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.dragEvent)||void 0===s?void 0:s.data)||void 0===e?void 0:e.source,h=null===(a=null===(r=null===(l=null==i?void 0:i.data)||void 0===l?void 0:l.dragEvent)||void 0===r?void 0:r.data)||void 0===a?void 0:a.originalSource;null!=d&&null!=c&&null!=f&&null!=h&&(c.tagName!==_&&c.id!==z||d.id!==k?d.tagName!==_&&d.id!==z||c.id!==k||(f.className=this._fieldsAvailableStyle,f.querySelector("snk-field-config").modeInsertion=!0,h.className=this._fieldsAvailableStyle,h.querySelector("snk-field-config").modeInsertion=!0):(f.className=this._formFieldsStyle,f.querySelector("snk-field-config").modeInsertion=!1,h.className=this._formFieldsStyle,h.querySelector("snk-field-config").modeInsertion=!1))}isCancelDragAvailableField(i,o,n){var t,s;return null!=i&&null!=o&&null!=n&&(null===(t=n.data)||void 0===t?void 0:t.newIndex)!==(null===(s=n.data)||void 0===s?void 0:s.oldIndex)&&i.id===k&&o.id===i.id&&(n.cancel(),this._fieldsAvailable=[],setTimeout((()=>{this.buildAvailableFields()}),this._sortableTimer),!0)}isRemoveField(i,o,n){if(null==i||null==o||null==n)return!1;if((o.tagName===_||o.id===z)&&i.id===k){const i={detail:{field:n,type:m.remove}};return setTimeout((()=>{this.handleFieldConfigChange(i)}),this._renderTimer),!0}return!1}isAddOrMoveField(i,o,n,t){var s;return null!=i&&null!=o&&null!=n&&null!=t&&(t.newIndex!==t.oldIndex||o.dataset.groupName!==i.dataset.groupName||i.id===z&&o.id===k)&&(this.isFieldAvailable(i,o)&&(n.tab=null===(s=this._tabConfig)||void 0===s?void 0:s.selectedTab),n.group=i.dataset.groupName,setTimeout((()=>{i.id.includes(C)&&this.clearTempGroups(!0),this.updateFieldsToSave(o.dataset.groupName!==i.dataset.groupName||i.id===z&&o.id===k?this._sortableTimer:0)}),this._renderTimer),!0)}isFieldAvailable(i,o){return null!=i&&null!=o&&(i.tagName===_||i.id===z)&&o.id===k}controlStopDraggingField(i){var o,n,t,s,e,l;const r=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.oldContainer,a=null===(n=null==i?void 0:i.data)||void 0===n?void 0:n.newContainer;if(this.isCancelDragAvailableField(a,r,i))return;const d=null===(e=null===(s=null===(t=null==i?void 0:i.data)||void 0===t?void 0:t.dragEvent)||void 0===s?void 0:s.data)||void 0===e?void 0:e.originalSource,c=null===(l=null==d?void 0:d.querySelector("snk-field-config"))||void 0===l?void 0:l.fieldConfig;this.isRemoveField(a,r,c)||this.isAddOrMoveField(a,r,c,null==i?void 0:i.data)}updateFieldsToSave(i=0){const o=this.getFieldsToSave();(null==o?void 0:o.length)>0&&(this._formConfig.fields=o),this.loadFields(i),this._formConfigChanged=!0}controlSortableField(){null!=this._sortableContainer&&(this._sortableField&&this._sortableField.destroy(),this._sortableField=new e(this._sortableContainer.querySelectorAll('[data-draggable-parent="field"]'),{draggable:'[data-draggable-element="field"]',mirror:{constrainDimensions:!0},distance:h.dragStartDistance}),this._sortableField.on(g.dragStart,(i=>this.controlStartDraggingField(i))),this._sortableField.on(g.dragSorted,(i=>this.controlSortedDraggingField(i))),this._sortableField.on(g.dragStop,(i=>this.controlStopDraggingField(i))))}controlStartDraggingGroup(i){(this._mouseOnFieldConfig||this._editingTitleGroup)&&(null==i||i.cancel(),this._mouseOnFieldConfig=!1)}controlStopDraggingGroup(i){i.data.newIndex!==i.data.oldIndex&&setTimeout((()=>{this.updateFieldsToSave(this._sortableTimer)}),this._renderTimer)}controlSortableGroup(){null!=this._sortableContainer&&(this._sortableGroup&&this._sortableGroup.destroy(),this._sortableGroup=new e(this._sortableContainer.querySelectorAll('[data-draggable-parent="group"]'),{draggable:'[data-draggable-element="group"]',mirror:{constrainDimensions:!0},distance:h.dragStartDistance}),this._sortableGroup.on(g.dragStart,(i=>this.controlStartDraggingGroup(i))),this._sortableGroup.on(g.dragStop,(i=>this.controlStopDraggingGroup(i))))}loadUserConfig(){null!=this.configManager&&this.configManager.fetchUserAvailableConfigs().then((i=>{if(this._formConfigOptions=i,null==this._formConfigOptions)return;let o=null==this._formConfig||this._formConfig.defaultConfiguration;const n=i.find((i=>i.origin===(o?b.DEFAULT:b.USER)));this.setFormConfig(n)}))}setFormConfig(i){this._optionFormConfigSelected=i}controlSelectFormConfig(i){const o=null==i?void 0:i.detail,n=this._formConfigOptions.find((i=>i.origin===(null==o?void 0:o.value)));this.setFormConfig(n),this._optionFormConfigChanged=!0,this.loadConfigByUser()}changeTabOrder(i){const o=[],n=this._tabConfig.querySelectorAll(".tab-config__tab");this._tabSelected=i,n.forEach(((i,n)=>{var t;if(n){const s=null===(t=i.querySelector(".tab-config__tab-label"))||void 0===t?void 0:t.getAttribute("title");o.push({label:s,order:n-1})}})),this._layoutFormConfig.map((i=>{o.forEach((o=>{o.label===i.tab&&(o.visible=i.visible)}))})),o.length>0&&(this._formConfig.tabs=o,this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0)}async loadConfigByUser(){if(null==this.configManager)return;if(null==this._optionFormConfigSelected)return;let i;switch(this._optionFormConfigSelected.origin){case b.DEFAULT:case b.DEFAULT:i=await this.configManager.fetchDefaultConfig()}null!=i&&(this._formConfig=i,this._tabSelected=1,this.loadFields(this._sortableTimer),this.controlFieldConfig(),this.clearTempGroups())}loadConfig(i=0){this.loadFormConfig(i),this.loadUserConfig()}addNewGroup(){var i,o;const n=null===(i=this._tabConfig)||void 0===i?void 0:i.selectedTab;null==(null===(o=this._tempGroups)||void 0===o?void 0:o.find((i=>i.tab===n&&i.group.includes(this._labelNewGroup))))&&(this._tempGroups.push({tab:n,group:this.handleDuplicateGroups(this._labelNewGroup,this._tabConfig.selectedTab)}),this.loadFields(),this.controlFieldConfig(),this._formConfigChanged=!0)}clearTempGroups(i=!1){var o;(null===(o=this._tempGroups)||void 0===o?void 0:o.length)>0&&(this._tempGroups=i?this._tempGroups.filter((i=>i.tab!==this._tabConfig.selectedTab)):[])}removeGroup(i){null!=i?this._tempGroups=this._tempGroups.filter(((o,n)=>n!==i&&o.tab===this._tabConfig.selectedTab||o.tab!==this._tabConfig.selectedTab)):this.updateFieldsToSave(this._sortableTimer)}checkGroupExists(i,o,n=!1){var t,s,e;const l=null===(t=this._tabConfig)||void 0===t?void 0:t.selectedTab,r=null===(s=this._layoutFormConfig)||void 0===s?void 0:s.find((i=>i.tab===l)),a=null===(e=null==r?void 0:r.groups)||void 0===e?void 0:e.map((i=>{var o;return null===(o=i.group)||void 0===o?void 0:o.toLowerCase()}));if(null==a?void 0:a.includes(null==i?void 0:i.toLowerCase())){const t=this.getMessage("snkFormConfig.confirm.title"),s=`\n ${this.getMessage("snkFormConfig.alert.titleGroupExists")}\n <b>${i}</b>\n ${this.getMessage("snkFormConfig.alert.inTab")}\n <b>${l===u.main?this.getMessage("snkFormConfig.form.mainArea"):l}</b>.\n <br/><br/>\n ${this.getMessage("snkFormConfig.alert.infoValidTitle")}\n `;return c.alert(t,s).then((()=>{var i,t;n?null===(i=this._newGroupBoxes[o])||void 0===i||i.applyFocusTextEdit():null===(t=this._currentGroupBoxes[l][o])||void 0===t||t.applyFocusTextEdit()})),!1}return!0}saveEditLabelTempGroup(i,o){const{newValue:n}=i.detail;null!=this._newGroupBoxes&&null!=this._newGroupBoxes[o]&&(this._newGroupBoxes[o].dataset.groupName=n)}saveEditLabelGroup(i){var o;const{value:n,newValue:t}=i.detail;null===(o=this._formConfig.fields)||void 0===o||o.forEach((i=>{i.group===n&&(i.group=t)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}renderTempGroupByTab(i){return this._tempGroups.map(((o,t)=>{if(o.tab===i)return n("ez-collapsible-box",{ref:i=>this._newGroupBoxes[t]=i,id:`${C}-${t}`,editable:!0,removable:!0,"header-size":"large",label:o.group,"icon-placement":"left","data-group-name":o.group,"data-draggable-parent":"field",class:"form-config__add-group",onEzRemove:()=>this.removeGroup(t),onEzSaveEditLabel:i=>this.saveEditLabelTempGroup(i,t),onEzEditLabelMode:i=>this._editingTitleGroup=i.detail,conditionalSave:i=>this.checkGroupExists(i,t,!0)},this.getFieldsByGroup(o))}))}handleDuplicateGroups(i,o){var n;const t=this._layoutFormConfig[this._tabConfig.selectedIndex].groups.map((i=>i.group));return null!=t&&(null===(n=this._layoutFormConfig)||void 0===n||n.map((n=>{n.tab===o&&n.groups.some((o=>o.group===i))&&(i+=`${this.captureHighestValueTitle(t)}`)}))),i}captureHighestValueTitle(i){let o=[];return null==i||i.map((i=>{null!=i&&o.push(i.replace(/[^0-9]/g,""))})),Math.max.apply(null,o)>0?` (${Math.max.apply(null,o)+1})`:" (1)"}getLayoutFormConfig(){var i,o;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let n=[],t=[];for(const i of this._formConfig.fields)if(null==t.find((o=>i.name===o.name&&i.tab===o.tab))){t.push(i);const s=this.dataUnit.getField(i.name);if(null==s?void 0:s.visible){null!=i.label&&""!==i.label||(i.label=s.label),null!=i.tab&&""!==i.tab||(i.tab=this.getMessage("snkFormConfig.form.tabGeneral"));let t=n.find((o=>o.tab===i.tab));if(null==t){let s=null;if(null!=this._formConfig.tabs){const o=this._formConfig.tabs.filter((o=>o.label===i.tab));o.length>0&&(s=o[0].visible)}const e=(null===(o=i.tab)||void 0===o?void 0:o.label)||i.tab;t=null!==s?{tab:e,groups:[],visible:s}:{tab:e,groups:[],visible:!0},n.push(t)}const e=t.groups.find((o=>o.group===i.group));if(e)e.fields.push(i);else{const o={group:i.group,fields:[i]};void 0===i.group?t.groups.unshift(o):t.groups.push(o)}}}return n}configureTabs(i){var o;return null==(null===(o=this._formConfig)||void 0===o?void 0:o.tabs)?i:(null==i&&(i=[]),this._formConfig.tabs.map((o=>i.find((i=>{var n,t;return(null===(n=o.label)||void 0===n?void 0:n.toLowerCase())===(null===(t=i.tab)||void 0===t?void 0:t.toLowerCase())}))||{tab:o.label,groups:[],visible:o.visible})))}configureTabMain(i){return null==i&&(i=[]),null==i.find((i=>i.tab===u.main))&&i.unshift({tab:u.main,groups:[],visible:!0}),i}updateTabs(){const i=this.getTabsToSave();(null==i?void 0:i.length)>0&&(this._formConfig.tabs=i,1===i.length&&(this._tabSelected=0))}buildFormConfig(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let o=this.getLayoutFormConfig();o=this.configureTabs(o),o=this.configureTabMain(o),this._layoutFormConfig=o,this.updateTabs()}buildAvailableFields(){var i,o;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;let n=[],t=this.dataUnit.metadata.fields;for(const i of this._formConfig.fields)n.push(i);const s=t.filter((({name:i,visible:o})=>!0===o&&!1===n.some((({name:o})=>o===i))));this._fieldsAvailable=s,this._listEnabledFields=s,null!=(null===(o=this._filterFieldsAvailable)||void 0===o?void 0:o.value)&&this.onFilterChange(this._filterFieldsAvailable.value)}changeTabSelected(i){this._tabSelected=i.index;const o=this._formContainer.querySelector("div#tab"+i.index);this._formContainer.querySelectorAll(".form-config__tab-content").forEach((i=>i.className="form-config__hide-content sc-snk-form-config")),o&&(o.className="form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium sc-snk-form-config")}onFilterChange(i){this._fieldsAvailable=a.applyStringFilter(i,this._listEnabledFields,!0,"label")}orderFieldsAvailable(i){return a.sortAlphabetically(i)}handleLabelCounter(i){const o=[this.getMessage("snkFormConfig.availableFields.labelNoFields"),this.getMessage("snkFormConfig.availableFields.labelOneField")];return i>1?`${i} ${this.getMessage("snkFormConfig.availableFields.labelAvailableFields")}`:o[i]}controlAddFieldConfig(i){var o;if(this._formConfigChanged=!1,null==i)return;null==this._formConfig.fields&&(this._formConfig.fields=[]);const n=this._formConfig.fields.filter((o=>o.name===i.name&&o.tab&&i.tab));n.length>0?n.forEach((o=>{o.name=i.name,o.label=i.label,o.required=i.required,o.readOnly=i.readOnly,o.group=i.group})):this._formConfig.fields.push({name:i.name,label:i.label,required:i.required,readOnly:i.readOnly,group:i.group,tab:null===(o=this._tabConfig)||void 0===o?void 0:o.selectedTab}),this.loadFields(),this.controlFieldConfig(),this._formConfigChanged=!0,this.resetSortables()}controlRemoveFieldConfig(i,o){var n;this._formConfigChanged=!1,null!=i&&(this._formConfig.fields=null===(n=this._formConfig.fields)||void 0===n?void 0:n.filter((o=>o.name!==i.name)),this.loadFields(o),this.controlFieldConfig(),this._formConfigChanged=!0,this.resetSortables())}resetSortables(){this.controlSortableField(),this.controlSortableGroup()}handleFieldConfigChange(i,o=0){const{field:n,type:t}=i.detail;t!==m.configuration?t!==m.remove?t!==m.add||this.controlAddFieldConfig(n):this.controlRemoveFieldConfig(n,o):this.controlFieldConfig(n)}changeTabLabel(i){var o,n;const{value:t,newValue:s}=i.detail.detail;null===(o=this._formConfig.fields)||void 0===o||o.forEach((i=>{i.tab===t&&(i.tab=s)})),null===(n=this._formConfig.tabs)||void 0===n||n.forEach((i=>{i.label===t&&(i.label=s)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}handleDeleteTab(i){let o={canClose:!1,labelCancel:this.getMessage("snkFormConfig.confirm.labelCancel"),labelConfirm:this.getMessage("snkFormConfig.confirm.labelDelete"),btnConfirmDanger:!1};const n=this.getMessage("snkFormConfig.confirm.title"),t=this.getMessage("snkFormConfig.confirm.deleteTab")+` <b>${i.detail.label}</b>?`;c.confirm(n,t,null,f.WARN,o).then((o=>{var n;o&&(this._formConfig.tabs=null===(n=this._formConfig.tabs)||void 0===n?void 0:n.filter((o=>o.label!==i.detail.label)),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0)}))}changeHideTab(i){var o;null===(o=this._formConfig.tabs)||void 0===o||o.forEach((o=>{o.label===i.detail.label&&(o.visible=!o.visible)})),this.loadFields(this._sortableTimer),this.controlFieldConfig(),this._formConfigChanged=!0}handleCanStartDragTab(){var i,o;const n=this._layoutFormConfig.map((i=>i.tab));for(const o of n)null===(i=this._currentGroupBoxes[o])||void 0===i||i.map((i=>null==i?void 0:i.cancelEdition()));null===(o=this._newGroupBoxes)||void 0===o||o.map((i=>null==i?void 0:i.cancelEdition()))}getMessage(i,o){return this.messagesBuilder.getMessage(i,o)}componentDidRender(){this.controlSortableField(),this.controlSortableGroup()}async componentWillRender(){if(null==this.messagesBuilder){const i=d.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}componentWillLoad(){this.loadConfig()}componentDidLoad(){r.addIDInfo(this._element,null,{dataUnit:this.dataUnit})}render(){var i,o,s,e;return n(t,null,n("div",{class:"ez-row ez-padding--medium"},n("div",{class:"ez-col ez-col--sd-7 ez-col--tb-9 ez-align--middle"},n("ez-button",{mode:"icon",title:this.getMessage("snkFormConfig.goBackTitle"),iconName:"arrow_back",class:"ez-padding--small",size:"small",onClick:()=>this.closeFormConfig(),id:"formConfigToBack"}),n("h1",{class:"ez-title ez-title--primary ez-title--extra-large ez-padding--small"},this.getMessage("snkFormConfig.title")),this._formConfigOptions&&n("ez-actions-button",{class:"form-config__actions-button ez-margin-left--medium",value:null===(i=this._optionFormConfigSelected)||void 0===i?void 0:i.origin,showLabel:!0,displayIcon:"chevron-down",checkOption:!0,size:"small",actions:this._formConfigOptions.map((i=>({value:i.origin,label:i.name}))),onEzAction:i=>this.controlSelectFormConfig(i),id:"selectConfig"})),n("div",{class:"ez-col ez-col--sd-5 ez-col--tb-3 ez-align--middle ez-align--right"},!0===this._formConfigChanged&&!1===this._optionFormConfigChanged&&n("div",{class:"ez-row ez-align--middle ez-align--right"},n("ez-button",{label:"Cancelar",class:"ez-padding-left--medium",size:"small",onClick:()=>this.cancelChangeConfig()}),n("ez-button",{label:"Salvar",class:"ez-button--primary ez-padding-left--medium",size:"small",onClick:()=>this.saveConfig()},n("ez-icon",{class:"ez-margin-right--small",slot:"leftIcon",iconName:"save"}))),!0===this._optionFormConfigChanged&&n("div",{class:"ez-row ez-align--middle ez-align--right"},n("ez-button",{label:"Cancelar",class:"ez-padding-left--medium",size:"small",onClick:()=>this.cancelChangeOptionConfig()}),n("ez-button",{label:this.getMessage("snkFormConfig.applyConfig"),class:"ez-button--primary ez-padding-left--medium",size:"small",onClick:()=>this.applyOptionConfig()})))),n("div",{class:"ez-row ez-padding--medium",ref:i=>this._sortableContainer=i},n("div",{class:"form-config__tab-container ez-col ez-col--sd-9 ez-col--tb-9 ez-padding-right--medium"},(null===(o=this._layoutFormConfig)||void 0===o?void 0:o.length)>0&&n("section",{class:"ez-box__container",ref:i=>this._formContainer=i},n("snk-tab-config",{ref:i=>this._tabConfig=i,selectedIndex:this._tabSelected,messagesBuilder:this.messagesBuilder,onEzTabChange:i=>this.changeTabSelected(i.detail),onEzOrderChange:i=>this.changeTabOrder(i.detail),onEditionTitleTab:i=>this.changeTabLabel(i),onDeleteTab:i=>this.handleDeleteTab(i),onHideTab:i=>this.changeHideTab(i),onCanStartDrag:()=>this.handleCanStartDragTab(),tabItems:this._layoutFormConfig.map((i=>({tabKey:i.tab,label:i.tab,visible:i.visible})))}),this._layoutFormConfig.map(((i,o)=>n("div",{id:"tab"+o,"data-draggable-parent":"group",class:this._tabSelected===o?"form-config__tab-content ez-flex ez-flex--column ez-size-width--full ez-padding--medium":"form-config__hide-content"},i.groups.map(((o,t)=>o.group?(null==this._currentGroupBoxes[i.tab]&&(this._currentGroupBoxes[i.tab]=[]),n("ez-collapsible-box",{ref:o=>this._currentGroupBoxes[i.tab][t]=o,editable:!0,removable:!0,"header-size":"large",label:o.group,"icon-placement":"left","data-group-name":o.group,"data-draggable-parent":"field","data-draggable-element":"group",onEzRemove:()=>this.removeGroup(),onEzSaveEditLabel:i=>this.saveEditLabelGroup(i),onEzEditLabelMode:i=>this._editingTitleGroup=i.detail,conditionalSave:i=>this.checkGroupExists(i,t)},this.getFieldsByGroup(o))):n("div",{class:"ez-flex ez-flex--column ez-size-width--full"},n("label",{class:"ez-text ez-text--secondary ez-margin-vertical--small"},this.getMessage("snkFormConfig.form.subTitleInfo")),n("div",{id:z,class:"ez-row","data-draggable-parent":"field"},this.getFieldsByGroup(o)),n("hr",{class:"ez-divider-horizontal ez-margin-vertical--medium"})))),this.renderTempGroupByTab(i.tab)))),n("div",{class:"form-config__btn-add-group ez-row"},n("div",{class:"form-config__btn-add-group-container ez-col ez-col--sd-12 ez-col--tb-12 ez-align--center"},n("ez-button",{label:this.getMessage("snkFormConfig.form.labelNewGroup"),class:"ez-padding-horizontal--small ez-button--primary",size:"small",onClick:()=>this.addNewGroup()},n("ez-icon",{class:"ez-margin-right--small",slot:"leftIcon",iconName:"plus"})))))),n("div",{class:"form-config__fields-available ez-col ez-col--sd-3 ez-col--tb-3"},n("section",{class:"ez-box__container ez-col ez-col--pn-12"},n("h1",{class:"ez-title ez-title--large ez-title--primary ez-padding-bottom--medium"},this.getMessage("snkFormConfig.availableFields.title")),n("ez-filter-input",{id:"searchFields",ref:i=>this._filterFieldsAvailable=i,label:this.getMessage("snkFormConfig.availableFields.labelSearchField"),onEzChange:i=>this.onFilterChange(i.detail)}),n("span",{class:"ez-box__label-counter ez-text ez-text--medium ez-text--primary ez-margin-bottom--medium"},this.handleLabelCounter(null===(s=this._fieldsAvailable)||void 0===s?void 0:s.length)),(null===(e=this._layoutFormConfig)||void 0===e?void 0:e.length)>0&&n("div",{id:k,class:"ez-row","data-draggable-parent":"field"},this.orderFieldsAvailable(this._fieldsAvailable).map((i=>n("div",{key:i.name,class:this._fieldsAvailableStyle,"data-draggable-element":"field",onMouseDown:i=>this.controlMoveField(i)},n("snk-field-config",{messagesBuilder:this.messagesBuilder,onEzClickIcon:i=>{this.handleFieldConfigChange(i)},dataUnit:this.dataUnit,fieldConfig:i,id:i.name})))))))))}get _element(){return s(this)}static get watchers(){return{configManager:["observeConfigManager"]}}};x.style=".sc-snk-form-config-h{--snk-form-config--z-index:var(--more-visible, 2);--snk-form-config--background-color:var(--background--xlight, #fff);--snk-form-config__icon--color:var(--text--disable, #AFB6C0);--snk-form-config__label-counter--font-weight:var(--text-weight--extra-small, 200);--snk-form-config__add-group-container--border-radius:var(--border--radius-medium, 12px);--snk-form-config__add-group-container--background-color:var(--background--medium, #d2dce9);--snk-form-config__add-group-container--padding:var(--space--small, 6px);--snk-form-config__add-group-content--border:2px dashed var(--color-strokes, #DCE0E8);--snk-form-config__add-group-content--border-radius:var(--border--radius-small, 6px);--snk-form-config__add-group-label--padding:var(--space--large, 24px);--snk-form-config__btn-add-group--padding:var(--space--large, 24px) var(--space--medium, 12px) 0;--snk-form-config__btn-add-group-container--padding:var(--space--medium, 12px);--snk-form-config__btn-add-group-container--border-radius:var(--border--radius-medium, 12px);--snk-form-config__btn-add-group-container--border:2px solid var(--color-strokes, #DCE0E8);--snk-form-config__btn-add-group-container--background-color:var(--background--body, #fafcff);display:flex;flex-direction:column;position:fixed;top:0;left:0;width:100%;height:100%;z-index:var(--snk-form-config--z-index);background-color:var(--snk-form-config--background-color)}.form-config__header-container.sc-snk-form-config{display:flex}.form-config__field-container.sc-snk-form-config{width:32%;padding:6px}.form-config__hide-content.sc-snk-form-config{display:none}ez-icon.sc-snk-form-config .left-icon.sc-snk-form-config{--ez-icon--color:var(--snk-form-config__icon--color)}.ez-box__label-counter.sc-snk-form-config{margin-top:-7px;font-weight:var(--snk-form-config__label-counter--font-weight)}.form-config__btn-options.sc-snk-form-config{--ez-button--min-width:300px;--ez-button--background-color:var(--snk-form-config--background-color)}[data-draggable-parent].sc-snk-form-config{position:relative}.form-config__field-config--selected.sc-snk-form-config{position:static}.form-config__field-config--dragged.sc-snk-form-config .draggable-mirror.sc-snk-form-config{z-index:var(--snk-form-config--z-index)}.form-config__config-options.sc-snk-form-config{position:relative;margin-top:-3px;min-width:100%;z-index:1}.form-config__tab-container.sc-snk-form-config,.form-config__fields-available.sc-snk-form-config{position:relative;height:100%;max-height:calc(100vh - 92px)}.form-config__tab-container.sc-snk-form-config .ez-box__container.sc-snk-form-config,.form-config__fields-available.sc-snk-form-config .ez-box__container.sc-snk-form-config{align-content:flex-start;height:100%}.form-config__fields-available.sc-snk-form-config [data-draggable-parent].sc-snk-form-config{align-content:flex-start;overflow-y:auto;height:100%;max-height:calc(100% - 122px)}.form-config__tab-content.sc-snk-form-config{align-content:flex-start;overflow-y:auto;height:auto;max-height:calc(100% - 128px)}[data-draggable-element].sc-snk-form-config{cursor:grab}.form-config__actions-button.sc-snk-form-config{--ez-actions-button__btn-action--min-width:235px}.form-config__add-group.sc-snk-form-config{position:relative;min-height:120px;margin-bottom:10px}.form-config__add-group-container.sc-snk-form-config{position:absolute;display:flex;flex-wrap:wrap;width:100%;box-sizing:border-box;border-radius:var(--snk-form-config__add-group-container--border-radius);background-color:var(--snk-form-config__add-group-container--background-color);padding:var(--snk-form-config__add-group-container--padding)}.form-config__add-group-content.sc-snk-form-config{width:100%;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;box-sizing:border-box;border:var(--snk-form-config__add-group-content--border);border-radius:var(--snk-form-config__add-group-content--border-radius)}.form-config__add-group-label.sc-snk-form-config{display:flex;justify-content:center;box-sizing:border-box;padding:var(--snk-form-config__add-group-label--padding)}.form-config__btn-add-group.sc-snk-form-config{position:relative;padding:var(--snk-form-config__btn-add-group--padding)}.form-config__btn-add-group-container.sc-snk-form-config{padding:var(--snk-form-config__btn-add-group-container--padding);border-radius:var(--snk-form-config__btn-add-group-container--border-radius);border:var(--snk-form-config__btn-add-group-container--border);background-color:var(--snk-form-config__btn-add-group-container--background-color)}ez-collapsible-box.draggable-mirror.sc-snk-form-config{display:table;background-color:var(--snk-form-config--background-color)}ez-collapsible-box.sc-snk-form-config{margin-bottom:10px}@media screen and (min-width: 480px){.form-config__field-config--selected.sc-snk-form-config .ez-flex.form-config__config-options.sc-snk-form-config{min-width:calc(300% + 12px)}.form-config__field-config--selected.sc-snk-form-config:nth-child(3n+2) .ez-flex.form-config__config-options.sc-snk-form-config{left:calc(100% / 1 * -1)}.form-config__field-config--selected.sc-snk-form-config:nth-child(3n+3) .ez-flex.form-config__config-options.sc-snk-form-config{left:calc(100% / 1 * -2)}}";export{x as snk_form_config}
|
@@ -1 +1 @@
|
|
1
|
-
import{r as t,c as i,h as e,H as s,g as r}from"./p-d2d301a6.js";import{ElementIDUtils as o,ObjectUtils as l}from"@sankhyalabs/core";import{F as a}from"./p-ff1990ad.js";import{E as n}from"./p-1a68fb59.js";import{C as d}from"./p-
|
1
|
+
import{r as t,c as i,h as e,H as s,g as r}from"./p-d2d301a6.js";import{ElementIDUtils as o,ObjectUtils as l}from"@sankhyalabs/core";import{F as a}from"./p-ff1990ad.js";import{E as n}from"./p-1a68fb59.js";import{C as d}from"./p-3287a6cc.js";import{F as h}from"./p-d9804798.js";import"./p-181975f1.js";import"./p-594bc21d.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const c=class{constructor(e){t(this,e),this.filterChange=i(this,"filterChange",7),this.editPersonalizedFilter=i(this,"editPersonalizedFilter",7),this.addPersonalizedFilter=i(this,"addPersonalizedFilter",7),this.filterItem=void 0,this.configName=void 0,this.resourceID=void 0}observeFilterItem(t){var i,e;this._editor&&(this._editor.config=t),null===(e=null===(i=this._editor)||void 0===i?void 0:i.reloadList)||void 0===e||e.call(i),this.filterChange.emit(t)}getContentEditorConfig(){const t={presentationMode:n.MODAL};switch(this.filterItem.type){case a.BINARY_SELECT:return{tag:"snk-filter-binary-select",props:t};case a.MULTI_SELECT:return{tag:"snk-filter-multi-select"};case a.PERIOD:return{tag:"snk-filter-period",props:t};case a.SEARCH:return{tag:"snk-filter-search"};case a.NUMBER:return{tag:"snk-filter-number",props:t};case a.PERSONALIZED:return this.buildSnkFilterPersonalizedProps();case a.CHECK_BOX_LIST:return{tag:"snk-filter-checkbox-list",props:t};case a.MULTI_LIST:return{tag:"snk-entity-list",props:{maxHeightList:"640px",rightListSlotBuilder:t=>this.buildRightSlot(t)}}}return{tag:"snk-filter-text"}}buildSnkFilterPersonalizedProps(){return{tag:"snk-personalized-filter-editor",props:{onEditFilter:t=>this.editPersonalizedFilter.emit(t.detail),onAddFilter:()=>this.addPersonalizedFilter.emit()}}}isVisible(t){return!!this.filterItem.visible||void 0!==t}updateFilterValue(t){const i=void 0!==(null==t?void 0:t.value)?t.value:t;this.filterItem=Object.assign(Object.assign({},this.filterItem),null!=this.filterItem.groupedItems?{visible:i>0,value:i,groupedItems:t.items}:{value:this.filterItem.type===(a.SEARCH||a.CHECK_BOX_LIST)?t:i,visible:this.isVisible(i)})}handleDeleteFilter(t,i){i===a.PERSONALIZED&&d.removePersonalizedFilter(t,this.resourceID,this.configName)}componentDidLoad(){if(this._element){o.addIDInfo(this._element);const t=this._element.getAttribute(o.DATA_ELEMENT_ID_ATTRIBUTE_NAME);this._idContentEditor=`${t}_${this.filterItem.id}`}}buildRightSlot(t){return e("ez-icon",{iconName:"delete",onClick:()=>this.removeValueFromConfig(t)})}removeValueFromConfig(t){var i,e,s;const r=null===(e=null===(i=this.filterItem)||void 0===i?void 0:i.value)||void 0===e?void 0:e.findIndex((({id:i})=>i===t.id)),o=l.copy(this.filterItem);null===(s=null==o?void 0:o.value)||void 0===s||s.splice(r,1),this.updateFilterValue(o.value)}canShowDetailModal(){const{CUSTOM_FILTER:t,OTHER_FILTERS:i}=h;return![t,i].includes(this.filterItem.filterType)&&this.filterItem.type!==a.BINARY_SELECT}render(){const{tag:t,props:i}=this.getContentEditorConfig();return e(s,null,e("div",{class:"ez-flex ez-flex--column grow"},this.canShowDetailModal()&&e("div",{class:"col ez-col--sd-12 ez-align--right ez-padding-medium ez-flex--align-items-center"},e("div",{class:"ez-title ez-title--small ez-title--primary grow"},this.filterItem.detailModal)),e(t,Object.assign({ref:t=>this._editor=t,config:this.filterItem,value:this.filterItem.value,onValueChanged:t=>this.updateFilterValue(t.detail),"data-element-id":this._idContentEditor},i))))}get _element(){return r(this)}static get watchers(){return{filterItem:["observeFilterItem"]}}};c.style=".grow{flex-grow:1}.gap{gap:4px}";export{c as snk_filter_modal_item}
|
@@ -1 +1 @@
|
|
1
|
-
import{r as i,c as e,h as s,F as t,H as n}from"./p-d2d301a6.js";import{StringUtils as l,ObjectUtils as r,ApplicationContext as a,ElementIDUtils as o}from"@sankhyalabs/core";import{P as h}from"./p-057fad05.js";import{P as d,C as c}from"./p-52920496.js";import{ApplicationUtils as f}from"@sankhyalabs/ezui/dist/collection/utils";import{a as p}from"./p-933c0c0b.js";import{s as z}from"./p-6dc031de.js";import"./p-ff1990ad.js";import"./p-df5451c7.js";import"./p-dc7c9047.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const m=class{constructor(s){i(this,s),this.ezCancel=e(this,"ezCancel",7),this.ezSave=e(this,"ezSave",7),this.ezAfterSave=e(this,"ezAfterSave",7),this._personalizedFilterFetcher=new d,this._filterMetadataStorage=new Map,this._dataSourceFetcher={fetchData:async i=>{let e=null==i?void 0:i.uri;if(l.isEmpty(e)&&(e=this.entityUri),!this._filterMetadataStorage.has(e)){const i=await this._personalizedFilterFetcher.loadFields(e);this._filterMetadataStorage.set(e,i)}return this._filterMetadataStorage.get(e)}},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}async createPersonalizedFilter(){const i={name:"",active:!0,expression:"",parameters:[],assistent:{id:l.generateUUID(),items:[{id:l.generateUUID(),entityName:"",fieldName:"",description:"",fieldLabel:"Valor",type:void 0,expression:void 0,operand:void 0,paramVariable:!1,value:void 0,systemConfig:null,userConfig:null}],childrenGroups:[],operand:p.AND}};this._originalFilterAssistent=r.copy(i),this._filterAssistent=r.copy(i)}loadFilter(i,e){null!=i&&e!=i&&null!=this.resourceID&&c.loadPersonalizedFilter(i,this.resourceID,this.configName).then((i=>{const e=this.applyDefaultValues(i);this._filterAssistent=e,this._originalFilterAssistent=r.copy(e),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent}))}componentWillLoad(){var i;null==z.get(`filterFieldsDataSource.${this.entityUri}`)&&z.set(`filterFieldsDataSource.${this.entityUri}`,this._dataSourceFetcher),this.messagesBuilder||(this._application=a.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"))}getMessage(i,e){return this._application.messagesBuilder.getMessage(i,e)}saveFilter(){c.savePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName).then((i=>{this._elButtonSave.enabled=!1,f.info(this.getMessage(`snkPersonalizedFilter.${this._filterAssistent.id?"confirmEdit":"confirmSave"}.title`),{iconName:"check"});const e=Object.assign(Object.assign({},i),this._filterAssistent);e.parameters=h.buildVariableParameters(this._filterAssistent.assistent),this._originalFilterAssistent=r.copy(e),this._filterAssistent=r.copy(e),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:e}=this._filterAssistent,s=i?h.buildGroupExpression(i):e;this._filterAssistent.expression=s,this.ezSave.emit(s),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:e=""}=await this._personalizedFilterFetcher.validatePersonalizedFilter(this.entityUri,this._filterAssistent.expression);return i||this._application.error(this.getMessage("snkPersonalizedFilter.errorValidation.title"),e.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 e;i&&(this._filterAssistent=r.copy(null!==(e=this._originalFilterAssistent)&&void 0!==e?e:{}),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((e=>{if(null==e.fieldLabel){const s=(i.parameters||[]).find((i=>i.fieldName===e.fieldName));s&&(e.fieldLabel=s.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 e=this.buildExpression(i.entityName,i.name,i.entityPath);this._elAdvancedMode.querySelector("ez-text-area").appendTextToSelection(e)}buildExpression(i,e,s){return s.length>0&&s.shift(),s.length>0?`${s.join("->")}->${e}`:`${i}.${e}`}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 s(t,null,s("ez-button",{class:"snk-personalized-filter__button-mode",label:this.getMessage("snkPersonalizedFilter.info.addField"),enabled:!0,onClick:i=>this.onAddField(i.target)},s("ez-icon",{class:"ez-padding-right--small",slot:"leftIcon",iconName:"plus"})),s("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 s("ez-view-stack",{ref:i=>this._viewStackRef=i},s("stack-item",null,this._filterAssistentMode&&s("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)})),s("stack-item",null,s("snk-filter-advanced-mode",{ref:i=>this._elAdvancedMode=i,filterAssistent:this._filterAssistent,application:this._application,onEzExpressionChange:i=>this.handleExpressionChangeAdvancedMode(i.detail)})))}handleModeChange(){var i,e;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===(e=this._originalFilterAssistent)||void 0===e?void 0:e.expression))this._filterAssistentMode=!this._filterAssistentMode;else{const i=this._filterAssistent.expression,e=h.buildGroupExpression(this._filterAssistent.assistent);i!==e?f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.description")).then((i=>{i&&(this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:e}),this._filterAssistentMode=!this._filterAssistentMode)})):this._filterAssistentMode=!this._filterAssistentMode}}render(){var i,e,t,l;if((null===(i=this._filterAssistent)||void 0===i?void 0:i.assistent)||!this._filterAssistentMode)return s(n,null,s("div",{class:"snk-personalized-filter"},s("div",null,s("snk-simple-bar",{label:this.getMessage(this.filterId?"snkPersonalizedFilter.info.titleEdit":"snkPersonalizedFilter.info.titleAdd"),onExit:()=>this.handleCancel()},s("div",{class:"snk-personalized-filter__header-actions",slot:"rightSlot"},s("ez-button",{size:"small",label:this.getMessage("snkPersonalizedFilter.info.labelCancel"),onClick:()=>this.handleCancel()}),s("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)})))),s("div",{class:"ez-box ez-margin-bottom--medium ez-box__main"},s("div",{class:"ez-box__container"},s("div",{class:"ez-flex ez-flex--column ez-size-width--full"},s("div",{class:"ez-flex"},s("ez-text-input",{class:"ez-padding-right--medium",label:this.getMessage("snkPersonalizedFilter.info.labelNameFilter"),value:null===(e=this._filterAssistent)||void 0===e?void 0:e.name,onEzChange:i=>this.handleTitleChange(i.detail)}),this.renderButtonAddField(),s("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===(t=this._filterAssistent)||void 0===t?void 0:t.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 e,h as s,F as t,H as n}from"./p-d2d301a6.js";import{StringUtils as l,ObjectUtils as r,ApplicationContext as a,ElementIDUtils as o}from"@sankhyalabs/core";import{P as h}from"./p-057fad05.js";import{P as d,C as c}from"./p-3287a6cc.js";import{ApplicationUtils as f}from"@sankhyalabs/ezui/dist/collection/utils";import{a as p}from"./p-933c0c0b.js";import{s as z}from"./p-6dc031de.js";import"./p-ff1990ad.js";import"./p-181975f1.js";import"./p-594bc21d.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const m=class{constructor(s){i(this,s),this.ezCancel=e(this,"ezCancel",7),this.ezSave=e(this,"ezSave",7),this.ezAfterSave=e(this,"ezAfterSave",7),this._personalizedFilterFetcher=new d,this._filterMetadataStorage=new Map,this._dataSourceFetcher={fetchData:async i=>{let e=null==i?void 0:i.uri;if(l.isEmpty(e)&&(e=this.entityUri),!this._filterMetadataStorage.has(e)){const i=await this._personalizedFilterFetcher.loadFields(e);this._filterMetadataStorage.set(e,i)}return this._filterMetadataStorage.get(e)}},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}async createPersonalizedFilter(){const i={name:"",active:!0,expression:"",parameters:[],assistent:{id:l.generateUUID(),items:[{id:l.generateUUID(),entityName:"",fieldName:"",description:"",fieldLabel:"Valor",type:void 0,expression:void 0,operand:void 0,paramVariable:!1,value:void 0,systemConfig:null,userConfig:null}],childrenGroups:[],operand:p.AND}};this._originalFilterAssistent=r.copy(i),this._filterAssistent=r.copy(i)}loadFilter(i,e){null!=i&&e!=i&&null!=this.resourceID&&c.loadPersonalizedFilter(i,this.resourceID,this.configName).then((i=>{const e=this.applyDefaultValues(i);this._filterAssistent=e,this._originalFilterAssistent=r.copy(e),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent}))}componentWillLoad(){var i;null==z.get(`filterFieldsDataSource.${this.entityUri}`)&&z.set(`filterFieldsDataSource.${this.entityUri}`,this._dataSourceFetcher),this.messagesBuilder||(this._application=a.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"))}getMessage(i,e){return this._application.messagesBuilder.getMessage(i,e)}saveFilter(){c.savePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName).then((i=>{this._elButtonSave.enabled=!1,f.info(this.getMessage(`snkPersonalizedFilter.${this._filterAssistent.id?"confirmEdit":"confirmSave"}.title`),{iconName:"check"});const e=Object.assign(Object.assign({},i),this._filterAssistent);e.parameters=h.buildVariableParameters(this._filterAssistent.assistent),this._originalFilterAssistent=r.copy(e),this._filterAssistent=r.copy(e),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:e}=this._filterAssistent,s=i?h.buildGroupExpression(i):e;this._filterAssistent.expression=s,this.ezSave.emit(s),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:e=""}=await this._personalizedFilterFetcher.validatePersonalizedFilter(this.entityUri,this._filterAssistent.expression);return i||this._application.error(this.getMessage("snkPersonalizedFilter.errorValidation.title"),e.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 e;i&&(this._filterAssistent=r.copy(null!==(e=this._originalFilterAssistent)&&void 0!==e?e:{}),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((e=>{if(null==e.fieldLabel){const s=(i.parameters||[]).find((i=>i.fieldName===e.fieldName));s&&(e.fieldLabel=s.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 e=this.buildExpression(i.entityName,i.name,i.entityPath);this._elAdvancedMode.querySelector("ez-text-area").appendTextToSelection(e)}buildExpression(i,e,s){return s.length>0&&s.shift(),s.length>0?`${s.join("->")}->${e}`:`${i}.${e}`}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 s(t,null,s("ez-button",{class:"snk-personalized-filter__button-mode",label:this.getMessage("snkPersonalizedFilter.info.addField"),enabled:!0,onClick:i=>this.onAddField(i.target)},s("ez-icon",{class:"ez-padding-right--small",slot:"leftIcon",iconName:"plus"})),s("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 s("ez-view-stack",{ref:i=>this._viewStackRef=i},s("stack-item",null,this._filterAssistentMode&&s("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)})),s("stack-item",null,s("snk-filter-advanced-mode",{ref:i=>this._elAdvancedMode=i,filterAssistent:this._filterAssistent,application:this._application,onEzExpressionChange:i=>this.handleExpressionChangeAdvancedMode(i.detail)})))}handleModeChange(){var i,e;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===(e=this._originalFilterAssistent)||void 0===e?void 0:e.expression))this._filterAssistentMode=!this._filterAssistentMode;else{const i=this._filterAssistent.expression,e=h.buildGroupExpression(this._filterAssistent.assistent);i!==e?f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.description")).then((i=>{i&&(this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:e}),this._filterAssistentMode=!this._filterAssistentMode)})):this._filterAssistentMode=!this._filterAssistentMode}}render(){var i,e,t,l;if((null===(i=this._filterAssistent)||void 0===i?void 0:i.assistent)||!this._filterAssistentMode)return s(n,null,s("div",{class:"snk-personalized-filter"},s("div",null,s("snk-simple-bar",{label:this.getMessage(this.filterId?"snkPersonalizedFilter.info.titleEdit":"snkPersonalizedFilter.info.titleAdd"),onExit:()=>this.handleCancel()},s("div",{class:"snk-personalized-filter__header-actions",slot:"rightSlot"},s("ez-button",{size:"small",label:this.getMessage("snkPersonalizedFilter.info.labelCancel"),onClick:()=>this.handleCancel()}),s("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)})))),s("div",{class:"ez-box ez-margin-bottom--medium ez-box__main"},s("div",{class:"ez-box__container"},s("div",{class:"ez-flex ez-flex--column ez-size-width--full"},s("div",{class:"ez-flex"},s("ez-text-input",{class:"ez-padding-right--medium",label:this.getMessage("snkPersonalizedFilter.info.labelNameFilter"),value:null===(e=this._filterAssistent)||void 0===e?void 0:e.name,onEzChange:i=>this.handleTitleChange(i.detail)}),this.renderButtonAddField(),s("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===(t=this._filterAssistent)||void 0===t?void 0:t.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}
|