const m = require('mithril') const socket = require('../socket') const Module = require('../module') const util = require('../util') const Status = Module({ init: function() { }, remove: function() { }, restartClicked: function() { socket.emit('core.restart', {}) }, startSoftware: function(name) { socket.emit('core.start', { name: name, }) }, view: function() { let name = this.core.name if (this.core.title) { name += ' - ' + this.core.title } return m('div#status', [ m('h1.header', name), 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) }), ]), m('button.fatal', { hidden: !this.core.allowRestart, onclick: () => this.restartClicked(), }, 'Restart ' + this.core.name) ]) } }) module.exports = Status