2016-04-10 08:37:05 +00:00
|
|
|
const m = require('mithril')
|
2020-12-08 11:09:46 +00:00
|
|
|
const Module = require('./module')
|
|
|
|
// const createModule = require('./common/module')
|
2020-04-06 22:47:58 +00:00
|
|
|
const socket = require('../shared/socket')
|
2016-04-10 08:37:05 +00:00
|
|
|
|
2020-12-08 11:09:46 +00:00
|
|
|
const Menu = Module({
|
2016-04-14 04:01:51 +00:00
|
|
|
init: function() {
|
2020-12-08 11:09:46 +00:00
|
|
|
this.list = []
|
|
|
|
this.settings = {}
|
|
|
|
this.totalSchedule = 0
|
|
|
|
this.status = {
|
2018-06-26 18:35:12 +00:00
|
|
|
connected: false,
|
|
|
|
playing: false,
|
2020-12-08 11:09:46 +00:00
|
|
|
error: '',
|
|
|
|
}
|
|
|
|
this._socketOn(() => this.socketOpen())
|
2018-06-26 18:35:12 +00:00
|
|
|
this.newHost = ''
|
|
|
|
this.enableEdit = false
|
|
|
|
},
|
|
|
|
|
2020-12-08 11:09:46 +00:00
|
|
|
socketOpen: function() {
|
|
|
|
socket.on('graphic.all', (res) => {
|
|
|
|
this.list = res
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
socket.on('graphic.created', (res) => {
|
|
|
|
this.list.push(res)
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
this.on('settings.all', (res) => {
|
|
|
|
this.settings = res
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
this.on('schedule.total', (res) => {
|
|
|
|
this.totalSchedule = res.total
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
this.on('casparcg.status', (res) => {
|
|
|
|
this.status = res
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
socket.emit('graphic.all', {})
|
|
|
|
socket.emit('settings.all', {})
|
|
|
|
socket.emit('schedule.total', {})
|
|
|
|
socket.emit('casparcg.status', {})
|
|
|
|
},
|
|
|
|
|
2018-06-26 18:35:12 +00:00
|
|
|
setHost(value) {
|
|
|
|
this.newHost = value
|
|
|
|
this.enableEdit = true
|
|
|
|
},
|
|
|
|
|
|
|
|
saveNewHost() {
|
|
|
|
socket.emit('settings.update', {
|
2020-04-06 22:47:58 +00:00
|
|
|
name: 'casparhost',
|
2018-06-26 18:35:12 +00:00
|
|
|
value: this.newHost,
|
|
|
|
})
|
|
|
|
|
|
|
|
this.newHost = ''
|
|
|
|
this.enableEdit = false
|
|
|
|
},
|
2020-12-08 11:09:46 +00:00
|
|
|
view: function() {
|
|
|
|
return [
|
|
|
|
m(m.route.Link, {
|
|
|
|
href: '/',
|
|
|
|
class: m.route.get() === '/' && 'active' || '',
|
|
|
|
}, `Schedule (${this.totalSchedule})` ),
|
|
|
|
m('h4.header.header--space', 'Graphics'),
|
|
|
|
this.list.map((item) =>
|
|
|
|
m(m.route.Link, {
|
|
|
|
href: `/graphic/${item.id}`,
|
|
|
|
class: m.route.get() === `/graphic/${item.id}` && 'active' || '',
|
|
|
|
}, item.name)
|
|
|
|
),
|
|
|
|
m('h5.header.header--space', 'Other'),
|
|
|
|
m(m.route.Link, {
|
|
|
|
href: '/add',
|
|
|
|
class: m.route.get() === '/add' && 'active' || '',
|
|
|
|
}, 'Add graphic' ),
|
|
|
|
m('h5.header.header--space', 'CasparCG Status'),
|
|
|
|
m('input[type=text]', {
|
|
|
|
placeholder: 'Host IP',
|
|
|
|
value: this.newHost || this.settings.casparhost || '',
|
|
|
|
oninput: control => this.setHost(control.target.value),
|
|
|
|
}),
|
|
|
|
this.enableEdit && m('button', {
|
|
|
|
onclick: () => this.saveNewHost(),
|
|
|
|
}, 'Connect'),
|
|
|
|
m('div.status', {
|
|
|
|
class: this.status.connected && 'green',
|
|
|
|
}, 'connected'),
|
|
|
|
m('div.status', {
|
|
|
|
class: this.status.playing && 'green',
|
|
|
|
}, 'playing'),
|
|
|
|
m('div.status-error', { hidden: !this.status.error }, this.status.error)
|
|
|
|
]
|
|
|
|
}
|
2016-04-14 04:01:51 +00:00
|
|
|
})
|
2016-04-10 08:37:05 +00:00
|
|
|
module.exports = Menu
|