diff --git a/app/client.js b/app/client.js index 60c7272..e38be1f 100644 --- a/app/client.js +++ b/app/client.js @@ -3,6 +3,7 @@ var socket = require('./socket') var engines = { text: require('./frontend/text'), countdown: require('./frontend/countdown'), + schedule: require('./frontend/schedule'), } var current = [] diff --git a/app/controller/components.js b/app/controller/components.js index c6c7781..2858940 100644 --- a/app/controller/components.js +++ b/app/controller/components.js @@ -6,6 +6,45 @@ exports.error = function(error) { return m('div.error-box', error) } +exports.presetOnlyList = function(vm) { + return [ + m('label', 'Presets'), + m('ul.panel-graphic-preset', vm.presets.map((item, index) => + m('li', { key: index }, [ + m('.row', { key: index }, [ + m('div', { class: 'small-8 columns panel-graphic-property-item' }, + m('input[type=text]', { + readonly: true, + value: item.values[graphic.settings.main], + }) + ), + m('div', { class: 'small-2 columns' }, + m('a.panel-graphic-preset-remove.button.success', { + onclick: vm.displayPreset.bind(vm, item), + }, 'Display') + ), + m('div', { class: 'small-2 columns' }, + m('a.panel-graphic-preset-remove.button.alert', { + onclick: vm.removePreset.bind(vm, item), + }, 'Remove') + ), + ]) + ]) + )) + ] +} + +exports.presetButtons = function(vm) { + return [ + m('a.panel-graphic-preset-add.button', { + onclick: vm.addPreset.bind(vm), + }, 'Save to preset list'), + m('a.panel-graphic-display.success.button', { + onclick: vm.displayCurrent.bind(vm), + }, 'Display'), + ] +} + exports.presetList = function(vm) { return [ m('a.panel-graphic-preset-add.button', { diff --git a/app/controller/graphic/controller.js b/app/controller/graphic/controller.js index 70fcdae..ebaf9ad 100644 --- a/app/controller/graphic/controller.js +++ b/app/controller/graphic/controller.js @@ -11,6 +11,7 @@ const Graphic = createModule({ this.currentView = 'view' this.current = {} this.newProperty = m.prop('') + this.newTextField = m.prop('') }, updated: function(name, variable, control) { @@ -25,24 +26,51 @@ const Graphic = createModule({ } }, - addProperty: function() { - if (!this.newProperty()) { - this.error = 'Please type in property name' - return - } - if (this.graphic.settings.properties.includes(this.newProperty())) { - this.error = 'A property with that name already exists' - return + addDataField: function(type, name) { + if (!name) { + return 'Please type in proper name' } - this.graphic.settings.properties.push(this.newProperty()) - this.newProperty('') - - if (!this.graphic.settings.main) { - this.graphic.settings.main = this.graphic.settings.properties[0] + if (this.graphic.settings[type].includes(name)) { + return 'A property with that name already exists' } + this.graphic.settings[type].push(name) + socket.emit('graphic.update', this.graphic) + + return null + }, + + addProperty: function() { + this.error = this.addDataField('properties', this.newProperty()) + + if (!this.error) { + this.newProperty('') + + if (!this.graphic.settings.main) { + this.graphic.settings.main = this.graphic.settings.properties[0] + socket.emit('graphic.update', this.graphic) + } + } + }, + + addTextField: function() { + this.error = this.addDataField('textfields', this.newTextField()) + + if (!this.error) { + this.newTextField('') + } + }, + + removeDataField: function(type, name) { + this.graphic.settings[type].splice( + this.graphic.settings[type].indexOf(name), 1) + socket.emit('graphic.update', this.graphic) + }, + + removeProperty: function(prop) { + this.removeDataField('properties', prop) }, cleanCurrent: function() { @@ -116,12 +144,6 @@ const Graphic = createModule({ }) }, - removeProperty: function(prop) { - this.graphic.settings.properties.splice( - this.graphic.settings.properties.indexOf(prop), 1) - socket.emit('graphic.update', this.graphic) - }, - switchView: function() { if (Graphic.vm.currentView === 'view') { Graphic.vm.currentView = 'settings' diff --git a/app/controller/graphic/engine/schedule.js b/app/controller/graphic/engine/schedule.js new file mode 100644 index 0000000..d0dc583 --- /dev/null +++ b/app/controller/graphic/engine/schedule.js @@ -0,0 +1,162 @@ +const m = require('mithril') +const components = require('../../components') + +exports.view = function(ctlr, graphic, vm) { + if (!graphic.settings.properties) { + graphic.settings.properties = [] + } + if (!graphic.settings.textfields) { + graphic.settings.textfields = [] + } + if (graphic.settings.properties.length === 0) { + return [ + m('p', 'No properties have been defined.'), + m('p', 'Click settings to create and define properties to display.'), + ] + } + return [ + components.presetOnlyList(vm), + graphic.settings.properties.map((prop, index) => + m('label', { key: index }, [ + prop, + m('input[type=text]', { + value: vm.current[prop] || '', + oninput: vm.updated.bind(vm, prop, 'current'), + }), + ]) + ), + graphic.settings.textfields.map((prop, index) => + m('label', { key: index }, [ + prop, + m('textarea', { + rows: '6', + oninput: vm.updated.bind(vm, prop, 'current'), + value: vm.current[prop] || '', + }), + ]) + ), + components.presetButtons(vm), + ] +} + +exports.settings = function(cltr, graphic, vm) { + return [ + m('label', [ + 'Name', + m('input[type=text]', { + value: graphic.name, + oninput: vm.updated.bind(vm, 'name'), + }), + ]), + m('label', [ + 'HTML (', + m('a', { href: 'https://lodash.com/docs#template', target: '_blank' }, 'variables'), + ' available: ', + graphic.settings.properties.map(prop => + `<%- ${prop} %>` + ).join(', '), + ', ', + graphic.settings.textfields.map(prop => + `<%- ${prop} %>` + ).join(', '), + ')', + m('p', `