@sankhyalabs/sankhyablocks 8.7.0 → 8.8.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{ConfigStorage-1097ff27.js → ConfigStorage-a97ca159.js} +2 -2
- package/dist/cjs/{DataFetcher-a00bc007.js → DataFetcher-2a99283c.js} +19 -10
- package/dist/cjs/{SnkFormConfigManager-a4b4d852.js → SnkFormConfigManager-f641f502.js} +2 -2
- package/dist/cjs/{SnkMultiSelectionListDataSource-804ff4c7.js → SnkMultiSelectionListDataSource-4e3de426.js} +11 -0
- package/dist/cjs/{auth-fetcher-92f3040b.js → auth-fetcher-78231356.js} +1 -1
- package/dist/cjs/dataunit-fetcher-a4e8352b.js +906 -0
- package/dist/cjs/{form-config-fetcher-60fbeb94.js → form-config-fetcher-a322a522.js} +1 -1
- package/dist/cjs/{pesquisa-fetcher-b2ed9767.js → pesquisa-fetcher-7ef61508.js} +1 -1
- package/dist/cjs/snk-actions-button.cjs.entry.js +4 -3
- package/dist/cjs/snk-application.cjs.entry.js +17 -8
- package/dist/cjs/snk-attach.cjs.entry.js +16 -3
- package/dist/cjs/snk-crud.cjs.entry.js +6 -4
- package/dist/cjs/snk-data-exporter.cjs.entry.js +1 -1
- package/dist/cjs/snk-detail-view.cjs.entry.js +8 -6
- package/dist/cjs/snk-filter-bar.cjs.entry.js +3 -3
- package/dist/cjs/snk-filter-modal-item.cjs.entry.js +3 -3
- package/dist/cjs/snk-form-config.cjs.entry.js +2 -2
- package/dist/cjs/snk-form.cjs.entry.js +4 -4
- package/dist/cjs/snk-grid-config.cjs.entry.js +3 -3
- package/dist/cjs/snk-grid.cjs.entry.js +25 -14
- package/dist/cjs/{snk-guides-viewer-eab0ec84.js → snk-guides-viewer-c540f4c5.js} +5 -4
- package/dist/cjs/snk-guides-viewer.cjs.entry.js +8 -6
- package/dist/cjs/snk-personalized-filter.cjs.entry.js +19 -9
- package/dist/cjs/snk-simple-crud.cjs.entry.js +8 -92
- package/dist/collection/components/snk-application/snk-application.js +11 -3
- package/dist/collection/components/snk-attach/snk-attach.js +14 -2
- package/dist/collection/components/snk-grid/filtercolumn/SnkMultiSelectionListDataSource.js +11 -0
- package/dist/collection/components/snk-grid/snk-grid.js +24 -14
- package/dist/collection/components/snk-personalized-filter/snk-personalized-filter.js +16 -6
- package/dist/collection/lib/dataUnit/InMemoryLoader.js +23 -2
- package/dist/collection/lib/http/data-fetcher/DataFetcher.js +19 -10
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +113 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.js +77 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.js +179 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/{dataunit-fetcher.js → data-unit/dataunit-fetcher.js} +48 -100
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataResult.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataStrategy.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadingInfo.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRecordField.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IResponseRecord.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DataUnitStrategy.js +68 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.js +131 -0
- package/dist/collection/lib/index.js +1 -1
- package/dist/components/DataFetcher.js +19 -10
- package/dist/components/SnkMultiSelectionListDataSource.js +11 -0
- package/dist/components/dataunit-fetcher.js +809 -100
- package/dist/components/snk-actions-button2.js +1 -1
- package/dist/components/snk-application2.js +11 -4
- package/dist/components/snk-attach2.js +13 -1
- package/dist/components/snk-crud.js +1 -1
- package/dist/components/snk-detail-view2.js +1 -1
- package/dist/components/snk-grid2.js +19 -11
- package/dist/components/snk-personalized-filter2.js +16 -6
- package/dist/components/snk-simple-crud2.js +2 -88
- package/dist/esm/{ConfigStorage-4d30a649.js → ConfigStorage-26f89143.js} +2 -2
- package/dist/esm/{DataFetcher-487d6aad.js → DataFetcher-90e91631.js} +19 -10
- package/dist/esm/{SnkFormConfigManager-da594f63.js → SnkFormConfigManager-18948123.js} +2 -2
- package/dist/esm/{SnkMultiSelectionListDataSource-892f37f9.js → SnkMultiSelectionListDataSource-36887f31.js} +11 -0
- package/dist/esm/{auth-fetcher-5c3ae75b.js → auth-fetcher-a8c8ee7e.js} +1 -1
- package/dist/esm/dataunit-fetcher-c22b889c.js +902 -0
- package/dist/esm/{form-config-fetcher-cd3fa459.js → form-config-fetcher-7c3b6273.js} +1 -1
- package/dist/{components/pesquisa-fetcher.js → esm/pesquisa-fetcher-90d6853b.js} +1 -1
- package/dist/esm/snk-actions-button.entry.js +4 -3
- package/dist/esm/snk-application.entry.js +17 -8
- package/dist/esm/snk-attach.entry.js +16 -3
- package/dist/esm/snk-crud.entry.js +6 -4
- package/dist/esm/snk-data-exporter.entry.js +1 -1
- package/dist/esm/snk-detail-view.entry.js +8 -6
- package/dist/esm/snk-filter-bar.entry.js +3 -3
- package/dist/esm/snk-filter-modal-item.entry.js +3 -3
- package/dist/esm/snk-form-config.entry.js +2 -2
- package/dist/esm/snk-form.entry.js +4 -4
- package/dist/esm/snk-grid-config.entry.js +3 -3
- package/dist/esm/snk-grid.entry.js +26 -15
- package/dist/esm/{snk-guides-viewer-cff5e95d.js → snk-guides-viewer-e87b77d5.js} +5 -4
- package/dist/esm/snk-guides-viewer.entry.js +8 -6
- package/dist/esm/snk-personalized-filter.entry.js +19 -9
- package/dist/esm/snk-simple-crud.entry.js +7 -91
- package/dist/sankhyablocks/p-182246c9.entry.js +1 -0
- package/dist/sankhyablocks/{p-ee57d9f5.js → p-240f5892.js} +1 -1
- package/dist/sankhyablocks/p-42de2707.entry.js +1 -0
- package/dist/sankhyablocks/p-5356efdd.entry.js +1 -0
- package/dist/sankhyablocks/{p-c9fa27ce.entry.js → p-57550ddc.entry.js} +1 -1
- package/dist/sankhyablocks/{p-e2160bdd.js → p-5d51bff4.js} +1 -1
- package/dist/sankhyablocks/{p-ebd9f2b1.entry.js → p-5dd52ec5.entry.js} +1 -1
- package/dist/sankhyablocks/p-6541f0df.js +1 -0
- package/dist/sankhyablocks/p-68fbd480.entry.js +1 -0
- package/dist/sankhyablocks/{p-5e5816ed.entry.js → p-8652f90b.entry.js} +1 -1
- package/dist/sankhyablocks/{p-358e8f7b.js → p-910af03c.js} +1 -1
- package/dist/sankhyablocks/p-992a9d0f.js +1 -0
- package/dist/sankhyablocks/p-9e705c91.entry.js +1 -0
- package/dist/sankhyablocks/p-a046a2e1.js +1 -0
- package/dist/sankhyablocks/p-a221bc67.js +1 -0
- package/dist/sankhyablocks/{p-54f01129.entry.js → p-b3cd0dd1.entry.js} +3 -3
- package/dist/sankhyablocks/p-b7798801.entry.js +1 -0
- package/dist/sankhyablocks/p-bcc2b79d.js +59 -0
- package/dist/sankhyablocks/p-d07651cc.entry.js +1 -0
- package/dist/sankhyablocks/{p-33745612.js → p-d47bbee3.js} +1 -1
- package/dist/sankhyablocks/{p-86d00468.entry.js → p-d563e451.entry.js} +1 -1
- package/dist/sankhyablocks/{p-6cd36947.entry.js → p-e74e2153.entry.js} +1 -1
- package/dist/sankhyablocks/p-eab2c97d.entry.js +1 -0
- package/dist/sankhyablocks/{p-d109914d.entry.js → p-ebfa6460.entry.js} +1 -1
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/dist/types/components/snk-application/snk-application.d.ts +1 -1
- package/dist/types/components/snk-attach/snk-attach.d.ts +1 -0
- package/dist/types/components/snk-grid/filtercolumn/SnkMultiSelectionListDataSource.d.ts +1 -0
- package/dist/types/components/snk-grid/snk-grid.d.ts +3 -4
- package/dist/types/components/snk-personalized-filter/snk-personalized-filter.d.ts +3 -1
- package/dist/types/components.d.ts +3 -2
- package/dist/types/lib/dataUnit/InMemoryLoader.d.ts +2 -1
- package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +1 -1
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.d.ts +13 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.d.ts +19 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.d.ts +25 -0
- package/dist/types/lib/http/data-fetcher/fetchers/{dataunit-fetcher.d.ts → data-unit/dataunit-fetcher.d.ts} +5 -3
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataResult.d.ts +6 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataStrategy.d.ts +7 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadingInfo.d.ts +8 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRecordField.d.ts +4 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IResponseRecord.d.ts +6 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DataUnitStrategy.d.ts +9 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.d.ts +15 -0
- package/dist/types/lib/http/data-fetcher/fetchers/personalized-filter-fetcher.d.ts +1 -1
- package/dist/types/lib/index.d.ts +1 -1
- package/package.json +3 -3
- package/dist/cjs/dataunit-fetcher-32bb845f.js +0 -356
- package/dist/esm/dataunit-fetcher-d3033a06.js +0 -354
- package/dist/esm/pesquisa-fetcher-615da3ca.js +0 -165
- package/dist/sankhyablocks/p-0abc880c.entry.js +0 -1
- package/dist/sankhyablocks/p-1284f14a.entry.js +0 -1
- package/dist/sankhyablocks/p-162161ae.entry.js +0 -1
- package/dist/sankhyablocks/p-329f7520.entry.js +0 -1
- package/dist/sankhyablocks/p-401da0a5.entry.js +0 -1
- package/dist/sankhyablocks/p-5d62a74e.js +0 -1
- package/dist/sankhyablocks/p-5e63571e.entry.js +0 -1
- package/dist/sankhyablocks/p-6b2ee5b5.entry.js +0 -1
- package/dist/sankhyablocks/p-719c246f.js +0 -1
- package/dist/sankhyablocks/p-89b3df4c.js +0 -1
- package/dist/sankhyablocks/p-90946802.js +0 -76
- package/dist/sankhyablocks/p-b417c608.entry.js +0 -1
- package/dist/sankhyablocks/p-fa9d3f73.js +0 -1
@@ -1,354 +0,0 @@
|
|
1
|
-
import { DataUnit, StringUtils, DataType, DataUnitStorage, ChangeOperation } from '@sankhyalabs/core';
|
2
|
-
import { d as dist, D as DataFetcher } from './DataFetcher-487d6aad.js';
|
3
|
-
import { DISTINCT_FILTER_NAME_PREFIX } from '@sankhyalabs/ezui/dist/collection/utils/constants';
|
4
|
-
import { DataUnitTransient } from '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
5
|
-
|
6
|
-
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
7
|
-
var t = {};
|
8
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
9
|
-
t[p] = s[p];
|
10
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
11
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
12
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
13
|
-
t[p[i]] = s[p[i]];
|
14
|
-
}
|
15
|
-
return t;
|
16
|
-
};
|
17
|
-
class DataUnitFetcher {
|
18
|
-
constructor() {
|
19
|
-
this.templateByQuery = new Map();
|
20
|
-
this._loadDataTimeout = {};
|
21
|
-
this.buldTemplates();
|
22
|
-
}
|
23
|
-
buldTemplates() {
|
24
|
-
this.templateByQuery.set("fetchDataUnit", dist.gql `query($name: String!) {
|
25
|
-
$queryAlias$: fetchDataUnit(name: $name){
|
26
|
-
name
|
27
|
-
fields{
|
28
|
-
name
|
29
|
-
defaultValue
|
30
|
-
label
|
31
|
-
visible
|
32
|
-
readOnly
|
33
|
-
required
|
34
|
-
dataType
|
35
|
-
userInterface
|
36
|
-
calculated
|
37
|
-
group
|
38
|
-
order
|
39
|
-
properties{
|
40
|
-
name
|
41
|
-
value
|
42
|
-
}
|
43
|
-
dependencies{
|
44
|
-
masterFields
|
45
|
-
type
|
46
|
-
expression
|
47
|
-
}
|
48
|
-
}
|
49
|
-
children{
|
50
|
-
name
|
51
|
-
label
|
52
|
-
links{
|
53
|
-
source
|
54
|
-
target
|
55
|
-
}
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}`);
|
59
|
-
this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $limit: Int $offset:Int $filters: [InputFilter!] $sort: [InputSort!] $parentRecordId: String) {
|
60
|
-
$queryAlias$: fetchDataUnit(name: $dataunit){
|
61
|
-
data(limit: $limit offset: $offset filters: $filters sort: $sort parentRecordId: $parentRecordId){
|
62
|
-
limit
|
63
|
-
offset
|
64
|
-
total
|
65
|
-
hasMore
|
66
|
-
records{
|
67
|
-
id
|
68
|
-
label
|
69
|
-
fields {
|
70
|
-
name
|
71
|
-
value
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}`);
|
77
|
-
this.templateByQuery.set("saveData", dist.gql `mutation($changes: [InputBatchChange!]!) {
|
78
|
-
$queryAlias$: batchOperationDataUnit(changes: $changes){
|
79
|
-
oldId
|
80
|
-
id
|
81
|
-
label
|
82
|
-
ownerDataUnitName
|
83
|
-
fields {
|
84
|
-
name
|
85
|
-
value
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}`);
|
89
|
-
this.templateByQuery.set("fetchDataRecord", dist.gql `query($dataunit: String! $recordID: [String!]) {
|
90
|
-
$queryAlias$: fetchDataUnit(name: $dataunit){
|
91
|
-
record(id: $recordID){
|
92
|
-
id
|
93
|
-
label
|
94
|
-
fields {
|
95
|
-
name
|
96
|
-
value
|
97
|
-
}
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}`);
|
101
|
-
this.templateByQuery.set("fetchDistinctColumn", dist.gql `query($dataUnit: String!, $fieldName: String!, $argument: String, $filters: [InputFilter], $parentRecordId: String) {
|
102
|
-
$queryAlias$: selectDistinct(dataUnit: $dataUnit, fieldName: $fieldName, argument: $argument, filters: $filters, parentRecordId: $parentRecordId)
|
103
|
-
}`);
|
104
|
-
}
|
105
|
-
getDataUnit(entityName, resourceID, parentDataUnit, configName) {
|
106
|
-
const duName = `dd://${entityName}/${resourceID}${configName ? "/" + configName : ""}`;
|
107
|
-
const dataUnit = parentDataUnit != undefined ? parentDataUnit.getChildDataunit(duName) : new DataUnit(duName);
|
108
|
-
dataUnit.metadataLoader = (dataUnit) => this.loadMetadata(dataUnit);
|
109
|
-
dataUnit.dataLoader = (dataUnit, request) => this.loadData(dataUnit, request);
|
110
|
-
dataUnit.saveLoader = (_dataUnit, changes) => this.saveData(dataUnit, changes);
|
111
|
-
dataUnit.removeLoader = (dataUnit, recordIds) => this.removeRecords(dataUnit, recordIds);
|
112
|
-
dataUnit.recordLoader = (dataUnit, recordIds) => this.loadRecord(dataUnit, recordIds);
|
113
|
-
return dataUnit;
|
114
|
-
}
|
115
|
-
loadMetadata(dataUnit) {
|
116
|
-
return new Promise((resolve, reject) => {
|
117
|
-
DataFetcher.get()
|
118
|
-
.callGraphQL({
|
119
|
-
values: { name: dataUnit.name },
|
120
|
-
query: this.templateByQuery.get("fetchDataUnit"),
|
121
|
-
})
|
122
|
-
.then((resp) => {
|
123
|
-
var _a;
|
124
|
-
const metadata = {
|
125
|
-
name: resp.name,
|
126
|
-
label: resp.name,
|
127
|
-
children: [...resp.children],
|
128
|
-
fields: []
|
129
|
-
};
|
130
|
-
(_a = resp.fields) === null || _a === void 0 ? void 0 : _a.forEach((source) => {
|
131
|
-
let properties = undefined;
|
132
|
-
if (Array.isArray(source.properties)) {
|
133
|
-
properties = {};
|
134
|
-
if (source.calculated) {
|
135
|
-
properties.gridHeaderTooltip = "Campos calculados não podem ser ordenados";
|
136
|
-
}
|
137
|
-
source.properties.forEach((prop) => (properties[prop.name] = prop.value));
|
138
|
-
}
|
139
|
-
metadata.fields.push(Object.assign(Object.assign({}, source), { properties }));
|
140
|
-
});
|
141
|
-
metadata.fields.sort((a, b) => a.order - b.order);
|
142
|
-
resolve(metadata);
|
143
|
-
})
|
144
|
-
.catch((error) => {
|
145
|
-
reject(error);
|
146
|
-
});
|
147
|
-
});
|
148
|
-
}
|
149
|
-
async loadData(dataUnit, request) {
|
150
|
-
try {
|
151
|
-
const duName = dataUnit.name;
|
152
|
-
if (this._loadDataTimeout[duName]) {
|
153
|
-
clearTimeout(this._loadDataTimeout[duName]);
|
154
|
-
delete this._loadDataTimeout[duName];
|
155
|
-
}
|
156
|
-
const result = await this.doLoadData(dataUnit, request);
|
157
|
-
delete this._loadDataTimeout[duName];
|
158
|
-
await new Promise(resolve => {
|
159
|
-
this._loadDataTimeout[duName] = setTimeout(resolve, 200);
|
160
|
-
});
|
161
|
-
return Promise.resolve(result);
|
162
|
-
}
|
163
|
-
catch (error) {
|
164
|
-
return Promise.reject(error);
|
165
|
-
}
|
166
|
-
}
|
167
|
-
loadSelectDistinct(dataUnit, fieldName, argument) {
|
168
|
-
const { parentRecordId, filters } = dataUnit.getLastLoadRequest() || {};
|
169
|
-
const filteredFilters = filters.filter(f => f.name !== `${DISTINCT_FILTER_NAME_PREFIX}${fieldName}`);
|
170
|
-
const values = {
|
171
|
-
dataUnit: dataUnit.name,
|
172
|
-
argument,
|
173
|
-
fieldName,
|
174
|
-
parentRecordId,
|
175
|
-
filters: filteredFilters
|
176
|
-
};
|
177
|
-
return new Promise((resolve, reject) => {
|
178
|
-
DataFetcher.get()
|
179
|
-
.callGraphQL({
|
180
|
-
values,
|
181
|
-
query: this.templateByQuery.get("fetchDistinctColumn"),
|
182
|
-
})
|
183
|
-
.then((result) => {
|
184
|
-
resolve(result);
|
185
|
-
})
|
186
|
-
.catch((error) => {
|
187
|
-
reject(error);
|
188
|
-
});
|
189
|
-
});
|
190
|
-
}
|
191
|
-
doLoadData(dataUnit, request) {
|
192
|
-
return new Promise((resolve, reject) => {
|
193
|
-
var _a;
|
194
|
-
const { sort, filters, limit, offset, quickFilter } = request;
|
195
|
-
const variables = { dataunit: dataUnit.name, sort, filters };
|
196
|
-
variables.limit = limit;
|
197
|
-
variables.offset = offset;
|
198
|
-
variables.parentRecordId = request.parentRecordId;
|
199
|
-
if (!StringUtils.isEmpty(quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.term)) {
|
200
|
-
if (variables.filter === undefined) {
|
201
|
-
variables.filter = [];
|
202
|
-
}
|
203
|
-
const quickFilterCriteria = {
|
204
|
-
name: "__QUICK_FILTER__",
|
205
|
-
expression: "__QUICK_FILTER__",
|
206
|
-
params: [{ name: "term", dataType: DataType.TEXT, value: quickFilter.term }]
|
207
|
-
};
|
208
|
-
if (((_a = quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.fields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
209
|
-
quickFilterCriteria.params.push({ name: "fields", dataType: DataType.OBJECT, value: quickFilter.fields });
|
210
|
-
}
|
211
|
-
variables.filter.push(quickFilterCriteria);
|
212
|
-
}
|
213
|
-
DataFetcher.get()
|
214
|
-
.callGraphQL({
|
215
|
-
values: variables,
|
216
|
-
query: this.templateByQuery.get("fetchData"),
|
217
|
-
})
|
218
|
-
.then((resp) => {
|
219
|
-
const { limit, offset, total, hasMore, records } = resp.data;
|
220
|
-
let paginationInfo;
|
221
|
-
if (limit) {
|
222
|
-
const firstRecord = total == 0 ? 0 : offset + 1;
|
223
|
-
const lastRecord = offset + Math.min(records.length, limit);
|
224
|
-
const currentPage = offset / limit;
|
225
|
-
paginationInfo = {
|
226
|
-
firstRecord,
|
227
|
-
lastRecord,
|
228
|
-
total,
|
229
|
-
currentPage,
|
230
|
-
hasMore
|
231
|
-
};
|
232
|
-
}
|
233
|
-
const processedRecords = [];
|
234
|
-
records.forEach((responseRecord) => {
|
235
|
-
const duRecord = { __record__id__: responseRecord.id, __record__label__: responseRecord.label };
|
236
|
-
responseRecord.fields.forEach(({ name, value }) => {
|
237
|
-
duRecord[name] = dataUnit.valueFromString(name, value);
|
238
|
-
});
|
239
|
-
processedRecords.push(duRecord);
|
240
|
-
});
|
241
|
-
resolve({
|
242
|
-
paginationInfo,
|
243
|
-
records: processedRecords
|
244
|
-
});
|
245
|
-
})
|
246
|
-
.catch((error) => {
|
247
|
-
reject(error);
|
248
|
-
});
|
249
|
-
});
|
250
|
-
}
|
251
|
-
saveData(dataUnit, duChanges) {
|
252
|
-
const changes = duChanges.map((change) => {
|
253
|
-
const { dataUnit: changeDU, record, updatingFields, operation } = change;
|
254
|
-
const dataUnitInstance = DataUnitStorage.get(changeDU);
|
255
|
-
let parsedUpdatingFields;
|
256
|
-
if (updatingFields) {
|
257
|
-
parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
|
258
|
-
const descriptor = dataUnitInstance.getField(fieldName);
|
259
|
-
const dataType = descriptor ? descriptor.dataType : DataType.TEXT;
|
260
|
-
return { fieldName, dataType, value: dataUnitInstance.valueToString(fieldName, value) };
|
261
|
-
});
|
262
|
-
}
|
263
|
-
const reqChange = { dataUnit: changeDU, fields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
|
264
|
-
if (change.sourceId) {
|
265
|
-
reqChange.sourceId = change.sourceId;
|
266
|
-
}
|
267
|
-
if (record.__parent__record__id__) {
|
268
|
-
reqChange.parentRecordId = record.__parent__record__id__;
|
269
|
-
}
|
270
|
-
return reqChange;
|
271
|
-
});
|
272
|
-
return new Promise((resolve, reject) => {
|
273
|
-
const changesFormatted = changes.map((_a) => {
|
274
|
-
var rest = __rest(_a, []);
|
275
|
-
return rest;
|
276
|
-
});
|
277
|
-
DataFetcher.get()
|
278
|
-
.callGraphQL({
|
279
|
-
values: { changes: changesFormatted },
|
280
|
-
query: this.templateByQuery.get("saveData"),
|
281
|
-
})
|
282
|
-
.then((resp) => {
|
283
|
-
const dataUnitRecords = [];
|
284
|
-
resp === null || resp === void 0 ? void 0 : resp.forEach((responseRecord) => {
|
285
|
-
const duRecord = {
|
286
|
-
__record__id__: responseRecord.id,
|
287
|
-
__record__label__: responseRecord.label,
|
288
|
-
__owner__dataunit__name__: responseRecord.ownerDataUnitName,
|
289
|
-
};
|
290
|
-
const dataUnitInstance = DataUnitStorage.get(duRecord.__owner__dataunit__name__) || dataUnit;
|
291
|
-
if (responseRecord.oldId) {
|
292
|
-
duRecord.__old__id__ = responseRecord.oldId;
|
293
|
-
}
|
294
|
-
responseRecord.fields.forEach(({ name, value }) => {
|
295
|
-
var _a;
|
296
|
-
duRecord[name] = ((_a = dataUnitInstance === null || dataUnitInstance === void 0 ? void 0 : dataUnitInstance.valueFromString) === null || _a === void 0 ? void 0 : _a.call(dataUnitInstance, name, value)) || value;
|
297
|
-
});
|
298
|
-
dataUnitRecords.push(duRecord);
|
299
|
-
});
|
300
|
-
resolve(dataUnitRecords);
|
301
|
-
})
|
302
|
-
.catch((error) => {
|
303
|
-
reject(error);
|
304
|
-
});
|
305
|
-
});
|
306
|
-
}
|
307
|
-
getTransientInfo(dataUnit, recordID) {
|
308
|
-
const { records } = dataUnit.getSelectionInfo();
|
309
|
-
return Object.entries(records.filter(record => record.__record__id__ == recordID)[0]).filter(([key]) => key.startsWith(DataUnitTransient.DATA_UNIT_TRANSIENT_PREFIX_NAME)).map(([name, value]) => ({ fieldName: name, value, dataType: DataType.TEXT }));
|
310
|
-
}
|
311
|
-
removeRecords(dataUnit, recordIds) {
|
312
|
-
const changes = recordIds.map((recordId) => {
|
313
|
-
return { dataUnit: dataUnit.name, operation: ChangeOperation.DELETE, recordId, fields: this.getTransientInfo(dataUnit, recordId) };
|
314
|
-
});
|
315
|
-
return new Promise((resolve, reject) => {
|
316
|
-
DataFetcher.get()
|
317
|
-
.callGraphQL({
|
318
|
-
values: { changes: changes },
|
319
|
-
query: this.templateByQuery.get("saveData"),
|
320
|
-
})
|
321
|
-
.then((_resp) => {
|
322
|
-
resolve(recordIds);
|
323
|
-
})
|
324
|
-
.catch((error) => {
|
325
|
-
reject(error);
|
326
|
-
});
|
327
|
-
});
|
328
|
-
}
|
329
|
-
loadRecord(dataUnit, recordIds) {
|
330
|
-
return new Promise((resolve, reject) => {
|
331
|
-
DataFetcher.get()
|
332
|
-
.callGraphQL({
|
333
|
-
values: { recordID: recordIds, dataunit: dataUnit.name },
|
334
|
-
query: this.templateByQuery.get("fetchDataRecord"),
|
335
|
-
})
|
336
|
-
.then((response) => {
|
337
|
-
const dataUnitRecords = [];
|
338
|
-
response.record.forEach(responseRecord => {
|
339
|
-
const duRecord = { __record__id__: responseRecord.id, __record__label__: responseRecord.label };
|
340
|
-
responseRecord.fields.forEach(({ name, value }) => {
|
341
|
-
duRecord[name] = dataUnit.valueFromString(name, value);
|
342
|
-
});
|
343
|
-
dataUnitRecords.push(duRecord);
|
344
|
-
});
|
345
|
-
resolve(dataUnitRecords);
|
346
|
-
})
|
347
|
-
.catch((error) => {
|
348
|
-
reject(error);
|
349
|
-
});
|
350
|
-
});
|
351
|
-
}
|
352
|
-
}
|
353
|
-
|
354
|
-
export { DataUnitFetcher as D };
|
@@ -1,165 +0,0 @@
|
|
1
|
-
import { DataType } from '@sankhyalabs/core';
|
2
|
-
import { d as dist, D as DataFetcher } from './DataFetcher-487d6aad.js';
|
3
|
-
|
4
|
-
class PesquisaFetcher {
|
5
|
-
constructor() {
|
6
|
-
this._defaultPageSize = 100;
|
7
|
-
this._templateByQuery = new Map();
|
8
|
-
this._searchListenersByDataUnit = new Map();
|
9
|
-
this.buldTemplates();
|
10
|
-
}
|
11
|
-
buldTemplates() {
|
12
|
-
this._templateByQuery.set("search", dist.gql `query($entityName: String! $argument: String $criteria: InputSearchCriteria $options: InputSearchOptions) {
|
13
|
-
$queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria options: $options){
|
14
|
-
value
|
15
|
-
label
|
16
|
-
}
|
17
|
-
}`);
|
18
|
-
}
|
19
|
-
loadSearchOptions(entityName, argument, criteria, options) {
|
20
|
-
var _a;
|
21
|
-
const cleanText = (argument === null || argument === void 0 ? void 0 : argument.toString().trim()) || undefined;
|
22
|
-
argument = isNaN(Number(cleanText)) && cleanText ? `%${cleanText}` : cleanText;
|
23
|
-
criteria === null || criteria === void 0 ? void 0 : criteria.params.forEach(param => {
|
24
|
-
if (param.dataType === DataType.OBJECT) {
|
25
|
-
param.value = JSON.stringify(param.value);
|
26
|
-
}
|
27
|
-
});
|
28
|
-
const listenerResult = this.applySearchListener(SearchListenerType.beforeSearch, entityName, argument, criteria, options);
|
29
|
-
const values = {
|
30
|
-
argument: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.argument) || argument,
|
31
|
-
entityName,
|
32
|
-
criteria: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.criteria) || criteria,
|
33
|
-
options: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.searchOptions) || options,
|
34
|
-
};
|
35
|
-
if (values.options) {
|
36
|
-
(_a = values.options) === null || _a === void 0 ? true : delete _a.dataUnitId;
|
37
|
-
}
|
38
|
-
return new Promise((resolve, reject) => {
|
39
|
-
DataFetcher.get()
|
40
|
-
.callGraphQL({
|
41
|
-
values,
|
42
|
-
query: this._templateByQuery.get("search"),
|
43
|
-
})
|
44
|
-
.then((result) => {
|
45
|
-
resolve(result);
|
46
|
-
})
|
47
|
-
.catch((error) => {
|
48
|
-
reject(error);
|
49
|
-
});
|
50
|
-
});
|
51
|
-
}
|
52
|
-
loadAdvancedSearch(entityName, argument, criteria, searchOptions) {
|
53
|
-
var _a, _b, _c;
|
54
|
-
const listenerResult = this.applySearchListener(SearchListenerType.beforeSearch, entityName, argument, criteria, searchOptions);
|
55
|
-
const values = {
|
56
|
-
argument: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.argument) || argument,
|
57
|
-
criteria: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.criteria) || criteria,
|
58
|
-
searchOptions: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.searchOptions) || searchOptions,
|
59
|
-
};
|
60
|
-
const serviceName = "PesquisaSP.getSuggestion";
|
61
|
-
const externalCriteria = {
|
62
|
-
query: {
|
63
|
-
$: (_a = values.criteria) === null || _a === void 0 ? void 0 : _a.expression
|
64
|
-
}
|
65
|
-
};
|
66
|
-
if (((_b = values.criteria) === null || _b === void 0 ? void 0 : _b.params.length) > 0) {
|
67
|
-
externalCriteria.params = {
|
68
|
-
param: values.criteria.params.map(param => {
|
69
|
-
let value = param.value;
|
70
|
-
let type = param.dataType;
|
71
|
-
if (type === DataType.OBJECT) {
|
72
|
-
value = value.value;
|
73
|
-
type = "S";
|
74
|
-
}
|
75
|
-
else {
|
76
|
-
type = convertParamType(param.dataType);
|
77
|
-
}
|
78
|
-
return { $: value, type };
|
79
|
-
})
|
80
|
-
};
|
81
|
-
}
|
82
|
-
const options = searchOptions != undefined
|
83
|
-
? {
|
84
|
-
"pkFieldName": searchOptions.codeFieldName,
|
85
|
-
"label": searchOptions.descriptionFieldName,
|
86
|
-
"fieldName": searchOptions.codeFieldName,
|
87
|
-
"useDescriptionOptions": false,
|
88
|
-
"enableRowsCounter": true
|
89
|
-
}
|
90
|
-
: undefined;
|
91
|
-
const reqBody = {
|
92
|
-
"serviceName": serviceName,
|
93
|
-
"requestBody": {
|
94
|
-
"criteria": Object.assign({ "entityName": entityName, "compacted": false, "ignoreEntityCriteria": false, "limit": this._defaultPageSize, "query": { "$": values.argument }, "orderByDesc": false, "externalCriteria": externalCriteria, "localEntityName": (_c = values.searchOptions) === null || _c === void 0 ? void 0 : _c.rootEntity }, { options }),
|
95
|
-
"clientEventList": {
|
96
|
-
"clientEvent": []
|
97
|
-
}
|
98
|
-
}
|
99
|
-
};
|
100
|
-
return new Promise((resolve, reject) => {
|
101
|
-
DataFetcher.get()
|
102
|
-
.callServiceBroker("PesquisaSP.getSuggestion", JSON.stringify(reqBody))
|
103
|
-
.then(result => resolve(result))
|
104
|
-
.catch(error => reject(error));
|
105
|
-
});
|
106
|
-
}
|
107
|
-
addSearchListener(entityName, dataUnitID, listener) {
|
108
|
-
var _a;
|
109
|
-
const dataUnitSearchListeners = this._searchListenersByDataUnit.get(dataUnitID) || [];
|
110
|
-
const entityListener = dataUnitSearchListeners.find(currentListener => currentListener.entity === entityName);
|
111
|
-
if (!entityListener) {
|
112
|
-
this._searchListenersByDataUnit.set(dataUnitID, [...dataUnitSearchListeners, { entity: entityName, listener }]);
|
113
|
-
}
|
114
|
-
else {
|
115
|
-
for (const type of Object.keys(listener)) {
|
116
|
-
if (type in entityListener.listener) {
|
117
|
-
const listenerFunctionIsEquals = ((_a = entityListener.listener[type]) === null || _a === void 0 ? void 0 : _a.toString()) === listener[type].toString();
|
118
|
-
if (listenerFunctionIsEquals)
|
119
|
-
continue;
|
120
|
-
entityListener.listener[type] = listener[type];
|
121
|
-
}
|
122
|
-
}
|
123
|
-
}
|
124
|
-
return () => {
|
125
|
-
const newListeners = dataUnitSearchListeners.filter(currentListener => currentListener.entity !== entityName);
|
126
|
-
if (!newListeners.length) {
|
127
|
-
this._searchListenersByDataUnit.delete(dataUnitID);
|
128
|
-
return;
|
129
|
-
}
|
130
|
-
this._searchListenersByDataUnit.set(dataUnitID, newListeners);
|
131
|
-
};
|
132
|
-
}
|
133
|
-
applySearchListener(listenerType, entityName, argument, criteria, searchOptions) {
|
134
|
-
var _a;
|
135
|
-
const dataUnitId = searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.dataUnitId;
|
136
|
-
if (!dataUnitId)
|
137
|
-
return;
|
138
|
-
const entityListener = (_a = this._searchListenersByDataUnit.get(dataUnitId)) === null || _a === void 0 ? void 0 : _a.find(({ entity }) => entity === entityName);
|
139
|
-
if (!entityListener)
|
140
|
-
return;
|
141
|
-
const { listener } = entityListener;
|
142
|
-
if (!(listenerType in listener))
|
143
|
-
return;
|
144
|
-
return listener[listenerType]({ argument, criteria, searchOptions });
|
145
|
-
}
|
146
|
-
}
|
147
|
-
function convertParamType(dataType) {
|
148
|
-
//Alerta: Cuidado pra não contaminar o DataType com a implementação
|
149
|
-
//atual da pesquisa... em geral, somente inteiros,
|
150
|
-
//data (com ou sem hora) e string são realmente relevantes
|
151
|
-
switch (dataType) {
|
152
|
-
case DataType.NUMBER:
|
153
|
-
return "I";
|
154
|
-
case DataType.DATE:
|
155
|
-
return "D";
|
156
|
-
default:
|
157
|
-
return "S";
|
158
|
-
}
|
159
|
-
}
|
160
|
-
var SearchListenerType;
|
161
|
-
(function (SearchListenerType) {
|
162
|
-
SearchListenerType["beforeSearch"] = "beforeSearch";
|
163
|
-
})(SearchListenerType || (SearchListenerType = {}));
|
164
|
-
|
165
|
-
export { PesquisaFetcher as P };
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,c as i,h as s,H as e,g as a}from"./p-d2d301a6.js";import{StringUtils as h,ElementIDUtils as o,ApplicationContext as n}from"@sankhyalabs/core";import{T as r}from"./p-c9841939.js";import"./p-e2160bdd.js";import"./p-ee57d9f5.js";import{P as d}from"./p-5534e08c.js";import"./p-9e7d65a4.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-584d7212.js";import"./p-33745612.js";import{c}from"./p-4a78e118.js";import{A as l}from"./p-719c246f.js";import"./p-6dc031de.js";import"./p-112455b1.js";import"./p-8d884fab.js";const m=class{constructor(s){t(this,s),this.actionClick=i(this,"actionClick",7),this.configuratorSave=i(this,"configuratorSave",7),this.configuratorCancel=i(this,"configuratorCancel",7),this.formItemsReady=i(this,"formItemsReady",7),this._viewHistory=[],this._dataUnit=void 0,this._dataState=void 0,this.attachmentRegisterKey=void 0,this._currentViewMode=c.GRID,this._canEdit=void 0,this._resourceID=void 0,this.configName=void 0,this.selectionToastConfig=void 0,this.showActionButtons=!1,this.actionsList=void 0,this.taskbarManager=void 0,this.recordsValidator=void 0,this.statusResolver=void 0,this.multipleSelection=!0,this.presentationMode=d.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.customContainerId=`SNK-CRUD-CUSTOM-CONTAINER-${h.generateUUID()}`}async goToView(t){this.executeAction(t)}async openConfigurator(){var t;null===(t=this._snkConfigurator)||void 0===t||t.open()}async closeConfigurator(){var t;null===(t=this._snkConfigurator)||void 0===t||t.close()}async reloadFilterBar(){var t;null===(t=this._snkGrid)||void 0===t||t.reloadFilterBar()}currentViewModeWatcher(t){this._viewHistory=[...this._viewHistory.slice(-1),t]}async gridToForm(t=!1){this._backToGrid=!t&&await this._viewStack.getSelectedIndex()===c.GRID,this.setViewMode(c.FORM)}async executeAction(t){return t===r.GRID_MODE?this.setViewMode(c.GRID):t===r.FORM_MODE||t===r.UPDATE?this.gridToForm(t!==r.UPDATE):t===r.CONFIGURATOR?this._snkConfigurator.open():"ATTACH"===t?this.setViewMode(c.ATTACHMENT):void 0}backView(){const t=this._viewHistory.at(-2)||c.GRID;this.setViewMode(t)}setViewMode(t){this._viewStack.show(t),this._currentViewMode=t}openConfig(t){this._snkConfigurator.close(),t===c.GRID?this._snkGrid.showConfig():t===c.FORM&&this._guidesViewer.showFormConfig()}addDataElementID(){o.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}insertionModeHandler(){this.gridToForm()}cancelHandler(){this._backToGrid&&this.setViewMode(c.GRID)}async getAttachmentRegisterKey(){if(this._snkDataUnit)return(await this._snkDataUnit.getSelectedRecordsIDsInfo()).map((({value:t})=>t)).join("_")}componentWillLoad(){const t=n.getContextValue("__SNK__APPLICATION__");t.hasAccess(l.UPDATE,this._resourceID).then((t=>this._canEdit=t));let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._snkDataUnit.addEventListener("insertionMode",(()=>this.insertionModeHandler())),this._snkDataUnit.addEventListener("cancelEdition",(()=>this.cancelHandler())),this._dataUnit=this._snkDataUnit.dataUnit,this._dataState=this._snkDataUnit.dataState,this._dataUnit?this.initDataUnit(t):this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail,this.initDataUnit(t)})),this._snkDataUnit.addEventListener("dataStateChange",(async({detail:t})=>{this._dataState=t,void 0!==t.selectedRecord&&(this.attachmentRegisterKey=await this.getAttachmentRegisterKey())}));break}i=i.parentElement}this.configName||(this.configName=t.configName)}async initDataUnit(t){this.addDataElementID(),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),null==this._resourceID&&(this._resourceID=this._snkDataUnit.resourceID,null==this._resourceID&&(this._resourceID=await t.getResourceID()))}handleConfiguratorEvent(t,i){t.stopImmediatePropagation(),"SAVE"!==i?this.configuratorCancel.emit():this.configuratorSave.emit()}render(){if(null!=this._resourceID)return this._snkDataUnit.ignoreSaveMessage=this._currentViewMode===c.GRID,s(e,null,s("ez-view-stack",{ref:t=>this._viewStack=t,"data-element-id":"crud"},s("stack-item",null,s("snk-grid",{ref:t=>this._snkGrid=t,"data-element-id":"crud_grid",configName:this.configName,onGridDoubleClick:()=>this.gridToForm(!0),taskbarManager:this.taskbarManager,onActionClick:t=>this.executeAction(t.detail),messagesBuilder:this.messagesBuilder,actionsList:this.actionsList,statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,presentationMode:this.presentationMode,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,canEdit:this._canEdit,resourceID:this._resourceID},s("slot",{name:"GRID_TASKBAR_CUSTOM_ELEMENTS"}),s("slot",{name:"GRID_HEADER_CUSTOM_ELEMENTS"}),s("slot",{name:"SnkGridHeader"}),s("slot",{name:"SnkGridFooter"}),s("slot",{name:"SnkGridTaskBar"}))),s("stack-item",null,s("snk-guides-viewer",{ref:t=>this._guidesViewer=t,entityPath:this._snkDataUnit.entityName,messagesBuilder:this.messagesBuilder,onExit:()=>this.setViewMode(c.GRID),dataState:this._dataState,dataUnit:this._dataUnit,actionsList:this.actionsList,taskbarManager:this.taskbarManager,configName:this.configName,onActionClick:t=>this.executeAction(t.detail),presentationMode:this.presentationMode,"data-element-id":"crud_form",canEdit:this._canEdit,resourceID:this._resourceID,detailTaskbarCustomContainerId:this.customContainerId},s("slot",{name:"GUIDES_VIEWER_TASKBAR_CUSTOM_ELEMENTS"}),s("slot",{name:"SnkFormTaskBar"}))),s("stack-item",null,s("snk-attach",{registerKey:this.attachmentRegisterKey,messagesBuilder:this.messagesBuilder,entityName:this._snkDataUnit.entityName,onBack:this.backView.bind(this)})),s("snk-configurator",{ref:t=>this._snkConfigurator=t,viewMode:this._currentViewMode,messagesBuilder:this.messagesBuilder,onConfigSelected:t=>this.setViewMode(t.detail),onOpenConfig:t=>this.openConfig(t.detail),showActionButtons:this.showActionButtons,onSave:t=>this.handleConfiguratorEvent(t,"SAVE"),onCancel:t=>this.handleConfiguratorEvent(t,"CANCEL"),resourceID:this._resourceID,customContainerId:this.customContainerId})),s("div",{id:`${this.customContainerId}`},s("slot",{name:"SnkConfigContainerSlot"}),s("slot",{name:"DETAIL_GRID_HEADER_CUSTOM_ELEMENTS"}),s("slot",{name:"DETAIL_GRID_TASKBAR_CUSTOM_ELEMENTS"}),s("slot",{name:"DETAIL_TASKBAR_CUSTOM_ELEMENTS"})))}get _element(){return a(this)}static get watchers(){return{_currentViewMode:["currentViewModeWatcher"]}}};m.style=".sc-snk-crud-h{display:flex;flex-direction:column;height:100%;width:100%}";export{m as snk_crud}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,c as i,f as s,h as e,H as a}from"./p-d2d301a6.js";import{S as h}from"./p-5d62a74e.js";import{FormMetadata as o,buildFormMetadata as n}from"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-e2160bdd.js";import"./p-ee57d9f5.js";import"@sankhyalabs/core";import{P as r}from"./p-5534e08c.js";import"./p-9e7d65a4.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-584d7212.js";import"./p-33745612.js";import{T as d}from"./p-c9841939.js";import{c as l}from"./p-4a78e118.js";import{S as c}from"./p-89b3df4c.js";import{S as m}from"./p-f1f7b545.js";import"./p-358e8f7b.js";import"./p-112455b1.js";import"./p-8d884fab.js";import"./p-6dc031de.js";import"./p-c2beb95c.js";import"@sankhyalabs/core/dist/dataunit/DataUnit";class u{constructor(t,i,s){this._parentGuide=t,this._formMetadata=i,this._dataUnit=s}get id(){return this._parentGuide.id}buildGuideItem(t){const i=Object.assign({},this._parentGuide);delete i.expanded,delete i.children;const s=this._dataUnit.getSelectedRecord();if(!s)return i;const e=this._dataUnit.isNewRecord(s.__record__id__),a=Array.from(this._formMetadata.getAllSheets().values()).map((i=>{const{name:s,label:a}=i,h=null!=o.getDetailName(s.split("::").pop()),n=h&&e,r=this._parentGuide.id,d=h?`${r}::${s}`:`${r}__FORM:${s}`;return h&&t.has(d)&&!n?t.get(d).buildGuideItem(t):{id:d,label:a,disabled:n,tooltip:n?"Finalize o cadastro para ter acesso a esta guia.":void 0}})),h=a.shift();return h.label=e?"Novo Registro":s.__record__label__,h.children=a,i.children=[h],i}}const p=class{constructor(s){t(this,s),this.snkDetailGuidesChange=i(this,"snkDetailGuidesChange",7),this.snkSwitchGuide=i(this,"snkSwitchGuide",7),this.formItemsReady=i(this,"formItemsReady",7),this._disabledButtons=void 0,this._currentView=void 0,this.attachmentRegisterKey=void 0,this.formConfigManager=void 0,this.dataUnitName=void 0,this.resourceID=void 0,this.guideItemPath=void 0,this.entityName=void 0,this.label=void 0,this.dataUnit=void 0,this.selectedForm=void 0,this.dataState=void 0,this.messagesBuilder=void 0,this.branchGuide=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0}observerDataState(t,i){const s=!(null==i?void 0:i.insertionMode)&&(null==t?void 0:t.insertionMode),e=(null==i?void 0:i.insertionMode)&&!(null==t?void 0:t.insertionMode);if((s||e)&&this.loadMetadata(),null==this._formMetadata)return;const a=null==t?void 0:t.selectedRecord,h=null==i?void 0:i.selectedRecord;(null==a?void 0:a.__record__id__)!==(null==h?void 0:h.__record__id__)&&this.snkDetailGuidesChange.emit(new u(this.branchGuide,this._formMetadata,this.dataUnit)),s&&setTimeout((()=>{this.changeViewMode(l.FORM)}),0),e&&this.changeViewMode(l.GRID);const o=[];this.dataState.hasPrevious||o.push(d.PREVIOUS),this.dataState.hasNext||o.push(d.NEXT),this._disabledButtons=o}async changeViewMode(t){this.emitSwitchEvent(t)}async configGrid(){this._snkGrid&&this._snkGrid.showConfig()}async showUp(){this._snkFormView&&this._snkFormView.showUp(),this._snkGrid&&this._snkGrid.scrollIntoView({behavior:"smooth",block:"start"})}onContentCardChanged(t){c.updateContentCard(t.detail.formName,t.detail.cardConfig,t.detail.propertyChanged,this.formConfigManager).then((()=>s(this))),t.stopPropagation()}updateLabel(){const t=this.guideItemPath?this.guideItemPath.length:0;if(t>0){const i=t>0?this.guideItemPath.map((t=>t.label)):void 0;this.label=i.pop(),this._levelPath=i.length>0?i.join(" / "):void 0}else this.label="",this._levelPath=void 0}getFormGuideId(t){var i;if(!t){if(null==(null===(i=this.dataState)||void 0===i?void 0:i.selectedRecord))return;const s=Array.from(this._formMetadata.getAllSheets().keys());if(!s||0==s.length)return;t=s[0]}return`${this.stripFormPattern(this.branchGuide.id)}__FORM:${t}`}stripFormPattern(t){return t.replace(p.REGEX_FORM_ID,"")}loadMetadata(){var t;if(!this.dataUnit)return;if(!this.formConfigManager.isLoaded)return;const i=this.formConfigManager.getConfig(null===(t=this.dataState)||void 0===t?void 0:t.insertionMode,this.dataUnit);this._formMetadata=n(null==i||0===i.fields.length?void 0:i,this.dataUnit,!0)}dataUnitReadyHandler(t){this.dataUnit=t.detail,this.loadMetadata()}updateViewStack(t){var i,s;this._viewStack=t,this._currentView=this.selectedForm?1:0,null===(s=null===(i=this._viewStack)||void 0===i?void 0:i.show)||void 0===s||s.call(i,this._currentView)}getFormFields(){return this.selectedForm&&this._formMetadata?this._formMetadata.getSheet(this.selectedForm).fields:[]}emitSwitchEvent(t){const i=t===l.GRID?this.stripFormPattern(this.branchGuide.id):this.getFormGuideId();i&&this.snkSwitchGuide.emit(i)}handleAttachBack(){this._viewStack.show(l.GRID)}executeActionHandler(t){t.detail===d.GRID_MODE&&(this.emitSwitchEvent(l.GRID),t.stopPropagation()),t.detail===d.FORM_MODE&&(this.emitSwitchEvent(l.FORM),t.stopPropagation()),t.detail===d.ATTACH&&(this._viewStack.show(l.ATTACHMENT),t.stopPropagation())}async getAttachmentRegisterKey(){if(this._snkDataUnit)return(await this._snkDataUnit.getSelectedRecordsIDsInfo()).map((({value:t})=>t)).join("_")}async handleDataStateChange({detail:t}){this.dataState=t,void 0!==t.selectedRecord&&this._snkDataUnit&&(this.attachmentRegisterKey=await this.getAttachmentRegisterKey())}componentWillLoad(){this._configName=`dynaform.${this.entityName}`,this.formConfigManager=new h(this._configName,this.resourceID,(()=>this.loadMetadata())),this.formConfigManager.loadConfig(),null==this.messagesBuilder&&(this.messagesBuilder=new m(this.entityName))}render(){return this.updateLabel(),e(a,null,e("snk-data-unit",{ref:t=>this._snkDataUnit=t,dataUnitName:`${this.dataUnitName}`,onDataUnitReady:t=>this.dataUnitReadyHandler(t),entityName:this.entityName,onDataStateChange:this.handleDataStateChange.bind(this),ignoreSaveMessage:this._currentView===l.GRID,messagesBuilder:this.messagesBuilder,configName:this._configName},e("ez-view-stack",{ref:t=>this.updateViewStack(t)},e("stack-item",null,e("div",{class:"ez-box ez-box--shadow grid-container"},e("div",{class:"ez-flex ez-title--primary ez-size-width--full ez-padding--large detail-header"},e("div",{class:"ez-flex ez-text ez-text--bold ez-flex--justify-start ez-flex--align-items-center"},this._levelPath?e("span",{class:"level-path"},this._levelPath+" /"):void 0,this.label)),e("snk-grid",{class:"ez-size-width--full ez-size-height--full",ref:t=>this._snkGrid=t,configName:this._configName,messagesBuilder:this.messagesBuilder,onGridDoubleClick:()=>this.emitSwitchEvent(l.FORM),onActionClick:t=>this.executeActionHandler(t),presentationMode:r.SECONDARY,canEdit:this.canEdit,isDetail:!0,taskbarCustomContainerId:this.taskbarCustomContainerId,gridHeaderCustomSlotId:"DETAIL_GRID_HEADER_CUSTOM_ELEMENTS",topTaskbarCustomSlotId:"DETAIL_GRID_TASKBAR_CUSTOM_ELEMENTS"}))),e("stack-item",null,e("snk-form-view",{ref:t=>this._snkFormView=t,canExpand:!1,canFix:!1,name:this.selectedForm,formMetadata:this._formMetadata,dataUnit:this.dataUnit,fields:this.getFormFields(),label:this.label,levelPath:this._levelPath,onFormItemsReady:({detail:t})=>this.formItemsReady.emit(t)},e("snk-taskbar",{key:"guideViewerTaskbar",class:"form-taskbar","data-element-id":"guideViewer",configName:this._configName,messagesBuilder:this.messagesBuilder,disabledButtons:this._disabledButtons,buttons:"INSERT,PREVIOUS,NEXT,DIVIDER,CLONE,REMOVE,MORE_OPTIONS,DIVIDER,GRID_MODE,CONFIGURATOR",primaryButton:"INSERT",presentationMode:r.SECONDARY,onActionClick:t=>this.executeActionHandler(t),dataUnit:this.dataUnit,resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:"DETAIL_TASKBAR_CUSTOM_ELEMENTS"},e("slot",{name:"DETAIL_TASKBAR_CUSTOM_ELEMENTS"})))),e("stack-item",null,e("snk-attach",{registerKey:this.attachmentRegisterKey,messagesBuilder:this.messagesBuilder,entityName:this.entityName,onBack:this.handleAttachBack.bind(this)})))))}static get watchers(){return{dataState:["observerDataState"]}}};p.REGEX_FORM_ID=/__FORM:[^:]+/g,p.style=".sc-snk-detail-view-h{display:flex;row-gap:24px;flex-direction:column;width:100%;height:100%}.level-path.sc-snk-detail-view{color:var(--color--title-primary, #2B3A54);font-weight:var(--text-weight--medium, 400);padding-right:3px}.form-taskbar.sc-snk-detail-view{padding-bottom:var(--space--medium)}.grid-container.sc-snk-detail-view{background-color:#FFF;min-height:100px}.detail-header.sc-snk-detail-view{padding-bottom:0}";export{p as snk_detail_view}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,c as e,h as i}from"./p-d2d301a6.js";import{ApplicationContext as s,DataType as n,Action as a}from"@sankhyalabs/core";import{D as r}from"./p-e2160bdd.js";import{S as o}from"./p-9e7d65a4.js";import{c as h}from"./p-4a78e118.js";import{D as d}from"./p-90946802.js";import{T as l}from"./p-c9841939.js";import"./p-112455b1.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-8d884fab.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"./p-5534e08c.js";import"./p-6dc031de.js";class c{constructor(t,e,i){var s;this.entityName=t,this.registerKey=e,this.dataUnitName=i,this.validateFields=t=>{if(t.LINK&&t.NOMEARQUIVO)throw new Error(o.LINK_AND_FILE_AT_THE_SAME_TIME);if(!t.LINK&&!t.NOMEARQUIVO)throw new Error(o.ANY_LINK_OR_FILE_FILLED);if(!this.registerKey)throw new Error("Register key can not be null")},this.resourceID=window.resourceID||(null===(s=window.workspace)||void 0===s?void 0:s.resourceID)}async save(t){var e,i;const s="AnexoSistemaSP.salvar";let{updatingFields:n}=t;n=Object.assign(Object.assign({},n),{NOMEARQUIVO:null===(e=n.NOMEARQUIVO)||void 0===e?void 0:e[0]});try{this.validateFields(n);const t=n.LINK?null:n.NOMEARQUIVO,e={serviceName:s,requestBody:{params:{resourceID:this.resourceID,description:n.DESCRICAO,fileSelect:t?1:0,keySession:null===(i=null==t?void 0:t.properties)||void 0===i?void 0:i.fileNameTmp,nameAttach:null==t?void 0:t.name,link:n.LINK,nameEntity:this.entityName,pkEntity:this.registerKey,typeAcess:n.TIPOACESSO,typeApres:n.TIPOAPRES}}},a=await r.get().callServiceBroker(s,JSON.stringify(e));return Promise.resolve([Object.assign(Object.assign(Object.assign({},a),n),{ARQUIVOOULINK:n.LINK?n.LINK:null==t?void 0:t.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}async edit(t){var e,i,s;const n="AnexoSistemaSP.salvar";let{updatingFields:a,record:o}=t;const h=t=>void 0!==a[t]?a[t]:o[t],d=h("NOMEARQUIVO"),l=null===(i=null===(e=a.NOMEARQUIVO)||void 0===e?void 0:e[0])||void 0===i?void 0:i.downloadURL;a=Object.assign(Object.assign({},a),{DESCRICAO:h("DESCRICAO"),LINK:h("LINK"),TIPOACESSO:h("TIPOACESSO"),TIPOAPRES:h("TIPOAPRES"),CHAVEARQUIVO:o.CHAVEARQUIVO,NOMEARQUIVO:null==d?void 0:d[0]});const c=a.LINK?null:a.NOMEARQUIVO;try{this.validateFields(a);const t={serviceName:n,requestBody:{params:{resourceID:this.resourceID,nuAttach:null==o?void 0:o.NUATTACH,description:a.DESCRICAO,fileSelect:l?1:0,keySession:null===(s=null==c?void 0:c.properties)||void 0===s?void 0:s.fileNameTmp,keyAttach:a.CHAVEARQUIVO,nameAttach:null==c?void 0:c.name,link:a.LINK,nameEntity:this.entityName,pkEntity:this.registerKey,typeAcess:a.TIPOACESSO,typeApres:a.TIPOAPRES}}},e=await r.get().callServiceBroker(n,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},e),a),{ARQUIVOOULINK:a.LINK?a.LINK:null==c?void 0:c.name,__owner__dataunit__name__:this.dataUnitName})])}catch(t){return Promise.reject(t)}}delete(t){var e;const i="AnexoSistemaSP.excluir",s=(null===(e=t.NOMEARQUIVO)||void 0===e?void 0:e[0])||{},n={serviceName:i,requestBody:{paramsDelete:{keyAttach:t.CHAVEARQUIVO,nameAttach:null==s?void 0:s.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO}}};return new Promise(((t,e)=>{r.get().callServiceBroker(i,JSON.stringify(n)).then((e=>t(e))).catch((t=>e(t)))}))}getDownloadKey(t){var e;const i="AnexoSistemaSP.baixar",s=(null===(e=t.NOMEARQUIVO)||void 0===e?void 0:e[0])||{},n={serviceName:i,requestBody:{paramsDown:{nameAttach:null==s?void 0:s.name,nameEntity:t.NOMEINSTANCIA,nuAttach:t.NUATTACH,pkEntity:t.PKREGISTRO,keyAttach:t.CHAVEARQUIVO}}};return new Promise(((t,e)=>{r.get().callServiceBroker(i,JSON.stringify(n)).then((e=>t(e))).catch((t=>e(t)))}))}}class m{constructor(t,e){this.entityName=t,this.getMessage=e,this._application=s.getContextValue("__SNK__APPLICATION__")}initLoaders(t,e,i){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,e)=>this.dataLoader(t,e),t.saveLoader=(t,s)=>this.saveLoader(s,e).then((t=>(t.length&&i(),t))),t.removeLoader=(t,s)=>this.removeLoader(t,s,e).then((t=>(t.length&&i(),t)))}dataLoader(t,e){return new Promise((i=>{this.loader(t,e).then((t=>{const e=((null==t?void 0:t.records)||[]).map((t=>{let e;return t.LINK||(e=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:e})}));i(Object.assign(Object.assign({},t),{records:e}))}))}))}saveLoader(t,e){return new Promise((i=>{var s;const n=Array.isArray(t)?t[0]:{};((null===(s=null==n?void 0:n.record)||void 0===s?void 0:s.NUATTACH)>=0?e.edit.bind(e):e.save.bind(e))(n).then((t=>{i(t)})).catch((t=>t.message===o.LINK_AND_FILE_AT_THE_SAME_TIME?(this._application.alert(this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.title"),this.getMessage("snkAttach.alertValidation.fileAndLinkAtTheSameTime.message")),i([])):t.message===o.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),i([])):t.message?(this._application.error(t.title||t.name,t.message),i([])):void i([])))}))}removeLoader(t,e,i){return new Promise((s=>{const{records:n}=t.getSelectionInfo();i.delete(n[0]).then((()=>s(e)))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:n.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,e,i){return new Promise((s=>e.type===a.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(i.goToView(h.GRID),s(e)):s(void 0))):s(e):e.type===a.DATA_SAVED?(t.loadData(),s(e)):void s(e)))}}const u=s.getContextValue("__SNK__APPLICATION__"),v=t=>{var e,i;return null===(i=null===(e=null==u?void 0:u.messagesBuilder)||void 0===e?void 0:e.getMessage)||void 0===i?void 0:i.call(e,t,null)},A={DOWNLOAD:{hint:v("snkAttach.taskbar.titleDownload"),name:"DOWNLOAD",iconName:"file-download"},LINK:{hint:v("snkAttach.taskbar.titleLink"),name:"LINK",iconName:"launch"}},O=()=>{const t=[l.REMOVE,"DOWNLOAD","LINK"];return{getButtons:(t,e,i)=>{if((null==e?void 0:e.insertionMode)||(null==e?void 0:e.isDirty))return i.reverse();i.splice(i.indexOf(l.REFRESH),1);const{selectedRecord:s}=e||{},n=(null==s?void 0:s.LINK)?A.LINK:A.DOWNLOAD;i.splice(i.indexOf(l.DIVIDER)+1,0,l.REMOVE,n,l.DIVIDER);const a=Array.from(new Set(i.filter((t=>t!==l.CLONE))));return a.splice(a.indexOf(n)+1,0,l.DIVIDER),a},isEnabled:(e,i,s)=>{const n=void 0!==(null==i?void 0:i.selectedRecord);return!(t.includes(s)&&!n)}}},p={grid:{columns:[{name:"ARQUIVOOULINK",orderIndex:0,width:0},{name:"DESCRICAO",orderIndex:1,width:0},{name:"DHCAD",orderIndex:2,width:0},{name:"DHALTER",orderIndex:3,width:0},{name:"TIPOAPRES",orderIndex:4,width:0},{name:"TIPOACESSO",orderIndex:5,width:0},{name:"CODUSU",orderIndex:6,width:0},{name:"CODUSUALT",orderIndex:7,width:0}]},form:{emptyConfig:!1,fields:[{name:"DESCRICAO",required:!0},{name:"TIPOAPRES",required:!0},{name:"TIPOACESSO",required:!0},{name:"LINK"},{name:"NOMEARQUIVO"}]}},k=class{constructor(i){t(this,i),this.back=e(this,"back",7),this.handleTaskbarClick=({detail:t})=>{if(["DOWNLOAD","LINK"].includes(t))return this.downloadAttachment(this.dataUnit.getSelectedRecord())},this.handleBack=()=>{this.dataUnit.cancelEdition().then((t=>{t&&this.back.emit()}))},this.handleFinish=()=>{if(!this.dataUnit.isDirty())return this.back.emit();this.dataUnit.saveData().then((()=>{this.showFinishedToast(),this.back.emit()}))},this.registerKey=void 0,this.entityName=void 0,this.messagesBuilder=void 0,this.dataUnit=void 0,this.crudConfig=void 0}registerKeyWatcher(t,e){var i;e!==t&&(this.returnToGridMode(),this._attachFetcher=new c(this.entityName,this.registerKey,null===(i=this.dataUnit)||void 0===i?void 0:i.name),this._dataUnitBuilder.initLoaders(this.dataUnit,this._attachFetcher,(()=>{this.returnToGridMode()})),this.dataUnit.loadData())}getMessage(t,e){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,e)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error("Nenhum registro selecionado");t.LINK?window.open(`${t.LINK}`):this._attachFetcher.getDownloadKey(t).then((({chave:t})=>{window.open(`/mge/visualizadorArquivos.mge?chaveArquivo=${t.valor}&forcarDownload=S`)}))}returnToGridMode(){this.dataUnit.clearSelection(),this._crudElement&&this._crudElement.goToView(h.GRID)}loadAttachmentDataUnit(){var t;try{const e=this.dataUnit||(new d).getDataUnit("AnexoSistema","br.com.sankhya.core.v3.anexoSistema");return this._attachFetcher=new c(this.entityName,this.registerKey,null===(t=this.dataUnit)||void 0===t?void 0:t.name),e.metadata||e.loadMetadata().then((()=>{this.crudConfig=p})),this._dataUnitBuilder=new m(this.entityName,this.getMessage.bind(this)),e.addFilterProvider({getFilter:()=>this._dataUnitBuilder.getFilters(this.registerKey)}),e.addInterceptor({interceptAction:t=>this._dataUnitBuilder.getInterceptions(e,t,this._crudElement)}),this.dataUnit=e,this.dataUnit.loadData(),this.dataUnit}catch(t){throw new Error("There was an error while creating the data unit")}}componentWillLoad(){this._application=s.getContextValue("__SNK__APPLICATION__"),this.loadAttachmentDataUnit()}render(){var t,e;return this.dataUnit?i("main",{class:"snk-attach__main"},i("header",{class:"snk-attach__header"},i("snk-simple-bar",{onExit:this.handleBack,messagesBuilder:this.messagesBuilder},i("div",{slot:"rightSlot"},i("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})))),i("div",{class:"snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column"},i("div",{class:"ez-box__container"},i("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this.dataUnit,taskbarManager:O(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(e=this.crudConfig)||void 0===e?void 0:e.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick},i("div",{slot:"snkSimpleCrudHeader"},i("div",{class:"ez-flex ez-flex--column"},i("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium"},this.getMessage("snkAttach.title")),i("span",{class:"ez-text ez-text--medium ez-text--secondary"},this.getMessage("snkAttach.description")))))))):null}static get watchers(){return{registerKey:["registerKeyWatcher"]}}};k.style=".snk-attach__header.sc-snk-attach,.snk-attach__crud-section.sc-snk-attach{padding:0 var(--space--lg)}.snk-attach__file-info.sc-snk-attach{padding:var(--space--small);max-width:50%}.snk-attach__main.sc-snk-attach{height:85%}.ez-box__container.sc-snk-attach{height:100%}";export{k as snk_attach}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,h as s,H as i,g as e}from"./p-d2d301a6.js";import{ApplicationContext as n,StringUtils as o,ErrorException as a,WarningException as c,ObjectUtils as r,DateUtils as l,ArrayUtils as h,ElementIDUtils as u}from"@sankhyalabs/core";import{D as d}from"./p-e2160bdd.js";import{P as p}from"./p-eaad0aa8.js";import"./p-ee57d9f5.js";import"./p-5534e08c.js";import"./p-9e7d65a4.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-584d7212.js";import"./p-33745612.js";import{R as m}from"./p-688dcb4c.js";import"./p-112455b1.js";import"./p-8d884fab.js";class v{execute(t){var s;const i={actionID:t.actionID,refreshType:null===(s=t.actionConfig.javaCall)||void 0===s?void 0:s.refreshType};return new Promise((t=>{t({execSource:i,callback:this.callExecJava})}))}callExecJava(t){const s={requestBody:{javaCall:t}};d.get().callServiceBroker("ActionButtonsSP.executeJava",JSON.stringify(s))}}class b{execute(t){var s;const i={actionID:t.actionID,refreshType:null===(s=t.actionConfig.runScript)||void 0===s?void 0:s.refreshType};return new Promise((t=>{t({execSource:i,callback:this.callExecScript})}))}callExecScript(t){const s={runScript:t};d.get().callServiceBroker("ActionButtonsSP.executeScript",s)}}class k{constructor(){this._application=n.getContextValue("__SNK__APPLICATION__")}async execute(t,s){const i=t.resourceID;if(!i)return;let e=await this.buildLaunchObject(t,s);return this._application.openApp(i,e),null}buildLaunchObject(t,s){return new Promise((i=>{let e=t.actionConfig.params.param;if(e&&e.length>0){let n={},c=[];e.forEach((i=>{const e=i.localField;let r=s.getFieldValue(e);if(!r){let i=s.getField(e).label;throw i=o.isEmpty(s.getField(e).label)?e:i,new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.launchScreen.emptyField",{description:t.description,localFieldLabel:i}))}r=o.isEmpty(r.toString())?void 0:r.toString(),n[i.targetField]=r,c.push({fieldName:i.targetField,value:r})})),n.ACTION_PARAMETERS=c,n.call_time=Date.now(),i(n)}i(null)}))}}class w{execute(t){var s,i,e;const n=null===(s=t.actionConfig.dbCall)||void 0===s?void 0:s.name,o=null===(i=t.actionConfig.dbCall)||void 0===i?void 0:i.rootEntity,a={actionID:t.actionID,refreshType:null===(e=t.actionConfig.dbCall)||void 0===e?void 0:e.refreshType,procName:n,rootEntity:o};return new Promise((t=>{t({execSource:a,callback:this.callExecProcedure})}))}callExecProcedure(t){const s={requestBody:{stpCall:t}};d.get().callServiceBroker("ActionButtonsSP.executeSTP",JSON.stringify(s))}}var f,_;!function(t){t.LAUNCH_SCREEN="LC",t.JAVASCRIPT="SC",t.JAVA="RJ",t.PROCEDURE="SP",t.EMBEDDED="EB"}(f||(f={}));class S{constructor(t){this.actionType=t,this._application=n.getContextValue("__SNK__APPLICATION__")}get executor(){switch(this.actionType){case f.LAUNCH_SCREEN:return new k;case f.JAVASCRIPT:return new b;case f.JAVA:return new v;case f.PROCEDURE:return new w;default:throw new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.nonExistentType",{actionType:this.actionType}))}}}!function(t){t.NONE="NONE",t.PARENT="PARENT",t.MASTER="MASTER",t.ALL="ALL"}(_||(_={}));const y="__MASTER_ROW__";class P{constructor(t,s,i){var e;this._lastValuesCache={},this._actionsExecuteInterface=t,this._dataUnit=s,this._selectedRows=(null===(e=null==s?void 0:s.getSelectionInfo())||void 0===e?void 0:e.isAllRecords())?[]:null==s?void 0:s.getSelectionInfo().records,this._application=n.getContextValue("__SNK__APPLICATION__"),this._appResourceId=i}apply(t,s){this._application.closePopUp(),this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:i,callback:e})=>{this.resolvePromptParams(t,i,s).then((()=>{this.actionExecute(i,e)}))}))}async execute(t){var s;if(!t.actionConfig)throw new c(this._application.messagesBuilder.getMessage("snkActionsButton.title.warning",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.incorrectAction",{description:t.description}));if(null===(s=t.actionConfig.params)||void 0===s?void 0:s.promptParam){const s=t.actionConfig.params.promptParam;let i=!1;for(let t=0;t<s.length;t++)if(!i&&"true"===s[t].saveLast){i=!0;break}i&&(t.actionConfig.params.promptParam=await this.loadSavedValuesIntoParams(t));const e=document.createElement("snk-actions-form");window.document.body.appendChild(e),e.action=r.copy(t),e.applyParameters=t=>{this.apply(t,i)},e.openPopup()}else t.type!=f.LAUNCH_SCREEN?this._actionsExecuteInterface.execute(t,this._dataUnit).then((({execSource:t,callback:s})=>{this.actionExecute(t,s)})):this._actionsExecuteInterface.execute(t,this._dataUnit)}loadSavedValuesIntoParams(t){return this.loadLastValues(t).then((s=>{let i=t.actionConfig.params.promptParam;return s&&s.param.forEach((t=>{i=i.map((s=>s.name!==t.paramName?s:Object.assign(Object.assign({},s),"B"===s.paramType?{value:"S"===t.$}:{value:t.$})))})),i}))}actionExecute(t,s){t.virtualPage=this.buildVirtualPage(),this.prepareAndExecute(t,s),this.recordsReloader(t.refreshType)}resolvePromptParams(t,s,i){return new Promise((e=>{let n=[];t.actionConfig.params.promptParam.forEach((t=>{n.push(this.buildPromptParam(t))})),this.putParamsOnExecSource(n,s),i&&this.saveLastValues(t,n),e()}))}buildPromptParam(t){let s,i,e=t.paramType,n=!1,o=t.value;switch(e){case p.DATE:e="D";break;case p.DATETIME:e="H";break;case p.DECIMAL:e="F",s={"sk-precision":Number(t.precision)};break;case p.BOOLEAN:e="S",n=!0,o=t.value?"S":"N";break;case p.ENTITY:s={"sk-entity-name":t.entityName,"sk-allow-show-hierarchical-mode":t.hierarchyEntity,"sk-data-type":"S"},t.hierarchyEntity&&t.entityPK&&(i=t.entityPK),o=t.value?Number(t.value):null;break;case p.OPTIONS:e="O";let a=t.options.split(";").map((function(t,s){let i,e;if(t.indexOf("=")>-1){let s=t.split("=");i=s[0],e=s[1]}else i=s+1,e=t;return{data:i,value:e}}));s={"sk-options":a}}return{description:t.label,required:"true"==t.required,fieldName:t.name,fieldNameOri:t.name,entityPK:i,paramType:t.paramType,type:e,isCheckbox:n,saveLast:t.saveLast,fieldProp:s,value:o,isGeneratedName:t.isGeneratedName}}putParamsOnExecSource(t,s){s.params={param:[]},t.forEach((t=>{if(t.isGeneratedName&&t.value)throw new a(this._application.messagesBuilder.getMessage("snkActionsButton.title.error",void 0),this._application.messagesBuilder.getMessage("snkActionsButton.action.emptyParamName",void 0));o.isEmpty(t.value)||s.params.param.push({type:this.getParamDataType(t.paramType),paramName:t.fieldName,$:this.getParamValue(t)})}))}getParamDataType(t){let s;switch(t){case"D":s="F";break;case"DT":case"DH":s="D";break;case"B":case"ENTITY":case"SO":s="S";break;default:s=t}return s}getParamValue(t){let s=t.value;return s?("DT"==t.paramType?s=l.formatDate(s):"DH"==t.paramType&&(s=l.formatDateTime(s)),s):s}async loadLastValues(t){const s=await this.buildResourceId(t.actionID);return new Promise(((t,i)=>{if(this._lastValuesCache[s])t(this._lastValuesCache[s]);else{const e={config:{chave:s,tipo:"T"}};d.get().callServiceBroker("SystemUtilsSP.getConf",e).then((i=>{var e,n;let o;(null===(n=null===(e=i.config)||void 0===e?void 0:e.data)||void 0===n?void 0:n.params)&&(o=i.config.data.params,Array.isArray(o.param)||(o.param=[o.param])),this._lastValuesCache[s]=o,t(o)})).catch((t=>{i(t)}))}}))}async saveLastValues(t,s){if(this._application){let i={params:{param:[]}};s.forEach((t=>{"true"==t.saveLast&&i.params.param.push({paramName:t.fieldName,$:t.value})}));const e=await this.buildResourceId(t.actionID);this._lastValuesCache[e]=i.params,this._application.saveConfig(e,i)}}async buildResourceId(t){return this._appResourceId+".actionconfig."+t}prepareAndExecute(t,s){this.addRows(t),s(t)}addRows(t){const s={row:[]},i=this._selectedRows;for(const t in i){const e=i[t],n={};e.hasOwnProperty(y)&&(n.master="S",n.entityName=e.__ENTITY_NAME__,delete e[y],delete e.__ENTITY_NAME__);for(const t in e)"NUFIN"===t&&(n.field||(n.field=[]),n.field.push({fieldName:t,$:e[t]}));s.row.push(n)}s.row.length>0&&(t.rows=s)}recordsReloader(t){switch(t){case _.NONE:break;case _.PARENT:case _.MASTER:case _.ALL:this._dataUnit.loadData();break;default:this._dataUnit.reloadCurrentRecord()}}buildVirtualPage(){var t,s,i,e;if(null===(s=null===(t=this._dataUnit)||void 0===t?void 0:t.getSelectionInfo())||void 0===s?void 0:s.isAllRecords())return{filters:{filters:null===(i=this._dataUnit)||void 0===i?void 0:i.getAppliedFilters()},orders:{orders:null===(e=this._dataUnit)||void 0===e?void 0:e.getSort()}}}}class A{clientConfirm(t,s){const i=n.getContextValue("__SNK__APPLICATION__");let e="";t.content.event.hasOwnProperty("stpCall")?(s.requestBody=t.content.event.stpCall,e=f.PROCEDURE):t.content.event.hasOwnProperty("runScript")?(s.requestBody=t.content.event.runScript,e=f.JAVASCRIPT):t.content.event.hasOwnProperty("javaCall")&&(s.requestBody=t.content.event.javaCall,e=f.JAVA);let o={type:"S",sequence:t.content.event.sequence};s.requestBody.params?Array.isArray(s.requestBody.params.param)||(s.requestBody.params.param=[s.requestBody.params.param]):s.requestBody.params={param:[]},s.requestBody.params.param.push(o);const a=t.content.event.title.$,c=t.content.event.message.$;let r;switch(e){case f.JAVASCRIPT:r={runScript:s.requestBody};break;case f.PROCEDURE:r={requestBody:{stpCall:s.requestBody}};break;case f.JAVA:r={requestBody:{javaCall:s.requestBody}}}if("S"==t.content.event.showNoOption){o.paramName="__ESCOLHA_SIMNAO__";const t=document.createElement("snk-client-confirm");window.document.body.appendChild(t),t.titleMessage=a,t.message=c,t.accept=()=>{o.$="S",s.reCall(r)},t.cancel=()=>{o.$="N",s.reCall(r)},t.openPopup()}else i.confirm(a,c,null,"warn",{labelCancel:"Cancelar",labelConfirm:"Sim"}).then((t=>{t&&(o.paramName="__CONFIRMACAO__",o.$="S",s.reCall(r))}))}}const N=class{constructor(s){t(this,s),this.CLIENT_EVENT_CONFIRM_NAME="br.com.sankhya.actionbutton.clientconfirm",this.handleClick=t=>{const s=this._actions.find((s=>s.actionID==t.detail.id)),i=new S(s.type).executor;new P(i,this._dataUnit,this._resourceID).execute(Object.assign({},s)),this._showDropdown=!1},this._items=[],this._showDropdown=!1,this._actions=[],this._isOrderActions=!1}async getActions(){let t={param:{entityName:this._entityName,resourceID:this._resourceID}};return d.get().callServiceBroker("ActionButtonsSP.getActions",t).then((t=>{var s;(null===(s=t.actions)||void 0===s?void 0:s.action)&&(this._actions=this._isOrderActions?h.sortAlphabetically(t.actions.action,"description"):t.actions.action)}))}controlDropdown(){this._showDropdown=!this._showDropdown}canShowDropdown(){var t;return this._showDropdown&&(null===(t=this._items)||void 0===t?void 0:t.length)>0}positionDropdown(){var t;const s=null===(t=this._ezButton)||void 0===t?void 0:t.getBoundingClientRect();s&&this._dropdownParent&&(this._dropdownParent.style.top=s.y+s.height+5+"px",this._dropdownParent.style.left=s.x+"px")}closeDropdown(t){const s=null==t?void 0:t.target;s&&(s.closest(".snk-actions-button")||(this._showDropdown=!1))}setEvents(){document.removeEventListener("click",this.closeDropdown.bind(this)),document.addEventListener("click",this.closeDropdown.bind(this)),document.removeEventListener("scroll",this.positionDropdown.bind(this)),document.addEventListener("scroll",this.positionDropdown.bind(this))}async componentWillLoad(){this._application=n.getContextValue("__SNK__APPLICATION__"),this._isOrderActions=await this._application.getBooleanParam("global.ordenar.acoes.personalizadas");const t=this._element.parentElement;this._dataUnit=null==t?void 0:t.dataUnit,this._resourceID=null==t?void 0:t.resourceID,this._entityName=this._dataUnit.name.split("/")[2],null==this._resourceID&&(this._resourceID=await m.getResourceID()),this.setEvents(),this.getActions().then((()=>{this.loadItems()}))}async componentDidLoad(){if(this._element&&(u.addIDInfo(this._element),this.positionDropdown(),!await this._application.hasClientEvent(this.CLIENT_EVENT_CONFIRM_NAME))){const t=new A;this._application.addClientEvent(this.CLIENT_EVENT_CONFIRM_NAME,t.clientConfirm)}}componentDidUpdate(){this.positionDropdown()}loadItems(){this._actions&&0!=this._actions.length&&this._actions.forEach((t=>{this._items.push({id:t.actionID,label:t.description})}))}getElementID(t){return{[u.DATA_ELEMENT_ID_ATTRIBUTE_NAME]:u.getInternalIDInfo(t)}}render(){return s(i,null,this._actions&&this._actions.length>0&&s("div",{class:`ez-padding-left--medium snk-actions-button \n ${this.canShowDropdown()?" snk-actions-button--overlap":""}\n `},s("ez-button",Object.assign({ref:t=>this._ezButton=t,iconName:"acao",size:"small",mode:"icon",title:this._application.messagesBuilder.getMessage("snkActionsButton.title.actions",void 0),onClick:()=>this.controlDropdown()},this.getElementID("button"))),s("div",Object.assign({ref:t=>this._dropdownParent=t,class:(this.canShowDropdown()?"snk-actions-button__dropdown--show":"snk-actions-button__dropdown")+"\n "},this.getElementID("dropdown")),this.canShowDropdown()&&s("ez-dropdown",Object.assign({items:this._items,onEzClick:t=>this.handleClick(t)},this.getElementID("dropdown"))))),this.canShowDropdown()&&s("div",Object.assign({class:"ez-scrim ez-scrim--light"},this.getElementID("ezScrim"))))}get _element(){return e(this)}};N.style=".sc-snk-actions-button-h{--snk-actions-button--z-index:var(--most-visible, 3);display:flex;width:fit-content;height:fit-content}.snk-actions-button.sc-snk-actions-button{display:flex;width:fit-content;height:fit-content}.snk-actions-button__dropdown--show.sc-snk-actions-button{display:flex;flex-direction:column;position:fixed}.snk-actions-button__dropdown.sc-snk-actions-button>ez-dropdown.sc-snk-actions-button{position:relative}.snk-actions-button--overlap.sc-snk-actions-button{z-index:var(--snk-actions-button--z-index)}.snk-actions-button__dropdown.sc-snk-actions-button{display:none}";export{N as snk_actions_button}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{r as t,c as i,h as s,g as e}from"./p-d2d301a6.js";import{DataUnit as a,defaultDataLoader as r,StringUtils as n,ChangeOperation as o,ObjectUtils as h,ApplicationContext as d,DataType as l,UserInterface as m}from"@sankhyalabs/core";import{c,S as u}from"./p-4a78e118.js";import{T as p}from"./p-c9841939.js";import"./p-e2160bdd.js";import"./p-ee57d9f5.js";import{P as g}from"./p-5534e08c.js";import"./p-9e7d65a4.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-584d7212.js";import"./p-33745612.js";import{T as v}from"./p-c2beb95c.js";import{S as b}from"./p-fa9d3f73.js";import"./p-6dc031de.js";import"./p-112455b1.js";import"./p-8d884fab.js";class k{constructor(t,i){this.records=i,this.metadata=t,this._dataUnit=new a(k.IN_MEMORY_DATA_UNIT_NAME),this._dataUnit.metadataLoader=()=>this.metadaLoader(),this._dataUnit.dataLoader=(t,i)=>r(t,i,this.getRecordsToLoad()),this._dataUnit.saveLoader=(t,i)=>this.saveLoader(t,i),this._dataUnit.removeLoader=(t,i)=>this.removeLoader(t,i),this.dataUnit.loadMetadata().then((()=>this.dataUnit.loadData()))}getRecordsToLoad(){if(this._initialRecords)try{return this._initialRecords}finally{this._initialRecords=void 0}return this.dataUnit.records}get dataUnit(){return this._dataUnit}get records(){return this.dataUnit.records}set records(t){const i=null==t?void 0:t.map((t=>(t.__record__id__||(t.__record__id__=this.generateUniqueId()),t)));this._dataUnit?this._dataUnit.records=i:this._initialRecords=i}get metadata(){return this._metadata}set metadata(t){this._metadata=t,this._dataUnit&&(this._dataUnit.metadata=this._metadata)}generateUniqueId(){return n.generateUUID()}metadaLoader(){return Promise.resolve(this._metadata)}saveLoader(t,i){return new Promise((t=>{let s=[];i.forEach((t=>{let{record:i,updatingFields:e,operation:a}=t;const r=Object.assign(Object.assign({},i),e);if(a===o.INSERT||a===o.COPY)r.__old__id__=i.__record__id__,r.__record__id__=this.generateUniqueId(),this.records.push(r);else{const t=this.records.findIndex((t=>t.__record__id__==r.__record__id__));this.records[t]=r}s.push(r)})),t(s)}))}removeLoader(t,i){return new Promise((t=>{t(i)}))}}k.IN_MEMORY_DATA_UNIT_NAME="InMemoryDataUnit";const f=class{constructor(s){t(this,s),this.dataStateChange=i(this,"dataStateChange",3),this.dataUnitReady=i(this,"dataUnitReady",3),this.actionClick=i(this,"actionClick",7),this.formItemsReady=i(this,"formItemsReady",7),this.REGULAR_DEFAULT_BTNS=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER"],this.REGULAR_SELECTED_BTNS=["INSERT","REFRESH","PREVIOUS","NEXT","DIVIDER","CLONE","REMOVE","DIVIDER"],this._multiSelectionListDataSource=new b,this._taskbarProcessor=new v({"snkSimpleCrudTaskbar.form_regular":this.resolveInMemoryBtns(this.REGULAR_DEFAULT_BTNS).concat(p.GRID_MODE),"snkSimpleCrudTaskbar.grid_regular":this.resolveInMemoryBtns(this.REGULAR_DEFAULT_BTNS).concat(p.FORM_MODE),"snkSimpleCrudTaskbar.form_selected":this.resolveInMemoryBtns(this.REGULAR_SELECTED_BTNS).concat(p.GRID_MODE),"snkSimpleCrudTaskbar.grid_selected":this.resolveInMemoryBtns(this.REGULAR_SELECTED_BTNS).concat(p.FORM_MODE),"snkSimpleCrudTaskbar.finish_edition":["CANCEL","SAVE"]}),this._currentViewMode=c.GRID,this._config=void 0,this.dataState=void 0,this.dataUnit=void 0,this.mode=u.SERVER,this.gridConfig=void 0,this.formConfig=void 0,this.multipleSelection=void 0,this.useCancelConfirm=!0,this.taskbarManager=void 0,this.messagesBuilder=void 0,this.useEnterLikeTab=!1}resolveInMemoryBtns(t){const i=[...t];return this.mode===u.IN_MEMORY&&i.splice(1,1),i}async goToView(t){this._currentViewMode=t,this._viewStack&&this._viewStack.show(t)}actionClickListener(t){const i=t.detail;i===p.GRID_MODE?this.goToView(c.GRID):i===p.FORM_MODE&&this.goToView(c.FORM),t.stopPropagation()}onModeChange(){this.mode==u.IN_MEMORY&&this.initInMemoryDataUnit()}observeDataState(t,i){h.objectToString(i)!=h.objectToString(t)&&this.dataStateChange.emit(t)}componentWillRender(){this._taskbarProcessor.process(this.getTaskBarId(),this.taskbarManager,this.dataState,this.getTaskBarDisabledButtons())}componentWillLoad(){this.processMetadata(),this.onModeChange(),this.configDatasource()}configDatasource(){const t=d.getContextValue("__SNK__APPLICATION__");this._multiSelectionListDataSource.setApplication(t),this._multiSelectionListDataSource.setDataUnit(this.dataUnit)}getTaskBarId(){var t,i,s;return(null===(t=this.dataState)||void 0===t?void 0:t.isDirty)?"snkSimpleCrudTaskbar.finish_edition":(null===(i=this.dataState)||void 0===i?void 0:i.selectionInfo)&&!this.dataState.selectionInfo.isAllRecords()&&(null===(s=this.dataState.selectionInfo.records)||void 0===s?void 0:s.length)>0?this._currentViewMode===c.GRID?"snkSimpleCrudTaskbar.grid_selected":"snkSimpleCrudTaskbar.form_selected":this._currentViewMode===c.GRID?"snkSimpleCrudTaskbar.grid_regular":"snkSimpleCrudTaskbar.form_regular"}initInMemoryDataUnit(){this._inMemoryLoader=new k(this._metadata),this.dataUnit=this._inMemoryLoader.dataUnit,this.dataUnitReady.emit(this.dataUnit)}setMetadata(t){return this._inMemoryLoader?this._inMemoryLoader.metadata=t:this.dataUnit&&(this.dataUnit.metadata=t),Promise.resolve()}setRecords(t){return this._inMemoryLoader?this._inMemoryLoader.records=t:this.dataUnit&&(this.dataUnit.records=t),Promise.resolve()}getRecords(){return Promise.resolve(this.dataUnit.records)}processMetadata(){const t=this._element.querySelectorAll("snk-field-metadata"),i=[],s={fields:[],emptyConfig:!1};t.forEach((t=>{const e={name:t.getAttribute("name")||t.getAttribute("label"),label:t.getAttribute("label"),dataType:l[t.getAttribute("dataType")]||l.TEXT,userInterface:m[t.getAttribute("userInterface")]||m.SHORTTEXT,readOnly:"true"==t.getAttribute("readOnly"),required:"true"==t.getAttribute("required"),tab:t.getAttribute("tab")||void 0,visible:"false"!=t.getAttribute("visible")};s.fields.push({name:e.name,tab:e.tab,visible:e.visible}),i.push(e)})),i.length>0&&(this.formConfig||(this.formConfig=s),this._metadata={name:"SimpleCrud",label:"SimpleCrud",fields:i})}onDataStateChange(t){this.dataState=Object.assign({},t.detail)}getTaskBarDisabledButtons(){var t,i,s,e;const a=[];return(null===(t=this.dataState)||void 0===t?void 0:t.hasNext)||a.push(p.NEXT),(null===(i=this.dataState)||void 0===i?void 0:i.hasPrevious)||a.push(p.PREVIOUS),(null===(e=null===(s=this.dataState)||void 0===s?void 0:s.selectionInfo)||void 0===e?void 0:e.isEmpty())&&a.push(p.FORM_MODE),a}handleCancelEdit(){var t;(null===(t=this.dataState)||void 0===t?void 0:t.recordsIsEmpty)&&(this.goToView(c.GRID),this.dataUnit.clearSelection())}render(){var t;return s("snk-data-unit",{class:"simple-crud__container",dataUnit:this.dataUnit,useCancelConfirm:this.useCancelConfirm,onDataStateChange:t=>this.onDataStateChange(t),onCancelEdition:this.handleCancelEdit.bind(this),onInsertionMode:()=>this.goToView(c.FORM),onDataUnitReady:t=>this.dataUnitReady.emit(t.detail),ignoreSaveMessage:this._currentViewMode===c.GRID,onMessagesBuilderUpdated:t=>this.messagesBuilder=t.detail},s("header",null,s("slot",{name:"snkSimpleCrudHeader"})),s("section",{class:"ez-box ez-box--shadow simple-crud__container-section"},s("snk-taskbar",{class:"ez-box ez-box--shadow ez-padding--medium ez-margin-bottom--large",dataUnit:this.dataUnit,primaryButton:(null===(t=this.dataState)||void 0===t?void 0:t.isDirty)?"SAVE":"INSERT","data-element-id":"grid_left",messagesBuilder:this.messagesBuilder,buttons:this._taskbarProcessor.buttons,disabledButtons:this._taskbarProcessor.disabledButtons,customButtons:this._taskbarProcessor.customButtons,slot:"leftButtons",presentationMode:g.SECONDARY},s("slot",{name:"TASKBAR_CUSTOM_ELEMENTS"})),s("ez-view-stack",{ref:t=>this._viewStack=t,"data-element-id":"simple-crud"},s("stack-item",null,s("ez-grid",{dataUnit:this.dataUnit,config:this.gridConfig,"no-header":!0,multipleSelection:this.multipleSelection,onEzDoubleClick:()=>this.goToView(c.FORM),columnfilterDataSource:this.dataUnit.name.includes(k.IN_MEMORY_DATA_UNIT_NAME)?void 0:this._multiSelectionListDataSource,useEnterLikeTab:this.useEnterLikeTab},s("div",{slot:"footer"},s("slot",{name:"snkSimpleCrudFooter"})))),s("stack-item",null,s("ez-form",{dataUnit:this.dataUnit,config:this.formConfig})))))}get _element(){return e(this)}static get watchers(){return{mode:["onModeChange"],dataState:["observeDataState"]}}};f.style=".sc-snk-simple-crud-h{display:flex;height:100%;width:100%}.simple-crud__container.sc-snk-simple-crud{display:grid;grid-template-rows:max-content;row-gap:12px;height:100%;width:100%}.simple-crud__container-section.sc-snk-simple-crud{flex-wrap:unset;flex-direction:column}ez-grid.sc-snk-simple-crud{--ez-grid__container--shadow:none;min-height:300px}ez-form.sc-snk-simple-crud{min-height:300px}";export{f as snk_simple_crud}
|
@@ -1 +0,0 @@
|
|
1
|
-
import{C as t}from"./p-358e8f7b.js";import{ObjectUtils as s}from"@sankhyalabs/core";import{F as e}from"./p-33745612.js";class i{constructor(t,s,e){this._resourceID=s,this._configName=t,this._onConfigChange=e}async loadConfig(){return new Promise((s=>{t.loadFormConfig(this._configName,this._resourceID).then((t=>{this.setConfig(t),s(t)})).catch((t=>{console.warn(t)}))}))}saveConfig(e){const i=s.copy(e);return new Promise((s=>{t.saveFormConfig(e,this._configName,this._resourceID).then((t=>{this.setConfig(Object.assign(Object.assign({},i),t)),s(Object.assign(Object.assign({},i),t))}))}))}saveCardState(s,e,i){return new Promise((r=>{var n;const h=(null===(n=this._config)||void 0===n?void 0:n.cardsState)||new Map,o=h.get(s);h.set(s,"fixed"===i?this.updateFixSequence(Object.assign(Object.assign({},o),{fixed:e.fixed}),h):Object.assign(Object.assign({},o),{[i]:e[i]})),t.saveCardState(h,this._configName,this._resourceID).then((t=>{this._config=Object.assign(Object.assign({},this._config),{cardsState:h}),r(t)}))}))}updateFixSequence(t,s){let e=-1;return Array.from(s.values()).forEach((s=>{s.fixed||delete t.fixSequence,null!=s.fixSequence&&(e=Math.max(e,s.fixSequence))})),t.fixed?t.fixSequence=e+1:delete t.fixSequence,t}getFieldsList(t){var s;const e=null===(s=this._config)||void 0===s?void 0:s.fields;return null!=e&&e.length>0?[...e]:null!=t?t.metadata.fields.filter((t=>!1!==t.visible)).map((({name:t})=>({name:t}))):[]}getInsertionConfig(t){const s=this.getFieldsList(t).filter((s=>{if(t){const e=t.getField(s.name);if(e&&e.readOnly)return!1}return!s.readOnly}));return Object.assign(Object.assign({},this._config),{fields:s})}setConfig(t){this.isLoaded=!0;const{cardsState:s,summary:e,defaultVars:i}=this._config||{};this._config=Object.assign({},t),s&&(this._config.cardsState=s),e&&(this._config.summary=e),i&&(this._config.defaultVars=i),this._onConfigChange&&this._onConfigChange(Object.assign({},this._config))}getConfig(t,s){return t?this.getInsertionConfig(s):Object.assign({},this._config)}getFormConfigFetcher(){return null==this._formConfigFetcher&&(this._formConfigFetcher=new e),this._formConfigFetcher}async fetchUserAvailableConfigs(){return null!=this._configName?Promise.resolve(void 0):this.getFormConfigFetcher().fetchUserAvailableConfigs(this._configName,this._resourceID)}async fetchLegacyConfig(){return this.getFormConfigFetcher().fetchLegacyConfig(this._configName,this._resourceID)}async fetchDefaultConfig(){return this.getFormConfigFetcher().fetchDefaultConfig(this._configName,this._resourceID)}}export{i as S}
|