cx 25.10.0 → 25.11.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.
@@ -1,140 +1,143 @@
1
- import { ArrayAdapter } from "./ArrayAdapter";
2
- import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
3
- import { Grouper } from "../../data/Grouper";
4
- import { isArray } from "../../util/isArray";
5
- import { isDefined } from "../../util/isDefined";
6
- import { getComparer } from "../../data/comparer";
7
- import { Culture } from "../Culture";
8
- import { isObject } from "../../util/isObject";
9
-
10
- export class GroupAdapter extends ArrayAdapter {
11
- init() {
12
- super.init();
13
-
14
- if (this.groupRecordsAlias) this.groupRecordsName = this.groupRecordsAlias;
15
-
16
- if (this.groupings) this.groupBy(this.groupings);
17
- }
18
-
19
- getRecords(context, instance, records, parentStore) {
20
- let result = super.getRecords(context, instance, records, parentStore);
21
-
22
- if (this.groupings) {
23
- let groupedResults = [];
24
- this.processLevel([], result, groupedResults, parentStore);
25
- result = groupedResults;
26
- }
27
-
28
- return result;
29
- }
30
-
31
- processLevel(keys, records, result, parentStore) {
32
- let level = keys.length;
33
- let inverseLevel = this.groupings.length - level;
34
-
35
- if (inverseLevel == 0) {
36
- for (let i = 0; i < records.length; i++) {
37
- records[i].store.setStore(parentStore);
38
- result.push(records[i]);
39
- }
40
- return;
41
- }
42
-
43
- let grouping = this.groupings[level];
44
- let { grouper } = grouping;
45
- grouper.reset();
46
- grouper.processAll(records);
47
- let results = grouper.getResults();
48
- if (grouping.comparer) results.sort(grouping.comparer);
49
-
50
- results.forEach((gr) => {
51
- keys.push(gr.key);
52
-
53
- let key = keys.map(serializeKey).join("|");
54
-
55
- let $group = {
56
- ...gr.key,
57
- ...gr.aggregates,
58
- $name: gr.name,
59
- $level: inverseLevel,
60
- $records: gr.records || [],
61
- $key: key,
62
- };
63
-
64
- let data = {
65
- [this.recordName]: gr.records.length > 0 ? gr.records[0].data : null,
66
- [this.groupName]: $group,
67
- };
68
-
69
- let groupStore = new ReadOnlyDataView({
70
- store: parentStore,
71
- data,
72
- immutable: this.immutable,
73
- });
74
-
75
- let group = {
76
- key,
77
- data,
78
- group: $group,
79
- grouping,
80
- store: groupStore,
81
- level: inverseLevel,
82
- };
83
-
84
- if (grouping.includeHeader !== false)
85
- result.push({
86
- ...group,
87
- type: "group-header",
88
- key: "header:" + group.key,
89
- });
90
-
91
- this.processLevel(keys, gr.records, result, groupStore);
92
-
93
- if (grouping.includeFooter !== false)
94
- result.push({
95
- ...group,
96
- type: "group-footer",
97
- key: "footer:" + group.key,
98
- });
99
-
100
- keys.pop();
101
- });
102
- }
103
-
104
- groupBy(groupings) {
105
- if (!groupings) this.groupings = null;
106
- else if (isArray(groupings)) {
107
- this.groupings = groupings;
108
- this.groupings.forEach((g) => {
109
- let groupSorters = [];
110
- let key = {};
111
- for (let name in g.key) {
112
- if (!g.key[name] || !isDefined(g.key[name].direction) || !isDefined(g.key[name].value))
113
- g.key[name] = { value: g.key[name], direction: "ASC" };
114
- key[name] = g.key[name].value;
115
- groupSorters.push({
116
- field: name,
117
- direction: g.key[name].direction,
118
- });
119
- }
120
- g.grouper = new Grouper(key, { ...this.aggregates, ...g.aggregates }, (r) => r.store.getData(), g.text);
121
- if (g.comparer == null && groupSorters.length > 0)
122
- g.comparer = getComparer(
123
- groupSorters,
124
- (x) => x.key,
125
- this.sortOptions ? Culture.getComparer(this.sortOptions) : null,
126
- );
127
- });
128
- } else throw new Error("Invalid grouping provided.");
129
- }
130
- }
131
-
132
- GroupAdapter.prototype.groupName = "$group";
133
-
134
- function serializeKey(data) {
135
- if (isObject(data))
136
- return Object.keys(data)
137
- .map((k) => serializeKey(data[k]))
138
- .join(":");
139
- return data?.toString() ?? "";
140
- }
1
+ import { ArrayAdapter } from "./ArrayAdapter";
2
+ import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
3
+ import { Grouper } from "../../data/Grouper";
4
+ import { isArray } from "../../util/isArray";
5
+ import { isDefined } from "../../util/isDefined";
6
+ import { getComparer } from "../../data/comparer";
7
+ import { Culture } from "../Culture";
8
+ import { isObject } from "../../util/isObject";
9
+
10
+ export class GroupAdapter extends ArrayAdapter {
11
+ init() {
12
+ super.init();
13
+
14
+ if (this.groupRecordsAlias) this.groupRecordsName = this.groupRecordsAlias;
15
+
16
+ if (this.groupings) this.groupBy(this.groupings);
17
+ }
18
+
19
+ getRecords(context, instance, records, parentStore) {
20
+ let result = super.getRecords(context, instance, records, parentStore);
21
+
22
+ if (this.groupings) {
23
+ let groupedResults = [];
24
+ this.processLevel([], result, groupedResults, parentStore);
25
+ result = groupedResults;
26
+ }
27
+
28
+ return result;
29
+ }
30
+
31
+ processLevel(keys, records, result, parentStore) {
32
+ let level = keys.length;
33
+ let inverseLevel = this.groupings.length - level;
34
+
35
+ if (inverseLevel == 0) {
36
+ if (this.preserveOrder && this.sorter) records = this.sorter(records);
37
+ for (let i = 0; i < records.length; i++) {
38
+ records[i].store.setStore(parentStore);
39
+ result.push(records[i]);
40
+ }
41
+ return;
42
+ }
43
+
44
+ let grouping = this.groupings[level];
45
+ let { grouper } = grouping;
46
+ grouper.reset();
47
+ grouper.processAll(records);
48
+ let results = grouper.getResults();
49
+
50
+ if (grouping.comparer && !this.preserveOrder) results.sort(grouping.comparer);
51
+
52
+ results.forEach((gr) => {
53
+ keys.push(gr.key);
54
+
55
+ let key = keys.map(serializeKey).join("|");
56
+
57
+ let $group = {
58
+ ...gr.key,
59
+ ...gr.aggregates,
60
+ $name: gr.name,
61
+ $level: inverseLevel,
62
+ $records: gr.records || [],
63
+ $key: key,
64
+ };
65
+
66
+ let data = {
67
+ [this.recordName]: gr.records.length > 0 ? gr.records[0].data : null,
68
+ [this.groupName]: $group,
69
+ };
70
+
71
+ let groupStore = new ReadOnlyDataView({
72
+ store: parentStore,
73
+ data,
74
+ immutable: this.immutable,
75
+ });
76
+
77
+ let group = {
78
+ key,
79
+ data,
80
+ group: $group,
81
+ grouping,
82
+ store: groupStore,
83
+ level: inverseLevel,
84
+ };
85
+
86
+ if (grouping.includeHeader !== false)
87
+ result.push({
88
+ ...group,
89
+ type: "group-header",
90
+ key: "header:" + group.key,
91
+ });
92
+
93
+ this.processLevel(keys, gr.records, result, groupStore);
94
+
95
+ if (grouping.includeFooter !== false)
96
+ result.push({
97
+ ...group,
98
+ type: "group-footer",
99
+ key: "footer:" + group.key,
100
+ });
101
+
102
+ keys.pop();
103
+ });
104
+ }
105
+
106
+ groupBy(groupings) {
107
+ if (!groupings) this.groupings = null;
108
+ else if (isArray(groupings)) {
109
+ this.groupings = groupings;
110
+ this.groupings.forEach((g) => {
111
+ let groupSorters = [];
112
+ let key = {};
113
+ for (let name in g.key) {
114
+ if (!g.key[name] || !isDefined(g.key[name].direction) || !isDefined(g.key[name].value))
115
+ g.key[name] = { value: g.key[name], direction: "ASC" };
116
+ key[name] = g.key[name].value;
117
+ groupSorters.push({
118
+ field: name,
119
+ direction: g.key[name].direction,
120
+ });
121
+ }
122
+ g.grouper = new Grouper(key, { ...this.aggregates, ...g.aggregates }, (r) => r.store.getData(), g.text);
123
+ if (g.comparer == null && groupSorters.length > 0)
124
+ g.comparer = getComparer(
125
+ groupSorters,
126
+ (x) => x.key,
127
+ this.sortOptions ? Culture.getComparer(this.sortOptions) : null,
128
+ );
129
+ });
130
+ } else throw new Error("Invalid grouping provided.");
131
+ }
132
+ }
133
+
134
+ GroupAdapter.prototype.groupName = "$group";
135
+ GroupAdapter.prototype.preserveOrder = false;
136
+
137
+ function serializeKey(data) {
138
+ if (isObject(data))
139
+ return Object.keys(data)
140
+ .map((k) => serializeKey(data[k]))
141
+ .join(":");
142
+ return data?.toString() ?? "";
143
+ }