mirror of
https://github.com/status-im/consul.git
synced 2025-02-08 20:05:09 +00:00
Clean up the JS a bit and make Ember code more idiomatic
This commit is contained in:
parent
1e3840b044
commit
dd1796b99a
@ -9,40 +9,30 @@ App.DcController = Ember.Controller.extend({
|
|||||||
// Whether or not the dropdown menu can be seen
|
// Whether or not the dropdown menu can be seen
|
||||||
isDropdownVisible: false,
|
isDropdownVisible: false,
|
||||||
|
|
||||||
datacenter: function() {
|
datacenter: Ember.computed.alias('content'),
|
||||||
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'),
|
|
||||||
|
|
||||||
// Returns the total number of failing checks.
|
// Returns the total number of failing checks.
|
||||||
//
|
//
|
||||||
// We treat any non-passing checks as failing
|
// We treat any non-passing checks as failing
|
||||||
//
|
//
|
||||||
totalChecksFailing: function() {
|
totalChecksFailing: function() {
|
||||||
var checks = this.get('checks');
|
return this.get('nodes').reduce(function(sum, node) {
|
||||||
return (checks.filterBy('Status', 'critical').get('length') +
|
return sum + node.get('failingChecks');
|
||||||
checks.filterBy('Status', 'warning').get('length'));
|
}, 0);
|
||||||
|
}.property('nodes'),
|
||||||
|
|
||||||
|
totalChecksPassing: function() {
|
||||||
|
return this.get('nodes').reduce(function(sum, node) {
|
||||||
|
return sum + node.get('passingChecks');
|
||||||
|
}, 0);
|
||||||
}.property('nodes'),
|
}.property('nodes'),
|
||||||
|
|
||||||
//
|
//
|
||||||
// Returns the human formatted message for the button state
|
// Returns the human formatted message for the button state
|
||||||
//
|
//
|
||||||
checkMessage: function() {
|
checkMessage: function() {
|
||||||
var checks = this.get('checks');
|
|
||||||
var failingChecks = this.get('totalChecksFailing');
|
var failingChecks = this.get('totalChecksFailing');
|
||||||
var passingChecks = checks.filterBy('Status', 'passing').get('length');
|
var passingChecks = this.get('totalChecksPassing');
|
||||||
|
|
||||||
if (this.get('hasFailingChecks') === true) {
|
if (this.get('hasFailingChecks') === true) {
|
||||||
return failingChecks + ' failing';
|
return failingChecks + ' failing';
|
||||||
@ -67,10 +57,7 @@ App.DcController = Ember.Controller.extend({
|
|||||||
//
|
//
|
||||||
// Boolean if the datacenter has any failing checks.
|
// Boolean if the datacenter has any failing checks.
|
||||||
//
|
//
|
||||||
hasFailingChecks: function() {
|
hasFailingChecks: Ember.computed.gt('totalChecksFailing', 0),
|
||||||
var failingChecks = this.get('totalChecksFailing');
|
|
||||||
return (failingChecks > 0);
|
|
||||||
}.property('nodes'),
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
// Hide and show the dropdown menu
|
// Hide and show the dropdown menu
|
||||||
@ -89,7 +76,7 @@ KvBaseController = Ember.ObjectController.extend({
|
|||||||
if (this.get('isRoot')) {
|
if (this.get('isRoot')) {
|
||||||
return this.get('rootKey');
|
return this.get('rootKey');
|
||||||
}
|
}
|
||||||
return this.get("parentKey");
|
return this.get('parentKey');
|
||||||
},
|
},
|
||||||
|
|
||||||
transitionToNearestParent: function(parent) {
|
transitionToNearestParent: function(parent) {
|
||||||
@ -113,10 +100,7 @@ KvBaseController = Ember.ObjectController.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add mixins
|
App.KvShowController = KvBaseController.extend(Ember.Validations.Mixin, {
|
||||||
App.KvShowController = KvBaseController.extend(Ember.Validations.Mixin);
|
|
||||||
|
|
||||||
App.KvShowController.reopen({
|
|
||||||
needs: ["dc"],
|
needs: ["dc"],
|
||||||
dc: Ember.computed.alias("controllers.dc"),
|
dc: Ember.computed.alias("controllers.dc"),
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -264,7 +248,7 @@ ItemBaseController = Ember.ArrayController.extend({
|
|||||||
var filter = this.get('filter');
|
var filter = this.get('filter');
|
||||||
var status = this.get('status');
|
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());
|
return item.get('filterKey').toLowerCase().match(filter.toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -281,7 +265,7 @@ ItemBaseController = Ember.ArrayController.extend({
|
|||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
toggleCondensed: function() {
|
toggleCondensed: function() {
|
||||||
this.set('condensed', !this.get('condensed'));
|
this.toggleProperty('condensed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -54,17 +54,13 @@ App.Service = Ember.Object.extend({
|
|||||||
// Boolean of whether or not there are failing checks in the service.
|
// Boolean of whether or not there are failing checks in the service.
|
||||||
// This is used to set color backgrounds and so on.
|
// This is used to set color backgrounds and so on.
|
||||||
//
|
//
|
||||||
hasFailingChecks: function() {
|
hasFailingChecks: Ember.computed.gt('failingChecks', 0),
|
||||||
return (this.get('failingChecks') > 0);
|
|
||||||
}.property('Checks'),
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Key used for filtering through an array of this model, i.e s
|
// Key used for filtering through an array of this model, i.e s
|
||||||
// searching
|
// searching
|
||||||
//
|
//
|
||||||
filterKey: function() {
|
filterKey: Ember.computed.alias('Name'),
|
||||||
return this.get('Name');
|
|
||||||
}.property('Name'),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -75,10 +71,13 @@ App.Node = Ember.Object.extend({
|
|||||||
// The number of failing checks within the service.
|
// The number of failing checks within the service.
|
||||||
//
|
//
|
||||||
failingChecks: function() {
|
failingChecks: function() {
|
||||||
var checks = this.get('Checks');
|
return this.get('Checks').reduce(function(sum, check) {
|
||||||
// We view both warning and critical as failing
|
var status = Ember.get(check, 'Status');
|
||||||
return (checks.filterBy('Status', 'critical').get('length') +
|
// We view both warning and critical as failing
|
||||||
checks.filterBy('Status', 'warning').get('length'));
|
return (status === 'critical' || status === 'warning') ?
|
||||||
|
sum + 1 :
|
||||||
|
sum;
|
||||||
|
}, 0);
|
||||||
}.property('Checks'),
|
}.property('Checks'),
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -104,26 +103,16 @@ App.Node = Ember.Object.extend({
|
|||||||
// Boolean of whether or not there are failing checks in the service.
|
// Boolean of whether or not there are failing checks in the service.
|
||||||
// This is used to set color backgrounds and so on.
|
// This is used to set color backgrounds and so on.
|
||||||
//
|
//
|
||||||
hasFailingChecks: function() {
|
hasFailingChecks: Ember.computed.gt('failingChecks', 0),
|
||||||
return (this.get('failingChecks') > 0);
|
|
||||||
}.property('Checks'),
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// The number of services on the node
|
// The number of services on the node
|
||||||
//
|
//
|
||||||
numServices: function() {
|
numServices: Ember.computed.alias('Services.length'),
|
||||||
return (this.get('Services').length);
|
|
||||||
}.property('Services'),
|
|
||||||
// The number of services on the node
|
|
||||||
//
|
|
||||||
|
|
||||||
services: function() {
|
services: Ember.computed.alias('Services'),
|
||||||
return (this.get('Services'));
|
|
||||||
}.property('Services'),
|
|
||||||
|
|
||||||
filterKey: function() {
|
filterKey: Ember.computed.alias('Node')
|
||||||
return this.get('Node');
|
|
||||||
}.property('Node')
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user