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._management = {
|
2020-09-09 15:42:55 +00:00
|
|
|
name: 'manage',
|
2020-09-08 07:53:42 +00:00
|
|
|
port: null,
|
|
|
|
repository: null,
|
|
|
|
active: null,
|
|
|
|
latestInstalled: null,
|
|
|
|
latestVersion: null,
|
|
|
|
running: null,
|
2020-09-09 15:42:55 +00:00
|
|
|
updating: null,
|
|
|
|
starting: null,
|
2020-09-08 07:53:42 +00:00
|
|
|
}
|
|
|
|
this._app = {
|
2020-09-09 15:42:55 +00:00
|
|
|
name: 'app',
|
2020-09-08 07:53:42 +00:00
|
|
|
port: null,
|
|
|
|
repository: null,
|
|
|
|
active: null,
|
|
|
|
latestInstalled: null,
|
|
|
|
latestVersion: null,
|
|
|
|
running: null,
|
2020-09-09 15:42:55 +00:00
|
|
|
updating: null,
|
|
|
|
starting: null,
|
2020-09-08 07:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._socketOn(() => this.loadData())
|
|
|
|
},
|
|
|
|
|
|
|
|
loadData: function() {
|
|
|
|
socket.emit('core.config', {}, (res) => {
|
|
|
|
this._name = res.name + ' - ' + res.serviceName
|
|
|
|
this._app.port = res.port
|
|
|
|
this._app.repository = res.appRepository
|
|
|
|
this._management.port = res.managePort
|
|
|
|
this._management.repository = res.manageRepository
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
this.on('core.db', (res) => {
|
|
|
|
this._management.active = res.manageActive
|
|
|
|
this._management.latestInstalled = res.manageLatestInstalled
|
|
|
|
this._management.latestVersion = res.manageLatestVersion
|
|
|
|
this._app.active = res.appActive
|
|
|
|
this._app.latestInstalled = res.appLatestInstalled
|
|
|
|
this._app.latestVersion = res.appLatestVersion
|
|
|
|
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
this.on('core.status', (res) => {
|
2020-09-09 15:42:55 +00:00
|
|
|
console.log(res)
|
2020-09-08 07:53:42 +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
|
|
|
|
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', [
|
|
|
|
loopOver.map((group) => {
|
|
|
|
return m('div.item', [
|
|
|
|
m('h4', group[0]),
|
|
|
|
m('p', this[group[1]].port
|
|
|
|
? `Port: ${this[group[1]].port}`
|
|
|
|
: ''),
|
|
|
|
m('p', this[group[1]].repository
|
|
|
|
? `${this[group[1]].repository}`
|
|
|
|
: '< no repository >'),
|
|
|
|
m('p', this[group[1]].active
|
|
|
|
? `Running version: ${this[group[1]].active}`
|
|
|
|
: '< no running version >'),
|
|
|
|
m('p', this[group[1]].latestInstalled
|
|
|
|
? `Latest installed: ${this[group[1]].latestInstalled}`
|
|
|
|
: '< no version installed >'),
|
|
|
|
m('p', this[group[1]].latestVersion
|
|
|
|
? `Latest version: ${this[group[1]].latestVersion}`
|
|
|
|
: '< no version found >'),
|
2020-09-09 15:42:55 +00:00
|
|
|
this[group[1]].running !== null && this[group[1]].repository
|
2020-09-08 07:53:42 +00:00
|
|
|
? m('p',
|
2020-09-09 15:42:55 +00:00
|
|
|
{ class: this[group[1]].running ? 'running' : 'notrunning' },
|
|
|
|
this[group[1]].running ? 'Running' : 'Not Running'
|
2020-09-08 07:53:42 +00:00
|
|
|
)
|
|
|
|
: null,
|
2020-09-09 15:42:55 +00:00
|
|
|
!this[group[1]].running && (this[group[1]].updating || this[group[1]].starting)
|
|
|
|
? m('div.status', this.getStatus(this[group[1]]))
|
|
|
|
: null,
|
2020-09-08 07:53:42 +00:00
|
|
|
m('button', {
|
2020-09-09 15:42:55 +00:00
|
|
|
hidden: this[group[1]].running || this[group[1]].updating || this[group[1]].starting || !this[group[1]].repository,
|
|
|
|
onclick: () => this.start(this[group[1]].name),
|
2020-09-08 07:53:42 +00:00
|
|
|
}, 'Update/Start')
|
|
|
|
])
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
m('button', {
|
|
|
|
onclick: () => this.restartClicked(),
|
|
|
|
}, 'Restart service')
|
|
|
|
])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = Status
|