@sankhyalabs/ezui 1.1.132 → 1.1.133

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.
@@ -8,8 +8,11 @@ import { SortMode, UserInterface } from "@sankhyalabs/core/dist/dataunit/metadat
8
8
  import { NumberUtils } from "@sankhyalabs/core";
9
9
  export default class AgGridController {
10
10
  constructor(enterprise) {
11
+ this.DEFAULT_ROW_HEIGHT = 25;
11
12
  this._menuItems = [];
12
13
  this._idAttribName = "__record__id__";
14
+ this._isFirstRecordOfPage = true;
15
+ this._isLastRecordOfPage = false;
13
16
  this._enterprise = enterprise;
14
17
  }
15
18
  getSort() {
@@ -37,7 +40,9 @@ export default class AgGridController {
37
40
  this._pageSize = options.pageSize;
38
41
  this._serverURL = options.serverURL;
39
42
  this._dataUnit = options.dataUnit;
40
- this._dataUnit.sortingProvider = this;
43
+ if (this._dataUnit) {
44
+ this._dataUnit.sortingProvider = this;
45
+ }
41
46
  this._dataSource = new DataSource(this._dataUnit, this._serverURL);
42
47
  this._gridOptions = {
43
48
  localeText: gridTerms,
@@ -46,7 +51,7 @@ export default class AgGridController {
46
51
  rowSelection: this._multipleSelection ? "multiple" : "single",
47
52
  serverSideDatasource: this._dataSource,
48
53
  sortingOrder: ['desc', 'asc', null],
49
- getRowNodeId: (params) => typeof params === "string" ? params : params[this._idAttribName],
54
+ getRowNodeId: this._dataUnit ? (params) => typeof params === "string" ? params : params[this._idAttribName] : undefined,
50
55
  getMainMenuItems: (params) => {
51
56
  const column = params.column;
52
57
  const items = [column.isPinned() ? "clearPinned" : "pinLeft", "separator"];
@@ -56,14 +61,12 @@ export default class AgGridController {
56
61
  }));
57
62
  return items;
58
63
  },
59
- getRowHeight: () => {
60
- //FIXME: Existe um bug no PartialStore.prototype.destroyAllBlocks do ag-grid, pois
61
- //apesar de destruir os blocos, mantém a variável "blockHeights" com o tamanho antigo
62
- //dos blocos, então, quando removemos uma linha, a altura do bloco não é recalculada.
63
- //Descobri que setando manualmente a altura das linhas, apesar do bloco ficar com
64
- //tamanho errado, isso afeta menos o componente.
65
- return 25;
66
- }
64
+ //FIXME: Existe um bug no PartialStore.prototype.destroyAllBlocks do ag-grid, pois
65
+ //apesar de destruir os blocos, mantém a variável "blockHeights" com o tamanho antigo
66
+ //dos blocos, então, quando removemos uma linha, a altura do bloco não é recalculada.
67
+ //Descobri que setando manualmente a altura das linhas, apesar do bloco ficar com
68
+ //tamanho errado, isso afeta menos o componente.
69
+ rowHeight: this.DEFAULT_ROW_HEIGHT
67
70
  };
68
71
  this.setOptionsEvents(this._gridOptions);
69
72
  this.setOptionsPagination(this._gridOptions);
@@ -86,16 +89,17 @@ export default class AgGridController {
86
89
  opt.onPaginationChanged = () => this.onPaginationChange();
87
90
  opt.onRowDoubleClicked = evt => this.onRowDoubleClick(evt);
88
91
  opt.onDragStopped = evt => this.onCallStateChange("columnMovedEnd", evt);
89
- opt.onViewportChanged = () => {
90
- if (this._dataUnit) {
91
- this.selectRows(this._dataUnit.getSelection());
92
- }
93
- };
92
+ }
93
+ syncSelection() {
94
+ if (this._dataUnit) {
95
+ this.selectRows(this._dataUnit.getSelection());
96
+ }
94
97
  }
95
98
  setOptionsPagination(opt) {
96
99
  opt.pagination = (this._pageSize > -1);
97
100
  opt.paginationPageSize = this._pageSize;
98
101
  opt.cacheBlockSize = this._pageSize;
102
+ opt.maxBlocksInCache = 1;
99
103
  }
100
104
  setOptionsSupress(opt) {
101
105
  opt.suppressDragLeaveHidesColumns = true;
@@ -131,7 +135,7 @@ export default class AgGridController {
131
135
  if (this._grid === undefined) {
132
136
  throw new Error("Erro interno: Grid ainda não inicializado.");
133
137
  }
134
- this._gridOptions.api.refreshServerSideStore({});
138
+ this._gridOptions.api.refreshServerSideStore({ purge: true });
135
139
  }
136
140
  changeValues(changes, rowIds) {
137
141
  if (this._grid === undefined) {
@@ -268,6 +272,75 @@ export default class AgGridController {
268
272
  this.goToPage(0);
269
273
  this._gridOptions.api.refreshServerSideStore({ purge: true });
270
274
  }
275
+ isLastOfPage() {
276
+ return this._isLastRecordOfPage;
277
+ }
278
+ isFirstOfPage() {
279
+ return this._isFirstRecordOfPage;
280
+ }
281
+ previousRecord() {
282
+ const pagination = this.getPaginationStatus();
283
+ if (this._isFirstRecordOfPage && pagination.hasPrevious) {
284
+ this.previousPage();
285
+ }
286
+ else {
287
+ if (this._dataUnit) {
288
+ this._dataUnit.previousRecord();
289
+ }
290
+ else {
291
+ const node = this._gridOptions.api.getSelectedNodes()[0];
292
+ this.setSelectedIndex(node.rowIndex - 1);
293
+ }
294
+ }
295
+ }
296
+ nextRecord() {
297
+ const pagination = this.getPaginationStatus();
298
+ if (this._isLastRecordOfPage && pagination.hasNext) {
299
+ this.nextPage();
300
+ }
301
+ else {
302
+ if (this._dataUnit) {
303
+ this._dataUnit.nextRecord();
304
+ }
305
+ else {
306
+ const node = this._gridOptions.api.getSelectedNodes()[0];
307
+ this.setSelectedIndex(node.rowIndex + 1);
308
+ }
309
+ }
310
+ }
311
+ setSelectedIndex(index) {
312
+ var _a;
313
+ (_a = this._gridOptions.api.getDisplayedRowAtIndex(index)) === null || _a === void 0 ? void 0 : _a.setSelected(true);
314
+ }
315
+ hasPreviousRecord() {
316
+ const pagination = this.getPaginationStatus();
317
+ if (this._isFirstRecordOfPage) {
318
+ return pagination.hasPrevious;
319
+ }
320
+ else {
321
+ if (this._dataUnit) {
322
+ return this._dataUnit.hasPrevious();
323
+ }
324
+ else {
325
+ return pagination.hasPrevious || this._gridOptions.api.getSelectedRows()[0].rowIndex > 0;
326
+ }
327
+ }
328
+ }
329
+ hasNextRecord() {
330
+ const pagination = this.getPaginationStatus();
331
+ if (this._isLastRecordOfPage) {
332
+ return pagination.hasNext;
333
+ }
334
+ else {
335
+ if (this._dataUnit) {
336
+ return this._dataUnit.hasNext() || this.getPaginationStatus().hasNext;
337
+ }
338
+ else {
339
+ const api = this._gridOptions.api;
340
+ return pagination.hasNext || api.getSelectedRows()[0].rowIndex < api.getDisplayedRowCount();
341
+ }
342
+ }
343
+ }
271
344
  buildColDef(source) {
272
345
  return {
273
346
  headerName: source.label,
@@ -349,31 +422,44 @@ export default class AgGridController {
349
422
  return false;
350
423
  }
351
424
  onSelectionChange(e) {
425
+ const selectedNodes = e.api.getSelectedNodes();
426
+ if (selectedNodes.length > 0) {
427
+ this._isFirstRecordOfPage = selectedNodes[0].rowIndex === e.api.getFirstDisplayedRow();
428
+ this._isLastRecordOfPage = selectedNodes[0].rowIndex === e.api.getLastDisplayedRow();
429
+ }
352
430
  if (this._selectionChangeCallback) {
353
- this._selectionChangeCallback(e.api.getSelectedRows());
431
+ this._selectionChangeCallback({
432
+ selection: e.api.getSelectedRows(),
433
+ isFirstOfPage: this._isFirstRecordOfPage,
434
+ isLastOfPage: this._isLastRecordOfPage
435
+ });
354
436
  }
355
437
  }
356
438
  onPaginationChange() {
439
+ this.syncSelection();
357
440
  if (this._paginationChangeCallback) {
358
441
  if (this._gridOptions.api) {
359
- const api = this._gridOptions.api;
360
- const currentPage = api.paginationGetCurrentPage();
361
- const isLastPage = api.paginationGetTotalPages() === (currentPage + 1);
362
- const pageSize = api.paginationGetPageSize();
363
- const totalRows = api.paginationGetRowCount();
364
- const pageStart = currentPage * pageSize + 1;
365
- const pageEnd = Math.min(totalRows, (currentPage + 1) * pageSize);
366
- this._paginationChangeCallback({
367
- hasPrevious: currentPage > 0,
368
- hasNext: !isLastPage,
369
- currentPage: currentPage + 1,
370
- pageStart,
371
- pageEnd,
372
- totalRows
373
- });
442
+ this._paginationChangeCallback(this.getPaginationStatus());
374
443
  }
375
444
  }
376
445
  }
446
+ getPaginationStatus() {
447
+ const api = this._gridOptions.api;
448
+ const currentPage = api.paginationGetCurrentPage();
449
+ const isLastPage = api.paginationGetTotalPages() === (currentPage + 1);
450
+ const pageSize = api.paginationGetPageSize();
451
+ const totalRows = api.paginationGetRowCount();
452
+ const pageStart = currentPage * pageSize + 1;
453
+ const pageEnd = Math.min(totalRows, (currentPage + 1) * pageSize);
454
+ return {
455
+ hasPrevious: currentPage > 0,
456
+ hasNext: !isLastPage,
457
+ currentPage: currentPage + 1,
458
+ pageStart,
459
+ pageEnd,
460
+ totalRows
461
+ };
462
+ }
377
463
  onRowDoubleClick(evt) {
378
464
  if (this._doubleClickCallBack) {
379
465
  this._doubleClickCallBack(evt.data);
@@ -66,6 +66,74 @@ export class EzGrid {
66
66
  async quickFilter(term) {
67
67
  this._gridController.quickFilter(term);
68
68
  }
69
+ /**
70
+ * Método para fazer um filtro rápido na grid.
71
+ */
72
+ async nextPage() {
73
+ this._gridController.nextPage();
74
+ }
75
+ /**
76
+ * Método para fazer um filtro rápido na grid.
77
+ */
78
+ async previousPage() {
79
+ this._gridController.previousPage();
80
+ }
81
+ /**
82
+ * Método para fazer um filtro rápido na grid.
83
+ */
84
+ async hasNextPage() {
85
+ return new Promise(resolve => {
86
+ resolve(this._navigationHasNext);
87
+ });
88
+ }
89
+ /**
90
+ * Método para fazer um filtro rápido na grid.
91
+ */
92
+ async hasPreviousPage() {
93
+ return new Promise(resolve => {
94
+ resolve(this._navigationHasPrevious);
95
+ });
96
+ }
97
+ /**
98
+ * Método para verificar se o registro selecionado é o ultimo da página.
99
+ */
100
+ async isLastOfPage() {
101
+ return new Promise(resolve => {
102
+ resolve(this._gridController.isLastOfPage());
103
+ });
104
+ }
105
+ /**
106
+ * Método para verificar se o registro selecionado é o primeiro da página.
107
+ */
108
+ async isFirstOfPage() {
109
+ return new Promise(resolve => {
110
+ resolve(this._gridController.isFirstOfPage());
111
+ });
112
+ }
113
+ /**
114
+ * Método para navegar para o proxímo registro da grid.
115
+ */
116
+ async nextRecord() {
117
+ this._gridController.nextRecord();
118
+ }
119
+ /**
120
+ * Método para navegar para o registro anterior da grid.
121
+ */
122
+ async previousRecord() {
123
+ this._gridController.previousRecord();
124
+ }
125
+ /**
126
+ * Método para verificar se existem proximos registros.
127
+ */
128
+ async hasNextRecord() {
129
+ return Promise.resolve(this._gridController.hasNextRecord());
130
+ }
131
+ /**
132
+ * Método para verificar se existem registros anteriores.
133
+ */
134
+ async hasPreviousRecord() {
135
+ return Promise.resolve(this._gridController.hasPreviousRecord());
136
+ }
69
137
  componentWillLoad() {
70
138
  if (this.dataUnit) {
71
139
  this._dataUnitBridge = new DataUnitBridge(this._gridController, this.dataUnit);
@@ -138,7 +206,7 @@ export class EzGrid {
138
206
  componentDidLoad() {
139
207
  this._gridController.initDatagrid(this._container, {
140
208
  onColumnStateChange: (type, state, info) => this.onColumnStateChange(type, state, info),
141
- onSelectionChange: (selection) => this.ezSelectionChange.emit(selection),
209
+ onSelectionChange: (state) => this.ezSelectionChange.emit(state.selection),
142
210
  onPaginationChange: (status) => {
143
211
  this._navigationHasPrevious = status.hasPrevious;
144
212
  this._navigationHasNext = status.hasNext;
@@ -174,8 +242,8 @@ export class EzGrid {
174
242
  h("div", { class: "ez-text ez-text--primary ez-text--medium ez-margin-right--medium" },
175
243
  h("strong", { class: "ez-text ez-text--primary ez-text--medium" }, `${this._navigationFirstRow}-${this._navigationLastRow}`),
176
244
  ` de ${this._navigationTotalRows}`),
177
- h("ez-button", { size: "small", iconName: "chevron-left", class: "ez-margin-right--medium", mode: "icon", enabled: this._navigationHasPrevious, onClick: () => this._gridController.previousPage(), label: "P\u00E1gina anterior" }),
178
- h("ez-button", { size: "small", iconName: "chevron-right", class: "ez-margin-right--medium", mode: "icon", enabled: this._navigationHasNext, onClick: () => this._gridController.nextPage(), label: "Pr\u00F3xima P\u00E1gina" })
245
+ h("ez-button", { size: "small", iconName: "chevron-left", class: "ez-margin-right--medium", mode: "icon", enabled: this._navigationHasPrevious, onClick: () => this.previousPage(), label: "P\u00E1gina anterior" }),
246
+ h("ez-button", { size: "small", iconName: "chevron-right", class: "ez-margin-right--medium", mode: "icon", enabled: this._navigationHasNext, onClick: () => this.nextPage(), label: "Pr\u00F3xima P\u00E1gina" })
179
247
  ];
180
248
  }
181
249
  applyConfig(config) {
@@ -590,6 +658,166 @@ export class EzGrid {
590
658
  "tags": []
591
659
  }
592
660
  },
661
+ "nextPage": {
662
+ "complexType": {
663
+ "signature": "() => Promise<void>",
664
+ "parameters": [],
665
+ "references": {
666
+ "Promise": {
667
+ "location": "global"
668
+ }
669
+ },
670
+ "return": "Promise<void>"
671
+ },
672
+ "docs": {
673
+ "text": "M\u00E9todo para fazer um filtro r\u00E1pido na grid.",
674
+ "tags": []
675
+ }
676
+ },
677
+ "previousPage": {
678
+ "complexType": {
679
+ "signature": "() => Promise<void>",
680
+ "parameters": [],
681
+ "references": {
682
+ "Promise": {
683
+ "location": "global"
684
+ }
685
+ },
686
+ "return": "Promise<void>"
687
+ },
688
+ "docs": {
689
+ "text": "M\u00E9todo para fazer um filtro r\u00E1pido na grid.",
690
+ "tags": []
691
+ }
692
+ },
693
+ "hasNextPage": {
694
+ "complexType": {
695
+ "signature": "() => Promise<boolean>",
696
+ "parameters": [],
697
+ "references": {
698
+ "Promise": {
699
+ "location": "global"
700
+ }
701
+ },
702
+ "return": "Promise<boolean>"
703
+ },
704
+ "docs": {
705
+ "text": "M\u00E9todo para fazer um filtro r\u00E1pido na grid.",
706
+ "tags": []
707
+ }
708
+ },
709
+ "hasPreviousPage": {
710
+ "complexType": {
711
+ "signature": "() => Promise<boolean>",
712
+ "parameters": [],
713
+ "references": {
714
+ "Promise": {
715
+ "location": "global"
716
+ }
717
+ },
718
+ "return": "Promise<boolean>"
719
+ },
720
+ "docs": {
721
+ "text": "M\u00E9todo para fazer um filtro r\u00E1pido na grid.",
722
+ "tags": []
723
+ }
724
+ },
725
+ "isLastOfPage": {
726
+ "complexType": {
727
+ "signature": "() => Promise<boolean>",
728
+ "parameters": [],
729
+ "references": {
730
+ "Promise": {
731
+ "location": "global"
732
+ }
733
+ },
734
+ "return": "Promise<boolean>"
735
+ },
736
+ "docs": {
737
+ "text": "M\u00E9todo para verificar se o registro selecionado \u00E9 o ultimo da p\u00E1gina.",
738
+ "tags": []
739
+ }
740
+ },
741
+ "isFirstOfPage": {
742
+ "complexType": {
743
+ "signature": "() => Promise<boolean>",
744
+ "parameters": [],
745
+ "references": {
746
+ "Promise": {
747
+ "location": "global"
748
+ }
749
+ },
750
+ "return": "Promise<boolean>"
751
+ },
752
+ "docs": {
753
+ "text": "M\u00E9todo para verificar se o registro selecionado \u00E9 o primeiro da p\u00E1gina.",
754
+ "tags": []
755
+ }
756
+ },
757
+ "nextRecord": {
758
+ "complexType": {
759
+ "signature": "() => Promise<void>",
760
+ "parameters": [],
761
+ "references": {
762
+ "Promise": {
763
+ "location": "global"
764
+ }
765
+ },
766
+ "return": "Promise<void>"
767
+ },
768
+ "docs": {
769
+ "text": "M\u00E9todo para navegar para o prox\u00EDmo registro da grid.",
770
+ "tags": []
771
+ }
772
+ },
773
+ "previousRecord": {
774
+ "complexType": {
775
+ "signature": "() => Promise<void>",
776
+ "parameters": [],
777
+ "references": {
778
+ "Promise": {
779
+ "location": "global"
780
+ }
781
+ },
782
+ "return": "Promise<void>"
783
+ },
784
+ "docs": {
785
+ "text": "M\u00E9todo para navegar para o registro anterior da grid.",
786
+ "tags": []
787
+ }
788
+ },
789
+ "hasNextRecord": {
790
+ "complexType": {
791
+ "signature": "() => Promise<boolean>",
792
+ "parameters": [],
793
+ "references": {
794
+ "Promise": {
795
+ "location": "global"
796
+ }
797
+ },
798
+ "return": "Promise<boolean>"
799
+ },
800
+ "docs": {
801
+ "text": "M\u00E9todo para verificar se existem proximos registros.",
802
+ "tags": []
803
+ }
804
+ },
805
+ "hasPreviousRecord": {
806
+ "complexType": {
807
+ "signature": "() => Promise<boolean>",
808
+ "parameters": [],
809
+ "references": {
810
+ "Promise": {
811
+ "location": "global"
812
+ }
813
+ },
814
+ "return": "Promise<boolean>"
815
+ },
816
+ "docs": {
817
+ "text": "M\u00E9todo para verificar se existem registros anteriores.",
818
+ "tags": []
819
+ }
820
+ },
593
821
  "openGridConfig": {
594
822
  "complexType": {
595
823
  "signature": "() => Promise<void>",