@sankhyalabs/sankhyablocks 9.1.0-ms.3 → 9.1.0-ms.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/cjs/{ClientSideExporterProvider-b7943abc.js → ClientSideExporterProvider-6a4108c9.js} +4 -4
  2. package/dist/cjs/{ConfigStorage-48ba265b.js → ConfigStorage-34aa43d8.js} +2 -2
  3. package/dist/cjs/{DataFetcher-1afdb18e.js → DataFetcher-e23a263b.js} +6 -1
  4. package/dist/cjs/{ISave-c76e2c51.js → ISave-e0be2362.js} +1 -1
  5. package/dist/cjs/{SnkFormConfigManager-aa4631bd.js → SnkFormConfigManager-61bf3266.js} +2 -2
  6. package/dist/cjs/{auth-fetcher-1687ac0a.js → auth-fetcher-8670a38f.js} +1 -1
  7. package/dist/cjs/{dataunit-fetcher-c2aef198.js → dataunit-fetcher-c34a8217.js} +1 -1
  8. package/dist/cjs/{form-config-fetcher-40d3f752.js → form-config-fetcher-d8b78403.js} +1 -1
  9. package/dist/cjs/pesquisa-grid_2.cjs.entry.js +4 -4
  10. package/dist/cjs/snk-actions-button_8.cjs.entry.js +5 -5
  11. package/dist/cjs/snk-application.cjs.entry.js +6 -6
  12. package/dist/cjs/snk-attach.cjs.entry.js +5 -5
  13. package/dist/cjs/snk-configurator.cjs.entry.js +1 -1
  14. package/dist/cjs/snk-crud.cjs.entry.js +6 -5
  15. package/dist/cjs/snk-data-exporter.cjs.entry.js +5 -5
  16. package/dist/cjs/{snk-data-unit-87c56d62.js → snk-data-unit-a4f9287b.js} +1 -1
  17. package/dist/cjs/snk-data-unit.cjs.entry.js +3 -3
  18. package/dist/cjs/snk-detail-view.cjs.entry.js +7 -7
  19. package/dist/cjs/snk-filter-bar_4.cjs.entry.js +3 -3
  20. package/dist/cjs/snk-filter-modal-item.cjs.entry.js +3 -3
  21. package/dist/cjs/snk-form_2.cjs.entry.js +4 -4
  22. package/dist/cjs/snk-grid.cjs.entry.js +6 -6
  23. package/dist/cjs/{snk-guides-viewer-fedf7ba8.js → snk-guides-viewer-29298823.js} +5 -5
  24. package/dist/cjs/snk-guides-viewer.cjs.entry.js +7 -7
  25. package/dist/cjs/snk-personalized-filter.cjs.entry.js +3 -3
  26. package/dist/cjs/snk-pesquisa.cjs.entry.js +4 -4
  27. package/dist/cjs/snk-simple-crud.cjs.entry.js +7 -7
  28. package/dist/collection/components/snk-configurator/snk-configurator.js +1 -1
  29. package/dist/collection/components/snk-crud/snk-crud.js +19 -0
  30. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +6 -1
  31. package/dist/components/DataFetcher.js +6 -1
  32. package/dist/components/snk-configurator2.js +1 -1
  33. package/dist/components/snk-crud.js +1 -0
  34. package/dist/esm/{ClientSideExporterProvider-b468acad.js → ClientSideExporterProvider-09dee1a3.js} +4 -4
  35. package/dist/esm/{ConfigStorage-79b9e180.js → ConfigStorage-89154c4e.js} +2 -2
  36. package/dist/esm/{DataFetcher-88e56266.js → DataFetcher-db08cad0.js} +6 -1
  37. package/dist/esm/{ISave-5efafc97.js → ISave-da565824.js} +1 -1
  38. package/dist/esm/{SnkFormConfigManager-b4b93298.js → SnkFormConfigManager-d64d62d6.js} +2 -2
  39. package/dist/esm/{auth-fetcher-3510520e.js → auth-fetcher-43c8d76b.js} +1 -1
  40. package/dist/esm/{dataunit-fetcher-613a6fb9.js → dataunit-fetcher-1b78797a.js} +1 -1
  41. package/dist/esm/{form-config-fetcher-fa208a6c.js → form-config-fetcher-e623539b.js} +1 -1
  42. package/dist/esm/pesquisa-grid_2.entry.js +4 -4
  43. package/dist/esm/snk-actions-button_8.entry.js +5 -5
  44. package/dist/esm/snk-application.entry.js +6 -6
  45. package/dist/esm/snk-attach.entry.js +5 -5
  46. package/dist/esm/snk-configurator.entry.js +1 -1
  47. package/dist/esm/snk-crud.entry.js +6 -5
  48. package/dist/esm/snk-data-exporter.entry.js +5 -5
  49. package/dist/esm/{snk-data-unit-8da2d175.js → snk-data-unit-330db397.js} +1 -1
  50. package/dist/esm/snk-data-unit.entry.js +3 -3
  51. package/dist/esm/snk-detail-view.entry.js +7 -7
  52. package/dist/esm/snk-filter-bar_4.entry.js +3 -3
  53. package/dist/esm/snk-filter-modal-item.entry.js +3 -3
  54. package/dist/esm/snk-form_2.entry.js +4 -4
  55. package/dist/esm/snk-grid.entry.js +6 -6
  56. package/dist/esm/{snk-guides-viewer-0fc793de.js → snk-guides-viewer-9335318d.js} +5 -5
  57. package/dist/esm/snk-guides-viewer.entry.js +7 -7
  58. package/dist/esm/snk-personalized-filter.entry.js +3 -3
  59. package/dist/esm/snk-pesquisa.entry.js +4 -4
  60. package/dist/esm/snk-simple-crud.entry.js +7 -7
  61. package/dist/sankhyablocks/{p-d0d8de69.entry.js → p-0750661e.entry.js} +1 -1
  62. package/dist/sankhyablocks/{p-cb4bcf34.entry.js → p-1079e61b.entry.js} +1 -1
  63. package/dist/sankhyablocks/{p-134414d0.entry.js → p-1c69a957.entry.js} +1 -1
  64. package/dist/sankhyablocks/p-22a8656b.entry.js +1 -0
  65. package/dist/sankhyablocks/{p-a5bb2f93.entry.js → p-2d58f98e.entry.js} +1 -1
  66. package/dist/sankhyablocks/{p-59d84130.entry.js → p-2ebd3bfd.entry.js} +1 -1
  67. package/dist/sankhyablocks/{p-9751c42f.entry.js → p-31193a60.entry.js} +1 -1
  68. package/dist/sankhyablocks/{p-8f8367d5.js → p-37b4f642.js} +1 -1
  69. package/dist/sankhyablocks/{p-6d2c841d.js → p-3b1d73f9.js} +1 -1
  70. package/dist/sankhyablocks/{p-a6513fcb.js → p-412e06e9.js} +1 -1
  71. package/dist/sankhyablocks/p-5126b34e.entry.js +1 -0
  72. package/dist/sankhyablocks/{p-5b963f03.entry.js → p-5b31b239.entry.js} +1 -1
  73. package/dist/sankhyablocks/{p-f21325f1.entry.js → p-7c9815ea.entry.js} +1 -1
  74. package/dist/sankhyablocks/{p-6416975c.js → p-8758404f.js} +1 -1
  75. package/dist/sankhyablocks/{p-8691b78e.entry.js → p-9a6fbf3d.entry.js} +1 -1
  76. package/dist/sankhyablocks/{p-a414a26c.entry.js → p-a2c6944d.entry.js} +1 -1
  77. package/dist/sankhyablocks/{p-601b252b.js → p-b21d32f6.js} +1 -1
  78. package/dist/sankhyablocks/{p-c926cf6b.entry.js → p-b2946adb.entry.js} +1 -1
  79. package/dist/sankhyablocks/{p-6dd38d7b.js → p-c9657baa.js} +1 -1
  80. package/dist/sankhyablocks/{p-536dc236.entry.js → p-c99293d5.entry.js} +1 -1
  81. package/dist/sankhyablocks/p-cb2a4613.entry.js +1 -0
  82. package/dist/sankhyablocks/{p-fbba7e3d.js → p-cd1a5b6a.js} +1 -1
  83. package/dist/sankhyablocks/{p-73285a8a.js → p-e25412da.js} +1 -1
  84. package/dist/sankhyablocks/p-e56eb36b.entry.js +1 -0
  85. package/dist/sankhyablocks/{p-e0313142.entry.js → p-f442c8f6.entry.js} +1 -1
  86. package/dist/sankhyablocks/{p-7bb04271.js → p-fa591f6f.js} +1 -1
  87. package/dist/sankhyablocks/{p-848c0ece.js → p-fc87708a.js} +1 -1
  88. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  89. package/dist/types/components/snk-crud/snk-crud.d.ts +1 -0
  90. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +1 -0
  91. package/package.json +1 -1
  92. package/dist/sankhyablocks/p-9ad3557c.entry.js +0 -1
  93. package/dist/sankhyablocks/p-ef2022ac.entry.js +0 -1
  94. package/dist/sankhyablocks/p-efb76b5f.entry.js +0 -1
  95. package/dist/sankhyablocks/p-fac65ae7.entry.js +0 -1
@@ -1 +1 @@
1
- import{r as t,h as i,H as s,g as e,c as n}from"./p-d8d8169b.js";import{ApplicationContext as o,StringUtils as a,ErrorException as r,WarningException as l,ObjectUtils as c,DateUtils as d,ServiceUtils as h,StorageType as u,ArrayUtils as g,ElementIDUtils as p}from"@sankhyalabs/core";import{D as m}from"./p-fbba7e3d.js";import{P as f}from"./p-eaad0aa8.js";import"./p-6dd38d7b.js";import"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-8f8367d5.js";import"./p-ff1990ad.js";import{F as v}from"./p-601b252b.js";import{O as b}from"./p-9019a32f.js";import{g as _}from"./p-7dd49d15.js";import{R as k}from"./p-688dcb4c.js";import{ApplicationUtils as w,DialogType as y,FormLayout as x}from"@sankhyalabs/ezui/dist/collection/utils";import{C}from"./p-6416975c.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";class z{execute(t){var i;const s={actionID:t.actionID,refreshType:null===(i=t.actionConfig.javaCall)||void 0===i?void 0:i.refreshType};return new Promise((t=>{t({execSource:s,callback:this.callExecJava})}))}async callExecJava(t){const i={requestBody:{javaCall:t}};await m.get().callServiceBroker("ActionButtonsSP.executeJava",JSON.stringify(i))}}class S{execute(t){var i;const s={actionID:t.actionID,refreshType:null===(i=t.actionConfig.runScript)||void 0===i?void 0:i.refreshType};return new Promise((t=>{t({execSource:s,callback:this.callExecScript})}))}async callExecScript(t){const i={runScript:t};await m.get().callServiceBroker("ActionButtonsSP.executeScript",i)}}class A{constructor(){this._application=o.getContextValue("__SNK__APPLICATION__")}async execute(t,i){const s=t.resourceID;if(!s)return;let e=await this.buildLaunchObject(t,i);return this._application.openApp(s,e),null}buildLaunchObject(t,i){return new Promise((s=>{let e=t.actionConfig.params.param;if(e&&e.length>0){let n={},o=[];e.forEach((s=>{const e=s.localField;let l=i.getFieldValue(e);if(!l){let s=i.getField(e).label;throw s=a.isEmpty(i.getField(e).label)?e:s,new r(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.launchScreen.emptyField",{description:t.description,localFieldLabel:s}))}l=a.isEmpty(l.toString())?void 0:l.toString(),n[s.targetField]=l,o.push({fieldName:s.targetField,value:l})})),n.ACTION_PARAMETERS=o,n.call_time=Date.now(),s(n)}s(null)}))}}class L{execute(t){var i,s,e;const n=null===(i=t.actionConfig.dbCall)||void 0===i?void 0:i.name,o=null===(s=t.actionConfig.dbCall)||void 0===s?void 0:s.rootEntity,a={actionID:t.actionID,refreshType:null===(e=t.actionConfig.dbCall)||void 0===e?void 0:e.refreshType,procName:n,rootEntity:o};return new Promise((t=>{t({execSource:a,callback:this.callExecProcedure})}))}async callExecProcedure(t){const i={requestBody:{stpCall:t}};await m.get().callServiceBroker("ActionButtonsSP.executeSTP",JSON.stringify(i))}}var O,P;!function(t){t.LAUNCH_SCREEN="LC",t.JAVASCRIPT="SC",t.JAVA="RJ",t.PROCEDURE="SP",t.EMBEDDED="EB"}(O||(O={}));class I{constructor(t){this.actionType=t,this._application=o.getContextValue("__SNK__APPLICATION__")}get executor(){switch(this.actionType){case O.LAUNCH_SCREEN:return new A;case O.JAVASCRIPT:return new S;case O.JAVA:return new z;case O.PROCEDURE:return new L;default:throw new r(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.nonExistentType",{actionType:this.actionType}))}}}!function(t){t.NONE="NONE",t.PARENT="PARENT",t.MASTER="MASTER",t.ALL="ALL"}(P||(P={}));const N="__MASTER_ROW__";class T{constructor(t,i,s){var e;this._lastValuesCache={},this._actionsExecuteInterface=t,this._dataUnit=i,this._selectedRows=(null===(e=null==i?void 0:i.getSelectionInfo())||void 0===e?void 0:e.isAllRecords())?[]:null==i?void 0:i.getSelectionInfo().records,this._application=o.getContextValue("__SNK__APPLICATION__"),this._appResourceId=s}getPrimaryKeys(){return _(this._dataUnit).map((({name:t})=>t))}apply(t,i){this._application.closePopUp(),this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:s,callback:e})=>{this.resolvePromptParams(t,s,i).then((()=>{this.actionExecute(s,e)}))}))}async execute(t){var i;if(!t.actionConfig)throw new l(this._application.messagesBuilder.getMessage("snkActionsButton.title.warning",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.incorrectAction",{description:t.description}));if(null===(i=t.actionConfig.params)||void 0===i?void 0:i.promptParam){const i=t.actionConfig.params.promptParam;let s=!1;for(let t=0;t<i.length;t++)if(!s&&"true"===i[t].saveLast){s=!0;break}s&&(t.actionConfig.params.promptParam=await this.loadSavedValuesIntoParams(t));const e=document.createElement("snk-actions-form");window.document.body.appendChild(e),e.action=c.copy(t),e.applyParameters=t=>{this.apply(t,s)},e.openPopup()}else t.type!=O.LAUNCH_SCREEN?this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:t,callback:i})=>{this.actionExecute(t,i)})):this._actionsExecuteInterface.execute(t,this._dataUnit)}loadSavedValuesIntoParams(t){return this.loadLastValues(t).then((i=>{let s=t.actionConfig.params.promptParam;return i&&i.param.forEach((t=>{s=s.map((i=>i.name!==t.paramName?i:Object.assign(Object.assign({},i),"B"===i.paramType?{value:"S"===t.$}:{value:t.$})))})),s}))}async actionExecute(t,i){t.virtualPage=this.buildVirtualPage(),await this.prepareAndExecute(t,i),this.recordsReloader(t.refreshType)}resolvePromptParams(t,i,s){return new Promise((e=>{let n=[];t.actionConfig.params.promptParam.forEach((t=>{n.push(this.buildPromptParam(t))})),this.putParamsOnExecSource(n,i),s&&this.saveLastValues(t,n),e()}))}buildPromptParam(t){let i,s,e=t.paramType,n=!1,o=t.value;switch(e){case f.DATE:e="D";break;case f.DATETIME:e="H";break;case f.DECIMAL:e="F",i={"sk-precision":Number(t.precision)};break;case f.BOOLEAN:e="S",n=!0,o=t.value?"S":"N";break;case f.ENTITY:i={"sk-entity-name":t.entityName,"sk-allow-show-hierarchical-mode":t.hierarchyEntity,"sk-data-type":"S"},t.hierarchyEntity&&t.entityPK&&(s=t.entityPK),o=t.value?Number(t.value):null;break;case f.OPTIONS:e="O";let a=t.options.split(";").map((function(t,i){let s,e;if(t.indexOf("=")>-1){let i=t.split("=");s=i[0],e=i[1]}else s=i+1,e=t;return{data:s,value:e}}));i={"sk-options":a}}return{description:t.label,required:"true"==t.required,fieldName:t.name,fieldNameOri:t.name,entityPK:s,paramType:t.paramType,type:e,isCheckbox:n,saveLast:t.saveLast,fieldProp:i,value:o,isGeneratedName:t.isGeneratedName}}putParamsOnExecSource(t,i){i.params={param:[]},t.forEach((t=>{if(t.isGeneratedName&&t.value)throw new r(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.emptyParamName",void 0));a.isEmpty(t.value)||i.params.param.push({type:this.getParamDataType(t.paramType),paramName:t.fieldName,$:this.getParamValue(t)})}))}getParamDataType(t){let i;switch(t){case"D":i="F";break;case"DT":case"DH":i="D";break;case"B":case"ENTITY":case"SO":i="S";break;default:i=t}return i}getParamValue(t){let i=t.value;return i?("DT"==t.paramType?i=d.formatDate(i):"DH"==t.paramType&&(i=d.formatDateTime(i)),i):i}async loadLastValues(t){const i=await this.buildResourceId(t.actionID);return new Promise(((t,s)=>{if(this._lastValuesCache[i])t(this._lastValuesCache[i]);else{const e={config:{chave:i,tipo:"T"}};m.get().callServiceBroker("SystemUtilsSP.getConf",e).then((s=>{var e,n;let o;(null===(n=null===(e=s.config)||void 0===e?void 0:e.data)||void 0===n?void 0:n.params)&&(o=s.config.data.params,Array.isArray(o.param)||(o.param=[o.param])),this._lastValuesCache[i]=o,t(o)})).catch((t=>{s(t)}))}}))}async saveLastValues(t,i){if(this._application){let s={params:{param:[]}};i.forEach((t=>{"true"==t.saveLast&&s.params.param.push({paramName:t.fieldName,$:t.value})}));const e=await this.buildResourceId(t.actionID);this._lastValuesCache[e]=s.params,this._application.saveConfig(e,s)}}async buildResourceId(t){return this._appResourceId+".actionconfig."+t}async prepareAndExecute(t,i){this.addRows(t),await i(t)}addRows(t){const i=this.getPrimaryKeys(),s={row:[]},e=this._selectedRows;for(const t in e){const n=e[t],o={};n.hasOwnProperty(N)&&(o.master="S",o.entityName=n.__ENTITY_NAME__,delete n[N],delete n.__ENTITY_NAME__),o.field||(o.field=[]);for(const t of i)o.field.push({fieldName:t,$:n[t]});s.row.push(o)}s.row.length>0&&(t.rows=s)}recordsReloader(t){switch(t){case P.NONE:break;case P.PARENT:case P.MASTER:case P.ALL:this._dataUnit.loadData();break;default:this._dataUnit.reloadCurrentRecord()}}buildVirtualPage(){var t,i,s,e;if(null===(i=null===(t=this._dataUnit)||void 0===t?void 0:t.getSelectionInfo())||void 0===i?void 0:i.isAllRecords())return{filters:{filters:null===(s=this._dataUnit)||void 0===s?void 0:s.getAppliedFilters()},orders:{orders:null===(e=this._dataUnit)||void 0===e?void 0:e.getSort()}}}}class D{async clientConfirm(t,i){return new Promise((s=>{const e=o.getContextValue("__SNK__APPLICATION__");let n="";t.content.event.hasOwnProperty("stpCall")?(i.requestBody=t.content.event.stpCall,n=O.PROCEDURE):t.content.event.hasOwnProperty("runScript")?(i.requestBody=t.content.event.runScript,n=O.JAVASCRIPT):t.content.event.hasOwnProperty("javaCall")&&(i.requestBody=t.content.event.javaCall,n=O.JAVA);let a={type:"S",sequence:t.content.event.sequence};i.requestBody.params?Array.isArray(i.requestBody.params.param)||(i.requestBody.params.param=[i.requestBody.params.param]):i.requestBody.params={param:[]},i.requestBody.params.param.push(a);const r=t.content.event.title.$,l=t.content.event.message.$;let c;switch(n){case O.JAVASCRIPT:c={runScript:i.requestBody};break;case O.PROCEDURE:c={requestBody:{stpCall:i.requestBody}};break;case O.JAVA:c={requestBody:{javaCall:i.requestBody}}}if("S"==t.content.event.showNoOption){a.paramName="__ESCOLHA_SIMNAO__";const t=document.createElement("snk-client-confirm");window.document.body.appendChild(t),t.titleMessage=r,t.message=l,t.accept=async()=>{a.$="S",await i.reCall(c),s()},t.cancel=async()=>{a.$="N",await i.reCall(c),s()},t.openPopup()}else e.confirm(r,l,null,"warn",{labelCancel:"Cancelar",labelConfirm:"Sim"}).then((async t=>{t&&(a.paramName="__CONFIRMACAO__",a.$="S",await i.reCall(c),s())}))}))}}const E=class{constructor(i){t(this,i),this.CLIENT_EVENT_CONFIRM_NAME="br.com.sankhya.actionbutton.clientconfirm",this._actions=[],this.handleClick=t=>{const i=this._actions.find((i=>i.actionID==t.detail.id)),s=new I(i.type).executor;new T(s,this._dataUnit,this._resourceID).execute(Object.assign({},i)),this._showDropdown=!1},this._items=[],this._showDropdown=!1}async getActions(){const t=await h.useCacheWithService(`SnkActionsButton_${this._entityName}-${this._resourceID}`,(async()=>{var t;const i={param:{entityName:this._entityName,resourceID:this._resourceID}};return(null===(t=(await m.get().callServiceBroker("ActionButtonsSP.getActions",i)).actions)||void 0===t?void 0:t.action)||[]}),u.IN_MEMORY_CACHE);this._actions=E.parameters.isOrderActions?g.sortAlphabetically(t,"description"):t}controlDropdown(){this._showDropdown=!this._showDropdown}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this._items)||void 0===t?void 0:t.length)>0}positionDropdown(){var t;const i=null===(t=this._ezButton)||void 0===t?void 0:t.getBoundingClientRect();i&&this._dropdownParent&&(this._dropdownParent.style.top=i.y+i.height+5+"px",this._dropdownParent.style.left=i.x+"px")}closeDropdown(t){const i=null==t?void 0:t.target;i&&(i.closest(".snk-actions-button")||(this._showDropdown=!1))}setEvents(){document.removeEventListener("click",this.closeDropdown.bind(this)),document.addEventListener("click",this.closeDropdown.bind(this)),document.removeEventListener("scroll",this.positionDropdown.bind(this)),document.addEventListener("scroll",this.positionDropdown.bind(this))}async componentWillLoad(){this._application=o.getContextValue("__SNK__APPLICATION__"),await this.loadParameters();const t=this._element.parentElement;this._dataUnit=null==t?void 0:t.dataUnit,this._resourceID=null==t?void 0:t.resourceID,this._entityName=this._dataUnit.name.split("/")[2],null==this._resourceID&&(this._resourceID=await k.getResourceID()),this.setEvents(),await this.getActions(),this.loadItems()}async componentDidLoad(){if(this._element&&(p.addIDInfo(this._element),this.positionDropdown(),!await this._application.hasClientEvent(this.CLIENT_EVENT_CONFIRM_NAME))){const t=new D;this._application.addClientEvent(this.CLIENT_EVENT_CONFIRM_NAME,t.clientConfirm)}}componentDidUpdate(){this.positionDropdown()}loadItems(){this._actions&&0!=this._actions.length&&this._actions.forEach((t=>{this._items.push({id:t.actionID,label:t.description})}))}getElementID(t){return{[p.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:p.getInternalIDInfo(t)}}async loadParameters(){null==E.parameters.isOrderActions&&(E.parameters.isOrderActions=await this._application.getBooleanParam("global.ordenar.acoes.personalizadas"))}render(){return i(s,null,this._actions&&this._actions.length>0&&i("div",{class:`ez-padding-left--medium snk-actions-button\n ${this.canShowDropdown()?" ez-elevation--16":""}\n `},i("ez-button",Object.assign({ref:t=>this._ezButton=t,iconName:"acao",size:"small",mode:"icon",title:this._application.messagesBuilder.getMessage("snkActionsButton.title.actions",void 0),onClick:()=>this.controlDropdown()},this.getElementID("button"))),i("div",Object.assign({ref:t=>this._dropdownParent=t,class:(this.canShowDropdown()?"snk-actions-button__dropdown--show":"snk-actions-button__dropdown")+"\n "},this.getElementID("dropdown")),this.canShowDropdown()&&i("ez-dropdown",Object.assign({items:this._items,onEzClick:t=>this.handleClick(t)},this.getElementID("dropdown"))))),this.canShowDropdown()&&i("div",Object.assign({class:"ez-scrim ez-scrim--light"},this.getElementID("ezScrim"))))}get _element(){return e(this)}};E.parameters={isOrderActions:null},E.style=".sc-snk-actions-button-h{display:flex;width:fit-content;height:fit-content}.snk-actions-button.sc-snk-actions-button{display:flex;width:fit-content;height:fit-content}.snk-actions-button__dropdown--show.sc-snk-actions-button{display:flex;flex-direction:column;position:fixed}.snk-actions-button__dropdown.sc-snk-actions-button>ez-dropdown.sc-snk-actions-button{position:relative}.snk-actions-button__dropdown.sc-snk-actions-button{display:none}";const j=class{constructor(i){t(this,i),this.configChange=n(this,"configChange",7),this.configCancel=n(this,"configCancel",7),this._orderListItems=[],this._orderPriorityList=[],this._visibleList=[],this._hiddenList=[],this._columListItems=[],this._dataChanged=!1,this._componenteInternalKey=Date.now(),this.selectedIndex=0,this.columns=void 0,this.config=void 0,this.configName=void 0,this.resourceID=void 0,this._collapsibleBoxListOrder=!0,this._collapsibleBoxListSelect=!1}getMessage(t,i){return o.getContextValue("__SNK__APPLICATION__").messagesBuilder.getMessage(t,i)}getSortableColumns(){let t=[];return this.columns.filter((t=>{var i;return a.getBooleanValue(null===(i=null==t?void 0:t.props)||void 0===i?void 0:i.get("sortable"),!0)})).forEach((i=>{var s,e;let n=null===(s=this.config)||void 0===s?void 0:s.columns.find((t=>t.name===i.name)),o={label:i.label,sort:null!==(e=null==i?void 0:i.sort)&&void 0!==e?e:b.asc.value,id:i.name};n&&(o.orderIndex=n.orderIndex,o.ascending=n.ascending),i.hidden||t.push(o)})),t}createOrderList(){let t=this.getSortableColumns();t.sort(((t,i)=>0!=t.orderIndex||0!=i.orderIndex||null==t.ascending&&null==i.ascending?null!=t.ascending&&null!=i.ascending?t.orderIndex-i.orderIndex:null!=t.ascending||null!=i.ascending?null!=t.ascending?-1:null!=i.ascending?1:0:t.orderIndex-i.orderIndex:null!=t.ascending?-1:null!=i.ascending?1:0)),this._orderListItems=t}createColumnList(){let t={group:this.getMessage("snkGridConfig.group.visible"),items:[]},i={group:this.getMessage("snkGridConfig.group.hidden"),items:[],sort:b.asc.value};this.columns.forEach((s=>{var e;let n={label:s.label,selected:!1,sort:null!==(e=null==s?void 0:s.sort)&&void 0!==e?e:b.asc.value,id:s.name};s.hidden?i.items.push(n):t.items.push(n)})),this._columListItems=[t,i],this._visibleList=t.items,this._hiddenList=i.items,this.createOrderList()}createOrderListSlotDataElementId(t){return`${this._element.getAttribute(p.DATA_ELEMENT_ID_ATTRIBUTE_NAME)}_configItem_${a.toCamelCase(t.label)}`}buildOrderListSlot(t){const s=this.createOrderListSlotDataElementId(t);let e=b.none.value;return null!=(null==t?void 0:t.ascending)&&(e=1==t.ascending?b.asc.value:b.desc.value),i("snk-select-box",{selectedOption:e,key:"snk-select-box-"+this._componenteInternalKey+"-"+t,"data-element-id":s,onEzChange:i=>{i.stopPropagation(),this.updateOrder(i.detail,t.label)}})}updateOrder(t,i){var s;this._dataChanged=!0;let e,n=[...this.columns],o=n.find((t=>t.label===i));o&&(o.sort=t.value===b.none.value?void 0:t.value),(null===(s=this._orderPriorityList)||void 0===s?void 0:s.length)>0?(this._orderPriorityList.find((t=>t.label===o.label)).sort=t,this._orderPriorityList.filter((t=>t.sort)).forEach(((t,i)=>{t.label===o.label&&(o.sortIndex=i)}))):(e=n.filter((t=>t.sort&&!0!==t.hidden)).map(((t,i)=>({label:t.label,orderIndex:i}))),e.forEach((t=>{n.find((i=>i.label===t.label)).sortIndex=t.orderIndex}))),this.columns=n}finish(){if(!this._dataChanged)return void this.closeConfig();let t=[];this._columListItems.forEach((i=>{i.items.forEach((s=>{const e=this.columns.find((t=>t.label===s.label));let n=Object.assign({},e);n.hidden=i.group===this.getMessage("snkGridConfig.group.hidden"),t.push(n)}))})),this.columns=t,this._dataChanged=!1,this.closeConfig(),this.save()}saveGridConfigOnStorage(t){C.saveGridConfig(t,this.configName,this.resourceID).then((t=>{this.configChange.emit(t),w.info(this.getMessage("snkGridConfig.info.successfullyConfigSaved"),{iconName:"check"})}))}reOrderPriorityColumns(t,i){let s=[];s=t.filter((t=>t.sort&&!0!==t.hidden)).map((t=>({label:t.label,orderIndex:0})));let e=0,n=[];return i.forEach((t=>{let i=s.find((i=>i.label===t.label));i&&(i.orderIndex=e,n.push(i),e++)})),n.length>0&&(s=n),s}save(){var t;let i;i=this.config?this.config:this.createConfigFromState(this.columns);let s,e=[];(null===(t=this._orderPriorityList)||void 0===t?void 0:t.length)>0&&(s=this.reOrderPriorityColumns(this.columns,this._orderPriorityList)),this.columns.forEach((t=>{let n=i.columns.find((i=>t.name===i.name));!0===t.hidden&&n||(n?n.width=t.width:!1===t.hidden&&(n={name:t.name,width:t.width,orderIndex:0}),n&&(t.sort?(n.ascending=t.sort.toUpperCase()===b.asc.value,s?function(t,i){if(s){let e=s.find((i=>i.label===t.label));e&&(i.orderIndex=e.orderIndex)}}(t,n):n.orderIndex=t.sortIndex):(delete n.ascending,n.orderIndex=0),n.configVersion=j.CURRENT_CONFIG_VERSION,e.push(n)))})),i.columns=e,this.saveGridConfigOnStorage(i)}createConfigFromState(t){let i={columns:[]};return t.forEach((t=>{if(!t.hidden){let s={name:t.name};t.width&&(s.width=t.width),t.sort?(s.ascending=t.sort.toUpperCase()===b.asc.value,s.orderIndex=t.sortIndex):s.orderIndex=0,s&&i.columns.push(s)}})),i}closeConfig(){if(this._dataChanged){let t={canClose:!1,labelCancel:this.getMessage("snkGridConfig.confirm.cancel"),labelConfirm:this.getMessage("snkGridConfig.confirm.save"),btnConfirmDanger:!1};w.confirm(this.getMessage("snkGridConfig.confirm.alert"),this.getMessage("snkGridConfig.confirm.msgCancel"),null,y.WARN,t).then((t=>{t?this.finish():(this._dataChanged=!1,this.configCancel.emit(),this._componenteInternalKey=Date.now())}))}else this.configCancel.emit()}handleColumnListChange(t){var i;if(t.detail){let s=null===(i=t.detail.find((t=>t.group===this.getMessage("snkGridConfig.group.visible"))))||void 0===i?void 0:i.items;s&&(this._dataChanged=!0,this._orderListItems=s)}}handleOrderListChange(t){if(t.detail){let i=t.detail;i&&(this._dataChanged=!0,this._orderPriorityList=i)}}componentWillRender(){var t;(null===(t=this.columns)||void 0===t?void 0:t.length)>0&&this.createColumnList()}componentDidLoad(){p.addIDInfo(this._element)}handleRightListChange(t){const i=this._columListItems.find((t=>t.group===this.getMessage("snkGridConfig.group.visible")));i&&i.items!=t&&(i.items=t,this._dataChanged=!0)}getListSlots(){return{RIGHT_LIST:{itemRightSlotBuilder:t=>this.buildOrderListSlot(t)}}}render(){return i(s,null,i("div",{class:"grid-config__header"},i("div",{class:"title-container"},i("div",{class:"ez-margin-bottom--medium"},i("label",{class:"title"},this.getMessage("snkGridConfig.gridConfiguration")),i("label",{class:"subtitle"},this.getMessage("snkGridConfig.columnVisibilityOrder"))),i("div",{class:"button-close"},i("ez-button",{mode:"icon",iconName:"close",size:"medium",class:"ez-button--tertiary",onClick:()=>this.closeConfig()})))),i("div",{class:"grid-config__body"},i("ez-collapsible-box",{id:"group-select-columns",label:this.getMessage("snkGridConfig.columnsSelection"),"header-size":"medium",key:"key_group-select-columns",value:this._collapsibleBoxListSelect,onEzChange:({detail:t})=>this._collapsibleBoxListOrder=!t},i("div",{class:"grid-config__main"},i("ez-double-list",{leftList:this._hiddenList,leftTitle:this.getMessage("snkGridConfig.availableColumns"),rightList:this._visibleList,rightTitle:this.getMessage("snkGridConfig.selectedColumns"),onEzRightListChanged:({detail:t})=>this.handleRightListChange(t),emptyMessage:{LEFT_LIST:this.getMessage("snkGridConfig.emptyMensage.left"),RIGHT_LIST:this.getMessage("snkGridConfig.emptyMensage.right")},entityLabel:"coluna",entityLabelPlural:"colunas"}))),i("ez-collapsible-box",{id:"ID_group-order-columns",label:this.getMessage("snkGridConfig.dataOrdering"),"header-size":"medium",key:"KEY_group-order-columns",value:this._collapsibleBoxListOrder,onEzChange:({detail:t})=>this._collapsibleBoxListSelect=!t},i("div",{class:"grid-config__main"},i("ez-double-list",{rightList:this._orderListItems,rightTitle:this.getMessage("snkGridConfig.selectedColumns"),useOnlyRightList:!0,slotsListBuilder:this.getListSlots(),emptyMessage:{RIGHT_LIST:this.getMessage("snkGridConfig.emptyMensage.right")},entityLabel:"coluna",entityLabelPlural:"colunas"})))),i("div",{class:"grid-config__footer"},i("ez-button",{class:"padding-right--medium",label:this.getMessage("snkGridConfig.cancel"),onClick:()=>this.closeConfig()}),i("ez-button",{label:this.getMessage("snkGridConfig.complete"),class:"ez-button--primary",onClick:()=>this.finish()})))}static get assetsDirs(){return["../assets"]}get _element(){return e(this)}};j.CURRENT_CONFIG_VERSION=1,j.style='.sc-snk-grid-config-h{--snk-grid-config__footer--padding-top:var(--space--medium, 12px);--snk-grid-config__main--padding-right:var(--space--medium, 12px);--snk-grid-config__tabselector-container--padding:var(--space--medium, 12px);--snk-grid-config__button-close--padding-left:var(--space--medium, 12px);--snk-grid-config__title--color:var(--title--primary, #2B3A54);--snk-grid-config__title--font-family:var(--font-pattern, "Roboto");--snk-grid-config__title--font-size:var(--title--large, 20px);--snk-grid-config__title--font-weight:var(--text-weight--extra-large, 700);--snk-grid-config__subtitle--font-family:var(--font-pattern, "Roboto");--snk-grid-config__subtitle--font-size:var(--text--medium, 14px);--snk-grid-config__group--font-family:var(--font-pattern, "Roboto");--snk-grid-config__group--font-size:var(--text--medium, 14px);--snk-grid-config__group--font-weight:var(--text-weight--large, 600);--snk-grid-config__group--padding-bottom:var(--space-small, 6px);--snk-grid-config__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-grid-config__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-grid-config__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-grid-config__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-grid-config__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-grid-config__scrollbar--width:var(--space--small, 6px);display:flex;flex-direction:column;max-height:100%;width:100%}.grid-config__body.sc-snk-grid-config{overflow:auto}.padding-right--medium.sc-snk-grid-config{padding-right:var(--space--medium)}ez-list.sc-snk-grid-config{height:100%}.height-calc.sc-snk-grid-config{max-height:calc(100% - 24px)}.grid-config__footer.sc-snk-grid-config{display:flex;justify-content:flex-end;width:100%;padding-top:var(--snk-grid-config__footer--padding-top)}.hidden.sc-snk-grid-config{display:none}.tabselector-container.sc-snk-grid-config{padding:var(--snk-grid-config__tabselector-container--padding) 0}.button-close.sc-snk-grid-config{padding-left:var(--snk-grid-config__button-close--padding-left)}.title-container.sc-snk-grid-config{display:flex;justify-content:space-between;align-items:center;width:100%}.title.sc-snk-grid-config{display:flex;margin:0;line-height:normal;letter-spacing:0em;text-align:left;color:var(--snk-grid-config__title--color);font-size:var(--snk-grid-config__title--font-size);font-family:var(--snk-grid-config__title--font-family);font-weight:var(--snk-grid-config__title--font-weight)}.subtitle.sc-snk-grid-config{color:var(--text--primary);font-size:var(--snk-grid-config__subtitle--font-size);font-family:var(--snk-grid-config__subtitle--font-family)}.grid-config__main.sc-snk-grid-config{overflow-y:auto;scrollbar-width:thin;width:100%;padding-bottom:20px;scrollbar-color:var(--snk-grid-config__scrollbar--color-clicked) var(--snk-grid-config__scrollbar--color-background)}.group-name.sc-snk-grid-config{font-family:var(--snk-grid-config__group--font-family);font-size:var(--snk-grid-config__group--font-size);font-weight:var(--snk-grid-config__group--font-weight);padding-bottom:var(--snk-grid-config__group--padding-bottom)}';const B=class{constructor(i){t(this,i),this._formConfigFetcher=new v,this.layoutType=x.CASCADE}async save(){this._LayoutFormConfigSingleton.setConfig(this.layoutType),this._formConfigFetcher.saveLayoutFormConfig("formColCfg."+this._resourceID,{config:this.layoutType,newConfig:!0})}async componentWillLoad(){const t=o.getContextValue("__SNK__APPLICATION__");this._LayoutFormConfigSingleton=await(null==t?void 0:t.getLayoutFormConfig()),this._resourceID=await(null==t?void 0:t.getResourceID()),this.setLayoutInit()}setLayoutInit(){if(!this._LayoutFormConfigSingleton)return;const{config:t}=this._LayoutFormConfigSingleton;this.layoutType=Number(t)in x?Number(t):x.CASCADE}toggleLayout(t){this.layoutType=t}render(){return i("div",{class:"ez-flex ez-flex--column"},i("div",{class:"ez-margin-bottom--small"},i("ez-check",{label:"Layout em cascata",class:"ez-margin-bottom--small",onEzChange:()=>this.toggleLayout(x.CASCADE),value:this.layoutType===x.CASCADE}),i("snk-view-representation",{mode:x.CASCADE}),i("label",{class:"ez-label ez-margin--small ez-flex ez-text--medium"},"Todos os campos serão organizados em uma coluna única.")),i("div",null,i("ez-check",{label:"Layout lado a lado",class:"ez-margin-bottom--small",onEzChange:()=>this.toggleLayout(x.SIDE_BY_SIDE),value:this.layoutType===x.SIDE_BY_SIDE}),i("snk-view-representation",{mode:x.SIDE_BY_SIDE}),i("label",{class:"ez-label ez-margin--small ez-flex ez-text--medium"},"Todos os campos serão dispostos lado a lado, ajustando-se automaticamente à largura da tela.")))}};B.style=".sc-snk-layout-form-config-h{display:block}";const G=class{constructor(i){t(this,i),this.ezChange=n(this,"ezChange",7),this.selectedOption=b.none}render(){return i("ez-combo-box",{class:"grid-config-combo ez-input--inverted",label:"",suppressSearch:!0,value:this.selectedOption,enabled:!0,canShowError:!1,suppressEmptyOption:!0},Object.keys(b).map((t=>i("option",{value:b[t].value},b[t].label))))}static get assetsDirs(){return["../assets"]}};G.style="ez-combo-box{width:100px;--ez-text-input__margin-bottom:0px}.grid-config-combo{--ez-text-input--height:28px;--ez-text-input__input--background-color:#fff;--ez-text-input__input--border-color:#dce0e8}";const R=class{constructor(i){t(this,i),this.snkConfigSaved=n(this,"snkConfigSaved",7),this._formConfigFetcher=new v,this.fieldsToSave=[],this.dataUnit=void 0,this.configName=void 0,this.avaliableFields=[],this.selectedFields=[]}async show(){var t;await(null===(t=this.ezDoubleListRef)||void 0===t?void 0:t.resetSelectedLists()),await this.initializeFormConfig(),this.ezPopupRef.opened=!0}async initializeFormConfig(){if(!this.configName)return;const t=this.getAllVisibleFieldsFromDataUnit(),i=await this.getConfig();if(0===i.length)return this.avaliableFields=[],this.selectedFields=[...t],void(this.fieldsToSave=[...this.selectedFields]);const s=this.sortDisplayedFields(i,t),e=t.filter((t=>!i.includes(t.id)));this.avaliableFields=[...e],this.selectedFields=[...s],this.fieldsToSave=[...this.selectedFields]}async getConfig(){const t=await this._formConfigFetcher.fetchSimpleFormConfig(this.configName);return[...this.removeDuplicates(t)]}removeDuplicates(t){return t.filter(((i,s)=>t.indexOf(i)===s))}sortDisplayedFields(t,i){const s=[];return t.forEach((t=>{const e=i.find((i=>i.id===t));e&&s.push(e)})),s}getAllVisibleFieldsFromDataUnit(){var t,i,s;return(null!==(s=null===(i=null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)||void 0===i?void 0:i.fields)&&void 0!==s?s:[]).filter((t=>t.visible)).map((t=>({id:t.name,label:t.label})))}close(){this.ezPopupRef.opened=!1}async handleResetConfigs(){await this._formConfigFetcher.restoreFormConfig(this.configName),await this.initializeFormConfig(),await this.handleSave()}handleCancel(){this.close()}async handleSave(){const t=this.fieldsToSave.map((t=>t.id));await this._formConfigFetcher.saveSimpleFormConfig(this.configName,t),this.close(),this.snkConfigSaved.emit()}render(){return i("ez-popup",{ref:t=>this.ezPopupRef=t,heightMode:"auto",size:"medium",ezTitle:"Configurar formulário"},i("div",{class:"config-container"},i("div",{class:"config-lists"},i("ez-double-list",{ref:t=>this.ezDoubleListRef=t,leftList:this.avaliableFields,leftTitle:"Campos disponíveis",rightList:this.selectedFields,rightTitle:"Campos selecionados",onEzRightListChanged:({detail:t})=>this.fieldsToSave=[...t],entityLabel:"campo",entityLabelPlural:"campos"})),i("div",{class:"config-actions"},i("ez-button",{label:"Restaurar",onClick:this.handleResetConfigs.bind(this),size:"small"}),i("ez-button",{label:"Cancelar",onClick:this.handleCancel.bind(this),size:"small"}),i("ez-button",{label:"Salvar",class:"ez-button--primary",onClick:this.handleSave.bind(this),size:"small"}))))}};R.style=":host{display:block}.config-container{display:flex;flex-direction:column;align-items:center;justify-content:space-between}.config-lists{width:100%;margin-bottom:12px}.config-actions{display:flex;flex-direction:row;justify-content:flex-end;width:100%;gap:12px}";const F=class{constructor(i){t(this,i),this.mode=x.SIDE_BY_SIDE}renderCascadeLayout(){return i("div",{class:"svg-container__collumn"},[...Array(3)].map((()=>i("div",{class:"svg-container__section"},i("div",{class:"svg-container__line svg-container__line--short"}),i("div",{class:"svg-container__line svg-container__line--long"})))))}renderSideBySideLayout(){return i("div",{class:"svg-container__inline"},[...Array(2)].map((()=>this.renderCascadeLayout())))}render(){return i("div",{class:"svg-container ez-margin-left--small"},i("div",{class:"svg-container__background"},i("div",{class:"svg-container__header"},i("div",{class:"svg-container__circle svg-container__circle--red"}),i("div",{class:"svg-container__circle svg-container__circle--yellow"}),i("div",{class:"svg-container__circle svg-container__circle--green"})),this.mode===x.CASCADE?this.renderCascadeLayout():this.renderSideBySideLayout()))}};F.style=".sc-snk-view-representation-h{display:block}.svg-container.sc-snk-view-representation{display:flex;width:185px;height:125px;border-radius:8px;background-color:#f7f7f7;padding:10px 12px;box-sizing:border-box;position:relative}.svg-container__background.sc-snk-view-representation{display:flex;flex-direction:column;width:100%}.svg-container__header.sc-snk-view-representation{display:flex;gap:2px;margin-bottom:12px}.svg-container__circle.sc-snk-view-representation{width:9px;height:9px;border-radius:50%}.svg-container__circle--red.sc-snk-view-representation{background-color:#ed7678}.svg-container__circle--yellow.sc-snk-view-representation{background-color:#eddb76}.svg-container__circle--green.sc-snk-view-representation{background-color:#7ad08e}.svg-container__section.sc-snk-view-representation{width:100%}.svg-container__collumn.sc-snk-view-representation{width:100%;display:flex;flex-direction:column}.svg-container__inline.sc-snk-view-representation{display:flex;flex-direction:row;gap:6px}.svg-container__line.sc-snk-view-representation{height:13px;border-radius:4px;background-color:#d9d9d9;margin-bottom:4px}.svg-container__line--short.sc-snk-view-representation{width:39.68px;height:7px;border-radius:3.5px}.svg-container__line--long.sc-snk-view-representation{width:100%}";const M=class{constructor(i){t(this,i),this.taskbarActionSelected=n(this,"taskbarActionSelected",7),this.taskbarActionsOpened=n(this,"taskbarActionsOpened",7),this.taskbarActionsButtonDisconnected=n(this,"taskbarActionsButtonDisconnected",7),this._showDropdown=!1,this.title=void 0,this.enabled=void 0,this.actions=void 0}async handleKeyDown(t){"Escape"!==t.key&&"Esc"!==t.key||await this.hideActions()}async handleClose(){await this.hideActions()}async showActions(){this._showDropdown=!0,requestAnimationFrame((()=>{this._element.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}))}async hideActions(){this._showDropdown=!1}async isOpened(){return this._showDropdown}controlDropdown(){this._showDropdown=!this._showDropdown}loadItems(){return this.actions.filter((t=>void 0!==t)).map((t=>{var i;return{id:t.value,label:t.label,value:t.value,type:null!==(i=t.type)&&void 0!==i?i:"item",children:t.children,iconName:t.iconName,subAction:t.subAction,group:t.group,disableCloseOnSelect:t.disableCloseOnSelect}}))}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this.actions)||void 0===t?void 0:t.length)>0}onSelectAction(t){const i=this.actions.map((t=>Object.assign(Object.assign({},t),{id:t.value}))),s=this.getSelectedAction(t.id,i);this.taskbarActionSelected.emit(s),s.disableCloseOnSelect||(this._showDropdown=!1)}getSelectedAction(t,i){let s=null;for(const e of i){if(e.id===t){s=e;break}if((null==e?void 0:e.children)&&(s=this.getSelectedAction(t,e.children),s))break}return s}dropdownItemBuilder(t,s){const e=this.actions.find((i=>i.value===t.id));if(!e||!e.itemBuilder)return;const n=e.itemBuilder(this._element,e);return"string"==typeof n?i("div",{innerHTML:n}):n}initializeEagerItems(){var t;null===(t=this.actions)||void 0===t||t.forEach((t=>{var i;t&&t.eagerInitialize&&t.itemBuilder&&(null===(i=t.itemBuilder)||void 0===i||i.call(t,this._element,t))}))}componentDidLoad(){this.initializeEagerItems()}componentDidRender(){this._showDropdown&&this.taskbarActionsOpened.emit(this._element)}disconnectedCallback(){this.taskbarActionsButtonDisconnected.emit()}render(){return i(s,null,i("div",{class:(this.canShowDropdown()?" ez-elevation--16":"")+" ez-dropdown-container"},i("ez-button",{title:this.title,mode:"icon",iconName:"dots-vertical",size:"small",enabled:this.enabled,onClick:()=>this.controlDropdown()}),this.canShowDropdown()&&i("ez-dropdown",{class:"ez-dropdown--sticky",items:this.loadItems(),onEzClick:t=>this.onSelectAction(t.detail),onEzOutsideClick:()=>this._showDropdown=!1,itemBuilder:(t,i)=>this.dropdownItemBuilder(t,i)})))}get _element(){return e(this)}};M.style=".sc-taskbar-actions-button-h{--ez-dropdown--min-width:150px;display:flex;width:fit-content;height:fit-content}.ez-dropdown-container.sc-taskbar-actions-button{position:relative;display:inline-block}.ez-dropdown--sticky.sc-taskbar-actions-button{position:absolute;display:block;min-width:var(--ez-dropdown--min-width)}";const K=class{constructor(i){t(this,i),this._showDropdown=!1,this.iconName=void 0,this.action=void 0,this.name=void 0,this.className=void 0,this.dataElementId=void 0,this.title=void 0,this.enabled=void 0,this.actions=void 0}initializeEagerItems(){var t;null===(t=this.actions)||void 0===t||t.forEach((t=>{var i;t&&t.eagerInitialize&&t.itemBuilder&&(null===(i=t.itemBuilder)||void 0===i||i.call(t,this._splitButtonRef,t))}))}componentDidLoad(){this.initializeEagerItems()}dropdownItemBuilder(t,s){const e=this.actions.find((i=>i.value===t.id));if(!e||!e.itemBuilder)return;const n=e.itemBuilder(this._splitButtonRef,e);return"string"==typeof n?i("div",{innerHTML:n}):n}loadItems(){return this.actions.filter((t=>void 0!==t)).map((t=>{var i;return{id:t.value,label:t.label,value:t.value,type:null!==(i=t.type)&&void 0!==i?i:"item",children:t.children,iconName:t.iconName,subAction:t.subAction,group:t.group,disableCloseOnSelect:t.disableCloseOnSelect}}))}render(){return i(s,null,i("ez-split-button",{ref:t=>this._splitButtonRef=t,key:this.dataElementId,class:`${this.className} "ez-split-button--tertiary ez-padding--medium"`,items:this.loadItems(),mode:"icon-only",iconName:this.iconName,enabled:this.enabled,show:this._showDropdown,onButtonClick:()=>this.action(this.name),itemBuilder:(t,i)=>this.dropdownItemBuilder(t,i)}))}};K.style="";export{E as snk_actions_button,j as snk_grid_config,B as snk_layout_form_config,G as snk_select_box,R as snk_simple_form_config,F as snk_view_representation,M as taskbar_actions_button,K as taskbar_split_button}
1
+ import{r as t,h as i,H as s,g as e,c as n}from"./p-d8d8169b.js";import{ApplicationContext as o,StringUtils as a,ErrorException as r,WarningException as l,ObjectUtils as c,DateUtils as d,ServiceUtils as h,StorageType as u,ArrayUtils as g,ElementIDUtils as p}from"@sankhyalabs/core";import{D as m}from"./p-cd1a5b6a.js";import{P as f}from"./p-eaad0aa8.js";import"./p-c9657baa.js";import"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-37b4f642.js";import"./p-ff1990ad.js";import{F as v}from"./p-b21d32f6.js";import{O as b}from"./p-9019a32f.js";import{g as _}from"./p-7dd49d15.js";import{R as k}from"./p-688dcb4c.js";import{ApplicationUtils as w,DialogType as y,FormLayout as x}from"@sankhyalabs/ezui/dist/collection/utils";import{C}from"./p-8758404f.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";class z{execute(t){var i;const s={actionID:t.actionID,refreshType:null===(i=t.actionConfig.javaCall)||void 0===i?void 0:i.refreshType};return new Promise((t=>{t({execSource:s,callback:this.callExecJava})}))}async callExecJava(t){const i={requestBody:{javaCall:t}};await m.get().callServiceBroker("ActionButtonsSP.executeJava",JSON.stringify(i))}}class S{execute(t){var i;const s={actionID:t.actionID,refreshType:null===(i=t.actionConfig.runScript)||void 0===i?void 0:i.refreshType};return new Promise((t=>{t({execSource:s,callback:this.callExecScript})}))}async callExecScript(t){const i={runScript:t};await m.get().callServiceBroker("ActionButtonsSP.executeScript",i)}}class A{constructor(){this._application=o.getContextValue("__SNK__APPLICATION__")}async execute(t,i){const s=t.resourceID;if(!s)return;let e=await this.buildLaunchObject(t,i);return this._application.openApp(s,e),null}buildLaunchObject(t,i){return new Promise((s=>{let e=t.actionConfig.params.param;if(e&&e.length>0){let n={},o=[];e.forEach((s=>{const e=s.localField;let l=i.getFieldValue(e);if(!l){let s=i.getField(e).label;throw s=a.isEmpty(i.getField(e).label)?e:s,new r(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.launchScreen.emptyField",{description:t.description,localFieldLabel:s}))}l=a.isEmpty(l.toString())?void 0:l.toString(),n[s.targetField]=l,o.push({fieldName:s.targetField,value:l})})),n.ACTION_PARAMETERS=o,n.call_time=Date.now(),s(n)}s(null)}))}}class L{execute(t){var i,s,e;const n=null===(i=t.actionConfig.dbCall)||void 0===i?void 0:i.name,o=null===(s=t.actionConfig.dbCall)||void 0===s?void 0:s.rootEntity,a={actionID:t.actionID,refreshType:null===(e=t.actionConfig.dbCall)||void 0===e?void 0:e.refreshType,procName:n,rootEntity:o};return new Promise((t=>{t({execSource:a,callback:this.callExecProcedure})}))}async callExecProcedure(t){const i={requestBody:{stpCall:t}};await m.get().callServiceBroker("ActionButtonsSP.executeSTP",JSON.stringify(i))}}var O,P;!function(t){t.LAUNCH_SCREEN="LC",t.JAVASCRIPT="SC",t.JAVA="RJ",t.PROCEDURE="SP",t.EMBEDDED="EB"}(O||(O={}));class I{constructor(t){this.actionType=t,this._application=o.getContextValue("__SNK__APPLICATION__")}get executor(){switch(this.actionType){case O.LAUNCH_SCREEN:return new A;case O.JAVASCRIPT:return new S;case O.JAVA:return new z;case O.PROCEDURE:return new L;default:throw new r(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.nonExistentType",{actionType:this.actionType}))}}}!function(t){t.NONE="NONE",t.PARENT="PARENT",t.MASTER="MASTER",t.ALL="ALL"}(P||(P={}));const N="__MASTER_ROW__";class T{constructor(t,i,s){var e;this._lastValuesCache={},this._actionsExecuteInterface=t,this._dataUnit=i,this._selectedRows=(null===(e=null==i?void 0:i.getSelectionInfo())||void 0===e?void 0:e.isAllRecords())?[]:null==i?void 0:i.getSelectionInfo().records,this._application=o.getContextValue("__SNK__APPLICATION__"),this._appResourceId=s}getPrimaryKeys(){return _(this._dataUnit).map((({name:t})=>t))}apply(t,i){this._application.closePopUp(),this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:s,callback:e})=>{this.resolvePromptParams(t,s,i).then((()=>{this.actionExecute(s,e)}))}))}async execute(t){var i;if(!t.actionConfig)throw new l(this._application.messagesBuilder.getMessage("snkActionsButton.title.warning",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.incorrectAction",{description:t.description}));if(null===(i=t.actionConfig.params)||void 0===i?void 0:i.promptParam){const i=t.actionConfig.params.promptParam;let s=!1;for(let t=0;t<i.length;t++)if(!s&&"true"===i[t].saveLast){s=!0;break}s&&(t.actionConfig.params.promptParam=await this.loadSavedValuesIntoParams(t));const e=document.createElement("snk-actions-form");window.document.body.appendChild(e),e.action=c.copy(t),e.applyParameters=t=>{this.apply(t,s)},e.openPopup()}else t.type!=O.LAUNCH_SCREEN?this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:t,callback:i})=>{this.actionExecute(t,i)})):this._actionsExecuteInterface.execute(t,this._dataUnit)}loadSavedValuesIntoParams(t){return this.loadLastValues(t).then((i=>{let s=t.actionConfig.params.promptParam;return i&&i.param.forEach((t=>{s=s.map((i=>i.name!==t.paramName?i:Object.assign(Object.assign({},i),"B"===i.paramType?{value:"S"===t.$}:{value:t.$})))})),s}))}async actionExecute(t,i){t.virtualPage=this.buildVirtualPage(),await this.prepareAndExecute(t,i),this.recordsReloader(t.refreshType)}resolvePromptParams(t,i,s){return new Promise((e=>{let n=[];t.actionConfig.params.promptParam.forEach((t=>{n.push(this.buildPromptParam(t))})),this.putParamsOnExecSource(n,i),s&&this.saveLastValues(t,n),e()}))}buildPromptParam(t){let i,s,e=t.paramType,n=!1,o=t.value;switch(e){case f.DATE:e="D";break;case f.DATETIME:e="H";break;case f.DECIMAL:e="F",i={"sk-precision":Number(t.precision)};break;case f.BOOLEAN:e="S",n=!0,o=t.value?"S":"N";break;case f.ENTITY:i={"sk-entity-name":t.entityName,"sk-allow-show-hierarchical-mode":t.hierarchyEntity,"sk-data-type":"S"},t.hierarchyEntity&&t.entityPK&&(s=t.entityPK),o=t.value?Number(t.value):null;break;case f.OPTIONS:e="O";let a=t.options.split(";").map((function(t,i){let s,e;if(t.indexOf("=")>-1){let i=t.split("=");s=i[0],e=i[1]}else s=i+1,e=t;return{data:s,value:e}}));i={"sk-options":a}}return{description:t.label,required:"true"==t.required,fieldName:t.name,fieldNameOri:t.name,entityPK:s,paramType:t.paramType,type:e,isCheckbox:n,saveLast:t.saveLast,fieldProp:i,value:o,isGeneratedName:t.isGeneratedName}}putParamsOnExecSource(t,i){i.params={param:[]},t.forEach((t=>{if(t.isGeneratedName&&t.value)throw new r(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.emptyParamName",void 0));a.isEmpty(t.value)||i.params.param.push({type:this.getParamDataType(t.paramType),paramName:t.fieldName,$:this.getParamValue(t)})}))}getParamDataType(t){let i;switch(t){case"D":i="F";break;case"DT":case"DH":i="D";break;case"B":case"ENTITY":case"SO":i="S";break;default:i=t}return i}getParamValue(t){let i=t.value;return i?("DT"==t.paramType?i=d.formatDate(i):"DH"==t.paramType&&(i=d.formatDateTime(i)),i):i}async loadLastValues(t){const i=await this.buildResourceId(t.actionID);return new Promise(((t,s)=>{if(this._lastValuesCache[i])t(this._lastValuesCache[i]);else{const e={config:{chave:i,tipo:"T"}};m.get().callServiceBroker("SystemUtilsSP.getConf",e).then((s=>{var e,n;let o;(null===(n=null===(e=s.config)||void 0===e?void 0:e.data)||void 0===n?void 0:n.params)&&(o=s.config.data.params,Array.isArray(o.param)||(o.param=[o.param])),this._lastValuesCache[i]=o,t(o)})).catch((t=>{s(t)}))}}))}async saveLastValues(t,i){if(this._application){let s={params:{param:[]}};i.forEach((t=>{"true"==t.saveLast&&s.params.param.push({paramName:t.fieldName,$:t.value})}));const e=await this.buildResourceId(t.actionID);this._lastValuesCache[e]=s.params,this._application.saveConfig(e,s)}}async buildResourceId(t){return this._appResourceId+".actionconfig."+t}async prepareAndExecute(t,i){this.addRows(t),await i(t)}addRows(t){const i=this.getPrimaryKeys(),s={row:[]},e=this._selectedRows;for(const t in e){const n=e[t],o={};n.hasOwnProperty(N)&&(o.master="S",o.entityName=n.__ENTITY_NAME__,delete n[N],delete n.__ENTITY_NAME__),o.field||(o.field=[]);for(const t of i)o.field.push({fieldName:t,$:n[t]});s.row.push(o)}s.row.length>0&&(t.rows=s)}recordsReloader(t){switch(t){case P.NONE:break;case P.PARENT:case P.MASTER:case P.ALL:this._dataUnit.loadData();break;default:this._dataUnit.reloadCurrentRecord()}}buildVirtualPage(){var t,i,s,e;if(null===(i=null===(t=this._dataUnit)||void 0===t?void 0:t.getSelectionInfo())||void 0===i?void 0:i.isAllRecords())return{filters:{filters:null===(s=this._dataUnit)||void 0===s?void 0:s.getAppliedFilters()},orders:{orders:null===(e=this._dataUnit)||void 0===e?void 0:e.getSort()}}}}class D{async clientConfirm(t,i){return new Promise((s=>{const e=o.getContextValue("__SNK__APPLICATION__");let n="";t.content.event.hasOwnProperty("stpCall")?(i.requestBody=t.content.event.stpCall,n=O.PROCEDURE):t.content.event.hasOwnProperty("runScript")?(i.requestBody=t.content.event.runScript,n=O.JAVASCRIPT):t.content.event.hasOwnProperty("javaCall")&&(i.requestBody=t.content.event.javaCall,n=O.JAVA);let a={type:"S",sequence:t.content.event.sequence};i.requestBody.params?Array.isArray(i.requestBody.params.param)||(i.requestBody.params.param=[i.requestBody.params.param]):i.requestBody.params={param:[]},i.requestBody.params.param.push(a);const r=t.content.event.title.$,l=t.content.event.message.$;let c;switch(n){case O.JAVASCRIPT:c={runScript:i.requestBody};break;case O.PROCEDURE:c={requestBody:{stpCall:i.requestBody}};break;case O.JAVA:c={requestBody:{javaCall:i.requestBody}}}if("S"==t.content.event.showNoOption){a.paramName="__ESCOLHA_SIMNAO__";const t=document.createElement("snk-client-confirm");window.document.body.appendChild(t),t.titleMessage=r,t.message=l,t.accept=async()=>{a.$="S",await i.reCall(c),s()},t.cancel=async()=>{a.$="N",await i.reCall(c),s()},t.openPopup()}else e.confirm(r,l,null,"warn",{labelCancel:"Cancelar",labelConfirm:"Sim"}).then((async t=>{t&&(a.paramName="__CONFIRMACAO__",a.$="S",await i.reCall(c),s())}))}))}}const E=class{constructor(i){t(this,i),this.CLIENT_EVENT_CONFIRM_NAME="br.com.sankhya.actionbutton.clientconfirm",this._actions=[],this.handleClick=t=>{const i=this._actions.find((i=>i.actionID==t.detail.id)),s=new I(i.type).executor;new T(s,this._dataUnit,this._resourceID).execute(Object.assign({},i)),this._showDropdown=!1},this._items=[],this._showDropdown=!1}async getActions(){const t=await h.useCacheWithService(`SnkActionsButton_${this._entityName}-${this._resourceID}`,(async()=>{var t;const i={param:{entityName:this._entityName,resourceID:this._resourceID}};return(null===(t=(await m.get().callServiceBroker("ActionButtonsSP.getActions",i)).actions)||void 0===t?void 0:t.action)||[]}),u.IN_MEMORY_CACHE);this._actions=E.parameters.isOrderActions?g.sortAlphabetically(t,"description"):t}controlDropdown(){this._showDropdown=!this._showDropdown}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this._items)||void 0===t?void 0:t.length)>0}positionDropdown(){var t;const i=null===(t=this._ezButton)||void 0===t?void 0:t.getBoundingClientRect();i&&this._dropdownParent&&(this._dropdownParent.style.top=i.y+i.height+5+"px",this._dropdownParent.style.left=i.x+"px")}closeDropdown(t){const i=null==t?void 0:t.target;i&&(i.closest(".snk-actions-button")||(this._showDropdown=!1))}setEvents(){document.removeEventListener("click",this.closeDropdown.bind(this)),document.addEventListener("click",this.closeDropdown.bind(this)),document.removeEventListener("scroll",this.positionDropdown.bind(this)),document.addEventListener("scroll",this.positionDropdown.bind(this))}async componentWillLoad(){this._application=o.getContextValue("__SNK__APPLICATION__"),await this.loadParameters();const t=this._element.parentElement;this._dataUnit=null==t?void 0:t.dataUnit,this._resourceID=null==t?void 0:t.resourceID,this._entityName=this._dataUnit.name.split("/")[2],null==this._resourceID&&(this._resourceID=await k.getResourceID()),this.setEvents(),await this.getActions(),this.loadItems()}async componentDidLoad(){if(this._element&&(p.addIDInfo(this._element),this.positionDropdown(),!await this._application.hasClientEvent(this.CLIENT_EVENT_CONFIRM_NAME))){const t=new D;this._application.addClientEvent(this.CLIENT_EVENT_CONFIRM_NAME,t.clientConfirm)}}componentDidUpdate(){this.positionDropdown()}loadItems(){this._actions&&0!=this._actions.length&&this._actions.forEach((t=>{this._items.push({id:t.actionID,label:t.description})}))}getElementID(t){return{[p.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:p.getInternalIDInfo(t)}}async loadParameters(){null==E.parameters.isOrderActions&&(E.parameters.isOrderActions=await this._application.getBooleanParam("global.ordenar.acoes.personalizadas"))}render(){return i(s,null,this._actions&&this._actions.length>0&&i("div",{class:`ez-padding-left--medium snk-actions-button\n ${this.canShowDropdown()?" ez-elevation--16":""}\n `},i("ez-button",Object.assign({ref:t=>this._ezButton=t,iconName:"acao",size:"small",mode:"icon",title:this._application.messagesBuilder.getMessage("snkActionsButton.title.actions",void 0),onClick:()=>this.controlDropdown()},this.getElementID("button"))),i("div",Object.assign({ref:t=>this._dropdownParent=t,class:(this.canShowDropdown()?"snk-actions-button__dropdown--show":"snk-actions-button__dropdown")+"\n "},this.getElementID("dropdown")),this.canShowDropdown()&&i("ez-dropdown",Object.assign({items:this._items,onEzClick:t=>this.handleClick(t)},this.getElementID("dropdown"))))),this.canShowDropdown()&&i("div",Object.assign({class:"ez-scrim ez-scrim--light"},this.getElementID("ezScrim"))))}get _element(){return e(this)}};E.parameters={isOrderActions:null},E.style=".sc-snk-actions-button-h{display:flex;width:fit-content;height:fit-content}.snk-actions-button.sc-snk-actions-button{display:flex;width:fit-content;height:fit-content}.snk-actions-button__dropdown--show.sc-snk-actions-button{display:flex;flex-direction:column;position:fixed}.snk-actions-button__dropdown.sc-snk-actions-button>ez-dropdown.sc-snk-actions-button{position:relative}.snk-actions-button__dropdown.sc-snk-actions-button{display:none}";const j=class{constructor(i){t(this,i),this.configChange=n(this,"configChange",7),this.configCancel=n(this,"configCancel",7),this._orderListItems=[],this._orderPriorityList=[],this._visibleList=[],this._hiddenList=[],this._columListItems=[],this._dataChanged=!1,this._componenteInternalKey=Date.now(),this.selectedIndex=0,this.columns=void 0,this.config=void 0,this.configName=void 0,this.resourceID=void 0,this._collapsibleBoxListOrder=!0,this._collapsibleBoxListSelect=!1}getMessage(t,i){return o.getContextValue("__SNK__APPLICATION__").messagesBuilder.getMessage(t,i)}getSortableColumns(){let t=[];return this.columns.filter((t=>{var i;return a.getBooleanValue(null===(i=null==t?void 0:t.props)||void 0===i?void 0:i.get("sortable"),!0)})).forEach((i=>{var s,e;let n=null===(s=this.config)||void 0===s?void 0:s.columns.find((t=>t.name===i.name)),o={label:i.label,sort:null!==(e=null==i?void 0:i.sort)&&void 0!==e?e:b.asc.value,id:i.name};n&&(o.orderIndex=n.orderIndex,o.ascending=n.ascending),i.hidden||t.push(o)})),t}createOrderList(){let t=this.getSortableColumns();t.sort(((t,i)=>0!=t.orderIndex||0!=i.orderIndex||null==t.ascending&&null==i.ascending?null!=t.ascending&&null!=i.ascending?t.orderIndex-i.orderIndex:null!=t.ascending||null!=i.ascending?null!=t.ascending?-1:null!=i.ascending?1:0:t.orderIndex-i.orderIndex:null!=t.ascending?-1:null!=i.ascending?1:0)),this._orderListItems=t}createColumnList(){let t={group:this.getMessage("snkGridConfig.group.visible"),items:[]},i={group:this.getMessage("snkGridConfig.group.hidden"),items:[],sort:b.asc.value};this.columns.forEach((s=>{var e;let n={label:s.label,selected:!1,sort:null!==(e=null==s?void 0:s.sort)&&void 0!==e?e:b.asc.value,id:s.name};s.hidden?i.items.push(n):t.items.push(n)})),this._columListItems=[t,i],this._visibleList=t.items,this._hiddenList=i.items,this.createOrderList()}createOrderListSlotDataElementId(t){return`${this._element.getAttribute(p.DATA_ELEMENT_ID_ATTRIBUTE_NAME)}_configItem_${a.toCamelCase(t.label)}`}buildOrderListSlot(t){const s=this.createOrderListSlotDataElementId(t);let e=b.none.value;return null!=(null==t?void 0:t.ascending)&&(e=1==t.ascending?b.asc.value:b.desc.value),i("snk-select-box",{selectedOption:e,key:"snk-select-box-"+this._componenteInternalKey+"-"+t,"data-element-id":s,onEzChange:i=>{i.stopPropagation(),this.updateOrder(i.detail,t.label)}})}updateOrder(t,i){var s;this._dataChanged=!0;let e,n=[...this.columns],o=n.find((t=>t.label===i));o&&(o.sort=t.value===b.none.value?void 0:t.value),(null===(s=this._orderPriorityList)||void 0===s?void 0:s.length)>0?(this._orderPriorityList.find((t=>t.label===o.label)).sort=t,this._orderPriorityList.filter((t=>t.sort)).forEach(((t,i)=>{t.label===o.label&&(o.sortIndex=i)}))):(e=n.filter((t=>t.sort&&!0!==t.hidden)).map(((t,i)=>({label:t.label,orderIndex:i}))),e.forEach((t=>{n.find((i=>i.label===t.label)).sortIndex=t.orderIndex}))),this.columns=n}finish(){if(!this._dataChanged)return void this.closeConfig();let t=[];this._columListItems.forEach((i=>{i.items.forEach((s=>{const e=this.columns.find((t=>t.label===s.label));let n=Object.assign({},e);n.hidden=i.group===this.getMessage("snkGridConfig.group.hidden"),t.push(n)}))})),this.columns=t,this._dataChanged=!1,this.closeConfig(),this.save()}saveGridConfigOnStorage(t){C.saveGridConfig(t,this.configName,this.resourceID).then((t=>{this.configChange.emit(t),w.info(this.getMessage("snkGridConfig.info.successfullyConfigSaved"),{iconName:"check"})}))}reOrderPriorityColumns(t,i){let s=[];s=t.filter((t=>t.sort&&!0!==t.hidden)).map((t=>({label:t.label,orderIndex:0})));let e=0,n=[];return i.forEach((t=>{let i=s.find((i=>i.label===t.label));i&&(i.orderIndex=e,n.push(i),e++)})),n.length>0&&(s=n),s}save(){var t;let i;i=this.config?this.config:this.createConfigFromState(this.columns);let s,e=[];(null===(t=this._orderPriorityList)||void 0===t?void 0:t.length)>0&&(s=this.reOrderPriorityColumns(this.columns,this._orderPriorityList)),this.columns.forEach((t=>{let n=i.columns.find((i=>t.name===i.name));!0===t.hidden&&n||(n?n.width=t.width:!1===t.hidden&&(n={name:t.name,width:t.width,orderIndex:0}),n&&(t.sort?(n.ascending=t.sort.toUpperCase()===b.asc.value,s?function(t,i){if(s){let e=s.find((i=>i.label===t.label));e&&(i.orderIndex=e.orderIndex)}}(t,n):n.orderIndex=t.sortIndex):(delete n.ascending,n.orderIndex=0),n.configVersion=j.CURRENT_CONFIG_VERSION,e.push(n)))})),i.columns=e,this.saveGridConfigOnStorage(i)}createConfigFromState(t){let i={columns:[]};return t.forEach((t=>{if(!t.hidden){let s={name:t.name};t.width&&(s.width=t.width),t.sort?(s.ascending=t.sort.toUpperCase()===b.asc.value,s.orderIndex=t.sortIndex):s.orderIndex=0,s&&i.columns.push(s)}})),i}closeConfig(){if(this._dataChanged){let t={canClose:!1,labelCancel:this.getMessage("snkGridConfig.confirm.cancel"),labelConfirm:this.getMessage("snkGridConfig.confirm.save"),btnConfirmDanger:!1};w.confirm(this.getMessage("snkGridConfig.confirm.alert"),this.getMessage("snkGridConfig.confirm.msgCancel"),null,y.WARN,t).then((t=>{t?this.finish():(this._dataChanged=!1,this.configCancel.emit(),this._componenteInternalKey=Date.now())}))}else this.configCancel.emit()}handleColumnListChange(t){var i;if(t.detail){let s=null===(i=t.detail.find((t=>t.group===this.getMessage("snkGridConfig.group.visible"))))||void 0===i?void 0:i.items;s&&(this._dataChanged=!0,this._orderListItems=s)}}handleOrderListChange(t){if(t.detail){let i=t.detail;i&&(this._dataChanged=!0,this._orderPriorityList=i)}}componentWillRender(){var t;(null===(t=this.columns)||void 0===t?void 0:t.length)>0&&this.createColumnList()}componentDidLoad(){p.addIDInfo(this._element)}handleRightListChange(t){const i=this._columListItems.find((t=>t.group===this.getMessage("snkGridConfig.group.visible")));i&&i.items!=t&&(i.items=t,this._dataChanged=!0)}getListSlots(){return{RIGHT_LIST:{itemRightSlotBuilder:t=>this.buildOrderListSlot(t)}}}render(){return i(s,null,i("div",{class:"grid-config__header"},i("div",{class:"title-container"},i("div",{class:"ez-margin-bottom--medium"},i("label",{class:"title"},this.getMessage("snkGridConfig.gridConfiguration")),i("label",{class:"subtitle"},this.getMessage("snkGridConfig.columnVisibilityOrder"))),i("div",{class:"button-close"},i("ez-button",{mode:"icon",iconName:"close",size:"medium",class:"ez-button--tertiary",onClick:()=>this.closeConfig()})))),i("div",{class:"grid-config__body"},i("ez-collapsible-box",{id:"group-select-columns",label:this.getMessage("snkGridConfig.columnsSelection"),"header-size":"medium",key:"key_group-select-columns",value:this._collapsibleBoxListSelect,onEzChange:({detail:t})=>this._collapsibleBoxListOrder=!t},i("div",{class:"grid-config__main"},i("ez-double-list",{leftList:this._hiddenList,leftTitle:this.getMessage("snkGridConfig.availableColumns"),rightList:this._visibleList,rightTitle:this.getMessage("snkGridConfig.selectedColumns"),onEzRightListChanged:({detail:t})=>this.handleRightListChange(t),emptyMessage:{LEFT_LIST:this.getMessage("snkGridConfig.emptyMensage.left"),RIGHT_LIST:this.getMessage("snkGridConfig.emptyMensage.right")},entityLabel:"coluna",entityLabelPlural:"colunas"}))),i("ez-collapsible-box",{id:"ID_group-order-columns",label:this.getMessage("snkGridConfig.dataOrdering"),"header-size":"medium",key:"KEY_group-order-columns",value:this._collapsibleBoxListOrder,onEzChange:({detail:t})=>this._collapsibleBoxListSelect=!t},i("div",{class:"grid-config__main"},i("ez-double-list",{rightList:this._orderListItems,rightTitle:this.getMessage("snkGridConfig.selectedColumns"),useOnlyRightList:!0,slotsListBuilder:this.getListSlots(),emptyMessage:{RIGHT_LIST:this.getMessage("snkGridConfig.emptyMensage.right")},entityLabel:"coluna",entityLabelPlural:"colunas"})))),i("div",{class:"grid-config__footer"},i("ez-button",{class:"padding-right--medium",label:this.getMessage("snkGridConfig.cancel"),onClick:()=>this.closeConfig()}),i("ez-button",{label:this.getMessage("snkGridConfig.complete"),class:"ez-button--primary",onClick:()=>this.finish()})))}static get assetsDirs(){return["../assets"]}get _element(){return e(this)}};j.CURRENT_CONFIG_VERSION=1,j.style='.sc-snk-grid-config-h{--snk-grid-config__footer--padding-top:var(--space--medium, 12px);--snk-grid-config__main--padding-right:var(--space--medium, 12px);--snk-grid-config__tabselector-container--padding:var(--space--medium, 12px);--snk-grid-config__button-close--padding-left:var(--space--medium, 12px);--snk-grid-config__title--color:var(--title--primary, #2B3A54);--snk-grid-config__title--font-family:var(--font-pattern, "Roboto");--snk-grid-config__title--font-size:var(--title--large, 20px);--snk-grid-config__title--font-weight:var(--text-weight--extra-large, 700);--snk-grid-config__subtitle--font-family:var(--font-pattern, "Roboto");--snk-grid-config__subtitle--font-size:var(--text--medium, 14px);--snk-grid-config__group--font-family:var(--font-pattern, "Roboto");--snk-grid-config__group--font-size:var(--text--medium, 14px);--snk-grid-config__group--font-weight:var(--text-weight--large, 600);--snk-grid-config__group--padding-bottom:var(--space-small, 6px);--snk-grid-config__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-grid-config__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-grid-config__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-grid-config__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-grid-config__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-grid-config__scrollbar--width:var(--space--small, 6px);display:flex;flex-direction:column;max-height:100%;width:100%}.grid-config__body.sc-snk-grid-config{overflow:auto}.padding-right--medium.sc-snk-grid-config{padding-right:var(--space--medium)}ez-list.sc-snk-grid-config{height:100%}.height-calc.sc-snk-grid-config{max-height:calc(100% - 24px)}.grid-config__footer.sc-snk-grid-config{display:flex;justify-content:flex-end;width:100%;padding-top:var(--snk-grid-config__footer--padding-top)}.hidden.sc-snk-grid-config{display:none}.tabselector-container.sc-snk-grid-config{padding:var(--snk-grid-config__tabselector-container--padding) 0}.button-close.sc-snk-grid-config{padding-left:var(--snk-grid-config__button-close--padding-left)}.title-container.sc-snk-grid-config{display:flex;justify-content:space-between;align-items:center;width:100%}.title.sc-snk-grid-config{display:flex;margin:0;line-height:normal;letter-spacing:0em;text-align:left;color:var(--snk-grid-config__title--color);font-size:var(--snk-grid-config__title--font-size);font-family:var(--snk-grid-config__title--font-family);font-weight:var(--snk-grid-config__title--font-weight)}.subtitle.sc-snk-grid-config{color:var(--text--primary);font-size:var(--snk-grid-config__subtitle--font-size);font-family:var(--snk-grid-config__subtitle--font-family)}.grid-config__main.sc-snk-grid-config{overflow-y:auto;scrollbar-width:thin;width:100%;padding-bottom:20px;scrollbar-color:var(--snk-grid-config__scrollbar--color-clicked) var(--snk-grid-config__scrollbar--color-background)}.group-name.sc-snk-grid-config{font-family:var(--snk-grid-config__group--font-family);font-size:var(--snk-grid-config__group--font-size);font-weight:var(--snk-grid-config__group--font-weight);padding-bottom:var(--snk-grid-config__group--padding-bottom)}';const B=class{constructor(i){t(this,i),this._formConfigFetcher=new v,this.layoutType=x.CASCADE}async save(){this._LayoutFormConfigSingleton.setConfig(this.layoutType),this._formConfigFetcher.saveLayoutFormConfig("formColCfg."+this._resourceID,{config:this.layoutType,newConfig:!0})}async componentWillLoad(){const t=o.getContextValue("__SNK__APPLICATION__");this._LayoutFormConfigSingleton=await(null==t?void 0:t.getLayoutFormConfig()),this._resourceID=await(null==t?void 0:t.getResourceID()),this.setLayoutInit()}setLayoutInit(){if(!this._LayoutFormConfigSingleton)return;const{config:t}=this._LayoutFormConfigSingleton;this.layoutType=Number(t)in x?Number(t):x.CASCADE}toggleLayout(t){this.layoutType=t}render(){return i("div",{class:"ez-flex ez-flex--column"},i("div",{class:"ez-margin-bottom--small"},i("ez-check",{label:"Layout em cascata",class:"ez-margin-bottom--small",onEzChange:()=>this.toggleLayout(x.CASCADE),value:this.layoutType===x.CASCADE}),i("snk-view-representation",{mode:x.CASCADE}),i("label",{class:"ez-label ez-margin--small ez-flex ez-text--medium"},"Todos os campos serão organizados em uma coluna única.")),i("div",null,i("ez-check",{label:"Layout lado a lado",class:"ez-margin-bottom--small",onEzChange:()=>this.toggleLayout(x.SIDE_BY_SIDE),value:this.layoutType===x.SIDE_BY_SIDE}),i("snk-view-representation",{mode:x.SIDE_BY_SIDE}),i("label",{class:"ez-label ez-margin--small ez-flex ez-text--medium"},"Todos os campos serão dispostos lado a lado, ajustando-se automaticamente à largura da tela.")))}};B.style=".sc-snk-layout-form-config-h{display:block}";const G=class{constructor(i){t(this,i),this.ezChange=n(this,"ezChange",7),this.selectedOption=b.none}render(){return i("ez-combo-box",{class:"grid-config-combo ez-input--inverted",label:"",suppressSearch:!0,value:this.selectedOption,enabled:!0,canShowError:!1,suppressEmptyOption:!0},Object.keys(b).map((t=>i("option",{value:b[t].value},b[t].label))))}static get assetsDirs(){return["../assets"]}};G.style="ez-combo-box{width:100px;--ez-text-input__margin-bottom:0px}.grid-config-combo{--ez-text-input--height:28px;--ez-text-input__input--background-color:#fff;--ez-text-input__input--border-color:#dce0e8}";const R=class{constructor(i){t(this,i),this.snkConfigSaved=n(this,"snkConfigSaved",7),this._formConfigFetcher=new v,this.fieldsToSave=[],this.dataUnit=void 0,this.configName=void 0,this.avaliableFields=[],this.selectedFields=[]}async show(){var t;await(null===(t=this.ezDoubleListRef)||void 0===t?void 0:t.resetSelectedLists()),await this.initializeFormConfig(),this.ezPopupRef.opened=!0}async initializeFormConfig(){if(!this.configName)return;const t=this.getAllVisibleFieldsFromDataUnit(),i=await this.getConfig();if(0===i.length)return this.avaliableFields=[],this.selectedFields=[...t],void(this.fieldsToSave=[...this.selectedFields]);const s=this.sortDisplayedFields(i,t),e=t.filter((t=>!i.includes(t.id)));this.avaliableFields=[...e],this.selectedFields=[...s],this.fieldsToSave=[...this.selectedFields]}async getConfig(){const t=await this._formConfigFetcher.fetchSimpleFormConfig(this.configName);return[...this.removeDuplicates(t)]}removeDuplicates(t){return t.filter(((i,s)=>t.indexOf(i)===s))}sortDisplayedFields(t,i){const s=[];return t.forEach((t=>{const e=i.find((i=>i.id===t));e&&s.push(e)})),s}getAllVisibleFieldsFromDataUnit(){var t,i,s;return(null!==(s=null===(i=null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)||void 0===i?void 0:i.fields)&&void 0!==s?s:[]).filter((t=>t.visible)).map((t=>({id:t.name,label:t.label})))}close(){this.ezPopupRef.opened=!1}async handleResetConfigs(){await this._formConfigFetcher.restoreFormConfig(this.configName),await this.initializeFormConfig(),await this.handleSave()}handleCancel(){this.close()}async handleSave(){const t=this.fieldsToSave.map((t=>t.id));await this._formConfigFetcher.saveSimpleFormConfig(this.configName,t),this.close(),this.snkConfigSaved.emit()}render(){return i("ez-popup",{ref:t=>this.ezPopupRef=t,heightMode:"auto",size:"medium",ezTitle:"Configurar formulário"},i("div",{class:"config-container"},i("div",{class:"config-lists"},i("ez-double-list",{ref:t=>this.ezDoubleListRef=t,leftList:this.avaliableFields,leftTitle:"Campos disponíveis",rightList:this.selectedFields,rightTitle:"Campos selecionados",onEzRightListChanged:({detail:t})=>this.fieldsToSave=[...t],entityLabel:"campo",entityLabelPlural:"campos"})),i("div",{class:"config-actions"},i("ez-button",{label:"Restaurar",onClick:this.handleResetConfigs.bind(this),size:"small"}),i("ez-button",{label:"Cancelar",onClick:this.handleCancel.bind(this),size:"small"}),i("ez-button",{label:"Salvar",class:"ez-button--primary",onClick:this.handleSave.bind(this),size:"small"}))))}};R.style=":host{display:block}.config-container{display:flex;flex-direction:column;align-items:center;justify-content:space-between}.config-lists{width:100%;margin-bottom:12px}.config-actions{display:flex;flex-direction:row;justify-content:flex-end;width:100%;gap:12px}";const F=class{constructor(i){t(this,i),this.mode=x.SIDE_BY_SIDE}renderCascadeLayout(){return i("div",{class:"svg-container__collumn"},[...Array(3)].map((()=>i("div",{class:"svg-container__section"},i("div",{class:"svg-container__line svg-container__line--short"}),i("div",{class:"svg-container__line svg-container__line--long"})))))}renderSideBySideLayout(){return i("div",{class:"svg-container__inline"},[...Array(2)].map((()=>this.renderCascadeLayout())))}render(){return i("div",{class:"svg-container ez-margin-left--small"},i("div",{class:"svg-container__background"},i("div",{class:"svg-container__header"},i("div",{class:"svg-container__circle svg-container__circle--red"}),i("div",{class:"svg-container__circle svg-container__circle--yellow"}),i("div",{class:"svg-container__circle svg-container__circle--green"})),this.mode===x.CASCADE?this.renderCascadeLayout():this.renderSideBySideLayout()))}};F.style=".sc-snk-view-representation-h{display:block}.svg-container.sc-snk-view-representation{display:flex;width:185px;height:125px;border-radius:8px;background-color:#f7f7f7;padding:10px 12px;box-sizing:border-box;position:relative}.svg-container__background.sc-snk-view-representation{display:flex;flex-direction:column;width:100%}.svg-container__header.sc-snk-view-representation{display:flex;gap:2px;margin-bottom:12px}.svg-container__circle.sc-snk-view-representation{width:9px;height:9px;border-radius:50%}.svg-container__circle--red.sc-snk-view-representation{background-color:#ed7678}.svg-container__circle--yellow.sc-snk-view-representation{background-color:#eddb76}.svg-container__circle--green.sc-snk-view-representation{background-color:#7ad08e}.svg-container__section.sc-snk-view-representation{width:100%}.svg-container__collumn.sc-snk-view-representation{width:100%;display:flex;flex-direction:column}.svg-container__inline.sc-snk-view-representation{display:flex;flex-direction:row;gap:6px}.svg-container__line.sc-snk-view-representation{height:13px;border-radius:4px;background-color:#d9d9d9;margin-bottom:4px}.svg-container__line--short.sc-snk-view-representation{width:39.68px;height:7px;border-radius:3.5px}.svg-container__line--long.sc-snk-view-representation{width:100%}";const M=class{constructor(i){t(this,i),this.taskbarActionSelected=n(this,"taskbarActionSelected",7),this.taskbarActionsOpened=n(this,"taskbarActionsOpened",7),this.taskbarActionsButtonDisconnected=n(this,"taskbarActionsButtonDisconnected",7),this._showDropdown=!1,this.title=void 0,this.enabled=void 0,this.actions=void 0}async handleKeyDown(t){"Escape"!==t.key&&"Esc"!==t.key||await this.hideActions()}async handleClose(){await this.hideActions()}async showActions(){this._showDropdown=!0,requestAnimationFrame((()=>{this._element.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}))}async hideActions(){this._showDropdown=!1}async isOpened(){return this._showDropdown}controlDropdown(){this._showDropdown=!this._showDropdown}loadItems(){return this.actions.filter((t=>void 0!==t)).map((t=>{var i;return{id:t.value,label:t.label,value:t.value,type:null!==(i=t.type)&&void 0!==i?i:"item",children:t.children,iconName:t.iconName,subAction:t.subAction,group:t.group,disableCloseOnSelect:t.disableCloseOnSelect}}))}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this.actions)||void 0===t?void 0:t.length)>0}onSelectAction(t){const i=this.actions.map((t=>Object.assign(Object.assign({},t),{id:t.value}))),s=this.getSelectedAction(t.id,i);this.taskbarActionSelected.emit(s),s.disableCloseOnSelect||(this._showDropdown=!1)}getSelectedAction(t,i){let s=null;for(const e of i){if(e.id===t){s=e;break}if((null==e?void 0:e.children)&&(s=this.getSelectedAction(t,e.children),s))break}return s}dropdownItemBuilder(t,s){const e=this.actions.find((i=>i.value===t.id));if(!e||!e.itemBuilder)return;const n=e.itemBuilder(this._element,e);return"string"==typeof n?i("div",{innerHTML:n}):n}initializeEagerItems(){var t;null===(t=this.actions)||void 0===t||t.forEach((t=>{var i;t&&t.eagerInitialize&&t.itemBuilder&&(null===(i=t.itemBuilder)||void 0===i||i.call(t,this._element,t))}))}componentDidLoad(){this.initializeEagerItems()}componentDidRender(){this._showDropdown&&this.taskbarActionsOpened.emit(this._element)}disconnectedCallback(){this.taskbarActionsButtonDisconnected.emit()}render(){return i(s,null,i("div",{class:(this.canShowDropdown()?" ez-elevation--16":"")+" ez-dropdown-container"},i("ez-button",{title:this.title,mode:"icon",iconName:"dots-vertical",size:"small",enabled:this.enabled,onClick:()=>this.controlDropdown()}),this.canShowDropdown()&&i("ez-dropdown",{class:"ez-dropdown--sticky",items:this.loadItems(),onEzClick:t=>this.onSelectAction(t.detail),onEzOutsideClick:()=>this._showDropdown=!1,itemBuilder:(t,i)=>this.dropdownItemBuilder(t,i)})))}get _element(){return e(this)}};M.style=".sc-taskbar-actions-button-h{--ez-dropdown--min-width:150px;display:flex;width:fit-content;height:fit-content}.ez-dropdown-container.sc-taskbar-actions-button{position:relative;display:inline-block}.ez-dropdown--sticky.sc-taskbar-actions-button{position:absolute;display:block;min-width:var(--ez-dropdown--min-width)}";const K=class{constructor(i){t(this,i),this._showDropdown=!1,this.iconName=void 0,this.action=void 0,this.name=void 0,this.className=void 0,this.dataElementId=void 0,this.title=void 0,this.enabled=void 0,this.actions=void 0}initializeEagerItems(){var t;null===(t=this.actions)||void 0===t||t.forEach((t=>{var i;t&&t.eagerInitialize&&t.itemBuilder&&(null===(i=t.itemBuilder)||void 0===i||i.call(t,this._splitButtonRef,t))}))}componentDidLoad(){this.initializeEagerItems()}dropdownItemBuilder(t,s){const e=this.actions.find((i=>i.value===t.id));if(!e||!e.itemBuilder)return;const n=e.itemBuilder(this._splitButtonRef,e);return"string"==typeof n?i("div",{innerHTML:n}):n}loadItems(){return this.actions.filter((t=>void 0!==t)).map((t=>{var i;return{id:t.value,label:t.label,value:t.value,type:null!==(i=t.type)&&void 0!==i?i:"item",children:t.children,iconName:t.iconName,subAction:t.subAction,group:t.group,disableCloseOnSelect:t.disableCloseOnSelect}}))}render(){return i(s,null,i("ez-split-button",{ref:t=>this._splitButtonRef=t,key:this.dataElementId,class:`${this.className} "ez-split-button--tertiary ez-padding--medium"`,items:this.loadItems(),mode:"icon-only",iconName:this.iconName,enabled:this.enabled,show:this._showDropdown,onButtonClick:()=>this.action(this.name),itemBuilder:(t,i)=>this.dropdownItemBuilder(t,i)}))}};K.style="";export{E as snk_actions_button,j as snk_grid_config,B as snk_layout_form_config,G as snk_select_box,R as snk_simple_form_config,F as snk_view_representation,M as taskbar_actions_button,K as taskbar_split_button}
@@ -1,4 +1,4 @@
1
- import{r as t,c as e,h as i,H as s,g as n}from"./p-d8d8169b.js";import{DateUtils as a,StringUtils as r,ObjectUtils as o,WaitingChangeException as h,SilentException as c,WarningException as l,ErrorException as d,ElementIDUtils as u,SearchUtils as p,ArrayUtils as m,KeyboardManager as g,OnboardingUtils as w,DependencyType as y,ApplicationContext as v,DataType as f,ErrorTracking as P,UserAgentUtils as _,LockManager as z,LockManagerOperation as k}from"@sankhyalabs/core";import{ApplicationUtils as x}from"@sankhyalabs/ezui/dist/collection/utils";import{C as A}from"./p-6416975c.js";import{d as I,D as S,U as b}from"./p-fbba7e3d.js";import{A as T,a as C}from"./p-73285a8a.js";import{P as L,D as N}from"./p-8f8367d5.js";import{P as E}from"./p-6dd38d7b.js";import{S as D}from"./p-fc4eac32.js";import{T as O}from"./p-9019a32f.js";import"./p-0f3698af.js";import"./p-ff1990ad.js";import{F as R}from"./p-601b252b.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";class j{static webConnectionCaller(t,e,i){var s;null===(s=window.AppletCaller)||void 0===s||s.webConnectionCaller(t,e,i)}}const M=U;function U(t,e){const i=F();return(U=function(t){return i[t-=378]})(t,e)}function F(){const t=["true","863GKWjmo","parse","56355fjjjAm","isSup","putAccess","4324480sjuCdS","hasOwnProperty","239748okvJLB","name","6055770tXeRaU","actions","forEach","7RPRvzn","1042CHxkUw","2988126NIwRMm","20MTNzmH","authorizationSf","item","string","hasAccess","isArray","Objeto não pode ser indefinido.","3071943fWslZp","parseFromJSON"];return(F=function(){return t})()}!function(){const t=U,e=F();for(;;)try{if(281287==parseInt(t(399))/1*(-parseInt(t(387))/2)+-parseInt(t(401))/3+parseInt(t(381))/4*(-parseInt(t(389))/5)+parseInt(t(388))/6*(-parseInt(t(386))/7)+parseInt(t(379))/8+parseInt(t(396))/9+parseInt(t(383))/10)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();class ${[M(397)](t){const e=M;if(typeof(t=utxt(t[e(390)]))==e(392)&&(t=JSON[e(400)](t)),null==t)throw Error(e(395));const i=new q("S"===t[e(402)]||!0===t[e(402)]);return Array[e(394)](t[e(391)])&&t[e(391)][e(385)]((t=>i.putAccess(t[e(382)],String(t.status)==e(398)))),i}}class q{constructor(t){const e=M;this.isSup=t,this[e(384)]={}}[M(378)](t,e){this[M(384)][t]=e}[M(393)](t){const e=M;if(this[e(402)])return!0;let i=!0;return this[e(384)][e(380)](t)&&(i=this.actions[t]),i}isUserSup(){return this.isSup}}class B{constructor(){this._embeddedParams=new Map,this._cachedParams=new Map,this.templateByQuery=new Map;try{if(null!=window.MGE_PARAMS){atob(window.MGE_PARAMS).split("__;__").forEach((t=>{const[e,i]=t.split("__=__");this._embeddedParams.set(e,i)}))}}catch(t){console.error("Problemas ao obter parâmetros embarcados"),console.error(t)}this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchParam",I.gql`query($name: String!) {
1
+ import{r as t,c as e,h as i,H as s,g as n}from"./p-d8d8169b.js";import{DateUtils as a,StringUtils as r,ObjectUtils as o,WaitingChangeException as h,SilentException as c,WarningException as l,ErrorException as d,ElementIDUtils as u,SearchUtils as p,ArrayUtils as m,KeyboardManager as g,OnboardingUtils as w,DependencyType as y,ApplicationContext as v,DataType as f,ErrorTracking as P,UserAgentUtils as _,LockManager as z,LockManagerOperation as k}from"@sankhyalabs/core";import{ApplicationUtils as x}from"@sankhyalabs/ezui/dist/collection/utils";import{C as A}from"./p-8758404f.js";import{d as I,D as S,U as b}from"./p-cd1a5b6a.js";import{A as T,a as C}from"./p-e25412da.js";import{P as L,D as N}from"./p-37b4f642.js";import{P as E}from"./p-c9657baa.js";import{S as D}from"./p-fc4eac32.js";import{T as O}from"./p-9019a32f.js";import"./p-0f3698af.js";import"./p-ff1990ad.js";import{F as R}from"./p-b21d32f6.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";class j{static webConnectionCaller(t,e,i){var s;null===(s=window.AppletCaller)||void 0===s||s.webConnectionCaller(t,e,i)}}const M=U;function U(t,e){const i=F();return(U=function(t){return i[t-=378]})(t,e)}function F(){const t=["true","863GKWjmo","parse","56355fjjjAm","isSup","putAccess","4324480sjuCdS","hasOwnProperty","239748okvJLB","name","6055770tXeRaU","actions","forEach","7RPRvzn","1042CHxkUw","2988126NIwRMm","20MTNzmH","authorizationSf","item","string","hasAccess","isArray","Objeto não pode ser indefinido.","3071943fWslZp","parseFromJSON"];return(F=function(){return t})()}!function(){const t=U,e=F();for(;;)try{if(281287==parseInt(t(399))/1*(-parseInt(t(387))/2)+-parseInt(t(401))/3+parseInt(t(381))/4*(-parseInt(t(389))/5)+parseInt(t(388))/6*(-parseInt(t(386))/7)+parseInt(t(379))/8+parseInt(t(396))/9+parseInt(t(383))/10)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();class ${[M(397)](t){const e=M;if(typeof(t=utxt(t[e(390)]))==e(392)&&(t=JSON[e(400)](t)),null==t)throw Error(e(395));const i=new q("S"===t[e(402)]||!0===t[e(402)]);return Array[e(394)](t[e(391)])&&t[e(391)][e(385)]((t=>i.putAccess(t[e(382)],String(t.status)==e(398)))),i}}class q{constructor(t){const e=M;this.isSup=t,this[e(384)]={}}[M(378)](t,e){this[M(384)][t]=e}[M(393)](t){const e=M;if(this[e(402)])return!0;let i=!0;return this[e(384)][e(380)](t)&&(i=this.actions[t]),i}isUserSup(){return this.isSup}}class B{constructor(){this._embeddedParams=new Map,this._cachedParams=new Map,this.templateByQuery=new Map;try{if(null!=window.MGE_PARAMS){atob(window.MGE_PARAMS).split("__;__").forEach((t=>{const[e,i]=t.split("__=__");this._embeddedParams.set(e,i)}))}}catch(t){console.error("Problemas ao obter parâmetros embarcados"),console.error(t)}this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchParam",I.gql`query($name: String!) {
2
2
  $queryAlias$: fetchResource(name: $name){
3
3
  name
4
4
  resource
@@ -1 +1 @@
1
- import{r as s,h as i,H as t,g as e}from"./p-d8d8169b.js";import{ObjectUtils as a,StringUtils as r,ElementIDUtils as o}from"@sankhyalabs/core";import{P as n,b as l,a as c}from"./p-6dd38d7b.js";import"./p-fbba7e3d.js";import"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-8f8367d5.js";import"./p-ff1990ad.js";import"./p-601b252b.js";import"./p-9019a32f.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";const h=class{constructor(i){s(this,i),this._mdByName={},this._startHighlightTag="<span class='card-item__highlight'>",this._endHighlightTag="</span>",this._specialCharsRegex=/[[.\-\$\+\*,_\&\(\)%\/\\#@!:\|\=\'\"]/gim,this._charsWithAccentuation="ÁÉÍÓÚ_ÃÕ_ÂÊÎÔÛ_ÀÈÌÒÙ_Ü_Ç_áéíóú_ãõ_âêîôû_àèìòù_ü_ç",this._charsWithoutAccentuation="AEIOU_AO_AEIOU_AEIOU_U_C_aeiou_ao_aeiou_aeiou_u_c",this._changeDeboucingTimeout=null,this._limitCharsToSearch=3,this._deboucingTime=450,this._gridDataSource=[],this.pesquisaFetcher=new n,this._itemList=void 0,this._startLoading=!1,this._presentationMode="list",this._currentView=void 0,this._valideDataSource=!1,this.searchLoader=void 0,this.treeLoader=void 0,this.selectItem=void 0,this.entityName=void 0,this.argument=void 0,this.isHierarchyEntity=!1,this.allowsNonAnalytic=!1}observeArgument(){this._textInput&&(this._textInput.value=this.argument)}clearSearch(){this.argument="",this._itemList=void 0}buildDetails(s,i){let t={};for(let e=0;e<s.length;e++){const a=s[e],r=i[a.fieldName];t[a.description]=this.highlightValue(i.__matchFields,a.options&&a.options[r]||r,s,!0)}return t}buildFirstFields(s,i,t=6){return s&&Array.isArray(s)&&s.forEach((s=>{let t=this.removeReference(i,this._mdByName[s]);t&&i.unshift(t)})),i=i.slice(0,t)}doSearch(s){this.searchLoader&&"function"==typeof this.searchLoader&&(this._startLoading=!0,this.searchLoader(s).then((s=>{s&&this.processSearchResponse(s)})).finally((()=>{this._startLoading=!1})))}processSearchResponse(s){let i=(s=a.stringToObject(s.json.$)).descriptionField,t=s.pkField;t&&(this._gridMetadata=l(s),this._gridDataSource=[...s.data],this._pkField=t,this._descriptionField=i,this._itemList=this.buildCardItemList(s,t,i))}buildCardItemList(s,i,t){var e;return null===(e=s.data)||void 0===e?void 0:e.map((e=>{var a;let r=this.filterFieldsMetadata(s,e),o=this.buildFirstFields(e.__matchFields,r);return{key:this.highlightValue(e.__matchFields,null===(a=e[i])||void 0===a?void 0:a.toString(),o,!0),title:t?this.highlightValue(e.__matchFields,e[t],o,!0):"",details:this.buildDetails(o,e)}}))}filterFieldsMetadata(s,i){return s.fieldsMetadata.filter((t=>{let e=!r.isEmpty(i[t.fieldName])&&!1!==t.visible&&"B"!==t.type&&s.pkField!==t.fieldName&&s.descriptionField!==t.fieldName&&(t.isPrimaryKey||!t.isLinkField)&&!("S"===t.type&&"H"===t.presentationType);return e&&(this._mdByName[t.fieldName]=t),("string"!=typeof i[t.fieldName]||!(i[t.fieldName].indexOf("<img")>-1||i[t.fieldName].indexOf("<svg")>-1))&&e}))}removeAtIndex(s,i){if(i>=0&&i<s.length)return s.splice(i,1)[0]}removeReference(s,i){let t=this.indexOf(s,i);return this.removeAtIndex(s,t)}indexOf(s,i){let t=-1;return Array.isArray(s)&&this.find(s,((s,e)=>(t=e,this.equals(i,s)))),t}equals(s,i){return a.objectToString(s)===a.objectToString(i)}find(s,i){if(s)for(let t=0,e=s.length;t<e;t++)if(i(s[t],t,s))return s[t]}highlightValue(s,i,t,e){let a=this.replaceHtmlEntities(i);if(this.argument&&(e||this.isIn(s,t.fieldName))){const s=this.getArgumentNumber();let i=(isNaN(s)?this.argument:s.toString()).split(/%|,|\s+/),e=0,r=this.replaceAccentuatedChars(a);i.forEach((s=>{if(s){s=this.replaceAccentuatedChars(s);let i=this.getSpecialCharacters(s);null!=i&&i.length>0&&(s=this.removeSpecialCharacters(s)),(t.mask||"CGC_CPF"===t.uiType||"Phone"===t.uiType)&&(s=s.split("").join("\\.?\\-?\\/?\\(?\\)?"));let o=new RegExp(s,"ig");o.lastIndex=e;let n=o.exec(r);if(n&&n.length>0){e=n.index;let s=n[0].length,i=a.substring(e,e+s),t=(null==i?void 0:i.trim())?this._startHighlightTag+i+this._endHighlightTag:"",o=a.substring(0,e),l=a.substring(e+s);a=o+t+l,e+=t.length,r=this.replaceAccentuatedChars(a)}}}))}return a}replaceHtmlEntities(s){return null==s?s:String(s).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}replaceAccentuatedChars(s){return null==s?s:this.replaceToSpace(s,["&amp;","&lt;","&gt;","&quot;"]).replace(/[^\w ]/g,(s=>{let i=this._charsWithAccentuation.indexOf(s);return i>-1&&(s=this._charsWithoutAccentuation.charAt(i)),s||""}))}replaceToSpace(s,i=[]){return null==s||i.forEach((i=>{const t=new RegExp(i,"g");let e="";for(let s=0;s<i.length;s++)e+=" ";s=String(s).replace(t,e)})),s}isIn(s,i){return this.indexOf(s,i)>-1}getSpecialCharacters(s){let i,t=[];for(;i=this._specialCharsRegex.exec(s);)t.push(s[i.index]);return t}removeSpecialCharacters(s){return this.getSpecialCharacters(s).forEach((i=>{s=this.replaceAll(s,i,"")})),s}replaceAll(s,i,t){let e=(null!=s?s:"").indexOf(i);for(;e>-1;)e=(s=s.replace(i,t)).indexOf(i);return s}getArgumentNumber(){return Number(this.argument||void 0)}createOption(s){let{key:i,title:t}=s;const e=new RegExp(this._startHighlightTag,"g"),a=new RegExp(this._endHighlightTag,"g");t=r.decodeHtmlEntities(t);const o={value:null==i?void 0:i.replace(e,"").replace(a,""),label:null==t?void 0:t.replace(e,"").replace(a,"")};this.selectItem(o)}onChangeValue(s){var i;if(this.clearDeboucingTimeout(),this._startLoading)return void(this._changeDeboucingTimeout=setTimeout((()=>{this.onChangeValue(s)}),this._deboucingTime));if(this.argument=(s.detail||"").trim(),this.isHierarchyEntity&&"list"===this._presentationMode)return void(null===(i=this._pesquisaTree)||void 0===i||i.applyFilter());const t=this.getArgumentNumber();this.argument&&(!isNaN(t)||this.argument.length>=this._limitCharsToSearch)?this._changeDeboucingTimeout=setTimeout((()=>{this.doSearch(isNaN(t)?this.argument:t.toString()),this._valideDataSource=!0}),this._deboucingTime):(this._itemList=void 0,this._gridDataSource=[],this._valideDataSource=!1)}clearDeboucingTimeout(){this._changeDeboucingTimeout&&(clearTimeout(this._changeDeboucingTimeout),this._changeDeboucingTimeout=void 0)}onClickSearch(){this.doSearch((this.argument||"").trim()),this._valideDataSource=!0}getMessageView(){return this._startLoading?"Aguarde, buscando registros...":this._itemList?this._itemList.length>=1?`${this._itemList.length} ${this._itemList.length>1?"registros encontrados":"registro encontrado"}`:"Nenhum registro encontrado":"Os resultados de sua pesquisa aparecerão aqui..."}async componentWillLoad(){const s=await this.pesquisaFetcher.loadPresentationConfig(this.entityName);this._presentationMode="list"===s?"list":"table"}async componentDidLoad(){o.addIDInfo(this._element),await this.chooseViewMode()}async handleChangeViewMode(){this._presentationMode="list"===this._presentationMode?"table":"list",await this.chooseViewMode(),await this.pesquisaFetcher.savePresentationConfig(this.entityName,this._presentationMode)}async chooseViewMode(){var s,i;if("list"!==this._presentationMode)return await(null===(s=this._viewStack)||void 0===s?void 0:s.show(c.GRID)),void(this._currentView=c.GRID);const t=this.isHierarchyEntity?c.TREE:c.CARDS;await(null===(i=this._viewStack)||void 0===i?void 0:i.show(t)),this._currentView=t}hideLimitMessage(){return!this._itemList||this._itemList.length<100}hideRecordsMessage(){return"list"===this._presentationMode&&this.isHierarchyEntity}getButtonModeInfo(){return"list"===this._presentationMode?{iconName:"table",title:"Modo grade"}:this.isHierarchyEntity?{iconName:"hierarchical-tree",title:"Modo árvore hierárquica"}:{iconName:"list",title:"Modo lista"}}render(){var s,e;return i(t,null,i("div",{class:"snk-pesquisa"},i("div",{class:"snk-pesquisa__input"},i("ez-text-input",{label:"Buscar",class:"ez-margin-right--medium",canShowError:!1,ref:s=>this._textInput=s,onEzChange:s=>this.onChangeValue(s),value:this.argument,"data-element-id":"searchInput"},i("ez-icon",{slot:"leftIcon",iconName:"search"}),this.argument&&(null===(s=this._textInput)||void 0===s?void 0:s.value)?i("button",{slot:"rightIcon",class:"snk-pesquisa__btn",onClick:()=>this.clearSearch()},i("ez-icon",{iconName:"close"})):void 0),i("ez-button",{class:"ez-button--primary",label:"Pesquisar",onClick:()=>this.onClickSearch()}),i("ez-button",{class:"ez-margin-left--medium",mode:"icon",iconName:this.getButtonModeInfo().iconName,title:this.getButtonModeInfo().title,onClick:async()=>await this.handleChangeViewMode()})),i("div",{class:"snk-pesquisa__records-label "+(this._currentView===c.TREE?"hidden":"")},i("label",{class:"snk-pesquisa__records "+(this.hideRecordsMessage()?"hidden":"")},this.getMessageView()),i("label",{class:"snk-pesquisa__records-limit "+(this.hideLimitMessage()?"hidden":"")},"Essa pesquisa foi limitada, existem mais resultados.")),i("div",{class:"snk-pesquisa__content"},i("ez-view-stack",{ref:s=>this._viewStack=s,"data-element-id":"simple-crud"},i("stack-item",null,this._valideDataSource&&i("pesquisa-grid",{metadata:this._gridMetadata,dataSource:this._gridDataSource,pkField:this._pkField,descriptionField:this._descriptionField,entityName:this.entityName,shouldLoadConfig:this._currentView===c.GRID,onPesquisaGridSelectItem:({detail:s})=>this.selectItem(s)})),i("stack-item",null,i("div",{class:"snk-pesquisa__cards-container"},null===(e=this._itemList)||void 0===e?void 0:e.map((s=>i("ez-card-item",{onEzClick:s=>this.createOption(s.detail),item:s}))))),i("stack-item",null,i("pesquisa-tree",{ref:s=>this._pesquisaTree=s,argument:this.argument,treeLoader:this.treeLoader,allowsNonAnalytic:this.allowsNonAnalytic,shouldLoadTree:this._currentView===c.TREE,onPesquisaTreeSelectItem:({detail:s})=>this.selectItem(s)}))))))}get _element(){return e(this)}static get watchers(){return{argument:["observeArgument"]}}};h.style=".sc-snk-pesquisa-h{--snk-pesquisa--font-size:var(--text--medium, 14px);--snk-pesquisa--font-family:var(--font-pattern, Arial);--snk-pesquisa--font-weight:var(--text-weight--medium, 400);--snk-pesquisa__records--color:var(--text--primary, #626e82);--snk-pesquisa__records--color-secondary:var(--text--secondary, #626e82);--snk-pesquisa__records--padding-vertical:var(--space--medium, 12px);--snk-pesquisa__content--padding-right:var(--space--small, 6px);--snk-pesquisa__btn--color:var(--title--primary, #2B3A54);--snk-pesquisa__btn-disabled--color:var(--text--disable, #AFB6C0);--snk-pesquisa__btn-hover--color:var(--color--primary, #4e4e4e);--snk-pesquisa__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-pesquisa__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-pesquisa__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-pesquisa__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-pesquisa__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-pesquisa__scrollbar--width:var(--space--small, 6px);height:100%;display:flex;flex-direction:column;overflow-y:auto}.snk-pesquisa.sc-snk-pesquisa{display:flex;flex-direction:column;height:100%}.snk-pesquisa__input.sc-snk-pesquisa{display:flex;width:100%;box-sizing:border-box;padding-top:4px;padding-right:4px}.snk-pesquisa__input.sc-snk-pesquisa ez-icon.sc-snk-pesquisa{--ez-icon--color:inherit;font-weight:var(--text-weight--large, 600)}.snk-pesquisa__content.sc-snk-pesquisa{display:flex;flex-direction:column;overflow-y:hidden;scrollbar-width:thin;scrollbar-color:var(--snk-pesquisa__scrollbar--color-clicked) var(--snk-pesquisa__scrollbar--color-background);padding-right:var(--snk-pesquisa__content--padding-right);height:100vh}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar{background-color:var(--snk-pesquisa__scrollbar--color-background);width:var(--snk-pesquisa__scrollbar--width);max-width:var(--snk-pesquisa__scrollbar--width);min-width:var(--snk-pesquisa__scrollbar--width)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-track{background-color:var(--snk-pesquisa__scrollbar--color-background);border-radius:var(--snk-pesquisa__scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb{background-color:var(--snk-pesquisa__scrollbar--color-default);border-radius:var(--snk-pesquisa__scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:vertical:hover,.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--snk-pesquisa__scrollbar--color-hover)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:vertical:active,.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--snk-pesquisa__scrollbar--color-clicked)}.snk-pesquisa__records-label.sc-snk-pesquisa{display:flex;flex-direction:row;justify-content:space-between;font-family:var(--snk-pesquisa--font-family);font-weight:var(--snk-pesquisa--font-weight);font-size:var(--snk-pesquisa--font-size);padding-bottom:var(--snk-pesquisa__records--padding-vertical);padding-top:var(--snk-pesquisa__records--padding-vertical)}.snk-pesquisa__records-label.hidden.sc-snk-pesquisa{display:none}.snk-pesquisa__records.sc-snk-pesquisa{color:var(--snk-pesquisa__records--color)}.snk-pesquisa__records-limit.sc-snk-pesquisa{color:var(--snk-pesquisa__records--color-secondary)}.snk-pesquisa__records-limit.hidden.sc-snk-pesquisa,.snk-pesquisa__records.hidden.sc-snk-pesquisa{visibility:hidden}.snk-pesquisa__btn.sc-snk-pesquisa{outline:none;border:none;background:none;cursor:pointer;color:var(--snk-pesquisa__btn--color)}.snk-pesquisa__btn.sc-snk-pesquisa:disabled{cursor:unset;color:var(--snk-pesquisa__btn-disabled--color)}.snk-pesquisa__btn.sc-snk-pesquisa:disabled:hover{cursor:unset;color:var(--snk-pesquisa__btn-disabled--color)}.snk-pesquisa__btn.sc-snk-pesquisa:hover{color:var(--snk-pesquisa__btn-hover--color)}.snk-pesquisa__cards-container.sc-snk-pesquisa{height:100%;overflow-y:auto}";export{h as snk_pesquisa}
1
+ import{r as s,h as i,H as t,g as e}from"./p-d8d8169b.js";import{ObjectUtils as a,StringUtils as r,ElementIDUtils as o}from"@sankhyalabs/core";import{P as n,b as l,a as c}from"./p-c9657baa.js";import"./p-cd1a5b6a.js";import"./p-0f3698af.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-37b4f642.js";import"./p-ff1990ad.js";import"./p-b21d32f6.js";import"./p-9019a32f.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";const h=class{constructor(i){s(this,i),this._mdByName={},this._startHighlightTag="<span class='card-item__highlight'>",this._endHighlightTag="</span>",this._specialCharsRegex=/[[.\-\$\+\*,_\&\(\)%\/\\#@!:\|\=\'\"]/gim,this._charsWithAccentuation="ÁÉÍÓÚ_ÃÕ_ÂÊÎÔÛ_ÀÈÌÒÙ_Ü_Ç_áéíóú_ãõ_âêîôû_àèìòù_ü_ç",this._charsWithoutAccentuation="AEIOU_AO_AEIOU_AEIOU_U_C_aeiou_ao_aeiou_aeiou_u_c",this._changeDeboucingTimeout=null,this._limitCharsToSearch=3,this._deboucingTime=450,this._gridDataSource=[],this.pesquisaFetcher=new n,this._itemList=void 0,this._startLoading=!1,this._presentationMode="list",this._currentView=void 0,this._valideDataSource=!1,this.searchLoader=void 0,this.treeLoader=void 0,this.selectItem=void 0,this.entityName=void 0,this.argument=void 0,this.isHierarchyEntity=!1,this.allowsNonAnalytic=!1}observeArgument(){this._textInput&&(this._textInput.value=this.argument)}clearSearch(){this.argument="",this._itemList=void 0}buildDetails(s,i){let t={};for(let e=0;e<s.length;e++){const a=s[e],r=i[a.fieldName];t[a.description]=this.highlightValue(i.__matchFields,a.options&&a.options[r]||r,s,!0)}return t}buildFirstFields(s,i,t=6){return s&&Array.isArray(s)&&s.forEach((s=>{let t=this.removeReference(i,this._mdByName[s]);t&&i.unshift(t)})),i=i.slice(0,t)}doSearch(s){this.searchLoader&&"function"==typeof this.searchLoader&&(this._startLoading=!0,this.searchLoader(s).then((s=>{s&&this.processSearchResponse(s)})).finally((()=>{this._startLoading=!1})))}processSearchResponse(s){let i=(s=a.stringToObject(s.json.$)).descriptionField,t=s.pkField;t&&(this._gridMetadata=l(s),this._gridDataSource=[...s.data],this._pkField=t,this._descriptionField=i,this._itemList=this.buildCardItemList(s,t,i))}buildCardItemList(s,i,t){var e;return null===(e=s.data)||void 0===e?void 0:e.map((e=>{var a;let r=this.filterFieldsMetadata(s,e),o=this.buildFirstFields(e.__matchFields,r);return{key:this.highlightValue(e.__matchFields,null===(a=e[i])||void 0===a?void 0:a.toString(),o,!0),title:t?this.highlightValue(e.__matchFields,e[t],o,!0):"",details:this.buildDetails(o,e)}}))}filterFieldsMetadata(s,i){return s.fieldsMetadata.filter((t=>{let e=!r.isEmpty(i[t.fieldName])&&!1!==t.visible&&"B"!==t.type&&s.pkField!==t.fieldName&&s.descriptionField!==t.fieldName&&(t.isPrimaryKey||!t.isLinkField)&&!("S"===t.type&&"H"===t.presentationType);return e&&(this._mdByName[t.fieldName]=t),("string"!=typeof i[t.fieldName]||!(i[t.fieldName].indexOf("<img")>-1||i[t.fieldName].indexOf("<svg")>-1))&&e}))}removeAtIndex(s,i){if(i>=0&&i<s.length)return s.splice(i,1)[0]}removeReference(s,i){let t=this.indexOf(s,i);return this.removeAtIndex(s,t)}indexOf(s,i){let t=-1;return Array.isArray(s)&&this.find(s,((s,e)=>(t=e,this.equals(i,s)))),t}equals(s,i){return a.objectToString(s)===a.objectToString(i)}find(s,i){if(s)for(let t=0,e=s.length;t<e;t++)if(i(s[t],t,s))return s[t]}highlightValue(s,i,t,e){let a=this.replaceHtmlEntities(i);if(this.argument&&(e||this.isIn(s,t.fieldName))){const s=this.getArgumentNumber();let i=(isNaN(s)?this.argument:s.toString()).split(/%|,|\s+/),e=0,r=this.replaceAccentuatedChars(a);i.forEach((s=>{if(s){s=this.replaceAccentuatedChars(s);let i=this.getSpecialCharacters(s);null!=i&&i.length>0&&(s=this.removeSpecialCharacters(s)),(t.mask||"CGC_CPF"===t.uiType||"Phone"===t.uiType)&&(s=s.split("").join("\\.?\\-?\\/?\\(?\\)?"));let o=new RegExp(s,"ig");o.lastIndex=e;let n=o.exec(r);if(n&&n.length>0){e=n.index;let s=n[0].length,i=a.substring(e,e+s),t=(null==i?void 0:i.trim())?this._startHighlightTag+i+this._endHighlightTag:"",o=a.substring(0,e),l=a.substring(e+s);a=o+t+l,e+=t.length,r=this.replaceAccentuatedChars(a)}}}))}return a}replaceHtmlEntities(s){return null==s?s:String(s).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}replaceAccentuatedChars(s){return null==s?s:this.replaceToSpace(s,["&amp;","&lt;","&gt;","&quot;"]).replace(/[^\w ]/g,(s=>{let i=this._charsWithAccentuation.indexOf(s);return i>-1&&(s=this._charsWithoutAccentuation.charAt(i)),s||""}))}replaceToSpace(s,i=[]){return null==s||i.forEach((i=>{const t=new RegExp(i,"g");let e="";for(let s=0;s<i.length;s++)e+=" ";s=String(s).replace(t,e)})),s}isIn(s,i){return this.indexOf(s,i)>-1}getSpecialCharacters(s){let i,t=[];for(;i=this._specialCharsRegex.exec(s);)t.push(s[i.index]);return t}removeSpecialCharacters(s){return this.getSpecialCharacters(s).forEach((i=>{s=this.replaceAll(s,i,"")})),s}replaceAll(s,i,t){let e=(null!=s?s:"").indexOf(i);for(;e>-1;)e=(s=s.replace(i,t)).indexOf(i);return s}getArgumentNumber(){return Number(this.argument||void 0)}createOption(s){let{key:i,title:t}=s;const e=new RegExp(this._startHighlightTag,"g"),a=new RegExp(this._endHighlightTag,"g");t=r.decodeHtmlEntities(t);const o={value:null==i?void 0:i.replace(e,"").replace(a,""),label:null==t?void 0:t.replace(e,"").replace(a,"")};this.selectItem(o)}onChangeValue(s){var i;if(this.clearDeboucingTimeout(),this._startLoading)return void(this._changeDeboucingTimeout=setTimeout((()=>{this.onChangeValue(s)}),this._deboucingTime));if(this.argument=(s.detail||"").trim(),this.isHierarchyEntity&&"list"===this._presentationMode)return void(null===(i=this._pesquisaTree)||void 0===i||i.applyFilter());const t=this.getArgumentNumber();this.argument&&(!isNaN(t)||this.argument.length>=this._limitCharsToSearch)?this._changeDeboucingTimeout=setTimeout((()=>{this.doSearch(isNaN(t)?this.argument:t.toString()),this._valideDataSource=!0}),this._deboucingTime):(this._itemList=void 0,this._gridDataSource=[],this._valideDataSource=!1)}clearDeboucingTimeout(){this._changeDeboucingTimeout&&(clearTimeout(this._changeDeboucingTimeout),this._changeDeboucingTimeout=void 0)}onClickSearch(){this.doSearch((this.argument||"").trim()),this._valideDataSource=!0}getMessageView(){return this._startLoading?"Aguarde, buscando registros...":this._itemList?this._itemList.length>=1?`${this._itemList.length} ${this._itemList.length>1?"registros encontrados":"registro encontrado"}`:"Nenhum registro encontrado":"Os resultados de sua pesquisa aparecerão aqui..."}async componentWillLoad(){const s=await this.pesquisaFetcher.loadPresentationConfig(this.entityName);this._presentationMode="list"===s?"list":"table"}async componentDidLoad(){o.addIDInfo(this._element),await this.chooseViewMode()}async handleChangeViewMode(){this._presentationMode="list"===this._presentationMode?"table":"list",await this.chooseViewMode(),await this.pesquisaFetcher.savePresentationConfig(this.entityName,this._presentationMode)}async chooseViewMode(){var s,i;if("list"!==this._presentationMode)return await(null===(s=this._viewStack)||void 0===s?void 0:s.show(c.GRID)),void(this._currentView=c.GRID);const t=this.isHierarchyEntity?c.TREE:c.CARDS;await(null===(i=this._viewStack)||void 0===i?void 0:i.show(t)),this._currentView=t}hideLimitMessage(){return!this._itemList||this._itemList.length<100}hideRecordsMessage(){return"list"===this._presentationMode&&this.isHierarchyEntity}getButtonModeInfo(){return"list"===this._presentationMode?{iconName:"table",title:"Modo grade"}:this.isHierarchyEntity?{iconName:"hierarchical-tree",title:"Modo árvore hierárquica"}:{iconName:"list",title:"Modo lista"}}render(){var s,e;return i(t,null,i("div",{class:"snk-pesquisa"},i("div",{class:"snk-pesquisa__input"},i("ez-text-input",{label:"Buscar",class:"ez-margin-right--medium",canShowError:!1,ref:s=>this._textInput=s,onEzChange:s=>this.onChangeValue(s),value:this.argument,"data-element-id":"searchInput"},i("ez-icon",{slot:"leftIcon",iconName:"search"}),this.argument&&(null===(s=this._textInput)||void 0===s?void 0:s.value)?i("button",{slot:"rightIcon",class:"snk-pesquisa__btn",onClick:()=>this.clearSearch()},i("ez-icon",{iconName:"close"})):void 0),i("ez-button",{class:"ez-button--primary",label:"Pesquisar",onClick:()=>this.onClickSearch()}),i("ez-button",{class:"ez-margin-left--medium",mode:"icon",iconName:this.getButtonModeInfo().iconName,title:this.getButtonModeInfo().title,onClick:async()=>await this.handleChangeViewMode()})),i("div",{class:"snk-pesquisa__records-label "+(this._currentView===c.TREE?"hidden":"")},i("label",{class:"snk-pesquisa__records "+(this.hideRecordsMessage()?"hidden":"")},this.getMessageView()),i("label",{class:"snk-pesquisa__records-limit "+(this.hideLimitMessage()?"hidden":"")},"Essa pesquisa foi limitada, existem mais resultados.")),i("div",{class:"snk-pesquisa__content"},i("ez-view-stack",{ref:s=>this._viewStack=s,"data-element-id":"simple-crud"},i("stack-item",null,this._valideDataSource&&i("pesquisa-grid",{metadata:this._gridMetadata,dataSource:this._gridDataSource,pkField:this._pkField,descriptionField:this._descriptionField,entityName:this.entityName,shouldLoadConfig:this._currentView===c.GRID,onPesquisaGridSelectItem:({detail:s})=>this.selectItem(s)})),i("stack-item",null,i("div",{class:"snk-pesquisa__cards-container"},null===(e=this._itemList)||void 0===e?void 0:e.map((s=>i("ez-card-item",{onEzClick:s=>this.createOption(s.detail),item:s}))))),i("stack-item",null,i("pesquisa-tree",{ref:s=>this._pesquisaTree=s,argument:this.argument,treeLoader:this.treeLoader,allowsNonAnalytic:this.allowsNonAnalytic,shouldLoadTree:this._currentView===c.TREE,onPesquisaTreeSelectItem:({detail:s})=>this.selectItem(s)}))))))}get _element(){return e(this)}static get watchers(){return{argument:["observeArgument"]}}};h.style=".sc-snk-pesquisa-h{--snk-pesquisa--font-size:var(--text--medium, 14px);--snk-pesquisa--font-family:var(--font-pattern, Arial);--snk-pesquisa--font-weight:var(--text-weight--medium, 400);--snk-pesquisa__records--color:var(--text--primary, #626e82);--snk-pesquisa__records--color-secondary:var(--text--secondary, #626e82);--snk-pesquisa__records--padding-vertical:var(--space--medium, 12px);--snk-pesquisa__content--padding-right:var(--space--small, 6px);--snk-pesquisa__btn--color:var(--title--primary, #2B3A54);--snk-pesquisa__btn-disabled--color:var(--text--disable, #AFB6C0);--snk-pesquisa__btn-hover--color:var(--color--primary, #4e4e4e);--snk-pesquisa__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-pesquisa__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-pesquisa__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-pesquisa__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-pesquisa__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-pesquisa__scrollbar--width:var(--space--small, 6px);height:100%;display:flex;flex-direction:column;overflow-y:auto}.snk-pesquisa.sc-snk-pesquisa{display:flex;flex-direction:column;height:100%}.snk-pesquisa__input.sc-snk-pesquisa{display:flex;width:100%;box-sizing:border-box;padding-top:4px;padding-right:4px}.snk-pesquisa__input.sc-snk-pesquisa ez-icon.sc-snk-pesquisa{--ez-icon--color:inherit;font-weight:var(--text-weight--large, 600)}.snk-pesquisa__content.sc-snk-pesquisa{display:flex;flex-direction:column;overflow-y:hidden;scrollbar-width:thin;scrollbar-color:var(--snk-pesquisa__scrollbar--color-clicked) var(--snk-pesquisa__scrollbar--color-background);padding-right:var(--snk-pesquisa__content--padding-right);height:100vh}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar{background-color:var(--snk-pesquisa__scrollbar--color-background);width:var(--snk-pesquisa__scrollbar--width);max-width:var(--snk-pesquisa__scrollbar--width);min-width:var(--snk-pesquisa__scrollbar--width)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-track{background-color:var(--snk-pesquisa__scrollbar--color-background);border-radius:var(--snk-pesquisa__scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb{background-color:var(--snk-pesquisa__scrollbar--color-default);border-radius:var(--snk-pesquisa__scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:vertical:hover,.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--snk-pesquisa__scrollbar--color-hover)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:vertical:active,.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--snk-pesquisa__scrollbar--color-clicked)}.snk-pesquisa__records-label.sc-snk-pesquisa{display:flex;flex-direction:row;justify-content:space-between;font-family:var(--snk-pesquisa--font-family);font-weight:var(--snk-pesquisa--font-weight);font-size:var(--snk-pesquisa--font-size);padding-bottom:var(--snk-pesquisa__records--padding-vertical);padding-top:var(--snk-pesquisa__records--padding-vertical)}.snk-pesquisa__records-label.hidden.sc-snk-pesquisa{display:none}.snk-pesquisa__records.sc-snk-pesquisa{color:var(--snk-pesquisa__records--color)}.snk-pesquisa__records-limit.sc-snk-pesquisa{color:var(--snk-pesquisa__records--color-secondary)}.snk-pesquisa__records-limit.hidden.sc-snk-pesquisa,.snk-pesquisa__records.hidden.sc-snk-pesquisa{visibility:hidden}.snk-pesquisa__btn.sc-snk-pesquisa{outline:none;border:none;background:none;cursor:pointer;color:var(--snk-pesquisa__btn--color)}.snk-pesquisa__btn.sc-snk-pesquisa:disabled{cursor:unset;color:var(--snk-pesquisa__btn-disabled--color)}.snk-pesquisa__btn.sc-snk-pesquisa:disabled:hover{cursor:unset;color:var(--snk-pesquisa__btn-disabled--color)}.snk-pesquisa__btn.sc-snk-pesquisa:hover{color:var(--snk-pesquisa__btn-hover--color)}.snk-pesquisa__cards-container.sc-snk-pesquisa{height:100%;overflow-y:auto}";export{h as snk_pesquisa}
@@ -0,0 +1 @@
1
+ import{r as o,c as r,h as t,g as i}from"./p-d8d8169b.js";import{ApplicationContext as n}from"@sankhyalabs/core";import{V as a}from"./p-9019a32f.js";import{A as s}from"./p-dc36cfbf.js";const l=class{constructor(t){o(this,t),this.configSelected=r(this,"configSelected",7),this.openConfig=r(this,"openConfig",7),this.save=r(this,"save",7),this.cancel=r(this,"cancel",7),this._opened=!1,this._permissions=void 0,this.showActionButtons=!1,this.configName=void 0,this.resourceID=void 0,this.viewMode=a.GRID,this.customContainerId=void 0,this.layoutFormConfig=!1,this.messagesBuilder=void 0}async open(){this._opened=!0,this.configSelected.emit(this.getViewModeValue()),this.modal.heightMode="full"}async close(){this.closeConfig()}closeConfig(){this._opened=!1}onViewModeChanged(o){this.viewMode=null==o?void 0:o.detail,this.configSelected.emit(this.viewMode)}onClickOpenConfig(){this.openConfig.emit(this.viewMode)}isAllowed(o){return!s[o]||!!this._permissions&&(this._permissions.isSup||this._permissions[o])}enableModeConfig(){return!(!this.isAllowed(s.CONFIG_GRID)||!this.isAllowed(s.CONFIG))}getViewModeValue(){return null!=this._permissions&&(this.isAllowed(s.CONFIG_GRID)?this.isAllowed(s.CONFIG)||(this.viewMode=a.GRID):this.viewMode=a.FORM),this.viewMode}getMessage(o){var r;return null===(r=this.messagesBuilder)||void 0===r?void 0:r.getMessage(o,{})}handleSave(){this.layoutFormConfig&&this._snkLayoutFormConfig.save(),this.save.emit()}componentWillLoad(){this._application=n.getContextValue("__SNK__APPLICATION__"),this._application?this._application.getAllAccess(this.resourceID).then((o=>this._permissions=o)):this._permissions={}}componentDidRender(){if(!this.customContainerId)return;const o=document.querySelector(`#${this.customContainerId}`),r=null==o?void 0:o.querySelector("#SnkConfigContainerSlot");if(!r)return;const t=r.firstElementChild;if(!t)return;const i=this._element.querySelector("#slotContainer");null==i||i.appendChild(t)}render(){return t("ez-modal",{ref:o=>this.modal=o,opened:this._opened,"close-esc":!1,"close-outside-click":!1,"modal-size":"small",scrim:"light",onEzCloseModal:()=>this.closeConfig()},t("div",{class:"snk-configurator"},t("div",{class:"snk-configurator__header"},t("label",{class:"snk-configurator__title"},this.getMessage("snkConfigurator.titleConfigurations")),t("div",{class:"snk-configurator__button-close"},t("ez-button",{mode:"icon",iconName:"close",size:"medium",onClick:()=>this.closeConfig()}))),t("div",{class:"snk-configurator__main"},t("ez-collapsible-box",{boxBordered:!0,label:"Modo de visualização ",headerSize:"medium",class:"snk-configurator__collapsable-box"},t("ez-radio-button",{value:this.getViewModeValue().toString(),onEzChange:o=>this.onViewModeChanged(o),enabled:this.enableModeConfig()},t("ez-radio-button-option",{label:this.getMessage("snkConfigurator.labelGrid"),value:a.GRID}),t("ez-radio-button-option",{label:this.getMessage("snkConfigurator.labelForm"),value:a.FORM})),t("div",{class:"snk-configurator__collsable-box-action"},t("ez-button",{label:this.getMessage(this.viewMode===a.GRID?"snkConfigurator.labelConfigGrid":"snkConfigurator.labelConfigForm"),class:"snk-configurator__button-config ez-button--secondary",onClick:()=>this.onClickOpenConfig(),id:"openConfigurator"}))),this.layoutFormConfig&&t("ez-collapsible-box",{boxBordered:!0,value:!0,label:"Layout do formulário",headerSize:"medium",class:"snk-configurator__collapsable-box ez-margin-top--medium"},t("div",{class:"ez-flex ez-flex--column ez-size-width--full"},t("snk-layout-form-config",{ref:o=>this._snkLayoutFormConfig=o}))),t("div",{id:"slotContainer",class:"snk-configurator__outline"})),this.showActionButtons&&t("div",{class:"snk-configurator__action-buttons"},t("ez-button",{label:"Cancelar",onClick:()=>this.cancel.emit()}),t("ez-button",{label:"Salvar",onClick:()=>this.handleSave(),class:"ez-button--primary"}))))}get _element(){return i(this)}};l.style='.sc-snk-configurator-h{--snk-configurator__button-close--padding-left:var(--space--medium, 12px);--snk-configurator__title--color:var(--title--primary, #2B3A54);--snk-configurator__title--font-family:var(--font-pattern, "Roboto");--snk-configurator__title--font-size:var(--title--large, 20px);--snk-configurator__title--font-weight:var(--text-weight--extra-large, 700);--snk-configurator__subtitle--color:var(--title--primary, #2B3A54);--snk-configurator__subtitle--font-family:var(--font-pattern, "Roboto");--snk-configurator__subtitle--font-size:var(--text--medium, 14px);--snk-configurator__subtitle--font-weight:var(--text-weight--large, 600);--snk-configurator__scrollbar--color-default:var(--scrollbar--default, #626e82);--snk-configurator__scrollbar--color-background:var(--scrollbar--background, #E5EAF0);--snk-configurator__scrollbar--color-hover:var(--scrollbar--hover, #2B3A54);--snk-configurator__scrollbar--color-clicked:var(--scrollbar--clicked, #a2abb9);--snk-configurator__scrollbar--border-radius:var(--border--radius-small, 6px);--snk-configurator__scrollbar--width:var(--space--small, 6px)}.snk-configurator.sc-snk-configurator{display:grid;grid-template-rows:auto 1fr auto;max-height:100%;width:100%}.snk-configurator__collsable-box-action.sc-snk-configurator{width:100%}.snk-configurator__action-buttons.sc-snk-configurator{display:flex;flex-direction:row;justify-content:flex-end;gap:var(--space--medium)}.snk-configurator__outline.sc-snk-configurator{display:flex;flex-direction:column;gap:var(--space--small);margin-top:var(--space--small);margin-bottom:var(--space--large)}@media screen and (min-width: 480px){.snk-configurator.sc-snk-configurator{width:359px;max-width:359px}}.snk-configurator__button-config.sc-snk-configurator{--ez-button--min-width:100%}.snk-configurator__header.sc-snk-configurator{display:flex;justify-content:space-between;align-items:center;width:100%}.snk-configurator__title.sc-snk-configurator{display:flex;margin:0;line-height:normal;letter-spacing:0em;text-align:left;color:var(--snk-configurator__title--color);font-size:var(--snk-configurator__title--font-size);font-family:var(--snk-configurator__title--font-family);font-weight:var(--snk-configurator__title--font-weight)}.snk-configurator__subtitle.sc-snk-configurator{display:flex;margin:0;padding-top:var(--space--medium);padding-bottom:var(--space--small);color:var(--snk-configurator__subtitle--color);font-size:var(--snk-configurator__subtitle--font-size);font-family:var(--snk-configurator__subtitle--font-family);font-weight:var(--snk-configurator__subtitle--font-weight)}.snk-configurator__button-close.sc-snk-configurator{padding-left:var(--snk-configurator__button-close--padding-left)}.snk-configurator__main.sc-snk-configurator{overflow-y:auto;scrollbar-width:thin;margin:var(--space--medium) 0;scrollbar-color:var(--snk-configurator__scrollbar--color-clicked) var(--snk-configurator__scrollbar--color-background)}.snk-configurator__main.sc-snk-configurator::-webkit-scrollbar{background-color:var(--snk-configurator__scrollbar--color-background);width:var(--snk-configurator__scrollbar--width);max-width:var(--snk-configurator__scrollbar--width);min-width:var(--snk-configurator__scrollbar--width)}.snk-configurator__main.sc-snk-configurator::-webkit-scrollbar-track{background-color:var(--snk-configurator__scrollbar--color-background);border-radius:var(--snk-configurator__scrollbar--border-radius)}.snk-configurator__main.sc-snk-configurator::-webkit-scrollbar-thumb{background-color:var(--snk-configurator__scrollbar--color-default);border-radius:var(--snk-configurator__scrollbar--border-radius)}.snk-configurator__main.sc-snk-configurator::-webkit-scrollbar-thumb:vertical:hover,.snk-configurator__main.sc-snk-configurator::-webkit-scrollbar-thumb:horizontal:hover{background-color:var(--snk-configurator__scrollbar--color-hover)}.snk-configurator__main.sc-snk-configurator::-webkit-scrollbar-thumb:vertical:active,.snk-configurator__main.sc-snk-configurator::-webkit-scrollbar-thumb:horizontal:active{background-color:var(--snk-configurator__scrollbar--color-clicked)}';export{l as snk_configurator}
@@ -1 +1 @@
1
- import{r as i,c as t,h as e,F as s,H as n}from"./p-d8d8169b.js";import{StringUtils as l,ObjectUtils as a,ApplicationContext as r,ElementIDUtils as o}from"@sankhyalabs/core";import{P as h}from"./p-988afe78.js";import{P as d,C as c}from"./p-6416975c.js";import{ApplicationUtils as f}from"@sankhyalabs/ezui/dist/collection/utils";import{a as p,D as z}from"./p-84345e7a.js";import{s as u}from"./p-a349689a.js";import"./p-ff1990ad.js";import"./p-601b252b.js";import"./p-fbba7e3d.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const m=class{constructor(e){i(this,e),this.ezCancel=t(this,"ezCancel",7),this.ezSave=t(this,"ezSave",7),this.ezAfterSave=t(this,"ezAfterSave",7),this._personalizedFilterFetcher=new d,this._filterMetadataStorage=new Map,this._dataSourceFetcher={fetchData:async i=>{let t=null==i?void 0:i.uri;if(l.isEmpty(t)&&(t=this.entityUri),!this._filterMetadataStorage.has(t)){const i=await this._personalizedFilterFetcher.loadFields(t);this._filterMetadataStorage.set(t,i)}return this._filterMetadataStorage.get(t)}},this._filterAssistentMode=!0,this._filterAssistent=void 0,this.messagesBuilder=void 0,this.entityUri=void 0,this.filterId=void 0,this.configName=void 0,this.resourceID=void 0,this.isDefaultFilter=!1}async createPersonalizedFilter(){const i={name:"",active:!0,expression:"",parameters:[],assistent:{id:l.generateUUID(),items:[{id:l.generateUUID(),entityName:"",fieldName:"",description:"",fieldLabel:"Valor",type:void 0,expression:void 0,operand:void 0,paramVariable:!1,value:void 0,systemConfig:null,userConfig:null}],childrenGroups:[],operand:p.AND}};this.isDefaultFilter&&this.buildDataDefaultFilter(i),this._originalFilterAssistent=a.copy(i),this._filterAssistent=a.copy(i)}loadFilter(i,t){null!=i&&t!=i&&null!=this.resourceID&&(i!==z.id?c.loadPersonalizedFilter(i,this.resourceID,this.configName).then((i=>{const t=this.applyDefaultValues(i);this._filterAssistent=t,this._originalFilterAssistent=a.copy(t),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})):c.loadDefaultFilter(i,this.resourceID,this.configName).then((i=>{const t=this.applyDefaultValues(i);this._filterAssistent=t,this._originalFilterAssistent=a.copy(t),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})))}componentWillLoad(){var i;null==u.get(`filterFieldsDataSource.${this.entityUri}`)&&u.set(`filterFieldsDataSource.${this.entityUri}`,this._dataSourceFetcher),this.messagesBuilder||(this._application=r.getContextValue("__SNK__APPLICATION__"),this.messagesBuilder=null===(i=this._application)||void 0===i?void 0:i.messagesBuilder),this.loadFilter(this.filterId,void 0)}componentDidRender(){var i;null===(i=this._viewStackRef)||void 0===i||i.show(this._filterAssistentMode?0:1),this._elButtonMode&&this._elButtonMode.setAttribute(o.DATA_ELEMENT_ID_ATTRIBUTE_NAME,o.getInternalIDInfo(this._filterAssistentMode?"advancedMode_ezButton":"assistentMode_ezButton"))}buildDataDefaultFilter(i){i.name=z.name,i.id=z.id}getMessage(i,t){return this._application.messagesBuilder.getMessage(i,t)}async saveFilter(){let i;i=this.isDefaultFilter?await c.saveDefaultFilter(this._filterAssistent,this.resourceID,this.configName):await c.savePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName),this._elButtonSave.enabled=!1,f.info(this.getMessage(`snkPersonalizedFilter.${this._filterAssistent.id?"confirmEdit":"confirmSave"}.title`),{iconName:"check"});const t=Object.assign(Object.assign({},i),this._filterAssistent);t.parameters=h.buildVariableParameters(this._filterAssistent.assistent),this._originalFilterAssistent=a.copy(t),this._filterAssistent=a.copy(t),this.ezAfterSave.emit()}removeFilter(){c.removePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName)}hasChangesToSave(){return JSON.stringify(this._filterAssistent)===JSON.stringify(this._originalFilterAssistent)}async handleSave(){if(this._filterAssistentMode){if(!h.validateFields(this._filterAssistent.assistent)||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));this.saveAssistentMode()}else{if(!this._filterAssistent.expression||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));if(!await this.validateExpressionBeforeSaving())return;this.saveAdvancedMode()}}saveAssistentMode(){const{assistent:i,expression:t}=this._filterAssistent,e=i?h.buildGroupExpression(i):t;this._filterAssistent.expression=e,this.ezSave.emit(e),this.saveFilter()}saveAdvancedMode(){this._originalFilterAssistent.expression!==this._filterAssistent.expression&&this._filterAssistent.assistent?f.confirm(this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.description")).then((i=>{i&&this.saveAndTransformToAdvancedMode()})):this._filterAssistent.assistent?this.saveAssistentMode():this.saveAndTransformToAdvancedMode()}saveAndTransformToAdvancedMode(){this._filterAssistent.assistent=void 0,this.ezSave.emit(this._filterAssistent.expression),this.saveFilter()}async validateExpressionBeforeSaving(){const{valid:i,message:t=""}=await this._personalizedFilterFetcher.validatePersonalizedFilter(this.entityUri,this._filterAssistent.expression);return i||this._application.error(this.getMessage("snkPersonalizedFilter.errorValidation.title"),t.replace(/.*Exception: /,"")),i}handleCancel(){if(this.hasChangesToSave())return this.ezCancel.emit();f.confirm(this.getMessage("snkPersonalizedFilter.confirmCancel.title"),this.getMessage("snkPersonalizedFilter.confirmCancel.description")).then((i=>{var t;i&&(this._filterAssistent=a.copy(null!==(t=this._originalFilterAssistent)&&void 0!==t?t:{}),this.ezCancel.emit(),this._elButtonSave.enabled=!1)}))}handleTitleChange(i){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{name:i}),this._elButtonSave.enabled=!this.hasChangesToSave()}applyDefaultValues(i){return this.addLabelToItems(i),this.addFilterGroupCondition(i),i}addFilterGroupCondition(i){i.assistent&&!i.assistent.operand&&(i.assistent.operand=p.AND)}addLabelToItems(i){i.assistent&&i.assistent.items&&i.assistent.items.length>0&&i.assistent.items.forEach((t=>{if(null==t.fieldLabel){const e=(i.parameters||[]).find((i=>i.fieldName===t.fieldName));e&&(t.fieldLabel=e.label)}}))}handleExpressionChangeAdvancedMode(i){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:i}),this._elButtonSave.enabled=!this.hasChangesToSave()}handleChangeFilterAssistentMode(i){this._elButtonSave.enabled=!this.hasChangesToSave(),this._filterAssistent=Object.assign({},i)}selectField(i){if(!("name"in i))return;const t=this.buildExpression(i.entityName,i.name,i.entityPath);this._elAdvancedMode.querySelector("ez-text-area").appendTextToSelection(t)}buildExpression(i,t,e){return e.length>0&&e.shift(),e.length>0?`${e.join("->")}->${t}`:`${i}.${t}`}onAddField(i){this._elAdvancedMode.querySelector("ez-text-area").setFocus(),i.setBlur(),this._elFilterFieldSearch&&this._elFilterFieldSearch.show(i,{horizontalGap:0,verticalGap:12,fromRight:!0})}renderButtonAddField(){if(!this._filterAssistentMode)return e(s,null,e("ez-button",{class:"snk-personalized-filter__button-mode",label:this.getMessage("snkPersonalizedFilter.info.addField"),enabled:!0,onClick:i=>this.onAddField(i.target)},e("ez-icon",{class:"ez-padding-right--small",slot:"leftIcon",iconName:"plus"})),e("snk-filter-field-search",{class:"ez-padding-left--medium",ref:i=>this._elFilterFieldSearch=i,onEzSelectFilterItem:i=>this.selectField(i.detail),fieldsDataSource:this._dataSourceFetcher}))}buildContainerPersonalizedFilter(){return e("ez-view-stack",{ref:i=>this._viewStackRef=i},e("stack-item",null,this._filterAssistentMode&&e("snk-filter-assistent-mode",{filterAssistent:this._filterAssistent,messagesBuilder:this.messagesBuilder,filterId:this.filterId,entityUri:this.entityUri,application:this._application,onEzChangeFilter:i=>this.handleChangeFilterAssistentMode(i.detail),isDefaultFilter:this.isDefaultFilter})),e("stack-item",null,e("snk-filter-advanced-mode",{ref:i=>this._elAdvancedMode=i,filterAssistent:this._filterAssistent,application:this._application,onEzExpressionChange:i=>this.handleExpressionChangeAdvancedMode(i.detail)})))}handleModeChange(){var i,t;if(this._filterAssistentMode)f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.description")).then((i=>{if(i&&(this._filterAssistentMode=!this._filterAssistentMode,!this.hasChangesToSave())){const i=h.buildGroupExpression(this._filterAssistent.assistent);this._filterAssistent.expression=i,this._elButtonSave.enabled=!this.hasChangesToSave()}}));else if((null===(i=this._filterAssistent)||void 0===i?void 0:i.expression)===(null===(t=this._originalFilterAssistent)||void 0===t?void 0:t.expression))this._filterAssistentMode=!this._filterAssistentMode;else{const i=this._filterAssistent.expression,t=h.buildGroupExpression(this._filterAssistent.assistent);i!==t?f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.description")).then((i=>{i&&(this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:t}),this._filterAssistentMode=!this._filterAssistentMode)})):this._filterAssistentMode=!this._filterAssistentMode}}buildTitle(){return this.getMessage(this.isDefaultFilter&&!this.filterId?"snkPersonalizedFilter.info.titleCreateDefault":this.isDefaultFilter&&this.filterId?"snkPersonalizedFilter.info.titleEditDefault":this.filterId?"snkPersonalizedFilter.info.titleEdit":"snkPersonalizedFilter.info.titleAdd")}render(){var i,t,s,l;if((null===(i=this._filterAssistent)||void 0===i?void 0:i.assistent)||!this._filterAssistentMode)return e(n,null,e("div",{class:"snk-personalized-filter"},e("div",null,e("snk-simple-bar",{label:this.buildTitle(),onExit:()=>this.handleCancel()},e("div",{class:"snk-personalized-filter__header-actions",slot:"rightSlot"},e("ez-button",{size:"small",label:this.getMessage("snkPersonalizedFilter.info.labelCancel"),onClick:()=>this.handleCancel()}),e("ez-button",{size:"small",ref:i=>this._elButtonSave=i,enabled:!1,class:"ez-button--primary",label:this.getMessage("snkPersonalizedFilter.info.labelSave"),onClick:this.handleSave.bind(this)})))),e("div",{class:"ez-box ez-margin-bottom--medium ez-box__main"},e("div",{class:"ez-box__container"},e("div",{class:"ez-flex ez-flex--column ez-size-width--full"},e("div",{class:"ez-flex"},e("ez-tooltip",{message:this.getMessage("snkPersonalizedFilter.info.textInputDisabled"),active:this.isDefaultFilter},e("ez-text-input",{class:"ez-padding-right--medium",label:this.getMessage("snkPersonalizedFilter.info.labelNameFilter"),value:null===(t=this._filterAssistent)||void 0===t?void 0:t.name,onEzChange:i=>this.handleTitleChange(i.detail),enabled:!this.isDefaultFilter})),this.renderButtonAddField(),e("ez-button",{ref:i=>this._elButtonMode=i,class:"snk-personalized-filter__button-mode",label:this.getMessage(this._filterAssistentMode?"snkPersonalizedFilter.info.activeModeAdvanced":"snkPersonalizedFilter.info.activeModeAssistent"),onClick:()=>this.handleModeChange(),"data-tooltip":this._filterAssistentMode||(null===(s=this._filterAssistent)||void 0===s?void 0:s.assistent)?void 0:this.getMessage("snkPersonalizedFilter.info.tooltipDisabledAssistentMode"),"data-flow":"bottom",enabled:!this._filterAssistent.name||Boolean(this._filterAssistentMode||(null===(l=this._filterAssistent)||void 0===l?void 0:l.assistent))})),this.buildContainerPersonalizedFilter())))))}static get watchers(){return{filterId:["loadFilter"]}}};m.style=".sc-snk-personalized-filter-h{display:flex;height:100%;padding:var(--space--large, 24px);--snk-personalized-filter--width:100%;--snk-personalized-filter--height:100%;--snk-personalized-filter--background-color-line:var(--color--disable-secondary);--snk-personalized-filter--margin-line:var(--border--radius-medium, 12px)}.snk-personalized-filter.sc-snk-personalized-filter{height:var(--snk-personalized-filter--width);width:var(--snk-personalized-filter--height)}.snk-personalized-filter__header-actions.sc-snk-personalized-filter{display:flex;gap:var(--space--medium)}.snk-personalized-filter__group.sc-snk-personalized-filter{flex:1}.snk-personalized-filter__expression-input--line.sc-snk-personalized-filter{width:100%;height:2px;background-color:var(--snk-personalized-filter--background-color-line);margin-top:var(--snk-personalized-filter--margin-line);margin-bottom:var(--snk-personalized-filter--margin-line)}.ez-box__main.sc-snk-personalized-filter{height:90%}.snk-personalized-filter__button-mode.sc-snk-personalized-filter{height:35px}";export{m as snk_personalized_filter}
1
+ import{r as i,c as t,h as e,F as s,H as n}from"./p-d8d8169b.js";import{StringUtils as l,ObjectUtils as a,ApplicationContext as r,ElementIDUtils as o}from"@sankhyalabs/core";import{P as h}from"./p-988afe78.js";import{P as d,C as c}from"./p-8758404f.js";import{ApplicationUtils as f}from"@sankhyalabs/ezui/dist/collection/utils";import{a as p,D as z}from"./p-84345e7a.js";import{s as u}from"./p-a349689a.js";import"./p-ff1990ad.js";import"./p-b21d32f6.js";import"./p-cd1a5b6a.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const m=class{constructor(e){i(this,e),this.ezCancel=t(this,"ezCancel",7),this.ezSave=t(this,"ezSave",7),this.ezAfterSave=t(this,"ezAfterSave",7),this._personalizedFilterFetcher=new d,this._filterMetadataStorage=new Map,this._dataSourceFetcher={fetchData:async i=>{let t=null==i?void 0:i.uri;if(l.isEmpty(t)&&(t=this.entityUri),!this._filterMetadataStorage.has(t)){const i=await this._personalizedFilterFetcher.loadFields(t);this._filterMetadataStorage.set(t,i)}return this._filterMetadataStorage.get(t)}},this._filterAssistentMode=!0,this._filterAssistent=void 0,this.messagesBuilder=void 0,this.entityUri=void 0,this.filterId=void 0,this.configName=void 0,this.resourceID=void 0,this.isDefaultFilter=!1}async createPersonalizedFilter(){const i={name:"",active:!0,expression:"",parameters:[],assistent:{id:l.generateUUID(),items:[{id:l.generateUUID(),entityName:"",fieldName:"",description:"",fieldLabel:"Valor",type:void 0,expression:void 0,operand:void 0,paramVariable:!1,value:void 0,systemConfig:null,userConfig:null}],childrenGroups:[],operand:p.AND}};this.isDefaultFilter&&this.buildDataDefaultFilter(i),this._originalFilterAssistent=a.copy(i),this._filterAssistent=a.copy(i)}loadFilter(i,t){null!=i&&t!=i&&null!=this.resourceID&&(i!==z.id?c.loadPersonalizedFilter(i,this.resourceID,this.configName).then((i=>{const t=this.applyDefaultValues(i);this._filterAssistent=t,this._originalFilterAssistent=a.copy(t),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})):c.loadDefaultFilter(i,this.resourceID,this.configName).then((i=>{const t=this.applyDefaultValues(i);this._filterAssistent=t,this._originalFilterAssistent=a.copy(t),this._filterAssistentMode=this._filterAssistent.hasOwnProperty("assistent")&&null!=this._filterAssistent.assistent})))}componentWillLoad(){var i;null==u.get(`filterFieldsDataSource.${this.entityUri}`)&&u.set(`filterFieldsDataSource.${this.entityUri}`,this._dataSourceFetcher),this.messagesBuilder||(this._application=r.getContextValue("__SNK__APPLICATION__"),this.messagesBuilder=null===(i=this._application)||void 0===i?void 0:i.messagesBuilder),this.loadFilter(this.filterId,void 0)}componentDidRender(){var i;null===(i=this._viewStackRef)||void 0===i||i.show(this._filterAssistentMode?0:1),this._elButtonMode&&this._elButtonMode.setAttribute(o.DATA_ELEMENT_ID_ATTRIBUTE_NAME,o.getInternalIDInfo(this._filterAssistentMode?"advancedMode_ezButton":"assistentMode_ezButton"))}buildDataDefaultFilter(i){i.name=z.name,i.id=z.id}getMessage(i,t){return this._application.messagesBuilder.getMessage(i,t)}async saveFilter(){let i;i=this.isDefaultFilter?await c.saveDefaultFilter(this._filterAssistent,this.resourceID,this.configName):await c.savePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName),this._elButtonSave.enabled=!1,f.info(this.getMessage(`snkPersonalizedFilter.${this._filterAssistent.id?"confirmEdit":"confirmSave"}.title`),{iconName:"check"});const t=Object.assign(Object.assign({},i),this._filterAssistent);t.parameters=h.buildVariableParameters(this._filterAssistent.assistent),this._originalFilterAssistent=a.copy(t),this._filterAssistent=a.copy(t),this.ezAfterSave.emit()}removeFilter(){c.removePersonalizedFilter(this._filterAssistent,this.resourceID,this.configName)}hasChangesToSave(){return JSON.stringify(this._filterAssistent)===JSON.stringify(this._originalFilterAssistent)}async handleSave(){if(this._filterAssistentMode){if(!h.validateFields(this._filterAssistent.assistent)||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));this.saveAssistentMode()}else{if(!this._filterAssistent.expression||!this._filterAssistent.name)return this._application.error(this.getMessage("snkPersonalizedFilter.error.title"),this.getMessage("snkPersonalizedFilter.error.description"));if(!await this.validateExpressionBeforeSaving())return;this.saveAdvancedMode()}}saveAssistentMode(){const{assistent:i,expression:t}=this._filterAssistent,e=i?h.buildGroupExpression(i):t;this._filterAssistent.expression=e,this.ezSave.emit(e),this.saveFilter()}saveAdvancedMode(){this._originalFilterAssistent.expression!==this._filterAssistent.expression&&this._filterAssistent.assistent?f.confirm(this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmSaveModeAdvanced.description")).then((i=>{i&&this.saveAndTransformToAdvancedMode()})):this._filterAssistent.assistent?this.saveAssistentMode():this.saveAndTransformToAdvancedMode()}saveAndTransformToAdvancedMode(){this._filterAssistent.assistent=void 0,this.ezSave.emit(this._filterAssistent.expression),this.saveFilter()}async validateExpressionBeforeSaving(){const{valid:i,message:t=""}=await this._personalizedFilterFetcher.validatePersonalizedFilter(this.entityUri,this._filterAssistent.expression);return i||this._application.error(this.getMessage("snkPersonalizedFilter.errorValidation.title"),t.replace(/.*Exception: /,"")),i}handleCancel(){if(this.hasChangesToSave())return this.ezCancel.emit();f.confirm(this.getMessage("snkPersonalizedFilter.confirmCancel.title"),this.getMessage("snkPersonalizedFilter.confirmCancel.description")).then((i=>{var t;i&&(this._filterAssistent=a.copy(null!==(t=this._originalFilterAssistent)&&void 0!==t?t:{}),this.ezCancel.emit(),this._elButtonSave.enabled=!1)}))}handleTitleChange(i){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{name:i}),this._elButtonSave.enabled=!this.hasChangesToSave()}applyDefaultValues(i){return this.addLabelToItems(i),this.addFilterGroupCondition(i),i}addFilterGroupCondition(i){i.assistent&&!i.assistent.operand&&(i.assistent.operand=p.AND)}addLabelToItems(i){i.assistent&&i.assistent.items&&i.assistent.items.length>0&&i.assistent.items.forEach((t=>{if(null==t.fieldLabel){const e=(i.parameters||[]).find((i=>i.fieldName===t.fieldName));e&&(t.fieldLabel=e.label)}}))}handleExpressionChangeAdvancedMode(i){this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:i}),this._elButtonSave.enabled=!this.hasChangesToSave()}handleChangeFilterAssistentMode(i){this._elButtonSave.enabled=!this.hasChangesToSave(),this._filterAssistent=Object.assign({},i)}selectField(i){if(!("name"in i))return;const t=this.buildExpression(i.entityName,i.name,i.entityPath);this._elAdvancedMode.querySelector("ez-text-area").appendTextToSelection(t)}buildExpression(i,t,e){return e.length>0&&e.shift(),e.length>0?`${e.join("->")}->${t}`:`${i}.${t}`}onAddField(i){this._elAdvancedMode.querySelector("ez-text-area").setFocus(),i.setBlur(),this._elFilterFieldSearch&&this._elFilterFieldSearch.show(i,{horizontalGap:0,verticalGap:12,fromRight:!0})}renderButtonAddField(){if(!this._filterAssistentMode)return e(s,null,e("ez-button",{class:"snk-personalized-filter__button-mode",label:this.getMessage("snkPersonalizedFilter.info.addField"),enabled:!0,onClick:i=>this.onAddField(i.target)},e("ez-icon",{class:"ez-padding-right--small",slot:"leftIcon",iconName:"plus"})),e("snk-filter-field-search",{class:"ez-padding-left--medium",ref:i=>this._elFilterFieldSearch=i,onEzSelectFilterItem:i=>this.selectField(i.detail),fieldsDataSource:this._dataSourceFetcher}))}buildContainerPersonalizedFilter(){return e("ez-view-stack",{ref:i=>this._viewStackRef=i},e("stack-item",null,this._filterAssistentMode&&e("snk-filter-assistent-mode",{filterAssistent:this._filterAssistent,messagesBuilder:this.messagesBuilder,filterId:this.filterId,entityUri:this.entityUri,application:this._application,onEzChangeFilter:i=>this.handleChangeFilterAssistentMode(i.detail),isDefaultFilter:this.isDefaultFilter})),e("stack-item",null,e("snk-filter-advanced-mode",{ref:i=>this._elAdvancedMode=i,filterAssistent:this._filterAssistent,application:this._application,onEzExpressionChange:i=>this.handleExpressionChangeAdvancedMode(i.detail)})))}handleModeChange(){var i,t;if(this._filterAssistentMode)f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAssistent.description")).then((i=>{if(i&&(this._filterAssistentMode=!this._filterAssistentMode,!this.hasChangesToSave())){const i=h.buildGroupExpression(this._filterAssistent.assistent);this._filterAssistent.expression=i,this._elButtonSave.enabled=!this.hasChangesToSave()}}));else if((null===(i=this._filterAssistent)||void 0===i?void 0:i.expression)===(null===(t=this._originalFilterAssistent)||void 0===t?void 0:t.expression))this._filterAssistentMode=!this._filterAssistentMode;else{const i=this._filterAssistent.expression,t=h.buildGroupExpression(this._filterAssistent.assistent);i!==t?f.confirm(this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.title"),this.getMessage("snkPersonalizedFilter.confirmChangeModeAdvanced.description")).then((i=>{i&&(this._filterAssistent=Object.assign(Object.assign({},this._filterAssistent),{expression:t}),this._filterAssistentMode=!this._filterAssistentMode)})):this._filterAssistentMode=!this._filterAssistentMode}}buildTitle(){return this.getMessage(this.isDefaultFilter&&!this.filterId?"snkPersonalizedFilter.info.titleCreateDefault":this.isDefaultFilter&&this.filterId?"snkPersonalizedFilter.info.titleEditDefault":this.filterId?"snkPersonalizedFilter.info.titleEdit":"snkPersonalizedFilter.info.titleAdd")}render(){var i,t,s,l;if((null===(i=this._filterAssistent)||void 0===i?void 0:i.assistent)||!this._filterAssistentMode)return e(n,null,e("div",{class:"snk-personalized-filter"},e("div",null,e("snk-simple-bar",{label:this.buildTitle(),onExit:()=>this.handleCancel()},e("div",{class:"snk-personalized-filter__header-actions",slot:"rightSlot"},e("ez-button",{size:"small",label:this.getMessage("snkPersonalizedFilter.info.labelCancel"),onClick:()=>this.handleCancel()}),e("ez-button",{size:"small",ref:i=>this._elButtonSave=i,enabled:!1,class:"ez-button--primary",label:this.getMessage("snkPersonalizedFilter.info.labelSave"),onClick:this.handleSave.bind(this)})))),e("div",{class:"ez-box ez-margin-bottom--medium ez-box__main"},e("div",{class:"ez-box__container"},e("div",{class:"ez-flex ez-flex--column ez-size-width--full"},e("div",{class:"ez-flex"},e("ez-tooltip",{message:this.getMessage("snkPersonalizedFilter.info.textInputDisabled"),active:this.isDefaultFilter},e("ez-text-input",{class:"ez-padding-right--medium",label:this.getMessage("snkPersonalizedFilter.info.labelNameFilter"),value:null===(t=this._filterAssistent)||void 0===t?void 0:t.name,onEzChange:i=>this.handleTitleChange(i.detail),enabled:!this.isDefaultFilter})),this.renderButtonAddField(),e("ez-button",{ref:i=>this._elButtonMode=i,class:"snk-personalized-filter__button-mode",label:this.getMessage(this._filterAssistentMode?"snkPersonalizedFilter.info.activeModeAdvanced":"snkPersonalizedFilter.info.activeModeAssistent"),onClick:()=>this.handleModeChange(),"data-tooltip":this._filterAssistentMode||(null===(s=this._filterAssistent)||void 0===s?void 0:s.assistent)?void 0:this.getMessage("snkPersonalizedFilter.info.tooltipDisabledAssistentMode"),"data-flow":"bottom",enabled:!this._filterAssistent.name||Boolean(this._filterAssistentMode||(null===(l=this._filterAssistent)||void 0===l?void 0:l.assistent))})),this.buildContainerPersonalizedFilter())))))}static get watchers(){return{filterId:["loadFilter"]}}};m.style=".sc-snk-personalized-filter-h{display:flex;height:100%;padding:var(--space--large, 24px);--snk-personalized-filter--width:100%;--snk-personalized-filter--height:100%;--snk-personalized-filter--background-color-line:var(--color--disable-secondary);--snk-personalized-filter--margin-line:var(--border--radius-medium, 12px)}.snk-personalized-filter.sc-snk-personalized-filter{height:var(--snk-personalized-filter--width);width:var(--snk-personalized-filter--height)}.snk-personalized-filter__header-actions.sc-snk-personalized-filter{display:flex;gap:var(--space--medium)}.snk-personalized-filter__group.sc-snk-personalized-filter{flex:1}.snk-personalized-filter__expression-input--line.sc-snk-personalized-filter{width:100%;height:2px;background-color:var(--snk-personalized-filter--background-color-line);margin-top:var(--snk-personalized-filter--margin-line);margin-bottom:var(--snk-personalized-filter--margin-line)}.ez-box__main.sc-snk-personalized-filter{height:90%}.snk-personalized-filter__button-mode.sc-snk-personalized-filter{height:35px}";export{m as snk_personalized_filter}
@@ -1 +1 @@
1
- import{r as t,c as i,h as e}from"./p-d8d8169b.js";import{ApplicationContext as a,DataType as s,Action as n,UserInterface as o,StringUtils as r,DataUnitLoaderUtils as l,DataUnit as d}from"@sankhyalabs/core";import{D as h}from"./p-fbba7e3d.js";import{S as c}from"./p-6dd38d7b.js";import"./p-0f3698af.js";import{P as v,D as u,I as m}from"./p-8f8367d5.js";import"./p-ff1990ad.js";import"./p-601b252b.js";import{V as A}from"./p-9019a32f.js";import{A as O}from"./p-73285a8a.js";import{T as p}from"./p-7de79adf.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-a349689a.js";class w{constructor(t){this.dataUnitName=t}async save({dataUnit:t,record:i,updatingFields:e,operation:a}){var s,n;const o="INSERT"==a,r=o?e:i;if(!o&&(null==e?void 0:e.DESCRICAO)&&(null==e?void 0:e.DESCRICAO)!==(null==i?void 0:i.DESCRICAO))throw new Error(c.DESCRIPTION_CANNOT_BE_CHANGED);const l={anexo:{codata:o?null==e?void 0:e.REGISTER_KEY:null==i?void 0:i.CODATA,sequencia:(null==r?void 0:r.SEQUENCIA)||"0",tipo:(null==r?void 0:r.TIPO)||"N",descricao:null==r?void 0:r.DESCRICAO,arquivo:null===(n=null===(s=e.CAMINHO_ARQUIVO)||void 0===s?void 0:s[0])||void 0===n?void 0:n.name,ehInclusao:o?"S":"N",ehArquivoRepositorio:"N"}};return new Promise(((i,a)=>{h.get().callServiceBroker("Attach.save",JSON.stringify(l)).then((a=>{var s;return i([Object.assign(Object.assign(Object.assign({},a),e),{__owner__dataunit__name__:null!==(s=this.dataUnitName)&&void 0!==s?s:t})])})).catch((t=>a(t)))}))}async edit(t){throw new Error("Method not implemented.")}async delete(t){var i={anexo:{codata:t.CODATA,tipo:t.TIPO,descricao:t.DESCRICAO}};const e=await h.get().callServiceBroker("Attach.remove",JSON.stringify(i));return Promise.resolve(e)}async getDownloadKey(t){var i,e,a;if("S"==t.EHARQUIVOREPOSITORIO){const a={config:{path:t.ARQUIVO,tipoconteudo:t.TIPOCONTEUDO}},s=await h.get().callServiceBroker("RepositorioArquivoSP.abreArquivo",JSON.stringify(a));return Promise.resolve({chave:{valor:null===(e=null===(i=null==s?void 0:s.responseBody)||void 0===i?void 0:i.chave)||void 0===e?void 0:e.valor}})}const s={anexo:{codata:t.CODATA,codemp:t.CODEMP,sequencia:t.SEQUENCIA,tipo:t.TIPO,descricao:t.DESCRICAO,tipoConteudo:t.TIPOCONTEUDO}},n=await h.get().callServiceBroker("Attach.view",JSON.stringify(s));return(null==n?void 0:n.chaveAnexo)?Promise.resolve({chave:{valor:null===(a=null==n?void 0:n.chaveAnexo)||void 0===a?void 0:a.idChaveAnexo}}):Promise.reject(new Error("File not found."))}}const k="AnexoSistemaSP.salvar",I="AnexoSistemaSP.excluir",S="AnexoSistemaSP.baixar";class _{constructor(t,i){var e;this.entityName=t,this.dataUnitName=i,this.validateFields=t=>{if(t.LINK&&t.NOMEARQUIVO)throw new Error(c.LINK_AND_FILE_AT_THE_SAME_TIME);if(!t.LINK&&!t.NOMEARQUIVO)throw new Error(c.ANY_LINK_OR_FILE_FILLED);if(!this._registerKey)throw new Error("Register key can not be null")},this.resourceID=window.resourceID||(null===(e=window.workspace)||void 0===e?void 0:e.resourceID)}set registerKey(t){this._registerKey=t}async save(t){var i,e;let{updatingFields:a}=t;a=Object.assign(Object.assign({},a),{NOMEARQUIVO:null===(i=a.NOMEARQUIVO)||void 0===i?void 0:i[0]});try{this.validateFields(a);const t=a.LINK?null:a.NOMEARQUIVO,i={serviceName:k,requestBody:{params:{resourceID:this.resourceID,description:a.DESCRICAO,fileSelect:t?1:0,keySession:null===(e=null==t?void 0:t.properties)||void 0===e?void 0:e.fileNameTmp,nameAttach:null==t?void 0:t.name,link:a.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:a.TIPOACESSO,typeApres:a.TIPOAPRES}}},s=await h.get().callServiceBroker(k,JSON.stringify(i));return Promise.resolve([Object.assign(Object.assign(Object.assign({},s),a),{ARQUIVOOULINK:a.LINK?a.LINK:null==t?void 0:t.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}async edit(t){var i,e,a;let{updatingFields:s,record:n}=t;const o=t=>void 0!==s[t]?s[t]:n[t],r=o("NOMEARQUIVO"),l=null===(e=null===(i=s.NOMEARQUIVO)||void 0===i?void 0:i[0])||void 0===e?void 0:e.downloadURL;s=Object.assign(Object.assign({},s),{DESCRICAO:o("DESCRICAO"),LINK:o("LINK"),TIPOACESSO:o("TIPOACESSO"),TIPOAPRES:o("TIPOAPRES"),CHAVEARQUIVO:n.CHAVEARQUIVO,NOMEARQUIVO:null==r?void 0:r[0]});const d=s.LINK?null:s.NOMEARQUIVO;try{this.validateFields(s);const t={serviceName:k,requestBody:{params:{resourceID:this.resourceID,nuAttach:null==n?void 0:n.NUATTACH,description:s.DESCRICAO,fileSelect:l?1:0,keySession:null===(a=null==d?void 0:d.properties)||void 0===a?void 0:a.fileNameTmp,keyAttach:s.CHAVEARQUIVO,nameAttach:null==d?void 0:d.name,link:s.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:s.TIPOACESSO,typeApres:s.TIPOAPRES}}},i=await h.get().callServiceBroker(k,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},i),s),{ARQUIVOOULINK:s.LINK?s.LINK:null==d?void 0:d.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}delete(t){var i;const e=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},a={serviceName:I,requestBody:{paramsDelete:{keyAttach:t.CHAVEARQUIVO,nameAttach:null==e?void 0:e.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO}}};return new Promise(((t,i)=>{h.get().callServiceBroker(I,JSON.stringify(a)).then((i=>t(i))).catch((t=>i(t)))}))}getDownloadKey(t){var i;const e=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},a={serviceName:S,requestBody:{paramsDown:{nameAttach:null==e?void 0:e.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO,keyAttach:t.CHAVEARQUIVO}}};return new Promise(((t,i)=>{h.get().callServiceBroker(S,JSON.stringify(a)).then((i=>t(i))).catch((t=>i(t)))}))}}class b{constructor(t,i){this.entityName=t,this.getMessage=i,this._application=a.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,a)=>this.saveLoader(a,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,a)=>this.removeLoader(t,a,i).then((t=>(t.length&&e(),t)))}metadataLoader(t){throw new Error("Method not implemented.")}dataLoader(t,i){return new Promise((e=>{this.loader(t,i).then((t=>{const i=((null==t?void 0:t.records)||[]).map((t=>{let i;return t.LINK||(i=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:i})}));e(Object.assign(Object.assign({},t),{records:i}))}))}))}saveLoader(t,i){return new Promise((e=>{var a;const s=Array.isArray(t)?t[0]:{};((null===(a=null==s?void 0:s.record)||void 0===a?void 0:a.NUATTACH)>=0?i.edit.bind(i):i.save.bind(i))(s).then((t=>{e(t)})).catch((t=>t.message===c.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),e([])):t.message===c.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((a=>{const{records:s}=t.getSelectionInfo(),n=s[0];e.delete(n).then((()=>(v.removeRecords(t,[n]),a(i))))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:s.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,i,e){return new Promise((a=>i.type===n.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(A.GRID),a(i)):a(void 0))):a(i):i.type===n.DATA_SAVED?(t.loadData(),a(i)):void a(i)))}}const y=a.getContextValue("__SNK__APPLICATION__"),f=t=>{var i,e;return null===(e=null===(i=null==y?void 0:y.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,t,null)},E={grid:{columns:[{name:"CODATA",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"ARQUIVO",orderIndex:2,width:0},{name:"DTALTER",orderIndex:3,width:0},{name:"USUARIO",orderIndex:4,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",label:f("snkAttach.attachMetadata.lblDescription"),visible:!0,readOnly:!1,required:!0},{name:"CAMINHO_ARQUIVO",label:f("snkAttach.attachMetadata.lblFile"),visible:!0,readOnly:!1,required:!0}]}},N={name:"Attach",label:"Attach List",fields:[{name:"CODATA",label:f("snkAttach.attachMetadata.lblCode"),dataType:s.TEXT},{name:"DESCRICAO",label:f("snkAttach.attachMetadata.lblDescription"),dataType:s.TEXT,readOnly:!1},{name:"ARQUIVO",label:f("snkAttach.attachMetadata.lblFileOrLink"),dataType:s.TEXT},{name:"USUARIO",label:f("snkAttach.attachMetadata.lblUser"),dataType:s.TEXT},{name:"DTALTER",label:f("snkAttach.attachMetadata.lblDate"),dataType:s.TEXT},{name:"CAMINHO_ARQUIVO",label:f("snkAttach.attachMetadata.lblFileUpload"),dataType:s.OBJECT,userInterface:o.FILE,readOnly:!1,required:!0,visible:!0,properties:{subTitle:f("snkAttach.attachMetadata.lblSubTitle"),MAX_FILES:1,STORAGESTRATEGY:"SESSION",INTERNAL_FILENAME:"Attach.upload"}}]};class g{constructor(t){this.getMessage=t,this._records=[],this._application=a.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){t.metadataLoader=t=>this.metadataLoader(t),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,a)=>this.saveLoader(a,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,a)=>this.removeLoader(t,a,i).then((t=>(t.length&&e(),t)))}metadataLoader(t){return Promise.resolve(N)}async dataLoader(t,i){if(!i.source)return Promise.resolve({records:this._records});if(!Number.isNaN(Number(i.source))){const t={criteria:{codata:i.source,tipoAnexo:"N"}},e=await this._application.getDataFetcher(),{anexos:{anexo:a=[]}}=await e.callServiceBroker("Attach.load",JSON.stringify(t)),s=[];a.forEach((t=>{s.push(Object.assign({__record__id__:r.generateUUID(),CAMINHO_ARQUIVO:[{name:null==t?void 0:t.ARQUIVO}]},t))})),this._records=s}return l.buildLoadDataResponse(this._records,t,i)}saveLoader(t,i){return new Promise((e=>{const a=Array.isArray(t)?t[0]:{};i.save(a).then(e).catch((t=>t.message===c.DESCRIPTION_CANNOT_BE_CHANGED?(this._application.alert(this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.title"),this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.message")),e([])):t.message===c.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),e([])):t.message===c.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((a=>{t.getSelectionInfo().records.forEach((async t=>{this._application.hasAccess(O.REMOVE).then((async s=>{s&&(await e.delete(t),a(i))}))}))}))}getFilters(){throw new Error("Method not implemented.")}getInterceptions(t,i,e){return new Promise((a=>{var s,o,r,l,d,h;switch(i.type){case n.EDITION_CANCELED:return t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(A.GRID),a(i)):a(void 0))):a(i);case n.DATA_SAVED:return t.loadData(void 0,void 0,!1,null===(r=null===(o=null===(s=null==i?void 0:i.payload)||void 0===s?void 0:s.records)||void 0===o?void 0:o[0])||void 0===r?void 0:r.REGISTER_KEY),a(i);case n.RECORDS_REMOVED:return t.loadData(void 0,void 0,!1,null===(h=null===(d=null===(l=null==i?void 0:i.payload)||void 0===l?void 0:l.cachedRecords)||void 0===d?void 0:d[0])||void 0===h?void 0:h.CODATA),a(i)}a(i)}))}}const C=a.getContextValue("__SNK__APPLICATION__"),T=t=>{var i,e;return null===(e=null===(i=null==C?void 0:C.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,t,null)},L={DOWNLOAD:{hint:T("snkAttach.taskbar.titleDownload"),name:"DOWNLOAD",iconName:"file-download"},LINK:{hint:T("snkAttach.taskbar.titleLink"),name:"LINK",iconName:"launch"}},P=()=>{const t=[p.REMOVE,"DOWNLOAD","LINK"];return{getButtons:(t,i,e)=>{const a=e.indexOf(p.REFRESH);if((null==i?void 0:i.insertionMode)||(null==i?void 0:i.isDirty))return e.reverse();-1!==a&&e.splice(a,1);const{selectedRecord:s}=i||{},n=(null==s?void 0:s.LINK)?L.LINK:L.DOWNLOAD;e.splice(e.indexOf(p.DIVIDER)+1,0,p.REMOVE,n,p.DIVIDER);const o=[p.CLONE,p.DATA_EXPORTER],r=Array.from(new Set(e.filter((t=>!o.includes(t)))));return r.splice(r.indexOf(n)+1,0,p.DIVIDER),r},isEnabled:(i,e,a)=>{const s=void 0!==(null==e?void 0:e.selectedRecord);return!(t.includes(a)&&!s)}}},R={grid:{columns:[{name:"ARQUIVOOULINK",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"DHCAD",orderIndex:2,width:0},{name:"DHALTER",orderIndex:3,width:0},{name:"TIPOAPRES",orderIndex:4,width:0},{name:"TIPOACESSO",orderIndex:5,width:0},{name:"CODUSU",orderIndex:6,width:0},{name:"CODUSUALT",orderIndex:7,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",required:!0},{name:"TIPOAPRES",required:!0},{name:"TIPOACESSO",required:!0},{name:"LINK"},{name:"NOMEARQUIVO"}]}},x=class{constructor(e){t(this,e),this.back=i(this,"back",7),this.handleTaskbarClick=async({detail:t})=>{if(["DOWNLOAD","LINK"].includes(t))return this.downloadAttachment(this._currentDataUnit.getSelectedRecord());"Attach"===this.fetcherType&&["SAVE"].includes(t)&&this._currentDataUnit.isDirty()&&await this._currentDataUnit.setFieldValue("REGISTER_KEY",this.registerKey)},this.handleBack=()=>{this._currentDataUnit.cancelEdition().then((t=>{t&&this.back.emit()}))},this.handleFinish=()=>{if(!this._currentDataUnit.isDirty())return this.back.emit();this.validateAnexoSistema()&&this._currentDataUnit.saveData().then((()=>{this.showFinishedToast(),this.back.emit()}))},this.fetcherType=void 0,this.fetcher=void 0,this.dataUnit=void 0,this.dataUnitBuilder=void 0,this.registerKey=void 0,this.entityName=void 0,this.messagesBuilder=void 0,this._currentFetcher=void 0,this._currentDataUnit=void 0,this.crudConfig=void 0}async registerKeyWatcher(t,i){var e;null==this._currentDataUnit&&this.loadAttachmentDataUnit(),i!==t&&(this._currentFetcher instanceof _&&(this._currentFetcher.registerKey=t),await(null===(e=this._currentDataUnit)||void 0===e?void 0:e.loadData()))}getAnexoSistemaFetcherInstance(){var t;const i=new _(this.entityName,null===(t=this._currentDataUnit)||void 0===t?void 0:t.name);return i.registerKey=this.registerKey,i}async initAttach(){var t,i,e,a,s;if(this.fetcherType||this.registerKey){if(this.fetcherType||(this.fetcherType="AnexoSistema"),this.returnToGridMode(),"AnexoSistema"===this.fetcherType)return this._currentFetcher=this.getAnexoSistemaFetcherInstance(),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this)),void await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData());if("Attach"===this.fetcherType&&(null===(e=this.registerKey)||void 0===e?void 0:e.split("_").length)>1)return;await(null===(a=this._currentDataUnit)||void 0===a?void 0:a.loadMetadata()),await(null===(s=this._currentDataUnit)||void 0===s?void 0:s.loadData(void 0,void 0,!0,this.registerKey))}}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error("Nenhum registro selecionado");t.LINK?window.open(`${t.LINK}`):this._currentFetcher.getDownloadKey(t).then((({chave:i})=>{var e;let a=!1;(null===(e=null==t?void 0:t.ARQUIVO)||void 0===e?void 0:e.endsWith(".pdf"))||(a=!0),window.open(`/mge/visualizadorArquivos.mge?chaveArquivo=${i.valor}${a?"&forcarDownload=S":""}`)}))}returnToGridMode(){var t;null===(t=this._currentDataUnit)||void 0===t||t.clearSelection(),this._crudElement&&this._crudElement.goToView(A.GRID)}async loadAttachmentDataUnit(){try{switch(this.fetcherType){case"AnexoSistema":await this.loadAnexoSistema();break;case"Attach":await this.loadAttach();break;default:this._currentFetcher=this.fetcher,this._currentDataUnit=this.dataUnit,this._currentDataUnitBuilder=this.dataUnitBuilder}}catch(t){throw new Error("There was an error while creating the data unit")}}async loadAnexoSistema(){var t,i;this._currentDataUnit=(new u).getDataUnit("AnexoSistema","br.com.sankhya.core.v3.anexoSistema"),this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=Object.assign({},R)),this.initDataUnitLoaders(),this._currentDataUnit.addFilterProvider({getFilter:()=>this._currentDataUnitBuilder.getFilters(this.registerKey)}),this._currentDataUnit.addInterceptor({interceptAction:t=>this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData()),this.disableEditFieldsNotInForm()}async loadAttach(){var t,i;this._currentFetcher=new w,this._currentDataUnit=new d(m.IN_MEMORY_DATA_UNIT_NAME),this._currentDataUnit.pageSize=150,this.initDataUnitLoaders(),this._currentDataUnit.addInterceptor({interceptAction:t=>{var i;return t.type===n.METADATA_LOADED&&(this.crudConfig=Object.assign({},E),null===(i=this._crudElement)||void 0===i||i.updateConfig()),this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}}),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=Object.assign({},E),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData(void 0,void 0,!0,this.registerKey)),this.disableEditFieldsNotInForm())}initDataUnitLoaders(){var t,i;"AnexoSistema"===this.fetcherType&&(this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnitBuilder=new b(this.entityName,this.getMessage.bind(this)),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this))),"Attach"===this.fetcherType&&(this._currentFetcher=new w,this._currentDataUnitBuilder=new g(this.getMessage.bind(this)),null===(i=this._currentDataUnitBuilder)||void 0===i||i.initLoaders(this._currentDataUnit,this._currentFetcher,(async()=>{this.returnToGridMode(),await this._currentDataUnit.loadData(void 0,void 0,!0,this.registerKey)})))}disableEditFieldsNotInForm(){var t;null===(t=this.crudConfig)||void 0===t||t.grid.columns.forEach((t=>{var i;const e=t.name;(null===(i=this.crudConfig)||void 0===i?void 0:i.form.fields.some((t=>t.name===e)))||this._currentDataUnit.disableField(e)}))}validateAnexoSistema(){var t;if(this._currentFetcher instanceof _)try{let i=this._currentDataUnit.getSelectedRecord();i=Object.assign(Object.assign({},i),{NOMEARQUIVO:null===(t=i.NOMEARQUIVO)||void 0===t?void 0:t[0]}),this._currentFetcher.validateFields(i)}catch(t){if(t.message===c.LINK_AND_FILE_AT_THE_SAME_TIME)return this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),!1;if(t.message===c.ANY_LINK_OR_FILE_FILLED)return this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),!1}return!0}async componentWillLoad(){this._application=a.getContextValue("__SNK__APPLICATION__"),await this.initAttach()}componentWillRender(){this.fetcherType||(this.fetcherType="AnexoSistema"),null==this._currentDataUnit&&this.loadAttachmentDataUnit()}async handleOnDataStateChange({detail:t}){"Attach"===this.fetcherType&&(t.insertionMode?this._currentDataUnit.enableField("DESCRICAO"):this._currentDataUnit.disableField("DESCRICAO"),await this._currentDataUnit.loadMetadata())}render(){var t,i;return this._currentDataUnit?e("main",{class:"snk-attach__main"},e("header",{class:"snk-attach__header"},e("snk-simple-bar",{onExit:this.handleBack,messagesBuilder:this.messagesBuilder},e("div",{slot:"rightSlot"},e("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})))),e("div",{class:"snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column"},e("div",{class:"ez-box__container"},e("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this._currentDataUnit,taskbarManager:P(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(i=this.crudConfig)||void 0===i?void 0:i.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick,messagesBuilder:this.messagesBuilder,onDataStateChange:this.handleOnDataStateChange.bind(this),multipleSelection:!0},e("div",{slot:"snkSimpleCrudHeader"},e("div",{class:"ez-flex ez-flex--column"},e("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium"},this.getMessage("snkAttach.title")),e("span",{class:"ez-text ez-text--medium ez-text--secondary ez-padding-bottom--medium"},this.getMessage("snkAttach.description")))))))):null}static get watchers(){return{registerKey:["registerKeyWatcher"]}}};x.style=".snk-attach__header.sc-snk-attach,.snk-attach__crud-section.sc-snk-attach{padding:0 var(--space--lg)}.snk-attach__file-info.sc-snk-attach{padding:var(--space--small);max-width:50%}.snk-attach__main.sc-snk-attach{height:85%}.ez-box__container.sc-snk-attach{height:100%}";export{x as snk_attach}
1
+ import{r as t,c as i,h as e}from"./p-d8d8169b.js";import{ApplicationContext as a,DataType as s,Action as n,UserInterface as o,StringUtils as r,DataUnitLoaderUtils as l,DataUnit as d}from"@sankhyalabs/core";import{D as h}from"./p-cd1a5b6a.js";import{S as c}from"./p-c9657baa.js";import"./p-0f3698af.js";import{P as v,D as u,I as m}from"./p-37b4f642.js";import"./p-ff1990ad.js";import"./p-b21d32f6.js";import{V as A}from"./p-9019a32f.js";import{A as O}from"./p-e25412da.js";import{T as p}from"./p-7de79adf.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-a349689a.js";class w{constructor(t){this.dataUnitName=t}async save({dataUnit:t,record:i,updatingFields:e,operation:a}){var s,n;const o="INSERT"==a,r=o?e:i;if(!o&&(null==e?void 0:e.DESCRICAO)&&(null==e?void 0:e.DESCRICAO)!==(null==i?void 0:i.DESCRICAO))throw new Error(c.DESCRIPTION_CANNOT_BE_CHANGED);const l={anexo:{codata:o?null==e?void 0:e.REGISTER_KEY:null==i?void 0:i.CODATA,sequencia:(null==r?void 0:r.SEQUENCIA)||"0",tipo:(null==r?void 0:r.TIPO)||"N",descricao:null==r?void 0:r.DESCRICAO,arquivo:null===(n=null===(s=e.CAMINHO_ARQUIVO)||void 0===s?void 0:s[0])||void 0===n?void 0:n.name,ehInclusao:o?"S":"N",ehArquivoRepositorio:"N"}};return new Promise(((i,a)=>{h.get().callServiceBroker("Attach.save",JSON.stringify(l)).then((a=>{var s;return i([Object.assign(Object.assign(Object.assign({},a),e),{__owner__dataunit__name__:null!==(s=this.dataUnitName)&&void 0!==s?s:t})])})).catch((t=>a(t)))}))}async edit(t){throw new Error("Method not implemented.")}async delete(t){var i={anexo:{codata:t.CODATA,tipo:t.TIPO,descricao:t.DESCRICAO}};const e=await h.get().callServiceBroker("Attach.remove",JSON.stringify(i));return Promise.resolve(e)}async getDownloadKey(t){var i,e,a;if("S"==t.EHARQUIVOREPOSITORIO){const a={config:{path:t.ARQUIVO,tipoconteudo:t.TIPOCONTEUDO}},s=await h.get().callServiceBroker("RepositorioArquivoSP.abreArquivo",JSON.stringify(a));return Promise.resolve({chave:{valor:null===(e=null===(i=null==s?void 0:s.responseBody)||void 0===i?void 0:i.chave)||void 0===e?void 0:e.valor}})}const s={anexo:{codata:t.CODATA,codemp:t.CODEMP,sequencia:t.SEQUENCIA,tipo:t.TIPO,descricao:t.DESCRICAO,tipoConteudo:t.TIPOCONTEUDO}},n=await h.get().callServiceBroker("Attach.view",JSON.stringify(s));return(null==n?void 0:n.chaveAnexo)?Promise.resolve({chave:{valor:null===(a=null==n?void 0:n.chaveAnexo)||void 0===a?void 0:a.idChaveAnexo}}):Promise.reject(new Error("File not found."))}}const k="AnexoSistemaSP.salvar",I="AnexoSistemaSP.excluir",S="AnexoSistemaSP.baixar";class _{constructor(t,i){var e;this.entityName=t,this.dataUnitName=i,this.validateFields=t=>{if(t.LINK&&t.NOMEARQUIVO)throw new Error(c.LINK_AND_FILE_AT_THE_SAME_TIME);if(!t.LINK&&!t.NOMEARQUIVO)throw new Error(c.ANY_LINK_OR_FILE_FILLED);if(!this._registerKey)throw new Error("Register key can not be null")},this.resourceID=window.resourceID||(null===(e=window.workspace)||void 0===e?void 0:e.resourceID)}set registerKey(t){this._registerKey=t}async save(t){var i,e;let{updatingFields:a}=t;a=Object.assign(Object.assign({},a),{NOMEARQUIVO:null===(i=a.NOMEARQUIVO)||void 0===i?void 0:i[0]});try{this.validateFields(a);const t=a.LINK?null:a.NOMEARQUIVO,i={serviceName:k,requestBody:{params:{resourceID:this.resourceID,description:a.DESCRICAO,fileSelect:t?1:0,keySession:null===(e=null==t?void 0:t.properties)||void 0===e?void 0:e.fileNameTmp,nameAttach:null==t?void 0:t.name,link:a.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:a.TIPOACESSO,typeApres:a.TIPOAPRES}}},s=await h.get().callServiceBroker(k,JSON.stringify(i));return Promise.resolve([Object.assign(Object.assign(Object.assign({},s),a),{ARQUIVOOULINK:a.LINK?a.LINK:null==t?void 0:t.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}async edit(t){var i,e,a;let{updatingFields:s,record:n}=t;const o=t=>void 0!==s[t]?s[t]:n[t],r=o("NOMEARQUIVO"),l=null===(e=null===(i=s.NOMEARQUIVO)||void 0===i?void 0:i[0])||void 0===e?void 0:e.downloadURL;s=Object.assign(Object.assign({},s),{DESCRICAO:o("DESCRICAO"),LINK:o("LINK"),TIPOACESSO:o("TIPOACESSO"),TIPOAPRES:o("TIPOAPRES"),CHAVEARQUIVO:n.CHAVEARQUIVO,NOMEARQUIVO:null==r?void 0:r[0]});const d=s.LINK?null:s.NOMEARQUIVO;try{this.validateFields(s);const t={serviceName:k,requestBody:{params:{resourceID:this.resourceID,nuAttach:null==n?void 0:n.NUATTACH,description:s.DESCRICAO,fileSelect:l?1:0,keySession:null===(a=null==d?void 0:d.properties)||void 0===a?void 0:a.fileNameTmp,keyAttach:s.CHAVEARQUIVO,nameAttach:null==d?void 0:d.name,link:s.LINK,nameEntity:this.entityName,pkEntity:this._registerKey,typeAcess:s.TIPOACESSO,typeApres:s.TIPOAPRES}}},i=await h.get().callServiceBroker(k,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},i),s),{ARQUIVOOULINK:s.LINK?s.LINK:null==d?void 0:d.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}delete(t){var i;const e=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},a={serviceName:I,requestBody:{paramsDelete:{keyAttach:t.CHAVEARQUIVO,nameAttach:null==e?void 0:e.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO}}};return new Promise(((t,i)=>{h.get().callServiceBroker(I,JSON.stringify(a)).then((i=>t(i))).catch((t=>i(t)))}))}getDownloadKey(t){var i;const e=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},a={serviceName:S,requestBody:{paramsDown:{nameAttach:null==e?void 0:e.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO,keyAttach:t.CHAVEARQUIVO}}};return new Promise(((t,i)=>{h.get().callServiceBroker(S,JSON.stringify(a)).then((i=>t(i))).catch((t=>i(t)))}))}}class y{constructor(t,i){this.entityName=t,this.getMessage=i,this._application=a.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,a)=>this.saveLoader(a,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,a)=>this.removeLoader(t,a,i).then((t=>(t.length&&e(),t)))}metadataLoader(t){throw new Error("Method not implemented.")}dataLoader(t,i){return new Promise((e=>{this.loader(t,i).then((t=>{const i=((null==t?void 0:t.records)||[]).map((t=>{let i;return t.LINK||(i=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:i})}));e(Object.assign(Object.assign({},t),{records:i}))}))}))}saveLoader(t,i){return new Promise((e=>{var a;const s=Array.isArray(t)?t[0]:{};((null===(a=null==s?void 0:s.record)||void 0===a?void 0:a.NUATTACH)>=0?i.edit.bind(i):i.save.bind(i))(s).then((t=>{e(t)})).catch((t=>t.message===c.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),e([])):t.message===c.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((a=>{const{records:s}=t.getSelectionInfo(),n=s[0];e.delete(n).then((()=>(v.removeRecords(t,[n]),a(i))))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:s.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,i,e){return new Promise((a=>i.type===n.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(A.GRID),a(i)):a(void 0))):a(i):i.type===n.DATA_SAVED?(t.loadData(),a(i)):void a(i)))}}const b=a.getContextValue("__SNK__APPLICATION__"),f=t=>{var i,e;return null===(e=null===(i=null==b?void 0:b.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,t,null)},E={grid:{columns:[{name:"CODATA",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"ARQUIVO",orderIndex:2,width:0},{name:"DTALTER",orderIndex:3,width:0},{name:"USUARIO",orderIndex:4,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",label:f("snkAttach.attachMetadata.lblDescription"),visible:!0,readOnly:!1,required:!0},{name:"CAMINHO_ARQUIVO",label:f("snkAttach.attachMetadata.lblFile"),visible:!0,readOnly:!1,required:!0}]}},N={name:"Attach",label:"Attach List",fields:[{name:"CODATA",label:f("snkAttach.attachMetadata.lblCode"),dataType:s.TEXT},{name:"DESCRICAO",label:f("snkAttach.attachMetadata.lblDescription"),dataType:s.TEXT,readOnly:!1},{name:"ARQUIVO",label:f("snkAttach.attachMetadata.lblFileOrLink"),dataType:s.TEXT},{name:"USUARIO",label:f("snkAttach.attachMetadata.lblUser"),dataType:s.TEXT},{name:"DTALTER",label:f("snkAttach.attachMetadata.lblDate"),dataType:s.TEXT},{name:"CAMINHO_ARQUIVO",label:f("snkAttach.attachMetadata.lblFileUpload"),dataType:s.OBJECT,userInterface:o.FILE,readOnly:!1,required:!0,visible:!0,properties:{subTitle:f("snkAttach.attachMetadata.lblSubTitle"),MAX_FILES:1,STORAGESTRATEGY:"SESSION",INTERNAL_FILENAME:"Attach.upload"}}]};class g{constructor(t){this.getMessage=t,this._records=[],this._application=a.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){t.metadataLoader=t=>this.metadataLoader(t),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,a)=>this.saveLoader(a,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,a)=>this.removeLoader(t,a,i).then((t=>(t.length&&e(),t)))}metadataLoader(t){return Promise.resolve(N)}async dataLoader(t,i){if(!i.source)return Promise.resolve({records:this._records});if(!Number.isNaN(Number(i.source))){const t={criteria:{codata:i.source,tipoAnexo:"N"}},e=await this._application.getDataFetcher(),{anexos:{anexo:a=[]}}=await e.callServiceBroker("Attach.load",JSON.stringify(t)),s=[];a.forEach((t=>{s.push(Object.assign({__record__id__:r.generateUUID(),CAMINHO_ARQUIVO:[{name:null==t?void 0:t.ARQUIVO}]},t))})),this._records=s}return l.buildLoadDataResponse(this._records,t,i)}saveLoader(t,i){return new Promise((e=>{const a=Array.isArray(t)?t[0]:{};i.save(a).then(e).catch((t=>t.message===c.DESCRIPTION_CANNOT_BE_CHANGED?(this._application.alert(this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.title"),this.getMessage("snkAttach.alertValidation.descriptionCannotBeChanged.message")),e([])):t.message===c.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),e([])):t.message===c.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((a=>{t.getSelectionInfo().records.forEach((async t=>{this._application.hasAccess(O.REMOVE).then((async s=>{s&&(await e.delete(t),a(i))}))}))}))}getFilters(){throw new Error("Method not implemented.")}getInterceptions(t,i,e){return new Promise((a=>{var s,o,r,l,d,h;switch(i.type){case n.EDITION_CANCELED:return t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(A.GRID),a(i)):a(void 0))):a(i);case n.DATA_SAVED:return t.loadData(void 0,void 0,!1,null===(r=null===(o=null===(s=null==i?void 0:i.payload)||void 0===s?void 0:s.records)||void 0===o?void 0:o[0])||void 0===r?void 0:r.REGISTER_KEY),a(i);case n.RECORDS_REMOVED:return t.loadData(void 0,void 0,!1,null===(h=null===(d=null===(l=null==i?void 0:i.payload)||void 0===l?void 0:l.cachedRecords)||void 0===d?void 0:d[0])||void 0===h?void 0:h.CODATA),a(i)}a(i)}))}}const C=a.getContextValue("__SNK__APPLICATION__"),T=t=>{var i,e;return null===(e=null===(i=null==C?void 0:C.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,t,null)},L={DOWNLOAD:{hint:T("snkAttach.taskbar.titleDownload"),name:"DOWNLOAD",iconName:"file-download"},LINK:{hint:T("snkAttach.taskbar.titleLink"),name:"LINK",iconName:"launch"}},P=()=>{const t=[p.REMOVE,"DOWNLOAD","LINK"];return{getButtons:(t,i,e)=>{const a=e.indexOf(p.REFRESH);if((null==i?void 0:i.insertionMode)||(null==i?void 0:i.isDirty))return e.reverse();-1!==a&&e.splice(a,1);const{selectedRecord:s}=i||{},n=(null==s?void 0:s.LINK)?L.LINK:L.DOWNLOAD;e.splice(e.indexOf(p.DIVIDER)+1,0,p.REMOVE,n,p.DIVIDER);const o=[p.CLONE,p.DATA_EXPORTER],r=Array.from(new Set(e.filter((t=>!o.includes(t)))));return r.splice(r.indexOf(n)+1,0,p.DIVIDER),r},isEnabled:(i,e,a)=>{const s=void 0!==(null==e?void 0:e.selectedRecord);return!(t.includes(a)&&!s)}}},R={grid:{columns:[{name:"ARQUIVOOULINK",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"DHCAD",orderIndex:2,width:0},{name:"DHALTER",orderIndex:3,width:0},{name:"TIPOAPRES",orderIndex:4,width:0},{name:"TIPOACESSO",orderIndex:5,width:0},{name:"CODUSU",orderIndex:6,width:0},{name:"CODUSUALT",orderIndex:7,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",required:!0},{name:"TIPOAPRES",required:!0},{name:"TIPOACESSO",required:!0},{name:"LINK"},{name:"NOMEARQUIVO"}]}},x=class{constructor(e){t(this,e),this.back=i(this,"back",7),this.handleTaskbarClick=async({detail:t})=>{if(["DOWNLOAD","LINK"].includes(t))return this.downloadAttachment(this._currentDataUnit.getSelectedRecord());"Attach"===this.fetcherType&&["SAVE"].includes(t)&&this._currentDataUnit.isDirty()&&await this._currentDataUnit.setFieldValue("REGISTER_KEY",this.registerKey)},this.handleBack=()=>{this._currentDataUnit.cancelEdition().then((t=>{t&&this.back.emit()}))},this.handleFinish=()=>{if(!this._currentDataUnit.isDirty())return this.back.emit();this.validateAnexoSistema()&&this._currentDataUnit.saveData().then((()=>{this.showFinishedToast(),this.back.emit()}))},this.fetcherType=void 0,this.fetcher=void 0,this.dataUnit=void 0,this.dataUnitBuilder=void 0,this.registerKey=void 0,this.entityName=void 0,this.messagesBuilder=void 0,this._currentFetcher=void 0,this._currentDataUnit=void 0,this.crudConfig=void 0}async registerKeyWatcher(t,i){var e;null==this._currentDataUnit&&this.loadAttachmentDataUnit(),i!==t&&(this._currentFetcher instanceof _&&(this._currentFetcher.registerKey=t),await(null===(e=this._currentDataUnit)||void 0===e?void 0:e.loadData()))}getAnexoSistemaFetcherInstance(){var t;const i=new _(this.entityName,null===(t=this._currentDataUnit)||void 0===t?void 0:t.name);return i.registerKey=this.registerKey,i}async initAttach(){var t,i,e,a,s;if(this.fetcherType||this.registerKey){if(this.fetcherType||(this.fetcherType="AnexoSistema"),this.returnToGridMode(),"AnexoSistema"===this.fetcherType)return this._currentFetcher=this.getAnexoSistemaFetcherInstance(),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this)),void await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData());if("Attach"===this.fetcherType&&(null===(e=this.registerKey)||void 0===e?void 0:e.split("_").length)>1)return;await(null===(a=this._currentDataUnit)||void 0===a?void 0:a.loadMetadata()),await(null===(s=this._currentDataUnit)||void 0===s?void 0:s.loadData(void 0,void 0,!0,this.registerKey))}}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error("Nenhum registro selecionado");t.LINK?window.open(`${t.LINK}`):this._currentFetcher.getDownloadKey(t).then((({chave:i})=>{var e;let a=!1;(null===(e=null==t?void 0:t.ARQUIVO)||void 0===e?void 0:e.endsWith(".pdf"))||(a=!0),window.open(`/mge/visualizadorArquivos.mge?chaveArquivo=${i.valor}${a?"&forcarDownload=S":""}`)}))}returnToGridMode(){var t;null===(t=this._currentDataUnit)||void 0===t||t.clearSelection(),this._crudElement&&this._crudElement.goToView(A.GRID)}async loadAttachmentDataUnit(){try{switch(this.fetcherType){case"AnexoSistema":await this.loadAnexoSistema();break;case"Attach":await this.loadAttach();break;default:this._currentFetcher=this.fetcher,this._currentDataUnit=this.dataUnit,this._currentDataUnitBuilder=this.dataUnitBuilder}}catch(t){throw new Error("There was an error while creating the data unit")}}async loadAnexoSistema(){var t,i;this._currentDataUnit=(new u).getDataUnit("AnexoSistema","br.com.sankhya.core.v3.anexoSistema"),this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=Object.assign({},R)),this.initDataUnitLoaders(),this._currentDataUnit.addFilterProvider({getFilter:()=>this._currentDataUnitBuilder.getFilters(this.registerKey)}),this._currentDataUnit.addInterceptor({interceptAction:t=>this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData()),this.disableEditFieldsNotInForm()}async loadAttach(){var t,i;this._currentFetcher=new w,this._currentDataUnit=new d(m.IN_MEMORY_DATA_UNIT_NAME),this._currentDataUnit.pageSize=150,this.initDataUnitLoaders(),this._currentDataUnit.addInterceptor({interceptAction:t=>{var i;return t.type===n.METADATA_LOADED&&(this.crudConfig=Object.assign({},E),null===(i=this._crudElement)||void 0===i||i.updateConfig()),this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit,t,this._crudElement)}}),this._currentDataUnit.metadata||(await(null===(t=this._currentDataUnit)||void 0===t?void 0:t.loadMetadata()),this.crudConfig=Object.assign({},E),await(null===(i=this._currentDataUnit)||void 0===i?void 0:i.loadData(void 0,void 0,!0,this.registerKey)),this.disableEditFieldsNotInForm())}initDataUnitLoaders(){var t,i;"AnexoSistema"===this.fetcherType&&(this._currentFetcher=this.getAnexoSistemaFetcherInstance(),this._currentDataUnitBuilder=new y(this.entityName,this.getMessage.bind(this)),null===(t=this._currentDataUnitBuilder)||void 0===t||t.initLoaders(this._currentDataUnit,this._currentFetcher,this.returnToGridMode.bind(this))),"Attach"===this.fetcherType&&(this._currentFetcher=new w,this._currentDataUnitBuilder=new g(this.getMessage.bind(this)),null===(i=this._currentDataUnitBuilder)||void 0===i||i.initLoaders(this._currentDataUnit,this._currentFetcher,(async()=>{this.returnToGridMode(),await this._currentDataUnit.loadData(void 0,void 0,!0,this.registerKey)})))}disableEditFieldsNotInForm(){var t;null===(t=this.crudConfig)||void 0===t||t.grid.columns.forEach((t=>{var i;const e=t.name;(null===(i=this.crudConfig)||void 0===i?void 0:i.form.fields.some((t=>t.name===e)))||this._currentDataUnit.disableField(e)}))}validateAnexoSistema(){var t;if(this._currentFetcher instanceof _)try{let i=this._currentDataUnit.getSelectedRecord();i=Object.assign(Object.assign({},i),{NOMEARQUIVO:null===(t=i.NOMEARQUIVO)||void 0===t?void 0:t[0]}),this._currentFetcher.validateFields(i)}catch(t){if(t.message===c.LINK_AND_FILE_AT_THE_SAME_TIME)return this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),!1;if(t.message===c.ANY_LINK_OR_FILE_FILLED)return this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),!1}return!0}async componentWillLoad(){this._application=a.getContextValue("__SNK__APPLICATION__"),await this.initAttach()}componentWillRender(){this.fetcherType||(this.fetcherType="AnexoSistema"),null==this._currentDataUnit&&this.loadAttachmentDataUnit()}async handleOnDataStateChange({detail:t}){"Attach"===this.fetcherType&&(t.insertionMode?this._currentDataUnit.enableField("DESCRICAO"):this._currentDataUnit.disableField("DESCRICAO"),await this._currentDataUnit.loadMetadata())}render(){var t,i;return this._currentDataUnit?e("main",{class:"snk-attach__main"},e("header",{class:"snk-attach__header"},e("snk-simple-bar",{onExit:this.handleBack,messagesBuilder:this.messagesBuilder},e("div",{slot:"rightSlot"},e("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})))),e("div",{class:"snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column"},e("div",{class:"ez-box__container"},e("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this._currentDataUnit,taskbarManager:P(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(i=this.crudConfig)||void 0===i?void 0:i.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick,messagesBuilder:this.messagesBuilder,onDataStateChange:this.handleOnDataStateChange.bind(this),multipleSelection:!0},e("div",{slot:"snkSimpleCrudHeader"},e("div",{class:"ez-flex ez-flex--column"},e("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium"},this.getMessage("snkAttach.title")),e("span",{class:"ez-text ez-text--medium ez-text--secondary ez-padding-bottom--medium"},this.getMessage("snkAttach.description")))))))):null}static get watchers(){return{registerKey:["registerKeyWatcher"]}}};x.style=".snk-attach__header.sc-snk-attach,.snk-attach__crud-section.sc-snk-attach{padding:0 var(--space--lg)}.snk-attach__file-info.sc-snk-attach{padding:var(--space--small);max-width:50%}.snk-attach__main.sc-snk-attach{height:85%}.ez-box__container.sc-snk-attach{height:100%}";export{x as snk_attach}
@@ -1 +1 @@
1
- import{r as i,c as t,h as s,g as e,H as h}from"./p-d8d8169b.js";import{ElementIDUtils as a,ObjectUtils as o,ApplicationContext as n}from"@sankhyalabs/core";import{S as d}from"./p-a6513fcb.js";import{R as l}from"./p-688dcb4c.js";import{buildFormConfigFromDataUnit as r}from"@sankhyalabs/ezui/dist/collection/utils/form";import{b as c,a as f,g,u,c as m}from"./p-35e73c5d.js";import{a as v,G as p}from"./p-9019a32f.js";import{ApplicationUtils as C}from"@sankhyalabs/ezui/dist/collection/utils";import{U as b}from"./p-601b252b.js";import"./p-6416975c.js";import"./p-ff1990ad.js";import"./p-fbba7e3d.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const y=class{constructor(s){i(this,s),this.exit=t(this,"exit",7),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this._customEditors=new Map,this._dataUnit=void 0,this._dataState=void 0,this._showFormConfig=!1,this._configManager=void 0,this.configName=void 0,this.recordsValidator=void 0,this.messagesBuilder=void 0,this.formLegacyConfigName=void 0,this.resourceID=void 0}async showConfig(){this._showFormConfig=!0}async hideConfig(){this._showFormConfig=!1}async addCustomEditor(i,t){if(this._form)return void this._form.addCustomEditor(i,t);const s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async setFieldProp(i,t,s){await this._form.setFieldProp(i,t,s)}closeConfig(){this.hideConfig()}dataunitReady(){a.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}setCustomEditors(){if(this._form)for(const[i,t]of this._customEditors)this._form.addCustomEditor(i,t),this._customEditors.delete(i)}async componentDidRender(){this.setCustomEditors()}async componentWillLoad(){let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataState=this._snkDataUnit.dataState,this._dataUnit?this.dataunitReady():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail})),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this));break}i=i.parentElement}null==this.resourceID&&(this.resourceID=await l.getResourceID()),this._configManager=new d(this.configName,this.resourceID,void 0,this._dataUnit),this.addFormLegacyConfig(),await this._configManager.loadConfig()}async handleDataStateChange(i){var t;this._dataState=i.detail;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const i of s||[]){if(!i)continue;const s=null===(t=this._dataState.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",i);(s||0===s)&&(await this.setFieldProp(i,"precision",s),await this.setFieldProp(i,"prettyPrecision",s))}}addFormLegacyConfig(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}render(){if(this._dataUnit&&this._dataState)return s("section",null,s("div",{class:"ez-row"},s("div",{class:"ez-col ez-col--sd-12"},s("ez-form",{ref:i=>this._form=i,key:"ezForm"+this._snkDataUnit.entityName,"data-element-id":"embedded",dataUnit:this._dataUnit,config:this._configManager.getConfig(this._dataUnit),recordsValidator:this.recordsValidator,class:this._showFormConfig?"snk-form__form--hidden":""}),this._showFormConfig&&s("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this._dataUnit,configManager:this._configManager,onConfigClose:()=>this.closeConfig()}))))}get _element(){return e(this)}};y.style=".sc-snk-form-h{--snk-form__header--min-height:94px;display:block}.snk-form__form--hidden.sc-snk-form{display:none}";const k=class{constructor(s){i(this,s),this.configClose=t(this,"configClose",7),this.configChange=t(this,"configChange",7),this.guidesMap=new Map,this.availableFields=[],this.guidesList=[],this.groupsList=[],this.selectedGuide=void 0,this._formConfig={},this.configOptions=[],this.originalConfigSelected=void 0,this.configSelected=void 0,this.hasChanges=!1,this.optionConfigChanged=!1,this.dataUnit=void 0,this.configManager=void 0,this.ignoreReadOnlyFormFields=void 0,this.messagesBuilder=void 0}handleFieldConfigChanged(){this.hasChanges=!0}async handleFormConfigOptionSelected({detail:i}){this.configSelected=i,await this.loadConfigByUser(),this.selectedGuide=void 0,this.optionConfigChanged=!o.equals(this.configSelected,this.originalConfigSelected),this.configSelected.origin===b.DEFAULT&&(this.hasChanges=!1)}async handleAddFieldToGuide({detail:i}){var t;this.selectedGuide?(this.availableFields=[...this.availableFields.filter((t=>t.name!==i.name))],await(null===(t=this.refFieldsLayout)||void 0===t?void 0:t.addFieldToLayout(i))):this.showNoGuideSelectedDialog()}async handleSetFieldAsAvailable({detail:i}){this.availableFields.some((t=>t.name===i.name))||(this.availableFields=[...this.availableFields,i])}async handleRemoveFieldFromAvailable({detail:i}){this.availableFields=this.availableFields.filter((t=>t.name!==i.name))}observeSelectedGuide(i){var t;const s=null!==(t=this.guidesMap.get(null==i?void 0:i.name))&&void 0!==t?t:[];this.groupsList=[...s]}observeConfigManager(){this.loadFormConfig()}showNoGuideSelectedDialog(){const i=this.getMessage("snkFormConfig.noGuideSelected.title"),t=this.getMessage("snkFormConfig.noGuideSelected.message");C.alert(i,t)}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}async initializeUserConfig(){if(null!=this.configManager)try{const i=await this.configManager.fetchUserAvailableConfigs();this.configOptions=i;const t=null==this._formConfig||this._formConfig.defaultConfiguration?b.DEFAULT:b.USER;this.configSelected=i.find((i=>i.origin===t)),this.originalConfigSelected=i.find((i=>i.origin===t))}catch(i){console.error("Falha ao buscar configurações de formulário definida pelo usuário."),console.error(i)}}async loadConfigByUser(){this.configManager&&this.configSelected&&(this.isConfigDefaultSelected()?await this.handleLoadDefaultConfig():this.loadFormConfig())}async handleLoadDefaultConfig(){const i=await this.configManager.fetchDefaultConfig();if(i)return void this.loadFormConfig(i);const t=this.configManager.getEmptyConfig();t&&this.loadFormConfig(t)}isConfigDefaultSelected(){return this.configSelected.origin===b.DEFAULT}loadFormConfig(i){this._formConfig=i||this.getConfig(),this.loadGuides(),this.initializeAvailableFields()}initializeAvailableFields(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;const t=[...this._formConfig.fields];this.availableFields=this.dataUnit.metadata.fields.filter((({name:i,visible:s,properties:e})=>{const h=t.some((({name:t})=>t===i));return h||!0!==e.visibleOnConfig||s?!0===s&&!1===h:e.visibleOnConfig}))}loadGuides(){var i;this.guidesList=[...c(this._formConfig,this.getMessage("snkFormConfig.form.mainArea"))],this.guidesMap=f(null===(i=this._formConfig)||void 0===i?void 0:i.fields,this.guidesList,this.dataUnit,this.getMessage("snkFormConfig.form.tabGeneral"))}getConfig(){let i=this.configManager.getConfig(this.dataUnit,!1);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=r(this.dataUnit)),o.copy(i)}handleSelectGuide({detail:i}){this.selectedGuide=i}handleLayoutChanged({detail:i}){this.hasChanges=!0,this.groupsList=[...i],this.guidesMap.set(this.selectedGuide.name,[...i])}getIsDefaultConfig(){var i;return(null===(i=this.configSelected)||void 0===i?void 0:i.origin)===b.DEFAULT&&!0===this.optionConfigChanged&&!1===this.hasChanges}getTabsToSave(){return this.guidesList.map((i=>({name:i.name,label:i.name===v.main?i.name:i.label,order:i.name===v.main?0:i.order,visible:i.visible})))}async handleSaveConfig(){var i;const t=await this.configManager.saveConfig(this.buildConfigToSave());this.configSelected=null===(i=this.configOptions)||void 0===i?void 0:i.find((i=>i.origin===(this.hasChanges?b.USER:b.DEFAULT))),this.originalConfigSelected=this.configSelected,this.hasChanges=!1,this.optionConfigChanged=!1,C.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"}),this.configChange.emit(t)}buildConfigToSave(){if(this.getIsDefaultConfig()){const i=this._formConfig;return i.defaultConfiguration=!0,i}const i=o.copy(this._formConfig);return i.tabs=this.getTabsToSave(),i.fields=g(this.guidesMap),i.defaultConfiguration=!1,i}handleAvailableFieldListChanged({detail:i}){this.availableFields=[...i]}handleSetFieldListAsAvailable({detail:i}){this.availableFields=[...this.availableFields,...i]}handleGuideDeleted({detail:i}){var t,s;const e=i.name,h=null!==(t=this.guidesMap.get(e))&&void 0!==t?t:[],a=[];h.forEach((i=>a.push(...i.fields))),this.availableFields=[...this.availableFields,...a],this.guidesList=[...this.guidesList.filter((i=>i.name!==e))],this.guidesMap.delete(e),(null===(s=this.selectedGuide)||void 0===s?void 0:s.name)===e&&(this.selectedGuide=void 0),this.hasChanges=!0}handleGuideListChanged({detail:i}){this.hasChanges=!0,this.guidesList=[...i]}handleGuideRenamed({detail:i}){var t;const s=null!==(t=this.guidesMap.get(this.selectedGuide.name))&&void 0!==t?t:[],e=u(s,i);this.guidesMap.delete(this.selectedGuide.name),this.guidesMap.set(i,e);const h={name:i,label:i,visible:this.selectedGuide.visible,order:this.selectedGuide.order};this.guidesList=[...this.guidesList.map((i=>i.name===this.selectedGuide.name?h:i))],this.groupsList=[...e],this.selectedGuide=h,this.hasChanges=!0}handleCreateNewGuide(){const i=m(this.guidesList),t={name:i,label:i,visible:!0,order:this.guidesList.length+1},s={name:p.noGroup,fields:[]};this.guidesList=[...this.guidesList,t],this.guidesMap.set(i,[s]),this.selectedGuide=t,this.hasChanges=!0}getGuideNames(){return[...this.guidesList.map((i=>i.name.toLowerCase())),this.getMessage("snkFormConfig.form.mainArea").toLowerCase()]}async componentWillRender(){if(null==this.messagesBuilder){const i=n.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}async componentWillLoad(){this.loadFormConfig(),await this.initializeUserConfig()}render(){return s(h,null,s("config-header",{configOptions:this.configOptions,selectedConfig:this.configSelected,messagesBuilder:this.messagesBuilder,hasChanges:this.hasChanges,optionConfigChanged:this.optionConfigChanged,onConfigClose:()=>this.configClose.emit(),onSaveConfig:async()=>await this.handleSaveConfig()}),s("div",{class:"ez-padding--medium"},s("div",{class:"ez-flex sidebarNavigator__container"},s("guides-configurator",{messagesBuilder:this.messagesBuilder,guidesList:this.guidesList,selectedGuide:this.selectedGuide,onGuideSelected:this.handleSelectGuide.bind(this),onGuideListChanged:this.handleGuideListChanged.bind(this),onCreateNewGuide:this.handleCreateNewGuide.bind(this),onGuideDeleted:this.handleGuideDeleted.bind(this)}),s("fields-layout",{ref:i=>this.refFieldsLayout=i,selectedGuide:this.selectedGuide,guideNames:this.getGuideNames(),groupsList:this.groupsList,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,onGuideRenamed:this.handleGuideRenamed.bind(this),onLayoutChanged:this.handleLayoutChanged.bind(this),onSetFieldListAsAvailable:this.handleSetFieldListAsAvailable.bind(this)}),s("fields-selector",{dataUnit:this.dataUnit,availableFields:this.availableFields,onFieldListChanged:this.handleAvailableFieldListChanged.bind(this)}))))}static get watchers(){return{selectedGuide:["observeSelectedGuide"],configManager:["observeConfigManager"]}}};k.style='.sc-snk-form-config-h{display:flex;flex-direction:column;height:100vh;width:100vw;font-family:var(--font-pattern, "Roboto");background:white;color:#2b3a54;--snk-form-config-container-height:calc(100vh - 95px);outline:none}.sidebarNavigator__container.sc-snk-form-config{height:var(--snk-form-config-container-height);gap:20px;align-items:flex-start}.guide-header.sc-snk-form-config{display:flex;width:100%;padding-bottom:12px;border-bottom:1px solid #dce0e8;height:30px;font-weight:500;font-size:16px}';export{y as snk_form,k as snk_form_config}
1
+ import{r as i,c as t,h as s,g as e,H as h}from"./p-d8d8169b.js";import{ElementIDUtils as a,ObjectUtils as o,ApplicationContext as n}from"@sankhyalabs/core";import{S as d}from"./p-412e06e9.js";import{R as l}from"./p-688dcb4c.js";import{buildFormConfigFromDataUnit as r}from"@sankhyalabs/ezui/dist/collection/utils/form";import{b as c,a as f,g,u,c as m}from"./p-35e73c5d.js";import{a as v,G as p}from"./p-9019a32f.js";import{ApplicationUtils as C}from"@sankhyalabs/ezui/dist/collection/utils";import{U as b}from"./p-b21d32f6.js";import"./p-8758404f.js";import"./p-ff1990ad.js";import"./p-cd1a5b6a.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";const y=class{constructor(s){i(this,s),this.exit=t(this,"exit",7),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this._customEditors=new Map,this._dataUnit=void 0,this._dataState=void 0,this._showFormConfig=!1,this._configManager=void 0,this.configName=void 0,this.recordsValidator=void 0,this.messagesBuilder=void 0,this.formLegacyConfigName=void 0,this.resourceID=void 0}async showConfig(){this._showFormConfig=!0}async hideConfig(){this._showFormConfig=!1}async addCustomEditor(i,t){if(this._form)return void this._form.addCustomEditor(i,t);const s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async setFieldProp(i,t,s){await this._form.setFieldProp(i,t,s)}closeConfig(){this.hideConfig()}dataunitReady(){a.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}setCustomEditors(){if(this._form)for(const[i,t]of this._customEditors)this._form.addCustomEditor(i,t),this._customEditors.delete(i)}async componentDidRender(){this.setCustomEditors()}async componentWillLoad(){let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataState=this._snkDataUnit.dataState,this._dataUnit?this.dataunitReady():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail})),this._snkDataUnit.addEventListener("dataStateChange",this.handleDataStateChange.bind(this));break}i=i.parentElement}null==this.resourceID&&(this.resourceID=await l.getResourceID()),this._configManager=new d(this.configName,this.resourceID,void 0,this._dataUnit),this.addFormLegacyConfig(),await this._configManager.loadConfig()}async handleDataStateChange(i){var t;this._dataState=i.detail;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const i of s||[]){if(!i)continue;const s=null===(t=this._dataState.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",i);(s||0===s)&&(await this.setFieldProp(i,"precision",s),await this.setFieldProp(i,"prettyPrecision",s))}}addFormLegacyConfig(){this.formLegacyConfigName&&this._configManager.addFormLegacyConfig(this.formLegacyConfigName)}render(){if(this._dataUnit&&this._dataState)return s("section",null,s("div",{class:"ez-row"},s("div",{class:"ez-col ez-col--sd-12"},s("ez-form",{ref:i=>this._form=i,key:"ezForm"+this._snkDataUnit.entityName,"data-element-id":"embedded",dataUnit:this._dataUnit,config:this._configManager.getConfig(this._dataUnit),recordsValidator:this.recordsValidator,class:this._showFormConfig?"snk-form__form--hidden":""}),this._showFormConfig&&s("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this._dataUnit,configManager:this._configManager,onConfigClose:()=>this.closeConfig()}))))}get _element(){return e(this)}};y.style=".sc-snk-form-h{--snk-form__header--min-height:94px;display:block}.snk-form__form--hidden.sc-snk-form{display:none}";const k=class{constructor(s){i(this,s),this.configClose=t(this,"configClose",7),this.configChange=t(this,"configChange",7),this.guidesMap=new Map,this.availableFields=[],this.guidesList=[],this.groupsList=[],this.selectedGuide=void 0,this._formConfig={},this.configOptions=[],this.originalConfigSelected=void 0,this.configSelected=void 0,this.hasChanges=!1,this.optionConfigChanged=!1,this.dataUnit=void 0,this.configManager=void 0,this.ignoreReadOnlyFormFields=void 0,this.messagesBuilder=void 0}handleFieldConfigChanged(){this.hasChanges=!0}async handleFormConfigOptionSelected({detail:i}){this.configSelected=i,await this.loadConfigByUser(),this.selectedGuide=void 0,this.optionConfigChanged=!o.equals(this.configSelected,this.originalConfigSelected),this.configSelected.origin===b.DEFAULT&&(this.hasChanges=!1)}async handleAddFieldToGuide({detail:i}){var t;this.selectedGuide?(this.availableFields=[...this.availableFields.filter((t=>t.name!==i.name))],await(null===(t=this.refFieldsLayout)||void 0===t?void 0:t.addFieldToLayout(i))):this.showNoGuideSelectedDialog()}async handleSetFieldAsAvailable({detail:i}){this.availableFields.some((t=>t.name===i.name))||(this.availableFields=[...this.availableFields,i])}async handleRemoveFieldFromAvailable({detail:i}){this.availableFields=this.availableFields.filter((t=>t.name!==i.name))}observeSelectedGuide(i){var t;const s=null!==(t=this.guidesMap.get(null==i?void 0:i.name))&&void 0!==t?t:[];this.groupsList=[...s]}observeConfigManager(){this.loadFormConfig()}showNoGuideSelectedDialog(){const i=this.getMessage("snkFormConfig.noGuideSelected.title"),t=this.getMessage("snkFormConfig.noGuideSelected.message");C.alert(i,t)}getMessage(i,t){return this.messagesBuilder.getMessage(i,t)}async initializeUserConfig(){if(null!=this.configManager)try{const i=await this.configManager.fetchUserAvailableConfigs();this.configOptions=i;const t=null==this._formConfig||this._formConfig.defaultConfiguration?b.DEFAULT:b.USER;this.configSelected=i.find((i=>i.origin===t)),this.originalConfigSelected=i.find((i=>i.origin===t))}catch(i){console.error("Falha ao buscar configurações de formulário definida pelo usuário."),console.error(i)}}async loadConfigByUser(){this.configManager&&this.configSelected&&(this.isConfigDefaultSelected()?await this.handleLoadDefaultConfig():this.loadFormConfig())}async handleLoadDefaultConfig(){const i=await this.configManager.fetchDefaultConfig();if(i)return void this.loadFormConfig(i);const t=this.configManager.getEmptyConfig();t&&this.loadFormConfig(t)}isConfigDefaultSelected(){return this.configSelected.origin===b.DEFAULT}loadFormConfig(i){this._formConfig=i||this.getConfig(),this.loadGuides(),this.initializeAvailableFields()}initializeAvailableFields(){var i;if(null==(null===(i=this._formConfig)||void 0===i?void 0:i.fields))return;const t=[...this._formConfig.fields];this.availableFields=this.dataUnit.metadata.fields.filter((({name:i,visible:s,properties:e})=>{const h=t.some((({name:t})=>t===i));return h||!0!==e.visibleOnConfig||s?!0===s&&!1===h:e.visibleOnConfig}))}loadGuides(){var i;this.guidesList=[...c(this._formConfig,this.getMessage("snkFormConfig.form.mainArea"))],this.guidesMap=f(null===(i=this._formConfig)||void 0===i?void 0:i.fields,this.guidesList,this.dataUnit,this.getMessage("snkFormConfig.form.tabGeneral"))}getConfig(){let i=this.configManager.getConfig(this.dataUnit,!1);return i.fields&&0===i.fields.length&&(i=void 0),null==i&&(i=r(this.dataUnit)),o.copy(i)}handleSelectGuide({detail:i}){this.selectedGuide=i}handleLayoutChanged({detail:i}){this.hasChanges=!0,this.groupsList=[...i],this.guidesMap.set(this.selectedGuide.name,[...i])}getIsDefaultConfig(){var i;return(null===(i=this.configSelected)||void 0===i?void 0:i.origin)===b.DEFAULT&&!0===this.optionConfigChanged&&!1===this.hasChanges}getTabsToSave(){return this.guidesList.map((i=>({name:i.name,label:i.name===v.main?i.name:i.label,order:i.name===v.main?0:i.order,visible:i.visible})))}async handleSaveConfig(){var i;const t=await this.configManager.saveConfig(this.buildConfigToSave());this.configSelected=null===(i=this.configOptions)||void 0===i?void 0:i.find((i=>i.origin===(this.hasChanges?b.USER:b.DEFAULT))),this.originalConfigSelected=this.configSelected,this.hasChanges=!1,this.optionConfigChanged=!1,C.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"),{iconName:"check"}),this.configChange.emit(t)}buildConfigToSave(){if(this.getIsDefaultConfig()){const i=this._formConfig;return i.defaultConfiguration=!0,i}const i=o.copy(this._formConfig);return i.tabs=this.getTabsToSave(),i.fields=g(this.guidesMap),i.defaultConfiguration=!1,i}handleAvailableFieldListChanged({detail:i}){this.availableFields=[...i]}handleSetFieldListAsAvailable({detail:i}){this.availableFields=[...this.availableFields,...i]}handleGuideDeleted({detail:i}){var t,s;const e=i.name,h=null!==(t=this.guidesMap.get(e))&&void 0!==t?t:[],a=[];h.forEach((i=>a.push(...i.fields))),this.availableFields=[...this.availableFields,...a],this.guidesList=[...this.guidesList.filter((i=>i.name!==e))],this.guidesMap.delete(e),(null===(s=this.selectedGuide)||void 0===s?void 0:s.name)===e&&(this.selectedGuide=void 0),this.hasChanges=!0}handleGuideListChanged({detail:i}){this.hasChanges=!0,this.guidesList=[...i]}handleGuideRenamed({detail:i}){var t;const s=null!==(t=this.guidesMap.get(this.selectedGuide.name))&&void 0!==t?t:[],e=u(s,i);this.guidesMap.delete(this.selectedGuide.name),this.guidesMap.set(i,e);const h={name:i,label:i,visible:this.selectedGuide.visible,order:this.selectedGuide.order};this.guidesList=[...this.guidesList.map((i=>i.name===this.selectedGuide.name?h:i))],this.groupsList=[...e],this.selectedGuide=h,this.hasChanges=!0}handleCreateNewGuide(){const i=m(this.guidesList),t={name:i,label:i,visible:!0,order:this.guidesList.length+1},s={name:p.noGroup,fields:[]};this.guidesList=[...this.guidesList,t],this.guidesMap.set(i,[s]),this.selectedGuide=t,this.hasChanges=!0}getGuideNames(){return[...this.guidesList.map((i=>i.name.toLowerCase())),this.getMessage("snkFormConfig.form.mainArea").toLowerCase()]}async componentWillRender(){if(null==this.messagesBuilder){const i=n.getContextValue("__SNK__APPLICATION__");this.messagesBuilder=i.messagesBuilder}}async componentWillLoad(){this.loadFormConfig(),await this.initializeUserConfig()}render(){return s(h,null,s("config-header",{configOptions:this.configOptions,selectedConfig:this.configSelected,messagesBuilder:this.messagesBuilder,hasChanges:this.hasChanges,optionConfigChanged:this.optionConfigChanged,onConfigClose:()=>this.configClose.emit(),onSaveConfig:async()=>await this.handleSaveConfig()}),s("div",{class:"ez-padding--medium"},s("div",{class:"ez-flex sidebarNavigator__container"},s("guides-configurator",{messagesBuilder:this.messagesBuilder,guidesList:this.guidesList,selectedGuide:this.selectedGuide,onGuideSelected:this.handleSelectGuide.bind(this),onGuideListChanged:this.handleGuideListChanged.bind(this),onCreateNewGuide:this.handleCreateNewGuide.bind(this),onGuideDeleted:this.handleGuideDeleted.bind(this)}),s("fields-layout",{ref:i=>this.refFieldsLayout=i,selectedGuide:this.selectedGuide,guideNames:this.getGuideNames(),groupsList:this.groupsList,messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,onGuideRenamed:this.handleGuideRenamed.bind(this),onLayoutChanged:this.handleLayoutChanged.bind(this),onSetFieldListAsAvailable:this.handleSetFieldListAsAvailable.bind(this)}),s("fields-selector",{dataUnit:this.dataUnit,availableFields:this.availableFields,onFieldListChanged:this.handleAvailableFieldListChanged.bind(this)}))))}static get watchers(){return{selectedGuide:["observeSelectedGuide"],configManager:["observeConfigManager"]}}};k.style='.sc-snk-form-config-h{display:flex;flex-direction:column;height:100vh;width:100vw;font-family:var(--font-pattern, "Roboto");background:white;color:#2b3a54;--snk-form-config-container-height:calc(100vh - 95px);outline:none}.sidebarNavigator__container.sc-snk-form-config{height:var(--snk-form-config-container-height);gap:20px;align-items:flex-start}.guide-header.sc-snk-form-config{display:flex;width:100%;padding-bottom:12px;border-bottom:1px solid #dce0e8;height:30px;font-weight:500;font-size:16px}';export{y as snk_form,k as snk_form_config}