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...'
|
2022-03-28 07:27:18 +00:00
|
|
|
this._apps = []
|
2020-09-08 07:53:42 +00:00
|
|
|
|
|
|
|
this._socketOn(() => this.loadData())
|
|
|
|
},
|
|
|
|
|
|
|
|
loadData: function() {
|
|
|
|
socket.emit('core.config', {}, (res) => {
|
2022-03-28 07:27:18 +00:00
|
|
|
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) => {
|
2022-03-28 07:27:18 +00:00
|
|
|
console.log('db', res)
|
2020-09-08 07:53:42 +00:00
|
|
|
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
this.on('core.status', (res) => {
|
2020-09-09 15:42:55 +00:00
|
|
|
console.log(res)
|
2022-03-28 07:27:18 +00:00
|
|
|
/*this._management.running = res.manage
|
2020-09-09 15:42:55 +00:00
|
|
|
this._management.updating = res.manageUpdating
|
|
|
|
this._management.starting = res.manageStarting
|
2020-09-08 07:53:42 +00:00
|
|
|
this._app.running = res.app
|
2020-09-09 15:42:55 +00:00
|
|
|
this._app.updating = res.appUpdating
|
2022-03-28 07:27:18 +00:00
|
|
|
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', {})
|
|
|
|
},
|
|
|
|
|
2020-09-09 15:42:55 +00:00
|
|
|
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', [
|
2022-03-28 07:27:18 +00:00
|
|
|
this._apps.map((app) => {
|
2020-09-08 07:53:42 +00:00
|
|
|
return m('div.item', [
|
2022-03-28 07:27:18 +00:00
|
|
|
m('h4', app.name),
|
|
|
|
m('p', app.config.port
|
|
|
|
? `Port: ${app.config.port}`
|
2020-09-08 07:53:42 +00:00
|
|
|
: ''),
|
2022-03-28 07:27:18 +00:00
|
|
|
m('p', app.config.repository
|
|
|
|
? `${app.config.repository}`
|
2020-09-08 07:53:42 +00:00
|
|
|
: '< no repository >'),
|
2022-03-28 07:27:18 +00:00
|
|
|
m('p', app.config.active
|
|
|
|
? `Running version: ${app.config.active}`
|
2020-09-08 07:53:42 +00:00
|
|
|
: '< no running version >'),
|
2022-03-28 07:27:18 +00:00
|
|
|
m('p', app.config.latestInstalled
|
|
|
|
? `Latest installed: ${app.config.latestInstalled}`
|
2020-09-08 07:53:42 +00:00
|
|
|
: '< no version installed >'),
|
2022-03-28 07:27:18 +00:00
|
|
|
m('p', app.config.latestVersion
|
|
|
|
? `Latest version: ${app.config.latestVersion}`
|
2020-09-08 07:53:42 +00:00
|
|
|
: '< no version found >'),
|
2022-03-28 07:27:18 +00:00
|
|
|
app.config.running !== null && app.config.repository
|
2020-09-08 07:53:42 +00:00
|
|
|
? m('p',
|
2022-03-28 07:27:18 +00:00
|
|
|
{ class: app.config.running ? 'running' : 'notrunning' },
|
|
|
|
app.config.running ? 'Running' : 'Not Running'
|
2020-09-08 07:53:42 +00:00
|
|
|
)
|
|
|
|
: null,
|
2022-03-28 07:27:18 +00:00
|
|
|
!app.config.running && (app.config.updating || app.config.starting)
|
|
|
|
? m('div.status', this.getStatus(app.config))
|
2020-09-09 15:42:55 +00:00
|
|
|
: null,
|
2020-09-08 07:53:42 +00:00
|
|
|
m('button', {
|
2022-03-28 07:27:18 +00:00
|
|
|
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
|