diff --git a/platform/persistence/src/CouchIndicator.js b/platform/persistence/src/CouchIndicator.js index 88e05df480..7818bf2988 100644 --- a/platform/persistence/src/CouchIndicator.js +++ b/platform/persistence/src/CouchIndicator.js @@ -5,18 +5,49 @@ define( function () { "use strict"; - function CouchIndicator($http, $interval, PATH, INTERVAL) { - function updateIndicator() { + var CONNECTED = { + text: "Connected", + glyphClass: "ok" + }, + DISCONNECTED = { + text: "Disconnected", + glyphClass: "err" + }, + PENDING = { + text: "Checking connection..." + }; + function CouchIndicator($http, $interval, PATH, INTERVAL) { + var state = PENDING; + + function handleError(err) { + state = DISCONNECTED; } + function handleResponse(response) { + var data = response.data; + + state = data.error ? DISCONNECTED : CONNECTED; + } + + function updateIndicator() { + $http.get(PATH).then(handleResponse, handleError); + } + + updateIndicator(); $interval(updateIndicator, INTERVAL); return { getGlyph: function () { return "D"; + }, + getGlyphClass: function () { + return state.glyphClass; + }, + getText: function () { + return state.text; } - } + }; }