sc-manager/client/status/status.js

124 lines
3.3 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 Status = Module({
init: function() {
this._name = '...loading...'
this._apps = []
2020-09-08 07:53:42 +00:00
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)
2020-09-08 07:53:42 +00:00
m.redraw()
})
this.on('core.db', (res) => {
console.log('db', res)
2020-09-08 07:53:42 +00:00
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
2020-09-08 07:53:42 +00:00
this._app.running = res.app
this._app.updating = res.appUpdating
this._app.starting = res.appStarting*/
2020-09-08 07:53:42 +00:00
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 >'
}
},
2020-09-08 07:53:42 +00:00
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) => {
2020-09-08 07:53:42 +00:00
return m('div.item', [
m('h4', app.name),
m('p', app.config.port
? `Port: ${app.config.port}`
2020-09-08 07:53:42 +00:00
: ''),
m('p', app.config.repository
? `${app.config.repository}`
2020-09-08 07:53:42 +00:00
: '< no repository >'),
m('p', app.config.active
? `Running version: ${app.config.active}`
2020-09-08 07:53:42 +00:00
: '< no running version >'),
m('p', app.config.latestInstalled
? `Latest installed: ${app.config.latestInstalled}`
2020-09-08 07:53:42 +00:00
: '< no version installed >'),
m('p', app.config.latestVersion
? `Latest version: ${app.config.latestVersion}`
2020-09-08 07:53:42 +00:00
: '< no version found >'),
app.config.running !== null && app.config.repository
2020-09-08 07:53:42 +00:00
? m('p',
{ class: app.config.running ? 'running' : 'notrunning' },
app.config.running ? 'Running' : 'Not Running'
2020-09-08 07:53:42 +00:00
)
: null,
!app.config.running && (app.config.updating || app.config.starting)
? m('div.status', this.getStatus(app.config))
: null,
2020-09-08 07:53:42 +00:00
m('button', {
hidden: app.config.running || app.config.updating || app.config.starting || !app.config.repository,
onclick: () => this.start(app.config.name),
2020-09-08 07:53:42 +00:00
}, 'Update/Start')
])
}),
]),
m('button', {
onclick: () => this.restartClicked(),
}, 'Restart service')
])
}
})
module.exports = Status