@nocobase/plugin-charts 0.9.1-alpha.2
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/client.d.ts +4 -0
- package/client.js +30 -0
- package/lib/client/ChartBlockEngine.d.ts +27 -0
- package/lib/client/ChartBlockEngine.js +201 -0
- package/lib/client/ChartBlockEngineDesigner.d.ts +3 -0
- package/lib/client/ChartBlockEngineDesigner.js +348 -0
- package/lib/client/ChartBlockInitializer.d.ts +3 -0
- package/lib/client/ChartBlockInitializer.js +324 -0
- package/lib/client/ChartQueryBlockInitializer.d.ts +9 -0
- package/lib/client/ChartQueryBlockInitializer.js +230 -0
- package/lib/client/ChartQueryMetadataProvider.d.ts +10 -0
- package/lib/client/ChartQueryMetadataProvider.js +118 -0
- package/lib/client/DataSetPreviewTable.d.ts +5 -0
- package/lib/client/DataSetPreviewTable.js +127 -0
- package/lib/client/Icons.d.ts +1 -0
- package/lib/client/Icons.js +226 -0
- package/lib/client/chartRenderComponents/index.d.ts +2 -0
- package/lib/client/chartRenderComponents/index.js +26 -0
- package/lib/client/hooks/index.d.ts +4 -0
- package/lib/client/hooks/index.js +52 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client/index.js +161 -0
- package/lib/client/locale/en-US.d.ts +23 -0
- package/lib/client/locale/en-US.js +29 -0
- package/lib/client/locale/index.d.ts +3 -0
- package/lib/client/locale/index.js +46 -0
- package/lib/client/locale/ja-JP.d.ts +2 -0
- package/lib/client/locale/ja-JP.js +8 -0
- package/lib/client/locale/ru-RU.d.ts +2 -0
- package/lib/client/locale/ru-RU.js +8 -0
- package/lib/client/locale/tr-TR.d.ts +2 -0
- package/lib/client/locale/tr-TR.js +8 -0
- package/lib/client/locale/zh-CN.d.ts +61 -0
- package/lib/client/locale/zh-CN.js +67 -0
- package/lib/client/select/CustomSelect.d.ts +11 -0
- package/lib/client/select/CustomSelect.js +193 -0
- package/lib/client/select/ReadPretty.d.ts +2 -0
- package/lib/client/select/ReadPretty.js +102 -0
- package/lib/client/select/index.d.ts +2 -0
- package/lib/client/select/index.js +31 -0
- package/lib/client/select/shared.d.ts +7 -0
- package/lib/client/select/shared.js +86 -0
- package/lib/client/settings/AddNewQuery.d.ts +2 -0
- package/lib/client/settings/AddNewQuery.js +321 -0
- package/lib/client/settings/ConfigureFields.d.ts +1 -0
- package/lib/client/settings/ConfigureFields.js +51 -0
- package/lib/client/settings/QueriesTable.d.ts +1 -0
- package/lib/client/settings/QueriesTable.js +108 -0
- package/lib/client/settings/queryTypes.d.ts +5 -0
- package/lib/client/settings/queryTypes.js +85 -0
- package/lib/client/settings/schemas/chartsQueries.d.ts +8 -0
- package/lib/client/settings/schemas/chartsQueries.js +378 -0
- package/lib/client/templates/AreaTemplate.d.ts +65 -0
- package/lib/client/templates/AreaTemplate.js +86 -0
- package/lib/client/templates/BarTemplate.d.ts +80 -0
- package/lib/client/templates/BarTemplate.js +103 -0
- package/lib/client/templates/ColumnTemplate.d.ts +80 -0
- package/lib/client/templates/ColumnTemplate.js +103 -0
- package/lib/client/templates/FunnelTemplate.d.ts +66 -0
- package/lib/client/templates/FunnelTemplate.js +87 -0
- package/lib/client/templates/LineTemplate.d.ts +67 -0
- package/lib/client/templates/LineTemplate.js +92 -0
- package/lib/client/templates/PieTemplate.d.ts +71 -0
- package/lib/client/templates/PieTemplate.js +92 -0
- package/lib/client/templates/RadarTemplate.d.ts +71 -0
- package/lib/client/templates/RadarTemplate.js +93 -0
- package/lib/client/templates/ScatterTemplate.d.ts +91 -0
- package/lib/client/templates/ScatterTemplate.js +112 -0
- package/lib/client/templates/TableTemplate.d.ts +28 -0
- package/lib/client/templates/TableTemplate.js +54 -0
- package/lib/client/templates/index.d.ts +1 -0
- package/lib/client/templates/index.js +33 -0
- package/lib/client/utils.d.ts +3 -0
- package/lib/client/utils.js +66 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +15 -0
- package/lib/server/actions/chartsQueries.d.ts +3 -0
- package/lib/server/actions/chartsQueries.js +104 -0
- package/lib/server/actions/index.d.ts +1 -0
- package/lib/server/actions/index.js +1 -0
- package/lib/server/collections/chartsQueries.d.ts +2 -0
- package/lib/server/collections/chartsQueries.js +36 -0
- package/lib/server/index.d.ts +1 -0
- package/lib/server/index.js +15 -0
- package/lib/server/plugin.d.ts +14 -0
- package/lib/server/plugin.js +142 -0
- package/lib/server/query.d.ts +12 -0
- package/lib/server/query.js +91 -0
- package/lib/server/shared/index.d.ts +2 -0
- package/lib/server/shared/index.js +8 -0
- package/package.json +14 -0
- package/server.d.ts +4 -0
- package/server.js +30 -0
- package/src/client/ChartBlockEngine.tsx +120 -0
- package/src/client/ChartBlockEngineDesigner.tsx +238 -0
- package/src/client/ChartBlockInitializer.tsx +216 -0
- package/src/client/ChartQueryBlockInitializer.tsx +136 -0
- package/src/client/ChartQueryMetadataProvider.tsx +62 -0
- package/src/client/DataSetPreviewTable.tsx +73 -0
- package/src/client/Icons.tsx +99 -0
- package/src/client/chartRenderComponents/index.ts +7 -0
- package/src/client/hooks/index.ts +19 -0
- package/src/client/index.tsx +101 -0
- package/src/client/locale/en-US.ts +23 -0
- package/src/client/locale/index.ts +18 -0
- package/src/client/locale/ja-JP.ts +1 -0
- package/src/client/locale/ru-RU.ts +1 -0
- package/src/client/locale/tr-TR.ts +1 -0
- package/src/client/locale/zh-CN.ts +63 -0
- package/src/client/select/CustomSelect.tsx +127 -0
- package/src/client/select/ReadPretty.tsx +36 -0
- package/src/client/select/index.md +38 -0
- package/src/client/select/index.ts +2 -0
- package/src/client/select/shared.ts +36 -0
- package/src/client/settings/AddNewQuery.tsx +161 -0
- package/src/client/settings/ConfigureFields.tsx +18 -0
- package/src/client/settings/QueriesTable.tsx +26 -0
- package/src/client/settings/queryTypes.ts +64 -0
- package/src/client/settings/schemas/chartsQueries.ts +319 -0
- package/src/client/templates/AreaTemplate.tsx +64 -0
- package/src/client/templates/BarTemplate.tsx +80 -0
- package/src/client/templates/ColumnTemplate.tsx +81 -0
- package/src/client/templates/FunnelTemplate.tsx +65 -0
- package/src/client/templates/LineTemplate.tsx +72 -0
- package/src/client/templates/PieTemplate.tsx +68 -0
- package/src/client/templates/RadarTemplate.tsx +71 -0
- package/src/client/templates/ScatterTemplate.tsx +90 -0
- package/src/client/templates/TableTemplate.tsx +48 -0
- package/src/client/templates/index.ts +21 -0
- package/src/client/utils.ts +39 -0
- package/src/index.ts +1 -0
- package/src/server/actions/chartsQueries.ts +44 -0
- package/src/server/actions/index.ts +0 -0
- package/src/server/collections/.gitkeep +0 -0
- package/src/server/collections/chartsQueries.ts +24 -0
- package/src/server/index.ts +1 -0
- package/src/server/plugin.ts +61 -0
- package/src/server/query.ts +39 -0
- package/src/server/shared/index.ts +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const templates: Map<any, any>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.templates = void 0;
|
|
7
|
+
|
|
8
|
+
var _PieTemplate = require("./PieTemplate");
|
|
9
|
+
|
|
10
|
+
var _BarTemplate = require("./BarTemplate");
|
|
11
|
+
|
|
12
|
+
var _ColumnTemplate = require("./ColumnTemplate");
|
|
13
|
+
|
|
14
|
+
var _LineTemplate = require("./LineTemplate");
|
|
15
|
+
|
|
16
|
+
var _AreaTemplate = require("./AreaTemplate");
|
|
17
|
+
|
|
18
|
+
var _ScatterTemplate = require("./ScatterTemplate");
|
|
19
|
+
|
|
20
|
+
var _RadarTemplate = require("./RadarTemplate");
|
|
21
|
+
|
|
22
|
+
var _FunnelTemplate = require("./FunnelTemplate");
|
|
23
|
+
|
|
24
|
+
const templates = new Map();
|
|
25
|
+
exports.templates = templates;
|
|
26
|
+
templates.set('Pie', _PieTemplate.pieTemplate);
|
|
27
|
+
templates.set('Line', _LineTemplate.lineTemplate);
|
|
28
|
+
templates.set('Area', _AreaTemplate.areaTemplate);
|
|
29
|
+
templates.set('Bar', _BarTemplate.barTemplate);
|
|
30
|
+
templates.set('Column', _ColumnTemplate.columnTemplate);
|
|
31
|
+
templates.set('Scatter', _ScatterTemplate.scatterTemplate);
|
|
32
|
+
templates.set('Radar', _RadarTemplate.radarTemplate);
|
|
33
|
+
templates.set('Funnel', _FunnelTemplate.funnelTemplate); // templates.set('DataSetPreviewTable', tableTemplate);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateArray = exports.parseDataSetString = void 0;
|
|
7
|
+
|
|
8
|
+
function _json() {
|
|
9
|
+
const data = _interopRequireDefault(require("json5"));
|
|
10
|
+
|
|
11
|
+
_json = function _json() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _shared() {
|
|
19
|
+
const data = require("@formily/shared");
|
|
20
|
+
|
|
21
|
+
_shared = function _shared() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
const validateArray = value => {
|
|
31
|
+
try {
|
|
32
|
+
value = _json().default.parse(value);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return 'Please input validate dataset';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (Array.isArray(value)) {
|
|
38
|
+
if (value.every(item => {
|
|
39
|
+
return typeof item === 'object' && Object.keys(item).length > 1;
|
|
40
|
+
})) return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return 'Please input validate dataset';
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
exports.validateArray = validateArray;
|
|
47
|
+
|
|
48
|
+
const parseDataSetString = str => {
|
|
49
|
+
const dataSetDataArray = _json().default.parse(str);
|
|
50
|
+
|
|
51
|
+
if (Array.isArray(dataSetDataArray)) {
|
|
52
|
+
if (dataSetDataArray.every(item => {
|
|
53
|
+
return typeof item === 'object' && Object.keys(item).length > 1;
|
|
54
|
+
})) dataSetDataArray.map(item => {
|
|
55
|
+
if (!(item === null || item === void 0 ? void 0 : item.id)) {
|
|
56
|
+
item.id = (0, _shared().uid)();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return item;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return dataSetDataArray;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.parseDataSetString = parseDataSetString;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './server';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _server.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _server = _interopRequireDefault(require("./server"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validate = exports.listMetadata = exports.getData = void 0;
|
|
7
|
+
|
|
8
|
+
function _json() {
|
|
9
|
+
const data = _interopRequireDefault(require("json5"));
|
|
10
|
+
|
|
11
|
+
_json = function _json() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var _query = require("../query");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
23
|
+
|
|
24
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
25
|
+
|
|
26
|
+
const getData = /*#__PURE__*/function () {
|
|
27
|
+
var _ref = _asyncToGenerator(function* (ctx, next) {
|
|
28
|
+
const filterByTk = ctx.action.params.filterByTk;
|
|
29
|
+
const r = ctx.db.getRepository('chartsQueries');
|
|
30
|
+
const instance = yield r.findOne({
|
|
31
|
+
filterByTk
|
|
32
|
+
});
|
|
33
|
+
const result = yield _query.query[instance.type](instance.options, {
|
|
34
|
+
db: ctx.db,
|
|
35
|
+
skipError: true
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (typeof result === 'string') {
|
|
39
|
+
ctx.body = _json().default.parse(result);
|
|
40
|
+
} else {
|
|
41
|
+
ctx.body = result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return next();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return function getData(_x, _x2) {
|
|
48
|
+
return _ref.apply(this, arguments);
|
|
49
|
+
};
|
|
50
|
+
}();
|
|
51
|
+
|
|
52
|
+
exports.getData = getData;
|
|
53
|
+
|
|
54
|
+
const validate = /*#__PURE__*/function () {
|
|
55
|
+
var _ref2 = _asyncToGenerator(function* (ctx, next) {
|
|
56
|
+
const values = ctx.action.params.values;
|
|
57
|
+
ctx.body = {
|
|
58
|
+
errorMessage: ''
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
yield _query.query.sql(values, {
|
|
63
|
+
db: ctx.db,
|
|
64
|
+
validateSQL: true
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
ctx.body = {
|
|
68
|
+
errorMessage: error.message
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return next();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return function validate(_x3, _x4) {
|
|
76
|
+
return _ref2.apply(this, arguments);
|
|
77
|
+
};
|
|
78
|
+
}();
|
|
79
|
+
|
|
80
|
+
exports.validate = validate;
|
|
81
|
+
|
|
82
|
+
const listMetadata = /*#__PURE__*/function () {
|
|
83
|
+
var _ref3 = _asyncToGenerator(function* (ctx, next) {
|
|
84
|
+
const r = ctx.db.getRepository('chartsQueries');
|
|
85
|
+
const items = yield r.find({
|
|
86
|
+
sort: '-id'
|
|
87
|
+
});
|
|
88
|
+
ctx.body = items.map(item => {
|
|
89
|
+
return {
|
|
90
|
+
id: item.id,
|
|
91
|
+
title: item.title,
|
|
92
|
+
type: item.type,
|
|
93
|
+
fields: item.fields
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
return next();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return function listMetadata(_x5, _x6) {
|
|
100
|
+
return _ref3.apply(this, arguments);
|
|
101
|
+
};
|
|
102
|
+
}();
|
|
103
|
+
|
|
104
|
+
exports.listMetadata = listMetadata;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var _default = (0, _database().defineCollection)({
|
|
19
|
+
name: 'chartsQueries',
|
|
20
|
+
fields: [{
|
|
21
|
+
name: 'title',
|
|
22
|
+
type: 'string'
|
|
23
|
+
}, {
|
|
24
|
+
name: 'type',
|
|
25
|
+
type: 'string'
|
|
26
|
+
}, {
|
|
27
|
+
name: 'options',
|
|
28
|
+
type: 'json'
|
|
29
|
+
}, {
|
|
30
|
+
name: 'fields',
|
|
31
|
+
type: 'json',
|
|
32
|
+
defaultValue: []
|
|
33
|
+
}]
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _plugin.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
2
|
+
export declare class ChartsPlugin extends Plugin {
|
|
3
|
+
syncFields: (instance: any, { transaction }: {
|
|
4
|
+
transaction: any;
|
|
5
|
+
}) => Promise<void>;
|
|
6
|
+
afterAdd(): void;
|
|
7
|
+
beforeLoad(): void;
|
|
8
|
+
load(): Promise<void>;
|
|
9
|
+
install(options?: InstallOptions): Promise<void>;
|
|
10
|
+
afterEnable(): Promise<void>;
|
|
11
|
+
afterDisable(): Promise<void>;
|
|
12
|
+
remove(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export default ChartsPlugin;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.ChartsPlugin = void 0;
|
|
7
|
+
|
|
8
|
+
function _server() {
|
|
9
|
+
const data = require("@nocobase/server");
|
|
10
|
+
|
|
11
|
+
_server = function _server() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _json() {
|
|
19
|
+
const data = _interopRequireDefault(require("json5"));
|
|
20
|
+
|
|
21
|
+
_json = function _json() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _path() {
|
|
29
|
+
const data = require("path");
|
|
30
|
+
|
|
31
|
+
_path = function _path() {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var _chartsQueries = require("./actions/chartsQueries");
|
|
39
|
+
|
|
40
|
+
var _query = require("./query");
|
|
41
|
+
|
|
42
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
43
|
+
|
|
44
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
45
|
+
|
|
46
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
47
|
+
|
|
48
|
+
class ChartsPlugin extends _server().Plugin {
|
|
49
|
+
constructor(...args) {
|
|
50
|
+
var _this;
|
|
51
|
+
|
|
52
|
+
super(...args);
|
|
53
|
+
_this = this;
|
|
54
|
+
|
|
55
|
+
this.syncFields = /*#__PURE__*/function () {
|
|
56
|
+
var _ref = _asyncToGenerator(function* (instance, {
|
|
57
|
+
transaction
|
|
58
|
+
}) {
|
|
59
|
+
var _data2;
|
|
60
|
+
|
|
61
|
+
const _data = yield _query.query[instance.type](instance.options, {
|
|
62
|
+
db: _this.db,
|
|
63
|
+
transaction,
|
|
64
|
+
validateSQL: true
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
let data;
|
|
68
|
+
|
|
69
|
+
if (typeof _data === 'string') {
|
|
70
|
+
data = _json().default.parse(_data);
|
|
71
|
+
} else {
|
|
72
|
+
data = _data;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const d = Array.isArray(data) ? (_data2 = data) === null || _data2 === void 0 ? void 0 : _data2[0] : data;
|
|
76
|
+
const fields = Object.keys(d || {}).map(f => {
|
|
77
|
+
return {
|
|
78
|
+
name: f
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
instance.set('fields', fields);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return function (_x, _x2) {
|
|
85
|
+
return _ref.apply(this, arguments);
|
|
86
|
+
};
|
|
87
|
+
}();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
afterAdd() {}
|
|
91
|
+
|
|
92
|
+
beforeLoad() {
|
|
93
|
+
this.app.db.on('chartsQueries.beforeCreate', this.syncFields);
|
|
94
|
+
this.app.db.on('chartsQueries.beforeUpdate', this.syncFields);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
load() {
|
|
98
|
+
var _this2 = this;
|
|
99
|
+
|
|
100
|
+
return _asyncToGenerator(function* () {
|
|
101
|
+
yield _this2.db.import({
|
|
102
|
+
directory: (0, _path().resolve)(__dirname, 'collections')
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
_this2.app.resourcer.registerActionHandlers({
|
|
106
|
+
'chartsQueries:getData': _chartsQueries.getData,
|
|
107
|
+
'chartsQueries:listMetadata': _chartsQueries.listMetadata,
|
|
108
|
+
'chartsQueries:validate': _chartsQueries.validate
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
_this2.app.acl.registerSnippet({
|
|
112
|
+
name: 'pm.charts.queries',
|
|
113
|
+
actions: ['chartsQueries:*']
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
_this2.app.acl.allow('chartsQueries', 'getData', 'loggedIn');
|
|
117
|
+
|
|
118
|
+
_this2.app.acl.allow('chartsQueries', 'listMetadata', 'loggedIn');
|
|
119
|
+
})();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
install(options) {
|
|
123
|
+
return _asyncToGenerator(function* () {})();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
afterEnable() {
|
|
127
|
+
return _asyncToGenerator(function* () {})();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
afterDisable() {
|
|
131
|
+
return _asyncToGenerator(function* () {})();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
remove() {
|
|
135
|
+
return _asyncToGenerator(function* () {})();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
exports.ChartsPlugin = ChartsPlugin;
|
|
141
|
+
var _default = ChartsPlugin;
|
|
142
|
+
exports.default = _default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Database } from '@nocobase/database';
|
|
2
|
+
export declare const query: {
|
|
3
|
+
api: (options: any) => Promise<any[]>;
|
|
4
|
+
json: (options: any) => Promise<any>;
|
|
5
|
+
sql: (options: any, { db, transaction, skipError, validateSQL, }: {
|
|
6
|
+
db: Database;
|
|
7
|
+
transaction?: any;
|
|
8
|
+
skipError?: boolean;
|
|
9
|
+
validateSQL?: boolean;
|
|
10
|
+
}) => Promise<unknown[]>;
|
|
11
|
+
};
|
|
12
|
+
export default query;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.query = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
|
|
10
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
+
|
|
16
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
17
|
+
|
|
18
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
|
+
|
|
20
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
21
|
+
|
|
22
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
23
|
+
|
|
24
|
+
const query = {
|
|
25
|
+
api: function () {
|
|
26
|
+
var _api = _asyncToGenerator(function* (options) {
|
|
27
|
+
return [];
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function api(_x) {
|
|
31
|
+
return _api.apply(this, arguments);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return api;
|
|
35
|
+
}(),
|
|
36
|
+
json: function () {
|
|
37
|
+
var _json = _asyncToGenerator(function* (options) {
|
|
38
|
+
return options.data || [];
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function json(_x2) {
|
|
42
|
+
return _json.apply(this, arguments);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return json;
|
|
46
|
+
}(),
|
|
47
|
+
sql: function () {
|
|
48
|
+
var _sql = _asyncToGenerator(function* (options, {
|
|
49
|
+
db,
|
|
50
|
+
transaction,
|
|
51
|
+
skipError,
|
|
52
|
+
validateSQL
|
|
53
|
+
}) {
|
|
54
|
+
try {
|
|
55
|
+
// 分号截取,只取第一段
|
|
56
|
+
const sql = options.sql.trim().split(';').shift();
|
|
57
|
+
|
|
58
|
+
if (!sql) {
|
|
59
|
+
throw new Error('SQL is empty');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!/^select/i.test(sql) && !/^with([\s\S]+)select([\s\S]+)/i.test(sql)) {
|
|
63
|
+
throw new Error('Only select query allowed');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const _yield$db$sequelize$q = yield db.sequelize.query(sql, {
|
|
67
|
+
transaction
|
|
68
|
+
}),
|
|
69
|
+
_yield$db$sequelize$q2 = _slicedToArray(_yield$db$sequelize$q, 1),
|
|
70
|
+
data = _yield$db$sequelize$q2[0];
|
|
71
|
+
|
|
72
|
+
return data;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (skipError) {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
function sql(_x3, _x4) {
|
|
83
|
+
return _sql.apply(this, arguments);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return sql;
|
|
87
|
+
}()
|
|
88
|
+
};
|
|
89
|
+
exports.query = query;
|
|
90
|
+
var _default = query;
|
|
91
|
+
exports.default = _default;
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-charts",
|
|
3
|
+
"version": "0.9.1-alpha.2",
|
|
4
|
+
"main": "lib/server/index.js",
|
|
5
|
+
"devDependencies": {
|
|
6
|
+
"@nocobase/client": "0.9.1-alpha.2",
|
|
7
|
+
"@nocobase/server": "0.9.1-alpha.2",
|
|
8
|
+
"@nocobase/test": "0.9.1-alpha.2"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"json5": "^2.2.3"
|
|
12
|
+
},
|
|
13
|
+
"gitHead": "d588a68eca4feed4642a4cb317301011266fe5c9"
|
|
14
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
4
|
+
|
|
5
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
|
|
7
|
+
var _index = _interopRequireWildcard(require("./lib/server"));
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
var _exportNames = {};
|
|
13
|
+
Object.defineProperty(exports, "default", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _index.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
Object.keys(_index).forEach(function (key) {
|
|
21
|
+
if (key === "default" || key === "__esModule") return;
|
|
22
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
23
|
+
if (key in exports && exports[key] === _index[key]) return;
|
|
24
|
+
Object.defineProperty(exports, key, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _index[key];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|