2018-06-26 18:35:12 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
const m = require('mithril')
|
|
|
|
const createModule = require('../common/module')
|
2020-04-06 22:47:58 +00:00
|
|
|
const socket = require('../../shared/socket')
|
2018-06-26 18:35:12 +00:00
|
|
|
|
|
|
|
const Dagskra = createModule({
|
|
|
|
init: function() {
|
|
|
|
this.error = ''
|
|
|
|
this.displayRemove = false
|
|
|
|
this.monitor('schedule', 'schedule.all', [])
|
|
|
|
},
|
|
|
|
|
|
|
|
scheduleListInit: function(control) {
|
|
|
|
this.initDragula(control, (source, target) => {
|
|
|
|
let dragOldIndex = _.findIndex(this.schedule, { id: Number(source.getAttribute('data')) })
|
|
|
|
let targetOldIndex = this.schedule.length - 1
|
|
|
|
if (target) {
|
|
|
|
targetOldIndex = _.findIndex(this.schedule, { id: Number(target.getAttribute('data')) })
|
|
|
|
}
|
|
|
|
|
|
|
|
this.schedule.splice(targetOldIndex, 0, this.schedule.splice(dragOldIndex, 1)[0])
|
|
|
|
|
|
|
|
this.schedule.forEach((item, i) => {
|
|
|
|
item.sort = i + 1
|
|
|
|
})
|
|
|
|
|
|
|
|
socket.emit('schedule.patch', this.schedule)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
displaySchedule: function(item) {
|
|
|
|
socket.emit('content.display', {
|
|
|
|
graphic: item.graphic,
|
|
|
|
data: item.values,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
removeSchedule: function(item) {
|
|
|
|
socket.emit('schedule.remove', item)
|
|
|
|
},
|
|
|
|
}, function() {
|
|
|
|
this.schedule.forEach(item => {
|
|
|
|
if (!item.cachedDisplay) {
|
|
|
|
try {
|
|
|
|
item.cachedDisplay = _.template(item.graphic.settings.main || '')(item.values)
|
|
|
|
} catch (e) {
|
|
|
|
item.cachedDisplay = `ERROR WITH TEMPLATE: ${e.message}`
|
|
|
|
}
|
|
|
|
item.cachedDisplay = `[${item.graphic.name}] ${item.cachedDisplay}`
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return [
|
|
|
|
m('h4.header', 'Schedule'),
|
|
|
|
m('div.graphic-presetlist', {
|
|
|
|
oncreate: control => this.scheduleListInit(control),
|
|
|
|
},
|
|
|
|
this.schedule.map(item =>
|
|
|
|
m('div.graphic-preset', {
|
|
|
|
key: `preset-${item.id}`,
|
|
|
|
data: item.id,
|
|
|
|
}, [
|
|
|
|
m('div.graphic-preset-reorder'),
|
|
|
|
m('input[type=text]', {
|
|
|
|
readonly: true,
|
|
|
|
value: item.cachedDisplay,
|
|
|
|
}),
|
|
|
|
m(`button.green`, {
|
|
|
|
onclick: () => this.displaySchedule(item),
|
|
|
|
}, 'Display'),
|
|
|
|
this.displayRemove && m('button.red', {
|
|
|
|
onclick: () => this.removeSchedule(item),
|
|
|
|
}, 'Remove') || null,
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
this.schedule.length
|
|
|
|
&& m('button.red.graphic-presetremove', {
|
|
|
|
onclick: () => (this.displayRemove = !this.displayRemove),
|
|
|
|
}, 'Remove entries')
|
|
|
|
|| m('div.schedule-empty', 'Schedule is empty'),
|
|
|
|
]
|
|
|
|
})
|
|
|
|
module.exports = Dagskra
|