diff --git a/app.js b/app.js index 7567064..4bf8ea4 100644 --- a/app.js +++ b/app.js @@ -49,9 +49,9 @@ app.use(lessMiddleware(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public'))); -let displays = require("./modules/websocket")(server, app, io, eventDispatcher); -let indexRouter = require('./routes/index.js')(displays); -let adminRouter = require('./routes/admin.js')(displays); +let websocket = require("./modules/websocket")(server, app, io, eventDispatcher); +let indexRouter = require('./routes/index.js')(websocket.displays, websocket.bundleManager); +let adminRouter = require('./routes/admin.js')(websocket.displays, websocket.bundleManager); app.use('/', indexRouter); app.use('/admin', adminRouter); diff --git a/data/default/bundle.json b/data/default/bundle.json index 6551bc5..ed70f4d 100644 --- a/data/default/bundle.json +++ b/data/default/bundle.json @@ -1,18 +1,21 @@ { - "bundleName": "default", - "background": "bg.jpg", - "duration": 20, - "useWebFonts": false, - "styleHeader": { - "fill": "#f90", - "fontSize": 56, - "fontWeight": 900, - "fontFamily": "Arial Black" - }, - "styleText": { - "fill": "#fff", - "fontSize": 32, - "fontWeight": 900, - "fontFamily": "Arial Black" - } + "bundleName": "default", + "background": "bg.jpg", + "duration": 40, + "transition": "blocks2", + "useWebFonts": false, + "styleHeader": { + "stroke": "", + "fill": "#f90", + "fontSize": "56", + "fontWeight": 900, + "fontFamily": "Arial Black" + }, + "styleText": { + "stroke": "", + "fill": "#fff", + "fontSize": "32", + "fontWeight": 900, + "fontFamily": "Arial Black" + } } \ No newline at end of file diff --git a/data/default/slides.json b/data/default/slides.json index 57a9f54..c94e5e9 100644 --- a/data/default/slides.json +++ b/data/default/slides.json @@ -9,18 +9,6 @@ "type": "slide", "index": 0 }, - { - "uuid": "xx91688-bb93-4376-a3ab-57ef755b4f0rd", - "name": "link: localhost", - "webUrl": "http://localhost", - "duration": 10, - "enabled": true, - "displayTime": false, - "transition": null, - "type": "webpage", - "index": 1, - "zoom": 1 - }, { "uuid": "6a298b8c-9246-411f-b364-2d73c7e292d0", "name": "header 3", @@ -29,7 +17,7 @@ "displayTime": false, "transition": "zip", "type": "slide", - "index": 2 + "index": 1 }, { "uuid": "03191688-bb93-4376-a3ab-53ed790b2155", @@ -39,6 +27,6 @@ "displayTime": true, "type": "slide", "transition": null, - "index": 3 + "index": 2 } ] \ No newline at end of file diff --git a/data/set1/bundle.json b/data/set1/bundle.json index 417cc07..1f3be24 100644 --- a/data/set1/bundle.json +++ b/data/set1/bundle.json @@ -1,18 +1,21 @@ { - "bundleName": "set1", - "background": "bg.jpg", - "useWebFonts": false, - "duration": 20, - "styleHeader": { - "fill": "#f90", - "fontSize": 56, - "fontWeight": 900, - "fontFamily": "Arial Black" - }, - "styleText": { - "fill": "#fff", - "fontFamily": "Arial Black", - "fontSize": 42, - "fontWeight": 900 - } + "bundleName": "set1", + "background": "bg.jpg", + "useWebFonts": false, + "duration": 20, + "styleHeader": { + "fill": "#f90", + "fontSize": "56", + "fontWeight": 900, + "fontFamily": "Arial Black", + "stroke": "" + }, + "styleText": { + "fill": "#fff", + "fontFamily": "Arial Black", + "fontSize": "42", + "fontWeight": 900, + "stroke": "" + }, + "transition": "blocks2" } \ No newline at end of file diff --git a/modules/bundle.js b/modules/bundle.js index dfab477..af3cf7c 100644 --- a/modules/bundle.js +++ b/modules/bundle.js @@ -117,6 +117,7 @@ class bundleClass { save() { try { fs.writeFileSync("./data/" + this.name + "/slides.json", this.toJson()); + fs.writeFileSync("./data/" + this.name + "/bundle.json", JSON.stringify(this.bundleData, null, "\t")); } catch (e) { cli.error("error while saving file:", e); } diff --git a/modules/websocket.js b/modules/websocket.js index 6a17daa..b3e8712 100644 --- a/modules/websocket.js +++ b/modules/websocket.js @@ -2,7 +2,7 @@ let meta = require("../data/meta.json"); let display = require("./display.js"); let admin = require("./admin.js"); let cli = require('./cli.js'); -let bundleManager = require('./bundleManager.js'); +let _bundleManager = require('./bundleManager.js'); let chalk = require('chalk'); let fs = require('fs'); @@ -48,17 +48,17 @@ module.exports = function (server, app, io, dispatcher) { cli.info("Starting bundle manager..."); - let bundler = new bundleManager(); + let bundleManager = new _bundleManager(); cli.info("Starting websocket backends..."); let screenId = 0; for (let metadata of meta.displays) { - screenView.push(new display(io, dispatcher, metadata, screenId, bundler)); + screenView.push(new display(io, dispatcher, metadata, screenId, bundleManager)); screenId += 1; } - let adminView = new admin(io, dispatcher, screenView, bundler); + let adminView = new admin(io, dispatcher, screenView, bundleManager); io.of("/lobby").on("connection", function (socket) { cli.info("WS/" + socket.conn.remoteAddress + " connect"); @@ -84,5 +84,5 @@ module.exports = function (server, app, io, dispatcher) { }); }); - return screenView; + return {displays: screenView, bundleManager: bundleManager}; }; diff --git a/public/js/dashboard.js b/public/js/dashboard.js index 42c9d1b..359221d 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -202,6 +202,10 @@ function editSlide(name, type) { } } +function editBundle(bundleName) { + window.open("/admin/edit/bundle?bundle=" + bundleName, '_blank', 'location=no,height=500,width=700,scrollbars=yes,status=no'); +} + function emit(callback, data) { if (data === undefined || data === null) { data = {}; diff --git a/routes/admin.js b/routes/admin.js index 4d05245..50ba665 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -1,14 +1,16 @@ let express = require('express'); let authMiddleWare = require('../modules/auth.js'); let router = express.Router(); - +let cli = require("../modules/cli.js"); let fs = require('fs'); let path = require('path'); let config = require("../config.js"); +let busboy = require("connect-busboy"); -module.exports = function (displays) { +module.exports = function (displays, bundleManager) { router.use(authMiddleWare); + router.use(busboy({immediate: true})); router.get('/', function (req, res, next) { res.render('admin/dashboard', {config: config}); @@ -28,6 +30,59 @@ module.exports = function (displays) { res.render('admin/edit', {config: config, bundle: bundle, displayId: displayId, file: file}); }); + router.post('/edit/bundle', function (req, res, next) { + let bundleData = {}; + + var transition = null; + if (req.body.transition !== "") { + transition = req.body.transition; + } + + var useWebFonts = false; + if (req.body.useWebFonts) { + useWebFonts = true; + } + + try { + + bundleData = bundleManager.getBundle(req.body.bundle).getBundleData(); + bundleData.bundleName = req.body.bundleName; + bundleData.background = req.body.background; + bundleData.duration = parseInt(req.body.duration); + bundleData.transition = transition; + bundleData.useWebFonts = useWebFonts; + bundleData.styleHeader.fontFamily = req.body.headerFontFamily; + bundleData.styleHeader.fontSize = req.body.headerFontSize; + bundleData.styleHeader.fill = req.body.headerFill; + bundleData.styleHeader.stroke = req.body.headerStroke; + bundleData.styleText.fontFamily = req.body.textFontFamily; + bundleData.styleText.fontSize = req.body.textFontSize; + bundleData.styleText.fill = req.body.textFill; + bundleData.styleText.stroke = req.body.textStroke; + + bundleManager.getBundle(req.body.bundle).save(); + + } catch (err) { + cli.error("error loading bundle", err); + + } + + res.send("
"); + }); + + router.get('/edit/bundle', function (req, res, next) { + let bundle = req.query['bundle']; + let bundleData = {}; + try { + bundleData = bundleManager.getBundle(bundle).getBundleData(); + } catch (err) { + cli.error("error loading bundle", err); + } + + // console.log(bundleData); + res.render('admin/editBundle', {config: config, bundle: bundle, bundleData: bundleData}); + }); + router.get('/edit/link', function (req, res, next) { let bundle = req.query['bundle']; let file = req.query['file']; diff --git a/routes/index.js b/routes/index.js index 7931154..57df86c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -5,7 +5,8 @@ let config = require("../config.js"); let displayMeta = require("../data/meta.json"); const cli = require('../modules/cli.js'); -module.exports = function (displays) { +module.exports = function (displays, bundleManager) { + router.get('/', function (req, res, next) { res.header('Access-Control-Allow-Origin', '*'); diff --git a/views/admin/editBundle.twig b/views/admin/editBundle.twig index f217b98..cdf1921 100644 --- a/views/admin/editBundle.twig +++ b/views/admin/editBundle.twig @@ -5,5 +5,159 @@ {% endblock %} {% block body %} +