sc-manager/client/status/status.js

124 lines
3.3 KiB
JavaScript

const m = require('mithril')
const socket = require('../socket')
const Module = require('../module')
const Status = Module({
init: function() {
this._name = '...loading...'
this._apps = []
this._socketOn(() => this.loadData())
},
loadData: function() {
socket.emit('core.config', {}, (res) => {
this._apps = []
console.log('config', res)
this._name = res.name
if (res.title) {
this._name += ' - ' + res.title
}
for (let appName of res.applications) {
this._apps.push({
name: appName,
config: res[appName],
})
}
console.log(this._apps)
m.redraw()
})
this.on('core.db', (res) => {
console.log('db', res)
m.redraw()
})
this.on('core.status', (res) => {
console.log(res)
/*this._management.running = res.manage
this._management.updating = res.manageUpdating
this._management.starting = res.manageStarting
this._app.running = res.app
this._app.updating = res.appUpdating
this._app.starting = res.appStarting*/
m.redraw()
})
socket.emit('core.listencore', {})
},
remove: function() {
socket.emit('core.unlistencore', {})
},
restartClicked: function() {
socket.emit('core.restart', {})
},
start: function(name) {
socket.emit('core.updatestart', {
name: name,
})
},
getStatus: function(active) {
if (active.updating) {
return '< Updating >'
} else {
return '< Starting >'
}
},
view: function() {
let loopOver = [
['Management service', '_management'],
['Application service', '_app'],
]
return m('div#status', [
m('h1.header', this._name),
m('div.split', [
this._apps.map((app) => {
return m('div.item', [
m('h4', app.name),
m('p', app.config.port
? `Port: ${app.config.port}`
: ''),
m('p', app.config.repository
? `${app.config.repository}`
: '< no repository >'),
m('p', app.config.active
? `Running version: ${app.config.active}`
: '< no running version >'),
m('p', app.config.latestInstalled
? `Latest installed: ${app.config.latestInstalled}`
: '< no version installed >'),
m('p', app.config.latestVersion
? `Latest version: ${app.config.latestVersion}`
: '< no version found >'),
app.config.running !== null && app.config.repository
? m('p',
{ class: app.config.running ? 'running' : 'notrunning' },
app.config.running ? 'Running' : 'Not Running'
)
: null,
!app.config.running && (app.config.updating || app.config.starting)
? m('div.status', this.getStatus(app.config))
: null,
m('button', {
hidden: app.config.running || app.config.updating || app.config.starting || !app.config.repository,
onclick: () => this.start(app.config.name),
}, 'Update/Start')
])
}),
]),
m('button', {
onclick: () => this.restartClicked(),
}, 'Restart service')
])
}
})
module.exports = Status