Skip to content

Commit

Permalink
0.0.10 top-color red on lost connection, loggin of changes only
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldrudell committed Sep 15, 2012
1 parent 5684707 commit dc728ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
11 changes: 10 additions & 1 deletion lib/appentity.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function AppEntity(conf) {
PORT: 0, PORT: 0,
URL: '', URL: '',
} }
var lastState = {}


// init file watchers // init file watchers
var myWatch = new watchit.WatchIt(doWatcherRestart, watchNotify) var myWatch = new watchit.WatchIt(doWatcherRestart, watchNotify)
Expand Down Expand Up @@ -205,7 +206,15 @@ function AppEntity(conf) {
} }


function sendUpdate() { function sendUpdate() {
if (listener) listener(getState()) var state = logDifference(getState())
if (listener) listener(state)
}

function logDifference(state) {
var s = ['Update', state.name + ':']
for (var p in state) if (state[p] != lastState[p]) s.push(p + ':', state[p])
console.log(s.join(' '))
return lastState = state
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion lib/godsocket.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function init(app, clientToControl) {
return send return send


function send(update) { function send(update) {
console.log('update:', JSON.stringify(update)) //console.log('update:', JSON.stringify(update))
socketManager.sockets.emit('fromgod', update) socketManager.sockets.emit('fromgod', update)
} }
} }
2 changes: 1 addition & 1 deletion package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node", "node",
"operations" "operations"
], ],
"version": "0.0.9", "version": "0.0.10",
"contributors": [ "contributors": [
{ {
"name": "Harald Rudell", "name": "Harald Rudell",
Expand Down
24 changes: 21 additions & 3 deletions public/javascripts/frontgod.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ if (typeof $ == 'undefined') alert ('jQuery is missing')
} }


var crashMap = {} var crashMap = {}
var haveACrash = false


function updateCreateApp(app) { function updateCreateApp(app) {
var div = $('#app' + app.id) var div = $('#app' + app.id)
Expand Down Expand Up @@ -108,7 +109,7 @@ if (typeof $ == 'undefined') alert ('jQuery is missing')
var newCrashMap = {} var newCrashMap = {}
// key: id, value: container div for app // key: id, value: container div for app
var elMap = {} var elMap = {}
// overall state // overall state: true means crashed
newCrashMap.all = false newCrashMap.all = false
elMap.all = $('.header') elMap.all = $('.header')
var stateList = $('.state') var stateList = $('.state')
Expand All @@ -121,19 +122,35 @@ if (typeof $ == 'undefined') alert ('jQuery is missing')
if (isCrashed) newCrashMap.all = true if (isCrashed) newCrashMap.all = true
elMap[id] = container elMap[id] = container
}) })
haveACrash = newCrashMap.all

// merge in connection state
if (!isConnected()) newCrashMap.all = true


// update all changed apps // update all changed apps
var bad = 'background-color:#ffb3b3'
for (var id in newCrashMap) { for (var id in newCrashMap) {
var isCrash = newCrashMap[id] var isCrash = newCrashMap[id]
if (isCrash != crashMap[id]) { if (isCrash != crashMap[id]) {
elMap[id].attr('style', isCrash ? bad : '') setElementColor(elMap[id], isCrash)
} }
} }


crashMap = newCrashMap crashMap = newCrashMap
} }


function updateTopColor() {
var bad = haveACrash || !isConnected()
if (bad != crashMap.all) setElementColor($('.header'), crashMap.all = bad)
}

function isConnected() {
return getState() == 2
}

function setElementColor(el, isBad) {
el.attr('style', isBad ? 'background-color:#ffb3b3' : '')
}

var timezoneMinutesOffUtc = -new Date().getTimezoneOffset() var timezoneMinutesOffUtc = -new Date().getTimezoneOffset()
function dateString(value) { function dateString(value) {
var result = '?' var result = '?'
Expand Down Expand Up @@ -228,6 +245,7 @@ if (typeof $ == 'undefined') alert ('jQuery is missing')
reconnectEnable(newState != 2) reconnectEnable(newState != 2)
//$('.connected').text() //$('.connected').text()
$('#status').text(texts[newState] + ' at ' + dateString(Date.now())) $('#status').text(texts[newState] + ' at ' + dateString(Date.now()))
updateTopColor()
} }
} }
function reconnectEnable(flag) { function reconnectEnable(flag) {
Expand Down

0 comments on commit dc728ea

Please sign in to comment.