ngx-axis-appforge 0.0.84 → 0.0.86
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/axis-components/table/index.d.ts +1 -0
- package/axis-components/table-helper/index.d.ts +34 -6
- package/fesm2022/ngx-axis-appforge-axis-components-table-design.mjs +7 -2
- package/fesm2022/ngx-axis-appforge-axis-components-table-design.mjs.map +1 -1
- package/fesm2022/ngx-axis-appforge-axis-components-table-helper.mjs +184 -35
- package/fesm2022/ngx-axis-appforge-axis-components-table-helper.mjs.map +1 -1
- package/fesm2022/ngx-axis-appforge-axis-components-table.mjs +28 -13
- package/fesm2022/ngx-axis-appforge-axis-components-table.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ class TableFieldDisplayService {
|
|
|
29
29
|
if (!this.fieldDisplayCache.has(field.field())) {
|
|
30
30
|
this.fieldDisplayCache.set(field.field(), new Map());
|
|
31
31
|
}
|
|
32
|
-
if (!this.fieldDisplayCache.get(field.field()).has(row[field.field()])) {
|
|
32
|
+
if (row[field.field()] === undefined || !this.fieldDisplayCache.get(field.field()).has(row[field.field()])) {
|
|
33
33
|
const child = this.scope?.snapshotOptions(field.child(), { row, loopRow });
|
|
34
34
|
let text;
|
|
35
35
|
switch (child.component) {
|
|
@@ -61,6 +61,9 @@ class TableFieldDisplayService {
|
|
|
61
61
|
text = child.text;
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
64
|
+
if (row[field.field()] === undefined) {
|
|
65
|
+
return text;
|
|
66
|
+
}
|
|
64
67
|
this.fieldDisplayCache.get(field.field()).set(row[field.field()], text);
|
|
65
68
|
}
|
|
66
69
|
return this.fieldDisplayCache.get(field.field()).get(row[field.field()]);
|
|
@@ -117,6 +120,7 @@ class TableService {
|
|
|
117
120
|
}
|
|
118
121
|
ready = signal(false, ...(ngDevMode ? [{ debugName: "ready" }] : []));
|
|
119
122
|
data;
|
|
123
|
+
customExportData;
|
|
120
124
|
options;
|
|
121
125
|
fields;
|
|
122
126
|
getRow;
|
|
@@ -126,7 +130,13 @@ class TableService {
|
|
|
126
130
|
fields.sort((a, b) => (a.groupLevel() ?? 0) - (b.groupLevel() ?? 0));
|
|
127
131
|
return fields;
|
|
128
132
|
}, ...(ngDevMode ? [{ debugName: "groupAbleFields" }] : []));
|
|
133
|
+
groupAbleFieldsForExport = computed(() => {
|
|
134
|
+
const fields = this.fields().filter(f => f.groupAble() && f.export?.());
|
|
135
|
+
fields.sort((a, b) => (a.groupLevel() ?? 0) - (b.groupLevel() ?? 0));
|
|
136
|
+
return fields;
|
|
137
|
+
}, ...(ngDevMode ? [{ debugName: "groupAbleFieldsForExport" }] : []));
|
|
129
138
|
rowsGroupMap = computed(() => this.buildRowsGroupMap(), ...(ngDevMode ? [{ debugName: "rowsGroupMap" }] : []));
|
|
139
|
+
rowsGroupMapForExport = computed(() => this.buildRowsGroupMapForExport(), ...(ngDevMode ? [{ debugName: "rowsGroupMapForExport" }] : []));
|
|
130
140
|
useBackEndPaging = computed(() => this.options.showPagination() && this.options.useBackEndPaging(), ...(ngDevMode ? [{ debugName: "useBackEndPaging" }] : []));
|
|
131
141
|
rows = computed(() => this.useBackEndPaging() ? this.data()?.rows : this.data(), ...(ngDevMode ? [{ debugName: "rows" }] : []));
|
|
132
142
|
pageIndex = signal(1, ...(ngDevMode ? [{ debugName: "pageIndex" }] : []));
|
|
@@ -139,6 +149,7 @@ class TableService {
|
|
|
139
149
|
return this.fields().filter(f => f.inuse());
|
|
140
150
|
}, ...(ngDevMode ? [{ debugName: "displayFields" }] : []));
|
|
141
151
|
fieldsControlsMap = signal({}, ...(ngDevMode ? [{ debugName: "fieldsControlsMap" }] : []));
|
|
152
|
+
tableDataForExport = computed(() => this.buildTableDataForExport(), ...(ngDevMode ? [{ debugName: "tableDataForExport" }] : []));
|
|
142
153
|
tableData = signal([], ...(ngDevMode ? [{ debugName: "tableData" }] : []));
|
|
143
154
|
fieldsFilterValueMap = new Map();
|
|
144
155
|
filedsFilterItemsCache = new Map();
|
|
@@ -148,6 +159,7 @@ class TableService {
|
|
|
148
159
|
pageCursorMarkIndexs = [];
|
|
149
160
|
init(opts) {
|
|
150
161
|
this.data = opts.data;
|
|
162
|
+
this.customExportData = opts.customExportData;
|
|
151
163
|
this.options = opts.options;
|
|
152
164
|
this.fields = opts.fields;
|
|
153
165
|
this.getRow = opts.getRow;
|
|
@@ -155,6 +167,58 @@ class TableService {
|
|
|
155
167
|
this.ready.set(true);
|
|
156
168
|
this.refreshTableData();
|
|
157
169
|
}
|
|
170
|
+
buildTableDataForExport() {
|
|
171
|
+
const data = [...(this.customExportData?.() ?? this.tableData())];
|
|
172
|
+
const sortFields = this.fields().filter(f => f.export?.() && this.fieldSortAble(f) && f.sortOrder() != null);
|
|
173
|
+
if (sortFields.length) {
|
|
174
|
+
sortFields.sort((a, b) => {
|
|
175
|
+
let ap = this.fieldSortPriority(a, this.groupAbleFieldsForExport());
|
|
176
|
+
let bp = this.fieldSortPriority(b, this.groupAbleFieldsForExport());
|
|
177
|
+
if (ap === bp) {
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
if (ap === false) {
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
else if (bp === false) {
|
|
184
|
+
return -1;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
return bp - ap;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
data.sort((a, b) => {
|
|
191
|
+
for (const f of sortFields) {
|
|
192
|
+
let sortFn = this.fieldsControlsMap()[f.field()]?.sortFn;
|
|
193
|
+
if (typeof sortFn != "function") {
|
|
194
|
+
sortFn = (a, b) => {
|
|
195
|
+
const va = a[f.field()];
|
|
196
|
+
const vb = b[f.field()];
|
|
197
|
+
const ta = typeof va;
|
|
198
|
+
const tb = typeof vb;
|
|
199
|
+
if (ta == tb) {
|
|
200
|
+
if (ta == "number") {
|
|
201
|
+
return va - vb;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return va.localeCompare(vb);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else if (ta == "number") {
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const res = sortFn(a, b);
|
|
213
|
+
if (res != 0) {
|
|
214
|
+
return res * (f.sortOrder() == "descend" ? -1 : 1);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return 0;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return data;
|
|
221
|
+
}
|
|
158
222
|
refreshTableData() {
|
|
159
223
|
let data = [...(this.rows() ?? [])];
|
|
160
224
|
if (!this.useBackEndPaging()) {
|
|
@@ -210,13 +274,20 @@ class TableService {
|
|
|
210
274
|
this.tableData.set(data);
|
|
211
275
|
}
|
|
212
276
|
buildRowsGroupMap() {
|
|
277
|
+
return this._buildRowsGroupMap(this.useBackEndPaging() ? this.data() : this.tableData(), this.useBackEndPaging());
|
|
278
|
+
}
|
|
279
|
+
buildRowsGroupMapForExport() {
|
|
280
|
+
return this._buildRowsGroupMap(this.tableDataForExport(), false, this.groupAbleFieldsForExport());
|
|
281
|
+
}
|
|
282
|
+
_buildRowsGroupMap(data, useBackEndPaging = false, groupAbleFields) {
|
|
213
283
|
const rowsGroupMap = new Map();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
284
|
+
groupAbleFields ??= this.groupAbleFields();
|
|
285
|
+
if (!useBackEndPaging) {
|
|
286
|
+
if (groupAbleFields.length > 0) {
|
|
287
|
+
for (let i = 0; i < data.length; i++) {
|
|
217
288
|
let valuePerfix = "";
|
|
218
|
-
const row =
|
|
219
|
-
for (const field of
|
|
289
|
+
const row = data[i];
|
|
290
|
+
for (const field of groupAbleFields) {
|
|
220
291
|
if (!rowsGroupMap.has(field.field())) {
|
|
221
292
|
rowsGroupMap.set(field.field(), new Map());
|
|
222
293
|
}
|
|
@@ -234,6 +305,15 @@ class TableService {
|
|
|
234
305
|
}
|
|
235
306
|
}
|
|
236
307
|
}
|
|
308
|
+
else {
|
|
309
|
+
for (const field in data.group_result ?? {}) {
|
|
310
|
+
const groups = new Map();
|
|
311
|
+
for (const value in data.group_result[field]) {
|
|
312
|
+
groups.set(value, data.group_result[field][value]);
|
|
313
|
+
}
|
|
314
|
+
rowsGroupMap.set(field, groups);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
237
317
|
return rowsGroupMap;
|
|
238
318
|
}
|
|
239
319
|
fieldSortAble(f) {
|
|
@@ -242,14 +322,15 @@ class TableService {
|
|
|
242
322
|
fieldSortDirections(f) {
|
|
243
323
|
return f.groupAble() ? ['ascend', 'descend'] : ['ascend', 'descend', null];
|
|
244
324
|
}
|
|
245
|
-
fieldSortPriority(f) {
|
|
325
|
+
fieldSortPriority(f, groupAbleFields) {
|
|
246
326
|
if (f.groupAble()) {
|
|
247
327
|
return (f.groupLevel() ?? 0) * -1;
|
|
248
328
|
}
|
|
329
|
+
groupAbleFields ??= this.groupAbleFields();
|
|
249
330
|
if (f.sortAble()) {
|
|
250
331
|
let p = 0;
|
|
251
|
-
if (
|
|
252
|
-
p =
|
|
332
|
+
if (groupAbleFields.length) {
|
|
333
|
+
p = groupAbleFields[groupAbleFields.length - 1].groupLevel() ?? 0;
|
|
253
334
|
p *= -1;
|
|
254
335
|
}
|
|
255
336
|
return (p - 1 + (f.sortPriority() ?? 0));
|
|
@@ -259,6 +340,9 @@ class TableService {
|
|
|
259
340
|
getGroupValue(row) {
|
|
260
341
|
return row[this.groupAbleFields()[0].field()];
|
|
261
342
|
}
|
|
343
|
+
getGroupValueForExport(row) {
|
|
344
|
+
return row[this.groupAbleFieldsForExport()[0].field()];
|
|
345
|
+
}
|
|
262
346
|
isGroupEnd(index, row) {
|
|
263
347
|
const topGroupField = this.groupAbleFields()[0];
|
|
264
348
|
if (!topGroupField) {
|
|
@@ -270,6 +354,17 @@ class TableService {
|
|
|
270
354
|
}
|
|
271
355
|
return false;
|
|
272
356
|
}
|
|
357
|
+
isGroupEndForExport(index, row) {
|
|
358
|
+
const topGroupField = this.groupAbleFieldsForExport()[0];
|
|
359
|
+
if (!topGroupField) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
const indexs = this.rowsGroupMapForExport().get(topGroupField.field())?.get(row[topGroupField.field()]?.toString());
|
|
363
|
+
if (indexs) {
|
|
364
|
+
return indexs[indexs.length - 1] == index;
|
|
365
|
+
}
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
273
368
|
rowspan(f, index, pageIndex, pageSize, row) {
|
|
274
369
|
if (f.groupAble()) {
|
|
275
370
|
const value = this.groupAbleFields().slice(0, this.groupAbleFields().findIndex(_f => _f.field() == f.field()) + 1).map(_f => row[_f.field()]).join("@");
|
|
@@ -455,13 +550,16 @@ class TableService {
|
|
|
455
550
|
this.pageCursorMarks.clear();
|
|
456
551
|
}
|
|
457
552
|
get backEndPageParams() {
|
|
553
|
+
const sortFields = this.displayFields().filter(f => this.fieldSortAble(f) && f.sortOrder() != null);
|
|
554
|
+
sortFields.sort((a, b) => this.fieldSortPriority(b) - this.fieldSortPriority(a));
|
|
458
555
|
return {
|
|
459
556
|
use_page: true,
|
|
460
557
|
page_index: this.pageIndex() - 1,
|
|
461
558
|
page_size: this.options.pageSize(),
|
|
462
559
|
query_total: !this.hasTotal,
|
|
463
560
|
cursor_mark: this.getNearestCursorMark(),
|
|
464
|
-
|
|
561
|
+
group_fields: this.groupAbleFields().map(f => f.field()),
|
|
562
|
+
order_by: sortFields.map(f => ({
|
|
465
563
|
column: f.field(),
|
|
466
564
|
desc_order: f.sortOrder() == "descend"
|
|
467
565
|
}))
|
|
@@ -477,8 +575,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
|
|
|
477
575
|
const AXIS_TABLE_SELECT_TOKEN = new InjectionToken('axis.tableSelect');
|
|
478
576
|
var ChangeScene;
|
|
479
577
|
(function (ChangeScene) {
|
|
480
|
-
ChangeScene[ChangeScene["
|
|
481
|
-
ChangeScene[ChangeScene["
|
|
578
|
+
ChangeScene[ChangeScene["refreshHeader"] = 0] = "refreshHeader";
|
|
579
|
+
ChangeScene[ChangeScene["userClick"] = 1] = "userClick";
|
|
580
|
+
ChangeScene[ChangeScene["linkage"] = 2] = "linkage";
|
|
482
581
|
})(ChangeScene || (ChangeScene = {}));
|
|
483
582
|
class SelectService {
|
|
484
583
|
scope;
|
|
@@ -505,8 +604,11 @@ class SelectService {
|
|
|
505
604
|
setOfDisabledId = signal(new Set(), ...(ngDevMode ? [{ debugName: "setOfDisabledId" }] : []));
|
|
506
605
|
subs = [];
|
|
507
606
|
subSelects = new Map();
|
|
607
|
+
useBackEndPaging = computed(() => this.options.showPagination() && this.options.useBackEndPaging(), ...(ngDevMode ? [{ debugName: "useBackEndPaging" }] : []));
|
|
608
|
+
dataCache = new Map();
|
|
609
|
+
selectedRows = computed(() => this.buildSelectedData(), ...(ngDevMode ? [{ debugName: "selectedRows" }] : []));
|
|
508
610
|
get rows() {
|
|
509
|
-
if (this.
|
|
611
|
+
if (this.useBackEndPaging()) {
|
|
510
612
|
return this.data()?.rows;
|
|
511
613
|
}
|
|
512
614
|
else {
|
|
@@ -523,7 +625,6 @@ class SelectService {
|
|
|
523
625
|
setOfCheckedId.add(item);
|
|
524
626
|
}
|
|
525
627
|
this.setOfCheckedId.set(setOfCheckedId);
|
|
526
|
-
untracked(() => this.refreshCheckedStatus(ChangeScene.userClick));
|
|
527
628
|
if (opts.onSelectedChange) {
|
|
528
629
|
this.subs.push(this.changeSubject.subscribe(_ => {
|
|
529
630
|
opts.onSelectedChange(this.setOfCheckedId());
|
|
@@ -633,7 +734,7 @@ class SelectService {
|
|
|
633
734
|
this.setOfCheckedId().delete(key);
|
|
634
735
|
}
|
|
635
736
|
}
|
|
636
|
-
refreshCheckedStatus(scene) {
|
|
737
|
+
refreshCheckedStatus(scene = ChangeScene.userClick) {
|
|
637
738
|
const listOfEnabledData = this.rows?.filter(row => !this.setOfDisabledId().has(row[this.keyField])) ?? [];
|
|
638
739
|
const checked = listOfEnabledData.length > 0 && listOfEnabledData.every(row => this.setOfCheckedId().has(row[this.keyField]) && !this.setOfIndeterminateId().has(row[this.keyField]));
|
|
639
740
|
if (checked) {
|
|
@@ -643,12 +744,31 @@ class SelectService {
|
|
|
643
744
|
const indeterminate = listOfEnabledData.some(row => this.setOfCheckedId().has(row[this.keyField]) || this.setOfIndeterminateId().has(row[this.keyField])) && !checked;
|
|
644
745
|
this.headerChecked.set(indeterminate ? "indeterminate" : "none");
|
|
645
746
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
747
|
+
if (scene != ChangeScene.refreshHeader) {
|
|
748
|
+
this.setOfCheckedId.set(new Set([...this.setOfCheckedId()]));
|
|
749
|
+
this.setOfIndeterminateId.set(new Set([...this.setOfIndeterminateId()]));
|
|
750
|
+
this.changeSubject.next(scene);
|
|
751
|
+
}
|
|
649
752
|
}
|
|
650
|
-
|
|
651
|
-
|
|
753
|
+
buildSelectedData() {
|
|
754
|
+
if (this.useBackEndPaging()) {
|
|
755
|
+
const res = [];
|
|
756
|
+
if (this.rows) {
|
|
757
|
+
for (const row of this.rows) {
|
|
758
|
+
if (this.dataCache.has(row[this.keyField])) {
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
this.dataCache.set(row[this.keyField], row);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
for (const id of this.setOfCheckedId()) {
|
|
765
|
+
res.push(this.dataCache.get(id));
|
|
766
|
+
}
|
|
767
|
+
return res;
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
return this.rows?.filter(row => this.setOfCheckedId().has(row[this.keyField]));
|
|
771
|
+
}
|
|
652
772
|
}
|
|
653
773
|
close() {
|
|
654
774
|
for (const sub of this.subs) {
|
|
@@ -752,9 +872,12 @@ class StatisticService {
|
|
|
752
872
|
fields;
|
|
753
873
|
getRow;
|
|
754
874
|
tableSvc;
|
|
875
|
+
useBackEndPaging = computed(() => this.options.showPagination() && this.options.useBackEndPaging(), ...(ngDevMode ? [{ debugName: "useBackEndPaging" }] : []));
|
|
755
876
|
hasStatistic = false;
|
|
756
877
|
statisticMap = computed(() => this.buildStatisticMap(), ...(ngDevMode ? [{ debugName: "statisticMap" }] : []));
|
|
878
|
+
statisticMapForExport = computed(() => this.buildStatisticMapForExport(), ...(ngDevMode ? [{ debugName: "statisticMapForExport" }] : []));
|
|
757
879
|
statisticGroupMap = computed(() => this.buildStatisticGroupMap(), ...(ngDevMode ? [{ debugName: "statisticGroupMap" }] : []));
|
|
880
|
+
statisticGroupMapForExport = computed(() => this.buildStatisticGroupMapForExport(), ...(ngDevMode ? [{ debugName: "statisticGroupMapForExport" }] : []));
|
|
758
881
|
init(opts) {
|
|
759
882
|
this.options = opts.options;
|
|
760
883
|
this.data = opts.data;
|
|
@@ -764,36 +887,62 @@ class StatisticService {
|
|
|
764
887
|
this.ready.set(true);
|
|
765
888
|
}
|
|
766
889
|
buildStatisticMap() {
|
|
890
|
+
return this._buildStatisticMap(this.data());
|
|
891
|
+
}
|
|
892
|
+
buildStatisticMapForExport() {
|
|
893
|
+
return this._buildStatisticMap(this.tableSvc?.customExportData?.() ?? this.data());
|
|
894
|
+
}
|
|
895
|
+
_buildStatisticMap(data) {
|
|
767
896
|
if (!this.ready()) {
|
|
768
897
|
return {};
|
|
769
898
|
}
|
|
770
899
|
let res = {};
|
|
771
|
-
if (this.options.showStatistic() &&
|
|
772
|
-
if (this.
|
|
773
|
-
res =
|
|
900
|
+
if (this.options.showStatistic() && data) {
|
|
901
|
+
if (this.useBackEndPaging()) {
|
|
902
|
+
res = data.statistic_result;
|
|
774
903
|
}
|
|
775
904
|
else {
|
|
776
|
-
res = this.statisticCompute(
|
|
905
|
+
res = this.statisticCompute(data);
|
|
777
906
|
}
|
|
778
907
|
}
|
|
779
|
-
return res;
|
|
908
|
+
return res ?? {};
|
|
780
909
|
}
|
|
781
910
|
buildStatisticGroupMap() {
|
|
911
|
+
if (!this.ready() || !this.tableSvc) {
|
|
912
|
+
return {};
|
|
913
|
+
}
|
|
914
|
+
return this._buildStatisticGroupMap(this.tableSvc.tableData(), this.useBackEndPaging());
|
|
915
|
+
}
|
|
916
|
+
buildStatisticGroupMapForExport() {
|
|
917
|
+
if (!this.ready() || !this.tableSvc) {
|
|
918
|
+
return {};
|
|
919
|
+
}
|
|
920
|
+
return this._buildStatisticGroupMap(this.tableSvc.tableDataForExport(), false, this.tableSvc.groupAbleFieldsForExport(), this.tableSvc.rowsGroupMapForExport());
|
|
921
|
+
}
|
|
922
|
+
_buildStatisticGroupMap(data, useBackEndPaging = false, groupAbleFields, rowsGroupMap) {
|
|
782
923
|
if (!this.ready() || !this.tableSvc) {
|
|
783
924
|
return {};
|
|
784
925
|
}
|
|
785
926
|
let res = {};
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
res = this.data().statistic_result;
|
|
927
|
+
if (useBackEndPaging) {
|
|
928
|
+
if (data?.query_statistic_group) {
|
|
929
|
+
res = data.statistic_group_result ?? {};
|
|
790
930
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
931
|
+
}
|
|
932
|
+
else {
|
|
933
|
+
groupAbleFields ??= this.tableSvc.groupAbleFields();
|
|
934
|
+
const groupField = groupAbleFields[0];
|
|
935
|
+
if (this.options.showStatistic() && groupField) {
|
|
936
|
+
if (useBackEndPaging) {
|
|
937
|
+
res = data.statistic_result;
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
rowsGroupMap ??= this.tableSvc.rowsGroupMap();
|
|
941
|
+
const group = rowsGroupMap.get(groupField.field());
|
|
942
|
+
if (group) {
|
|
943
|
+
for (const [value, indexs] of group) {
|
|
944
|
+
res[value] = this.statisticCompute(indexs.map(index => data[index]));
|
|
945
|
+
}
|
|
797
946
|
}
|
|
798
947
|
}
|
|
799
948
|
}
|