service-core/dev/app/header.js

45 lines
1 KiB
JavaScript
Raw Normal View History

2020-09-01 17:31:38 +00:00
const m = require('mithril')
const socket = require('./socket')
const Header = {
oninit: function() {
this.connected = socket.connected
socket.on('connect', () => {
this.connected = true
m.redraw()
})
socket.on('disconnect', () => {
this.connected = false
m.redraw()
})
},
view: function() {
2020-09-07 00:47:53 +00:00
let path = m.route.get() || ''
2020-09-01 17:31:38 +00:00
return [
m('div.seperator'),
m(m.route.Link, {
href: '/',
2020-09-07 00:47:53 +00:00
class: path === '/' || path === '' ? 'active' : '',
}, 'Status'),
2020-09-01 17:31:38 +00:00
m('div.seperator'),
m(m.route.Link, {
href: '/log',
class: path === '/log' ? 'active' : '',
}, 'Log'),
m('div.seperator'),
2020-09-07 00:47:53 +00:00
m(m.route.Link, {
href: '/updater',
class: path.startsWith('/updater') ? 'active' : '',
}, 'Updater'),
m('div.seperator'),
2020-09-01 17:31:38 +00:00
!this.connected && m('div.disconnected', `
Lost connection with server, Attempting to reconnect
`) || null,
]
}
}
module.exports = Header