@sankhyalabs/sankhyablocks 8.16.0-dev.39 → 8.16.0-dev.40
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/index-f9e81701.js +8 -28
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/sankhyablocks.cjs.js +1 -1
- package/dist/cjs/{snk-form-config.cjs.entry.js → snk-config-options_3.cjs.entry.js} +363 -1
- package/dist/cjs/{snk-filter-bar.cjs.entry.js → snk-filter-bar_4.cjs.entry.js} +685 -0
- package/dist/cjs/snk-simple-crud.cjs.entry.js +3 -1
- package/dist/collection/collection-manifest.json +11 -31
- package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +3 -1
- package/dist/collection/sw.js +46 -0
- package/dist/components/snk-simple-crud2.js +3 -1
- package/dist/esm/{SnkFormConfigManager-139f09fa.js → SnkFormConfigManager-f1a0fc92.js} +1 -1
- package/dist/esm/{constants-8457af36.js → constants-7302ee87.js} +1 -1
- package/dist/esm/index-a7d3d3f1.js +8 -28
- package/dist/esm/loader.js +1 -1
- package/dist/esm/sankhyablocks.js +1 -1
- package/dist/esm/snk-actions-button_4.entry.js +1 -1
- package/dist/esm/snk-attach.entry.js +1 -1
- package/dist/esm/{snk-form-config.entry.js → snk-config-options_3.entry.js} +364 -4
- package/dist/esm/snk-configurator.entry.js +1 -1
- package/dist/esm/snk-crud.entry.js +1 -1
- package/dist/esm/snk-data-exporter.entry.js +1 -1
- package/dist/esm/snk-detail-view.entry.js +3 -3
- package/dist/esm/snk-field-config.entry.js +1 -1
- package/dist/esm/{snk-filter-bar.entry.js → snk-filter-bar_4.entry.js} +684 -2
- package/dist/esm/{snk-guides-viewer-c1ef991c.js → snk-guides-viewer-2f4dcdc5.js} +2 -2
- package/dist/esm/snk-guides-viewer.entry.js +3 -3
- package/dist/esm/snk-simple-crud.entry.js +5 -3
- package/dist/esm/snk-tab-config.entry.js +1 -1
- package/dist/sankhyablocks/p-052213ba.entry.js +1 -0
- package/dist/sankhyablocks/{p-11a0a7ac.entry.js → p-0b6cd238.entry.js} +1 -1
- package/dist/sankhyablocks/p-0e320bd2.entry.js +1 -0
- package/dist/sankhyablocks/{p-281bc322.entry.js → p-275de842.entry.js} +1 -1
- package/dist/sankhyablocks/{p-8eb67fa4.entry.js → p-2d3f9482.entry.js} +1 -1
- package/dist/sankhyablocks/{p-7663f597.entry.js → p-41793e17.entry.js} +1 -1
- package/dist/sankhyablocks/{p-1b6d51bf.entry.js → p-5e51e833.entry.js} +1 -1
- package/dist/sankhyablocks/{p-d3341910.entry.js → p-72c10005.entry.js} +1 -1
- package/dist/sankhyablocks/{p-11cc69fc.js → p-7bd9683d.js} +1 -1
- package/dist/sankhyablocks/{p-95df461f.entry.js → p-8b4fc28f.entry.js} +1 -1
- package/dist/sankhyablocks/{p-b0ef4383.js → p-95ce311a.js} +1 -1
- package/dist/sankhyablocks/{p-5ea74956.entry.js → p-ab1645fb.entry.js} +1 -1
- package/dist/sankhyablocks/{p-47f79aa0.entry.js → p-cefb0ee1.entry.js} +1 -1
- package/dist/sankhyablocks/p-fa6c5826.entry.js +1 -0
- package/dist/sankhyablocks/{p-afbb070d.js → p-fadc8339.js} +1 -1
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/package.json +3 -2
- package/dist/cjs/snk-config-options.cjs.entry.js +0 -239
- package/dist/cjs/snk-filter-item.cjs.entry.js +0 -312
- package/dist/cjs/snk-filter-list.cjs.entry.js +0 -152
- package/dist/cjs/snk-filter-modal.cjs.entry.js +0 -249
- package/dist/cjs/snk-form.cjs.entry.js +0 -144
- package/dist/esm/snk-config-options.entry.js +0 -235
- package/dist/esm/snk-filter-item.entry.js +0 -308
- package/dist/esm/snk-filter-list.entry.js +0 -148
- package/dist/esm/snk-filter-modal.entry.js +0 -245
- package/dist/esm/snk-form.entry.js +0 -140
- package/dist/sankhyablocks/p-06898e5a.entry.js +0 -1
- package/dist/sankhyablocks/p-3b60db06.entry.js +0 -1
- package/dist/sankhyablocks/p-60b29483.entry.js +0 -1
- package/dist/sankhyablocks/p-70a4af56.entry.js +0 -1
- package/dist/sankhyablocks/p-b9679243.entry.js +0 -1
- package/dist/sankhyablocks/p-d3f53df2.entry.js +0 -1
- package/dist/sankhyablocks/p-e8763234.entry.js +0 -1
- package/dist/sankhyablocks/p-feba9d4b.entry.js +0 -1
@@ -1,245 +0,0 @@
|
|
1
|
-
import { r as registerInstance, h } from './index-a7d3d3f1.js';
|
2
|
-
import { ModalAction } from '@sankhyalabs/ezui/dist/collection/components/ez-modal-container';
|
3
|
-
import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
|
4
|
-
import { F as FilterType } from './filter-type.enum-a80c1b6b.js';
|
5
|
-
import { F as FilterItemType } from './filter-item-type.enum-d45e026f.js';
|
6
|
-
import { ObjectUtils } from '@sankhyalabs/core';
|
7
|
-
import { P as PersonalizedFilterUtils } from './PersonalizedFilterUtils-e2b38ef7.js';
|
8
|
-
import { F as FilterNumberVariation } from './filterNumberVariation-8cee02ea.js';
|
9
|
-
import './index-ae591a44.js';
|
10
|
-
|
11
|
-
const snkFilterModalCss = "ez-modal{--ez-modal-content-padding:24px 12px}.snk-filter-modal__container{width:344px;max-width:344px;min-width:344px;overflow:hidden}.snk-filter-modal__content{display:flex;flex-direction:column;gap:var(--space--medium, 12px);padding-right:var(--space--3xs, 4px)}.snk-filter-modal__collapsible-box{border:var(--border--small, 1px solid) var(--color--strokes, #DCE0E8);border-radius:var(--border--radius-medium);padding:var(--space--medium, 12px) var(--space--small, 6px)}.snk-filter-modal__rendered-items{max-height:760px;overflow-x:clip;overflow-y:auto}.snk-filter-modal__rendered-items::-webkit-scrollbar{width:var(--space--small);min-width:var(--space--small);max-width:var(--space--small)}";
|
12
|
-
|
13
|
-
const SnkFilterModal = class {
|
14
|
-
constructor(hostRef) {
|
15
|
-
registerInstance(this, hostRef);
|
16
|
-
this.getMessage = undefined;
|
17
|
-
this.configName = undefined;
|
18
|
-
this.filters = undefined;
|
19
|
-
this.applyFilters = undefined;
|
20
|
-
this.closeModal = undefined;
|
21
|
-
this.addPersonalizedFilter = undefined;
|
22
|
-
this.editPersonalizedFilter = undefined;
|
23
|
-
this.deletePersonalizedFilter = undefined;
|
24
|
-
this.filtersToDelete = [];
|
25
|
-
this.disablePersonalizedFilter = undefined;
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* Emitido quando um filtro personalizado é deletado.
|
29
|
-
*/
|
30
|
-
deletePersonalizedFilterListener(event) {
|
31
|
-
this.filtersToDelete.push(event.detail);
|
32
|
-
}
|
33
|
-
getCustomMessage(key, params) {
|
34
|
-
var _a;
|
35
|
-
return (_a = this.getMessage) === null || _a === void 0 ? void 0 : _a.call(this, `snkFilterBar.filterModal.${key}`, params);
|
36
|
-
}
|
37
|
-
//TODO: tratar clear all dos filtros personalizados
|
38
|
-
handleClearAll() {
|
39
|
-
const { customFilters, quickFilters, otherFilters, multiListFilters } = this.filters.reduce((acc, filter) => {
|
40
|
-
if (filter.type === FilterItemType.MULTI_LIST) {
|
41
|
-
acc.multiListFilters.push(filter);
|
42
|
-
return acc;
|
43
|
-
}
|
44
|
-
if (filter.filterType === FilterType.QUICK_FILTER) {
|
45
|
-
acc.quickFilters.push(filter);
|
46
|
-
return acc;
|
47
|
-
}
|
48
|
-
if (filter.filterType === FilterType.CUSTOM_FILTER) {
|
49
|
-
acc.customFilters.push(filter);
|
50
|
-
return acc;
|
51
|
-
}
|
52
|
-
if (filter.filterType === FilterType.OTHER_FILTERS) {
|
53
|
-
acc.otherFilters.push(filter);
|
54
|
-
return acc;
|
55
|
-
}
|
56
|
-
return acc;
|
57
|
-
}, { quickFilters: [], customFilters: [], otherFilters: [], multiListFilters: [] });
|
58
|
-
this.handleClearFilterList(quickFilters);
|
59
|
-
this.handleClearCustomFilters(customFilters);
|
60
|
-
this.handleClearOthersFilters(otherFilters);
|
61
|
-
multiListFilters.forEach(multiListFilter => this.handleClearSigleFilter(multiListFilter));
|
62
|
-
}
|
63
|
-
handleClearOthersFilters(otherFilters) {
|
64
|
-
this.filters = this.filters.map(filter => otherFilters.includes(filter) ? (Object.assign(Object.assign({}, filter), { value: undefined })) : filter);
|
65
|
-
}
|
66
|
-
handleClearCustomFilters(customFilters) {
|
67
|
-
this.filters.forEach((filter, index) => {
|
68
|
-
if (filter.filterType === FilterType.CUSTOM_FILTER)
|
69
|
-
this.filters[index] = this.clearAllCustomFilter(customFilters).shift();
|
70
|
-
});
|
71
|
-
}
|
72
|
-
clearAllCustomFilter(filterConfigSnapshot) {
|
73
|
-
return filterConfigSnapshot.map(filterItem => {
|
74
|
-
const copy = Object.assign({}, filterItem);
|
75
|
-
delete copy.value;
|
76
|
-
copy.visible = false;
|
77
|
-
if (copy.groupedItems) {
|
78
|
-
copy.groupedItems = this.clearAllCustomFilter(copy.groupedItems);
|
79
|
-
}
|
80
|
-
return copy;
|
81
|
-
});
|
82
|
-
}
|
83
|
-
handleClose() {
|
84
|
-
const hasChangesToSave = ObjectUtils.objectToString(this.filters) !== ObjectUtils.objectToString(this._originalFilterConfig);
|
85
|
-
if (!hasChangesToSave) {
|
86
|
-
this.closeModal();
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
return ApplicationUtils.confirm(this.getCustomMessage('validations.notSaved.title'), this.getCustomMessage('validations.notSaved.message')).then((cancelAction) => {
|
90
|
-
if (cancelAction)
|
91
|
-
this.closeModal();
|
92
|
-
});
|
93
|
-
}
|
94
|
-
handleApplyFilters() {
|
95
|
-
const filterPersonalized = this.filters.find(filter => filter.filterType === FilterType.CUSTOM_FILTER);
|
96
|
-
if (this.isValidCustomFilter(filterPersonalized)) {
|
97
|
-
this.applyFilters(this.filters);
|
98
|
-
}
|
99
|
-
if (this.filtersToDelete.length > 0) {
|
100
|
-
this.filtersToDelete.forEach(filter => {
|
101
|
-
this.deletePersonalizedFilter(filter, this.configName);
|
102
|
-
});
|
103
|
-
this.filtersToDelete = [];
|
104
|
-
}
|
105
|
-
}
|
106
|
-
isValidCustomFilter(filterPersonalized) {
|
107
|
-
const isValid = PersonalizedFilterUtils.validateVariableValues(filterPersonalized);
|
108
|
-
if (!isValid) {
|
109
|
-
ApplicationUtils.alert(this.getCustomMessage('validations.notFullFilled.title'), this.getCustomMessage('validations.notFullFilled.message'));
|
110
|
-
return false;
|
111
|
-
}
|
112
|
-
return true;
|
113
|
-
}
|
114
|
-
modalActionListener(evt) {
|
115
|
-
const modalAction = evt.detail;
|
116
|
-
switch (modalAction) {
|
117
|
-
case ModalAction.CANCEL:
|
118
|
-
this.handleClearAll();
|
119
|
-
break;
|
120
|
-
case ModalAction.OK:
|
121
|
-
this.handleApplyFilters();
|
122
|
-
break;
|
123
|
-
case ModalAction.CLOSE:
|
124
|
-
this.handleClose();
|
125
|
-
break;
|
126
|
-
}
|
127
|
-
}
|
128
|
-
handleFilterChange(filterConfig) {
|
129
|
-
this.filters = this.filters.map(filter => filter.id === filterConfig.id ? filterConfig : filter);
|
130
|
-
}
|
131
|
-
handleClearFilterList(filterList) {
|
132
|
-
this.filters = this.filters.map(filter => filterList.includes(filter) ? (Object.assign(Object.assign({}, filter), { value: undefined })) : filter);
|
133
|
-
}
|
134
|
-
handleClearSigleFilter(filterItem) {
|
135
|
-
if (FilterItemType.MULTI_LIST === filterItem.type) {
|
136
|
-
let filterItemCopy = ObjectUtils.copy(filterItem);
|
137
|
-
this.uncheckFilterValues(filterItemCopy.value);
|
138
|
-
const filterListCopy = ObjectUtils.copy(this.filters);
|
139
|
-
const index = filterListCopy.findIndex(item => item.id === filterItem.id);
|
140
|
-
filterListCopy.splice(index, 1, filterItemCopy);
|
141
|
-
this.filters = ObjectUtils.copy(filterListCopy);
|
142
|
-
return;
|
143
|
-
}
|
144
|
-
if (FilterItemType.CHECK_BOX_LIST === filterItem.type) {
|
145
|
-
const filterListCopy = ObjectUtils.copy(this.filters);
|
146
|
-
filterListCopy.find(filter => filter.id === filterItem.id).value = undefined;
|
147
|
-
this.filters = ObjectUtils.copy(filterListCopy);
|
148
|
-
return;
|
149
|
-
}
|
150
|
-
this.filters.find(filter => filter.id === filterItem.id).value = undefined;
|
151
|
-
}
|
152
|
-
uncheckFilterValues(valueList) {
|
153
|
-
valueList.forEach(value => {
|
154
|
-
if (!!value) {
|
155
|
-
value.check = false;
|
156
|
-
}
|
157
|
-
});
|
158
|
-
return valueList;
|
159
|
-
}
|
160
|
-
renderFilterItem(filterItem, fullRow) {
|
161
|
-
return (h("snk-filter-modal-item", { class: fullRow ? 'ez-col ez-col--sd-12' : 'ez-col ez-col--sd-6 ez-padding--small', filterItem: filterItem, configName: this.configName, onFilterChange: (event) => this.handleFilterChange(event.detail), onEditPersonalizedFilter: evt => this.editPersonalizedFilter(evt.detail), onAddPersonalizedFilter: () => this.addPersonalizedFilter() }));
|
162
|
-
}
|
163
|
-
isDefaultFilterNumberVariation(filter) {
|
164
|
-
var _a;
|
165
|
-
return filter.type === FilterItemType.NUMBER
|
166
|
-
&& (!filter.props.variation || ((_a = filter.props) === null || _a === void 0 ? void 0 : _a.variation) === FilterNumberVariation.DEFAULT);
|
167
|
-
}
|
168
|
-
mountFiltersLines(filters) {
|
169
|
-
const MAX_LINE_LENGTH = 2;
|
170
|
-
let currentLine = 0;
|
171
|
-
let forceAddCurrent = false;
|
172
|
-
const filtersLines = {};
|
173
|
-
for (let curr = 0; curr < filters.length; curr++) {
|
174
|
-
filtersLines[currentLine] = filtersLines[currentLine] || [];
|
175
|
-
const item = filters[curr];
|
176
|
-
const isLast = curr === filters.length - 1;
|
177
|
-
const currentItemMatch = item.type === FilterItemType.TEXT || this.isDefaultFilterNumberVariation(item);
|
178
|
-
const nextItemMatch = isLast ? false : filters[curr + 1].type === FilterItemType.TEXT || this.isDefaultFilterNumberVariation(filters[curr + 1]);
|
179
|
-
if ((currentItemMatch && nextItemMatch) || forceAddCurrent) {
|
180
|
-
filtersLines[currentLine].push(item);
|
181
|
-
forceAddCurrent = filtersLines[currentLine].length < MAX_LINE_LENGTH;
|
182
|
-
if (filtersLines[currentLine].length === MAX_LINE_LENGTH)
|
183
|
-
++currentLine;
|
184
|
-
continue;
|
185
|
-
}
|
186
|
-
filtersLines[currentLine] = filtersLines[currentLine] || [];
|
187
|
-
filtersLines[currentLine].push(item);
|
188
|
-
++currentLine;
|
189
|
-
}
|
190
|
-
return Object.values(filtersLines);
|
191
|
-
}
|
192
|
-
renderFilterLine(filters) {
|
193
|
-
const fullLine = filters.length === 1;
|
194
|
-
return filters.map((filter) => this.renderFilterItem(filter, fullLine));
|
195
|
-
}
|
196
|
-
getIformedFiltersCount(listItems) {
|
197
|
-
let countInformedItens = 0;
|
198
|
-
listItems.forEach(item => {
|
199
|
-
var _a, _b, _c, _d, _e, _f;
|
200
|
-
if (FilterItemType.MULTI_LIST === item.type) {
|
201
|
-
countInformedItens += (_e = (_d = (_c = ((_b = (_a = item.value) === null || _a === void 0 ? void 0 : _a.elements) !== null && _b !== void 0 ? _b : item.value)) === null || _c === void 0 ? void 0 : _c.filter(value => value === null || value === void 0 ? void 0 : value.check)) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0;
|
202
|
-
return;
|
203
|
-
}
|
204
|
-
if (FilterItemType.CHECK_BOX_LIST === item.type) {
|
205
|
-
countInformedItens += Object.entries((_f = item.value) !== null && _f !== void 0 ? _f : {})
|
206
|
-
.filter(([_, value]) => value === true)
|
207
|
-
.map(([key, _]) => key).length;
|
208
|
-
return;
|
209
|
-
}
|
210
|
-
if (item.groupedItems != undefined) {
|
211
|
-
countInformedItens = item.groupedItems.filter(item => item.visible).length;
|
212
|
-
return;
|
213
|
-
}
|
214
|
-
if (!!item.value) {
|
215
|
-
countInformedItens++;
|
216
|
-
}
|
217
|
-
});
|
218
|
-
return countInformedItens;
|
219
|
-
}
|
220
|
-
renderCollapsibleFilterBox(label, listItems, isSingleItem, shouldRenderFooter = true) {
|
221
|
-
if (!listItems.length)
|
222
|
-
return null;
|
223
|
-
const appliedFilters = this.getIformedFiltersCount(listItems);
|
224
|
-
const lines = this.mountFiltersLines(listItems);
|
225
|
-
return (h("ez-collapsible-box", { class: "snk-filter-modal__collapsible-box", headerSize: "medium", value: true, label: label }, !!appliedFilters && (h("ez-badge", { class: "ez-badge--primary-subtle", slot: "rightSlot", label: appliedFilters === null || appliedFilters === void 0 ? void 0 : appliedFilters.toString() })), h("div", { class: "ez-row snk-filter-modal__rendered-items" }, lines.map(this.renderFilterLine.bind(this))), shouldRenderFooter && (h("div", { class: "ez-flex ez-flex--justify-end grow" }, h("ez-button", { class: "ez-button--tertiary", size: "medium", label: "Limpar", onClick: () => isSingleItem ? this.handleClearSigleFilter(listItems[0]) : this.handleClearFilterList(listItems) })))));
|
226
|
-
}
|
227
|
-
componentWillRender() {
|
228
|
-
this._modalTitle = this.getCustomMessage('title');
|
229
|
-
this._okButtonLabel = this.getCustomMessage('okButtonLabel');
|
230
|
-
this._cancelButtonLabel = this.getCustomMessage('cancelButtonLabel');
|
231
|
-
}
|
232
|
-
componentDidLoad() {
|
233
|
-
if (!this._originalFilterConfig)
|
234
|
-
this._originalFilterConfig = this.filters;
|
235
|
-
}
|
236
|
-
render() {
|
237
|
-
const customFilters = this.filters.filter(filter => filter.filterType === FilterType.CUSTOM_FILTER);
|
238
|
-
const quickFilters = this.filters.filter(filter => filter.filterType === FilterType.QUICK_FILTER);
|
239
|
-
const otherFilters = this.filters.filter(filter => filter.filterType === FilterType.OTHER_FILTERS);
|
240
|
-
return (h("ez-modal-container", { class: "snk-filter-modal__container", modalTitle: this._modalTitle, cancelButtonLabel: this._cancelButtonLabel, okButtonLabel: this._okButtonLabel, onEzModalAction: this.modalActionListener.bind(this) }, h("div", { class: "snk-filter-modal__content ez-col--sd-12" }, !this.disablePersonalizedFilter && this.renderCollapsibleFilterBox(this.getCustomMessage('customFilters'), customFilters, false, false), this.renderCollapsibleFilterBox(this.getCustomMessage('quickFilters'), quickFilters, false), otherFilters.map(filter => this.renderCollapsibleFilterBox(filter.label, [filter], true)))));
|
241
|
-
}
|
242
|
-
};
|
243
|
-
SnkFilterModal.style = snkFilterModalCss;
|
244
|
-
|
245
|
-
export { SnkFilterModal as snk_filter_modal };
|
@@ -1,140 +0,0 @@
|
|
1
|
-
import { r as registerInstance, c as createEvent, h, g as getElement } from './index-a7d3d3f1.js';
|
2
|
-
import { ElementIDUtils } from '@sankhyalabs/core';
|
3
|
-
import { S as SnkFormConfigManager } from './SnkFormConfigManager-139f09fa.js';
|
4
|
-
import { R as ResourceIDUtils } from './ResourceIDUtils-a114189a.js';
|
5
|
-
import './ConfigStorage-7b36d041.js';
|
6
|
-
import './form-config-fetcher-adbe5d34.js';
|
7
|
-
import './DataFetcher-a9c598f2.js';
|
8
|
-
import './PrintUtils-3e4ff0f5.js';
|
9
|
-
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
10
|
-
import './filter-item-type.enum-d45e026f.js';
|
11
|
-
import './constants-8457af36.js';
|
12
|
-
|
13
|
-
const snkFormCss = ".sc-snk-form-h{--snk-form__header--min-height:94px;display:block}.snk-form__form--hidden.sc-snk-form{display:none}";
|
14
|
-
|
15
|
-
const SnkForm = class {
|
16
|
-
constructor(hostRef) {
|
17
|
-
registerInstance(this, hostRef);
|
18
|
-
this.exit = createEvent(this, "exit", 7);
|
19
|
-
this.actionClick = createEvent(this, "actionClick", 7);
|
20
|
-
this.formItemsReady = createEvent(this, "formItemsReady", 7);
|
21
|
-
this._customEditors = new Map();
|
22
|
-
this._dataUnit = undefined;
|
23
|
-
this._dataState = undefined;
|
24
|
-
this._showFormConfig = false;
|
25
|
-
this._configManager = undefined;
|
26
|
-
this.configName = undefined;
|
27
|
-
this.recordsValidator = undefined;
|
28
|
-
this.messagesBuilder = undefined;
|
29
|
-
this.formLegacyConfigName = undefined;
|
30
|
-
this.resourceID = undefined;
|
31
|
-
}
|
32
|
-
/**
|
33
|
-
* Exibe a janela de configurações do formulário.
|
34
|
-
*/
|
35
|
-
async showConfig() {
|
36
|
-
this._showFormConfig = true;
|
37
|
-
}
|
38
|
-
/**
|
39
|
-
* Fecha a janela de configurações do formulário.
|
40
|
-
*/
|
41
|
-
async hideConfig() {
|
42
|
-
this._showFormConfig = false;
|
43
|
-
}
|
44
|
-
/**
|
45
|
-
* Registra um editor customizado para campos da grade e formulário.
|
46
|
-
*/
|
47
|
-
async addCustomEditor(fieldName, customEditor) {
|
48
|
-
if (this._form) {
|
49
|
-
this._form.addCustomEditor(fieldName, customEditor);
|
50
|
-
return;
|
51
|
-
}
|
52
|
-
const newCustomEditors = new Map(this._customEditors);
|
53
|
-
newCustomEditors.set(fieldName, customEditor);
|
54
|
-
this._customEditors = newCustomEditors;
|
55
|
-
}
|
56
|
-
/**
|
57
|
-
* Altera/adiciona uma propriedade nos metadados do campo.
|
58
|
-
*/
|
59
|
-
async setFieldProp(fieldName, propName, value) {
|
60
|
-
await this._form.setFieldProp(fieldName, propName, value);
|
61
|
-
}
|
62
|
-
closeConfig() {
|
63
|
-
this.hideConfig();
|
64
|
-
}
|
65
|
-
dataunitReady() {
|
66
|
-
const dataInfo = { dataUnit: this._dataUnit };
|
67
|
-
ElementIDUtils.addIDInfo(this._element, null, dataInfo);
|
68
|
-
}
|
69
|
-
setCustomEditors() {
|
70
|
-
if (!this._form) {
|
71
|
-
return;
|
72
|
-
}
|
73
|
-
for (const [fieldName, customEditor] of this._customEditors) {
|
74
|
-
this._form.addCustomEditor(fieldName, customEditor);
|
75
|
-
this._customEditors.delete(fieldName);
|
76
|
-
}
|
77
|
-
}
|
78
|
-
async componentDidRender() {
|
79
|
-
this.setCustomEditors();
|
80
|
-
}
|
81
|
-
async componentWillLoad() {
|
82
|
-
let parent = this._element.parentElement;
|
83
|
-
while (parent) {
|
84
|
-
if (parent.tagName.toUpperCase() === "SNK-DATA-UNIT") {
|
85
|
-
this._snkDataUnit = parent;
|
86
|
-
this._dataUnit = this._snkDataUnit.dataUnit;
|
87
|
-
this._dataState = this._snkDataUnit.dataState;
|
88
|
-
if (this._dataUnit) {
|
89
|
-
this.dataunitReady();
|
90
|
-
}
|
91
|
-
else {
|
92
|
-
this._snkDataUnit.addEventListener("dataUnitReady", (evt) => {
|
93
|
-
this._dataUnit = evt.detail;
|
94
|
-
});
|
95
|
-
}
|
96
|
-
this._snkDataUnit.addEventListener("dataStateChange", this.handleDataStateChange.bind(this));
|
97
|
-
break;
|
98
|
-
}
|
99
|
-
parent = parent.parentElement;
|
100
|
-
}
|
101
|
-
if (this.resourceID == undefined) {
|
102
|
-
this.resourceID = await ResourceIDUtils.getResourceID();
|
103
|
-
}
|
104
|
-
this._configManager = new SnkFormConfigManager(this.configName, this.resourceID, undefined, this._dataUnit);
|
105
|
-
this.addFormLegacyConfig();
|
106
|
-
await this._configManager.loadConfig();
|
107
|
-
}
|
108
|
-
async handleDataStateChange(evt) {
|
109
|
-
var _a;
|
110
|
-
this._dataState = evt.detail;
|
111
|
-
const fieldsWithRmPrecision = await this._snkDataUnit.getFieldsWithRmPrecision();
|
112
|
-
for (const field of fieldsWithRmPrecision || []) {
|
113
|
-
if (!field) {
|
114
|
-
continue;
|
115
|
-
}
|
116
|
-
const rmPrecision = (_a = this._dataState.rowMetadata) === null || _a === void 0 ? void 0 : _a.getProp('rm_precision', field);
|
117
|
-
if (!rmPrecision && rmPrecision !== 0) {
|
118
|
-
continue;
|
119
|
-
}
|
120
|
-
await this.setFieldProp(field, 'precision', rmPrecision);
|
121
|
-
await this.setFieldProp(field, 'prettyPrecision', rmPrecision);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
addFormLegacyConfig() {
|
125
|
-
if (this.formLegacyConfigName) {
|
126
|
-
this._configManager.addFormLegacyConfig(this.formLegacyConfigName);
|
127
|
-
}
|
128
|
-
}
|
129
|
-
render() {
|
130
|
-
if (!this._dataUnit || !this._dataState) {
|
131
|
-
return undefined;
|
132
|
-
}
|
133
|
-
return (h("section", null, h("div", { class: "ez-row" }, h("div", { class: "ez-col ez-col--sd-12" }, h("ez-form", { ref: (ref) => this._form = ref, 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 &&
|
134
|
-
h("snk-form-config", { messagesBuilder: this.messagesBuilder, dataUnit: this._dataUnit, configManager: this._configManager, onConfigClose: () => this.closeConfig() })))));
|
135
|
-
}
|
136
|
-
get _element() { return getElement(this); }
|
137
|
-
};
|
138
|
-
SnkForm.style = snkFormCss;
|
139
|
-
|
140
|
-
export { SnkForm as snk_form };
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as i,c as t,h as s,g as e}from"./p-d2d301a6.js";import{UserInterface as n,StringUtils as o,ApplicationContext as h,ObjectUtils as r,DataType as a,JSUtils as d,FloatingManager as l,ElementIDUtils as u}from"@sankhyalabs/core";import{CSSVarsUtils as c}from"@sankhyalabs/ezui/dist/collection/utils";import{d as m,S as v}from"./p-b0ef4383.js";import{T as f}from"./p-7e7a7473.js";import"./p-f3434fc4.js";import"./p-8a9638ae.js";import{C as g,S as p,R as C,b,a as S}from"./p-9f9b99d9.js";import{D as k,P as y}from"./p-30cf616e.js";import"./p-21749402.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{I as w}from"./p-47bce500.js";import"./p-ff1990ad.js";import{F as E}from"./p-06421fdb.js";import{T as _,b as I,o as T}from"./p-23736d75.js";import{C as F}from"./p-4d9549cf.js";import{S as R}from"./p-afbb070d.js";import{g as D}from"./p-7dd49d15.js";import{s as O}from"./p-6dc031de.js";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils/InMemoryFilterColumnDataSource";import"@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";import"@sankhyalabs/core/dist/utils/SortingUtils";import"./p-688dcb4c.js";const z=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","MORE_OPTIONS"],M=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER","MORE_OPTIONS"];class P extends g{getSelectedNumber(){return this.dataUnit.getSelectionInfo().length}getTotalRecords(){var i,t,s;const{total:e}=(null===(i=this.dataUnit)||void 0===i?void 0:i.getPaginationInfo())||{};return null!=e?e:null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.records)||void 0===s?void 0:s.length}getSelectedIDs(){return D(this.dataUnit)}getRecordID(){var i,t,s;return null===(s=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.records)||void 0===t?void 0:t[0])||void 0===s?void 0:s.__record__id__}async getRecords(){if(0===this.dataUnit.records.length)return Promise.resolve([]);const i=this.dataUnit.getSelectionInfo(),t=i.isEmpty()||i.isAllRecords()?await i.getAllRecords():i.records;return Promise.resolve(null==t?[]:t)}getHiddenOptions(){return[k.EXPORT_BY_EMAIL,k.EXPORT_PDF_TO_EMAIL,k.EXPORT_XLS_TO_EMAIL,k.EXPORT_PAGE_TO_PDF,k.EXPORT_PAGE_TO_XLS]}formatValue(i,t){const{id:s,descriptionFrom:e}=t,o=i[e||s];if(null==o)return"";if(null!=e)return o.label;if(this.dataUnit.getField(s).userInterface===n.SEARCH)return o.value;if(t.customFormatter){const s=this.getColumnsState().find((i=>t.id===i.name));return t.customFormatter.format(o,s,i.__record__id__)}return this.dataUnit.getFormattedValue(s,o)}}const L=class{constructor(s){i(this,s),this.dataStateChange=t(this,"dataStateChange",3),this.dataUnitReady=t(this,"dataUnitReady",3),this.actionClick=t(this,"actionClick",7),this.formItemsReady=t(this,"formItemsReady",7),this.configuratorSave=t(this,"configuratorSave",7),this.configuratorCancel=t(this,"configuratorCancel",7),this._multiSelectionListDataSource=new p,this._keyDownHandler=i=>this.keyDownListener(i),this._formConfigFetcher=new E,this._customEditors=new Map,this._customRenders=new Map,this._taskbarProcessor=new _({"snkSimpleCrudTaskbar.form_regular":this.getButtons(!1,[f.GRID_MODE],!0),"snkSimpleCrudTaskbar.grid_regular":this.getButtons(!1,[f.DATA_EXPORTER,f.FORM_MODE]),"snkSimpleCrudTaskbar.form_selected":this.getButtons(!0,[f.GRID_MODE],!0),"snkSimpleCrudTaskbar.grid_selected":this.getButtons(!0,[f.DATA_EXPORTER,f.FORM_MODE]),"snkSimpleCrudTaskbar.finish_edition":this.getFinishEditionButtonsCallback.bind(this)}),this._showPopUpGridConfig=!1,this._showFormConfig=!1,this._currentViewMode=m.GRID,this._config=void 0,this._fieldToGetFocus=void 0,this._customContainerId=`SNK-SIMPLE-CRUD-CUSTOM-CONTAINER-${o.generateUUID()}`,this.dataState=void 0,this.dataUnit=void 0,this.entityName=void 0,this.mode=v.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this._formFields=[],this._fieldsProps=new Map,this._enableContinuousInsert=!0,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.pageSize=150,this.resourceID=void 0,this.enableGridInsert=!1,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.actionsList=void 0,this.configName=void 0,this.showConfiguratorButtons=void 0,this.gridLegacyConfigName=void 0,this.formLegacyConfigName=void 0,this.ignoreReadOnlyFormFields=!1,this.autoFocus=!0,this.domainMessagesBuilder=void 0,this.autoLoad=void 0}async addCustomEditor(i,t){if(this._grid&&this._form)return this._grid.addCustomEditor(i,t),void this._form.addCustomEditor(i,t);const s=new Map(this._customEditors);s.set(i,t),this._customEditors=s}async addGridCustomRender(i,t){if(this._grid)return void this._grid.addGridCustomRender(i,t);const s=new Map(this._customRenders);s.set(i,t),this._customRenders=s}handleResourceIDChanged(i,t){o.isEmpty(i)||i!==t&&(this.loadFormConfig(!0),this.loadGridConfig(!0))}async addCustomValueFormatter(i,t){this._grid.addCustomValueFormatter(i,t)}async removeCustomValueFormatter(i){this._grid.removeCustomValueFormatter(i)}async setFieldProp(i,t,s){const e=new Map(this._fieldsProps),n=this._fieldsProps.get(i);e.set(i,Object.assign(Object.assign({},n),{[t]:s})),this._fieldsProps=e}getFinishEditionButtonsCallback(){const i=["CANCEL","SAVE"];return this.enableGridInsert&&this._currentViewMode!==m.ATTACHMENT&&i.push(this._currentViewMode===m.GRID?f.FORM_MODE:f.GRID_MODE),i}getButtons(i,t,s){let e=i?M:z;return s&&(e=e.filter((i=>i!==f.REFRESH))),this.addConfigButton(this.resolveInMemoryBtns(e).concat(t))}addConfigButton(i){return void 0===this.configName?i:i.concat(f.CONFIGURATOR)}get application(){return h.getContextValue("__SNK__APPLICATION__")}resolveInMemoryBtns(i){const t=[...i];return this.mode===v.IN_MEMORY&&t.splice(1,1),t}async goToView(i){this._currentViewMode=i,this._viewStack&&this._viewStack.show(i)}actionClickListener(i){const t=i.detail;t===f.CONFIGURATOR?this._snkConfigurator.open():t===f.GRID_MODE?this.goToView(m.GRID):t===f.FORM_MODE&&this.goToView(m.FORM),i.stopPropagation()}async onChangeEntityName(i){if(this.dataUnit)return;const t=h.getContextValue("__SNK__APPLICATION__");this.dataUnit=await t.getDataUnit(i,null,null,this.configName)}onModeChange(){this.mode==v.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(i,t){this.handleDataStateChange(i,t)}async observeFormLegacy(i,t){await this.handleUpdateFormLegacyConfig(i,t)}async observeGridLegacy(i,t){await this.handleUpdateGridLegacyConfig(i,t)}async handleDataStateChange(i,t){r.objectToString(t)!=r.objectToString(i)&&this.dataStateChange.emit(i),await this.processRmPrecision()}async processRmPrecision(){var i,t;const s=await this._snkDataUnit.getFieldsWithRmPrecision();for(const e of s||[]){if(!e)continue;const s=null===(t=null===(i=this.dataState)||void 0===i?void 0:i.rowMetadata)||void 0===t?void 0:t.getProp("rm_precision",e);(s||0===s)&&(await this.setFieldProp(e,"precision",s),await this.setFieldProp(e,"prettyPrecision",s))}this._rmPrecisionCustomValueFormatter.setDataState(this.dataState)}async handleUpdateGridLegacyConfig(i,t){null!=i&&i!=t&&this._gridConfigAlreadyLoaded&&await this.loadGridConfig(!0)}async handleUpdateFormLegacyConfig(i,t){null!=i&&i!=t&&this._formConfigAlreadyLoaded&&this.loadFormConfig(!0)}openConfig(i){this._snkConfigurator.close(),i===m.GRID?this.openGridConfig():i===m.FORM&&this.openFormConfig()}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._showPopUpGridConfig=!0}))}async openFormConfig(){var i,t;if(this.formLegacyConfigName){const s=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.formConfigUnavaliable.title",void 0),e=null===(t=this.messagesBuilder)||void 0===t?void 0:t.getMessage("snkSimpleCrud.formConfigUnavaliable.message",void 0);await this.application.alert(s,e)}else this._showFormConfig=!0}addGridLegacyConfigName(){this.gridLegacyConfigName&&this.configName&&F.addGridLegacyConfig(this.configName,this.gridLegacyConfigName)}loadGridConfig(i){if(void 0!==this.configName&&(null==this.gridConfig&&!this._gridConfigAlreadyLoaded||i))return this.addGridLegacyConfigName(),this._gridConfigAlreadyLoaded=!0,new Promise(((i,t)=>{F.loadGridConfig(this.configName,this.resolveResourceID()).then((t=>{this.setGridConfig(t),i()})).catch((i=>{t(i)}))}))}formConfigIsLoaded(){return null!=this.formConfig||this._formConfigAlreadyLoaded}async loadFormConfig(i=!1){if(void 0===this.configName)return;if(null==this._formConfigManager&&(this._formConfigManager=new R(this.configName,this.resolveResourceID(),void 0,this.dataUnit),this._formConfigManager.setConfig(this.formConfig)),this.formConfigIsLoaded()&&!i)return;this._formConfigAlreadyLoaded=!0;let t=await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);if(null!=t)return this._formConfigManager.setConfig(t),void this.setFormConfig(t);this.setFormConfig(await this._formConfigManager.loadConfig())}async componentWillRender(){this._resourceID=await this.application.getResourceID(),this.dataExporterProviderStore(),this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons()),void 0!==this.configName&&(null!=this.gridConfig||this._gridConfigAlreadyLoaded||(await this.addGridLegacyConfigName(),this.loadGridConfig(),this.loadFormConfig()))}componentDidRender(){this._rmPrecisionCustomValueFormatter.setGrid(this._grid),this.addGridCustomValueFormattters(),this.setFieldsProps(),this.setCustomRenders(),this.setCustomEditors()}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource(),this._rmPrecisionCustomValueFormatter=new C,this._continuousInsertUtils=new b(this.application,this.resolveResourceID(),this.configName),this.enableGridInsert&&this._continuousInsertUtils.getConfig().then((i=>this._enableContinuousInsert=i))}componentDidLoad(){c.applyVarsGrid(this._element,this._grid)}setCustomRenders(){if(this._grid)for(const[i,t]of this._customRenders)this._grid.addGridCustomRender(i,t),this._customRenders.delete(i)}setCustomEditors(){if(this._grid&&this._form)for(const[i,t]of this._customEditors)this._grid.addCustomEditor(i,t),this._form.addCustomEditor(i,t),this._customEditors.delete(i)}configDatasource(){this._multiSelectionListDataSource.setApplication(this.application),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}setFieldsProps(){if(this._form)for(const[i,t]of this._fieldsProps){for(const s in t)this._form.setFieldProp(i,s,t[s]);this._fieldsProps.delete(i)}}getTaskBarId(){var i,t;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"snkSimpleCrudTaskbar.finish_edition":(null===(t=this.dataState)||void 0===t?void 0:t.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&this.dataState.selectionInfo.length>0?this._currentViewMode===m.GRID?"snkSimpleCrudTaskbar.grid_selected":"snkSimpleCrudTaskbar.form_selected":this._currentViewMode===m.GRID?"snkSimpleCrudTaskbar.grid_regular":"snkSimpleCrudTaskbar.form_regular"}initInMemoryDataUnit(){this._inMemoryLoader=new w(this._metadata,void 0,{autoLoad:this.autoLoad}),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(i){return this._inMemoryLoader?this._inMemoryLoader.metadata=i:this.dataUnit&&(this.dataUnit.metadata=i),Promise.resolve()}setRecords(i){return this._inMemoryLoader?this._inMemoryLoader.records=i:this.dataUnit&&(this.dataUnit.records=i),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}async openConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.open()}async closeConfigurator(){var i;null===(i=this._snkConfigurator)||void 0===i||i.close()}async updateConfig(){null==this._formConfigManager&&(this._formConfigManager=new R(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}processMetadata(){const i=this._element.querySelectorAll("snk-field-metadata"),t=[],s={fields:[],emptyConfig:!1};i.forEach((i=>{const e={name:i.getAttribute("name")||i.getAttribute("label"),label:i.getAttribute("label"),dataType:a[i.getAttribute("dataType")]||a.TEXT,userInterface:n[i.getAttribute("userInterface")]||n.SHORTTEXT,readOnly:"true"==i.getAttribute("readOnly"),required:"true"==i.getAttribute("required"),tab:i.getAttribute("tab")||void 0,visible:"false"!=i.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),t.push(e)})),t.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:t})}addGridCustomValueFormattters(){var i,t,s;const e=(null===(i=this._metadata)||void 0===i?void 0:i.fields)||(null===(s=null===(t=this.dataUnit)||void 0===t?void 0:t.metadata)||void 0===s?void 0:s.fields);if(!e)return;const n=[];e.forEach((i=>{var t;(null===(t=i.properties)||void 0===t?void 0:t.rm_precision)&&!n.includes(i.name)&&n.push(i.name)})),n.forEach((i=>{this.addCustomValueFormatter(i,this._rmPrecisionCustomValueFormatter)}))}onDataStateChange(i){this.dataState=Object.assign({},i.detail)}getTaskBarDisabledButtons(){var i,t,s,e,n,o;const h=[];return(null===(i=this.dataState)||void 0===i?void 0:i.hasNext)||h.push(f.NEXT),(null===(t=this.dataState)||void 0===t?void 0:t.hasPrevious)||h.push(f.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&h.push(f.FORM_MODE),(null===(o=null===(n=this.dataState)||void 0===n?void 0:n.selectionInfo)||void 0===o?void 0:o.length)>1&&h.push(f.CLONE),h}handleCancelEdit(){var i;(null===(i=this.dataState)||void 0===i?void 0:i.recordsIsEmpty)&&(this.goToView(m.GRID),this.dataUnit.clearSelection())}handleConfiguratorEvent(i,t){i.stopImmediatePropagation(),"SAVE"!==t?this.configuratorCancel.emit():this.configuratorSave.emit()}getColumnSearch(i,t){return null!=this._columnSearch||(this._moreOptions=i,this._columnSearch=I(t,(({argument:i})=>new Promise((t=>{this._grid.filterColumns(i).then((i=>{t(i.filter((i=>!i.hidden)).map((i=>({label:i.label,value:i.name}))))}))}))),(t=>{var s;null!=t&&(this._grid.locateColumn(t.value),null===(s=i.hideActions)||void 0===s||s.call(i))}))),this._columnSearch}onSelectField(i,t){null!=i&&(this._fieldToGetFocus=i.value,t.hideActions())}getFieldSearch(i,t){return null!=this._fieldSearch||(this._moreOptions=i,i.addEventListener("ezPopoverOpen",(()=>this.findField())),this._fieldSearch=I(t,(({argument:i})=>this.fieldsOptionLoader(i)),(t=>this.onSelectField(t,i)))),this._fieldSearch}getFormFields(){var i,t;return null!==(t=null===(i=this.formConfig)||void 0===i?void 0:i.fields)&&void 0!==t?t:this._formFields}handleFormSetFields(i){r.equals(this._formFields,i)||(this._formFields=null!=i?i:[])}fieldsOptionLoader(i){const t=null==i?void 0:i.toLowerCase(),s=this.getFormFields().map((i=>{var t;return null===(t=this.dataUnit)||void 0===t?void 0:t.getField(i.name)})).filter((i=>{var s,e;return(null===(s=i.name)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(e=i.label)||void 0===e?void 0:e.toLowerCase().includes(t))})).map((i=>({value:i.name,label:i.label})));return Promise.resolve(s)}isGridInsertActive(){return this.enableGridInsert&&this.dataUnit.hasNewRecord()}getActionsList(){var i,t;const s=[{value:o.generateUUID(),label:null!==(t=null===(i=this.messagesBuilder)||void 0===i?void 0:i.getMessage("snkSimpleCrud.findColumn",void 0))&&void 0!==t?t:"Buscar",disableCloseOnSelect:!0,eagerInitialize:!0,itemBuilder:(i,t)=>this._currentViewMode===m.GRID?this.getColumnSearch(i,t):this.getFieldSearch(i,t)}];if(this.enableGridInsert&&s.push(this._continuousInsertUtils.actionContinuousInsert(this._enableContinuousInsert,(()=>{this._enableContinuousInsert=!this._enableContinuousInsert,this._continuousInsertUtils.handleSaveConfig(this._enableContinuousInsert)}))),this.isGridInsertActive())return s;if(null!=this.taskbarManager&&null!=this.taskbarManager.getMoreOptions){const i=this.getTopTaskBarId();return s.concat(this.taskbarManager.getMoreOptions(i,this.configName,this.dataState,this.actionsList))}return this.actionsList?s.concat(this.actionsList):s}getTopTaskBarId(){var i;return(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?`snkGridTopTaskbar.finish_edition${y.PRIMARY}`:`snkGridTopTaskbar.regular${y.PRIMARY}`}async keyDownListener(i){i.ctrlKey&&null!=i.key&&"F"===i.key.toUpperCase()&&null!=this._element&&(d.isHiddenElement(this._element)||(l.closeAll(),this._currentViewMode===m.GRID?await this.findColumn():await this.findField(),i.preventDefault()))}async findField(){await this.openSeach(this._fieldSearch)}async findColumn(){await this.openSeach(this._columnSearch)}async openSeach(i){await T(this._moreOptions,i)}clearFieldToFocusHandler(){this._fieldToGetFocus=void 0}connectedCallback(){window.addEventListener("keydown",this._keyDownHandler,{capture:!0})}disconnectedCallback(){window.removeEventListener("keydown",this._keyDownHandler)}gridConfigChangeHandler(i){F.saveGridConfig(i.detail,this.configName,this.resolveResourceID()),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}async dataExporterProviderStore(){if(null==this.dataUnit)return;if(null==this._grid)return;const i=new P(this.dataUnit,this._grid);O.set("exporterProviders",Object.assign(Object.assign({},O.get("exporterProviders")),{[this.getDataExporterStoreKey()]:i}))}getDataExporterStoreKey(){return`SnkSimpleCrudDataExporter:${null==this.configName?this.dataUnit.name:this.configName}`}setGridConfig(i){this.gridConfig=i,S.assertDefaultSorting(this.gridConfig,this.dataUnit)}setFormConfig(i,t){this.formConfig&&!t||(this.formConfig=i)}closeGridConfig(){this._showPopUpGridConfig=!1}closeFormConfig(){this._showFormConfig=!1}getPageSize(){return this.mode===v.IN_MEMORY?0:null==this.pageSize?150:this.pageSize}handleShowFormConfig(){return this._showFormConfig&&!this.formLegacyConfigName}resolveResourceID(){return o.isEmpty(this.resourceID)?this._resourceID:this.resourceID}getFormConfig(){var i;const t=null===(i=this._formConfigManager)||void 0===i?void 0:i.getConfig(this.dataUnit,this.ignoreReadOnlyFormFields);return this.configName||t?t:this.formConfig}updateFormConfig(){const i=Object.assign(Object.assign({},this.formConfig),{fields:this.dataUnit.metadata.fields});this.setFormConfig(i,!0),null==this._formConfigManager&&(this._formConfigManager=new R(this.configName,this.resolveResourceID())),this._formConfigManager.setConfig(this.formConfig)}handleDataUnitOnInsertionMode(){this.enableGridInsert||this.goToView(m.FORM)}render(){var i;if(null==this.dataUnit)return;const t=s("snk-taskbar",{class:this._currentViewMode===m.FORM&&"ez-box ez-box--shadow ez-padding--small",dataUnit:this.dataUnit,primaryButton:(null===(i=this.dataState)||void 0===i?void 0:i.isDirty)?"SAVE":"INSERT","data-element-id":"grid_left",messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,actionsList:this.getActionsList(),disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,"data-exporter-store-key":this.getDataExporterStoreKey(),slot:"leftButtons",presentationMode:y.SECONDARY},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"}));return s("snk-data-unit",{ref:i=>this._snkDataUnit=i,class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:i=>this.onDataStateChange(i),onCancelEdition:this.handleCancelEdit.bind(this),pageSize:this.getPageSize(),onInsertionMode:this.handleDataUnitOnInsertionMode.bind(this),onDataUnitReady:i=>this.dataUnitReady.emit(i.detail),ignoreSaveMessage:this._currentViewMode===m.GRID&&!this.enableGridInsert,onMessagesBuilderUpdated:i=>this.messagesBuilder=i.detail,onDataUnitFieldsHidded:this.updateFormConfig.bind(this),domainMessagesBuilder:this.domainMessagesBuilder},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:"ez-box ez-box--shadow simple-crud__container-section"},this._currentViewMode===m.FORM&&t,s("ez-view-stack",{ref:i=>this._viewStack=i,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{class:"ez-margin-bottom--large",ref:i=>this._grid=i,dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(m.FORM),onConfigChange:i=>this.gridConfigChangeHandler(i),columnfilterDataSource:this.dataUnit.name&&this.dataUnit.name.includes(w.IN_MEMORY_DATA_UNIT_NAME)?void 0:this._multiSelectionListDataSource,useEnterLikeTab:this.useEnterLikeTab,autoFocus:this.autoFocus,enableGridInsert:this.enableGridInsert,enableContinuousInsert:this._enableContinuousInsert},this._currentViewMode===m.GRID&&t,s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,s("ez-form",{ref:i=>this._form=i,class:"ez-margin-top--large "+(this.handleShowFormConfig()?"simple-crud__form--hidden":""),dataUnit:this.dataUnit,config:this.getFormConfig(),fieldToFocus:this._fieldToGetFocus,onEzFormSetFields:i=>this.handleFormSetFields(i.detail),onEzFormRequestClearFieldToFocus:this.clearFieldToFocusHandler.bind(this)}),this.handleShowFormConfig()&&s("snk-form-config",{messagesBuilder:this.messagesBuilder,dataUnit:this.dataUnit,configManager:this._formConfigManager,onConfigClose:()=>this.closeFormConfig()})),this.messagesBuilder&&s("snk-configurator",{ref:i=>this._snkConfigurator=i,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:i=>this.goToView(i.detail),onOpenConfig:i=>this.openConfig(i.detail),showActionButtons:this.showConfiguratorButtons,onSave:i=>this.handleConfiguratorEvent(i,"SAVE"),onCancel:i=>this.handleConfiguratorEvent(i,"CANCEL"),resourceID:this.resolveResourceID(),customContainerId:this._customContainerId})),s("div",{id:`${this._customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}))),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._showPopUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this.gridConfig,"data-element-id":this._element.getAttribute(u.DATA_ELEMENT_ID_ATTRIBUTE_NAME),selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resolveResourceID()})))}get _element(){return e(this)}static get watchers(){return{resourceID:["handleResourceIDChanged"],entityName:["onChangeEntityName"],mode:["onModeChange"],dataState:["observeDataState"],formLegacyConfigName:["observeFormLegacy"],gridLegacyConfigName:["observeGridLegacy"]}}};L.style=".sc-snk-simple-crud-h{display:flex;height:100%;width:100%;--snk-simple-crud-grid--min-height:300px}.simple-crud__container.sc-snk-simple-crud{display:grid;grid-template-rows:auto 1fr;height:100%;width:100%}.simple-crud__container-section.sc-snk-simple-crud{flex-wrap:unset;flex-direction:column}.simple-crud__form--hidden.sc-snk-simple-crud{display:none}ez-grid.sc-snk-simple-crud{--ez-grid__container--shadow:none;--ez-grid--min-height:var(--snk-simple-crud-grid--min-height)}ez-form.sc-snk-simple-crud{min-height:300px}";export{L as snk_simple_crud}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as i,c as e,h as t,H as l,g as s}from"./p-d2d301a6.js";import{UserInterface as n,ObjectUtils as o,StringUtils as a,ApplicationContext as d,ElementIDUtils as r}from"@sankhyalabs/core";import{DataType as u,getConvertedValue as h}from"@sankhyalabs/core/dist/dataunit/metadata/DataType";import{CheckMode as c}from"@sankhyalabs/ezui/dist/collection/utils";import{V as v,D as p,b}from"./p-b0ef4383.js";const f=class{constructor(t){i(this,t),this.configOptionsChanged=e(this,"configOptionsChanged",7),this._defaultType=void 0,this.fieldConfig={},this.idConfig=void 0,this.dataUnit=void 0,this.messagesBuilder=void 0}onConfigDefault(i){null!=i&&(this._defaultType=i,this.fieldConfig.defaultValue={type:this._defaultType},this.configOptionsChanged.emit(this.fieldConfig))}buildOptions(){var i,e,t;let l=null===(t=null===(i=this.dataUnit)||void 0===i?void 0:i.getField(null===(e=this.fieldConfig)||void 0===e?void 0:e.name))||void 0===t?void 0:t.userInterface;return l===n.SEARCH&&(l=n.INTEGERNUMBER),v.UserInterface[l]}enabledValueDefault(){var i,e,t;const l=null===(i=this.dataUnit)||void 0===i?void 0:i.getField(null===(e=this.fieldConfig)||void 0===e?void 0:e.name),s=null===(t=null==l?void 0:l.properties)||void 0===t?void 0:t.allowDefault,o=v.UserInterface.hasOwnProperty(null==l?void 0:l.userInterface)||(null==l?void 0:l.userInterface)===n.SEARCH;return!(null!=s&&"true"!==s||!o)}isAllowDefault(){var i,e;const t=null===(e=null===(i=this._fieldProperties)||void 0===i?void 0:i.properties)||void 0===e?void 0:e.allowDefault;return null==t||"true"===t}loadDefaultValue(){var i;null==this.fieldConfig?(this._defaultType=p.fixed,this.fieldConfig={defaultValue:{type:this._defaultType}}):null==(null===(i=this.fieldConfig.defaultValue)||void 0===i?void 0:i.type)?(this._defaultType=p.fixed,this.fieldConfig.defaultValue={type:this._defaultType}):this._defaultType=this.fieldConfig.defaultValue.type}getFieldProperties(i){var e;if(null!=i)return null===(e=this.dataUnit)||void 0===e?void 0:e.getField(i)}getMessage(i,e){return this.messagesBuilder.getMessage(i,e)}getDefaultType(){var i;return null!==(i=this.fieldConfig.defaultValue.type)&&void 0!==i?i:p.fixed}getEnabledByProperty(i,e){const t=this._fieldProperties;if(null==t)return!0;const l=t.properties||{};return l.hasOwnProperty(e)?"S"!==l[e]:!0!==t[i]}getValueByProperty(i){const e=this._fieldProperties;return null!=e&&!0===e[i]||this.fieldConfig[i]}getValidatedValue(i){var e,t;if(null==i)return;const l=null===(e=this.dataUnit)||void 0===e?void 0:e.getField(null===(t=this.fieldConfig)||void 0===t?void 0:t.name),s=null==l?void 0:l.dataType;if(null==s)return;const n=null!=(null==i?void 0:i.waitmessage)?void 0:s!==u.OBJECT&&s!==u.DATE&&"object"==typeof i?i.value:i;return s===u.OBJECT?JSON.stringify(n):n}buildInputDefault({value:i,enabled:e,label:l,name:s,required:a,userInterface:d},r,u){let h,c=0,v=0;const p=null==d||null==b[d]?b.DEFAULT:b[d];if(d===n.OPTIONSELECTOR){const i=null==r?void 0:r.options;if("string"==typeof i){const e=o.stringToObject(i);h=Object.keys(e).map((i=>({value:i,label:e[i]})))}else h=i}else d===n.DECIMALNUMBER&&(c=Number((null==r?void 0:r.precision)||2),v=Number((null==r?void 0:r.prettyPrecision)||c));return t(p,Object.assign({value:i,enabled:e,label:l,"data-field-name":s,key:s,onEzChange:i=>this.onChange(null==i?void 0:i.detail)},this.getConditionalAttributes(d,a,h,c,v,u)))}getConditionalAttributes(i,e,t,l,s,o){switch(i){case n.SEARCH:return{suppressEmptyOption:e,optionLoader:i=>this.onSearch(i)};case n.OPTIONSELECTOR:return{suppressEmptyOption:e,options:t};case n.CHECKBOX:case n.SWITCH:return{mode:o};case n.INTEGERNUMBER:case n.DECIMALNUMBER:return{precision:l,prettyPrecision:s,onEzStartChange:i=>this.onChange(null==i?void 0:i.detail)};case n.DATE:case n.DATETIME:case n.TIME:return{onEzStartChange:i=>this.onChange(null==i?void 0:i.detail)};default:return{}}}onChange(i){this.fieldConfig.defaultValue.value=this.getValidatedValue(i),this.configOptionsChanged.emit(this.fieldConfig)}onSearch(i){if(null!=this._application&&null!=this.fieldConfig)return this._application.executeSearch(i,this.fieldConfig.name,this.dataUnit)}buildField(i,e){const{name:t,label:l,readOnly:s,required:o,defaultValue:d}=e,{userInterface:r,properties:u}=i;let v,p=a.getBooleanValue(null==u?void 0:u.allowDefault,!s);r===n.FILE&&(p=!1),p&&(v=null==d?void 0:d.value,null!=v&&(v=h(null==i?void 0:i.dataType,v)));const b={value:v,enabled:p,label:l,name:t,required:o,userInterface:r};switch(r){case n.SWITCH:return this.buildInputDefault(b,void 0,c.SWITCH);case n.CHECKBOX:return this.buildInputDefault(b,void 0,c.REGULAR);case n.OPTIONSELECTOR:case n.DECIMALNUMBER:return this.buildInputDefault(b,u);default:return this.buildInputDefault(b)}}componentWillLoad(){var i;this.loadDefaultValue(),this._application=d.getContextValue("__SNK__APPLICATION__"),this._fieldProperties=this.getFieldProperties(null===(i=this.fieldConfig)||void 0===i?void 0:i.name)}componentDidLoad(){r.addIDInfo(this._element,this.fieldConfig.name)}render(){var i,e;return t(l,null,t("div",{id:this.idConfig},t("div",{class:"ez-row ez-padding--medium"},t("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},t("ez-text-input",{label:this.getMessage("snkConfigOptions.label.nameField"),value:null===(i=this.fieldConfig)||void 0===i?void 0:i.label,onEzChange:i=>{this.fieldConfig.label=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),t("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},t("ez-combo-box",{label:this.getMessage("snkConfigOptions.label.typeValueDefault"),suppressEmptyOption:!0,enabled:this.enabledValueDefault(),onEzChange:i=>{var e;return this.onConfigDefault(null===(e=i.detail)||void 0===e?void 0:e.value)},value:this.getDefaultType()},t("option",{value:p.fixed},this.getMessage("snkConfigOptions.options.valueFixed")),t("option",{value:p.variable},this.getMessage("snkConfigOptions.options.variable")))),t("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},this._defaultType===p.variable?t("ez-combo-box",{label:this.getMessage("snkConfigOptions.label.valueDefault"),enabled:this.isAllowDefault(),onEzChange:i=>{var e;this.fieldConfig.defaultValue.value=null===(e=i.detail)||void 0===e?void 0:e.value,this.configOptionsChanged.emit(this.fieldConfig)},value:this.fieldConfig.defaultValue.value,options:this.buildOptions()}):(null===(e=this._fieldProperties)||void 0===e?void 0:e.userInterface)&&this.buildField(this._fieldProperties,this.fieldConfig))),t("div",{class:"ez-row ez-padding--medium config-options__switch-row"},t("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},t("ez-check",{mode:c.SWITCH,label:this.getMessage("snkConfigOptions.label.clearDuplicate"),value:this.fieldConfig.cleanOnCopy,onEzChange:i=>{this.fieldConfig.cleanOnCopy=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),t("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},t("ez-check",{mode:c.SWITCH,label:this.getMessage("snkConfigOptions.label.requiredField"),enabled:this.getEnabledByProperty("required","systemRequired"),value:this.getValueByProperty("required"),onEzChange:i=>{this.fieldConfig.required=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})),t("div",{class:"ez-col ez-col--sd-12 ez-col--tb-4 ez-padding--small"},t("ez-check",{mode:c.SWITCH,label:this.getMessage("snkConfigOptions.label.protectedField"),enabled:this.getEnabledByProperty("readOnly","systemReadOnly"),value:this.getValueByProperty("readOnly"),onEzChange:i=>{this.fieldConfig.readOnly=i.detail,this.configOptionsChanged.emit(this.fieldConfig)}})))))}get _element(){return s(this)}};f.style=".sc-snk-config-options-h{--snk-config-options--border:2px solid var(--color--secondary-200, #D2D3DA);width:100%;border-radius:15px;border:var(--snk-config-options--border)}.config-options__switch-row.sc-snk-config-options{margin-top:-30px}";export{f as snk_config_options}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as i,c as t,h as s,g as o}from"./p-d2d301a6.js";import{ElementIDUtils as h}from"@sankhyalabs/core";import{S as a}from"./p-afbb070d.js";import{R as n}from"./p-688dcb4c.js";import"./p-4d9549cf.js";import"./p-06421fdb.js";import"./p-f3434fc4.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-ff1990ad.js";import"./p-b0ef4383.js";const e=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(){h.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 n.getResourceID()),this._configManager=new a(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 o(this)}};e.style=".sc-snk-form-h{--snk-form__header--min-height:94px;display:block}.snk-form__form--hidden.sc-snk-form{display:none}";export{e as snk_form}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,h as i}from"./p-d2d301a6.js";import{ModalAction as e}from"@sankhyalabs/ezui/dist/collection/components/ez-modal-container";import{ApplicationUtils as s}from"@sankhyalabs/ezui/dist/collection/utils";import{F as l}from"./p-d9804798.js";import{F as r}from"./p-ff1990ad.js";import{ObjectUtils as o}from"@sankhyalabs/core";import{P as a}from"./p-057fad05.js";import{F as n}from"./p-fa80e546.js";import"./p-933c0c0b.js";const d=class{constructor(i){t(this,i),this.getMessage=void 0,this.configName=void 0,this.filters=void 0,this.applyFilters=void 0,this.closeModal=void 0,this.addPersonalizedFilter=void 0,this.editPersonalizedFilter=void 0,this.deletePersonalizedFilter=void 0,this.filtersToDelete=[],this.disablePersonalizedFilter=void 0}deletePersonalizedFilterListener(t){this.filtersToDelete.push(t.detail)}getCustomMessage(t,i){var e;return null===(e=this.getMessage)||void 0===e?void 0:e.call(this,`snkFilterBar.filterModal.${t}`,i)}handleClearAll(){const{customFilters:t,quickFilters:i,otherFilters:e,multiListFilters:s}=this.filters.reduce(((t,i)=>i.type===r.MULTI_LIST?(t.multiListFilters.push(i),t):i.filterType===l.QUICK_FILTER?(t.quickFilters.push(i),t):i.filterType===l.CUSTOM_FILTER?(t.customFilters.push(i),t):i.filterType===l.OTHER_FILTERS?(t.otherFilters.push(i),t):t),{quickFilters:[],customFilters:[],otherFilters:[],multiListFilters:[]});this.handleClearFilterList(i),this.handleClearCustomFilters(t),this.handleClearOthersFilters(e),s.forEach((t=>this.handleClearSigleFilter(t)))}handleClearOthersFilters(t){this.filters=this.filters.map((i=>t.includes(i)?Object.assign(Object.assign({},i),{value:void 0}):i))}handleClearCustomFilters(t){this.filters.forEach(((i,e)=>{i.filterType===l.CUSTOM_FILTER&&(this.filters[e]=this.clearAllCustomFilter(t).shift())}))}clearAllCustomFilter(t){return t.map((t=>{const i=Object.assign({},t);return delete i.value,i.visible=!1,i.groupedItems&&(i.groupedItems=this.clearAllCustomFilter(i.groupedItems)),i}))}handleClose(){if(o.objectToString(this.filters)!==o.objectToString(this._originalFilterConfig))return s.confirm(this.getCustomMessage("validations.notSaved.title"),this.getCustomMessage("validations.notSaved.message")).then((t=>{t&&this.closeModal()}));this.closeModal()}handleApplyFilters(){const t=this.filters.find((t=>t.filterType===l.CUSTOM_FILTER));this.isValidCustomFilter(t)&&this.applyFilters(this.filters),this.filtersToDelete.length>0&&(this.filtersToDelete.forEach((t=>{this.deletePersonalizedFilter(t,this.configName)})),this.filtersToDelete=[])}isValidCustomFilter(t){return!!a.validateVariableValues(t)||(s.alert(this.getCustomMessage("validations.notFullFilled.title"),this.getCustomMessage("validations.notFullFilled.message")),!1)}modalActionListener(t){switch(t.detail){case e.CANCEL:this.handleClearAll();break;case e.OK:this.handleApplyFilters();break;case e.CLOSE:this.handleClose()}}handleFilterChange(t){this.filters=this.filters.map((i=>i.id===t.id?t:i))}handleClearFilterList(t){this.filters=this.filters.map((i=>t.includes(i)?Object.assign(Object.assign({},i),{value:void 0}):i))}handleClearSigleFilter(t){if(r.MULTI_LIST===t.type){let i=o.copy(t);this.uncheckFilterValues(i.value);const e=o.copy(this.filters),s=e.findIndex((i=>i.id===t.id));return e.splice(s,1,i),void(this.filters=o.copy(e))}if(r.CHECK_BOX_LIST===t.type){const i=o.copy(this.filters);return i.find((i=>i.id===t.id)).value=void 0,void(this.filters=o.copy(i))}this.filters.find((i=>i.id===t.id)).value=void 0}uncheckFilterValues(t){return t.forEach((t=>{t&&(t.check=!1)})),t}renderFilterItem(t,e){return i("snk-filter-modal-item",{class:e?"ez-col ez-col--sd-12":"ez-col ez-col--sd-6 ez-padding--small",filterItem:t,configName:this.configName,onFilterChange:t=>this.handleFilterChange(t.detail),onEditPersonalizedFilter:t=>this.editPersonalizedFilter(t.detail),onAddPersonalizedFilter:()=>this.addPersonalizedFilter()})}isDefaultFilterNumberVariation(t){var i;return t.type===r.NUMBER&&(!t.props.variation||(null===(i=t.props)||void 0===i?void 0:i.variation)===n.DEFAULT)}mountFiltersLines(t){let i=0,e=!1;const s={};for(let l=0;l<t.length;l++){s[i]=s[i]||[];const o=t[l],a=l===t.length-1,n=o.type===r.TEXT||this.isDefaultFilterNumberVariation(o),d=!a&&(t[l+1].type===r.TEXT||this.isDefaultFilterNumberVariation(t[l+1]));n&&d||e?(s[i].push(o),e=s[i].length<2,2===s[i].length&&++i):(s[i]=s[i]||[],s[i].push(o),++i)}return Object.values(s)}renderFilterLine(t){const i=1===t.length;return t.map((t=>this.renderFilterItem(t,i)))}getIformedFiltersCount(t){let i=0;return t.forEach((t=>{var e,s,l,o,a,n;r.MULTI_LIST!==t.type?r.CHECK_BOX_LIST!==t.type?null==t.groupedItems?t.value&&i++:i=t.groupedItems.filter((t=>t.visible)).length:i+=Object.entries(null!==(n=t.value)&&void 0!==n?n:{}).filter((([t,i])=>!0===i)).map((([t,i])=>t)).length:i+=null!==(a=null===(o=null===(l=null!==(s=null===(e=t.value)||void 0===e?void 0:e.elements)&&void 0!==s?s:t.value)||void 0===l?void 0:l.filter((t=>null==t?void 0:t.check)))||void 0===o?void 0:o.length)&&void 0!==a?a:0})),i}renderCollapsibleFilterBox(t,e,s,l=!0){if(!e.length)return null;const r=this.getIformedFiltersCount(e),o=this.mountFiltersLines(e);return i("ez-collapsible-box",{class:"snk-filter-modal__collapsible-box",headerSize:"medium",value:!0,label:t},!!r&&i("ez-badge",{class:"ez-badge--primary-subtle",slot:"rightSlot",label:null==r?void 0:r.toString()}),i("div",{class:"ez-row snk-filter-modal__rendered-items"},o.map(this.renderFilterLine.bind(this))),l&&i("div",{class:"ez-flex ez-flex--justify-end grow"},i("ez-button",{class:"ez-button--tertiary",size:"medium",label:"Limpar",onClick:()=>s?this.handleClearSigleFilter(e[0]):this.handleClearFilterList(e)})))}componentWillRender(){this._modalTitle=this.getCustomMessage("title"),this._okButtonLabel=this.getCustomMessage("okButtonLabel"),this._cancelButtonLabel=this.getCustomMessage("cancelButtonLabel")}componentDidLoad(){this._originalFilterConfig||(this._originalFilterConfig=this.filters)}render(){const t=this.filters.filter((t=>t.filterType===l.CUSTOM_FILTER)),e=this.filters.filter((t=>t.filterType===l.QUICK_FILTER)),s=this.filters.filter((t=>t.filterType===l.OTHER_FILTERS));return i("ez-modal-container",{class:"snk-filter-modal__container",modalTitle:this._modalTitle,cancelButtonLabel:this._cancelButtonLabel,okButtonLabel:this._okButtonLabel,onEzModalAction:this.modalActionListener.bind(this)},i("div",{class:"snk-filter-modal__content ez-col--sd-12"},!this.disablePersonalizedFilter&&this.renderCollapsibleFilterBox(this.getCustomMessage("customFilters"),t,!1,!1),this.renderCollapsibleFilterBox(this.getCustomMessage("quickFilters"),e,!1),s.map((t=>this.renderCollapsibleFilterBox(t.label,[t],!0)))))}};d.style="ez-modal{--ez-modal-content-padding:24px 12px}.snk-filter-modal__container{width:344px;max-width:344px;min-width:344px;overflow:hidden}.snk-filter-modal__content{display:flex;flex-direction:column;gap:var(--space--medium, 12px);padding-right:var(--space--3xs, 4px)}.snk-filter-modal__collapsible-box{border:var(--border--small, 1px solid) var(--color--strokes, #DCE0E8);border-radius:var(--border--radius-medium);padding:var(--space--medium, 12px) var(--space--small, 6px)}.snk-filter-modal__rendered-items{max-height:760px;overflow-x:clip;overflow-y:auto}.snk-filter-modal__rendered-items::-webkit-scrollbar{width:var(--space--small);min-width:var(--space--small);max-width:var(--space--small)}";export{d as snk_filter_modal}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,c as i,h as e,H as r,g as s}from"./p-d2d301a6.js";import{DataType as a,StringUtils as n,ObjectUtils as l,ElementIDUtils as o,ErrorException as h,ApplicationContext as d}from"@sankhyalabs/core";import{EzScrollDirection as c}from"@sankhyalabs/ezui/dist/collection/components/ez-scroller/EzScrollDirection";import{C as f}from"./p-4d9549cf.js";import{toString as m}from"@sankhyalabs/core/dist/dataunit/metadata/DataType";import{F as u}from"./p-ff1990ad.js";import{F as p}from"./p-933c0c0b.js";import{F as b}from"./p-fa80e546.js";import{ApplicationUtils as v}from"@sankhyalabs/ezui/dist/collection/utils";import{P as k}from"./p-057fad05.js";import"./p-06421fdb.js";import"./p-f3434fc4.js";import"./p-8d884fab.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";function g(t){let i="";return t.forEach(((t,e)=>{var r;i+=` ${e>0?null!==(r=t.operand)&&void 0!==r?r:"OR":""} ${t.expression}`})),i.trim()}class _{constructor({filterConfig:t,configName:i,onComplete:e,getMessage:r,disablePersonalizedFilter:s,onAddPersonalizedFilter:a,onEditPersonalizedFilter:n,onDeletePersonalizedFilter:l}){this._filterConfig=t,this._configName=i,this._onComplete=e,this._getMessage=r,this._disablePersonalizedFilter=s,this._addPersonalizedFilterFn=a,this._editPersonalizedFilterFn=n,this._onDeletePersonalizedFilter=l}applyFilters(t){this._onComplete(t),this._closeModal()}buildFilterModal(){const t=document.createElement("snk-filter-modal");return t.className="ez-size-height--full",t.filters=this._filterConfig,t.configName=this._configName,t.disablePersonalizedFilter=this._disablePersonalizedFilter,t.getMessage=this._getMessage.bind(this),t.applyFilters=this.applyFilters.bind(this),t.closeModal=()=>this._closeModal(),t.addPersonalizedFilter=()=>this._addPersonalizedFilterFn(),t.editPersonalizedFilter=t=>this._editPersonalizedFilterFn(t),t.deletePersonalizedFilter=(t,i)=>this._onDeletePersonalizedFilter(t,i),t}async showModal(){const t={content:this.buildFilterModal(),position:"left",heightMode:"full",closeOutsideClick:!1,useScrimLight:!0};this._closeModal=await v.showModal(t)}async closeModal(){this._closeModal()}}const x=class{constructor(e){t(this,e),this.configUpdated=i(this,"configUpdated",7),this._updateSequence=[],this._loadingPending=!1,this._configUpdated=!1,this._firstLoad=!0,this._pendingVariables=!1,this._customfiltersToBeUpdated=[],this._calculateSortIndex=t=>{if(!t.visible)return 0;if(t.hardFixed)return 1e6;let i=t.fixed?1e5:0;return i+=this.hasValidValue(t)?1e4:0,i+=this._updateSequence.lastIndexOf(t.id)+1,i},this._filtersComparator=(t,i)=>this._calculateSortIndex(i)-this._calculateSortIndex(t),this.customFilterBarConfig=void 0,this.dataUnit=void 0,this.title=void 0,this.configName=void 0,this.resourceID=void 0,this.mode="regular",this.filterConfig=void 0,this.messagesBuilder=void 0,this.disablePersonalizedFilter=void 0,this.filterBarLegacyConfigName=void 0,this.autoLoad=void 0,this.allowDefault=void 0,this.scrollerLocked=!1,this.showPersonalizedFilter=!1,this.personalizedFilterId=void 0}hasValidValue(t){return null!=t.value&&(!Array.isArray(t.value)||t.value.some((t=>!0===t.check)))}observeFilterConfig(t,i){l.equals(t,i)||this.handleFilterConfigsChanged(i,t)}handleFilterConfigsChanged(t,i){if(null!=t&&null==i)this._loadingPending=!0,this._configUpdated=!0;else{const e=new Map(t?t.map((t=>[t.id,t])):void 0);0===e.size&&i.length>0?(this._loadingPending=!0,this._configUpdated=!1):i.forEach((t=>{const i=e.get(t.id);if(null!=i){if(this._configUpdated=this._configUpdated||l.objectToString(i)!=l.objectToString(t),this._loadingPending=this._loadingPending||l.objectToString(i.value)!==l.objectToString(t.value),!this._loadingPending){const e=l.objectToString(i.groupedItems)!=l.objectToString(t.groupedItems);this._configUpdated=this._configUpdated||e,this._loadingPending=this._loadingPending||e}}else this._configUpdated=!0,this._loadingPending=this._loadingPending||null!=t.value}))}(this._loadingPending||this._configUpdated)&&this.configUpdated.emit(i),this.processAfterUpdateConfig()}async reload(){this.loadConfigFromStorage(!0)}async getFilterItem(t){const i=this.filterConfig.find((i=>i.id===t));return Promise.resolve(l.copy(i))}async updateFilterItem(t){return-1==this.filterConfig.findIndex((i=>i.id===t.id))?(console.warn("[SnkFilterBar.updateFilterItem] FilterItem não encontrado, o mesmo não será atualizado."),Promise.resolve()):(this._loadingPending=!0,this.updateFilter(t),Promise.resolve())}async addFilterItem(t){return this.filterConfig.findIndex((i=>i.id===t.id))>-1?(console.warn("[SnkFilterBar.addFilterItem] FilterItem já existe , o mesmo não será adicionado novamente."),Promise.resolve()):(this.filterConfig.push(t),this._loadingPending=!0,this.updateFilter(t),Promise.resolve())}async removeFilterItem(t){const i=this.filterConfig.findIndex((i=>i.id===t));if(-1==i)return console.warn("[SnkFilterBar.removeFilterItem] FilterItem não encontrado"),Promise.resolve(void 0);const e=this.filterConfig[i];return this.filterConfig=this.filterConfig.filter((i=>i.id!==t)),Promise.resolve(e)}componentDidLoad(){this._element&&o.addIDInfo(this._element,null,{dataUnit:this.dataUnit})}processPendingFilter(){if(this._pendingVariables){const t=this._element.querySelector("#filter-PERSONALIZED_FILTER_GROUP");t&&t.showUp(!0).then((()=>{this.processAfterUpdateConfig()}))}else this.processAfterUpdateConfig()}getPersonalizedFilterItem(){return this.filterConfig.find((t=>t.type===u.PERSONALIZED))}async processAfterUpdateConfig(){if(this._loadingPending){if(await this._application.isLoadedByPk()&&!this._configUpdated)return;const t=this.getPersonalizedFilterItem();if(this._pendingVariables=!k.validateVariableValues(t),this._pendingVariables)return;this._loadingPending=!1,this.doLoadData(null!=this.dataUnit.getLastLoadRequest())}this._configUpdated&&(this._configUpdated=!1,f.saveFilterBarConfig(this.filterConfig,this.configName,this.resourceID))}async doLoadData(t=!1){try{if(this._firstLoad&&!1===this.autoLoad)return;if(this._firstLoad&&!t&&void 0===this.autoLoad&&!await this._application.getBooleanParam("global.carregar.registros.iniciar.tela"))return;this.dataUnit.loadData(void 0,void 0,!0)}finally{this._firstLoad=!1}}getMessage(t,i,e){var r;return null==this.messagesBuilder&&this._application&&(this.messagesBuilder=this._application.messagesBuilder),(null===(r=this.messagesBuilder)||void 0===r?void 0:r.getMessage(t,i))||e}getFilter(t){var i;const e=[];return null===(i=this.filterConfig)||void 0===i||i.filter((t=>this.isActiveFilter(t))).forEach((t=>{const i=(t=>{switch(t.type){case u.DEFAULT_FILTER:return function(t){return{name:t.id,expression:t.props.expression,params:[]}}(t);case u.BINARY_SELECT:return function(t){const{id:i,value:e,props:r}=t;return{name:i,expression:r.options.find((t=>t.name===e)).expression,params:[]}}(t);case u.MULTI_SELECT:return function(t){const{id:i,value:e,props:r}=t;return{name:i,expression:r.expression,params:[{name:i,dataType:a.TEXT,value:e}]}}(t);case u.MULTI_LIST:return function(t){const{id:i,value:e,props:r}=t,s=(null!==(o=null!==(l=null==(n=e)?void 0:n.elements)&&void 0!==l?l:null==n?void 0:n.members)&&void 0!==o?o:n).filter((t=>null==t?void 0:t.check)).map((({id:t})=>Number.isNaN(+t)?String(t):Number(t)));var n,l,o;if(s.length>0)return{name:i,expression:r.expression,params:[{name:i,dataType:a.TEXT,value:JSON.stringify(s)}]}}(t);case u.PERIOD:return function(t){const{id:i,value:e,props:r}=t;let{end:s,start:n}=e;"string"==typeof s&&(s=new Date(s)),"string"==typeof n&&(n=new Date(n));const l=[];let o;return s&&n?(o=r.expression.fullfill,l.push({name:`${i}.START`,dataType:a.DATE,value:m(a.DATE,n)},{name:`${i}.END`,dataType:a.DATE,value:m(a.DATE,s)})):n?(o=r.expression.onlystart,l.push({name:i,dataType:a.DATE,value:m(a.DATE,n)})):(o=r.expression.onlyend,l.push({name:i,dataType:a.DATE,value:m(a.DATE,s)})),{name:i,expression:o,params:l}}(t);case u.SEARCH:return function(t){const{id:i,value:e,props:r}=t;return{name:i,expression:r.expression,params:[{name:i,dataType:a.TEXT,value:m(a.TEXT,e.value)}]}}(t);case u.TEXT:return function(t){let{id:i,value:e,props:r}=t;const s=r.expression;var l,o;return n.isEmpty(r.likeAs)||(l=e,e="CONTANIS"===(o=r.likeAs)?`%${l}%`:"STARTS_WITH"===o?`${l}%`:"ENDS_WITH"===o?`%${l}`:l),{name:i,expression:s,params:[{name:i,dataType:a.TEXT,value:m(a.TEXT,e)}]}}(t);case u.NUMBER:return function(t){const{id:i,value:e,props:r}=t;if(r.variation===b.INTERVAL){const{start:t,end:s}=null!=e?e:{start:0,end:0};if(t&&s)return{name:i,expression:r.intervalExpression.fullfill,params:[{name:`${i}.START`,dataType:a.NUMBER,value:m(a.NUMBER,t)},{name:`${i}.END`,dataType:a.NUMBER,value:m(a.NUMBER,s)}]};if(t)return{name:i,expression:r.intervalExpression.onlystart,params:[{name:i,dataType:a.NUMBER,value:m(a.NUMBER,t)}]};if(s)return{name:i,expression:r.intervalExpression.onlyend,params:[{name:i,dataType:a.NUMBER,value:m(a.NUMBER,s)}]}}return{name:i,expression:r.expression,params:[{name:i,dataType:a.NUMBER,value:m(a.NUMBER,e)}]}}(t);case u.PERSONALIZED:return function(t){const{id:i,groupedItems:e=[]}=t,r=e.filter((t=>!!t.visible)).map((t=>{var i;const e=t.props.expression,r=((null===(i=t.props.personalizedFilter)||void 0===i?void 0:i.parameters)||[]).map(((i,e)=>{const r=Array.from(t.value||0),s=i.dataType;let n=e>=0&&e<r.length?r[e]:null;return null!=n&&"object"==typeof n&&"value"in n&&(n=n.value),null==n&&s===a.BOOLEAN&&(n=!1),{name:i.name,dataType:s,value:"string"==typeof n?n:m(s,n)}}));return{expression:e,name:t.id,params:r}}));return{name:i,expression:r.map((t=>`(${t.expression})`)).join(` ${p.AND} `),params:r.flatMap((t=>t.params))}}(t);case u.CHECK_BOX_LIST:return function(t){var i;const{id:e,value:r,props:s}=t,a=Object.entries(null!=r?r:{}).filter((([t,i])=>!0===i)).map((([t,i])=>t));return{name:e,expression:g(null===(i=s.options)||void 0===i?void 0:i.filter((t=>a.includes(t.name)))),params:[]}}(t);default:return}})(t);i&&e.push(i)})),e}isActiveFilter(t){return t.type===u.DEFAULT_FILTER||this.filterActiveFilter(t)&&(t.groupedItems||null!=t.value)}registryFilterProvider(){this.dataUnit.addFilterProvider(this),this.filterConfig&&this.doLoadData()}itemFocused(t){this._element.querySelectorAll("snk-filter-item,snk-filter-list").forEach((i=>{i.id===t?"snk-filter-item"===i.tagName.toLowerCase()&&i.getClientRects()[0].x<0&&i.scrollIntoView({behavior:"auto",inline:"nearest"}):i.hideDetail()}))}filterActiveFilter(t){return t.visible||t.removalBlocked}filterPersonalizedItems(t){return t.type===u.PERSONALIZED}getPersonalizedFilterVariableItems(){return this.filterConfig.filter(this.filterPersonalizedItems).map((t=>{const i=`filter-${t.id}`;return e("snk-filter-item",{key:t.id,id:i,config:Object.assign({},t),onFocusin:()=>this.itemFocused(i),onVisibleChanged:t=>this.scrollerLocked=t.detail,onFilterChange:t=>this.updateFilter(t.detail),getMessage:(t,i)=>this.getMessage(t,i),showChips:!1})}))}getFilterItems(){const t=[],i=[];this.filterConfig.sort(((t,i)=>this._filtersComparator(t,i))).filter(this.filterActiveFilter).forEach(((r,s)=>{const a=`filter-${(r=l.copy(r)).id}`,n=e("snk-filter-item",{onVisibleChanged:t=>this.scrollerLocked=t.detail,onFilterChange:t=>this.updateFilter(t.detail),onFocusin:()=>this.itemFocused(a),id:a,config:r,class:s>0?"ez-padding-left--medium":"",getMessage:(t,i)=>this.getMessage(t,i),key:r.id});return r.fixed||r.hardFixed?t.push(n):i.push(n),n}));const r=[];return r.push(...t),t.length>0&&i.length>0&&r.push(e("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-filter-bar__divider"})),r.push(...i),r}calculateUpdateSequence(t){t&&(this._updateSequence=this._updateSequence.filter((i=>t.id!==i)),this._updateSequence.push(t.id))}normalizeItem(t){const i=Object.assign({},t);return["props","value","hardFixed","fixed"].forEach((t=>{null==i[t]&&delete i[t]})),""===t.value&&delete t.value,i}updateFilter(t){this.filterConfig=this.filterConfig.map((i=>(t=this.normalizeItem(t),i.id===t.id?(l.objectToString(i)!=l.objectToString(t)&&this.calculateUpdateSequence(t),t):i))).sort(((t,i)=>this._filtersComparator(t,i)))}loadPermitions(){this._application.isUserSup().then((t=>this.allowDefault=t))}addFilterBarLegacyConfigName(){this.filterBarLegacyConfigName&&this.configName&&f.addFilterBarLegacyConfig(this.configName,this.filterBarLegacyConfigName)}async loadConfigFromStorage(t){try{let i;t&&await f.deleteFilterBarConfigCache(this.configName,this.resourceID),i=this.customFilterBarConfig?await this.customFilterBarConfig(this.configName,this.resourceID,{contextURI:this.dataUnit.name}):await f.loadFilterBarConfig(this.configName,this.resourceID,{contextURI:this.dataUnit.name}),this.filterConfig=i.map((t=>this.normalizeItem(t))),this.filterConfig.sort(((t,i)=>this._filtersComparator(t,i)))}catch(t){throw new h(this.getMessage("snkFilterBar.failToLoadConfig"),t)}}attachDataUnit(){if(null==this.dataUnit){let t=this._element.parentElement;for(;t;)if("SNK-DATA-UNIT"===t.tagName.toUpperCase()){const i=t;this.dataUnit=i.dataUnit,this.dataUnit?this.registryFilterProvider():i.addEventListener("dataUnitReady",(t=>{this.dataUnit=t.detail,this.registryFilterProvider()}));break}t=t.parentElement}else this.registryFilterProvider()}filterChangeListener(t){this.updateFilter(t.detail)}async showFilterModal(){let t=l.copy(this.filterConfig);t=t.sort(((t,i)=>t.originOrder-i.originOrder)),this._filterModalFactory=new _({filterConfig:t,configName:this.configName,onComplete:t=>{this.filterConfig=t.map(this.normalizeItem).sort(((t,i)=>this._filtersComparator(t,i)))},disablePersonalizedFilter:this.disablePersonalizedFilter,getMessage:(t,i)=>this.getMessage(t,i),onAddPersonalizedFilter:()=>this.addPersonalizedFilter(),onEditPersonalizedFilter:t=>this.editPersonalizedFilter(t),onDeletePersonalizedFilter:(t,i)=>this.deletePersonalizedFilter(t,u.PERSONALIZED,i)}),await this._filterModalFactory.showModal()}addPersonalizedFilter(){this._filterModalFactory.closeModal(),this.personalizedFilterId=void 0,this.showPersonalizedFilter=!0,window.requestAnimationFrame((()=>{this._elPersonalizedFilter.createPersonalizedFilter()}))}editPersonalizedFilter(t){this._filterModalFactory.closeModal(),this.showPersonalizedFilter=!0,this.personalizedFilterId=t}deletePersonalizedFilter(t,i,e){i===u.PERSONALIZED&&f.removePersonalizedFilter(t,this.resourceID,e)}handleHidePersonalizedFilter(t){t?this.loadConfigFromStorage().then((()=>{this.hidePersonalizedFilter()})):this.hidePersonalizedFilter()}hidePersonalizedFilter(){this.personalizedFilterId=void 0,this.showPersonalizedFilter=!1}componentWillLoad(){this._application=d.getContextValue("__SNK__APPLICATION__"),this._application&&(this.loadPermitions(),this.addFilterBarLegacyConfigName(),this.loadConfigFromStorage()),this.attachDataUnit()}componentDidRender(){this.processPendingFilter()}render(){if(this.dataUnit&&this.filterConfig&&0!==this.filterConfig.length)return this.showPersonalizedFilter?e("snk-personalized-filter",{class:"filter-bar__personalized-filter",filterId:this.personalizedFilterId,ref:t=>this._elPersonalizedFilter=t,onEzCancel:()=>this.handleHidePersonalizedFilter(!1),onEzAfterSave:()=>this.handleHidePersonalizedFilter(!0),entityUri:this.dataUnit.name,configName:this.configName,resourceID:this.resourceID}):"regular"!==this.mode?e(r,{"data-mode":this.mode},this.getPersonalizedFilterVariableItems(),"button"===this.mode&&e("ez-button",{class:"ez-margin-left--medium",size:"small",label:this.getMessage("snkFilterBar.filters",void 0,"Filtros"),onClick:this.showFilterModal.bind(this)})):e(r,null,e("div",null,e("span",{class:"snk-filter-bar__title",title:this.title,"data-tooltip":this.title,"data-flow":"bottom"},this.title)),e("ez-scroller",{class:"snk-filter-bar__scroller",direction:c.HORIZONTAL,activeShadow:!0,locked:this.scrollerLocked},e("section",{class:"snk-filter-bar__filter-item-container"},this.getFilterItems())),e("ez-button",{class:"ez-padding-left--medium",size:"small",label:this.getMessage("snkFilterBar.filters",void 0,"Filtros"),onClick:this.showFilterModal.bind(this)},e("ez-icon",{slot:"leftIcon",iconName:"plus",class:"ez-padding-right--small"})))}get _element(){return s(this)}static get watchers(){return{filterConfig:["observeFilterConfig"]}}};x.style='.sc-snk-filter-bar-h{display:grid;grid-template-columns:1fr minmax(100px, 100%) 1fr 1fr;--snk-personalized-filter--z-index:var(--elevation--20, 20);--snk-personalized-filter--background-color:var(--background--xlight, #fff)}.snk-filter-bar__title.sc-snk-filter-bar{max-width:260px;display:inline-block;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;font-size:16px;font-family:var(--font-pattern, Arial);font-weight:var(--text-weight--large, 600);color:var(--color--title-primary, #2B3A54);margin-top:8px}[data-mode="hidden"].sc-snk-filter-bar-h{width:0px;height:0px}[data-mode="button"].sc-snk-filter-bar-h{grid-template-columns:1fr;width:fit-content}.snk-filter__popover-container.sc-snk-filter-bar{display:flex;cursor:auto}.filter-bar__personalized-filter.sc-snk-filter-bar{display:flex;flex-direction:column;position:fixed;top:0;left:0;width:100%;height:100%;overflow:auto;z-index:var(--snk-personalized-filter--z-index);background-color:var(--snk-personalized-filter--background-color)}.snk-filter__popover.sc-snk-filter-bar{display:flex;flex-direction:column;position:absolute;width:fit-content;height:fit-content;min-width:265px;background-color:var(--background--xlight, #fff);border-radius:var(--border--radius-medium, 12px);box-shadow:var(--shadow, 0px 0px 16px 0px #000)}.snk-filter-item__editor-header.sc-snk-filter-bar{flex-grow:1;font-weight:var(--text-weight--medium, 400);color:var(--color--title-primary, #2B3A54)}.snk-filter__popover-rule.sc-snk-filter-bar{border-style:solid;border-color:var(--color--disable-secondary, #F2F5F8);border-radius:1px;border-width:1px;width:100%}.editor__ez-check.sc-snk-filter-bar{--ez-check__label--padding-left:0}.snk-filter-item__editor-header-button.sc-snk-filter-bar{cursor:pointer;background-color:transparent;border:none;padding:3px;outline-color:var(--color--primary)}.snk-filter-bar__divider.sc-snk-filter-bar{margin-bottom:var(--space--small)}.snk-filter-bar__scroller.sc-snk-filter-bar{height:calc(100% + var(--space-extra-small, 3px))}.snk-filter-bar__filter-item-container.sc-snk-filter-bar{display:flex;align-items:start}.snk-filter-bar__scroller.sc-snk-filter-bar .sc-snk-filter-bar:first-child{margin-left:var(--space-extra-small, 3px)}.snk-filter-bar__filter-list-items-container.sc-snk-filter-bar{overflow-y:auto;max-height:360px;margin-top:var(--space--small, 6px)}.snk-filter-bar__filter-list-item.sc-snk-filter-bar{cursor:pointer;border-radius:var(--border--radius-small, 6px);border:none;background-color:transparent}.snk-filter-bar__filter-list-item__label.sc-snk-filter-bar{color:var(--title--primary)}.snk-filter-bar__filter-list-item__label--secondary.sc-snk-filter-bar{color:var(--text--primary)}.snk-filter-bar__filter-list-item__icon.sc-snk-filter-bar{--ez-icon--color:var(--title--primary)}.snk-filter-bar__filter-list-item__icon--secondary.sc-snk-filter-bar{--ez-icon--color:var(--text--secondary)}.snk-filter-bar__filter-list-item.sc-snk-filter-bar:focus-visible{outline:none;background-color:var(--background--medium)}.snk-filter-bar__filter-list-item.sc-snk-filter-bar:hover{background-color:var(--background--medium)}.snk-filter-bar__filter-list-items-container--empty.sc-snk-filter-bar{width:100%;height:100px;display:flex;justify-content:center;align-self:center;align-items:center}.snk-filter-bar__filter-list-items-button--active.sc-snk-filter-bar{position:relative}.snk-filter-bar__filter-list-items-button--active.sc-snk-filter-bar::after{display:flex;position:absolute;content:"";width:8px;height:8px;top:7px;left:17px;background-color:var(--icon--alert--color, #008561);border-radius:50%}.snk-filter-bar__filter-modal-item.sc-snk-filter-bar{--modal-item-border-width:2px;display:flex;flex-direction:row;margin-left:var(--modal-item-border-width);border-radius:var(--border--radius-medium, 12px);background-color:var(--background--medium, #f0f3f7);border:none;width:100%}.snk-filter-bar__filter-modal-item.sc-snk-filter-bar:focus-visible{outline:var(--color--primary) solid var(--modal-item-border-width)}.snk-filter-bar__filter-modal-item__check.sc-snk-filter-bar{width:auto}.snk-filter-bar__filter-modal-item__label.sc-snk-filter-bar{font-weight:var(--text-weight--medium)}.snk-filter-bar__filter-modal-content.sc-snk-filter-bar{display:grid;grid-template-rows:auto auto 1fr auto;width:99%;height:100%}';export{x as snk_filter_bar}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,c as i,h as s,H as e,g as l}from"./p-d2d301a6.js";import{FloatingManager as r,ElementIDUtils as n,ArrayUtils as a}from"@sankhyalabs/core";const h="__SHOWMORE__",o=class{constructor(s){t(this,s),this.snkItemSelected=i(this,"snkItemSelected",7),this._preselection=-1,this.innerClickCheck=(t,i)=>i.id!=r.MODAL_ELEMENT_ID||(this._detailIsVisible=!1,!1),this._filterArgument=void 0,this._showAll=void 0,this.label=void 0,this.iconName=void 0,this.items=void 0,this.getMessage=void 0,this.emptyText=void 0,this.findFilterText=void 0,this.buttonClass=void 0}showDetail(){this._preselection=-1,this._floatingID=r.float(this._popover,this._popoverContainer,{autoClose:!0,innerClickTest:this.innerClickCheck,backClickListener:()=>this.onListCloseCallback(),useOverlay:!0}),this._detailIsVisible=!0,this._showAll=!1,this._filterArgument="",this._filterInput.setFocus()}async hideDetail(){null!=this._floatingID&&r.close(this._floatingID)}onListCloseCallback(){this._floatingID=void 0,this._detailIsVisible=!1}buttonClick(){this._detailIsVisible?this.hideDetail():this.showDetail()}componentDidLoad(){this._element&&n.addIDInfo(this._element)}componentDidRender(){null==this._floatingID&&this._popover&&this._popover.remove()}buildIdElement(t,i){if(!t)return;const s={id:i};t.removeAttribute(n.DATA_ELEMENT_ID_ATTRIBUTE_NAME),n.addIDInfoIfNotExists(t,"filterItemList",s)}buildItemElement(t){const i=++this._selectableItemsCount;return s("button",{ref:i=>i&&this.buildIdElement(i,t.label),id:`filter-item${i}`,onFocusin:()=>this._preselection=i,class:"ez-col ez-col--sd-12 ez-align--middle ez-padding--small sc-snk-filter-bar snk-filter-bar__filter-list-item",onClick:()=>this.itemSelected(t.name),name:t.label,key:i},t.iconName?s("ez-icon",{iconName:t.iconName,size:"small",class:`ez-padding-right--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-item__icon ${t.iconClass||""}`}):void 0,s("div",{class:`ez-text ez-text--medium ez-text--primary ez-padding--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-item__label ${t.labelClass||""}`},t.label))}itemSelected(t){t===h?this._showAll=!0:(this.hideDetail(),this.snkItemSelected.emit(t))}getFilterItems(){const t=this.items?a.applyStringFilter(this._filterArgument,this.items.filter((t=>"FILTER"===t.kind))):[];return 0===t.length?s("div",{class:"ez-text ez-text--medium ez-text--primary ez-padding--extra-small sc-snk-filter-bar snk-filter-bar__filter-list-items-container--empty"},this.emptyText):(!this._filterArgument&&!this._showAll&&t.length>6&&(t.splice(5),t.push({kind:"INTERNAL",label:"Mostrar mais",iconName:"dots-horizontal",name:h,iconClass:"snk-filter-bar__filter-list-item__icon--secondary",labelClass:"snk-filter-bar__filter-list-item__label--secondary"})),this._selectableItemsCount=0,s("div",{class:"sc-snk-filter-bar snk-filter-bar__filter-list-items-container"},t.map((t=>this.buildItemElement(t)))))}getFooterItems(){return this.items.filter((t=>"FOOTER"===t.kind))}keyDownHandler(t){switch(t.key){case"ArrowDown":this.changePreselection(this._preselection+1),t.stopImmediatePropagation(),t.stopPropagation(),t.preventDefault();break;case"ArrowUp":this.changePreselection(this._preselection-1),t.stopImmediatePropagation(),t.stopPropagation(),t.preventDefault()}}changePreselection(t){if(t<0&&(t=this._selectableItemsCount),this._preselection=t>this._selectableItemsCount?0:t,0===this._preselection)this._filterInput.setFocus();else{const t=this._element.querySelector(`#filter-item${this._preselection}`);t&&t.focus()}}render(){return s(e,{class:"ez-flex ez-flex--column"},s("ez-button",{class:this.buttonClass,label:this.label,onClick:()=>this.buttonClick(),mode:this.iconName?"icon":void 0,iconName:this.iconName,size:"small"},s("slot",{name:"leftIcon"})),s("section",{class:"ez-margin-top--small sc-snk-filter-bar snk-filter__popover-container",ref:t=>this._popoverContainer=t},s("div",{class:"sc-snk-filter-bar snk-filter__popover ez-padding--small ez-elevation--4",ref:t=>this._popover=t},s("ez-filter-input",{ref:t=>this._filterInput=t,"data-element-id":"serachFilters",mode:"slim",label:this.findFilterText,value:this._filterArgument,onEzChange:t=>this._filterArgument=t.detail,onFocus:()=>this._preselection=0}),this.getFilterItems(),s("hr",{class:"sc-snk-filter-bar snk-filter__popover-rule"}),this.items?this.getFooterItems().map((t=>this.buildItemElement(t))):void 0)))}get _element(){return l(this)}};export{o as snk_filter_list}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,c as i,h as e,H as s,g as r}from"./p-d2d301a6.js";import{FloatingManager as n,DateUtils as l,ElementIDUtils as o}from"@sankhyalabs/core";import{F as h}from"./p-ff1990ad.js";import{F as a}from"./p-fa80e546.js";const c=class{constructor(e){t(this,e),this.visibleChanged=i(this,"visibleChanged",7),this.filterChange=i(this,"filterChange",3),this.innerClickCheck=(t,i)=>i.id!=n.MODAL_ELEMENT_ID||(this.detailIsVisible=!1,!1),this.detailIsVisible=void 0,this.config=void 0,this.getMessage=void 0,this.showChips=!0}observeDetailIsVisible(t){this.visibleChanged.emit(t)}async showUp(t=!1){return new Promise((i=>{this._filterItemElement.scrollIntoView({behavior:"auto",block:"nearest",inline:"nearest"}),t&&(this._closeCallback=i,window.requestAnimationFrame((()=>{this._floatingID=n.float(this._popover,this._popoverContainer,this.getFloatOptions()),this._popover.show(),this.detailIsVisible=!0})))}))}updatePosition(){null!=this._floatingID&&n.updateFloatPosition(this._popover,this._popoverContainer,this.getFloatOptions())}getFloatOptions(){return{autoClose:!0,innerClickTest:this.innerClickCheck,backClickListener:()=>this.onDetailCloseCallback(),left:this.getOffsetLeft(),top:this.getOffsetTop(),useOverlay:!0,overlayClassName:"ez-scrim ez-scrim--light",isFixed:!0}}getOffsetLeft(){const t=getComputedStyle(this._filterItemElement).getPropertyValue("padding-left"),i=this._filterItemElement.getBoundingClientRect(),e=430-(document.body.clientWidth-i.left);return`calc(${i.x}px + ${t} - ${e>0?e:0}px)`}getOffsetTop(){const t=this._filterItemElement.getBoundingClientRect();return t.y+t.height+"px"}controlScrollPage(){window.removeEventListener("scroll",this.updatePosition.bind(this)),window.addEventListener("scroll",this.updatePosition.bind(this))}getConfigChanges(){var t;const i=this.config;(null===(t=i.groupedItems)||void 0===t?void 0:t.length)&&(i.visible=!1,i.groupedItems=i.groupedItems.map((t=>Object.assign(Object.assign({},t),{visible:!1}))));const e=i.type===h.MULTI_LIST&&Array.isArray(i.value)?i.value.map((t=>Object.assign(Object.assign({},t),{check:!1}))):void 0;return Object.assign(Object.assign({},i),{value:e})}async hideDetail(){this.detailIsVisible&&null!=this._floatingID&&n.close(this._floatingID)}onDetailCloseCallback(){this._floatingID=void 0,this.detailIsVisible=!1,this._closeCallback&&(this._closeCallback(),this._closeCallback=void 0)}clickListener(t){if([this._chipElement,this._leftIconElement,this._rightIconElement].includes(t.target)){if(t.target===this._rightIconElement&&this.canClearFilter()){const t=this.getConfigChanges();this.filterChange.emit(t)}else this.detailIsVisible?this.hideDetail():this.showUp(!0);t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation()}}mouseDownListener(t){this.detailIsVisible&&[this._chipElement,this._leftIconElement,this._rightIconElement].includes(t.target)&&(t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation())}getLabel(t=!1){var i,e;const{type:s,value:r,label:n,props:o,groupedItems:c=[]}=this.config;if(r||c.length){if(s===h.BINARY_SELECT){const[i,e]=o.options,s=this.getMessage("snkFilterBar.binarySelectTooltip");if(i.name===r)return t?`${s} ${String(i.label).toLowerCase()}`:i.label;if(e.name===r)return t?`${s} ${String(e.label).toLowerCase()}`:e.label}if(s===h.MULTI_SELECT)return`${n}: ${o.options.find((t=>t.value===r)).label}`;if(s===h.PERIOD){let{end:i,start:e}=r;"string"==typeof i&&(i=new Date(i),i.setMinutes(i.getMinutes()+i.getTimezoneOffset())),"string"==typeof e&&(e=new Date(e),e.setMinutes(e.getMinutes()+e.getTimezoneOffset()));const s=new Intl.DateTimeFormat("pt-BR");if(i&&e){const s=e.getFullYear()===i.getFullYear(),r=Object.assign({day:"2-digit",month:"2-digit"},(!s||t)&&{year:"2-digit"}),o=l.formatDate(e,r),h=l.formatDate(i,r);return t?this.getMessage("snkFilterBar.fullPeriodTooltip",{LABEL:n,START_LABEL:o,END_LABEL:h}):`${n}: ${o} → ${h}`}return e?`${n}: ${this.getMessage("snkFilterBar.onlyStartToltip")} ${s.format(e)}`:i?`${n}: ${this.getMessage("snkFilterBar.onlyEndToltip")} ${s.format(i)}`:n}if(s===h.SEARCH)return`${n}: ${r.value} - ${r.label}`;if(s===h.PERSONALIZED){const t=this.calculateActiveCount(c);return t<=0?n:`${n}: ${this.getMessage("snkFilterBar.personalizedCount",{activeCount:t})}`}if(s===h.MULTI_LIST){const e=(null!==(i=r.elements)&&void 0!==i?i:r).filter((t=>null==t?void 0:t.check));return this.getLabelFromCheckedOptions(e,n,t)}if(s===h.CHECK_BOX_LIST){const i=Object.entries(null!=r?r:{}).filter((([t,i])=>!0===i)).map((([t,i])=>t)),s=(null!==(e=o.options)&&void 0!==e?e:[]).filter((t=>i.includes(t.name)));return this.getLabelFromCheckedOptions(s,n,t)}if(s===h.NUMBER&&o.variation===a.INTERVAL){const{start:t,end:i}=r;if(t&&i)return this.getMessage("snkFilterBar.fullIntervalTooltip",{LABEL:n,START_LABEL:t,END_LABEL:i});if(t)return`${n}: ${this.getMessage("snkFilterBar.onlyStartToltip")} ${Number(t)}`;if(i)return`${n}: ${this.getMessage("snkFilterBar.onlyEndToltip")} ${Number(i)}`}return`${n}: ${r}`}return n}getLabelFromCheckedOptions(t,i,e){const s=t.length;return 0===s?`${i}`:s>1?e?`${i}: ${t.map((t=>t.label)).join(",")}`:`${i}: ${s} ${this.getMessage("snkFilterBar.multiListToltip")}`:`${i}: ${t[0].label}`}calculateActiveCount(t){return t.reduce(((t,i)=>i.visible?t+1:t),0)}componentDidLoad(){this._filterItemElement&&(o.addIDInfo(this._filterItemElement),this._idSnkFilterDetail=`filterDetail_${this.config.id}`),this.controlScrollPage()}componentDidRender(){null==this._floatingID&&this._popover&&this._popover.remove()}filterChangeListener(){this.hideDetail()}canClearFilter(){const{value:t,groupedItems:i=[]}=this.config;return null!=t&&this.config.type===h.MULTI_LIST?t.some((t=>t.check)):void 0!==t||i.some((t=>t.visible))}getRightIconName(){return this.canClearFilter()?"close":this.detailIsVisible?"chevron-up":"chevron-down"}getLeftIconName(){switch(this.config.type){case h.PERIOD:return"calendar";case h.PERSONALIZED:return"tune"}}hasActiveElements(t){var i,e,s;return(null===(s=null===(e=null!==(i=null==t?void 0:t.elements)&&void 0!==i?i:t)||void 0===e?void 0:e.filter((t=>null==t?void 0:t.check)))||void 0===s?void 0:s.length)>0}hasActiveValue(t){return t.type!==h.MULTI_LIST&&void 0!==t.value||this.hasActiveElements(t.value)}getEnabledChip(){if(this.config.type===h.PERSONALIZED){const{groupedItems:t=[]}=this.config;return t.some((t=>t.visible))}return this.hasActiveValue(this.config)}render(){const t=this.getLeftIconName();return e(s,null,this.showChips&&e("ez-chip",{id:this.config.id,ref:t=>this._chipElement=t,label:this.getLabel(),value:this.getEnabledChip()},t&&e("ez-icon",{ref:t=>this._leftIconElement=t,iconName:t,class:"ez-padding-right--small",slot:"leftIcon"}),e("ez-icon",{ref:t=>this._rightIconElement=t,iconName:this.getRightIconName(),class:"ez-padding-left--small",slot:"rightIcon",id:"removeFilter"})),e("section",{class:"ez-margin-top--small sc-snk-filter-bar snk-filter__popover-container",ref:t=>this._popoverContainer=t},e("snk-filter-detail",{config:this.config,getMessage:this.getMessage,class:"sc-snk-filter-bar snk-filter__popover ez-padding--small ez-elevation--16",ref:t=>this._popover=t,key:this.config.id,"data-element-id":this._idSnkFilterDetail,showHardFixed:this.showChips})))}get _filterItemElement(){return r(this)}static get watchers(){return{detailIsVisible:["observeDetailIsVisible"]}}};export{c as snk_filter_item}
|