diff --git a/js/apps/system/aardvark/cluster.js b/js/apps/system/aardvark/cluster.js index 739825550a..b73d8c3315 100644 --- a/js/apps/system/aardvark/cluster.js +++ b/js/apps/system/aardvark/cluster.js @@ -70,6 +70,25 @@ res.json(resList); }); + controller.get("/Coordinators", function(req, res) { + var resList = [], + list = coords.getList(), + noBeat = beats.noBeat(); + + _.each(list, function(url, k) { + var v = {}; + v.name = k; + v.url = url; + resList.push(v); + if (_.contains(noBeat, k)) { + v.status = "critical"; + return; + } + v.status = "ok"; + }); + res.json(resList); + }); + controller.get("/Databases", function(req, res) { var list = dbs.getList(); res.json(_.map(list, function(d) { diff --git a/js/apps/system/aardvark/frontend/js/collections/clusterCoordinators.js b/js/apps/system/aardvark/frontend/js/collections/clusterCoordinators.js index 058e3e5577..2b3b5f8e19 100644 --- a/js/apps/system/aardvark/frontend/js/collections/clusterCoordinators.js +++ b/js/apps/system/aardvark/frontend/js/collections/clusterCoordinators.js @@ -1,5 +1,5 @@ /*jslint indent: 2, nomen: true, maxlen: 100, white: true, plusplus: true */ -/*global window, Backbone */ +/*global window, Backbone, console */ (function() { "use strict"; window.ClusterCoordinators = Backbone.Collection.extend({ @@ -8,32 +8,47 @@ url: "/_admin/aardvark/cluster/Coordinators", getList: function() { - return [ - { - name: "Charly", - url: "tcp://192.168.0.1:1337", - status: "ok" - }, - { - name: "Carlos", - url: "tcp://192.168.0.2:1337", - status: "critical" - }, - { - name: "Chantalle", - url: "tcp://192.168.0.5:1337", - status: "ok" - } - ]; + this.fetch({ + async: false + }); + return this.map(function(m) { + return m.forList(); + }); }, getOverview: function() { - // Fake data - return { - plan: 3, - having: 2, - status: "critical" + this.fetch({ + async: false + }); + var res = { + plan: 0, + having: 0, + status: "ok" + }, + updateStatus = function(to) { + if (res.status === "critical") { + return; + } + res.status = to; }; + this.each(function(m) { + res.plan++; + switch (m.get("status")) { + case "ok": + res.having++; + break; + case "warning": + res.having++; + updateStatus("warning"); + break; + case "critical": + updateStatus("critical"); + break; + default: + console.debug("Undefined server state occured. This is still in development"); + } + }); + return res; } }); diff --git a/js/apps/system/aardvark/frontend/js/models/clusterCollection.js b/js/apps/system/aardvark/frontend/js/models/clusterCollection.js index d892b6cd6c..e7c2bc02fc 100644 --- a/js/apps/system/aardvark/frontend/js/models/clusterCollection.js +++ b/js/apps/system/aardvark/frontend/js/models/clusterCollection.js @@ -6,11 +6,10 @@ window.ClusterCollection = Backbone.Model.extend({ defaults: { "name": "", - "id": "", "status": "ok" }, - idAttribute: "id", + idAttribute: "name", forList: function() { return { diff --git a/js/apps/system/aardvark/frontend/js/models/clusterCoordinator.js b/js/apps/system/aardvark/frontend/js/models/clusterCoordinator.js index d5930a52ba..d3d61d38f8 100644 --- a/js/apps/system/aardvark/frontend/js/models/clusterCoordinator.js +++ b/js/apps/system/aardvark/frontend/js/models/clusterCoordinator.js @@ -4,15 +4,23 @@ "use strict"; window.ClusterCoordinator = Backbone.Model.extend({ + defaults: { "name": "", - "url": "" + "url": "", + "status": "ok" }, idAttribute: "name", - url: function() { - return "/_admin/aardvark/cluster/Coordinators"; + url: "/_admin/aardvark/cluster/Coordinators", + + forList: function() { + return { + name: this.get("name"), + status: this.get("status"), + url: this.get("url") + }; } }); diff --git a/js/apps/system/aardvark/test/karma/karma.conf.js b/js/apps/system/aardvark/test/karma/karma.conf.js index 7c47e0f260..bc94486144 100644 --- a/js/apps/system/aardvark/test/karma/karma.conf.js +++ b/js/apps/system/aardvark/test/karma/karma.conf.js @@ -223,12 +223,21 @@ module.exports = function(karma) { // 'test/specs/graphViewer/specNodeReducer/modularityJoinerSpec.js', // 'test/specs/graphViewer/specWindowObjects/workerWrapperSpec.js', 'test/specs/graphViewer/specContextMenu/contextMenuSpec.js', + // Arango 'test/specs/arango/arangoSpec.js', + // Models 'test/specs/models/currentDatabaseSpec.js', 'test/specs/models/graphSpec.js', + // Collections + 'test/specs/collections/clusterServersSpec.js', + 'test/specs/collections/clusterDatabasesSpec.js', + 'test/specs/collections/clusterCollectionsSpec.js', + 'test/specs/collections/clusterShardsSpec.js', + + // Views 'test/specs/views/editListEntryViewSpec.js', 'test/specs/views/collectionViewSpec.js', diff --git a/js/apps/system/aardvark/test/specs/views/clusterCollectionViewSpec.js b/js/apps/system/aardvark/test/specs/views/clusterCollectionViewSpec.js index c3241db3ad..010dcea342 100644 --- a/js/apps/system/aardvark/test/specs/views/clusterCollectionViewSpec.js +++ b/js/apps/system/aardvark/test/specs/views/clusterCollectionViewSpec.js @@ -6,9 +6,11 @@ "use strict"; describe("Cluster Collection View", function() { - var view, div, shardsView, shardCol; + var view, div, shardsView, shardCol, server, db; beforeEach(function() { + server = "pavel"; + db = "_system"; div = document.createElement("div"); div.id = "clusterCollections"; document.body.appendChild(div); @@ -81,7 +83,7 @@ view = new window.ClusterCollectionView({ collection: collCol }); - view.render(); + view.render(db, server); }); it("should not unrender the server view", function() { @@ -117,27 +119,18 @@ }); it("should be able to navigate to Documents", function() { - info = { - name: "Documents" - }; $("#Documents").click(); - expect(shardsView.render).toHaveBeenCalledWith(info); + expect(shardsView.render).toHaveBeenCalledWith(db, "Documents", server); }); it("should be able to navigate to Edges", function() { - info = { - name: "Edges" - }; $("#Edges").click(); - expect(shardsView.render).toHaveBeenCalledWith(info); + expect(shardsView.render).toHaveBeenCalledWith(db, "Edges", server); }); it("should be able to navigate to People", function() { - info = { - name: "People" - }; $("#People").click(); - expect(shardsView.render).toHaveBeenCalledWith(info); + expect(shardsView.render).toHaveBeenCalledWith(db, "People", server); }); }); diff --git a/js/apps/system/aardvark/test/specs/views/clusterDatabaseViewSpec.js b/js/apps/system/aardvark/test/specs/views/clusterDatabaseViewSpec.js index 2d5415841e..c22d9fcfdf 100644 --- a/js/apps/system/aardvark/test/specs/views/clusterDatabaseViewSpec.js +++ b/js/apps/system/aardvark/test/specs/views/clusterDatabaseViewSpec.js @@ -6,9 +6,10 @@ "use strict"; describe("Cluster Database View", function() { - var view, div, colView, colCol; + var view, div, colView, colCol, server; beforeEach(function() { + server = "pavel"; div = document.createElement("div"); div.id = "clusterDatabases"; document.body.appendChild(div); @@ -83,7 +84,7 @@ view = new window.ClusterDatabaseView({ collection: dbCol }); - view.render(); + view.render(server); }); it("should not render the Server view", function() { @@ -116,19 +117,19 @@ it("should be able to navigate to _system", function() { db = "_system"; $("#" + db).click(); - expect(colView.render).toHaveBeenCalledWith(db); + expect(colView.render).toHaveBeenCalledWith(db, server); }); it("should be able to navigate to myDatabase", function() { db = "myDatabase"; $("#" + db).click(); - expect(colView.render).toHaveBeenCalledWith(db); + expect(colView.render).toHaveBeenCalledWith(db, server); }); it("should be able to navigate to otherDatabase", function() { db = "otherDatabase"; $("#" + db).click(); - expect(colView.render).toHaveBeenCalledWith(db); + expect(colView.render).toHaveBeenCalledWith(db, server); }); }); diff --git a/js/apps/system/aardvark/test/specs/views/clusterServerViewSpec.js b/js/apps/system/aardvark/test/specs/views/clusterServerViewSpec.js index bdd5f0bdbf..642c31a8d1 100644 --- a/js/apps/system/aardvark/test/specs/views/clusterServerViewSpec.js +++ b/js/apps/system/aardvark/test/specs/views/clusterServerViewSpec.js @@ -57,11 +57,8 @@ dbView.render.reset(); view.render.reset(); var name = o.primary.name; - info = { - name: name - }; $(getTile(name)).click(); - expect(dbView.render).toHaveBeenCalledWith(info); + expect(dbView.render).toHaveBeenCalledWith(name); expect(view.render).toHaveBeenCalledWith(true); }); }); diff --git a/js/apps/system/aardvark/test/specs/views/clusterShardsViewSpec.js b/js/apps/system/aardvark/test/specs/views/clusterShardsViewSpec.js index d5af341fcb..cd32dd91db 100644 --- a/js/apps/system/aardvark/test/specs/views/clusterShardsViewSpec.js +++ b/js/apps/system/aardvark/test/specs/views/clusterShardsViewSpec.js @@ -22,27 +22,27 @@ describe("rendering", function() { var s1, s2, s3, shards, shardCol, - checkButtonContent = function(col, cls) { - var btn = document.getElementById(col.name); + checkButtonContent = function(sh, cls) { + var btn = document.getElementById(sh.id); expect(btn).toBeOfClass("btn"); expect(btn).toBeOfClass("btn-server"); expect(btn).toBeOfClass("shard"); expect(btn).toBeOfClass("btn-" + cls); - expect($(btn).text()).toEqual(col.name); + expect($(btn).text()).toEqual(sh.id); }; beforeEach(function() { s1 = { - name: "Shard 1", + id: "Shard 1", status: "ok" }; s2 = { - name: "Shard 2", + id: "Shard 2", status: "warning" }; s3 = { - name: "Shard 3", + id: "Shard 3", status: "critical" }; shards = [