@hpcc-js/dgrid 3.5.9 → 3.7.0
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/LICENSE +43 -43
- package/README.md +31 -31
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +2 -2
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +6 -8
- package/src/Common.css +587 -494
- package/src/Common.ts +178 -166
- package/src/DBStore.ts +91 -90
- package/src/DatasourceStore.ts +127 -126
- package/src/DatasourceTable.ts +62 -62
- package/src/RowFormatter.ts +147 -146
- package/src/Table.ts +263 -246
- package/src/__package__.ts +3 -3
- package/src/__tests__/index.ts +1 -1
- package/src/__tests__/test1.ts +50 -50
- package/src/dgrid-shim.ts +20 -12
- package/src/i18n.js +11 -11
- package/src/index.ts +10 -10
- package/types/Common.d.ts +8 -5
- package/types/RowFormatter.d.ts +1 -0
- package/types/Table.d.ts +7 -0
- package/types/dgrid-shim.d.ts +1 -1
package/src/DatasourceStore.ts
CHANGED
|
@@ -1,126 +1,127 @@
|
|
|
1
|
-
import type { DDL2 } from "@hpcc-js/ddl-shim";
|
|
2
|
-
import { Deferred, QueryResults } from "./dgrid-shim.ts";
|
|
3
|
-
import { ColumnType, RowFormatter } from "./RowFormatter.ts";
|
|
4
|
-
|
|
5
|
-
export interface IDatasource {
|
|
6
|
-
id: () => string;
|
|
7
|
-
hash: () => string;
|
|
8
|
-
label: () => string;
|
|
9
|
-
|
|
10
|
-
outFields: () => DDL2.IField[];
|
|
11
|
-
total: () => number;
|
|
12
|
-
fetch: (from: number, count: number) => Promise<ReadonlyArray<object>>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class DatasourceCache implements IDatasource {
|
|
16
|
-
protected _datasource: IDatasource;
|
|
17
|
-
_prevHash: string;
|
|
18
|
-
_fetchCache: { [key: string]: Promise<ReadonlyArray<object>> } = {};
|
|
19
|
-
|
|
20
|
-
constructor(datasource: IDatasource) {
|
|
21
|
-
this._datasource = datasource;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
validateCache() {
|
|
25
|
-
const hash = this.hash();
|
|
26
|
-
if (this._prevHash !== hash) {
|
|
27
|
-
this._prevHash = hash;
|
|
28
|
-
this._fetchCache = {};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
id() { return this._datasource.id(); }
|
|
33
|
-
hash() { return this._datasource.hash(); }
|
|
34
|
-
label() { return this._datasource.label(); }
|
|
35
|
-
|
|
36
|
-
outFields() { return this._datasource.outFields(); }
|
|
37
|
-
total() { return this._datasource.total(); }
|
|
38
|
-
fetch(from: number, count: number): Promise<ReadonlyArray<object>> {
|
|
39
|
-
this.validateCache();
|
|
40
|
-
const cacheID = `${from}->${count}`;
|
|
41
|
-
let retVal = this._fetchCache[cacheID];
|
|
42
|
-
if (!retVal) {
|
|
43
|
-
retVal = this._datasource.fetch(from, count);
|
|
44
|
-
this._fetchCache[cacheID] = retVal;
|
|
45
|
-
}
|
|
46
|
-
return retVal;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export class DatasourceStore {
|
|
51
|
-
_datasource: DatasourceCache;
|
|
52
|
-
_columnsIdx: { [key: string]: number } = {};
|
|
53
|
-
_columns;
|
|
54
|
-
|
|
55
|
-
private rowFormatter: RowFormatter;
|
|
56
|
-
|
|
57
|
-
constructor(datasource: IDatasource, renderHtml: boolean) {
|
|
58
|
-
this._datasource = new DatasourceCache(datasource);
|
|
59
|
-
|
|
60
|
-
this._columnsIdx = {};
|
|
61
|
-
this._columns = this.db2Columns(this._datasource.outFields()).map((column, idx) => {
|
|
62
|
-
this._columnsIdx[column.field] = idx;
|
|
63
|
-
return column;
|
|
64
|
-
});
|
|
65
|
-
this.rowFormatter = new RowFormatter(this._columns, renderHtml);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
columns() {
|
|
69
|
-
return this._columns;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
db2Columns(fields: DDL2.IField[], prefix = ""): ColumnType[] {
|
|
73
|
-
if (!fields) return [];
|
|
74
|
-
return fields.map((field, idx) => {
|
|
75
|
-
const column: ColumnType = {
|
|
76
|
-
field: prefix + field.id,
|
|
77
|
-
leafID: field.id,
|
|
78
|
-
label: field.id,
|
|
79
|
-
idx,
|
|
80
|
-
className: "resultGridCell",
|
|
81
|
-
sortable: true,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
formattedRow
|
|
111
|
-
formattedRow.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
1
|
+
import type { DDL2 } from "@hpcc-js/ddl-shim";
|
|
2
|
+
import { Deferred, QueryResults } from "./dgrid-shim.ts";
|
|
3
|
+
import { ColumnType, RowFormatter } from "./RowFormatter.ts";
|
|
4
|
+
|
|
5
|
+
export interface IDatasource {
|
|
6
|
+
id: () => string;
|
|
7
|
+
hash: () => string;
|
|
8
|
+
label: () => string;
|
|
9
|
+
|
|
10
|
+
outFields: () => DDL2.IField[];
|
|
11
|
+
total: () => number;
|
|
12
|
+
fetch: (from: number, count: number) => Promise<ReadonlyArray<object>>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class DatasourceCache implements IDatasource {
|
|
16
|
+
protected _datasource: IDatasource;
|
|
17
|
+
_prevHash: string;
|
|
18
|
+
_fetchCache: { [key: string]: Promise<ReadonlyArray<object>> } = {};
|
|
19
|
+
|
|
20
|
+
constructor(datasource: IDatasource) {
|
|
21
|
+
this._datasource = datasource;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
validateCache() {
|
|
25
|
+
const hash = this.hash();
|
|
26
|
+
if (this._prevHash !== hash) {
|
|
27
|
+
this._prevHash = hash;
|
|
28
|
+
this._fetchCache = {};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
id() { return this._datasource.id(); }
|
|
33
|
+
hash() { return this._datasource.hash(); }
|
|
34
|
+
label() { return this._datasource.label(); }
|
|
35
|
+
|
|
36
|
+
outFields() { return this._datasource.outFields(); }
|
|
37
|
+
total() { return this._datasource.total(); }
|
|
38
|
+
fetch(from: number, count: number): Promise<ReadonlyArray<object>> {
|
|
39
|
+
this.validateCache();
|
|
40
|
+
const cacheID = `${from}->${count}`;
|
|
41
|
+
let retVal = this._fetchCache[cacheID];
|
|
42
|
+
if (!retVal) {
|
|
43
|
+
retVal = this._datasource.fetch(from, count);
|
|
44
|
+
this._fetchCache[cacheID] = retVal;
|
|
45
|
+
}
|
|
46
|
+
return retVal;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class DatasourceStore {
|
|
51
|
+
_datasource: DatasourceCache;
|
|
52
|
+
_columnsIdx: { [key: string]: number } = {};
|
|
53
|
+
_columns;
|
|
54
|
+
|
|
55
|
+
private rowFormatter: RowFormatter;
|
|
56
|
+
|
|
57
|
+
constructor(datasource: IDatasource, renderHtml: boolean) {
|
|
58
|
+
this._datasource = new DatasourceCache(datasource);
|
|
59
|
+
|
|
60
|
+
this._columnsIdx = {};
|
|
61
|
+
this._columns = this.db2Columns(this._datasource.outFields()).map((column, idx) => {
|
|
62
|
+
this._columnsIdx[column.field] = idx;
|
|
63
|
+
return column;
|
|
64
|
+
});
|
|
65
|
+
this.rowFormatter = new RowFormatter(this._columns, renderHtml);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
columns() {
|
|
69
|
+
return this._columns;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
db2Columns(fields: DDL2.IField[], prefix = ""): ColumnType[] {
|
|
73
|
+
if (!fields) return [];
|
|
74
|
+
return fields.map((field, idx) => {
|
|
75
|
+
const column: ColumnType = {
|
|
76
|
+
field: prefix + field.id,
|
|
77
|
+
leafID: field.id,
|
|
78
|
+
label: field.id,
|
|
79
|
+
idx,
|
|
80
|
+
className: "resultGridCell",
|
|
81
|
+
sortable: true,
|
|
82
|
+
hidden: false,
|
|
83
|
+
isSet: false
|
|
84
|
+
};
|
|
85
|
+
if (field.type === "dataset") {
|
|
86
|
+
column.children = this.db2Columns(field.children, prefix + field.id + "_");
|
|
87
|
+
} else {
|
|
88
|
+
column.formatter = (cell, row) => {
|
|
89
|
+
switch (typeof cell) {
|
|
90
|
+
case "string":
|
|
91
|
+
return cell.replace(/\t/g, " ");
|
|
92
|
+
}
|
|
93
|
+
return cell;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return column;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getIdentity(row) {
|
|
101
|
+
return row.__hpcc_id;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_request(start, end): Promise<{ totalLength: number, data: any[] }> {
|
|
105
|
+
if (!this._datasource) return Promise.resolve({ totalLength: 0, data: [] });
|
|
106
|
+
const retVal = this._datasource.fetch(start, end - start).then(response => {
|
|
107
|
+
return {
|
|
108
|
+
totalLength: this._datasource.total(),
|
|
109
|
+
data: response.map((row, idx) => {
|
|
110
|
+
const formattedRow: any = this.rowFormatter.format(row);
|
|
111
|
+
formattedRow.__hpcc_id = start + idx;
|
|
112
|
+
formattedRow.__origRow = row;
|
|
113
|
+
return formattedRow;
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
return retVal;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
fetchRange(options): Promise<any[]> {
|
|
121
|
+
const retVal = new Deferred();
|
|
122
|
+
this._request(options.start, options.end).then(response => retVal.resolve(response));
|
|
123
|
+
return new QueryResults(retVal.then(response => response.data), {
|
|
124
|
+
totalLength: retVal.then(response => response.totalLength)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
package/src/DatasourceTable.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { Widget } from "@hpcc-js/common";
|
|
2
|
-
import { Memory } from "./dgrid-shim.ts";
|
|
3
|
-
import { Common } from "./Common.ts";
|
|
4
|
-
import { DatasourceStore, IDatasource } from "./DatasourceStore.ts";
|
|
5
|
-
|
|
6
|
-
export class DatasourceTable extends Common {
|
|
7
|
-
_prevDatasource?: IDatasource;
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
invalidate(): this {
|
|
14
|
-
delete this._prevDatasource;
|
|
15
|
-
return this;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
enter(domNode, element) {
|
|
19
|
-
super.enter(domNode, element);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
update(domNode, element) {
|
|
23
|
-
super.update(domNode, element);
|
|
24
|
-
}
|
|
25
|
-
render(callback?: (w: Widget) => void): this {
|
|
26
|
-
return super.render(w => {
|
|
27
|
-
if (this._prevDatasource !== this.datasource()) {
|
|
28
|
-
this._dgrid.set("collection", new Memory());
|
|
29
|
-
this._dgrid.set("columns", []);
|
|
30
|
-
this._prevDatasource = this.datasource();
|
|
31
|
-
if (this._prevDatasource) {
|
|
32
|
-
const store = new DatasourceStore(this._prevDatasource, this.renderHtml());
|
|
33
|
-
this._dgrid.set("columns", store.columns());
|
|
34
|
-
this._dgrid.set("collection", store);
|
|
35
|
-
if (callback) {
|
|
36
|
-
callback(w);
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
if (callback) {
|
|
40
|
-
callback(w);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
if (callback) {
|
|
45
|
-
callback(w);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
click(row, col, sel) {
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
DatasourceTable.prototype._class += " dgrid_DatasourceTable";
|
|
55
|
-
|
|
56
|
-
export interface DatasourceTable {
|
|
57
|
-
datasource(): IDatasource;
|
|
58
|
-
datasource(_: IDatasource): this;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
DatasourceTable.prototype.publish("datasource", null, "object", "Datasource");
|
|
62
|
-
|
|
1
|
+
import { Widget } from "@hpcc-js/common";
|
|
2
|
+
import { Memory } from "./dgrid-shim.ts";
|
|
3
|
+
import { Common } from "./Common.ts";
|
|
4
|
+
import { DatasourceStore, IDatasource } from "./DatasourceStore.ts";
|
|
5
|
+
|
|
6
|
+
export class DatasourceTable extends Common {
|
|
7
|
+
_prevDatasource?: IDatasource;
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
invalidate(): this {
|
|
14
|
+
delete this._prevDatasource;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
enter(domNode, element) {
|
|
19
|
+
super.enter(domNode, element);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
update(domNode, element) {
|
|
23
|
+
super.update(domNode, element);
|
|
24
|
+
}
|
|
25
|
+
render(callback?: (w: Widget) => void): this {
|
|
26
|
+
return super.render(w => {
|
|
27
|
+
if (this._prevDatasource !== this.datasource()) {
|
|
28
|
+
this._dgrid.set("collection", new Memory());
|
|
29
|
+
this._dgrid.set("columns", []);
|
|
30
|
+
this._prevDatasource = this.datasource();
|
|
31
|
+
if (this._prevDatasource) {
|
|
32
|
+
const store = new DatasourceStore(this._prevDatasource, this.renderHtml());
|
|
33
|
+
this._dgrid.set("columns", store.columns());
|
|
34
|
+
this._dgrid.set("collection", store);
|
|
35
|
+
if (callback) {
|
|
36
|
+
callback(w);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
if (callback) {
|
|
40
|
+
callback(w);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
if (callback) {
|
|
45
|
+
callback(w);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
click(row, col, sel) {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
DatasourceTable.prototype._class += " dgrid_DatasourceTable";
|
|
55
|
+
|
|
56
|
+
export interface DatasourceTable {
|
|
57
|
+
datasource(): IDatasource;
|
|
58
|
+
datasource(_: IDatasource): this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
DatasourceTable.prototype.publish("datasource", null, "object", "Datasource");
|
|
62
|
+
|