@sankhyalabs/ezui 1.1.119 → 1.1.122

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 (42) hide show
  1. package/dist/cjs/ez-button.cjs.entry.js +1 -1
  2. package/dist/cjs/ez-form.cjs.entry.js +59 -15
  3. package/dist/cjs/ez-grid.cjs.entry.js +45 -12
  4. package/dist/cjs/ez-upload.cjs.entry.js +10 -3
  5. package/dist/cjs/ezui.cjs.js +1 -1
  6. package/dist/cjs/loader.cjs.js +1 -1
  7. package/dist/cjs/test-du.cjs.entry.js +39 -46
  8. package/dist/collection/components/ez-button/ez-button.css +23 -1
  9. package/dist/collection/components/ez-form/DataBinder.js +59 -15
  10. package/dist/collection/components/ez-form/fieldbuilder/tpl/FileInput.tpl.js +1 -1
  11. package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +27 -9
  12. package/dist/collection/components/ez-grid/controller/ag-grid/DataSource.js +6 -3
  13. package/dist/collection/components/ez-grid/ez-grid.js +47 -0
  14. package/dist/collection/components/ez-upload/ez-upload.js +29 -3
  15. package/dist/collection/components/test-du/test-du.js +47 -48
  16. package/dist/custom-elements/index.js +155 -79
  17. package/dist/esm/ez-button.entry.js +1 -1
  18. package/dist/esm/ez-form.entry.js +60 -16
  19. package/dist/esm/ez-grid.entry.js +45 -12
  20. package/dist/esm/ez-upload.entry.js +10 -3
  21. package/dist/esm/ezui.js +1 -1
  22. package/dist/esm/loader.js +1 -1
  23. package/dist/esm/test-du.entry.js +40 -47
  24. package/dist/ezui/ezui.esm.js +1 -1
  25. package/dist/ezui/p-68c509a7.entry.js +1 -0
  26. package/dist/ezui/p-8793a124.entry.js +1 -0
  27. package/dist/ezui/p-a6e28794.entry.js +1 -0
  28. package/dist/ezui/{p-3cd17150.entry.js → p-c86cd69e.entry.js} +1 -1
  29. package/dist/ezui/p-cdafca02.entry.js +1 -0
  30. package/dist/types/components/ez-form/DataBinder.d.ts +2 -0
  31. package/dist/types/components/ez-grid/controller/EzGridController.d.ts +6 -2
  32. package/dist/types/components/ez-grid/controller/ag-grid/AgGridController.d.ts +5 -2
  33. package/dist/types/components/ez-grid/controller/ag-grid/DataSource.d.ts +2 -0
  34. package/dist/types/components/ez-grid/ez-grid.d.ts +8 -0
  35. package/dist/types/components/ez-upload/ez-upload.d.ts +5 -0
  36. package/dist/types/components/test-du/test-du.d.ts +2 -0
  37. package/dist/types/components.d.ts +13 -1
  38. package/package.json +3 -2
  39. package/dist/ezui/p-126d33e2.entry.js +0 -1
  40. package/dist/ezui/p-1339fde7.entry.js +0 -1
  41. package/dist/ezui/p-73d3f767.entry.js +0 -1
  42. package/dist/ezui/p-c13353f1.entry.js +0 -1
@@ -1,32 +1,58 @@
1
- import { ApplicationContext } from "@sankhyalabs/core";
1
+ import { ApplicationContext, Action } from "@sankhyalabs/core";
2
2
  export default class DataBinder {
3
3
  constructor(dataUnit) {
4
4
  this._fields = new Map();
5
5
  this._dataUnit = dataUnit;
6
- this._dataUnit.subscribe(_action => {
6
+ this._dataUnit.subscribe(action => {
7
7
  var _a;
8
- (_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
9
- this.updateValue(field.fieldName, field.field);
10
- });
8
+ switch (action.type) {
9
+ case Action.DATA_LOADED:
10
+ case Action.DATA_SAVED:
11
+ case Action.RECORDS_REMOVED:
12
+ case Action.RECORDS_ADDED:
13
+ case Action.RECORDS_COPIED:
14
+ case Action.DATA_CHANGED:
15
+ case Action.EDITION_CANCELED:
16
+ case Action.CHANGE_UNDONE:
17
+ case Action.CHANGE_REDONE:
18
+ case Action.SELECTION_CHANGED:
19
+ case Action.NEXT_SELECTED:
20
+ case Action.PREVIOUS_SELECTED:
21
+ (_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
22
+ this.updateValue(field.fieldName, field.field);
23
+ });
24
+ break;
25
+ }
11
26
  });
12
27
  }
13
28
  bind(fields) {
14
29
  fields.forEach(fieldElement => {
15
30
  const fieldName = fieldElement.dataset.fieldName;
16
31
  this.updateBind(fieldName, fieldElement);
17
- this.updateValue(fieldName, fieldElement);
18
32
  });
19
33
  }
20
34
  updateValue(fieldName, field) {
21
- field["value"] = this._dataUnit.getFieldValue(fieldName);
35
+ const oldValue = field["value"];
36
+ const newValue = this._dataUnit.getFieldValue(fieldName);
37
+ if (oldValue != newValue) {
38
+ field["value"] = newValue;
39
+ }
22
40
  }
23
41
  updateBind(fieldName, field) {
24
42
  const oldBind = this._fields.get(fieldName);
25
43
  if (oldBind) {
26
44
  oldBind.destroy();
27
45
  }
28
- this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
46
+ field["value"] = this._dataUnit.getFieldValue(fieldName);
47
+ this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, waitingChange) => this.changeStarted(fieldName, waitingChange), (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
29
48
  this.bindSearchOptionsLoader(fieldName, field);
49
+ this.applyEzUploadContext(fieldName, field);
50
+ }
51
+ changeStarted(fieldName, waitingChange) {
52
+ if (this._dataUnit.records.length === 0) {
53
+ this._dataUnit.addRecord();
54
+ }
55
+ this._dataUnit.startChange(fieldName, waitingChange);
30
56
  }
31
57
  setFieldValue(fieldName, newValue) {
32
58
  if (this._dataUnit.records.length === 0) {
@@ -44,19 +70,37 @@ export default class DataBinder {
44
70
  }
45
71
  }
46
72
  }
73
+ applyEzUploadContext(fieldName, field) {
74
+ var _a, _b;
75
+ if (field.nodeName === "EZ-UPLOAD") {
76
+ field["urlUpload"] = ApplicationContext.getContextValue("__EZUI__UPLOAD__ADD__URL__");
77
+ field["urlDelete"] = ApplicationContext.getContextValue("__EZUI__UPLOAD__DEL__URL__");
78
+ const descriptor = this._dataUnit.getField(fieldName);
79
+ const destination = (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.DESTINATION;
80
+ if (destination) {
81
+ field["requestHeaders"] = { XTRAINF: `{"destination": "${destination}"}` };
82
+ }
83
+ field["maxFiles"] = ((_b = descriptor.properties) === null || _b === void 0 ? void 0 : _b.MAX_FILES) || 0;
84
+ }
85
+ }
47
86
  }
48
87
  class Bind {
88
+ constructor() {
89
+ this.startChangeEventName = "ezStartChange";
90
+ this.changeEventName = "ezChange";
91
+ }
49
92
  destroy() {
50
- this.field.removeEventListener(this.eventName, this.eventListener);
93
+ this.field.removeEventListener(this.startChangeEventName, this.startChangeListener);
94
+ this.field.removeEventListener(this.changeEventName, this.changeListener);
51
95
  }
52
- static create(fieldName, field, callback) {
96
+ static create(fieldName, field, startChangeCallback, changeCallback) {
53
97
  const b = new Bind();
54
- b.fieldName = fieldName;
55
98
  b.field = field;
56
- //FIXME: Verificar se o field é um EzField
57
- b.eventListener = (evt) => { callback(fieldName, evt.detail); };
58
- b.eventName = "ezChange";
59
- b.field.addEventListener(b.eventName, b.eventListener);
99
+ b.fieldName = fieldName;
100
+ b.startChangeListener = (evt) => { startChangeCallback(fieldName, evt.detail); };
101
+ b.field.addEventListener(b.startChangeEventName, b.startChangeListener);
102
+ b.changeListener = (evt) => { changeCallback(fieldName, evt.detail); };
103
+ b.field.addEventListener(b.changeEventName, b.changeListener);
60
104
  return b;
61
105
  }
62
106
  }
@@ -1,5 +1,5 @@
1
1
  import { h } from "@stencil/core";
2
2
  export const buildFile = ({ name, label, readOnly }) => {
3
3
  return (h("div", { class: "col col--sd-12 padding-horizontal--small" },
4
- h("ez-upload", { enabled: !readOnly, label: label, urlUpload: "", requestHeaders: "", maxFiles: 10, "data-field-name": name, key: name })));
4
+ h("ez-upload", { enabled: !readOnly, label: label, "data-field-name": name, key: name })));
5
5
  };
@@ -37,11 +37,13 @@ export default class AgGridController {
37
37
  this._serverURL = options.serverURL;
38
38
  this._dataUnit = options.dataUnit;
39
39
  this._dataUnit.sortingProvider = this;
40
+ this._dataSource = new DataSource(this._dataUnit, this._serverURL);
40
41
  this._gridOptions = {
41
42
  localeText: gridTerms,
42
43
  rowModelType: "serverSide",
44
+ serverSideStoreType: "partial",
43
45
  rowSelection: this._multipleSelection ? "multiple" : "single",
44
- serverSideDatasource: new DataSource(this._dataUnit, this._serverURL),
46
+ serverSideDatasource: this._dataSource,
45
47
  getRowNodeId: (params) => typeof params === "string" ? params : params[this._idAttribName],
46
48
  getMainMenuItems: (params) => {
47
49
  const column = params.column;
@@ -52,10 +54,13 @@ export default class AgGridController {
52
54
  }));
53
55
  return items;
54
56
  },
55
- onViewportChanged: () => {
56
- if (this._dataUnit) {
57
- this.selectRows(this._dataUnit.getSelection());
58
- }
57
+ getRowHeight: () => {
58
+ //FIXME: Existe um bug no PartialStore.prototype.destroyAllBlocks do ag-grid, pois
59
+ //apesar de destruir os blocos, mantém a variável "blockHeights" com o tamanho antigo
60
+ //dos blocos, então, quando removemos uma linha, a altura do bloco não é recalculada.
61
+ //Descobri que setando manualmente a altura das linhas, apesar do bloco ficar com
62
+ //tamanho errado, isso afeta menos o componente.
63
+ return 25;
59
64
  }
60
65
  };
61
66
  this.setOptionsEvents(this._gridOptions);
@@ -78,6 +83,11 @@ export default class AgGridController {
78
83
  opt.onSelectionChanged = e => this.onSelectionChange(e);
79
84
  opt.onPaginationChanged = () => this.onPaginationChange();
80
85
  opt.onRowDoubleClicked = evt => this.onRowDoubleClick(evt);
86
+ opt.onViewportChanged = () => {
87
+ if (this._dataUnit) {
88
+ this.selectRows(this._dataUnit.getSelection());
89
+ }
90
+ };
81
91
  }
82
92
  setOptionsPagination(opt) {
83
93
  opt.pagination = (this._pageSize > -1);
@@ -95,11 +105,11 @@ export default class AgGridController {
95
105
  }
96
106
  this._gridOptions.api.setRowData(data);
97
107
  }
98
- addRows(rows) {
108
+ addRows() {
99
109
  if (this._grid === undefined) {
100
110
  throw new Error("Erro interno: Grid ainda não inicializado.");
101
111
  }
102
- this._gridOptions.api.applyServerSideTransaction({ add: rows });
112
+ this._gridOptions.api.refreshServerSideStore({});
103
113
  }
104
114
  selectRows(rowIds) {
105
115
  if (this._grid === undefined) {
@@ -114,11 +124,11 @@ export default class AgGridController {
114
124
  });
115
125
  }
116
126
  }
117
- removeRows(rowIds) {
127
+ removeRows() {
118
128
  if (this._grid === undefined) {
119
129
  throw new Error("Erro interno: Grid ainda não inicializado.");
120
130
  }
121
- this._gridOptions.api.applyServerSideTransaction({ remove: rowIds });
131
+ this._gridOptions.api.refreshServerSideStore({});
122
132
  }
123
133
  changeValues(changes, rowIds) {
124
134
  if (this._grid === undefined) {
@@ -235,6 +245,14 @@ export default class AgGridController {
235
245
  previousPage() {
236
246
  this._gridOptions.api.paginationGoToPreviousPage();
237
247
  }
248
+ goToPage(page) {
249
+ this._gridOptions.api.paginationGoToPage(page);
250
+ }
251
+ quickFilter(term) {
252
+ this._dataSource.setQuickFilter(term);
253
+ this.goToPage(0);
254
+ this._gridOptions.api.refreshServerSideStore({ purge: true });
255
+ }
238
256
  buildColDef(source) {
239
257
  return {
240
258
  headerName: source.label,
@@ -19,15 +19,15 @@ export default class DataSource {
19
19
  }
20
20
  }
21
21
  else {
22
- this.loadData()
22
+ this.loadData({ limit: params.api.paginationGetPageSize(), offset: params.request.startRow, quickFilter: this._quickFilterTerm })
23
23
  .then(data => params.success(data))
24
24
  .catch(() => params.fail());
25
25
  }
26
26
  }
27
- loadData() {
27
+ loadData(page) {
28
28
  return new Promise((resolve, reject) => {
29
29
  if (this._dataUnit) {
30
- this._dataUnit.loadData().then(rowData => resolve({ rowData, rowCount: rowData.length }));
30
+ this._dataUnit.loadData(page).then(pageRes => resolve({ rowData: this._dataUnit.records, rowCount: pageRes.total }));
31
31
  }
32
32
  else {
33
33
  fetch(this._serverURL)
@@ -38,4 +38,7 @@ export default class DataSource {
38
38
  }
39
39
  });
40
40
  }
41
+ setQuickFilter(term) {
42
+ this._quickFilterTerm = term;
43
+ }
41
44
  }
@@ -54,6 +54,18 @@ export class EzGrid {
54
54
  async getColumns() {
55
55
  return Promise.resolve(this._gridController.getColumnsDef());
56
56
  }
57
+ /**
58
+ * Método para recarregar pagina atual da grid.
59
+ */
60
+ async refresh() {
61
+ this._gridController.refresh();
62
+ }
63
+ /**
64
+ * Método para fazer um filtro rápido na grid.
65
+ */
66
+ async quickFilter(term) {
67
+ this._gridController.quickFilter(term);
68
+ }
57
69
  componentWillLoad() {
58
70
  if (this.dataUnit) {
59
71
  this._dataUnitBridge = new DataUnitBridge(this._gridController, this.dataUnit);
@@ -433,6 +445,41 @@ export class EzGrid {
433
445
  "text": "M\u00E9todo retornar o estado atual das colunas do grid.",
434
446
  "tags": []
435
447
  }
448
+ },
449
+ "refresh": {
450
+ "complexType": {
451
+ "signature": "() => Promise<any>",
452
+ "parameters": [],
453
+ "references": {
454
+ "Promise": {
455
+ "location": "global"
456
+ }
457
+ },
458
+ "return": "Promise<any>"
459
+ },
460
+ "docs": {
461
+ "text": "M\u00E9todo para recarregar pagina atual da grid.",
462
+ "tags": []
463
+ }
464
+ },
465
+ "quickFilter": {
466
+ "complexType": {
467
+ "signature": "(term: string) => Promise<any>",
468
+ "parameters": [{
469
+ "tags": [],
470
+ "text": ""
471
+ }],
472
+ "references": {
473
+ "Promise": {
474
+ "location": "global"
475
+ }
476
+ },
477
+ "return": "Promise<any>"
478
+ },
479
+ "docs": {
480
+ "text": "M\u00E9todo para fazer um filtro r\u00E1pido na grid.",
481
+ "tags": []
482
+ }
436
483
  }
437
484
  }; }
438
485
  }
@@ -10,6 +10,9 @@ export class EzUpload {
10
10
  this.enabled = true;
11
11
  }
12
12
  changeValue(newValue) {
13
+ //Observamos o mundo externo, se um novo valor foi atribuído,
14
+ //precisamos cancelar a alteração anterior, isso envolve, percorrer
15
+ //a lista de ponteiros e cancelar todos os uploads em andamento.
13
16
  if (newValue !== this._updatingValue) {
14
17
  this._filePointers.forEach(f => {
15
18
  if (this.isRemoteFile(f)) {
@@ -18,8 +21,8 @@ export class EzUpload {
18
21
  });
19
22
  this._filePointers = new Map();
20
23
  this.updateFilePointers();
24
+ this._updatingValue = undefined;
21
25
  }
22
- this._updatingValue = undefined;
23
26
  }
24
27
  updateFilePointers() {
25
28
  if (this.value) {
@@ -89,6 +92,7 @@ export class EzUpload {
89
92
  }
90
93
  async doAddFile(file) {
91
94
  if (this.validateFile(file)) {
95
+ this.ezStartChange.emit({ waitmessage: "Há arquivos sendo enviados. Por favor aguarde a conclusão ou cancele o envio." });
92
96
  const uploadingFile = new RemoteFile(file);
93
97
  this._filePointers.set(file.name, uploadingFile);
94
98
  uploadingFile.upload(this.urlUpload, this._requestHeaders, (file) => this.updateFeedback(file))
@@ -108,8 +112,10 @@ export class EzUpload {
108
112
  this._updatingValue.push(f);
109
113
  }
110
114
  });
111
- this.value = this._updatingValue;
112
- this.ezChange.emit(this.value);
115
+ if (this._filePointers.size === this._updatingValue.length) {
116
+ this.value = this._updatingValue;
117
+ this.ezChange.emit(this.value);
118
+ }
113
119
  }
114
120
  buildProgressId(uploading) {
115
121
  let sanitizedName = uploading.name.replace(/[^a-z0-9_]/gi, "_");
@@ -435,6 +441,26 @@ export class EzUpload {
435
441
  }
436
442
  }
437
443
  }
444
+ }, {
445
+ "method": "ezStartChange",
446
+ "name": "ezStartChange",
447
+ "bubbles": true,
448
+ "cancelable": true,
449
+ "composed": true,
450
+ "docs": {
451
+ "tags": [],
452
+ "text": "Evento emitido ao iniciar a altera\u00E7\u00E3o (remover ou adicionar um arquivo)."
453
+ },
454
+ "complexType": {
455
+ "original": "WaitingChange",
456
+ "resolved": "WaitingChange",
457
+ "references": {
458
+ "WaitingChange": {
459
+ "location": "import",
460
+ "path": "@sankhyalabs/core"
461
+ }
462
+ }
463
+ }
438
464
  }]; }
439
465
  static get methods() { return {
440
466
  "addFiles": {
@@ -1,65 +1,61 @@
1
- import { Component, h } from '@stencil/core';
2
- import { DataUnit, DataType, UserInterface } from '@sankhyalabs/core';
1
+ import { Component, h, State } from '@stencil/core';
2
+ import { DataUnit, DataType, UserInterface, ApplicationContext } from '@sankhyalabs/core';
3
+ import { ApplicationUtils } from '../../utils';
3
4
  export class TestDu {
4
- /*private _ezButton// : HTMLEzButton;
5
- private _ezComboBox// : HTMLEzComboBox;
6
- private _ezDateInput// : HTMLEzDateInput;
7
- private _ezDateTimeInput// : HTMLEzDateTimeInput;
8
- private _ezNumberInput// : HTMLEzNumberInput
9
- private _ezSearch// : HTMLEzSearch
10
- private _ezUpload// : HTMLEzUpload
11
- private _ezFilterInput// : HTMLEzFilterInput*/
12
5
  componentWillLoad() {
6
+ ApplicationContext.setContextValue("__EZUI__UPLOAD__ADD__URL__", "http://localhost:8080/mge/ez.uploading");
13
7
  this.dataUnit = new DataUnit("testes_com_formulario");
8
+ this.dataUnit.subscribe(() => this.isDirty = this.dataUnit.isDirty());
14
9
  this.dataUnit.metadata = {
15
10
  name: "dd://br.com.sankhya.fin.cad.movimentacaoFinanceira/Financeiro",
16
11
  label: "Parceiro",
17
12
  fields: [
18
13
  {
19
- name: "CODPARC",
20
- label: "Parceiro",
21
- dataType: DataType.NUMBER,
22
- userInterface: UserInterface.SEARCH,
23
- required: true,
24
- properties: {}
25
- },
26
- {
27
- name: "RECDESP",
28
- label: "Receita/Despesa",
29
- dataType: DataType.TEXT,
30
- userInterface: UserInterface.OPTIONSELECTOR,
31
- required: true,
32
- properties: { options: `{"-1": "Despesa", "1": "Receita"}` }
33
- },
34
- {
35
- name: "P",
36
- label: "pera",
37
- dataType: DataType.TEXT,
38
- userInterface: UserInterface.OPTIONSELECTOR,
39
- properties: { options: `{"M": "Madura", "V": "Verde", "P": "Passada"}` }
40
- },
41
- {
42
- name: "ME",
43
- label: "ME",
44
- dataType: DataType.NUMBER,
45
- userInterface: UserInterface.DECIMALNUMBER,
46
- properties: { precision: 4, prettyPrecision: 1 }
14
+ name: "ANEXO",
15
+ label: "Anexo",
16
+ dataType: DataType.OBJECT,
17
+ userInterface: UserInterface.FILE,
18
+ properties: {
19
+ DESTINATION: "MULTIFILE",
20
+ MAX_FILES: "2"
21
+ }
47
22
  }
48
23
  ]
49
24
  };
50
- this.dataUnit.dataLoader = () => new Promise(accept => accept([
51
- {
52
- __record__id__: "1321321321321321",
53
- CODPARC: 10,
54
- NOMEPARC: "Parceiro 10",
55
- P: "M",
56
- L: "Bagaço",
57
- LI: "Azedo"
25
+ this.dataUnit.dataLoader = () => new Promise(accept => accept({
26
+ records: [{
27
+ __record__id__: "1321321321321321",
28
+ CODPARC: 10,
29
+ NOMEPARC: "Parceiro 10",
30
+ P: "M",
31
+ L: "Bagaço",
32
+ LI: "Azedo"
33
+ }],
34
+ limit: 0,
35
+ offset: 2,
36
+ total: 100,
37
+ hasMore: true
38
+ }));
39
+ this.dataUnit.saveLoader = (_dataUnit, changes) => {
40
+ const savedRecords = [];
41
+ changes.forEach(change => {
42
+ savedRecords.push(Object.assign(Object.assign({}, change.record), change.updatingFields));
43
+ });
44
+ return Promise.resolve(savedRecords);
45
+ };
46
+ }
47
+ save() {
48
+ this.dataUnit.saveData().catch(e => {
49
+ if (e.kind === "WAITING_CHANGE_ERROR") {
50
+ ApplicationUtils.alert(`Alterando campo ${e.fieldName}`, e.message);
58
51
  }
59
- ]));
52
+ });
60
53
  }
61
54
  render() {
62
- return (h("ez-form", { dataUnit: this.dataUnit }));
55
+ return (h("div", null,
56
+ h("button", { onClick: () => this.dataUnit.loadData() }, "Carregar"),
57
+ h("button", { onClick: () => this.save(), disabled: !this.isDirty }, "Salvar"),
58
+ h("ez-form", { dataUnit: this.dataUnit })));
63
59
  }
64
60
  static get is() { return "test-du"; }
65
61
  static get originalStyleUrls() { return {
@@ -68,4 +64,7 @@ export class TestDu {
68
64
  static get styleUrls() { return {
69
65
  "$": ["test-du.css"]
70
66
  }; }
67
+ static get states() { return {
68
+ "isDirty": {}
69
+ }; }
71
70
  }