@mongoosejs/studio 0.0.29 → 0.0.30
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/backend/actions/Dashboard/createDashboard.js +22 -0
- package/backend/actions/Dashboard/getDashboard.js +41 -8
- package/backend/actions/Dashboard/index.js +1 -0
- package/backend/db/dashboardSchema.js +4 -1
- package/frontend/public/app.js +381 -46
- package/frontend/public/index.html +1 -0
- package/frontend/public/tw.css +323 -0
- package/frontend/src/api.js +6 -0
- package/frontend/src/create-dashboard/create-dashboard.html +43 -0
- package/frontend/src/create-dashboard/create-dashboard.js +40 -0
- package/frontend/src/dashboard/dashboard.html +16 -7
- package/frontend/src/dashboard/dashboard.js +4 -4
- package/frontend/src/dashboard-result/dashboard-chart/dashboard-chart.html +8 -0
- package/frontend/src/dashboard-result/dashboard-chart/dashboard-chart.js +20 -0
- package/frontend/src/dashboard-result/dashboard-document/dashboard-document.html +8 -0
- package/frontend/src/dashboard-result/dashboard-document/dashboard-document.js +29 -0
- package/frontend/src/dashboard-result/dashboard-primitive/dashboard-primitive.html +8 -0
- package/frontend/src/dashboard-result/dashboard-primitive/dashboard-primitive.js +24 -0
- package/frontend/src/dashboard-result/dashboard-result.html +18 -0
- package/frontend/src/dashboard-result/dashboard-result.js +30 -0
- package/frontend/src/dashboards/dashboards.html +77 -3
- package/frontend/src/dashboards/dashboards.js +2 -3
- package/frontend/src/document/document.css +0 -16
- package/frontend/src/document/document.html +5 -34
- package/frontend/src/document/document.js +0 -34
- package/frontend/src/document-details/document-details.css +18 -0
- package/frontend/src/document-details/document-details.html +36 -0
- package/frontend/src/document-details/document-details.js +59 -0
- package/frontend/src/index.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const Archetype = require('archetype');
|
|
3
|
+
|
|
4
|
+
const CreateDashboardParams = new Archetype({
|
|
5
|
+
title: {
|
|
6
|
+
$type: 'string',
|
|
7
|
+
$required: true
|
|
8
|
+
},
|
|
9
|
+
code: {
|
|
10
|
+
$type: 'string',
|
|
11
|
+
$required: true
|
|
12
|
+
}
|
|
13
|
+
}).compile('CreateDashboardParams');
|
|
14
|
+
|
|
15
|
+
module.exports = ({ db }) => async function createDashboard(params) {
|
|
16
|
+
const { title, code } = new CreateDashboardParams(params);
|
|
17
|
+
const Dashboard = db.model('__Studio_Dashboard');
|
|
18
|
+
|
|
19
|
+
const dashboard = await Dashboard.create({ title, code });
|
|
20
|
+
|
|
21
|
+
return { dashboard };
|
|
22
|
+
};
|
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
|
|
2
3
|
const Archetype = require('archetype');
|
|
4
|
+
const vm = require('vm');
|
|
3
5
|
|
|
4
6
|
const GetDashboardParams = new Archetype({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
dashboardId: {
|
|
8
|
+
$type: 'string',
|
|
9
|
+
$required: true
|
|
10
|
+
},
|
|
11
|
+
evaluate: {
|
|
12
|
+
$type: 'boolean'
|
|
13
|
+
}
|
|
14
|
+
}).compile('GetDashboardParams');
|
|
10
15
|
|
|
11
16
|
module.exports = ({ db }) => async function getDashboard(params) {
|
|
12
|
-
const { dashboardId } = new GetDashboardParams(params);
|
|
17
|
+
const { dashboardId, evaluate } = new GetDashboardParams(params);
|
|
13
18
|
const Dashboard = db.model('__Studio_Dashboard');
|
|
14
19
|
|
|
15
20
|
const dashboard = await Dashboard.findOne({ _id: dashboardId });
|
|
21
|
+
if (evaluate) {
|
|
22
|
+
const context = vm.createContext({ db });
|
|
23
|
+
let result = null;
|
|
24
|
+
try {
|
|
25
|
+
result = await vm.runInContext(formatFunction(dashboard.code), context);
|
|
26
|
+
if (result.$document?.model) {
|
|
27
|
+
let schemaPaths = {};
|
|
28
|
+
const Model = Dashboard.db.model(result.$document?.model);
|
|
29
|
+
for (const path of Object.keys(Model.schema.paths)) {
|
|
30
|
+
schemaPaths[path] = {
|
|
31
|
+
instance: Model.schema.paths[path].instance,
|
|
32
|
+
path,
|
|
33
|
+
ref: Model.schema.paths[path].options?.ref,
|
|
34
|
+
required: Model.schema.paths[path].options?.required
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
result.$document.schemaPaths = schemaPaths;
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return { dashboard, error: { message: error.message } };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { dashboard, result };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { dashboard };
|
|
47
|
+
};
|
|
16
48
|
|
|
17
|
-
|
|
18
|
-
}
|
|
49
|
+
const formatFunction = code => `(async function() {
|
|
50
|
+
${code}
|
|
51
|
+
})();`
|
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
const mongoose = require('mongoose');
|
|
4
4
|
|
|
5
5
|
const dashboardSchema = new mongoose.Schema({
|
|
6
|
-
|
|
6
|
+
title: {
|
|
7
7
|
type: String,
|
|
8
8
|
required: true
|
|
9
9
|
},
|
|
10
10
|
code: {
|
|
11
11
|
type: String,
|
|
12
12
|
required: true
|
|
13
|
+
},
|
|
14
|
+
description: {
|
|
15
|
+
type: String
|
|
13
16
|
}
|
|
14
17
|
});
|
|
15
18
|
|