@sankhyalabs/sankhyablocks 8.8.0-rc.4 → 8.8.0-rc.6
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/{SnkMultiSelectionListDataSource-9fd9c742.js → SnkMultiSelectionListDataSource-4f7a031a.js} +1 -1
- package/dist/cjs/{dataunit-fetcher-1433ce24.js → dataunit-fetcher-a8bac9cc.js} +51 -23
- package/dist/cjs/snk-actions-button.cjs.entry.js +1 -1
- package/dist/cjs/snk-application.cjs.entry.js +1 -1
- package/dist/cjs/snk-attach.cjs.entry.js +1 -1
- package/dist/cjs/snk-crud.cjs.entry.js +1 -1
- package/dist/cjs/snk-detail-view.cjs.entry.js +2 -2
- package/dist/cjs/snk-grid.cjs.entry.js +3 -2
- package/dist/cjs/{snk-guides-viewer-0f03d633.js → snk-guides-viewer-00e028f1.js} +1 -1
- package/dist/cjs/snk-guides-viewer.cjs.entry.js +2 -2
- package/dist/cjs/snk-simple-crud.cjs.entry.js +2 -2
- package/dist/collection/components/snk-grid/snk-grid.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +6 -1
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.js +3 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.js +13 -14
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.js +29 -8
- package/dist/components/dataunit-fetcher.js +51 -23
- package/dist/components/snk-grid2.js +1 -0
- package/dist/esm/{SnkMultiSelectionListDataSource-447cd9e8.js → SnkMultiSelectionListDataSource-2a4ec61c.js} +1 -1
- package/dist/esm/{dataunit-fetcher-0162ce17.js → dataunit-fetcher-5e9245d7.js} +51 -23
- package/dist/esm/snk-actions-button.entry.js +1 -1
- package/dist/esm/snk-application.entry.js +1 -1
- package/dist/esm/snk-attach.entry.js +1 -1
- package/dist/esm/snk-crud.entry.js +1 -1
- package/dist/esm/snk-detail-view.entry.js +2 -2
- package/dist/esm/snk-grid.entry.js +3 -2
- package/dist/esm/{snk-guides-viewer-64c24a05.js → snk-guides-viewer-9efd5ce9.js} +1 -1
- package/dist/esm/snk-guides-viewer.entry.js +2 -2
- package/dist/esm/snk-simple-crud.entry.js +2 -2
- package/dist/sankhyablocks/p-171b12d5.js +59 -0
- package/dist/sankhyablocks/{p-503c9774.entry.js → p-3ad594b3.entry.js} +1 -1
- package/dist/sankhyablocks/{p-e350860d.entry.js → p-3b28c4b3.entry.js} +1 -1
- package/dist/sankhyablocks/{p-f5dbb069.entry.js → p-3d0a0a36.entry.js} +1 -1
- package/dist/sankhyablocks/p-61513624.entry.js +1 -0
- package/dist/sankhyablocks/{p-a84035fa.js → p-7469e2ef.js} +1 -1
- package/dist/sankhyablocks/{p-cc232268.entry.js → p-880d08b8.entry.js} +1 -1
- package/dist/sankhyablocks/{p-e5e06439.entry.js → p-ae6a90a1.entry.js} +1 -1
- package/dist/sankhyablocks/{p-7cbbb6e3.entry.js → p-b4edd50c.entry.js} +1 -1
- package/dist/sankhyablocks/{p-441cce40.entry.js → p-bb1bdb17.entry.js} +1 -1
- package/dist/sankhyablocks/{p-1161cb2d.js → p-c34cea23.js} +1 -1
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadingInfo.d.ts +2 -0
- package/package.json +1 -1
- package/dist/sankhyablocks/p-5bd7932e.entry.js +0 -1
- package/dist/sankhyablocks/p-85635c64.js +0 -59
@@ -116,6 +116,7 @@ const SnkGrid = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
116
116
|
if (this._gridConfig && this._dataUnit) {
|
117
117
|
this._dataUnit.defaultSorting = this._gridConfig
|
118
118
|
.columns
|
119
|
+
.filter(col => col.ascending != undefined)
|
119
120
|
.sort((colA, colB) => colA.orderIndex - colB.orderIndex)
|
120
121
|
.map(({ name: field, ascending }) => {
|
121
122
|
const { dataType } = this._dataUnit.getField(field);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { UserInterface, DateUtils } from '@sankhyalabs/core';
|
2
|
-
import { P as PreloadManager } from './dataunit-fetcher-
|
2
|
+
import { P as PreloadManager } from './dataunit-fetcher-5e9245d7.js';
|
3
3
|
|
4
4
|
class SnkMultiSelectionListDataSource {
|
5
5
|
setDataUnit(dataUnit) {
|
@@ -31,6 +31,9 @@ class ArrayRepository {
|
|
31
31
|
for (const item of this._list) {
|
32
32
|
const processedItem = itemProcessor(item);
|
33
33
|
if (processedItem == undefined) {
|
34
|
+
continue;
|
35
|
+
}
|
36
|
+
if (processedItem.value == undefined) {
|
34
37
|
hasEmpty = true;
|
35
38
|
continue;
|
36
39
|
}
|
@@ -126,26 +129,25 @@ class PreloadManager {
|
|
126
129
|
if (!PreloadManager.isCacheEnabled(dataUnit)) {
|
127
130
|
return Promise.resolve(undefined);
|
128
131
|
}
|
132
|
+
let filterFunction;
|
133
|
+
const request = dataUnit.getLastLoadRequest();
|
134
|
+
if (request != undefined) {
|
135
|
+
const columnFilters = PreloadManager.getColumnFilters(request.filters);
|
136
|
+
filterFunction = PreloadManager.getFilterFunction(dataUnit, Array.from(columnFilters.values()));
|
137
|
+
}
|
129
138
|
return new Promise((accept, reject) => {
|
130
139
|
PreloadManager.getRepository(dataUnit).distict(record => {
|
140
|
+
if (filterFunction != undefined && !filterFunction(record)) {
|
141
|
+
return undefined;
|
142
|
+
}
|
131
143
|
const fieldValue = record[fieldName];
|
132
144
|
if (fieldValue == undefined) {
|
133
|
-
return
|
145
|
+
return { key: null, value: null };
|
134
146
|
}
|
135
147
|
const value = fieldValue.value != undefined ? fieldValue.value : fieldValue;
|
136
148
|
return { key: dataUnit.getFormattedValue(fieldName, fieldValue), value };
|
137
149
|
})
|
138
|
-
.then(result =>
|
139
|
-
if (result != undefined && result.size > 0) {
|
140
|
-
const field = dataUnit.getField(fieldName);
|
141
|
-
const sortedMap = new Map(Array.from(result.entries())
|
142
|
-
.sort((itemA, itemB) => FieldComparator.compareValues(field, itemA[1], itemB[1]))
|
143
|
-
.map(([key, value]) => key === "" ? ["(Vazio)", value] : [key, value]));
|
144
|
-
accept(sortedMap);
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
accept(result);
|
148
|
-
})
|
150
|
+
.then(result => accept(result))
|
149
151
|
.catch(reason => reject(reason));
|
150
152
|
});
|
151
153
|
}
|
@@ -159,7 +161,7 @@ class PreloadManager {
|
|
159
161
|
return PreloadManager.loadFromCache(dataUnit, request);
|
160
162
|
}
|
161
163
|
}
|
162
|
-
//Como não vamos aproveitar o cache, ele precisa ser
|
164
|
+
//Como não vamos aproveitar o cache, ele precisa ser limpo.
|
163
165
|
PreloadManager.getRepository(dataUnit).clear().catch(() => { });
|
164
166
|
}
|
165
167
|
return loadFromServer(dataUnit, request);
|
@@ -229,7 +231,7 @@ class PreloadManager {
|
|
229
231
|
.then(loadResult => {
|
230
232
|
const stillLoading = PreloadManager._loadingStatus.get(dataUnit.name);
|
231
233
|
const { count, result: records } = loadResult;
|
232
|
-
const firstRecord = count == 0 ?
|
234
|
+
const firstRecord = count == 0 ? 0 : offset + 1;
|
233
235
|
const lastRecord = offset + Math.min(records.length, limit);
|
234
236
|
const currentPage = offset / limit;
|
235
237
|
const paginationInfo = {
|
@@ -375,17 +377,36 @@ class DatasetStrategy {
|
|
375
377
|
return Promise.resolve({ records: [], loadingInfo });
|
376
378
|
}
|
377
379
|
try {
|
380
|
+
const localSorting = [];
|
381
|
+
const serverSorting = [];
|
382
|
+
if (request.sort != undefined) {
|
383
|
+
for (const sort of request.sort) {
|
384
|
+
const descriptor = dataUnit.getField(sort.field);
|
385
|
+
const local = descriptor != undefined
|
386
|
+
&& descriptor.properties != undefined
|
387
|
+
&& descriptor.properties.calculated === "true";
|
388
|
+
if (local) {
|
389
|
+
localSorting.push(sort);
|
390
|
+
}
|
391
|
+
else {
|
392
|
+
serverSorting.push(sort);
|
393
|
+
}
|
394
|
+
}
|
395
|
+
}
|
378
396
|
const fields = this.getFieldsList(dataUnit);
|
379
397
|
const serviceName = "DatasetSP.loadRecords";
|
380
|
-
const requestBody = this.buildRequestBody(serviceName, fields, dataUnit, request, loadingInfo);
|
381
|
-
const {
|
398
|
+
const requestBody = this.buildRequestBody(serviceName, fields, dataUnit, request, loadingInfo, serverSorting);
|
399
|
+
const params = loadingInfo.quiet ? { urlParams: { quietMode: "true" } } : undefined;
|
400
|
+
const { result: responseRecords, pagerID: pagerId } = await DataFetcher.get().callServiceBroker(serviceName, requestBody, params);
|
382
401
|
const records = this.processRecords(dataUnit, fields, responseRecords);
|
383
402
|
const loadingInProgress = pagerId != undefined;
|
384
403
|
const count = loadingInfo.count + records.length;
|
404
|
+
const needReload = !loadingInProgress && localSorting.length > 0;
|
385
405
|
return Promise.resolve({
|
386
406
|
records,
|
387
407
|
loadingInfo: Object.assign(Object.assign({}, loadingInfo), { pagerId,
|
388
|
-
loadingInProgress, total: loadingInProgress ? undefined : count, count
|
408
|
+
loadingInProgress, total: loadingInProgress ? undefined : count, count,
|
409
|
+
needReload })
|
389
410
|
});
|
390
411
|
}
|
391
412
|
catch (error) {
|
@@ -395,7 +416,10 @@ class DatasetStrategy {
|
|
395
416
|
}
|
396
417
|
getFieldsList(dataUnit) {
|
397
418
|
let fields = ["__record__id__", "__record__label__"];
|
398
|
-
dataUnit.metadata.fields.forEach(descriptor => {
|
419
|
+
dataUnit.metadata.fields.forEach((descriptor) => {
|
420
|
+
if (descriptor.standAlone) {
|
421
|
+
return;
|
422
|
+
}
|
399
423
|
fields = fields.concat(this.getFieldNames(descriptor));
|
400
424
|
});
|
401
425
|
return fields;
|
@@ -407,7 +431,7 @@ class DatasetStrategy {
|
|
407
431
|
}
|
408
432
|
return [descriptor.name, descriptionField];
|
409
433
|
}
|
410
|
-
buildRequestBody(serviceName, fields, dataUnit, request, loadingInfo) {
|
434
|
+
buildRequestBody(serviceName, fields, dataUnit, request, loadingInfo, sorting) {
|
411
435
|
const dataSetID = dataUnit.dataUnitId;
|
412
436
|
const dataUnitName = dataUnit.name;
|
413
437
|
const entityName = DataUnitFetcher.parseDataUnitName(dataUnitName).entityName;
|
@@ -428,13 +452,13 @@ class DatasetStrategy {
|
|
428
452
|
tryJoinedFields: true,
|
429
453
|
parallelLoader: true,
|
430
454
|
crudListener: "br.com.sankhya.modelcore.dataset.DataUnitDatasetAdapter",
|
431
|
-
txProperties: this.getTxProperties(dataUnitName, request),
|
455
|
+
txProperties: this.getTxProperties(dataUnitName, request, sorting),
|
432
456
|
useDefaultRowsLimit: false
|
433
457
|
}
|
434
458
|
};
|
435
459
|
return JSON.stringify(requestBody);
|
436
460
|
}
|
437
|
-
getTxProperties(dataUnitName, request) {
|
461
|
+
getTxProperties(dataUnitName, request, sorting) {
|
438
462
|
const txProperties = {
|
439
463
|
"__DATA_UNIT_ADAPTER__[dataUnitName]": dataUnitName
|
440
464
|
};
|
@@ -442,7 +466,6 @@ class DatasetStrategy {
|
|
442
466
|
if (serverSideFilters.length !== 0) {
|
443
467
|
txProperties["__DATA_UNIT_ADAPTER__[criteria]"] = JSON.stringify(serverSideFilters);
|
444
468
|
}
|
445
|
-
const sorting = request.sort;
|
446
469
|
if (sorting != undefined && sorting.length !== 0) {
|
447
470
|
txProperties["__DATA_UNIT_ADAPTER__[sorting]"] = JSON.stringify(sorting);
|
448
471
|
}
|
@@ -549,7 +572,7 @@ class DataUnitDataLoader {
|
|
549
572
|
PreloadManager.cacheRecords(dataUnit, records, recreateCache, responseLoadingInfo.loadingInProgress);
|
550
573
|
if (PreloadManager.isCacheEnabled(dataUnit) && responseLoadingInfo.loadingInProgress) {
|
551
574
|
const newRequest = Object.assign(Object.assign({}, request), { offset: responseLoadingInfo.count });
|
552
|
-
const newLoadingInfo = Object.assign(Object.assign({}, responseLoadingInfo), { pageNumber: (responseLoadingInfo.pageNumber || 0) + 1 });
|
575
|
+
const newLoadingInfo = Object.assign(Object.assign({}, responseLoadingInfo), { pageNumber: (responseLoadingInfo.pageNumber || 0) + 1, quiet: true });
|
553
576
|
this.callLoader(dataUnit, newRequest, newLoadingInfo, dataLoader)
|
554
577
|
.then(result => DataUnitDataLoader.afterLoadingPage(dataUnit, result.loadingInfo))
|
555
578
|
.catch(reason => console.error(reason));
|
@@ -567,6 +590,11 @@ class DataUnitDataLoader {
|
|
567
590
|
dataUnit.updatePagination(Object.assign(Object.assign({}, dataUnitPagination), { count }));
|
568
591
|
return;
|
569
592
|
}
|
593
|
+
if (loadingInfo.needReload) {
|
594
|
+
//Ir para a primeira página, faz com que o loadData seja chamado novamente
|
595
|
+
dataUnit.gotoPage(0);
|
596
|
+
return;
|
597
|
+
}
|
570
598
|
dataUnit.updatePagination(Object.assign(Object.assign({}, dataUnitPagination), { total: count, count }));
|
571
599
|
}
|
572
600
|
static registryLoading(dataUnit, loadingInfo) {
|
@@ -7,7 +7,7 @@ import './index-1564817d.js';
|
|
7
7
|
import './ISave-4412b20c.js';
|
8
8
|
import '@sankhyalabs/ezui/dist/collection/utils/constants';
|
9
9
|
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
10
|
-
import './dataunit-fetcher-
|
10
|
+
import './dataunit-fetcher-5e9245d7.js';
|
11
11
|
import './filter-item-type.enum-5028ed3f.js';
|
12
12
|
import './form-config-fetcher-5b886892.js';
|
13
13
|
import { R as ResourceIDUtils } from './ResourceIDUtils-a114189a.js';
|
@@ -4,7 +4,7 @@ import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
|
|
4
4
|
import { C as ConfigStorage } from './ConfigStorage-9840d004.js';
|
5
5
|
import { d as dist, D as DataFetcher, U as UrlUtils } from './DataFetcher-07935045.js';
|
6
6
|
import { A as AutorizationType, a as AuthFetcher } from './auth-fetcher-1afab780.js';
|
7
|
-
import { D as DataUnitFetcher } from './dataunit-fetcher-
|
7
|
+
import { D as DataUnitFetcher } from './dataunit-fetcher-5e9245d7.js';
|
8
8
|
import { P as PesquisaFetcher } from './pesquisa-fetcher-7c46996d.js';
|
9
9
|
import { S as SnkMessageBuilder } from './SnkMessageBuilder-7ac66e9c.js';
|
10
10
|
import './form-config-fetcher-5b886892.js';
|
@@ -3,7 +3,7 @@ import { ApplicationContext, DataType, Action } from '@sankhyalabs/core';
|
|
3
3
|
import { D as DataFetcher } from './DataFetcher-07935045.js';
|
4
4
|
import { S as SaveErrorsEnum } from './ISave-4412b20c.js';
|
5
5
|
import { c as VIEW_MODE } from './constants-3644f1b6.js';
|
6
|
-
import { D as DataUnitFetcher } from './dataunit-fetcher-
|
6
|
+
import { D as DataUnitFetcher } from './dataunit-fetcher-5e9245d7.js';
|
7
7
|
import { T as TaskbarElement } from './taskbar-elements-0a6b8b95.js';
|
8
8
|
import './_commonjsHelpers-9943807e.js';
|
9
9
|
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
@@ -7,7 +7,7 @@ import { P as PresentationMode } from './index-1564817d.js';
|
|
7
7
|
import './ISave-4412b20c.js';
|
8
8
|
import '@sankhyalabs/ezui/dist/collection/utils/constants';
|
9
9
|
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
10
|
-
import './dataunit-fetcher-
|
10
|
+
import './dataunit-fetcher-5e9245d7.js';
|
11
11
|
import './filter-item-type.enum-5028ed3f.js';
|
12
12
|
import './form-config-fetcher-5b886892.js';
|
13
13
|
import { c as VIEW_MODE } from './constants-3644f1b6.js';
|
@@ -8,12 +8,12 @@ import { P as PresentationMode } from './index-1564817d.js';
|
|
8
8
|
import './ISave-4412b20c.js';
|
9
9
|
import '@sankhyalabs/ezui/dist/collection/utils/constants';
|
10
10
|
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
11
|
-
import './dataunit-fetcher-
|
11
|
+
import './dataunit-fetcher-5e9245d7.js';
|
12
12
|
import './filter-item-type.enum-5028ed3f.js';
|
13
13
|
import './form-config-fetcher-5b886892.js';
|
14
14
|
import { T as TaskbarElement } from './taskbar-elements-0a6b8b95.js';
|
15
15
|
import { c as VIEW_MODE } from './constants-3644f1b6.js';
|
16
|
-
import { S as SnkGuidesViewer } from './snk-guides-viewer-
|
16
|
+
import { S as SnkGuidesViewer } from './snk-guides-viewer-9efd5ce9.js';
|
17
17
|
import { S as SnkMessageBuilder } from './SnkMessageBuilder-7ac66e9c.js';
|
18
18
|
import './ConfigStorage-9840d004.js';
|
19
19
|
import './_commonjsHelpers-9943807e.js';
|
@@ -6,14 +6,14 @@ import { C as ConfigStorage } from './ConfigStorage-9840d004.js';
|
|
6
6
|
import { P as PresentationMode } from './index-1564817d.js';
|
7
7
|
import { T as TaskbarProcessor } from './taskbar-processor-94402e6e.js';
|
8
8
|
import { s as store } from './index-bdf75557.js';
|
9
|
-
import { S as SnkMultiSelectionListDataSource } from './SnkMultiSelectionListDataSource-
|
9
|
+
import { S as SnkMultiSelectionListDataSource } from './SnkMultiSelectionListDataSource-2a4ec61c.js';
|
10
10
|
import { SelectionMode } from '@sankhyalabs/core/dist/dataunit/DataUnit';
|
11
11
|
import './form-config-fetcher-5b886892.js';
|
12
12
|
import './DataFetcher-07935045.js';
|
13
13
|
import './_commonjsHelpers-9943807e.js';
|
14
14
|
import './PrintUtils-3e4ff0f5.js';
|
15
15
|
import './filter-item-type.enum-5028ed3f.js';
|
16
|
-
import './dataunit-fetcher-
|
16
|
+
import './dataunit-fetcher-5e9245d7.js';
|
17
17
|
import '@sankhyalabs/ezui/dist/collection/utils/constants';
|
18
18
|
import './ResourceIDUtils-a114189a.js';
|
19
19
|
|
@@ -108,6 +108,7 @@ const SnkGrid = class {
|
|
108
108
|
if (this._gridConfig && this._dataUnit) {
|
109
109
|
this._dataUnit.defaultSorting = this._gridConfig
|
110
110
|
.columns
|
111
|
+
.filter(col => col.ascending != undefined)
|
111
112
|
.sort((colA, colB) => colA.orderIndex - colB.orderIndex)
|
112
113
|
.map(({ name: field, ascending }) => {
|
113
114
|
const { dataType } = this._dataUnit.getField(field);
|
@@ -11,7 +11,7 @@ import { P as PresentationMode } from './index-1564817d.js';
|
|
11
11
|
import './ISave-4412b20c.js';
|
12
12
|
import '@sankhyalabs/ezui/dist/collection/utils/constants';
|
13
13
|
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
14
|
-
import './dataunit-fetcher-
|
14
|
+
import './dataunit-fetcher-5e9245d7.js';
|
15
15
|
import './filter-item-type.enum-5028ed3f.js';
|
16
16
|
import './form-config-fetcher-5b886892.js';
|
17
17
|
import { SelectionMode } from '@sankhyalabs/core/dist/dataunit/DataUnit';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export { S as snk_guides_viewer } from './snk-guides-viewer-
|
1
|
+
export { S as snk_guides_viewer } from './snk-guides-viewer-9efd5ce9.js';
|
2
2
|
import './index-a7d3d3f1.js';
|
3
3
|
import '@sankhyalabs/core';
|
4
4
|
import './SnkFormConfigManager-a7c4ac16.js';
|
@@ -18,6 +18,6 @@ import './constants-3644f1b6.js';
|
|
18
18
|
import './pesquisa-fetcher-7c46996d.js';
|
19
19
|
import './ISave-4412b20c.js';
|
20
20
|
import '@sankhyalabs/ezui/dist/collection/utils/constants';
|
21
|
-
import './dataunit-fetcher-
|
21
|
+
import './dataunit-fetcher-5e9245d7.js';
|
22
22
|
import './ResourceIDUtils-a114189a.js';
|
23
23
|
import '@sankhyalabs/core/dist/dataunit/DataUnit';
|
@@ -8,11 +8,11 @@ import { P as PresentationMode } from './index-1564817d.js';
|
|
8
8
|
import './ISave-4412b20c.js';
|
9
9
|
import '@sankhyalabs/ezui/dist/collection/utils/constants';
|
10
10
|
import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
|
11
|
-
import { I as InMemoryLoader } from './dataunit-fetcher-
|
11
|
+
import { I as InMemoryLoader } from './dataunit-fetcher-5e9245d7.js';
|
12
12
|
import './filter-item-type.enum-5028ed3f.js';
|
13
13
|
import './form-config-fetcher-5b886892.js';
|
14
14
|
import { T as TaskbarProcessor } from './taskbar-processor-94402e6e.js';
|
15
|
-
import { S as SnkMultiSelectionListDataSource } from './SnkMultiSelectionListDataSource-
|
15
|
+
import { S as SnkMultiSelectionListDataSource } from './SnkMultiSelectionListDataSource-2a4ec61c.js';
|
16
16
|
import './index-bdf75557.js';
|
17
17
|
import './_commonjsHelpers-9943807e.js';
|
18
18
|
import './PrintUtils-3e4ff0f5.js';
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import{FieldComparator as t,SortMode as e,DataUnit as r,defaultDataLoader as n,DataType as s,DateUtils as a,StringUtils as i,ChangeOperation as o,UserInterface as c,DataUnitStorage as l}from"@sankhyalabs/core";import{D as u,d}from"./p-4f7b9c50.js";import{DISTINCT_FILTER_NAME_PREFIX as h}from"@sankhyalabs/ezui/dist/collection/utils/constants";import{DataUnitTransient as f}from"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{R as m}from"./p-688dcb4c.js";class _{constructor(t){this._list=[],this._equalsFunction=t}async load(t,e,r,n){let s=[].concat(this._list);null!=t&&(s=this._list.filter((e=>t(e)))),null!=e&&(s=s.sort(e));const a=s.length;if(null!=n){const t=r||0;s=s.slice(t,n?t+n:s.length)}return Promise.resolve({result:s,count:a})}async distict(t){const e=[];let r=!1;for(const n of this._list){const s=t(n);null!=s&&(null!=s.value?e.push(s):r=!0)}return r&&e.push({key:"",value:null}),Promise.resolve(new Map(e.map((t=>[t.key,t.value]))))}async push(t){this._list.push(...t)}async clear(){this._list=[]}async delete(t){this._list=this._list.filter((e=>{for(const r of t)if(this._equalsFunction(e,r))return!1;return!0}))}async update(t){this._list=this._list.map((e=>{const r=t.find((t=>this._equalsFunction(e,t)));return null==r?e:r}))}async insert(t,e){const r=this._list.indexOf(t);-1!=r?this._list=this._list.slice(0,r).concat(e).concat(this._list.slice(r)):this._list.push(...e)}isOperating(){return!0}async isEmpty(){return Promise.resolve(0===this._list.length)}async count(){return Promise.resolve(this._list.length)}}const p=/FILTRO_COLUNA_(.+)/;class g{static setLoadingStatus(t,e){this._loadingStatus.set(t.name,e)}static isCacheEnabled(t){return g.getResourceId(t.name)===this.applicationResourceID&&this.getRepository(t).isOperating()}static getResourceId(t){const e=I.parseDataUnitName(t);return null==e?void 0:e.resourceID}static cacheRecords(t,e,r,n){g.setLoadingStatus(t,n),g.isCacheEnabled(t)?this.getRepository(t).push(e):r&&this._repositories.delete(t.name)}static getSortingFunction(r,n){if(null!=n&&0!=n.length)return(s,a)=>{for(const i of n){const n=t.compare(r.getField(i.field),s,a,i.mode===e.ASC);if(0!=n)return n}}}static async getDistinct(t,e){if(!g.isCacheEnabled(t))return Promise.resolve(void 0);let r;const n=t.getLastLoadRequest();if(null!=n){const e=g.getColumnFilters(n.filters);r=g.getFilterFunction(t,Array.from(e.values()))}return new Promise(((n,s)=>{g.getRepository(t).distict((n=>{if(null!=r&&!r(n))return;const s=n[e];if(null==s)return{key:null,value:null};const a=null!=s.value?s.value:s;return{key:t.getFormattedValue(e,s),value:a}})).then((t=>n(t))).catch((t=>s(t)))}))}static async loadData(t,e,n){try{if(g.isCacheEnabled(t)){if(("EZ_GRID_LOADING_SOURCE"===e.source||e.source===r.CHANGING_PAGE_LOADING_SOURCE)&&!await g.getRepository(t).isEmpty())return g.loadFromCache(t,e);g.getRepository(t).clear().catch((()=>{}))}return n(t,e)}catch(t){return console.error(t),Promise.reject(t)}}static insertRecords(t,e,r){g.isCacheEnabled(t)&&g.getRepository(t).insert(e,r)}static updateRecords(t,e){g.isCacheEnabled(t)&&g.getRepository(t).update(e)}static removeRecords(t,e){g.isCacheEnabled(t)&&g.getRepository(t).delete(e)}static async countRecords(t){return g.isCacheEnabled(t)?g.getRepository(t).count():Promise.resolve(0)}static getRepository(t){const e=t.name;return g._repositories.has(e)||g._repositories.set(e,new _(((t,e)=>t.__record__id__===e.__record__id__))),g._repositories.get(e)}static getFilterFunction(t,e){if(null!=e&&e.length>0)return r=>{for(const n of e)if(!g.recordMatchesFilter(t,r,n))return!1;return!0}}static recordMatchesFilter(e,r,n){const s=r[n.columnName];for(let r of n.params){const a=e.valueFromString(n.columnName,r.value);if(0===t.compareValues(e.getField(n.columnName),s,a))return!0}return!1}static async loadFromCache(t,e){return new Promise(((r,n)=>{const s=g.getColumnFilters(e.filters),{limit:a,offset:i,sort:o}=e;g.getRepository(t).load(g.getFilterFunction(t,Array.from(s.values())),g.getSortingFunction(t,o),i,a).then((e=>{const n=g._loadingStatus.get(t.name),{count:s,result:o}=e,c=0==s?0:i+1,l=i+Math.min(o.length,a);r({records:o,paginationInfo:{count:s,currentPage:i/a,firstRecord:c,lastRecord:l,hasMore:n||l<s,total:n?void 0:s}})})).catch((t=>n(t)))}))}static getColumnFilters(t){const e=new Map;return null==t||0==t.length||t.forEach((t=>{const r=p.exec(t.name);r&&e.set(t.name,Object.assign({columnName:r[1]},t))})),e}}g._repositories=new Map,g._loadingStatus=new Map;class y{constructor(t,e){this.metadata=t,this.records=e,this._dataUnit=new r(y.IN_MEMORY_DATA_UNIT_NAME),this._dataUnit.metadataLoader=()=>this.metadaLoader(),this._dataUnit.dataLoader=(t,e)=>n(t,e,this.getRecordsToLoad()),this._dataUnit.saveLoader=(t,e)=>this.saveLoader(t,e),this._dataUnit.removeLoader=(t,e)=>this.removeLoader(t,e),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}static getConvertedValue(t,e){return t.dataType===s.BOOLEAN?"S"===e:t.dataType===s.NUMBER?Number(e):t.dataType===s.DATE?a.strToDate(e,!0):e}set records(t){const e=this._metadata?new Map(this._metadata.fields.map((t=>[t.name,t]))):void 0,r=null==t?void 0:t.map((t=>{if(t.__record__id__||(t.__record__id__=this.generateUniqueId()),null!=e)for(const r in t){const n=t[r];"string"==typeof n&&e.has(r)&&(t[r]=y.getConvertedValue(e.get(r),n))}return t}));this._dataUnit?this._dataUnit.records=r:this._initialRecords=r}get metadata(){return this._metadata}set metadata(t){this._metadata=t,this._dataUnit&&(this._dataUnit.metadata=this._metadata)}generateUniqueId(){return i.generateUUID()}metadaLoader(){return Promise.resolve(this._metadata)}saveLoader(t,e){return new Promise((t=>{let r=[];e.forEach((t=>{let{record:e,updatingFields:n,operation:s}=t;const a=Object.assign(Object.assign({},e),n);if(s===o.INSERT||s===o.COPY)a.__old__id__=e.__record__id__,a.__record__id__=this.generateUniqueId(),this.records.push(a);else{const t=this.records.findIndex((t=>t.__record__id__==a.__record__id__));this.records[t]=a}r.push(a)})),t(r)}))}removeLoader(t,e){return new Promise((t=>{t(e)}))}}y.IN_MEMORY_DATA_UNIT_NAME="InMemoryDataUnit";class b{canSlice(){return!1}async load(t,e,r){if(null==t.metadata)return Promise.resolve({records:[],loadingInfo:r});try{const n=[],s=[];if(null!=e.sort)for(const r of e.sort){const e=t.getField(r.field);null!=e&&null!=e.properties&&"true"===e.properties.calculated?n.push(r):s.push(r)}const a=this.getFieldsList(t),i="DatasetSP.loadRecords",o=this.buildRequestBody(i,a,t,e,r,s),c=r.quiet?{urlParams:{quietMode:"true"}}:void 0,{result:l,pagerID:d}=await u.get().callServiceBroker(i,o,c),h=this.processRecords(t,a,l),f=null!=d,m=r.count+h.length,_=!f&&n.length>0;return Promise.resolve({records:h,loadingInfo:Object.assign(Object.assign({},r),{pagerId:d,loadingInProgress:f,total:f?void 0:m,count:m,needReload:_})})}catch(t){return console.error(t),Promise.reject(t)}}getFieldsList(t){let e=["__record__id__","__record__label__"];return t.metadata.fields.forEach((t=>{t.standAlone||(e=e.concat(this.getFieldNames(t)))})),e}getFieldNames(t){const e=this.getSearchDescriptionField(t);return null==e?t.name:[t.name,e]}buildRequestBody(t,e,r,n,s,a){const i=r.name,o={serviceName:t,requestBody:{dataSetID:r.dataUnitId,fields:e,entityName:I.parseDataUnitName(i).entityName,pageNumber:s.pageNumber,totalRecordsCount:s.count,pagerID:s.pagerId,standAlone:!1,standAloneFieldsMD:{__record__id__:{fieldType:"S",userType:"P"},__record__label__:{fieldType:"S",userType:"P"}},tryJoinedFields:!0,parallelLoader:!0,crudListener:"br.com.sankhya.modelcore.dataset.DataUnitDatasetAdapter",txProperties:this.getTxProperties(i,n,a),useDefaultRowsLimit:!1}};return JSON.stringify(o)}getTxProperties(t,e,r){const n={"__DATA_UNIT_ADAPTER__[dataUnitName]":t},s=e.filters.filter((t=>!t.name.startsWith("FILTRO_COLUNA_")));return 0!==s.length&&(n["__DATA_UNIT_ADAPTER__[criteria]"]=JSON.stringify(s)),null!=r&&0!==r.length&&(n["__DATA_UNIT_ADAPTER__[sorting]"]=JSON.stringify(r)),n}processRecords(t,e,r){return r.map((r=>{const n={__record__id__:r[0],__record__label__:r[1]};return t.metadata.fields.forEach((t=>{n[t.name]=this.buildFieldValue(t,e,r)})),n}))}buildFieldValue(t,e,r){const n=e.indexOf(t.name);if(n<0)return null;const s=r[n];if(i.isEmpty(s))return null;const a=this.getSearchDescriptionField(t);if(null!=a){const t=e.indexOf(a);if(t>=0)return{value:s,label:r[t]}}return t.userInterface===c.SEARCH?isNaN(Number(s))?s:Number(s):y.getConvertedValue(t,s)}getSearchDescriptionField(t){if(t.userInterface===c.SEARCH){const{ENTITYNAME:e,mergedFrom:r,DESCRIPTIONFIELD:n}=t.properties;if(!i.isEmpty(n))return null!=r?`${r}.${e}.${n}`:`${e}.${n}`}}}class v{static async debounce(t,e){const r=t.name;v._debouncingTimeouts[r]&&(clearTimeout(v._debouncingTimeouts[r]),delete v._debouncingTimeouts[r]),v._debouncingTimeouts[r]=setTimeout((()=>{delete v._debouncingTimeouts[r],e()}),100)}static async loadData(t,e){return new Promise(((r,n)=>{v.debounce(t,(()=>{g.loadData(t,e,this.loadFromServer).then((t=>r(t))).catch((t=>n(t)))}))}))}static async loadFromServer(t,e,r){try{r=v.registryLoading(t,r);const n=await v.callLoader(t,e,r);if(null==n)return;const s=n.records,a=v.buildPaginationInfo(s.length,e,n.loadingInfo),i=null==a?s:s.slice(0,a.lastRecord);return Promise.resolve({records:i,paginationInfo:a})}catch(t){return console.error(t),Promise.reject(t)}}static async callLoader(t,e,r,n){null==n&&(n=new b);const s=await n.load(t,e,r),{records:a,loadingInfo:i}=s;if(v.isOldRequest(t,i))return Promise.resolve(void 0);const o=!n.canSlice()||0===i.count;if(g.cacheRecords(t,a,o,i.loadingInProgress),g.isCacheEnabled(t)&&i.loadingInProgress){const r=Object.assign(Object.assign({},e),{offset:i.count}),s=Object.assign(Object.assign({},i),{pageNumber:(i.pageNumber||0)+1,quiet:!0});this.callLoader(t,r,s,n).then((e=>v.afterLoadingPage(t,e.loadingInfo))).catch((t=>console.error(t)))}return Promise.resolve(s)}static afterLoadingPage(t,e){g.setLoadingStatus(t,e.loadingInProgress);const r=t.getPaginationInfo();if(null==r)return;const n=e.count;e.loadingInProgress?t.updatePagination(Object.assign(Object.assign({},r),{count:n})):e.needReload?t.gotoPage(0):t.updatePagination(Object.assign(Object.assign({},r),{total:n,count:n}))}static registryLoading(t,e){return null==e&&(e={requestTime:(new Date).getTime(),count:0}),v._requestTimeByDataUnit.set(t.name,e.requestTime),e}static isOldRequest(t,e){return v._requestTimeByDataUnit.get(t.name)>e.requestTime}static buildPaginationInfo(t,e,r){let{limit:n,offset:s}=e;if(!n)return;1===r.pageNumber&&(s=0);const{total:a,count:i,loadingInProgress:o}=r,c=0===i||0===t?0:s+1,l=s+Math.min(t,n);return{total:a,count:i,lastRecord:l,firstRecord:c,currentPage:s/n,hasMore:l<i||o}}}v._requestTimeByDataUnit=new Map,v._debouncingTimeouts={};const D=/dd:\/\/([^/]+)\/([^/?]+)/;class I{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchDataUnit",d.gql`query($name: String!) {
|
2
|
+
$queryAlias$: fetchDataUnit(name: $name){
|
3
|
+
name
|
4
|
+
fields{
|
5
|
+
name
|
6
|
+
defaultValue
|
7
|
+
label
|
8
|
+
visible
|
9
|
+
readOnly
|
10
|
+
required
|
11
|
+
dataType
|
12
|
+
userInterface
|
13
|
+
calculated
|
14
|
+
group
|
15
|
+
order
|
16
|
+
properties{
|
17
|
+
name
|
18
|
+
value
|
19
|
+
}
|
20
|
+
dependencies{
|
21
|
+
masterFields
|
22
|
+
type
|
23
|
+
expression
|
24
|
+
}
|
25
|
+
}
|
26
|
+
children{
|
27
|
+
name
|
28
|
+
label
|
29
|
+
links{
|
30
|
+
source
|
31
|
+
target
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}`),this.templateByQuery.set("saveData",d.gql`mutation($changes: [InputBatchChange!]!) {
|
36
|
+
$queryAlias$: batchOperationDataUnit(changes: $changes){
|
37
|
+
oldId
|
38
|
+
id
|
39
|
+
label
|
40
|
+
ownerDataUnitName
|
41
|
+
fields {
|
42
|
+
name
|
43
|
+
value
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}`),this.templateByQuery.set("fetchDataRecord",d.gql`query($dataunit: String! $recordID: [String!]) {
|
47
|
+
$queryAlias$: fetchDataUnit(name: $dataunit){
|
48
|
+
record(id: $recordID){
|
49
|
+
id
|
50
|
+
label
|
51
|
+
fields {
|
52
|
+
name
|
53
|
+
value
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}`),this.templateByQuery.set("fetchDistinctColumn",d.gql`query($dataUnit: String!, $fieldName: String!, $argument: String, $filters: [InputFilter], $parentRecordId: String) {
|
58
|
+
$queryAlias$: selectDistinct(dataUnit: $dataUnit, fieldName: $fieldName, argument: $argument, filters: $filters, parentRecordId: $parentRecordId)
|
59
|
+
}`)}static parseDataUnitName(t){if(null==t)return;const e=D.exec(t);return e?{entityName:e[1],resourceID:e[2]}:void 0}getDataUnit(t,e,n,s){null==g.applicationResourceID&&m.getResourceID().then((t=>g.applicationResourceID=t));const a=`dd://${t}/${e}${s?"/"+s:""}`,i=null!=n?n.getChildDataunit(a):new r(a);return i.metadataLoader=t=>this.loadMetadata(t),i.dataLoader=(t,e)=>v.loadData(t,e),i.saveLoader=(t,e)=>this.saveData(i,e),i.removeLoader=(t,e)=>this.removeRecords(t,e),i.recordLoader=(t,e)=>this.loadRecord(t,e),i}loadMetadata(t){return new Promise(((e,r)=>{u.get().callGraphQL({values:{name:t.name},query:this.templateByQuery.get("fetchDataUnit")}).then((t=>{var r;const n={name:t.name,label:t.name,children:[...t.children],fields:[]};null===(r=t.fields)||void 0===r||r.forEach((t=>{let e;Array.isArray(t.properties)&&(e={},t.calculated&&(e.gridHeaderTooltip="Campos calculados não podem ser ordenados"),t.properties.forEach((t=>e[t.name]=t.value))),n.fields.push(Object.assign(Object.assign({},t),{properties:e}))})),n.fields.sort(((t,e)=>t.order-e.order)),e(n)})).catch((t=>{r(t)}))}))}loadSelectDistinct(t,e,r){const{parentRecordId:n,filters:s}=t.getLastLoadRequest()||{},a=s.filter((t=>t.name!==`${h}${e}`)),i={dataUnit:t.name,argument:r,fieldName:e,parentRecordId:n,filters:a};return new Promise(((t,e)=>{u.get().callGraphQL({values:i,query:this.templateByQuery.get("fetchDistinctColumn")}).then((e=>{t(e)})).catch((t=>{e(t)}))}))}saveData(t,e){const r=[],n=[],a=e.map((e=>{const{dataUnit:a,record:i,updatingFields:c,operation:u}=e,d=l.get(a);let h;c&&(h=Object.entries(c).map((([t,e])=>{const r=d.getField(t);return{fieldName:t,dataType:r?r.dataType:s.TEXT,value:d.valueToString(t,e)}}))),a===t.name&&(u===o.INSERT||u===o.COPY?n.push(i.__record__id__):r.push(i.__record__id__));const f={dataUnit:a,fields:h,operation:u,recordId:i.__record__id__};return e.sourceId&&(f.sourceId=e.sourceId),i.__parent__record__id__&&(f.parentRecordId=i.__parent__record__id__),f}));return new Promise(((e,s)=>{const i=a.map((t=>function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(r[n[s]]=t[n[s]])}return r}(t,[])));u.get().callGraphQL({values:{changes:i},query:this.templateByQuery.get("saveData")}).then((s=>{const a=[];null==s||s.forEach((e=>{const r={__record__id__:e.id,__record__label__:e.label,__owner__dataunit__name__:e.ownerDataUnitName},n=l.get(r.__owner__dataunit__name__)||t;e.oldId&&(r.__old__id__=e.oldId),e.fields.forEach((({name:t,value:e})=>{var s;r[t]=(null===(s=null==n?void 0:n.valueFromString)||void 0===s?void 0:s.call(n,t,e))||e})),a.push(r)})),this.updateCache(t,a,r,n),e(a)})).catch((t=>{s(t)}))}))}updateCache(t,e,r,n){const s=new Map(e.map((t=>[t.__old__id__||t.__record__id__,t]))),a=n.map((t=>{const e=Object.assign({},s.get(t));return delete e.__old__id__,e}));a.length>0&&g.insertRecords(t,t.records[0],a);const i=r.map((t=>Object.assign({},s.get(t))));g.updateRecords(t,i)}getTransientInfo(t,e){const{records:r}=t.getSelectionInfo();return Object.entries(r.filter((t=>t.__record__id__==e))[0]).filter((([t])=>t.startsWith(f.DATA_UNIT_TRANSIENT_PREFIX_NAME))).map((([t,e])=>({fieldName:t,value:e,dataType:s.TEXT})))}removeRecords(t,e){const r=e.map((e=>({dataUnit:t.name,operation:o.DELETE,recordId:e,fields:this.getTransientInfo(t,e)})));return new Promise(((n,s)=>{u.get().callGraphQL({values:{changes:r},query:this.templateByQuery.get("saveData")}).then((()=>{g.removeRecords(t,t.records.filter((t=>e.includes(t.__record__id__)))),n(e)})).catch((t=>{s(t)}))}))}loadRecord(t,e){return new Promise(((r,n)=>{u.get().callGraphQL({values:{recordID:e,dataunit:t.name},query:this.templateByQuery.get("fetchDataRecord")}).then((e=>{const n=[];e.record.forEach((e=>{const r={__record__id__:e.id,__record__label__:e.label};e.fields.forEach((({name:e,value:n})=>{r[e]=t.valueFromString(e,n)})),n.push(r)})),r(n)})).catch((t=>{n(t)}))}))}}export{I as D,y as I,g as P}
|
@@ -1 +1 @@
|
|
1
|
-
export{S as snk_guides_viewer}from"./p-
|
1
|
+
export{S as snk_guides_viewer}from"./p-c34cea23.js";import"./p-d2d301a6.js";import"@sankhyalabs/core";import"./p-96dd0c41.js";import"./p-b19c272c.js";import"./p-0f2b03e5.js";import"./p-4f7b9c50.js";import"./p-112455b1.js";import"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import"./p-8d884fab.js";import"./p-584d7212.js";import"@sankhyalabs/ezui/dist/collection/utils/form";import"./p-c2beb95c.js";import"./p-c9841939.js";import"./p-5534e08c.js";import"./p-6dc031de.js";import"./p-4a78e118.js";import"./p-efb2e247.js";import"./p-9e7d65a4.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"./p-171b12d5.js";import"./p-688dcb4c.js";import"@sankhyalabs/core/dist/dataunit/DataUnit";
|
@@ -1 +1 @@
|
|
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-4f7b9c50.js";import"./p-efb2e247.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-
|
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-4f7b9c50.js";import"./p-efb2e247.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-171b12d5.js";import"./p-584d7212.js";import"./p-0f2b03e5.js";import{c}from"./p-4a78e118.js";import{A as l}from"./p-de1196c8.js";import"./p-6dc031de.js";import"./p-112455b1.js";import"./p-8d884fab.js";import"./p-688dcb4c.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,4 +1,4 @@
|
|
1
|
-
import{r as t,c as s,h as e,g as i}from"./p-d2d301a6.js";import{DateUtils as n,StringUtils as r,ObjectUtils as a,WaitingChangeException as o,WarningException as c,ErrorException as h,OnboardingUtils as u,DependencyType as l,ElementIDUtils as p,DataType as d,ApplicationContext as m,ErrorTracking as w}from"@sankhyalabs/core";import{ApplicationUtils as f}from"@sankhyalabs/ezui/dist/collection/utils";import{C as y}from"./p-b19c272c.js";import{d as P,D as g,U as v}from"./p-4f7b9c50.js";import{A as I,a as A}from"./p-de1196c8.js";import{D as _}from"./p-
|
1
|
+
import{r as t,c as s,h as e,g as i}from"./p-d2d301a6.js";import{DateUtils as n,StringUtils as r,ObjectUtils as a,WaitingChangeException as o,WarningException as c,ErrorException as h,OnboardingUtils as u,DependencyType as l,ElementIDUtils as p,DataType as d,ApplicationContext as m,ErrorTracking as w}from"@sankhyalabs/core";import{ApplicationUtils as f}from"@sankhyalabs/ezui/dist/collection/utils";import{C as y}from"./p-b19c272c.js";import{d as P,D as g,U as v}from"./p-4f7b9c50.js";import{A as I,a as A}from"./p-de1196c8.js";import{D as _}from"./p-171b12d5.js";import{P as S}from"./p-efb2e247.js";import{S as b}from"./p-f1f7b545.js";import"./p-0f2b03e5.js";import"./p-584d7212.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-688dcb4c.js";class E{static webConnectionCaller(t,s,e){var i;null===(i=window.AppletCaller)||void 0===i||i.webConnectionCaller(t,s,e)}}const N=D;function D(t,s){const e=C();return(D=function(t){return e[t-=378]})(t,s)}function C(){const t=["true","863GKWjmo","parse","56355fjjjAm","isSup","putAccess","4324480sjuCdS","hasOwnProperty","239748okvJLB","name","6055770tXeRaU","actions","forEach","7RPRvzn","1042CHxkUw","2988126NIwRMm","20MTNzmH","authorizationSf","item","string","hasAccess","isArray","Objeto não pode ser indefinido.","3071943fWslZp","parseFromJSON"];return(C=function(){return t})()}!function(){const t=D,s=C();for(;;)try{if(281287==parseInt(t(399))/1*(-parseInt(t(387))/2)+-parseInt(t(401))/3+parseInt(t(381))/4*(-parseInt(t(389))/5)+parseInt(t(388))/6*(-parseInt(t(386))/7)+parseInt(t(379))/8+parseInt(t(396))/9+parseInt(t(383))/10)break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class T{[N(397)](t){const s=N;if(typeof(t=utxt(t[s(390)]))==s(392)&&(t=JSON[s(400)](t)),null==t)throw Error(s(395));const e=new L("S"===t[s(402)]||!0===t[s(402)]);return Array[s(394)](t[s(391)])&&t[s(391)][s(385)]((t=>e.putAccess(t[s(382)],String(t.status)==s(398)))),e}}class L{constructor(t){const s=N;this.isSup=t,this[s(384)]={}}[N(378)](t,s){this[N(384)][t]=s}[N(393)](t){const s=N;if(this[s(402)])return!0;let e=!0;return this[s(384)][s(380)](t)&&(e=this.actions[t]),e}isUserSup(){return this.isSup}}class O{constructor(){this.templateByQuery=new Map,this.buldTemplates()}buldTemplates(){this.templateByQuery.set("fetchParam",P.gql`query($name: String!) {
|
2
2
|
$queryAlias$: fetchResource(name: $name){
|
3
3
|
name
|
4
4
|
resource
|
@@ -0,0 +1 @@
|
|
1
|
+
import{r as i,c as t,h as s,g as e}from"./p-d2d301a6.js";import{SortMode as r,ElementIDUtils as d,ApplicationContext as a,DataType as o}from"@sankhyalabs/core";import{UserInterface as n}from"@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";import{T as h}from"./p-c9841939.js";import{C as l}from"./p-b19c272c.js";import{P as c}from"./p-5534e08c.js";import{T as u}from"./p-c2beb95c.js";import{s as v}from"./p-6dc031de.js";import{S as g}from"./p-7469e2ef.js";import{SelectionMode as m}from"@sankhyalabs/core/dist/dataunit/DataUnit";import"./p-0f2b03e5.js";import"./p-4f7b9c50.js";import"./p-112455b1.js";import"./p-8d884fab.js";import"./p-584d7212.js";import"./p-171b12d5.js";import"@sankhyalabs/ezui/dist/collection/utils/constants";import"./p-688dcb4c.js";const f=class{constructor(s){i(this,s),this.actionClick=t(this,"actionClick",7),this.gridDoubleClick=t(this,"gridDoubleClick",7),this._topTaskbarProcessor=new u({"snkGridTopTaskbar.regular":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.regular.secondary":["FORM_MODE","CONFIGURATOR","INSERT"],"snkGridTopTaskbar.finish_edition":["CANCEL","SAVE"],"snkGridTopTaskbar.finish_edition.secondary":[]}),this._headerTaskbarProcessor=new u({"snkGridHeaderTaskbar.unselected":["REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.selected":["UPDATE","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","ATTACH","REFRESH","DATA_EXPORTER","ACTIONS_BUTTON"],"snkGridHeaderTaskbar.detail.unselected":["REFRESH"],"snkGridHeaderTaskbar.detail.selected":["UPDATE","ATTACH","CLONE","REMOVE","MORE_OPTIONS","DIVIDER","REFRESH"]}),this._dataUnit=void 0,this._dataState=void 0,this._gridConfig=void 0,this._popUpGridConfig=!1,this.columnFilterDataSource=new g,this.configName=void 0,this.resourceID=void 0,this.selectionToastConfig=void 0,this.actionsList=void 0,this.isDetail=void 0,this.taskbarManager=void 0,this.statusResolver=void 0,this.multipleSelection=void 0,this.presentationMode=c.PRIMARY,this.messagesBuilder=void 0,this.useEnterLikeTab=!1,this.recordsValidator=void 0,this.canEdit=!0,this.taskbarCustomContainerId=void 0,this.gridHeaderCustomSlotId="GRID_HEADER_CUSTOM_ELEMENTS",this.topTaskbarCustomSlotId="GRID_TASKBAR_CUSTOM_ELEMENTS"}async showConfig(){null!=this._grid&&this.openGridConfig()}async hideConfig(){null!=this._grid&&this.closeGridConfig()}async setConfig(i){this.setGridConfig(i)}async reloadFilterBar(){var i;null===(i=this._snkFilterBar)||void 0===i||i.reload()}openGridConfig(){this._grid.getColumnsState().then((i=>{this._snkGridConfig.columns=i.filter((i=>i.name)),this._snkGridConfig.selectedIndex=0,this._popUpGridConfig=!0}))}closeGridConfig(){this._popUpGridConfig=!1}setGridConfig(i){this._gridConfig=i,this.assertDefaultSorting()}assertDefaultSorting(){this._gridConfig&&this._dataUnit&&(this._dataUnit.defaultSorting=this._gridConfig.columns.filter((i=>null!=i.ascending)).sort(((i,t)=>i.orderIndex-t.orderIndex)).map((({name:i,ascending:t})=>{const{dataType:s}=this._dataUnit.getField(i);return{field:i,dataType:s,mode:t?r.ASC:r.DESC}})))}loadConfig(){l.loadGridConfig(this.configName,this.resourceID).then((i=>{this.setGridConfig(i)})).catch((i=>{console.warn(i)}))}gridConfigChangeHandler(i){l.saveGridConfig(i.detail,this.configName,this.resourceID),i.stopPropagation()}modalConfigChangeHandler(i){const t=i.detail;this._grid.setColumnsState(t.columns).then((()=>{this.setGridConfig(t),this.closeGridConfig(),this.dataExporterProviderStore()})),i.stopPropagation()}buildColumnsMetadata(i){const t=[];return null==i||i.forEach((i=>{var s,e;if(i.hidden&&"RECDESP"!==i.name)return;const r=null===(s=this._dataUnit)||void 0===s?void 0:s.getField(i.name);if(t.push({label:i.label,id:i.name,width:i.width,type:null==r?void 0:r.dataType,userInterface:null==r?void 0:r.userInterface}),null!=(null===(e=null==r?void 0:r.properties)||void 0===e?void 0:e.DESCRIPTIONFIELD)){const i=r.properties.mergedFrom;t.push({label:r.properties.DESCRIPTIONENTITY,id:`${i?i+".":""}${r.properties.ENTITYNAME}.${r.properties.DESCRIPTIONFIELD}`,width:200,type:o.TEXT,userInterface:n.LONGTEXT})}})),t||[]}getPaginationInfo(){var i;return null===(i=this._dataUnit)||void 0===i?void 0:i.getPaginationInfo()}getExporterOffset(i){if(null==i)return;const t=i.firstRecord;return t>0?t-1:t}async dataExporterProviderStore(){var i;const t=await(null===(i=this._snkDataUnit)||void 0===i?void 0:i.getSelectedRecordsIDsInfo()),s={getFilters:()=>{var i;return null===(i=this._dataUnit)||void 0===i?void 0:i.getAppliedFilters()},getColumnsMetadata:async()=>{var i;const t=await(null===(i=this._grid)||void 0===i?void 0:i.getColumnsState());return this.buildColumnsMetadata(t)},getOrders:()=>{var i;return null===(i=this._dataUnit)||void 0===i?void 0:i.getSort()},getResourceURI:()=>{var i;return null===(i=this._dataUnit)||void 0===i?void 0:i.name},getSelectedNumber:()=>{var i,t;return null===(t=null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo)||void 0===t?void 0:t.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:()=>t||[],getOffset:()=>this.getExporterOffset(this.getPaginationInfo()),getLimit:()=>{var i;return null===(i=this._dataUnit)||void 0===i?void 0:i.pageSize},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__}};v.set("exporterProviders",Object.assign(Object.assign({},v.get("exporterProviders")),{[this.configName]:s}))}addElementID(){d.addIDInfo(this._element,null,{dataUnit:this._dataUnit})}finshLoading(){this.assertDefaultSorting(),this.addElementID(),null!=this.columnFilterDataSource&&(this.columnFilterDataSource.setApplication(this._application),this.columnFilterDataSource.setDataUnit(this._dataUnit))}componentWillLoad(){this._application=a.getContextValue("__SNK__APPLICATION__");let i=this._element.parentElement;for(;i;){if("SNK-DATA-UNIT"===i.tagName.toUpperCase()){this._snkDataUnit=i,this._dataUnit=this._snkDataUnit.dataUnit,this._dataUnit?this.finshLoading():this._snkDataUnit.addEventListener("dataUnitReady",(i=>{this._dataUnit=i.detail,this.finshLoading()})),this.messagesBuilder||(this.messagesBuilder=this._snkDataUnit.messagesBuilder),this._snkDataUnit.addEventListener("dataStateChange",(i=>{this._dataState=i.detail})),this._snkDataUnit.addEventListener("cancelEdition",(()=>{var i;(null===(i=this._dataState)||void 0===i?void 0:i.recordsIsEmpty)&&this._dataUnit.clearSelection()}));break}i=i.parentElement}this.loadConfig()}getHeaderDisabledButtons(){var i;const t=[];return(null===(i=this._dataState)||void 0===i?void 0:i.selectionInfo)&&(this._dataState.selectionInfo.length>1&&t.push(h.CLONE,"ATTACH"),this._dataState.selectionInfo.isAllRecords()&&t.push("REMOVE")),t}getInvisibleButtons(){let i=[];return this._dataUnit&&0!==this._dataUnit.records.length||i.push("DATA_EXPORTER"),this._dataState&&this._dataState.selectionInfo.mode===m.ALL_RECORDS&&i.push("ACTIONS_BUTTON"),i}componentWillRender(){var i;const t=this.getInvisibleButtons();let s;s=this._dataState&&(null===(i=this._dataState.selectionInfo)||void 0===i?void 0:i.length)?this.isDetail?"snkGridHeaderTaskbar.detail.selected":"snkGridHeaderTaskbar.selected":this.isDetail?"snkGridHeaderTaskbar.detail.unselected":"snkGridHeaderTaskbar.unselected",this._headerTaskbarProcessor.process(s,this.taskbarManager,this._dataState,this.getHeaderDisabledButtons(),t),this._topTaskbarProcessor.process(this.getTopTaskBarId(this.presentationMode===c.SECONDARY?".secondary":""),this.taskbarManager,this._dataState,void 0,t),this.dataExporterProviderStore()}getTopTaskBarId(i){var t;return(null===(t=this._dataState)||void 0===t?void 0:t.isDirty)?`snkGridTopTaskbar.finish_edition${i}`:`snkGridTopTaskbar.regular${i}`}getPrimaryButton(){return this.presentationMode===c.PRIMARY?"INSERT":""}render(){var i,t;if(this._dataUnit)return s("div",{class:"snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large"},s("div",{class:"snk-grid__header ez-margin-bottom--medium"},s("snk-filter-bar",{ref:i=>this._snkFilterBar=i,dataUnit:this._dataUnit,"data-element-id":"gridFilter",class:"snk-grid__filter-bar ez-align--top",configName:this.configName,messagesBuilder:this.messagesBuilder,resourceID:this.resourceID}),(null===(t=null===(i=this._snkFilterBar)||void 0===i?void 0:i.filterConfig)||void 0===t?void 0:t.length)>0&&s("hr",{class:"ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider"}),s("snk-taskbar",{class:"ez-padding-left--medium","data-element-id":"grid_top",key:"topTaskbar",configName:this.configName,dataUnit:this._dataUnit,messagesBuilder:this.messagesBuilder,buttons:this._topTaskbarProcessor.buttons,disabledButtons:this._topTaskbarProcessor.disabledButtons,customButtons:this._topTaskbarProcessor.customButtons,primaryButton:this.getPrimaryButton(),resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.topTaskbarCustomSlotId},s("slot",{name:this.topTaskbarCustomSlotId}))),s("ez-grid",{ref:i=>this._grid=i,class:(this.presentationMode===c.SECONDARY?"snk-grid-container__without-shadow ":"")+"snk-grid__table","data-element-id":"embedded",dataUnit:this._dataUnit,key:"grid-"+this._snkDataUnit.entityName,config:this._gridConfig,onConfigChange:i=>{this.gridConfigChangeHandler(i)},onEzDoubleClick:()=>this.gridDoubleClick.emit(),statusResolver:this.statusResolver,multipleSelection:this.multipleSelection,columnfilterDataSource:this.columnFilterDataSource,selectionToastConfig:this.selectionToastConfig,useEnterLikeTab:this.useEnterLikeTab,recordsValidator:this.recordsValidator,canEdit:this.canEdit},s("snk-taskbar",{dataUnit:this._dataUnit,configName:this.configName,messagesBuilder:this.messagesBuilder,"data-element-id":"grid_left",buttons:this._headerTaskbarProcessor.buttons,disabledButtons:this._headerTaskbarProcessor.disabledButtons,customButtons:this._headerTaskbarProcessor.customButtons,slot:"leftButtons",actionsList:this.actionsList,resourceID:this.resourceID,customContainerId:this.taskbarCustomContainerId,customSlotId:this.gridHeaderCustomSlotId},s("slot",{name:this.gridHeaderCustomSlotId}))),s("div",{class:"ez-col ez-col--sd-12"},s("slot",{name:"SnkGridFooter"})),s("ez-modal",{modalSize:"small",closeEsc:!1,closeOutsideClick:!1,opened:this._popUpGridConfig,onEzCloseModal:()=>this.closeGridConfig()},s("snk-grid-config",{ref:i=>this._snkGridConfig=i,config:this._gridConfig,"data-element-id":this._element.getAttribute(d.DATA_ELEMENT_ID_ATTRIBUTE_NAME),application:this._application,selectedIndex:0,configName:this.configName,onConfigChange:i=>this.modalConfigChangeHandler(i),onConfigCancel:()=>this.closeGridConfig(),resourceID:this.resourceID})))}get _element(){return e(this)}};f.style=".snk-grid__container.sc-snk-grid{display:flex;height:100%;width:100%}.snk-grid__header.sc-snk-grid{display:flex;flex-wrap:nowrap;width:100%}.snk-grid__filter-bar.sc-snk-grid{width:100%}.snk-grid__header-divider.sc-snk-grid{margin-bottom:var(--space--medium)}.snk-grid__table.sc-snk-grid{min-height:300px}.snk-grid-container__without-shadow.sc-snk-grid{--ezgrid__container--shadow:unset}";export{f as snk_grid}
|
@@ -1 +1 @@
|
|
1
|
-
import{UserInterface as t,DateUtils as e}from"@sankhyalabs/core";import{P as s}from"./p-
|
1
|
+
import{UserInterface as t,DateUtils as e}from"@sankhyalabs/core";import{P as s}from"./p-171b12d5.js";class i{setDataUnit(t){this._dataUnit=t}setApplication(t){this._application=t}formatLabel(s,i){const{userInterface:r}=this._dataUnit.getField(s);return r===t.DATETIME?e.formatDate(this._dataUnit.valueFromString(s,i)):String(this._dataUnit.getFormattedValue(s,i))}async getStaticOptions(t){if(null==t)return Promise.resolve(void 0);const e=await s.getDistinct(this._dataUnit,t);return Promise.resolve(null==e?void 0:Array.from(e.entries()).map((([t,e])=>({label:String(t),value:e,check:!0}))))}fetchData(e,s){return new Promise((i=>{this._application.executeSelectDistinct(this._dataUnit,s,e).then((e=>{i(e.map((e=>this._dataUnit.getField(s).userInterface===t.SEARCH?Object.assign(Object.assign({},JSON.parse(e)),{check:!0}):{value:e,label:this.formatLabel(s,e),check:!0})))}))}))}}export{i as S}
|
@@ -1 +1 @@
|
|
1
|
-
import{r as t,c as i,h as e}from"./p-d2d301a6.js";import{ApplicationContext as s,DataType as n,Action as a}from"@sankhyalabs/core";import{D as r}from"./p-4f7b9c50.js";import{S as o}from"./p-9e7d65a4.js";import{c as h}from"./p-4a78e118.js";import{D as d}from"./p-85635c64.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-688dcb4c.js";import"./p-5534e08c.js";import"./p-6dc031de.js";class c{constructor(t,i,e){var s;this.entityName=t,this.registerKey=i,this.dataUnitName=e,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 i,e;const s="AnexoSistemaSP.salvar";let{updatingFields:n}=t;n=Object.assign(Object.assign({},n),{NOMEARQUIVO:null===(i=n.NOMEARQUIVO)||void 0===i?void 0:i[0]});try{this.validateFields(n);const t=n.LINK?null:n.NOMEARQUIVO,i={serviceName:s,requestBody:{params:{resourceID:this.resourceID,description:n.DESCRICAO,fileSelect:t?1:0,keySession:null===(e=null==t?void 0:t.properties)||void 0===e?void 0:e.fileNameTmp,nameAttach:null==t?void 0:t.name,link:n.LINK,nameEntity:this.entityName,pkEntity:this.registerKey,typeAcess:n.TIPOACESSO,typeApres:n.TIPOAPRES}}},a=await r.get().callServiceBroker(s,JSON.stringify(i));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 i,e,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===(e=null===(i=a.NOMEARQUIVO)||void 0===i?void 0:i[0])||void 0===e?void 0:e.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}}},i=await r.get().callServiceBroker(n,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},i),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 i;const e="AnexoSistemaSP.excluir",s=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},n={serviceName:e,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,i)=>{r.get().callServiceBroker(e,JSON.stringify(n)).then((i=>t(i))).catch((t=>i(t)))}))}getDownloadKey(t){var i;const e="AnexoSistemaSP.baixar",s=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},n={serviceName:e,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,i)=>{r.get().callServiceBroker(e,JSON.stringify(n)).then((i=>t(i))).catch((t=>i(t)))}))}}class m{constructor(t,i){this.entityName=t,this.getMessage=i,this._application=s.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,s)=>this.saveLoader(s,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,s)=>this.removeLoader(t,s,i).then((t=>(t.length&&e(),t)))}dataLoader(t,i){return new Promise((e=>{this.loader(t,i).then((t=>{const i=((null==t?void 0:t.records)||[]).map((t=>{let i;return t.LINK||(i=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:i})}));e(Object.assign(Object.assign({},t),{records:i}))}))}))}saveLoader(t,i){return new Promise((e=>{var s;const n=Array.isArray(t)?t[0]:{};((null===(s=null==n?void 0:n.record)||void 0===s?void 0:s.NUATTACH)>=0?i.edit.bind(i):i.save.bind(i))(n).then((t=>{e(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")),e([])):t.message===o.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((s=>{const{records:n}=t.getSelectionInfo();e.delete(n[0]).then((()=>s(i)))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:n.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,i,e){return new Promise((s=>i.type===a.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(h.GRID),s(i)):s(void 0))):s(i):i.type===a.DATA_SAVED?(t.loadData(),s(i)):void s(i)))}}const u=s.getContextValue("__SNK__APPLICATION__"),v=t=>{var i,e;return null===(e=null===(i=null==u?void 0:u.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,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,i,e)=>{if((null==i?void 0:i.insertionMode)||(null==i?void 0:i.isDirty))return e.reverse();e.splice(e.indexOf(l.REFRESH),1);const{selectedRecord:s}=i||{},n=(null==s?void 0:s.LINK)?A.LINK:A.DOWNLOAD;e.splice(e.indexOf(l.DIVIDER)+1,0,l.REMOVE,n,l.DIVIDER);const a=Array.from(new Set(e.filter((t=>t!==l.CLONE))));return a.splice(a.indexOf(n)+1,0,l.DIVIDER),a},isEnabled:(i,e,s)=>{const n=void 0!==(null==e?void 0:e.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(e){t(this,e),this.back=i(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,i){var e;i!==t&&(this.returnToGridMode(),this._attachFetcher=new c(this.entityName,this.registerKey,null===(e=this.dataUnit)||void 0===e?void 0:e.name),this._dataUnitBuilder.initLoaders(this.dataUnit,this._attachFetcher,(()=>{this.returnToGridMode()})),this.dataUnit.loadData())}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error("Nenhum registro selecionado");t.LINK?window.open(`${t.LINK}`):this._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 i=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),i.metadata||i.loadMetadata().then((()=>{this.crudConfig=p})),this._dataUnitBuilder=new m(this.entityName,this.getMessage.bind(this)),i.addFilterProvider({getFilter:()=>this._dataUnitBuilder.getFilters(this.registerKey)}),i.addInterceptor({interceptAction:t=>this._dataUnitBuilder.getInterceptions(i,t,this._crudElement)}),this.dataUnit=i,this.dataUnit.loadData().then((()=>{this.disableEditFieldsNotInForm()})),this.dataUnit}catch(t){throw new Error("There was an error while creating the data unit")}}disableEditFieldsNotInForm(){var t;null===(t=this.crudConfig)||void 0===t||t.grid.columns.forEach((t=>{var i;const e=t.name;(null===(i=this.crudConfig)||void 0===i?void 0:i.form.fields.some((t=>t.name===e)))||this.dataUnit.disableField(e)}))}componentWillLoad(){this._application=s.getContextValue("__SNK__APPLICATION__"),this.loadAttachmentDataUnit()}render(){var t,i;return this.dataUnit?e("main",{class:"snk-attach__main"},e("header",{class:"snk-attach__header"},e("snk-simple-bar",{onExit:this.handleBack,messagesBuilder:this.messagesBuilder},e("div",{slot:"rightSlot"},e("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})))),e("div",{class:"snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column"},e("div",{class:"ez-box__container"},e("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this.dataUnit,taskbarManager:O(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(i=this.crudConfig)||void 0===i?void 0:i.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick},e("div",{slot:"snkSimpleCrudHeader"},e("div",{class:"ez-flex ez-flex--column"},e("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium"},this.getMessage("snkAttach.title")),e("span",{class:"ez-text ez-text--medium ez-text--secondary"},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
|
+
import{r as t,c as i,h as e}from"./p-d2d301a6.js";import{ApplicationContext as s,DataType as n,Action as a}from"@sankhyalabs/core";import{D as r}from"./p-4f7b9c50.js";import{S as o}from"./p-9e7d65a4.js";import{c as h}from"./p-4a78e118.js";import{D as d}from"./p-171b12d5.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-688dcb4c.js";import"./p-5534e08c.js";import"./p-6dc031de.js";class c{constructor(t,i,e){var s;this.entityName=t,this.registerKey=i,this.dataUnitName=e,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 i,e;const s="AnexoSistemaSP.salvar";let{updatingFields:n}=t;n=Object.assign(Object.assign({},n),{NOMEARQUIVO:null===(i=n.NOMEARQUIVO)||void 0===i?void 0:i[0]});try{this.validateFields(n);const t=n.LINK?null:n.NOMEARQUIVO,i={serviceName:s,requestBody:{params:{resourceID:this.resourceID,description:n.DESCRICAO,fileSelect:t?1:0,keySession:null===(e=null==t?void 0:t.properties)||void 0===e?void 0:e.fileNameTmp,nameAttach:null==t?void 0:t.name,link:n.LINK,nameEntity:this.entityName,pkEntity:this.registerKey,typeAcess:n.TIPOACESSO,typeApres:n.TIPOAPRES}}},a=await r.get().callServiceBroker(s,JSON.stringify(i));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 i,e,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===(e=null===(i=a.NOMEARQUIVO)||void 0===i?void 0:i[0])||void 0===e?void 0:e.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}}},i=await r.get().callServiceBroker(n,JSON.stringify(t));return Promise.resolve([Object.assign(Object.assign(Object.assign({},i),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 i;const e="AnexoSistemaSP.excluir",s=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},n={serviceName:e,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,i)=>{r.get().callServiceBroker(e,JSON.stringify(n)).then((i=>t(i))).catch((t=>i(t)))}))}getDownloadKey(t){var i;const e="AnexoSistemaSP.baixar",s=(null===(i=t.NOMEARQUIVO)||void 0===i?void 0:i[0])||{},n={serviceName:e,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,i)=>{r.get().callServiceBroker(e,JSON.stringify(n)).then((i=>t(i))).catch((t=>i(t)))}))}}class m{constructor(t,i){this.entityName=t,this.getMessage=i,this._application=s.getContextValue("__SNK__APPLICATION__")}initLoaders(t,i,e){this.loader||(this.loader=t.dataLoader),t.dataLoader=(t,i)=>this.dataLoader(t,i),t.saveLoader=(t,s)=>this.saveLoader(s,i).then((t=>(t.length&&e(),t))),t.removeLoader=(t,s)=>this.removeLoader(t,s,i).then((t=>(t.length&&e(),t)))}dataLoader(t,i){return new Promise((e=>{this.loader(t,i).then((t=>{const i=((null==t?void 0:t.records)||[]).map((t=>{let i;return t.LINK||(i=[{name:t.NOMEARQUIVO}]),Object.assign(Object.assign({},t),{ARQUIVOOULINK:t.LINK?t.LINK:t.NOMEARQUIVO,NOMEARQUIVO:i})}));e(Object.assign(Object.assign({},t),{records:i}))}))}))}saveLoader(t,i){return new Promise((e=>{var s;const n=Array.isArray(t)?t[0]:{};((null===(s=null==n?void 0:n.record)||void 0===s?void 0:s.NUATTACH)>=0?i.edit.bind(i):i.save.bind(i))(n).then((t=>{e(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")),e([])):t.message===o.ANY_LINK_OR_FILE_FILLED?(this._application.alert(this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.title"),this.getMessage("snkAttach.alertValidation.anyLinkOrFileFilled.message")),e([])):t.message?(this._application.error(t.title||t.name,t.message),e([])):void e([])))}))}removeLoader(t,i,e){return new Promise((s=>{const{records:n}=t.getSelectionInfo();e.delete(n[0]).then((()=>s(i)))}))}getFilters(t){return[{name:"AttachmentsByPK",expression:"this.PKREGISTRO = :PKREGISTRO",params:[{name:"PKREGISTRO",dataType:n.TEXT,value:`${t}_${this.entityName}`}]}]}getInterceptions(t,i,e){return new Promise((s=>i.type===a.EDITION_CANCELED?t.isDirty()?this._application.confirm(this.getMessage("snkAttach.cancelConfirmation.title"),this.getMessage("snkAttach.cancelConfirmation.message")).then((t=>t?(e.goToView(h.GRID),s(i)):s(void 0))):s(i):i.type===a.DATA_SAVED?(t.loadData(),s(i)):void s(i)))}}const u=s.getContextValue("__SNK__APPLICATION__"),v=t=>{var i,e;return null===(e=null===(i=null==u?void 0:u.messagesBuilder)||void 0===i?void 0:i.getMessage)||void 0===e?void 0:e.call(i,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,i,e)=>{if((null==i?void 0:i.insertionMode)||(null==i?void 0:i.isDirty))return e.reverse();e.splice(e.indexOf(l.REFRESH),1);const{selectedRecord:s}=i||{},n=(null==s?void 0:s.LINK)?A.LINK:A.DOWNLOAD;e.splice(e.indexOf(l.DIVIDER)+1,0,l.REMOVE,n,l.DIVIDER);const a=Array.from(new Set(e.filter((t=>t!==l.CLONE))));return a.splice(a.indexOf(n)+1,0,l.DIVIDER),a},isEnabled:(i,e,s)=>{const n=void 0!==(null==e?void 0:e.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(e){t(this,e),this.back=i(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,i){var e;i!==t&&(this.returnToGridMode(),this._attachFetcher=new c(this.entityName,this.registerKey,null===(e=this.dataUnit)||void 0===e?void 0:e.name),this._dataUnitBuilder.initLoaders(this.dataUnit,this._attachFetcher,(()=>{this.returnToGridMode()})),this.dataUnit.loadData())}getMessage(t,i){if(this.messagesBuilder)return this.messagesBuilder.getMessage(t,i)}showFinishedToast(){this._application.info(this.getMessage("snkAttach.finishedMessage"),{iconName:"check"})}downloadAttachment(t){if(!t)throw new Error("Nenhum registro selecionado");t.LINK?window.open(`${t.LINK}`):this._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 i=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),i.metadata||i.loadMetadata().then((()=>{this.crudConfig=p})),this._dataUnitBuilder=new m(this.entityName,this.getMessage.bind(this)),i.addFilterProvider({getFilter:()=>this._dataUnitBuilder.getFilters(this.registerKey)}),i.addInterceptor({interceptAction:t=>this._dataUnitBuilder.getInterceptions(i,t,this._crudElement)}),this.dataUnit=i,this.dataUnit.loadData().then((()=>{this.disableEditFieldsNotInForm()})),this.dataUnit}catch(t){throw new Error("There was an error while creating the data unit")}}disableEditFieldsNotInForm(){var t;null===(t=this.crudConfig)||void 0===t||t.grid.columns.forEach((t=>{var i;const e=t.name;(null===(i=this.crudConfig)||void 0===i?void 0:i.form.fields.some((t=>t.name===e)))||this.dataUnit.disableField(e)}))}componentWillLoad(){this._application=s.getContextValue("__SNK__APPLICATION__"),this.loadAttachmentDataUnit()}render(){var t,i;return this.dataUnit?e("main",{class:"snk-attach__main"},e("header",{class:"snk-attach__header"},e("snk-simple-bar",{onExit:this.handleBack,messagesBuilder:this.messagesBuilder},e("div",{slot:"rightSlot"},e("ez-button",{class:"ez-button--primary",label:this.getMessage("snkAttach.finish"),onClick:this.handleFinish})))),e("div",{class:"snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column"},e("div",{class:"ez-box__container"},e("snk-simple-crud",{ref:t=>this._crudElement=t,dataUnit:this.dataUnit,taskbarManager:O(),gridConfig:null===(t=this.crudConfig)||void 0===t?void 0:t.grid,formConfig:null===(i=this.crudConfig)||void 0===i?void 0:i.form,useCancelConfirm:!1,onActionClick:this.handleTaskbarClick},e("div",{slot:"snkSimpleCrudHeader"},e("div",{class:"ez-flex ez-flex--column"},e("span",{class:"ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium"},this.getMessage("snkAttach.title")),e("span",{class:"ez-text ez-text--medium ez-text--secondary"},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}
|