Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the JS a bit and make Ember code more idiomatic #1338

Merged
merged 1 commit into from
Oct 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions ui/javascripts/app/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,30 @@ App.DcController = Ember.Controller.extend({
// Whether or not the dropdown menu can be seen
isDropdownVisible: false,

datacenter: function() {
return this.get('content');
}.property('content'),

checks: function() {
var nodes = this.get('nodes');
var checks = Ember.A();

// Combine the checks from all of our nodes
// into one.
nodes.forEach(function(item) {
checks = checks.concat(item.Checks);
});

return checks;
}.property('nodes'),
datacenter: Ember.computed.alias('content'),

// Returns the total number of failing checks.
//
// We treat any non-passing checks as failing
//
totalChecksFailing: function() {
var checks = this.get('checks');
return (checks.filterBy('Status', 'critical').get('length') +
checks.filterBy('Status', 'warning').get('length'));
return this.get('nodes').reduce(function(sum, node) {
return sum + node.get('failingChecks');
}, 0);
}.property('nodes'),

totalChecksPassing: function() {
return this.get('nodes').reduce(function(sum, node) {
return sum + node.get('passingChecks');
}, 0);
}.property('nodes'),

//
// Returns the human formatted message for the button state
//
checkMessage: function() {
var checks = this.get('checks');
var failingChecks = this.get('totalChecksFailing');
var passingChecks = checks.filterBy('Status', 'passing').get('length');
var passingChecks = this.get('totalChecksPassing');

if (this.get('hasFailingChecks') === true) {
return failingChecks + ' failing';
Expand All @@ -67,10 +57,7 @@ App.DcController = Ember.Controller.extend({
//
// Boolean if the datacenter has any failing checks.
//
hasFailingChecks: function() {
var failingChecks = this.get('totalChecksFailing');
return (failingChecks > 0);
}.property('nodes'),
hasFailingChecks: Ember.computed.gt('totalChecksFailing', 0),

actions: {
// Hide and show the dropdown menu
Expand All @@ -89,7 +76,7 @@ KvBaseController = Ember.ObjectController.extend({
if (this.get('isRoot')) {
return this.get('rootKey');
}
return this.get("parentKey");
return this.get('parentKey');
},

transitionToNearestParent: function(parent) {
Expand All @@ -113,10 +100,7 @@ KvBaseController = Ember.ObjectController.extend({
}
});

// Add mixins
App.KvShowController = KvBaseController.extend(Ember.Validations.Mixin);

App.KvShowController.reopen({
App.KvShowController = KvBaseController.extend(Ember.Validations.Mixin, {
needs: ["dc"],
dc: Ember.computed.alias("controllers.dc"),
isLoading: false,
Expand Down Expand Up @@ -264,7 +248,7 @@ ItemBaseController = Ember.ArrayController.extend({
var filter = this.get('filter');
var status = this.get('status');

var items = this.get('items').filter(function(item, index, enumerable){
var items = this.get('items').filter(function(item){
return item.get('filterKey').toLowerCase().match(filter.toLowerCase());
});

Expand All @@ -281,7 +265,7 @@ ItemBaseController = Ember.ArrayController.extend({

actions: {
toggleCondensed: function() {
this.set('condensed', !this.get('condensed'));
this.toggleProperty('condensed');
}
}
});
Expand Down
37 changes: 13 additions & 24 deletions ui/javascripts/app/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ App.Service = Ember.Object.extend({
// Boolean of whether or not there are failing checks in the service.
// This is used to set color backgrounds and so on.
//
hasFailingChecks: function() {
return (this.get('failingChecks') > 0);
}.property('Checks'),
hasFailingChecks: Ember.computed.gt('failingChecks', 0),

//
// Key used for filtering through an array of this model, i.e s
// searching
//
filterKey: function() {
return this.get('Name');
}.property('Name'),
filterKey: Ember.computed.alias('Name'),
});

//
Expand All @@ -75,10 +71,13 @@ App.Node = Ember.Object.extend({
// The number of failing checks within the service.
//
failingChecks: function() {
var checks = this.get('Checks');
// We view both warning and critical as failing
return (checks.filterBy('Status', 'critical').get('length') +
checks.filterBy('Status', 'warning').get('length'));
return this.get('Checks').reduce(function(sum, check) {
var status = Ember.get(check, 'Status');
// We view both warning and critical as failing
return (status === 'critical' || status === 'warning') ?
sum + 1 :
sum;
}, 0);
}.property('Checks'),

//
Expand All @@ -104,26 +103,16 @@ App.Node = Ember.Object.extend({
// Boolean of whether or not there are failing checks in the service.
// This is used to set color backgrounds and so on.
//
hasFailingChecks: function() {
return (this.get('failingChecks') > 0);
}.property('Checks'),
hasFailingChecks: Ember.computed.gt('failingChecks', 0),

//
// The number of services on the node
//
numServices: function() {
return (this.get('Services').length);
}.property('Services'),
// The number of services on the node
//
numServices: Ember.computed.alias('Services.length'),

services: function() {
return (this.get('Services'));
}.property('Services'),
services: Ember.computed.alias('Services'),

filterKey: function() {
return this.get('Node');
}.property('Node')
filterKey: Ember.computed.alias('Node')
});


Expand Down