ui: add comments to application so far

This commit is contained in:
Jack Pearkes 2014-04-23 18:51:06 -04:00
parent 9dc755e4e8
commit a65ec76738

View file

@ -12,22 +12,47 @@ App.Router.map(function() {
this.route("kv", { path: "/:dc/kv" }); this.route("kv", { path: "/:dc/kv" });
}); });
//
// The main controller for the application. To use this in other
// controller you have to use the needs api
//
App.ApplicationController = Ember.Controller.extend({ App.ApplicationController = Ember.Controller.extend({
//
// Sets the current datacenter to be used when linking. DC is
// a required parameter in the routes, above, and we need
// to know our scope. This is so #link-to 'node' dc node-name
// works.
//
setDc: function(dc) { setDc: function(dc) {
localStorage.setItem("current_dc", dc); localStorage.setItem("current_dc", dc);
}, },
//
// Retrieves the current datacenter set by this.setDc from
// localstorage. returns null if the dc has not been set.
//
getDc: function() { getDc: function() {
return localStorage.getItem("current_dc"); return localStorage.getItem("current_dc");
}.property("getDc") }.property("getDc")
}); });
//
// path: /:dc/services
//
App.ServicesController = Ember.Controller.extend({ App.ServicesController = Ember.Controller.extend({
needs: ['application'] needs: ['application']
}) })
// Superclass to be used by all of the main routes below //
// Superclass to be used by all of the main routes below. All routes
// but the IndexRoute share the need to have a datacenter set.
//
//
App.BaseRoute = Ember.Route.extend({ App.BaseRoute = Ember.Route.extend({
//
// When activating the base route, if we don't have a datacenter set,
// transition the user to the index route to choose a datacenter.
//
activate: function() { activate: function() {
var controller = this.controllerFor('application'); var controller = this.controllerFor('application');
if (controller.getDc === null) { if (controller.getDc === null) {
@ -36,8 +61,12 @@ App.BaseRoute = Ember.Route.extend({
} }
}); });
// Does not extend baseroute due to it not needing //
// to check for an active DC // The route for choosing datacenters, typically the first route loaded.
//
// Note: This *does not* extend from BaseRoute as that could cause
// and loop of transitions.
//
App.IndexRoute = Ember.Route.extend({ App.IndexRoute = Ember.Route.extend({
model: function() { model: function() {
return window.fixtures.dcs; return window.fixtures.dcs;
@ -50,10 +79,21 @@ App.IndexRoute = Ember.Route.extend({
} }
}); });
//
// path: /
//
// The index is for choosing datacenters.
//
App.IndexController = Ember.Controller.extend({ App.IndexController = Ember.Controller.extend({
needs: ['application'], needs: ['application'],
actions: { actions: {
//
// selectDc is called with the datacenter name to be set for
// future actions within the application. It's a namespace, essentially.
//
// See ApplicationController#setDc
//
selectDc: function(dc) { selectDc: function(dc) {
this.get('controllers.application').setDc(dc) this.get('controllers.application').setDc(dc)
this.transitionToRoute('services', dc) this.transitionToRoute('services', dc)
@ -61,15 +101,28 @@ App.IndexController = Ember.Controller.extend({
} }
}); });
//
// A Consul service.
//
App.Service = Ember.Object.extend({ App.Service = Ember.Object.extend({
//
// The number of failing checks within the service.
//
failingChecks: function() { failingChecks: function() {
return this.get('Checks').filterBy('Status', 'critical').get('length'); return this.get('Checks').filterBy('Status', 'critical').get('length');
}.property('failingChecks'), }.property('failingChecks'),
//
// The number of passing checks within the service.
//
passingChecks: function() { passingChecks: function() {
return this.get('Checks').filterBy('Status', 'passing').get('length'); return this.get('Checks').filterBy('Status', 'passing').get('length');
}.property('passingChecks'), }.property('passingChecks'),
//
// The formatted message returned for the user which represents the
// number of checks failing or passing. Returns `1 passing` or `2 failing`
//
checkMessage: function() { checkMessage: function() {
if (this.get('hasFailingChecks') === false) { if (this.get('hasFailingChecks') === false) {
return this.get('passingChecks') + ' passing'; return this.get('passingChecks') + ' passing';
@ -78,18 +131,27 @@ App.Service = Ember.Object.extend({
} }
}.property('checkMessage'), }.property('checkMessage'),
//
// Boolean of whether or not there are failing checks in the service.
// This is used to set color backgrounds and so on.
//
hasFailingChecks: function() { hasFailingChecks: function() {
return (this.get('failingChecks') > 0); return (this.get('failingChecks') > 0);
}.property('hasFailingChecks') }.property('hasFailingChecks')
}); });
//
// Display all the services, allow to drill down into the specific services.
//
App.ServicesRoute = App.BaseRoute.extend({ App.ServicesRoute = App.BaseRoute.extend({
model: function() { model: function() {
return [App.Service.create(window.fixtures.services[0]), App.Service.create(window.fixtures.services[1])]; return [App.Service.create(window.fixtures.services[0]), App.Service.create(window.fixtures.services[1])];
} }
}); });
//
// Services
//
App.ServicesView = Ember.View.extend({ App.ServicesView = Ember.View.extend({
layoutName: 'default_layout' layoutName: 'default_layout'
}) })