diff --git a/data/default/bundle.json b/data/default/bundle.json index ce2f663..e17e13b 100644 --- a/data/default/bundle.json +++ b/data/default/bundle.json @@ -1,7 +1,7 @@ { - "bundleName": "default", + "displayName": "default nimi testi toimiiko 123", "background": "bg.jpg", - "duration": 40, + "duration": 0, "transition": "tiles3d", "useWebFonts": false, "displayTime": true, @@ -18,5 +18,6 @@ "fontSize": 32, "fontWeight": 900, "fontFamily": "Arial Black" - } + }, + "bundleName": "default" } \ No newline at end of file diff --git a/data/set1/bundle.json b/data/set1/bundle.json index 243d72f..49aa4b3 100644 --- a/data/set1/bundle.json +++ b/data/set1/bundle.json @@ -1,5 +1,5 @@ { - "bundleName": "set1", + "displayName": "set1", "background": "bg.jpg", "displayTime": true, "useWebFonts": false, diff --git a/modules/admin.js b/modules/admin.js index d690f7e..a271dda 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -380,10 +380,16 @@ class admin { } var duration = data.duration; - if (data.duration === "") { - data.duration = null; + if (data.duration == "") { + duration = null; } + var transition = data.transition; + if (data.transition == "") { + transition = null; + } + + try { fs.writeFileSync("./data/" + data.bundleName + "/render/" + filename + ".png", data.png.replace(/^data:image\/png;base64,/, ""), "base64"); fs.writeFileSync("./data/" + data.bundleName + "/slides/" + filename, JSON.stringify(data.json)); @@ -399,7 +405,7 @@ class admin { displayTime: data.displayTime, type: "slide", index: bundle.allSlides.length, - transition: data.transition, + transition: transition, }; let obj = bundle.findSlideByUuid(filename); @@ -409,7 +415,7 @@ class admin { obj.name = data.name; obj.duration = duration; obj.displayTime = data.displayTime; - obj.transition = data.transition; + obj.transition = transition; } bundle.save(); @@ -497,7 +503,7 @@ class admin { previewInstances.push({adminId: socket.id, preview: {}, currentView: {}}); let serverOptions = getView(displayId).serverOptions; - let bundleDirs = getDirectories("./data"); + let bundleDirs = self.bundleManager.getBundleInfos(); let meta = JSON.parse(fs.readFileSync("./data/meta.json").toString()); socket.emit("callback.dashboard.sync", { diff --git a/modules/bundle.js b/modules/bundle.js index af3cf7c..949e0ab 100644 --- a/modules/bundle.js +++ b/modules/bundle.js @@ -1,11 +1,15 @@ let cli = require("./cli.js"); let fs = require("fs"); +/** + * + */ class bundleClass { constructor(name, data, slides) { this.name = name; this.bundleData = data; + this.bundleData['bundleName']= this.name; this.allSlides = slides; this.enabledSlides = []; this.disabledSlides = []; @@ -13,6 +17,7 @@ class bundleClass { } getBundleData() { + this.bundleData['bundleName'] = this.name; // to ensure backwards compatibility return this.bundleData; } diff --git a/modules/bundleManager.js b/modules/bundleManager.js index 3e50024..aadb55b 100644 --- a/modules/bundleManager.js +++ b/modules/bundleManager.js @@ -31,7 +31,7 @@ class bundleManager { return this.bundles[name]; } else { try { - cli.info(name + " not in bundles, trygin to load from fs..."); + cli.info(name + " not in bundles, trying to load from fs..."); let data = getJson("./data/" + name + "/bundle.json"); let slides = getJson("./data/" + name + "/slides.json"); this.bundles[name] = new bundle(name, data, slides); @@ -43,6 +43,20 @@ class bundleManager { } } + /** + * + * @return {Array} + */ + getBundleInfos() { + let out = []; + for (let key in this.bundles) { + out.push({ + dir: key, + name: this.bundles[key].getBundleData().displayName + }); + } + return out; + } } function getDirectories(path) { diff --git a/modules/display.js b/modules/display.js index 76e745b..539e14d 100644 --- a/modules/display.js +++ b/modules/display.js @@ -111,7 +111,6 @@ class display { init(meta) { this.changeBundle(meta.bundle); - this.mainLoop(); } /** @@ -123,9 +122,12 @@ class display { let bundle = this.getBundle(); this.serverOptions.loopIndex = 0; this.serverOptions.currentFile = bundle.enabledSlides[0] || ""; - this.serverOptions.slideDuration = bundle.findSlideByUuid(bundle.enabledSlides[0]).duration || bundle.getBundleData().duration; + this.serverOptions.currentMeta = bundle.findSlideByUuid(bundle.enabledSlides[0]); + this.serverOptions.slideDuration = bundle.getBundleData().duration; this.serverOptions.currentId = bundle.enabledSlides.indexOf(this.serverOptions.currentFile); this.serverOptions.transition = bundle.getBundleData().transition; + this.serverOptions.loop = true; + this.mainLoop(); } getSlideData() { @@ -189,25 +191,30 @@ class display { this.serverOptions.displayTime = bundle.bundleData.displayTime; } - this.displayCurrentSlide(); - - - this.serverOptions.loopIndex += 1; - if (this.serverOptions.loop) { let that = this; // override slide timeout if set by slide var slideTimeout = this.serverOptions.slideDuration * 1000; - if (this.serverOptions.currentMeta.duration !== null) { + if (this.serverOptions.currentMeta.duration > 5) { slideTimeout = parseFloat(this.serverOptions.currentMeta.duration) * 1000; } - this.timeoutId.push( - setTimeout(function () { - that.mainLoop(); - }, slideTimeout)); + console.log(this.serverOptions.displayId + " timeout:" + slideTimeout); + + if (slideTimeout >= 5000) { + this.timeoutId.push( + setTimeout(function () { + that.mainLoop(); + }, slideTimeout)); + + } else { + this.serverOptions.loop = false; + } } + + this.displayCurrentSlide(); + this.serverOptions.loopIndex += 1; } overrideSlide(json, pngData, duration) { diff --git a/public/js/dashboard.js b/public/js/dashboard.js index db042df..88c6b36 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -30,17 +30,18 @@ socket.on("callback.dashboard.sync", function (data) { // update dropdown at menu with bundles var valueArray = []; for (var dir of bundleDirs) { - valueArray.push({name: dir, value: dir}); + valueArray.push({name: dir.name, value: dir.dir}); } $('#bundles') .dropdown({ direction: "upward", values: valueArray, - action: function (text, value) { + action: function (_label, _value) { $('#bundles') .dropdown("hide"); - emit("admin.setBundle", {bundle: value}); + + emit("admin.setBundle", {bundle: _value}); } }).dropdown("set selected", {bundle: serverOptions.currentBundle}); $('#currentBundle').text(serverOptions.currentBundle); @@ -101,14 +102,15 @@ socket.on("callback.dashboard.sync", function (data) { let output = ""; for (var i in data.bundleDirs) { let bundle = data.bundleDirs[i]; - output += '
' + + output += '
' + '
' + // '' + - '' + - '' + + '' + + '' + + '' + '
' + '
' + - '
' + bundle + '
' + + '
' + bundle.name + '
' + '
' + '
'; } @@ -188,6 +190,9 @@ function addLink() { editSlide("", "webpage"); } +function changeBundle(name) { + emit("admin.setBundle", {bundle: name}); +} function editBundleSlides(name) { window.open("/admin/edit/bundleSlides?bundle=" + name, '_blank', 'location=no,height=800,width=400,scrollbars=yes,status=no'); @@ -291,6 +296,19 @@ function updateSlides(settings) { $("#bundleSlides").html(output); $('#bundleSlides').children().css("border", "1px solid black"); $('#' + serverOptions.currentFile).css("border", "1px solid #1ebc30"); + $('.editable').editable(function (value, settings) { + var uuid = $(this).parent().parent().attr("id"); + emit("admin.renameSlide", {uuid: uuid, name: value, bundleName: serverOptions.currentBundle}); + return (value); + }, { + submit: 'rename', + tooltip: "Doubleclick to edit...", + event: "dblclick", + cssclass: 'ui mini nopadded form', + cancelcssclass: 'ui tiny basic negative button', + submitcssclass: 'ui tiny basic positive button', + }); + } diff --git a/public/js/edit.js b/public/js/edit.js index e687c5a..4002300 100644 --- a/public/js/edit.js +++ b/public/js/edit.js @@ -2,6 +2,7 @@ let canvas; let bundleData; let _clipboard = null; +let slideName = "untitled"; bundleData = { background: "", @@ -161,8 +162,8 @@ socket.on('callback.save', function (data) { if (data.error) { alert(data.error); } else { - alert("slide saved successfully."); - //window.close(); + // alert("slide saved successfully."); + window.close(); } }); @@ -177,6 +178,10 @@ socket.on('callback.edit.updateFileList', function (data) { socket.on('callback.edit', function (data) { canvas.clear(); + console.log(data); + if (data.slideData.name != null) { + slideName = data.slideData.name; + } $("#duration").val(data.slideData.duration + ""); @@ -446,12 +451,13 @@ function cueSlide() { function save() { canvas.setBackgroundImage(null, null, null); - var name = "untitled"; - var texts = canvas.getObjects('i-text'); - for (let i in texts) { - if (texts[i].id == "header") { - name = texts[i].text; - break; + if (slideName == "untitled") { + var texts = canvas.getObjects('i-text'); + for (let i in texts) { + if (texts[i].id == "header") { + slideName = texts[i].text; + break; + } } } @@ -471,20 +477,22 @@ function save() { var transition = $("#transitions").dropdown("get value"); - if (transition === "null") transition = null; + if (transition === "null") transition = ""; var obj = { bundleName: bundle, - name: name, + name: slideName, fileName: file, duration: duration, json: canvas.toJSON(['id']), png: canvas.toDataURL('png'), displayTime: checked, - transition: transition, + transition: transition }; + console.log(obj); + socket.emit("edit.save", obj); } diff --git a/routes/admin.js b/routes/admin.js index 0ff826f..f0311a2 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -53,7 +53,7 @@ module.exports = function (websocket) { try { bundleData = bundleManager.getBundle(req.body.bundle).getBundleData(); - bundleData.bundleName = req.body.bundleName; + bundleData.displayName = req.body.displayName; bundleData.background = req.body.background; bundleData.duration = parseInt(req.body.duration); bundleData.transition = transition; diff --git a/templates/bundle/bundle.json b/templates/bundle/bundle.json index c3e04ae..be62566 100644 --- a/templates/bundle/bundle.json +++ b/templates/bundle/bundle.json @@ -1,5 +1,5 @@ { - "bundleName": "bundle", + "displayName": "bundle", "background": "bg.jpg", "duration": 20, "useWebFonts": false, diff --git a/views/admin/editBundleProperties.twig b/views/admin/editBundleProperties.twig index d5ed4d7..cf923fc 100644 --- a/views/admin/editBundleProperties.twig +++ b/views/admin/editBundleProperties.twig @@ -18,7 +18,7 @@
- +