@zeedhi/teknisa-components-common 1.90.3 → 1.91.1
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/tek-components-common.esm.js +163 -27
- package/dist/tek-components-common.umd.js +163 -27
- package/package.json +2 -2
- package/tests/unit/components/tek-grid/grid.spec.ts +87 -77
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +28 -19
- package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +44 -0
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +135 -0
- package/types/components/tek-grid/interfaces.d.ts +19 -2
- package/types/utils/grid-base/export-options/button-option.d.ts +16 -0
- package/types/utils/grid-base/export-options/index.d.ts +3 -0
- package/types/utils/grid-base/export-options/interfaces.d.ts +5 -0
- package/types/utils/grid-base/export-options/multi-option.d.ts +12 -0
- package/types/utils/grid-base/grid-base.d.ts +3 -2
- package/types/utils/index.d.ts +5 -5
|
@@ -711,6 +711,95 @@ class TekGridDeleteRowsError extends Error {
|
|
|
711
711
|
}
|
|
712
712
|
}
|
|
713
713
|
|
|
714
|
+
class ButtonOption {
|
|
715
|
+
constructor(config) {
|
|
716
|
+
this.config = config;
|
|
717
|
+
}
|
|
718
|
+
buildComponent(grid) {
|
|
719
|
+
const { type, label, portrait = true, iconName, } = this.config;
|
|
720
|
+
const orientation = portrait ? 'portrait' : 'landscape';
|
|
721
|
+
return {
|
|
722
|
+
label,
|
|
723
|
+
iconName,
|
|
724
|
+
name: `${grid.name}_export_${type}_${orientation}`,
|
|
725
|
+
component: 'ZdButton',
|
|
726
|
+
flat: true,
|
|
727
|
+
events: {
|
|
728
|
+
click: () => grid.getReport(type, portrait),
|
|
729
|
+
},
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
class MultiOption {
|
|
735
|
+
constructor(config) {
|
|
736
|
+
this.config = config;
|
|
737
|
+
}
|
|
738
|
+
formatName(id, type, grid) {
|
|
739
|
+
return `${grid.name}_export_${type}_${id}`;
|
|
740
|
+
}
|
|
741
|
+
buildTooltip(option, type, grid) {
|
|
742
|
+
const { label } = option;
|
|
743
|
+
return {
|
|
744
|
+
name: this.formatName(`tooltip_${label}`, type, grid),
|
|
745
|
+
component: 'ZdTooltip',
|
|
746
|
+
bottom: true,
|
|
747
|
+
label,
|
|
748
|
+
children: [],
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
buildButton(option, type, grid) {
|
|
752
|
+
const { cssClass, label, iconName, reportParams, } = option;
|
|
753
|
+
const { portrait: optionPortrait, rowObj } = reportParams || {};
|
|
754
|
+
return {
|
|
755
|
+
name: this.formatName(`button_${label}`, type, grid),
|
|
756
|
+
component: 'ZdButton',
|
|
757
|
+
cssClass,
|
|
758
|
+
icon: true,
|
|
759
|
+
iconName,
|
|
760
|
+
events: {
|
|
761
|
+
click: () => grid.getReport(type, optionPortrait, rowObj),
|
|
762
|
+
},
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
buildDivider(option, type, grid) {
|
|
766
|
+
const { label } = option;
|
|
767
|
+
return {
|
|
768
|
+
name: this.formatName(`divider_${label}`, type, grid),
|
|
769
|
+
component: 'ZdDivider',
|
|
770
|
+
cssClass: 'zd-my-1',
|
|
771
|
+
vertical: true,
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
buildComponent(grid) {
|
|
775
|
+
const { type, label, multiOption, } = this.config;
|
|
776
|
+
const optionComponents = multiOption.map((option) => ([
|
|
777
|
+
Object.assign(Object.assign({}, this.buildTooltip(option, type, grid)), { children: [
|
|
778
|
+
this.buildButton(option, type, grid),
|
|
779
|
+
] }),
|
|
780
|
+
this.buildDivider(option, type, grid),
|
|
781
|
+
]))
|
|
782
|
+
.flat();
|
|
783
|
+
optionComponents.pop();
|
|
784
|
+
const text = {
|
|
785
|
+
name: this.formatName('text', type, grid),
|
|
786
|
+
component: 'ZdText',
|
|
787
|
+
cssClass: 'zd-display-flex zd-align-center zd-flex-grow-1 tek-grid-export-multioption-text',
|
|
788
|
+
events: {
|
|
789
|
+
click: ({ event }) => event === null || event === void 0 ? void 0 : event.stopPropagation(),
|
|
790
|
+
},
|
|
791
|
+
text: label || '',
|
|
792
|
+
};
|
|
793
|
+
const result = {
|
|
794
|
+
name: this.formatName('row', type, grid),
|
|
795
|
+
component: 'ZdRow',
|
|
796
|
+
cssClass: 'zd-display-flex zd-ma-0 zd-py-0 zd-gap-x-1 tek-grid-export-multioption-row',
|
|
797
|
+
children: [text, ...optionComponents],
|
|
798
|
+
};
|
|
799
|
+
return result;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
714
803
|
class GridBase {
|
|
715
804
|
constructor(grid) {
|
|
716
805
|
this.exportConfigButtons = [];
|
|
@@ -735,20 +824,15 @@ class GridBase {
|
|
|
735
824
|
this.grid = grid;
|
|
736
825
|
this.exportConfigButtons = this.getExportConfigButtons();
|
|
737
826
|
}
|
|
827
|
+
getOption(config) {
|
|
828
|
+
if (config.multiOption)
|
|
829
|
+
return new MultiOption(config);
|
|
830
|
+
return new ButtonOption(config);
|
|
831
|
+
}
|
|
738
832
|
getExportConfigButtons() {
|
|
739
833
|
return this.grid.exportConfig.map((config) => {
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
return {
|
|
743
|
-
label,
|
|
744
|
-
iconName,
|
|
745
|
-
name: `${this.grid.name}_export_${type}_${orientation}`,
|
|
746
|
-
component: 'ZdButton',
|
|
747
|
-
flat: true,
|
|
748
|
-
events: {
|
|
749
|
-
click: () => this.grid.getReport(type, portrait),
|
|
750
|
-
},
|
|
751
|
-
};
|
|
834
|
+
const option = this.getOption(config);
|
|
835
|
+
return option.buildComponent(this.grid);
|
|
752
836
|
});
|
|
753
837
|
}
|
|
754
838
|
createToolbarProps() {
|
|
@@ -1089,6 +1173,8 @@ Messages.add({
|
|
|
1089
1173
|
TEKGRID_MULTIPLE_VALUE_HINT: 'Separe valores usando ";"',
|
|
1090
1174
|
TEKGRID_EXPORT: 'Exportar',
|
|
1091
1175
|
TEKGRID_EXPORT_AS: 'Exportar como {{ type }}',
|
|
1176
|
+
TEKGRID_PORTRAIT: 'Retrato',
|
|
1177
|
+
TEKGRID_LANDSCAPE: 'Paisagem',
|
|
1092
1178
|
TEKGRID_COLUMN_VISIBLE: 'Visível',
|
|
1093
1179
|
TEKGRID_COLUMN_GROUPED: 'Grupo',
|
|
1094
1180
|
TEKGRID_COLUMN_AGGREGATION: 'Totalização',
|
|
@@ -1158,6 +1244,8 @@ Messages.add({
|
|
|
1158
1244
|
TEKGRID_MULTIPLE_VALUE_HINT: 'Separate values using ";"',
|
|
1159
1245
|
TEKGRID_EXPORT: 'Export',
|
|
1160
1246
|
TEKGRID_EXPORT_AS: 'Export as {{ type }}',
|
|
1247
|
+
TEKGRID_PORTRAIT: 'Portrait',
|
|
1248
|
+
TEKGRID_LANDSCAPE: 'Landscape',
|
|
1161
1249
|
TEKGRID_COLUMN_VISIBLE: 'Visible',
|
|
1162
1250
|
TEKGRID_COLUMN_GROUPED: 'Grouped',
|
|
1163
1251
|
TEKGRID_COLUMN_AGGREGATION: 'Aggregation',
|
|
@@ -1227,6 +1315,8 @@ Messages.add({
|
|
|
1227
1315
|
TEKGRID_MULTIPLE_VALUE_HINT: 'Separe los valores usando ";"',
|
|
1228
1316
|
TEKGRID_EXPORT: 'Exportar',
|
|
1229
1317
|
TEKGRID_EXPORT_AS: 'Exportar como {{ type }}',
|
|
1318
|
+
TEKGRID_PORTRAIT: 'Vertical',
|
|
1319
|
+
TEKGRID_LANDSCAPE: 'Horizontal',
|
|
1230
1320
|
TEKGRID_COLUMN_VISIBLE: 'Visible',
|
|
1231
1321
|
TEKGRID_COLUMN_GROUPED: 'Grupo',
|
|
1232
1322
|
TEKGRID_COLUMN_AGGREGATION: 'Totalización',
|
|
@@ -2080,6 +2170,15 @@ class TekGrid extends GridEditable {
|
|
|
2080
2170
|
{
|
|
2081
2171
|
type: 'pdf',
|
|
2082
2172
|
label: I18n.translate('TEKGRID_EXPORT_AS', { type: 'PDF' }),
|
|
2173
|
+
multiOption: [
|
|
2174
|
+
{ label: I18n.translate('TEKGRID_PORTRAIT'), iconName: 'mdi-file-outline' },
|
|
2175
|
+
{
|
|
2176
|
+
label: I18n.translate('TEKGRID_LANDSCAPE'),
|
|
2177
|
+
iconName: 'mdi-file-outline',
|
|
2178
|
+
cssClass: 'tek-grid-export-landscape',
|
|
2179
|
+
reportParams: { portrait: false },
|
|
2180
|
+
},
|
|
2181
|
+
],
|
|
2083
2182
|
},
|
|
2084
2183
|
{
|
|
2085
2184
|
type: 'xls',
|
|
@@ -2474,8 +2573,9 @@ class TekGrid extends GridEditable {
|
|
|
2474
2573
|
resetFooterVariables(group) {
|
|
2475
2574
|
this.summaryColumns.forEach((column) => {
|
|
2476
2575
|
group.footer[column.name] = {
|
|
2477
|
-
sum: 0,
|
|
2478
2576
|
count: 0,
|
|
2577
|
+
sum: undefined,
|
|
2578
|
+
avg: undefined,
|
|
2479
2579
|
min: undefined,
|
|
2480
2580
|
max: undefined,
|
|
2481
2581
|
};
|
|
@@ -2484,17 +2584,24 @@ class TekGrid extends GridEditable {
|
|
|
2484
2584
|
isUndefined(value) {
|
|
2485
2585
|
return value === undefined || value === null;
|
|
2486
2586
|
}
|
|
2487
|
-
calcSummaryValues(summary, rowValue) {
|
|
2587
|
+
calcSummaryValues(columnName, summary, rowValue) {
|
|
2488
2588
|
if (!this.isUndefined(rowValue)) {
|
|
2489
2589
|
summary.count += 1;
|
|
2490
|
-
if (
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2590
|
+
if (this.events.calcSummary) {
|
|
2591
|
+
this.callEvent('calcSummary', {
|
|
2592
|
+
component: this, columnName, summary, rowValue,
|
|
2593
|
+
});
|
|
2594
|
+
}
|
|
2595
|
+
else {
|
|
2596
|
+
if (summary.min === undefined)
|
|
2597
|
+
summary.min = rowValue;
|
|
2598
|
+
if (summary.max === undefined)
|
|
2599
|
+
summary.max = rowValue;
|
|
2600
|
+
summary.min = rowValue < summary.min ? rowValue : summary.min;
|
|
2601
|
+
summary.max = rowValue > summary.max ? rowValue : summary.max;
|
|
2602
|
+
if (typeof rowValue === 'number') {
|
|
2603
|
+
summary.sum = (summary.sum || 0) + rowValue;
|
|
2604
|
+
}
|
|
2498
2605
|
}
|
|
2499
2606
|
}
|
|
2500
2607
|
}
|
|
@@ -2506,14 +2613,15 @@ class TekGrid extends GridEditable {
|
|
|
2506
2613
|
if (this.isUndefined(this.summary[columnName])) {
|
|
2507
2614
|
this.summary[columnName] = {
|
|
2508
2615
|
count: 0,
|
|
2509
|
-
sum:
|
|
2616
|
+
sum: undefined,
|
|
2617
|
+
avg: undefined,
|
|
2510
2618
|
min: undefined,
|
|
2511
2619
|
max: undefined,
|
|
2512
2620
|
};
|
|
2513
2621
|
}
|
|
2514
|
-
this.calcSummaryValues(this.summary[columnName], rowValue);
|
|
2622
|
+
this.calcSummaryValues(columnName, this.summary[columnName], rowValue);
|
|
2515
2623
|
this.groups.forEach((group) => {
|
|
2516
|
-
this.calcSummaryValues(group.footer[columnName], rowValue);
|
|
2624
|
+
this.calcSummaryValues(columnName, group.footer[columnName], rowValue);
|
|
2517
2625
|
});
|
|
2518
2626
|
});
|
|
2519
2627
|
}
|
|
@@ -2536,7 +2644,12 @@ class TekGrid extends GridEditable {
|
|
|
2536
2644
|
summaryData[column.name] = currentGroup.sum;
|
|
2537
2645
|
}
|
|
2538
2646
|
else if (aggregation === 'AVG') {
|
|
2539
|
-
|
|
2647
|
+
if (currentGroup.avg) {
|
|
2648
|
+
summaryData[column.name] = currentGroup.avg;
|
|
2649
|
+
}
|
|
2650
|
+
else if (typeof currentGroup.sum === 'number') {
|
|
2651
|
+
summaryData[column.name] = currentGroup.sum / currentGroup.count;
|
|
2652
|
+
}
|
|
2540
2653
|
}
|
|
2541
2654
|
else if (aggregation === 'MIN') {
|
|
2542
2655
|
summaryData[column.name] = currentGroup.min;
|
|
@@ -3398,10 +3511,33 @@ class TekTreeGrid extends TreeGridEditable {
|
|
|
3398
3511
|
{
|
|
3399
3512
|
type: 'pdf',
|
|
3400
3513
|
label: I18n.translate('TEKGRID_EXPORT_AS', { type: 'PDF' }),
|
|
3514
|
+
multiOption: [
|
|
3515
|
+
{ label: I18n.translate('TEKGRID_PORTRAIT'), iconName: 'mdi-file-outline' },
|
|
3516
|
+
{
|
|
3517
|
+
label: I18n.translate('TEKGRID_LANDSCAPE'),
|
|
3518
|
+
iconName: 'mdi-file-outline',
|
|
3519
|
+
cssClass: 'tek-grid-export-landscape',
|
|
3520
|
+
reportParams: { portrait: false },
|
|
3521
|
+
},
|
|
3522
|
+
],
|
|
3401
3523
|
},
|
|
3402
3524
|
{
|
|
3403
3525
|
type: 'xls',
|
|
3404
|
-
label: I18n.translate('TEKGRID_EXPORT_AS', {
|
|
3526
|
+
label: I18n.translate('TEKGRID_EXPORT_AS', {
|
|
3527
|
+
type: `XLS ${I18n.translate('TEKGRID_WITHOUT_GROUPS')}`,
|
|
3528
|
+
}),
|
|
3529
|
+
},
|
|
3530
|
+
{
|
|
3531
|
+
type: 'xls2',
|
|
3532
|
+
label: I18n.translate('TEKGRID_EXPORT_AS', {
|
|
3533
|
+
type: `XLS ${I18n.translate('TEKGRID_WITH_GROUPS')}`,
|
|
3534
|
+
}),
|
|
3535
|
+
},
|
|
3536
|
+
{
|
|
3537
|
+
type: 'xls3',
|
|
3538
|
+
label: I18n.translate('TEKGRID_EXPORT_AS', {
|
|
3539
|
+
type: `XLS ${I18n.translate('TEKGRID_GRID_MIRROR')}`,
|
|
3540
|
+
}),
|
|
3405
3541
|
},
|
|
3406
3542
|
{
|
|
3407
3543
|
type: 'csv',
|
|
@@ -715,6 +715,95 @@
|
|
|
715
715
|
}
|
|
716
716
|
}
|
|
717
717
|
|
|
718
|
+
class ButtonOption {
|
|
719
|
+
constructor(config) {
|
|
720
|
+
this.config = config;
|
|
721
|
+
}
|
|
722
|
+
buildComponent(grid) {
|
|
723
|
+
const { type, label, portrait = true, iconName, } = this.config;
|
|
724
|
+
const orientation = portrait ? 'portrait' : 'landscape';
|
|
725
|
+
return {
|
|
726
|
+
label,
|
|
727
|
+
iconName,
|
|
728
|
+
name: `${grid.name}_export_${type}_${orientation}`,
|
|
729
|
+
component: 'ZdButton',
|
|
730
|
+
flat: true,
|
|
731
|
+
events: {
|
|
732
|
+
click: () => grid.getReport(type, portrait),
|
|
733
|
+
},
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
class MultiOption {
|
|
739
|
+
constructor(config) {
|
|
740
|
+
this.config = config;
|
|
741
|
+
}
|
|
742
|
+
formatName(id, type, grid) {
|
|
743
|
+
return `${grid.name}_export_${type}_${id}`;
|
|
744
|
+
}
|
|
745
|
+
buildTooltip(option, type, grid) {
|
|
746
|
+
const { label } = option;
|
|
747
|
+
return {
|
|
748
|
+
name: this.formatName(`tooltip_${label}`, type, grid),
|
|
749
|
+
component: 'ZdTooltip',
|
|
750
|
+
bottom: true,
|
|
751
|
+
label,
|
|
752
|
+
children: [],
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
buildButton(option, type, grid) {
|
|
756
|
+
const { cssClass, label, iconName, reportParams, } = option;
|
|
757
|
+
const { portrait: optionPortrait, rowObj } = reportParams || {};
|
|
758
|
+
return {
|
|
759
|
+
name: this.formatName(`button_${label}`, type, grid),
|
|
760
|
+
component: 'ZdButton',
|
|
761
|
+
cssClass,
|
|
762
|
+
icon: true,
|
|
763
|
+
iconName,
|
|
764
|
+
events: {
|
|
765
|
+
click: () => grid.getReport(type, optionPortrait, rowObj),
|
|
766
|
+
},
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
buildDivider(option, type, grid) {
|
|
770
|
+
const { label } = option;
|
|
771
|
+
return {
|
|
772
|
+
name: this.formatName(`divider_${label}`, type, grid),
|
|
773
|
+
component: 'ZdDivider',
|
|
774
|
+
cssClass: 'zd-my-1',
|
|
775
|
+
vertical: true,
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
buildComponent(grid) {
|
|
779
|
+
const { type, label, multiOption, } = this.config;
|
|
780
|
+
const optionComponents = multiOption.map((option) => ([
|
|
781
|
+
Object.assign(Object.assign({}, this.buildTooltip(option, type, grid)), { children: [
|
|
782
|
+
this.buildButton(option, type, grid),
|
|
783
|
+
] }),
|
|
784
|
+
this.buildDivider(option, type, grid),
|
|
785
|
+
]))
|
|
786
|
+
.flat();
|
|
787
|
+
optionComponents.pop();
|
|
788
|
+
const text = {
|
|
789
|
+
name: this.formatName('text', type, grid),
|
|
790
|
+
component: 'ZdText',
|
|
791
|
+
cssClass: 'zd-display-flex zd-align-center zd-flex-grow-1 tek-grid-export-multioption-text',
|
|
792
|
+
events: {
|
|
793
|
+
click: ({ event }) => event === null || event === void 0 ? void 0 : event.stopPropagation(),
|
|
794
|
+
},
|
|
795
|
+
text: label || '',
|
|
796
|
+
};
|
|
797
|
+
const result = {
|
|
798
|
+
name: this.formatName('row', type, grid),
|
|
799
|
+
component: 'ZdRow',
|
|
800
|
+
cssClass: 'zd-display-flex zd-ma-0 zd-py-0 zd-gap-x-1 tek-grid-export-multioption-row',
|
|
801
|
+
children: [text, ...optionComponents],
|
|
802
|
+
};
|
|
803
|
+
return result;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
718
807
|
class GridBase {
|
|
719
808
|
constructor(grid) {
|
|
720
809
|
this.exportConfigButtons = [];
|
|
@@ -739,20 +828,15 @@
|
|
|
739
828
|
this.grid = grid;
|
|
740
829
|
this.exportConfigButtons = this.getExportConfigButtons();
|
|
741
830
|
}
|
|
831
|
+
getOption(config) {
|
|
832
|
+
if (config.multiOption)
|
|
833
|
+
return new MultiOption(config);
|
|
834
|
+
return new ButtonOption(config);
|
|
835
|
+
}
|
|
742
836
|
getExportConfigButtons() {
|
|
743
837
|
return this.grid.exportConfig.map((config) => {
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
return {
|
|
747
|
-
label,
|
|
748
|
-
iconName,
|
|
749
|
-
name: `${this.grid.name}_export_${type}_${orientation}`,
|
|
750
|
-
component: 'ZdButton',
|
|
751
|
-
flat: true,
|
|
752
|
-
events: {
|
|
753
|
-
click: () => this.grid.getReport(type, portrait),
|
|
754
|
-
},
|
|
755
|
-
};
|
|
838
|
+
const option = this.getOption(config);
|
|
839
|
+
return option.buildComponent(this.grid);
|
|
756
840
|
});
|
|
757
841
|
}
|
|
758
842
|
createToolbarProps() {
|
|
@@ -1093,6 +1177,8 @@
|
|
|
1093
1177
|
TEKGRID_MULTIPLE_VALUE_HINT: 'Separe valores usando ";"',
|
|
1094
1178
|
TEKGRID_EXPORT: 'Exportar',
|
|
1095
1179
|
TEKGRID_EXPORT_AS: 'Exportar como {{ type }}',
|
|
1180
|
+
TEKGRID_PORTRAIT: 'Retrato',
|
|
1181
|
+
TEKGRID_LANDSCAPE: 'Paisagem',
|
|
1096
1182
|
TEKGRID_COLUMN_VISIBLE: 'Visível',
|
|
1097
1183
|
TEKGRID_COLUMN_GROUPED: 'Grupo',
|
|
1098
1184
|
TEKGRID_COLUMN_AGGREGATION: 'Totalização',
|
|
@@ -1162,6 +1248,8 @@
|
|
|
1162
1248
|
TEKGRID_MULTIPLE_VALUE_HINT: 'Separate values using ";"',
|
|
1163
1249
|
TEKGRID_EXPORT: 'Export',
|
|
1164
1250
|
TEKGRID_EXPORT_AS: 'Export as {{ type }}',
|
|
1251
|
+
TEKGRID_PORTRAIT: 'Portrait',
|
|
1252
|
+
TEKGRID_LANDSCAPE: 'Landscape',
|
|
1165
1253
|
TEKGRID_COLUMN_VISIBLE: 'Visible',
|
|
1166
1254
|
TEKGRID_COLUMN_GROUPED: 'Grouped',
|
|
1167
1255
|
TEKGRID_COLUMN_AGGREGATION: 'Aggregation',
|
|
@@ -1231,6 +1319,8 @@
|
|
|
1231
1319
|
TEKGRID_MULTIPLE_VALUE_HINT: 'Separe los valores usando ";"',
|
|
1232
1320
|
TEKGRID_EXPORT: 'Exportar',
|
|
1233
1321
|
TEKGRID_EXPORT_AS: 'Exportar como {{ type }}',
|
|
1322
|
+
TEKGRID_PORTRAIT: 'Vertical',
|
|
1323
|
+
TEKGRID_LANDSCAPE: 'Horizontal',
|
|
1234
1324
|
TEKGRID_COLUMN_VISIBLE: 'Visible',
|
|
1235
1325
|
TEKGRID_COLUMN_GROUPED: 'Grupo',
|
|
1236
1326
|
TEKGRID_COLUMN_AGGREGATION: 'Totalización',
|
|
@@ -2084,6 +2174,15 @@
|
|
|
2084
2174
|
{
|
|
2085
2175
|
type: 'pdf',
|
|
2086
2176
|
label: core.I18n.translate('TEKGRID_EXPORT_AS', { type: 'PDF' }),
|
|
2177
|
+
multiOption: [
|
|
2178
|
+
{ label: core.I18n.translate('TEKGRID_PORTRAIT'), iconName: 'mdi-file-outline' },
|
|
2179
|
+
{
|
|
2180
|
+
label: core.I18n.translate('TEKGRID_LANDSCAPE'),
|
|
2181
|
+
iconName: 'mdi-file-outline',
|
|
2182
|
+
cssClass: 'tek-grid-export-landscape',
|
|
2183
|
+
reportParams: { portrait: false },
|
|
2184
|
+
},
|
|
2185
|
+
],
|
|
2087
2186
|
},
|
|
2088
2187
|
{
|
|
2089
2188
|
type: 'xls',
|
|
@@ -2478,8 +2577,9 @@
|
|
|
2478
2577
|
resetFooterVariables(group) {
|
|
2479
2578
|
this.summaryColumns.forEach((column) => {
|
|
2480
2579
|
group.footer[column.name] = {
|
|
2481
|
-
sum: 0,
|
|
2482
2580
|
count: 0,
|
|
2581
|
+
sum: undefined,
|
|
2582
|
+
avg: undefined,
|
|
2483
2583
|
min: undefined,
|
|
2484
2584
|
max: undefined,
|
|
2485
2585
|
};
|
|
@@ -2488,17 +2588,24 @@
|
|
|
2488
2588
|
isUndefined(value) {
|
|
2489
2589
|
return value === undefined || value === null;
|
|
2490
2590
|
}
|
|
2491
|
-
calcSummaryValues(summary, rowValue) {
|
|
2591
|
+
calcSummaryValues(columnName, summary, rowValue) {
|
|
2492
2592
|
if (!this.isUndefined(rowValue)) {
|
|
2493
2593
|
summary.count += 1;
|
|
2494
|
-
if (
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2594
|
+
if (this.events.calcSummary) {
|
|
2595
|
+
this.callEvent('calcSummary', {
|
|
2596
|
+
component: this, columnName, summary, rowValue,
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
else {
|
|
2600
|
+
if (summary.min === undefined)
|
|
2601
|
+
summary.min = rowValue;
|
|
2602
|
+
if (summary.max === undefined)
|
|
2603
|
+
summary.max = rowValue;
|
|
2604
|
+
summary.min = rowValue < summary.min ? rowValue : summary.min;
|
|
2605
|
+
summary.max = rowValue > summary.max ? rowValue : summary.max;
|
|
2606
|
+
if (typeof rowValue === 'number') {
|
|
2607
|
+
summary.sum = (summary.sum || 0) + rowValue;
|
|
2608
|
+
}
|
|
2502
2609
|
}
|
|
2503
2610
|
}
|
|
2504
2611
|
}
|
|
@@ -2510,14 +2617,15 @@
|
|
|
2510
2617
|
if (this.isUndefined(this.summary[columnName])) {
|
|
2511
2618
|
this.summary[columnName] = {
|
|
2512
2619
|
count: 0,
|
|
2513
|
-
sum:
|
|
2620
|
+
sum: undefined,
|
|
2621
|
+
avg: undefined,
|
|
2514
2622
|
min: undefined,
|
|
2515
2623
|
max: undefined,
|
|
2516
2624
|
};
|
|
2517
2625
|
}
|
|
2518
|
-
this.calcSummaryValues(this.summary[columnName], rowValue);
|
|
2626
|
+
this.calcSummaryValues(columnName, this.summary[columnName], rowValue);
|
|
2519
2627
|
this.groups.forEach((group) => {
|
|
2520
|
-
this.calcSummaryValues(group.footer[columnName], rowValue);
|
|
2628
|
+
this.calcSummaryValues(columnName, group.footer[columnName], rowValue);
|
|
2521
2629
|
});
|
|
2522
2630
|
});
|
|
2523
2631
|
}
|
|
@@ -2540,7 +2648,12 @@
|
|
|
2540
2648
|
summaryData[column.name] = currentGroup.sum;
|
|
2541
2649
|
}
|
|
2542
2650
|
else if (aggregation === 'AVG') {
|
|
2543
|
-
|
|
2651
|
+
if (currentGroup.avg) {
|
|
2652
|
+
summaryData[column.name] = currentGroup.avg;
|
|
2653
|
+
}
|
|
2654
|
+
else if (typeof currentGroup.sum === 'number') {
|
|
2655
|
+
summaryData[column.name] = currentGroup.sum / currentGroup.count;
|
|
2656
|
+
}
|
|
2544
2657
|
}
|
|
2545
2658
|
else if (aggregation === 'MIN') {
|
|
2546
2659
|
summaryData[column.name] = currentGroup.min;
|
|
@@ -3402,10 +3515,33 @@
|
|
|
3402
3515
|
{
|
|
3403
3516
|
type: 'pdf',
|
|
3404
3517
|
label: core.I18n.translate('TEKGRID_EXPORT_AS', { type: 'PDF' }),
|
|
3518
|
+
multiOption: [
|
|
3519
|
+
{ label: core.I18n.translate('TEKGRID_PORTRAIT'), iconName: 'mdi-file-outline' },
|
|
3520
|
+
{
|
|
3521
|
+
label: core.I18n.translate('TEKGRID_LANDSCAPE'),
|
|
3522
|
+
iconName: 'mdi-file-outline',
|
|
3523
|
+
cssClass: 'tek-grid-export-landscape',
|
|
3524
|
+
reportParams: { portrait: false },
|
|
3525
|
+
},
|
|
3526
|
+
],
|
|
3405
3527
|
},
|
|
3406
3528
|
{
|
|
3407
3529
|
type: 'xls',
|
|
3408
|
-
label: core.I18n.translate('TEKGRID_EXPORT_AS', {
|
|
3530
|
+
label: core.I18n.translate('TEKGRID_EXPORT_AS', {
|
|
3531
|
+
type: `XLS ${core.I18n.translate('TEKGRID_WITHOUT_GROUPS')}`,
|
|
3532
|
+
}),
|
|
3533
|
+
},
|
|
3534
|
+
{
|
|
3535
|
+
type: 'xls2',
|
|
3536
|
+
label: core.I18n.translate('TEKGRID_EXPORT_AS', {
|
|
3537
|
+
type: `XLS ${core.I18n.translate('TEKGRID_WITH_GROUPS')}`,
|
|
3538
|
+
}),
|
|
3539
|
+
},
|
|
3540
|
+
{
|
|
3541
|
+
type: 'xls3',
|
|
3542
|
+
label: core.I18n.translate('TEKGRID_EXPORT_AS', {
|
|
3543
|
+
type: `XLS ${core.I18n.translate('TEKGRID_GRID_MIRROR')}`,
|
|
3544
|
+
}),
|
|
3409
3545
|
},
|
|
3410
3546
|
{
|
|
3411
3547
|
type: 'csv',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeedhi/teknisa-components-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.91.1",
|
|
4
4
|
"description": "Teknisa Components Common",
|
|
5
5
|
"author": "Zeedhi <zeedhi@teknisa.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@zeedhi/core": "*"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "12c0d9d2635c1d23829ff759b773223ea8f29b2d"
|
|
36
36
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
Button, Dropdown,
|
|
4
|
+
Button, Dropdown, IModal, Modal, ModalService, Search, TextInput, Text, Report,
|
|
5
5
|
} from '@zeedhi/common';
|
|
6
6
|
import {
|
|
7
|
-
KeyMap, Http, Metadata, IDictionary,
|
|
7
|
+
KeyMap, Http, Metadata, IDictionary, IEventParam,
|
|
8
8
|
} from '@zeedhi/core';
|
|
9
9
|
import {
|
|
10
10
|
ITekGrid,
|
|
@@ -157,48 +157,6 @@ describe('TekGrid', () => {
|
|
|
157
157
|
expect(instance.toolbarSlot.length).toBe(0);
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
-
it('should create default export buttons from exportConfig', () => {
|
|
161
|
-
const instance = new TekGrid({
|
|
162
|
-
name: 'grid',
|
|
163
|
-
component: 'TekGrid',
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
expect((instance as any).gridBase.exportConfigButtons[0].label).toBe('Export as PDF');
|
|
167
|
-
expect((instance as any).gridBase.exportConfigButtons[0].iconName).toBeUndefined();
|
|
168
|
-
expect((instance as any).gridBase.exportConfigButtons[0].name).toBe('grid_export_pdf_portrait');
|
|
169
|
-
expect((instance as any).gridBase.exportConfigButtons[0].component).toBe('ZdButton');
|
|
170
|
-
expect((instance as any).gridBase.exportConfigButtons[0].flat).toBeTruthy();
|
|
171
|
-
expect((instance as any).gridBase.exportConfigButtons[0].events).toBeDefined();
|
|
172
|
-
|
|
173
|
-
expect((instance as any).gridBase.exportConfigButtons[1].label).toBe('Export as XLS TEKGRID_WITHOUT_GROUPS');
|
|
174
|
-
expect((instance as any).gridBase.exportConfigButtons[1].iconName).toBeUndefined();
|
|
175
|
-
expect((instance as any).gridBase.exportConfigButtons[1].name).toBe('grid_export_xls_portrait');
|
|
176
|
-
expect((instance as any).gridBase.exportConfigButtons[1].component).toBe('ZdButton');
|
|
177
|
-
expect((instance as any).gridBase.exportConfigButtons[1].flat).toBeTruthy();
|
|
178
|
-
expect((instance as any).gridBase.exportConfigButtons[1].events).toBeDefined();
|
|
179
|
-
|
|
180
|
-
expect((instance as any).gridBase.exportConfigButtons[2].label).toBe('Export as XLS TEKGRID_WITH_GROUPS');
|
|
181
|
-
expect((instance as any).gridBase.exportConfigButtons[2].iconName).toBeUndefined();
|
|
182
|
-
expect((instance as any).gridBase.exportConfigButtons[2].name).toBe('grid_export_xls2_portrait');
|
|
183
|
-
expect((instance as any).gridBase.exportConfigButtons[2].component).toBe('ZdButton');
|
|
184
|
-
expect((instance as any).gridBase.exportConfigButtons[2].flat).toBeTruthy();
|
|
185
|
-
expect((instance as any).gridBase.exportConfigButtons[2].events).toBeDefined();
|
|
186
|
-
|
|
187
|
-
expect((instance as any).gridBase.exportConfigButtons[3].label).toBe('Export as XLS TEKGRID_GRID_MIRROR');
|
|
188
|
-
expect((instance as any).gridBase.exportConfigButtons[3].iconName).toBeUndefined();
|
|
189
|
-
expect((instance as any).gridBase.exportConfigButtons[3].name).toBe('grid_export_xls3_portrait');
|
|
190
|
-
expect((instance as any).gridBase.exportConfigButtons[3].component).toBe('ZdButton');
|
|
191
|
-
expect((instance as any).gridBase.exportConfigButtons[3].flat).toBeTruthy();
|
|
192
|
-
expect((instance as any).gridBase.exportConfigButtons[3].events).toBeDefined();
|
|
193
|
-
|
|
194
|
-
expect((instance as any).gridBase.exportConfigButtons[4].label).toBe('Export as CSV');
|
|
195
|
-
expect((instance as any).gridBase.exportConfigButtons[4].iconName).toBeUndefined();
|
|
196
|
-
expect((instance as any).gridBase.exportConfigButtons[4].name).toBe('grid_export_csv_portrait');
|
|
197
|
-
expect((instance as any).gridBase.exportConfigButtons[4].component).toBe('ZdButton');
|
|
198
|
-
expect((instance as any).gridBase.exportConfigButtons[4].flat).toBeTruthy();
|
|
199
|
-
expect((instance as any).gridBase.exportConfigButtons[4].events).toBeDefined();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
160
|
it('should change export buttons from exportConfig', () => {
|
|
203
161
|
const instance = new TekGrid({
|
|
204
162
|
name: 'grid',
|
|
@@ -243,44 +201,14 @@ describe('TekGrid', () => {
|
|
|
243
201
|
httpReportSpy.mockReset();
|
|
244
202
|
});
|
|
245
203
|
|
|
246
|
-
it('should call getReport on export button click', () => {
|
|
247
|
-
(window as any).open = jest.fn();
|
|
248
|
-
|
|
249
|
-
const instance = new TekGrid({
|
|
250
|
-
name: 'grid_getReport',
|
|
251
|
-
component: 'TekGrid',
|
|
252
|
-
events: {
|
|
253
|
-
beforeOpenReport: jest.fn(),
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
instance.onCreated();
|
|
258
|
-
|
|
259
|
-
const buttonProps = (instance as any).gridBase.exportConfigButtons[0] as IButton;
|
|
260
|
-
const button = new Button(buttonProps);
|
|
261
|
-
|
|
262
|
-
const event = new Event('click');
|
|
263
|
-
button.click(event, {} as HTMLElement);
|
|
264
|
-
|
|
265
|
-
expect(reportSpy).toBeCalledTimes(1);
|
|
266
|
-
|
|
267
|
-
(window as any).open.mockClear();
|
|
268
|
-
});
|
|
269
|
-
|
|
270
204
|
it('should call window open on getReport method', async () => {
|
|
271
205
|
(window as any).open = jest.fn();
|
|
272
206
|
|
|
273
207
|
const instance = new TekGrid({
|
|
274
208
|
name: 'grid',
|
|
275
209
|
component: 'TekGrid',
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
uniqueKey: 'id',
|
|
279
|
-
route: '/zeedhi',
|
|
280
|
-
lazyLoad: true,
|
|
281
|
-
data: [
|
|
282
|
-
{ id: '1', department_id: '1' },
|
|
283
|
-
],
|
|
210
|
+
events: {
|
|
211
|
+
beforeOpenReport: jest.fn(),
|
|
284
212
|
},
|
|
285
213
|
columns: [
|
|
286
214
|
{
|
|
@@ -1419,7 +1347,7 @@ describe('TekGrid', () => {
|
|
|
1419
1347
|
expect(instance.groupedData[5].salary).toBe(50);
|
|
1420
1348
|
});
|
|
1421
1349
|
|
|
1422
|
-
it('should
|
|
1350
|
+
it('should aggregate with different functions', async () => {
|
|
1423
1351
|
const instance = createAndMount({
|
|
1424
1352
|
name: 'grid_aggregate_4',
|
|
1425
1353
|
component: 'TekGrid',
|
|
@@ -1491,6 +1419,88 @@ describe('TekGrid', () => {
|
|
|
1491
1419
|
expect(instance.groupedData[6].column_count).toBe(3);
|
|
1492
1420
|
});
|
|
1493
1421
|
|
|
1422
|
+
it('should aggregate using calcSummary event', async () => {
|
|
1423
|
+
const doCalcSummary = ({ summary, rowValue }: IEventParam<any>) => {
|
|
1424
|
+
summary.sum = `${(summary.sum || '')}${rowValue}`;
|
|
1425
|
+
summary.avg = `${summary.sum}/${summary.count}`;
|
|
1426
|
+
summary.max = summary.max === undefined || summary.max < rowValue ? rowValue : summary.max;
|
|
1427
|
+
summary.min = summary.min === undefined || summary.min > rowValue ? rowValue : summary.min;
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
const instance = createAndMount({
|
|
1431
|
+
name: 'grid_aggregate_5',
|
|
1432
|
+
component: 'TekGrid',
|
|
1433
|
+
showSummaryTotal: true,
|
|
1434
|
+
events: {
|
|
1435
|
+
calcSummary: doCalcSummary,
|
|
1436
|
+
},
|
|
1437
|
+
columns: [
|
|
1438
|
+
{
|
|
1439
|
+
name: 'id',
|
|
1440
|
+
label: 'id',
|
|
1441
|
+
},
|
|
1442
|
+
{
|
|
1443
|
+
name: 'column_sum',
|
|
1444
|
+
label: 'sum',
|
|
1445
|
+
aggregation: 'SUM',
|
|
1446
|
+
},
|
|
1447
|
+
{
|
|
1448
|
+
name: 'column_min',
|
|
1449
|
+
label: 'min',
|
|
1450
|
+
aggregation: 'MIN',
|
|
1451
|
+
},
|
|
1452
|
+
{
|
|
1453
|
+
name: 'column_max',
|
|
1454
|
+
label: 'max',
|
|
1455
|
+
aggregation: 'MAX',
|
|
1456
|
+
},
|
|
1457
|
+
{
|
|
1458
|
+
name: 'column_avg',
|
|
1459
|
+
label: 'avg',
|
|
1460
|
+
aggregation: 'AVG',
|
|
1461
|
+
},
|
|
1462
|
+
{
|
|
1463
|
+
name: 'column_count',
|
|
1464
|
+
label: 'count',
|
|
1465
|
+
aggregation: 'COUNT',
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
name: 'department',
|
|
1469
|
+
label: 'department',
|
|
1470
|
+
grouped: true,
|
|
1471
|
+
},
|
|
1472
|
+
],
|
|
1473
|
+
datasource: {
|
|
1474
|
+
uniqueKey: 'id',
|
|
1475
|
+
data: [
|
|
1476
|
+
{
|
|
1477
|
+
id: 1, department: 1, column_sum: 'd', column_min: 'd', column_max: 'd', column_avg: 'd', column_count: 'd',
|
|
1478
|
+
},
|
|
1479
|
+
{
|
|
1480
|
+
id: 2, department: 1, column_sum: 'b', column_min: 'b', column_max: 'b', column_avg: 'b', column_count: 'b',
|
|
1481
|
+
},
|
|
1482
|
+
{
|
|
1483
|
+
id: 3, department: 1, column_sum: 'a', column_min: 'a', column_max: 'a', column_avg: 'a', column_count: 'a',
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
id: 4, department: 1, column_sum: 'c', column_min: 'c', column_max: 'c', column_avg: 'c', column_count: 'c',
|
|
1487
|
+
},
|
|
1488
|
+
],
|
|
1489
|
+
},
|
|
1490
|
+
});
|
|
1491
|
+
|
|
1492
|
+
await flushPromises();
|
|
1493
|
+
|
|
1494
|
+
expect(instance.datasource.data.length).toBe(4);
|
|
1495
|
+
expect(instance.groupedData.length).toBe(7);
|
|
1496
|
+
expect(instance.groupedData[6].groupSummary).toBeTruthy();
|
|
1497
|
+
expect(instance.groupedData[6].column_sum).toBe('dbac');
|
|
1498
|
+
expect(instance.groupedData[6].column_min).toBe('a');
|
|
1499
|
+
expect(instance.groupedData[6].column_max).toBe('d');
|
|
1500
|
+
expect(instance.groupedData[6].column_avg).toBe('dbac/4');
|
|
1501
|
+
expect(instance.groupedData[6].column_count).toBe(4);
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1494
1504
|
it('should group data on rest datasource with lazyLoad', async () => {
|
|
1495
1505
|
const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
|
|
1496
1506
|
data: {
|
|
@@ -477,44 +477,53 @@ describe('TekTreeGrid', () => {
|
|
|
477
477
|
httpReportSpy.mockClear();
|
|
478
478
|
});
|
|
479
479
|
|
|
480
|
-
it('should call
|
|
480
|
+
it('should call window open on getReport method', async () => {
|
|
481
481
|
(window as any).open = jest.fn();
|
|
482
482
|
|
|
483
483
|
const instance = new TekTreeGrid({
|
|
484
|
-
name: '
|
|
484
|
+
name: 'grid',
|
|
485
485
|
component: 'TekTreeGrid',
|
|
486
486
|
events: {
|
|
487
487
|
beforeOpenReport: jest.fn(),
|
|
488
488
|
},
|
|
489
|
+
datasource: {
|
|
490
|
+
type: 'tek-rest',
|
|
491
|
+
uniqueKey: 'id',
|
|
492
|
+
route: '/zeedhi',
|
|
493
|
+
lazyLoad: false,
|
|
494
|
+
data: [
|
|
495
|
+
{ id: '1', department_id: '1' },
|
|
496
|
+
],
|
|
497
|
+
},
|
|
498
|
+
columns: [
|
|
499
|
+
{
|
|
500
|
+
name: 'id',
|
|
501
|
+
label: 'ID',
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
name: 'department_id',
|
|
505
|
+
label: 'Department ID',
|
|
506
|
+
},
|
|
507
|
+
],
|
|
489
508
|
});
|
|
490
509
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
const buttonProps = (instance as any).gridBase.exportConfigButtons[0] as IButton;
|
|
494
|
-
const button = new Button(buttonProps);
|
|
495
|
-
|
|
496
|
-
const event = new Event('click');
|
|
497
|
-
button.click(event, {} as HTMLElement);
|
|
510
|
+
const spy = jest.spyOn(window, 'open');
|
|
511
|
+
await instance.getReport('pdf');
|
|
498
512
|
|
|
499
|
-
expect(
|
|
513
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
500
514
|
|
|
501
515
|
(window as any).open.mockClear();
|
|
516
|
+
spy.mockClear();
|
|
502
517
|
});
|
|
503
518
|
|
|
504
|
-
it('should call window open on getReport method', async () => {
|
|
519
|
+
it('should call window open on getReport method when using tekmemorydatasource', async () => {
|
|
505
520
|
(window as any).open = jest.fn();
|
|
506
521
|
|
|
507
522
|
const instance = new TekTreeGrid({
|
|
508
523
|
name: 'grid',
|
|
509
524
|
component: 'TekTreeGrid',
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
uniqueKey: 'id',
|
|
513
|
-
route: '/zeedhi',
|
|
514
|
-
lazyLoad: false,
|
|
515
|
-
data: [
|
|
516
|
-
{ id: '1', department_id: '1' },
|
|
517
|
-
],
|
|
525
|
+
events: {
|
|
526
|
+
beforeOpenReport: jest.fn(),
|
|
518
527
|
},
|
|
519
528
|
columns: [
|
|
520
529
|
{
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Button } from '@zeedhi/common';
|
|
2
|
+
import { TekGrid } from '../../../../../src/components';
|
|
3
|
+
import { ButtonOption } from '../../../../../src/utils';
|
|
4
|
+
|
|
5
|
+
describe('ButtonOption', () => {
|
|
6
|
+
describe('buildComponent()', () => {
|
|
7
|
+
it('when called, should build a simple button component', () => {
|
|
8
|
+
const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
9
|
+
const config = {
|
|
10
|
+
type: 'pdf',
|
|
11
|
+
label: 'Exportar PDF',
|
|
12
|
+
};
|
|
13
|
+
const option = new ButtonOption(config);
|
|
14
|
+
|
|
15
|
+
const component = option.buildComponent(grid);
|
|
16
|
+
|
|
17
|
+
expect(component).toEqual(expect.objectContaining({
|
|
18
|
+
label: config.label,
|
|
19
|
+
name: 'Grid_export_pdf_portrait',
|
|
20
|
+
component: 'ZdButton',
|
|
21
|
+
iconName: undefined,
|
|
22
|
+
flat: true,
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('the generated button component should call grid.getReport on click', () => {
|
|
27
|
+
const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
28
|
+
const spy = jest.fn();
|
|
29
|
+
grid.getReport = spy;
|
|
30
|
+
const config = {
|
|
31
|
+
type: 'pdf',
|
|
32
|
+
label: 'Exportar PDF',
|
|
33
|
+
};
|
|
34
|
+
const option = new ButtonOption(config);
|
|
35
|
+
|
|
36
|
+
const component = option.buildComponent(grid);
|
|
37
|
+
|
|
38
|
+
const instance = new Button(component);
|
|
39
|
+
instance.click();
|
|
40
|
+
|
|
41
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Button, IText, Text } from '@zeedhi/common';
|
|
2
|
+
import { ITekGridExportConfig, TekGrid } from '../../../../../src/components';
|
|
3
|
+
import { MultiOption } from '../../../../../src/utils';
|
|
4
|
+
|
|
5
|
+
describe('MultiOption', () => {
|
|
6
|
+
describe('buildComponent()', () => {
|
|
7
|
+
it('when called, should build a row with multiple buttons', () => {
|
|
8
|
+
const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
9
|
+
const config: ITekGridExportConfig = {
|
|
10
|
+
type: 'pdf',
|
|
11
|
+
label: 'Exportar PDF',
|
|
12
|
+
multiOption: [
|
|
13
|
+
{ label: 'portrait', iconName: 'icon-portrait' },
|
|
14
|
+
{ label: 'landscape', iconName: 'icon-landscape' },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
const option = new MultiOption(config);
|
|
18
|
+
|
|
19
|
+
const component = option.buildComponent(grid);
|
|
20
|
+
|
|
21
|
+
expect(component).toEqual({
|
|
22
|
+
name: 'Grid_export_pdf_row',
|
|
23
|
+
component: 'ZdRow',
|
|
24
|
+
cssClass: 'zd-display-flex zd-ma-0 zd-py-0 zd-gap-x-1 tek-grid-export-multioption-row',
|
|
25
|
+
children: [
|
|
26
|
+
expect.objectContaining({
|
|
27
|
+
name: 'Grid_export_pdf_text',
|
|
28
|
+
component: 'ZdText',
|
|
29
|
+
text: 'Exportar PDF',
|
|
30
|
+
cssClass: 'zd-display-flex zd-align-center zd-flex-grow-1 tek-grid-export-multioption-text',
|
|
31
|
+
}),
|
|
32
|
+
{
|
|
33
|
+
name: 'Grid_export_pdf_tooltip_portrait',
|
|
34
|
+
component: 'ZdTooltip',
|
|
35
|
+
bottom: true,
|
|
36
|
+
label: 'portrait',
|
|
37
|
+
children: [
|
|
38
|
+
expect.objectContaining({
|
|
39
|
+
name: 'Grid_export_pdf_button_portrait',
|
|
40
|
+
component: 'ZdButton',
|
|
41
|
+
icon: true,
|
|
42
|
+
iconName: 'icon-portrait',
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
expect.objectContaining({
|
|
47
|
+
name: 'Grid_export_pdf_divider_portrait',
|
|
48
|
+
component: 'ZdDivider',
|
|
49
|
+
cssClass: 'zd-my-1',
|
|
50
|
+
vertical: true,
|
|
51
|
+
}),
|
|
52
|
+
{
|
|
53
|
+
name: 'Grid_export_pdf_tooltip_landscape',
|
|
54
|
+
component: 'ZdTooltip',
|
|
55
|
+
bottom: true,
|
|
56
|
+
label: 'landscape',
|
|
57
|
+
children: [
|
|
58
|
+
expect.objectContaining({
|
|
59
|
+
name: 'Grid_export_pdf_button_landscape',
|
|
60
|
+
component: 'ZdButton',
|
|
61
|
+
icon: true,
|
|
62
|
+
iconName: 'icon-landscape',
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('the generated text component should call stopPropagation on click', () => {
|
|
71
|
+
const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
72
|
+
const config: ITekGridExportConfig = {
|
|
73
|
+
type: 'pdf',
|
|
74
|
+
label: 'Exportar PDF',
|
|
75
|
+
multiOption: [
|
|
76
|
+
{ label: 'portrait', iconName: 'icon-portrait' },
|
|
77
|
+
{ label: 'landscape', iconName: 'icon-landscape' },
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
const option = new MultiOption(config);
|
|
81
|
+
|
|
82
|
+
const component = option.buildComponent(grid);
|
|
83
|
+
|
|
84
|
+
const instance = new Text(component.children![0] as IText);
|
|
85
|
+
const spy = jest.fn();
|
|
86
|
+
const event = { stopPropagation: spy } as unknown as Event;
|
|
87
|
+
instance.click(event);
|
|
88
|
+
|
|
89
|
+
expect(spy).toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('the generated text component should not throw if event is undefined', () => {
|
|
93
|
+
const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
94
|
+
const config: ITekGridExportConfig = {
|
|
95
|
+
type: 'pdf',
|
|
96
|
+
label: 'Exportar PDF',
|
|
97
|
+
multiOption: [
|
|
98
|
+
{ label: 'portrait', iconName: 'icon-portrait' },
|
|
99
|
+
{ label: 'landscape', iconName: 'icon-landscape' },
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
const option = new MultiOption(config);
|
|
103
|
+
|
|
104
|
+
const component = option.buildComponent(grid);
|
|
105
|
+
|
|
106
|
+
const instance = new Text(component.children![0] as IText);
|
|
107
|
+
|
|
108
|
+
expect(() => instance.callEvent('click', { event: undefined })).not.toThrow();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('the generated button components should call grid.getReport on click', () => {
|
|
112
|
+
const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
113
|
+
const spy = jest.fn();
|
|
114
|
+
grid.getReport = spy;
|
|
115
|
+
const config: ITekGridExportConfig = {
|
|
116
|
+
type: 'pdf',
|
|
117
|
+
multiOption: [
|
|
118
|
+
{ label: 'portrait', iconName: 'icon-portrait' },
|
|
119
|
+
{ label: 'landscape', iconName: 'icon-landscape' },
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
const option = new MultiOption(config);
|
|
123
|
+
|
|
124
|
+
const component = option.buildComponent(grid);
|
|
125
|
+
|
|
126
|
+
const instance = new Button(component.children![1].children![0]);
|
|
127
|
+
instance.click();
|
|
128
|
+
|
|
129
|
+
const instance2 = new Button(component.children![3].children![0]);
|
|
130
|
+
instance2.click();
|
|
131
|
+
|
|
132
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -4,8 +4,13 @@ import { IDynamicFilterItem, TekGrid, TekGridLayoutOptions, TekTreeGrid } from '
|
|
|
4
4
|
export interface ITekGridLayoutEventParams extends IEventParam<ITekGrid> {
|
|
5
5
|
layouts: ITekGridLayoutInfo;
|
|
6
6
|
}
|
|
7
|
+
export interface ITekGridCalcSummaryEventParams extends IEventParam<ITekGrid> {
|
|
8
|
+
summary: ITekGridSummary;
|
|
9
|
+
columnName: string;
|
|
10
|
+
rowValue: IDictionary<any>;
|
|
11
|
+
}
|
|
7
12
|
export declare type ITekGridEvent<T> = (event: T) => Promise<any>;
|
|
8
|
-
export interface ITekGridEvents<T = IEventParam<any> | ITekGridLayoutEventParams> extends IComponentEvents<T> {
|
|
13
|
+
export interface ITekGridEvents<T = IEventParam<any> | ITekGridLayoutEventParams | ITekGridCalcSummaryEventParams> extends IComponentEvents<T> {
|
|
9
14
|
addClick?: EventDef<T>;
|
|
10
15
|
afterCancel?: EventDef<T>;
|
|
11
16
|
afterDelete?: EventDef<T>;
|
|
@@ -14,6 +19,7 @@ export interface ITekGridEvents<T = IEventParam<any> | ITekGridLayoutEventParams
|
|
|
14
19
|
beforeCancel?: EventDef<T>;
|
|
15
20
|
beforeDelete?: EventDef<T>;
|
|
16
21
|
beforeSave?: EventDef<T>;
|
|
22
|
+
calcSummary?: EventDef<T>;
|
|
17
23
|
filterClick?: EventDef<T>;
|
|
18
24
|
loadLayouts?: EventDef<T, ITekGridEvent<T>>;
|
|
19
25
|
saveLayouts?: EventDef<T>;
|
|
@@ -54,11 +60,21 @@ export interface ITekGrid extends IGridEditable {
|
|
|
54
60
|
layoutOptions?: TekGridLayoutOptions;
|
|
55
61
|
mainGrid?: boolean;
|
|
56
62
|
}
|
|
63
|
+
export declare type MultiOptionParams = {
|
|
64
|
+
iconName: string;
|
|
65
|
+
label: string;
|
|
66
|
+
cssClass?: string;
|
|
67
|
+
reportParams?: {
|
|
68
|
+
portrait?: boolean;
|
|
69
|
+
rowObj?: any;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
57
72
|
export interface ITekGridExportConfig {
|
|
58
73
|
type: string;
|
|
59
74
|
portrait?: boolean;
|
|
60
75
|
label?: string;
|
|
61
76
|
iconName?: string;
|
|
77
|
+
multiOption?: MultiOptionParams[];
|
|
62
78
|
}
|
|
63
79
|
export interface ITekGridLayoutInfo {
|
|
64
80
|
currentLayoutName?: string;
|
|
@@ -141,7 +157,8 @@ export interface ITekGridFooter {
|
|
|
141
157
|
[key: string]: ITekGridSummary;
|
|
142
158
|
}
|
|
143
159
|
export interface ITekGridSummary {
|
|
144
|
-
sum:
|
|
160
|
+
sum: any;
|
|
161
|
+
avg: any;
|
|
145
162
|
count: number;
|
|
146
163
|
min: any;
|
|
147
164
|
max: any;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ITekGridExportConfig, TekGrid, TekTreeGrid } from '../../../components';
|
|
2
|
+
import { IExportOption } from './interfaces';
|
|
3
|
+
export declare class ButtonOption implements IExportOption {
|
|
4
|
+
private config;
|
|
5
|
+
constructor(config: ITekGridExportConfig);
|
|
6
|
+
buildComponent(grid: TekGrid | TekTreeGrid): {
|
|
7
|
+
label: string | undefined;
|
|
8
|
+
iconName: string | undefined;
|
|
9
|
+
name: string;
|
|
10
|
+
component: string;
|
|
11
|
+
flat: boolean;
|
|
12
|
+
events: {
|
|
13
|
+
click: () => any;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IRow } from '@zeedhi/common';
|
|
2
|
+
import { ITekGridExportConfig, TekGrid, TekTreeGrid } from '../../../components';
|
|
3
|
+
import { IExportOption } from './interfaces';
|
|
4
|
+
export declare class MultiOption implements IExportOption {
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: ITekGridExportConfig);
|
|
7
|
+
private formatName;
|
|
8
|
+
private buildTooltip;
|
|
9
|
+
private buildButton;
|
|
10
|
+
private buildDivider;
|
|
11
|
+
buildComponent(grid: TekGrid | TekTreeGrid): IRow;
|
|
12
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IComponentRender } from '@zeedhi/common';
|
|
2
2
|
import { IEventParam } from '@zeedhi/core';
|
|
3
3
|
import { TekGrid, TekGridFilterButton, TekTreeGrid } from '../../components';
|
|
4
4
|
export interface ITekGridAtoms {
|
|
@@ -23,6 +23,7 @@ export declare class GridBase {
|
|
|
23
23
|
private grid;
|
|
24
24
|
private exportConfigButtons;
|
|
25
25
|
constructor(grid: TekGrid | TekTreeGrid);
|
|
26
|
+
private getOption;
|
|
26
27
|
private getExportConfigButtons;
|
|
27
28
|
createToolbarProps(): ({
|
|
28
29
|
name: string;
|
|
@@ -153,7 +154,7 @@ export declare class GridBase {
|
|
|
153
154
|
iconName: string;
|
|
154
155
|
isVisible: string;
|
|
155
156
|
};
|
|
156
|
-
children:
|
|
157
|
+
children: IComponentRender[];
|
|
157
158
|
label?: undefined;
|
|
158
159
|
bottom?: undefined;
|
|
159
160
|
vertical?: undefined;
|
package/types/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
1
|
+
export * from './report-filter/report-filter';
|
|
2
|
+
export * from './grid-base/grid-base';
|
|
3
|
+
export * from './grid-base/grid-controller';
|
|
4
|
+
export * from './grid-base/export-options';
|
|
5
|
+
export * from './config/config';
|