handle circle color changes for server state

This commit is contained in:
Stephen Birarda 2015-12-21 11:47:15 -07:00
parent 9c793d4317
commit 21c701dc6d
5 changed files with 46 additions and 13 deletions

View file

@ -147,6 +147,7 @@ header {
.process-status { .process-status {
@status-red: #BD5F6D; @status-red: #BD5F6D;
@status-green: #59AEA8; @status-green: #59AEA8;
@status-orange: #D89C40;
margin-bottom: 10px; margin-bottom: 10px;
@ -163,9 +164,13 @@ header {
background-color: @status-red; background-color: @status-red;
} }
&.running { &.started {
background-color: @status-green; background-color: @status-green;
} }
&.stopping {
background-color: @status-orange;
}
} }
} }

View file

@ -53,12 +53,12 @@
<h4 id="status">STATUS</h4> <h4 id="status">STATUS</h4>
</div> </div>
<div id="domain-server-status" class="process-status"> <div id="ds-status" class="process-status">
<div class="circle running"></div> <div class="circle started"></div>
<span>Domain Server</span> <span>Domain Server</span>
</div> </div>
<div id="assignment-status" class="process-status"> <div id="ac-status" class="process-status">
<div class="circle running"></div> <div class="circle started"></div>
<span>Assignment Clients</span> <span>Assignment Clients</span>
</div> </div>
</div> </div>

View file

@ -1,5 +1,6 @@
$(function() { $(function() {
const ipcRenderer = require('electron').ipcRenderer; const ipcRenderer = require('electron').ipcRenderer;
const HFProcess = require('./modules/hf-process.js');
function onProcessUpdate(event, arg) { function onProcessUpdate(event, arg) {
console.log("update", event, arg); console.log("update", event, arg);
@ -11,10 +12,18 @@ $(function() {
// $('#process-interface .power-off').prop('disabled', !interfaceOn); // $('#process-interface .power-off').prop('disabled', !interfaceOn);
var serverState = arg.home.state; var serverState = arg.home.state;
$('#server .status').text(serverState); var serverCircles = $('#ds-status .circle, #ac-status .circle');
var serverOn = serverState != 'stopped'; switch (serverState) {
$('#server .power-on').prop('disabled', serverOn); case HFProcess.ProcessStates.STOPPED:
$('#server .power-off').prop('disabled', !serverOn); serverCircles.attr('class', 'circle stopped');
break;
case HFProcess.ProcessStates.STOPPING:
serverCircles.attr('class', 'circle stopping');
break;
case HFProcess.ProcessStates.STARTED:
serverCircles.attr('class', 'circle started');
break;
}
} }
$('#process-interface .power-on').click(function() { $('#process-interface .power-on').click(function() {
@ -23,10 +32,10 @@ $(function() {
$('#process-interface .power-off').click(function() { $('#process-interface .power-off').click(function() {
ipcRenderer.send('stop-process', { name: 'interface' }); ipcRenderer.send('stop-process', { name: 'interface' });
}); });
$('#server .power-on').click(function() { $('#manage-server #restart').click(function() {
ipcRenderer.send('start-server', { name: 'home' }); ipcRenderer.send('restart-server', { name: 'home' });
}); });
$('#server .power-off').click(function() { $('#manage-server #stop').click(function() {
ipcRenderer.send('stop-server', { name: 'home' }); ipcRenderer.send('stop-server', { name: 'home' });
}); });
$('#open-logs').click(function() { $('#open-logs').click(function() {

View file

@ -148,7 +148,9 @@ app.on('ready', function() {
pInterface.stop(); pInterface.stop();
sendProcessUpdate(); sendProcessUpdate();
}); });
ipcMain.on('start-server', function(event, arg) { ipcMain.on('restart-server', function(event, arg) {
homeServer.stop();
sendProcessUpdate();
homeServer.start(); homeServer.start();
sendProcessUpdate(); sendProcessUpdate();
}); });

View file

@ -24,6 +24,7 @@ function ProcessGroup(name, processes) {
this.name = name; this.name = name;
this.state = ProcessGroupStates.STOPPED; this.state = ProcessGroupStates.STOPPED;
this.processes = []; this.processes = [];
this.restarting = false;
for (let process of processes) { for (let process of processes) {
this.addProcess(process); this.addProcess(process);
@ -57,6 +58,16 @@ ProcessGroup.prototype = extend(ProcessGroup.prototype, {
} }
this.state = ProcessGroupStates.STOPPING; this.state = ProcessGroupStates.STOPPING;
}, },
restart: function() {
// set our restart flag so the group will restart once stopped
this.restarting = true;
// call stop, that will put them in the stopping state
this.stop();
// update our state
this.state = ProcessGroupStates.STOPPING;
},
// Event handlers // Event handlers
onProcessStateUpdate: function(process) { onProcessStateUpdate: function(process) {
@ -69,6 +80,12 @@ ProcessGroup.prototype = extend(ProcessGroup.prototype, {
} }
if (!processesStillRunning) { if (!processesStillRunning) {
this.state = ProcessGroupStates.STOPPED; this.state = ProcessGroupStates.STOPPED;
// if we we're supposed to restart, call start now and reset the flag
if (this.restarting) {
this.start();
this.restarting = false;
}
} }
this.emit('state-update', this, process); this.emit('state-update', this, process);
} }