basic sample dynamic create + enable delete

This commit is contained in:
morsh 2017-07-30 13:40:10 +03:00
Родитель 007fcc8a93
Коммит 8e6c8c171a
3 изменённых файлов: 29 добавлений и 103 удалений

3
.gitignore поставляемый
Просмотреть файл

@ -20,5 +20,4 @@ client/**/*.css
*.orig
# private files
*.private.*
!*sample.basic.private.js
*.private.*

Просмотреть файл

@ -1,84 +0,0 @@
return {
id: "basic_sample",
name: "Basic Sample",
icon: "extension",
url: "basic_sample",
description: "A basic sample to see how data is connected to graphs",
preview: "/images/bot-framework-preview.png",
config: {
connections: { },
layout: {
isDraggable: true,
isResizable: true,
rowHeight: 30,
verticalCompact: false,
cols: { lg: 12,md: 10,sm: 6,xs: 4,xxs: 2 },
breakpoints: { lg: 1200,md: 996,sm: 768,xs: 480,xxs: 0 }
}
},
dataSources: [
{
id: "samples",
type: "Sample",
params: {
samples: {
data_for_pie: [
{ name: "value1",value: 60 },
{ name: "value2",value: 10 },
{ name: "value3",value: 30 }
],
scorecard_data_value: 3000000,
scorecard_data_subvalue: 4000
}
}
}
],
filters: [],
elements: [
{
id: "pie_sample1",
type: "PieData",
title: "Pie Sample 1",
subtitle: "Description of pie sample 1",
size: { w: 5,h: 8 },
dependencies: { values: "samples:data_for_pie" },
props: { showLegend: true }
},
{
id: "pie_sample2",
type: "PieData",
title: "Pie Sample 2",
subtitle: "Hover on the values to see the difference from sample 1",
size: { w: 5,h: 8 },
dependencies: { values: "samples:data_for_pie" },
props: { showLegend: true, compact: true }
},
{
id: "scorecard_sample1",
type: "Scorecard",
title: "Value",
size: { w: 1, h: 3},
dependencies: {
value: "samples:scorecard_data_value",
color: "::#2196F3",
icon: "::av_timer"
}
},
{
id: "scorecard_sample2",
type: "Scorecard",
title: "Same Value",
size: { w: 1, h: 3},
dependencies: {
value: "samples:scorecard_data_value",
color: "::#2196F3",
icon: "::av_timer",
subvalue: "samples:scorecard_data_subvalue"
},
props: {
subheading: "Value #2"
}
}
],
dialogs: []
}

Просмотреть файл

@ -63,25 +63,36 @@ router.get('/dashboards', (req, res) => {
let script = '';
let files = fs.readdirSync(privateDashboard);
files = (files || []).filter(fileName => isValidFile(path.join(privateDashboard, fileName)));
// In case no dashboard is present, create a new sample file
if (!files || !files.length) {
const sampleFileName = 'basic_sample.private.js';
const sampleTemplatePath = path.join(preconfDashboard, 'sample.ts');
const samplePath = path.join(privateDashboard, sampleFileName);
let content = getFileContents(sampleTemplatePath);
fs.writeFileSync(samplePath, content);
files = [ sampleFileName ];
}
if (files && files.length) {
files.forEach((fileName) => {
let filePath = path.join(privateDashboard, fileName);
if (isValidFile(filePath)) {
const fileContents = getFileContents(filePath);
const jsonDefinition = getMetadata(fileContents);
let content = 'return ' + JSON.stringify(jsonDefinition);
const filePath = path.join(privateDashboard, fileName);
const fileContents = getFileContents(filePath);
const jsonDefinition = getMetadata(fileContents);
let content = 'return ' + JSON.stringify(jsonDefinition);
// Ensuing this dashboard is loaded into the dashboards array on the page
script += `
(function (window) {
var dashboard = (function () {
${content}
})();
window.dashboardDefinitions = window.dashboardDefinitions || [];
window.dashboardDefinitions.push(dashboard);
})(window);
`;
}
// Ensuing this dashboard is loaded into the dashboards array on the page
script += `
(function (window) {
var dashboard = (function () {
${content}
})();
window.dashboardDefinitions = window.dashboardDefinitions || [];
window.dashboardDefinitions.push(dashboard);
})(window);
`;
});
}
@ -157,7 +168,7 @@ router.post('/dashboards/:id', (req, res) => {
}
res.json({ script });
})
});
});
router.get('/templates/:id', (req, res) => {