[Indicators] Implement CouchDB indicator

Initial implementation of an indicator which reflects
current connection to CouchDB. WTD-608.
This commit is contained in:
Victor Woeltjen 2014-12-15 12:34:16 -08:00
parent 8cfcd2cd15
commit c1ea620341

View File

@ -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;
}
}
};
}