sc-manager/client/status/status.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-09-08 07:53:42 +00:00
const m = require('mithril')
const socket = require('../socket')
const Module = require('../module')
const util = require('../util')
2020-09-08 07:53:42 +00:00
const Status = Module({
init: function() {
},
remove: function() {
},
restartClicked: function() {
socket.emit('core.restart', {})
},
startSoftware: function(name) {
socket.emit('core.start', {
name: name,
})
},
2020-09-08 07:53:42 +00:00
view: function() {
let name = this.core.name
if (this.core.title) {
name += ' - ' + this.core.title
}
2020-09-08 07:53:42 +00:00
return m('div#status', [
m('h1.header', name),
2020-09-08 07:53:42 +00:00
m('div.split', [
this.core.apps.map((app) => {
let box = []
let appStatus = this.core.status[app.name] || {}
box.push(m('h4', [
app.name + ' (',
m('span', { class: appStatus.running ? 'running' : 'notrunning' }, appStatus.running ? 'Running ' + appStatus.running : 'Not running'),
')'
]))
box.push(m('p', app.config.port
? `Port: ${app.config.port}`
: ''))
box.push(m('p', util.getRepoMessage(app)))
box.push(m('p', 'Running version: ' + util.getVersionSummary(appStatus.active, appStatus)))
box.push(m('p', 'Latest installed: ' + util.getVersionSummary(appStatus.latestInstalled)))
if (!this.core.status[app.name].running) {
box.push(m('button', {
onclick: () => this.startSoftware(app.name),
}, 'Start'))
} else if (app.config.scAllowStop) {
box.push(m('button.fatal', {
onclick: () => this.startSoftware(app.name),
}, 'Restart'))
}
return m('div.item', box)
2020-09-08 07:53:42 +00:00
}),
]),
m('button.fatal', {
hidden: !this.core.allowRestart,
2020-09-08 07:53:42 +00:00
onclick: () => this.restartClicked(),
}, 'Restart ' + this.core.name)
2020-09-08 07:53:42 +00:00
])
}
})
module.exports = Status