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 {
@status-red: #BD5F6D;
@status-green: #59AEA8;
@status-orange: #D89C40;
margin-bottom: 10px;
@ -163,9 +164,13 @@ header {
background-color: @status-red;
}
&.running {
&.started {
background-color: @status-green;
}
&.stopping {
background-color: @status-orange;
}
}
}

View file

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

View file

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

View file

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

View file

@ -24,6 +24,7 @@ function ProcessGroup(name, processes) {
this.name = name;
this.state = ProcessGroupStates.STOPPED;
this.processes = [];
this.restarting = false;
for (let process of processes) {
this.addProcess(process);
@ -57,6 +58,16 @@ ProcessGroup.prototype = extend(ProcessGroup.prototype, {
}
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
onProcessStateUpdate: function(process) {
@ -69,6 +80,12 @@ ProcessGroup.prototype = extend(ProcessGroup.prototype, {
}
if (!processesStillRunning) {
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);
}