@mongoosejs/studio
Advanced tools
Comparing version 0.0.29 to 0.0.30
'use strict'; | ||
const Archetype = require('archetype'); | ||
const vm = require('vm'); | ||
const GetDashboardParams = new Archetype({ | ||
dashboardId: { | ||
$type: 'string', | ||
$required: true | ||
} | ||
}).compile('GetDashboardParams'); | ||
dashboardId: { | ||
$type: 'string', | ||
$required: true | ||
}, | ||
evaluate: { | ||
$type: 'boolean' | ||
} | ||
}).compile('GetDashboardParams'); | ||
module.exports = ({ db }) => async function getDashboard(params) { | ||
const { dashboardId } = new GetDashboardParams(params); | ||
const { dashboardId, evaluate } = new GetDashboardParams(params); | ||
const Dashboard = db.model('__Studio_Dashboard'); | ||
const dashboard = await Dashboard.findOne({ _id: dashboardId }); | ||
if (evaluate) { | ||
const context = vm.createContext({ db }); | ||
let result = null; | ||
try { | ||
result = await vm.runInContext(formatFunction(dashboard.code), context); | ||
if (result.$document?.model) { | ||
let schemaPaths = {}; | ||
const Model = Dashboard.db.model(result.$document?.model); | ||
for (const path of Object.keys(Model.schema.paths)) { | ||
schemaPaths[path] = { | ||
instance: Model.schema.paths[path].instance, | ||
path, | ||
ref: Model.schema.paths[path].options?.ref, | ||
required: Model.schema.paths[path].options?.required | ||
}; | ||
} | ||
result.$document.schemaPaths = schemaPaths; | ||
} | ||
} catch (error) { | ||
return { dashboard, error: { message: error.message } }; | ||
} | ||
return { dashboard, result }; | ||
} | ||
return { dashboard } | ||
}; | ||
return { dashboard }; | ||
}; | ||
const formatFunction = code => `(async function() { | ||
${code} | ||
})();` |
'use strict'; | ||
exports.createDashboard = require('./createDashboard'); | ||
exports.getDashboard = require('./getDashboard'); | ||
exports.getDashboards = require('./getDashboards'); | ||
exports.updateDashboard = require('./updateDashboard'); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
const dashboardSchema = new mongoose.Schema({ | ||
name: { | ||
title: { | ||
type: String, | ||
@@ -14,2 +14,5 @@ required: true | ||
required: true | ||
}, | ||
description: { | ||
type: String | ||
} | ||
@@ -16,0 +19,0 @@ }); |
@@ -23,2 +23,5 @@ 'use strict'; | ||
exports.Dashboard = { | ||
createDashboard(params) { | ||
return client.post('', { action: 'Dashboard.createDashboard', ...params }).then(res => res.data); | ||
}, | ||
getDashboard(params) { | ||
@@ -62,2 +65,5 @@ return client.post('', { action: 'Dashboard.getDashboard', ...params }).then(res => res.data); | ||
exports.Dashboard = { | ||
createDashboard: function createDashboard(params) { | ||
return client.post('/Dashboard/createDashboard', params).then(res => res.data); | ||
}, | ||
getDashboard: function getDashboard(params) { | ||
@@ -64,0 +70,0 @@ return client.get('/Dashboard/getDashboard', params).then(res => res.data); |
@@ -12,5 +12,5 @@ 'use strict'; | ||
code: '', | ||
name: '', | ||
showEditor: false, | ||
dashboard: null | ||
dashboard: null, | ||
result: null | ||
} | ||
@@ -28,3 +28,3 @@ }, | ||
const dashboardId = this.$route.query.dashboardId; | ||
const { dashboard } = await api.Dashboard.getDashboard({ params: { dashboardId: dashboardId } }); | ||
const { dashboard, result } = await api.Dashboard.getDashboard({ params: { dashboardId: dashboardId, evaluate: true } }); | ||
if (!dashboard) { | ||
@@ -34,6 +34,6 @@ return; | ||
this.dashboard = dashboard; | ||
this.name = this.dashboard.name; | ||
this.code = this.dashboard.code; | ||
this.result = result; | ||
this.status = 'loaded'; | ||
} | ||
}); |
@@ -10,3 +10,5 @@ 'use strict'; | ||
data: () => ({ | ||
status: 'loading', | ||
dashboards: [], | ||
showCreateDashboardModal: false | ||
}), | ||
@@ -16,7 +18,4 @@ async mounted() { | ||
this.dashboards = dashboards; | ||
if (!this.$route.query.dashboardId) { | ||
return; | ||
} | ||
this.status = 'loaded'; | ||
}, | ||
}); |
@@ -39,39 +39,5 @@ 'use strict'; | ||
}).map(key => schemaPaths[key]); | ||
this.getVirtuals(); | ||
this.status = 'loaded'; | ||
}, | ||
methods: { | ||
getComponentForPath(schemaPath) { | ||
if (schemaPath.instance === 'Array') { | ||
return 'detail-array'; | ||
} | ||
return 'detail-default'; | ||
}, | ||
getEditComponentForPath(path) { | ||
if (path.instance == 'Date') { | ||
return 'edit-date'; | ||
} | ||
if (path.instance == 'Number') { | ||
return 'edit-number'; | ||
} | ||
if (path.instance === 'Array') { | ||
return 'edit-array'; | ||
} | ||
return 'edit-default'; | ||
}, | ||
getValueForPath(path) { | ||
return mpath.get(path, this.document); | ||
}, | ||
getEditValueForPath({ path }) { | ||
return path in this.changes ? this.changes[path] : mpath.get(path, this.document); | ||
}, | ||
getVirtuals() { | ||
const exists = this.schemaPaths.map(x => x.path); | ||
const docKeys = Object.keys(this.document); | ||
for (let i = 0; i < docKeys.length; i++) { | ||
if (!exists.includes(docKeys[i])) { | ||
this.virtuals.push({ name: docKeys[i], value: this.document[docKeys[i]] }); | ||
} | ||
} | ||
}, | ||
cancelEdit() { | ||
@@ -78,0 +44,0 @@ this.changes = {}; |
@@ -15,5 +15,10 @@ 'use strict'; | ||
require('./charts/charts')(app); | ||
require('./create-dashboard/create-dashboard')(app); | ||
require('./create-document/create-document')(app); | ||
require('./dashboards/dashboards')(app); | ||
require('./dashboard/dashboard')(app); | ||
require('./dashboard-result/dashboard-result')(app); | ||
require('./dashboard-result/dashboard-chart/dashboard-chart')(app); | ||
require('./dashboard-result/dashboard-document/dashboard-document')(app); | ||
require('./dashboard-result/dashboard-primitive/dashboard-primitive')(app); | ||
require('./dashboard/edit-dashboard/edit-dashboard')(app) | ||
@@ -24,2 +29,3 @@ require('./detail-array/detail-array')(app); | ||
require('./document/confirm-changes/confirm-changes')(app); | ||
require('./document-details/document-details')(app); | ||
require('./edit-array/edit-array')(app); | ||
@@ -26,0 +32,0 @@ require('./edit-default/edit-default')(app); |
{ | ||
"name": "@mongoosejs/studio", | ||
"version": "0.0.29", | ||
"version": "0.0.30", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "archetype": "0.13.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
804190
125
14420
3