2014-12-15 18:37:16 +00:00
|
|
|
/*global define*/
|
|
|
|
|
|
|
|
define(
|
|
|
|
[],
|
|
|
|
function () {
|
|
|
|
"use strict";
|
|
|
|
|
2014-12-15 20:34:16 +00:00
|
|
|
var CONNECTED = {
|
|
|
|
text: "Connected",
|
|
|
|
glyphClass: "ok"
|
|
|
|
},
|
|
|
|
DISCONNECTED = {
|
|
|
|
text: "Disconnected",
|
|
|
|
glyphClass: "err"
|
|
|
|
},
|
|
|
|
PENDING = {
|
|
|
|
text: "Checking connection..."
|
|
|
|
};
|
|
|
|
|
2014-12-15 18:37:16 +00:00
|
|
|
function CouchIndicator($http, $interval, PATH, INTERVAL) {
|
2014-12-15 20:34:16 +00:00
|
|
|
var state = PENDING;
|
|
|
|
|
|
|
|
function handleError(err) {
|
|
|
|
state = DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleResponse(response) {
|
|
|
|
var data = response.data;
|
2014-12-15 18:37:16 +00:00
|
|
|
|
2014-12-15 20:34:16 +00:00
|
|
|
state = data.error ? DISCONNECTED : CONNECTED;
|
2014-12-15 18:37:16 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 20:34:16 +00:00
|
|
|
function updateIndicator() {
|
|
|
|
$http.get(PATH).then(handleResponse, handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateIndicator();
|
2014-12-15 18:37:16 +00:00
|
|
|
$interval(updateIndicator, INTERVAL);
|
|
|
|
|
|
|
|
return {
|
|
|
|
getGlyph: function () {
|
|
|
|
return "D";
|
2014-12-15 20:34:16 +00:00
|
|
|
},
|
|
|
|
getGlyphClass: function () {
|
|
|
|
return state.glyphClass;
|
|
|
|
},
|
|
|
|
getText: function () {
|
|
|
|
return state.text;
|
2014-12-15 18:37:16 +00:00
|
|
|
}
|
2014-12-15 20:34:16 +00:00
|
|
|
};
|
2014-12-15 18:37:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return CouchIndicator;
|
|
|
|
}
|
|
|
|
);
|