From c1ea620341d6bc8ccab59c446adb446e035c0751 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 15 Dec 2014 12:34:16 -0800 Subject: [PATCH] [Indicators] Implement CouchDB indicator Initial implementation of an indicator which reflects current connection to CouchDB. WTD-608. --- platform/persistence/src/CouchIndicator.js | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) 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; } - } + }; }