@sankhyalabs/sankhyablocks 8.15.0-rc.16 → 8.15.0-rc.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/cjs/{SnkMultiSelectionListDataSource-1438f8f2.js → SnkMultiSelectionListDataSource-8b5bfa05.js} +1 -1
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/{pesquisa-fetcher-94f6b316.js → pesquisa-fetcher-036a9588.js} +40 -39
  4. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  5. package/dist/cjs/snk-actions-button_4.cjs.entry.js +1 -1
  6. package/dist/cjs/snk-application.cjs.entry.js +1 -1
  7. package/dist/cjs/snk-attach.cjs.entry.js +61 -40
  8. package/dist/cjs/snk-crud.cjs.entry.js +1 -1
  9. package/dist/cjs/snk-detail-view.cjs.entry.js +2 -2
  10. package/dist/cjs/snk-grid.cjs.entry.js +2 -2
  11. package/dist/cjs/{snk-guides-viewer-25721856.js → snk-guides-viewer-2f61fb02.js} +1 -1
  12. package/dist/cjs/snk-guides-viewer.cjs.entry.js +2 -2
  13. package/dist/cjs/snk-simple-crud.cjs.entry.js +9 -2
  14. package/dist/collection/components/snk-attach/snk-attach.js +39 -24
  15. package/dist/collection/components/snk-attach/structure/builder/attach-crud-config.builder.js +1 -1
  16. package/dist/collection/components/snk-attach/structure/fetcher/factory/attach-fetcher-data-unit.factory.js +29 -22
  17. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +24 -1
  18. package/dist/collection/lib/dataUnit/InMemoryLoader.js +6 -41
  19. package/dist/collection/lib/dataUnit/dataUnitInMemoryUtils.js +33 -0
  20. package/dist/components/dataunit-fetcher.js +38 -40
  21. package/dist/components/snk-attach2.js +61 -40
  22. package/dist/components/snk-simple-crud2.js +10 -2
  23. package/dist/esm/{SnkMultiSelectionListDataSource-aad5d4ff.js → SnkMultiSelectionListDataSource-4274be27.js} +1 -1
  24. package/dist/esm/loader.js +1 -1
  25. package/dist/esm/{pesquisa-fetcher-f05a12ca.js → pesquisa-fetcher-a9e27c84.js} +38 -40
  26. package/dist/esm/sankhyablocks.js +1 -1
  27. package/dist/esm/snk-actions-button_4.entry.js +1 -1
  28. package/dist/esm/snk-application.entry.js +1 -1
  29. package/dist/esm/snk-attach.entry.js +61 -40
  30. package/dist/esm/snk-crud.entry.js +1 -1
  31. package/dist/esm/snk-detail-view.entry.js +2 -2
  32. package/dist/esm/snk-grid.entry.js +2 -2
  33. package/dist/esm/{snk-guides-viewer-b94752f2.js → snk-guides-viewer-16974807.js} +1 -1
  34. package/dist/esm/snk-guides-viewer.entry.js +2 -2
  35. package/dist/esm/snk-simple-crud.entry.js +9 -2
  36. package/dist/sankhyablocks/{p-0bba5c9f.entry.js → p-1c7d57e5.entry.js} +1 -1
  37. package/dist/sankhyablocks/p-32331e9b.entry.js +1 -0
  38. package/dist/sankhyablocks/{p-6c9adfca.js → p-3f88728d.js} +1 -1
  39. package/dist/sankhyablocks/{p-85ba3d6b.entry.js → p-433f0d45.entry.js} +1 -1
  40. package/dist/sankhyablocks/{p-437316f2.entry.js → p-4ab95a67.entry.js} +1 -1
  41. package/dist/sankhyablocks/p-751bd42a.entry.js +1 -0
  42. package/dist/sankhyablocks/{p-48413484.entry.js → p-c6751382.entry.js} +3 -3
  43. package/dist/sankhyablocks/{p-d78d4062.js → p-d0126ca0.js} +3 -3
  44. package/dist/sankhyablocks/{p-a1642e7c.entry.js → p-d6321b12.entry.js} +1 -1
  45. package/dist/sankhyablocks/{p-d5cb4b5a.entry.js → p-dcce8ca0.entry.js} +1 -1
  46. package/dist/sankhyablocks/{p-88b29791.js → p-fbc60023.js} +1 -1
  47. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  48. package/dist/types/components/snk-attach/snk-attach.d.ts +2 -1
  49. package/dist/types/components/snk-attach/structure/builder/attach-crud-config.builder.d.ts +10 -1
  50. package/dist/types/components/snk-attach/structure/fetcher/factory/attach-fetcher-data-unit.factory.d.ts +5 -4
  51. package/dist/types/components/snk-simple-crud/snk-simple-crud.d.ts +1 -0
  52. package/dist/types/components.d.ts +1 -0
  53. package/dist/types/lib/dataUnit/InMemoryLoader.d.ts +0 -2
  54. package/dist/types/lib/dataUnit/dataUnitInMemoryUtils.d.ts +4 -0
  55. package/package.json +1 -1
  56. package/dist/sankhyablocks/p-9e8618ec.entry.js +0 -1
  57. package/dist/sankhyablocks/p-d8113b2f.entry.js +0 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const snkGuidesViewer = require('./snk-guides-viewer-25721856.js');
5
+ const snkGuidesViewer = require('./snk-guides-viewer-2f61fb02.js');
6
6
  require('./index-f9e81701.js');
7
7
  require('@sankhyalabs/core');
8
8
  require('./SnkFormConfigManager-33995e92.js');
@@ -18,7 +18,7 @@ require('./taskbar-elements-3ecd1278.js');
18
18
  require('./index-0922807b.js');
19
19
  require('./index-102ba62d.js');
20
20
  require('./constants-35ddd366.js');
21
- require('./pesquisa-fetcher-94f6b316.js');
21
+ require('./pesquisa-fetcher-036a9588.js');
22
22
  require('@sankhyalabs/ezui/dist/collection/utils/constants');
23
23
  require('@sankhyalabs/ezui/dist/collection/components/ez-grid/utils');
24
24
  require('./ResourceIDUtils-5ff86aa7.js');
@@ -8,8 +8,8 @@ const utils = require('@sankhyalabs/ezui/dist/collection/utils');
8
8
  const constants = require('./constants-35ddd366.js');
9
9
  const taskbarElements = require('./taskbar-elements-3ecd1278.js');
10
10
  require('./DataFetcher-99f0f6ed.js');
11
- const pesquisaFetcher = require('./pesquisa-fetcher-94f6b316.js');
12
- const SnkMultiSelectionListDataSource = require('./SnkMultiSelectionListDataSource-1438f8f2.js');
11
+ const pesquisaFetcher = require('./pesquisa-fetcher-036a9588.js');
12
+ const SnkMultiSelectionListDataSource = require('./SnkMultiSelectionListDataSource-8b5bfa05.js');
13
13
  const index$1 = require('./index-0922807b.js');
14
14
  require('./ISave-e91b70a7.js');
15
15
  require('@sankhyalabs/ezui/dist/collection/utils/constants');
@@ -313,6 +313,13 @@ const SnkSimpleCrud = class {
313
313
  var _a;
314
314
  (_a = this._snkConfigurator) === null || _a === void 0 ? void 0 : _a.close();
315
315
  }
316
+ updateConfig() {
317
+ if (this._formConfigManager == undefined) {
318
+ this._formConfigManager = new SnkFormConfigManager.SnkFormConfigManager(this.configName, this.resolveResourceID());
319
+ }
320
+ this._formConfigManager.setConfig(this.formConfig);
321
+ return;
322
+ }
316
323
  processMetadata() {
317
324
  const fieldsMetadataElem = this._element.querySelectorAll("snk-field-metadata");
318
325
  const fieldMetadata = [];
@@ -1,8 +1,9 @@
1
1
  import { h } from "@stencil/core";
2
- import { DataUnit, ApplicationContext } from "@sankhyalabs/core";
2
+ import { DataUnit, ApplicationContext, Action } from "@sankhyalabs/core";
3
3
  import { AnexoSistemaFetcher, AttachFetcher, DataUnitFetcher } from "../../lib";
4
4
  import { VIEW_MODE } from "../../lib/utils/constants";
5
5
  import { AnexoSistemaDataUnitFactory, AttachFetcherDataUnitFactory, buildTaskBarManager, anexoSistemaCrudConfig, attachCrudConfig } from "./structure";
6
+ import InMemoryLoader from "../../lib/dataUnit/InMemoryLoader";
6
7
  const RESOURCE_ID = 'AnexoSistema';
7
8
  const DATA_UNIT_NAME = 'br.com.sankhya.core.v3.anexoSistema';
8
9
  export class SnkAttach {
@@ -28,7 +29,7 @@ export class SnkAttach {
28
29
  this.back.emit();
29
30
  });
30
31
  };
31
- this.fetcherType = "AnexoSistema";
32
+ this.fetcherType = undefined;
32
33
  this.fetcher = undefined;
33
34
  this.dataUnit = undefined;
34
35
  this.dataUnitBuilder = undefined;
@@ -40,8 +41,8 @@ export class SnkAttach {
40
41
  this.crudConfig = undefined;
41
42
  }
42
43
  registerKeyWatcher(newRegisterKey, oldRegisterKey) {
43
- var _a, _b, _c, _d;
44
- if (this._currentDataUnit == null) {
44
+ var _a, _b, _c, _d, _e, _f;
45
+ if (!this._currentDataUnit) {
45
46
  this.loadAttachmentDataUnit();
46
47
  }
47
48
  if (oldRegisterKey !== newRegisterKey) {
@@ -56,11 +57,7 @@ export class SnkAttach {
56
57
  if (hasMoreOneItem)
57
58
  return;
58
59
  }
59
- return this._currentDataUnit
60
- .loadMetadata()
61
- .then(() => {
62
- this._currentDataUnit.loadData(undefined, undefined, true, this.registerKey);
63
- });
60
+ return (_f = (_e = this._currentDataUnit) === null || _e === void 0 ? void 0 : _e.loadMetadata()) === null || _f === void 0 ? void 0 : _f.then(this._currentDataUnit.loadData.bind(undefined, undefined, true, this.registerKey));
64
61
  }
65
62
  }
66
63
  /**
@@ -126,7 +123,7 @@ export class SnkAttach {
126
123
  if (!this._currentDataUnit.metadata) {
127
124
  this._currentDataUnit
128
125
  .loadMetadata()
129
- .then(() => this.crudConfig = anexoSistemaCrudConfig);
126
+ .then(() => this.crudConfig = Object.assign({}, anexoSistemaCrudConfig));
130
127
  }
131
128
  this._currentDataUnitBuilder = new AnexoSistemaDataUnitFactory(this.entityName, this.getMessage.bind(this));
132
129
  this._currentDataUnit.addFilterProvider({
@@ -138,25 +135,29 @@ export class SnkAttach {
138
135
  this._currentDataUnit.loadData().then(this.disableEditFieldsNotInForm.bind(this));
139
136
  }
140
137
  loadAttach() {
141
- var _a;
138
+ var _a, _b, _c;
142
139
  this._currentFetcher = new AttachFetcher();
143
- this._currentDataUnit = new DataUnit();
140
+ this._currentDataUnit = new DataUnit(InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME);
144
141
  this._currentDataUnit.addInterceptor({
145
- interceptAction: (action) => this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit, action, this._crudElement)
142
+ interceptAction: (action) => {
143
+ var _a;
144
+ if (action.type === Action.METADATA_LOADED) {
145
+ this.crudConfig = Object.assign({}, attachCrudConfig);
146
+ (_a = this._crudElement) === null || _a === void 0 ? void 0 : _a.updateConfig();
147
+ }
148
+ return this._currentDataUnitBuilder.getInterceptions(this._currentDataUnit, action, this._crudElement);
149
+ }
146
150
  });
147
151
  this._currentDataUnitBuilder = new AttachFetcherDataUnitFactory(this.getMessage.bind(this));
148
152
  (_a = this._currentDataUnitBuilder) === null || _a === void 0 ? void 0 : _a.initLoaders(this._currentDataUnit, this._currentFetcher, async () => {
149
- await this._currentDataUnit.loadData(undefined, undefined, true, this.registerKey);
150
153
  this.returnToGridMode();
154
+ await this._currentDataUnit.loadData(undefined, undefined, true, this.registerKey);
151
155
  });
152
156
  if (!this._currentDataUnit.metadata) {
153
- this._currentDataUnit
154
- .loadMetadata()
155
- .then(() => {
156
- this.crudConfig = attachCrudConfig;
157
- this._currentDataUnit
158
- .loadData(undefined, undefined, true, this.registerKey)
159
- .then(this.disableEditFieldsNotInForm.bind(this));
157
+ (_c = (_b = this._currentDataUnit) === null || _b === void 0 ? void 0 : _b.loadMetadata()) === null || _c === void 0 ? void 0 : _c.then(() => {
158
+ var _a, _b;
159
+ this.crudConfig = Object.assign({}, attachCrudConfig);
160
+ (_b = (_a = this._currentDataUnit) === null || _a === void 0 ? void 0 : _a.loadData(undefined, undefined, true, this.registerKey)) === null || _b === void 0 ? void 0 : _b.then(this.disableEditFieldsNotInForm.bind(this));
160
161
  });
161
162
  }
162
163
  }
@@ -174,15 +175,30 @@ export class SnkAttach {
174
175
  this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
175
176
  }
176
177
  componentWillRender() {
178
+ if (!this.fetcherType) {
179
+ this.fetcherType = "AnexoSistema";
180
+ }
177
181
  if (this._currentDataUnit == null) {
178
182
  this.loadAttachmentDataUnit();
179
183
  }
180
184
  }
185
+ async handleOnDataStateChange({ detail }) {
186
+ if (this.fetcherType !== 'Attach')
187
+ return;
188
+ if (!detail.insertionMode) {
189
+ this._currentDataUnit.disableField('DESCRICAO');
190
+ }
191
+ else {
192
+ this._currentDataUnit.enableField('DESCRICAO');
193
+ }
194
+ await this._currentDataUnit.loadMetadata();
195
+ }
196
+ ;
181
197
  render() {
182
198
  var _a, _b;
183
199
  if (!this._currentDataUnit)
184
200
  return null;
185
- return (h("main", { class: "snk-attach__main" }, h("header", { class: "snk-attach__header" }, h("snk-simple-bar", { onExit: this.handleBack, messagesBuilder: this.messagesBuilder }, h("div", { slot: "rightSlot" }, h("ez-button", { class: "ez-button--primary", label: this.getMessage("snkAttach.finish"), onClick: this.handleFinish })))), h("div", { class: "snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column" }, h("div", { class: "ez-box__container" }, h("snk-simple-crud", { ref: (el) => this._crudElement = el, dataUnit: this._currentDataUnit, taskbarManager: buildTaskBarManager(), gridConfig: (_a = this.crudConfig) === null || _a === void 0 ? void 0 : _a.grid, formConfig: (_b = this.crudConfig) === null || _b === void 0 ? void 0 : _b.form, useCancelConfirm: false, onActionClick: this.handleTaskbarClick, messagesBuilder: this.messagesBuilder }, h("div", { slot: "snkSimpleCrudHeader" }, h("div", { class: "ez-flex ez-flex--column" }, h("span", { class: "ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium" }, this.getMessage("snkAttach.title")), h("span", { class: "ez-text ez-text--medium ez-text--secondary" }, this.getMessage("snkAttach.description")))))))));
201
+ return (h("main", { class: "snk-attach__main" }, h("header", { class: "snk-attach__header" }, h("snk-simple-bar", { onExit: this.handleBack, messagesBuilder: this.messagesBuilder }, h("div", { slot: "rightSlot" }, h("ez-button", { class: "ez-button--primary", label: this.getMessage("snkAttach.finish"), onClick: this.handleFinish })))), h("div", { class: "snk-attach__crud-section ez-size-height--full ez-size-width--full ez-flex ez-flex--column" }, h("div", { class: "ez-box__container" }, h("snk-simple-crud", { ref: (el) => this._crudElement = el, dataUnit: this._currentDataUnit, taskbarManager: buildTaskBarManager(), gridConfig: (_a = this.crudConfig) === null || _a === void 0 ? void 0 : _a.grid, formConfig: (_b = this.crudConfig) === null || _b === void 0 ? void 0 : _b.form, useCancelConfirm: false, onActionClick: this.handleTaskbarClick, messagesBuilder: this.messagesBuilder, onDataStateChange: this.handleOnDataStateChange.bind(this) }, h("div", { slot: "snkSimpleCrudHeader" }, h("div", { class: "ez-flex ez-flex--column" }, h("span", { class: "ez-title--primary ez-text ez-text--large ez-text--bold ez-padding-bottom--medium" }, this.getMessage("snkAttach.title")), h("span", { class: "ez-text ez-text--medium ez-text--secondary" }, this.getMessage("snkAttach.description")))))))));
186
202
  }
187
203
  static get is() { return "snk-attach"; }
188
204
  static get encapsulation() { return "scoped"; }
@@ -218,8 +234,7 @@ export class SnkAttach {
218
234
  "text": "FetcherType define o tipo de fetcher respons\u00E1vel por carregar os dados do DataUnit."
219
235
  },
220
236
  "attribute": "fetcher-type",
221
- "reflect": false,
222
- "defaultValue": "\"AnexoSistema\""
237
+ "reflect": false
223
238
  },
224
239
  "fetcher": {
225
240
  "type": "unknown",
@@ -39,7 +39,7 @@ export const attachFetcherMetadataBuilder = {
39
39
  label: "Attach List",
40
40
  fields: [
41
41
  { name: "CODATA", label: getMessage("snkAttach.attachMetadata.lblCode"), dataType: DataType.TEXT },
42
- { name: "DESCRICAO", label: getMessage("snkAttach.attachMetadata.lblDescription"), dataType: DataType.TEXT },
42
+ { name: "DESCRICAO", label: getMessage("snkAttach.attachMetadata.lblDescription"), dataType: DataType.TEXT, readOnly: false },
43
43
  { name: "ARQUIVO", label: getMessage("snkAttach.attachMetadata.lblFileOrLink"), dataType: DataType.TEXT },
44
44
  { name: "USUARIO", label: getMessage("snkAttach.attachMetadata.lblUser"), dataType: DataType.TEXT },
45
45
  { name: "DTALTER", label: getMessage("snkAttach.attachMetadata.lblDate"), dataType: DataType.TEXT },
@@ -1,12 +1,14 @@
1
- import { Action, ApplicationContext, StringUtils } from "@sankhyalabs/core";
2
- import { SaveErrorsEnum } from "../../../../../lib/http/data-fetcher/fetchers/AttachFetcher/interfaces";
3
- import { AutorizationType } from "../../../../../lib/http/data-fetcher/fetchers/auth-fetcher";
4
- import { attachFetcherMetadataBuilder } from "../../builder/attach-crud-config.builder";
5
- import { VIEW_MODE } from "../../../../../lib/utils/constants";
1
+ import { Action, ApplicationContext, StringUtils, } from '@sankhyalabs/core';
2
+ import { SaveErrorsEnum } from '../../../../../lib/http/data-fetcher/fetchers/AttachFetcher/interfaces';
3
+ import { AutorizationType } from '../../../../../lib/http/data-fetcher/fetchers/auth-fetcher';
4
+ import { attachFetcherMetadataBuilder } from '../../builder/attach-crud-config.builder';
5
+ import { VIEW_MODE } from '../../../../../lib/utils/constants';
6
+ import { applyFilter, applySorting, buildPaginationInfo } from '../../../../../lib/dataUnit/dataUnitInMemoryUtils';
6
7
  const SERVICE_LOAD = "Attach.load";
7
8
  export class AttachFetcherDataUnitFactory {
8
9
  constructor(getMessage) {
9
10
  this.getMessage = getMessage;
11
+ this._records = [];
10
12
  this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
11
13
  }
12
14
  initLoaders(dataUnit, fetcher, onSuccess) {
@@ -26,25 +28,30 @@ export class AttachFetcherDataUnitFactory {
26
28
  metadataLoader(_) {
27
29
  return Promise.resolve(attachFetcherMetadataBuilder);
28
30
  }
29
- async dataLoader(_, request) {
31
+ async dataLoader(dataUnit, request) {
30
32
  if (!request.source) {
31
- return Promise.resolve({ records: [] });
33
+ return Promise.resolve({ records: this._records });
32
34
  }
33
- const criteria = {
34
- criteria: {
35
- codata: request.source,
36
- tipoAnexo: "N"
37
- }
38
- };
39
- const applicationDataFetcher = await this._application.getDataFetcher();
40
- const { anexos: { anexo = [] } } = await applicationDataFetcher.callServiceBroker(SERVICE_LOAD, JSON.stringify(criteria));
41
- const records = [];
42
- anexo.forEach((param) => {
43
- records.push(Object.assign({ __record__id__: StringUtils.generateUUID(), CAMINHO_ARQUIVO: [{
44
- name: param === null || param === void 0 ? void 0 : param.ARQUIVO,
45
- }] }, param));
46
- });
47
- return Promise.resolve({ records });
35
+ if (!Number.isNaN(Number(request.source))) {
36
+ const criteria = {
37
+ criteria: {
38
+ codata: request.source,
39
+ tipoAnexo: "N"
40
+ }
41
+ };
42
+ const applicationDataFetcher = await this._application.getDataFetcher();
43
+ const { anexos: { anexo = [] } } = await applicationDataFetcher.callServiceBroker(SERVICE_LOAD, JSON.stringify(criteria));
44
+ const records = [];
45
+ anexo.forEach((param) => {
46
+ records.push(Object.assign({ __record__id__: StringUtils.generateUUID(), CAMINHO_ARQUIVO: [{
47
+ name: param === null || param === void 0 ? void 0 : param.ARQUIVO,
48
+ }] }, param));
49
+ });
50
+ this._records = records;
51
+ }
52
+ let records = applyFilter(this._records, dataUnit, request.filters);
53
+ records = applySorting(records, dataUnit, request.sort);
54
+ return Promise.resolve({ records, paginationInfo: buildPaginationInfo(records, request.offset, request.limit) });
48
55
  }
49
56
  saveLoader(changes, fetcher) {
50
57
  return new Promise((resolve) => {
@@ -287,6 +287,13 @@ export class SnkSimpleCrud {
287
287
  var _a;
288
288
  (_a = this._snkConfigurator) === null || _a === void 0 ? void 0 : _a.close();
289
289
  }
290
+ updateConfig() {
291
+ if (this._formConfigManager == undefined) {
292
+ this._formConfigManager = new SnkFormConfigManager(this.configName, this.resolveResourceID());
293
+ }
294
+ this._formConfigManager.setConfig(this.formConfig);
295
+ return;
296
+ }
290
297
  processMetadata() {
291
298
  const fieldsMetadataElem = this._element.querySelectorAll("snk-field-metadata");
292
299
  const fieldMetadata = [];
@@ -609,7 +616,7 @@ export class SnkSimpleCrud {
609
616
  },
610
617
  "formConfig": {
611
618
  "type": "unknown",
612
- "mutable": false,
619
+ "mutable": true,
613
620
  "complexType": {
614
621
  "original": "IFormConfig",
615
622
  "resolved": "IFormConfig",
@@ -1097,6 +1104,22 @@ export class SnkSimpleCrud {
1097
1104
  "text": "Usado para fechar o configurator do CRUD",
1098
1105
  "tags": []
1099
1106
  }
1107
+ },
1108
+ "updateConfig": {
1109
+ "complexType": {
1110
+ "signature": "() => Promise<void>",
1111
+ "parameters": [],
1112
+ "references": {
1113
+ "Promise": {
1114
+ "location": "global"
1115
+ }
1116
+ },
1117
+ "return": "Promise<void>"
1118
+ },
1119
+ "docs": {
1120
+ "text": "",
1121
+ "tags": []
1122
+ }
1100
1123
  }
1101
1124
  };
1102
1125
  }
@@ -1,6 +1,5 @@
1
1
  import { ChangeOperation, DataType, DataUnit, DateUtils, StringUtils, } from '@sankhyalabs/core';
2
- import { ColumnFilterManager } from "@sankhyalabs/ezui/dist/collection/components/ez-grid/utils";
3
- import PreloadManager from '../http/data-fetcher/fetchers/data-unit/cache/PreloadManager';
2
+ import { applyFilter, applySorting, buildPaginationInfo } from './dataUnitInMemoryUtils';
4
3
  export default class InMemoryLoader {
5
4
  constructor(metadata, records) {
6
5
  this.metadata = metadata;
@@ -13,10 +12,10 @@ export default class InMemoryLoader {
13
12
  this.dataUnit.loadMetadata().then(() => this.dataUnit.loadData());
14
13
  }
15
14
  getRecordsToLoad() {
16
- if (this._initialRecords == undefined || this.dataUnit.records.length > 0) {
15
+ if (this._initialRecords == undefined && this.dataUnit.records.length > 0) {
17
16
  this._initialRecords = this.dataUnit.records;
18
17
  }
19
- return this._initialRecords;
18
+ return [...this._initialRecords, ...this.dataUnit.getAddedRecords()];
20
19
  }
21
20
  get dataUnit() {
22
21
  return this._dataUnit;
@@ -74,30 +73,9 @@ export default class InMemoryLoader {
74
73
  return StringUtils.generateUUID();
75
74
  }
76
75
  inMemoryLoader(dataUnit, request, recordsIn) {
77
- let records = this.applyFilter(recordsIn, dataUnit, request.filters);
78
- records = this.applySorting(records, dataUnit, request.sort);
79
- return Promise.resolve({ records, paginationInfo: buildPaginationInfo(request, records) });
80
- }
81
- applyFilter(records, dataUnit, filters) {
82
- const columnFilters = ColumnFilterManager.getColumnFilters(filters, "");
83
- if (columnFilters == undefined || columnFilters.size == 0) {
84
- return records;
85
- }
86
- const filterFunciton = ColumnFilterManager.getFilterFunction(dataUnit, Array.from(columnFilters.values()));
87
- if (filterFunciton == undefined) {
88
- return records;
89
- }
90
- return records.filter(filterFunciton);
91
- }
92
- applySorting(records, dataUnit, sorting) {
93
- if (sorting == undefined || sorting.length == 0) {
94
- return records;
95
- }
96
- const sortingFunction = PreloadManager.getSortingFunction(dataUnit, sorting);
97
- if (sortingFunction == undefined) {
98
- return records;
99
- }
100
- return records.sort(sortingFunction);
76
+ let records = applyFilter(recordsIn, dataUnit, request.filters);
77
+ records = applySorting(records, dataUnit, request.sort);
78
+ return Promise.resolve({ records, paginationInfo: buildPaginationInfo(records, request.offset, request.limit) });
101
79
  }
102
80
  metadaLoader() {
103
81
  return Promise.resolve(this._metadata);
@@ -130,16 +108,3 @@ export default class InMemoryLoader {
130
108
  }
131
109
  }
132
110
  InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME = "InMemoryDataUnit";
133
- function buildPaginationInfo({ offset, limit }, records) {
134
- if (offset === undefined || limit === undefined) {
135
- return undefined;
136
- }
137
- const lastRecord = Math.min(offset + limit, records.length);
138
- return {
139
- currentPage: Math.ceil(offset / limit),
140
- firstRecord: offset,
141
- lastRecord: lastRecord,
142
- total: records.length,
143
- hasMore: !!(records.length - lastRecord),
144
- };
145
- }
@@ -0,0 +1,33 @@
1
+ import { ColumnFilterManager } from '@sankhyalabs/ezui/dist/collection/components/ez-grid/utils';
2
+ import PreloadManager from '../http/data-fetcher/fetchers/data-unit/cache/PreloadManager';
3
+ export function applyFilter(records, dataUnit, filters) {
4
+ const columnFilters = ColumnFilterManager.getColumnFilters(filters, "");
5
+ if (!(columnFilters === null || columnFilters === void 0 ? void 0 : columnFilters.size)) {
6
+ return records;
7
+ }
8
+ const filterFunction = ColumnFilterManager.getFilterFunction(dataUnit, Array.from(columnFilters.values()));
9
+ if (filterFunction == undefined) {
10
+ return records;
11
+ }
12
+ return records.filter(filterFunction);
13
+ }
14
+ export function applySorting(records, dataUnit, sorting) {
15
+ if (sorting == undefined || sorting.length == 0) {
16
+ return records;
17
+ }
18
+ const sortingFunction = PreloadManager.getSortingFunction(dataUnit, sorting);
19
+ if (sortingFunction == undefined) {
20
+ return records;
21
+ }
22
+ return records.sort(sortingFunction);
23
+ }
24
+ export function buildPaginationInfo(records, offset = 0, limit = 0) {
25
+ const lastRecord = Math.min(offset + limit, records.length);
26
+ return {
27
+ currentPage: limit === 0 ? 0 : Math.ceil(offset / limit),
28
+ firstRecord: offset,
29
+ lastRecord: lastRecord,
30
+ total: records.length,
31
+ hasMore: !!(records.length - lastRecord),
32
+ };
33
+ }
@@ -383,6 +383,38 @@ class PreloadManager {
383
383
  PreloadManager._repositories = new Map();
384
384
  PreloadManager._loadingStatus = new Map();
385
385
 
386
+ function applyFilter(records, dataUnit, filters) {
387
+ const columnFilters = ColumnFilterManager.getColumnFilters(filters, "");
388
+ if (!(columnFilters === null || columnFilters === void 0 ? void 0 : columnFilters.size)) {
389
+ return records;
390
+ }
391
+ const filterFunction = ColumnFilterManager.getFilterFunction(dataUnit, Array.from(columnFilters.values()));
392
+ if (filterFunction == undefined) {
393
+ return records;
394
+ }
395
+ return records.filter(filterFunction);
396
+ }
397
+ function applySorting(records, dataUnit, sorting) {
398
+ if (sorting == undefined || sorting.length == 0) {
399
+ return records;
400
+ }
401
+ const sortingFunction = PreloadManager.getSortingFunction(dataUnit, sorting);
402
+ if (sortingFunction == undefined) {
403
+ return records;
404
+ }
405
+ return records.sort(sortingFunction);
406
+ }
407
+ function buildPaginationInfo(records, offset = 0, limit = 0) {
408
+ const lastRecord = Math.min(offset + limit, records.length);
409
+ return {
410
+ currentPage: limit === 0 ? 0 : Math.ceil(offset / limit),
411
+ firstRecord: offset,
412
+ lastRecord: lastRecord,
413
+ total: records.length,
414
+ hasMore: !!(records.length - lastRecord),
415
+ };
416
+ }
417
+
386
418
  class InMemoryLoader {
387
419
  constructor(metadata, records) {
388
420
  this.metadata = metadata;
@@ -395,10 +427,10 @@ class InMemoryLoader {
395
427
  this.dataUnit.loadMetadata().then(() => this.dataUnit.loadData());
396
428
  }
397
429
  getRecordsToLoad() {
398
- if (this._initialRecords == undefined || this.dataUnit.records.length > 0) {
430
+ if (this._initialRecords == undefined && this.dataUnit.records.length > 0) {
399
431
  this._initialRecords = this.dataUnit.records;
400
432
  }
401
- return this._initialRecords;
433
+ return [...this._initialRecords, ...this.dataUnit.getAddedRecords()];
402
434
  }
403
435
  get dataUnit() {
404
436
  return this._dataUnit;
@@ -456,30 +488,9 @@ class InMemoryLoader {
456
488
  return StringUtils.generateUUID();
457
489
  }
458
490
  inMemoryLoader(dataUnit, request, recordsIn) {
459
- let records = this.applyFilter(recordsIn, dataUnit, request.filters);
460
- records = this.applySorting(records, dataUnit, request.sort);
461
- return Promise.resolve({ records, paginationInfo: buildPaginationInfo(request, records) });
462
- }
463
- applyFilter(records, dataUnit, filters) {
464
- const columnFilters = ColumnFilterManager.getColumnFilters(filters, "");
465
- if (columnFilters == undefined || columnFilters.size == 0) {
466
- return records;
467
- }
468
- const filterFunciton = ColumnFilterManager.getFilterFunction(dataUnit, Array.from(columnFilters.values()));
469
- if (filterFunciton == undefined) {
470
- return records;
471
- }
472
- return records.filter(filterFunciton);
473
- }
474
- applySorting(records, dataUnit, sorting) {
475
- if (sorting == undefined || sorting.length == 0) {
476
- return records;
477
- }
478
- const sortingFunction = PreloadManager.getSortingFunction(dataUnit, sorting);
479
- if (sortingFunction == undefined) {
480
- return records;
481
- }
482
- return records.sort(sortingFunction);
491
+ let records = applyFilter(recordsIn, dataUnit, request.filters);
492
+ records = applySorting(records, dataUnit, request.sort);
493
+ return Promise.resolve({ records, paginationInfo: buildPaginationInfo(records, request.offset, request.limit) });
483
494
  }
484
495
  metadaLoader() {
485
496
  return Promise.resolve(this._metadata);
@@ -512,19 +523,6 @@ class InMemoryLoader {
512
523
  }
513
524
  }
514
525
  InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME = "InMemoryDataUnit";
515
- function buildPaginationInfo({ offset, limit }, records) {
516
- if (offset === undefined || limit === undefined) {
517
- return undefined;
518
- }
519
- const lastRecord = Math.min(offset + limit, records.length);
520
- return {
521
- currentPage: Math.ceil(offset / limit),
522
- firstRecord: offset,
523
- lastRecord: lastRecord,
524
- total: records.length,
525
- hasMore: !!(records.length - lastRecord),
526
- };
527
- }
528
526
 
529
527
  class DatasetStrategy {
530
528
  canSlice() {
@@ -1143,4 +1141,4 @@ class DataUnitFetcher {
1143
1141
  }
1144
1142
  }
1145
1143
 
1146
- export { DataUnitFetcher as D, InMemoryLoader as I, PesquisaFetcher as P, PreloadManager as a };
1144
+ export { DataUnitFetcher as D, InMemoryLoader as I, PesquisaFetcher as P, PreloadManager as a, applyFilter as b, applySorting as c, buildPaginationInfo as d };