2014-04-25 17:49:36 +00:00
|
|
|
App.DcController = Ember.Controller.extend({
|
2014-04-30 21:31:40 +00:00
|
|
|
// Whether or not the dropdown menu can be seen
|
2014-04-25 20:24:36 +00:00
|
|
|
isDropdownVisible: false,
|
|
|
|
|
2014-04-30 22:05:44 +00:00
|
|
|
datacenter: function() {
|
|
|
|
return this.get('content')
|
|
|
|
}.property('Content'),
|
|
|
|
|
2014-04-25 20:24:36 +00:00
|
|
|
checks: function() {
|
2014-04-30 21:31:40 +00:00
|
|
|
var nodes = this.get('nodes');
|
2014-04-25 20:24:36 +00:00
|
|
|
var checks = Ember.A()
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Combine the checks from all of our nodes
|
|
|
|
// into one.
|
|
|
|
nodes.forEach(function(item) {
|
2014-04-25 20:24:36 +00:00
|
|
|
checks = checks.concat(item.Checks)
|
|
|
|
});
|
|
|
|
|
|
|
|
return checks
|
2014-04-30 22:05:44 +00:00
|
|
|
}.property('nodes'),
|
2014-04-30 21:31:40 +00:00
|
|
|
|
|
|
|
// 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'))
|
2014-04-30 22:05:44 +00:00
|
|
|
}.property('nodes'),
|
2014-04-25 20:24:36 +00:00
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
//
|
|
|
|
// Returns the human formatted message for the button state
|
|
|
|
//
|
2014-04-25 20:24:36 +00:00
|
|
|
checkMessage: function() {
|
|
|
|
var checks = this.get('checks')
|
2014-04-30 21:31:40 +00:00
|
|
|
var failingChecks = this.get('totalChecksFailing');
|
|
|
|
var passingChecks = checks.filterBy('Status', 'passing').get('length');
|
2014-04-25 20:24:36 +00:00
|
|
|
|
|
|
|
if (this.get('hasFailingChecks') == true) {
|
2014-04-30 21:31:40 +00:00
|
|
|
return failingChecks + ' checks failing';
|
2014-04-25 20:24:36 +00:00
|
|
|
} else {
|
2014-04-30 21:31:40 +00:00
|
|
|
return passingChecks + ' checks passing';
|
2014-04-25 20:24:36 +00:00
|
|
|
}
|
|
|
|
|
2014-04-30 22:05:44 +00:00
|
|
|
}.property('nodes'),
|
2014-04-25 20:24:36 +00:00
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
//
|
|
|
|
// Boolean if the datacenter has any failing checks.
|
|
|
|
//
|
2014-04-25 20:24:36 +00:00
|
|
|
hasFailingChecks: function() {
|
2014-05-01 17:19:43 +00:00
|
|
|
var failingChecks = this.get('totalChecksFailing')
|
|
|
|
return (failingChecks > 0);
|
2014-04-30 22:05:44 +00:00
|
|
|
}.property('nodes'),
|
2014-04-25 20:24:36 +00:00
|
|
|
|
|
|
|
actions: {
|
2014-04-30 21:31:40 +00:00
|
|
|
// Hide and show the dropdown menu
|
2014-04-25 20:24:36 +00:00
|
|
|
toggle: function(item){
|
|
|
|
this.toggleProperty('isDropdownVisible');
|
2014-05-01 16:21:32 +00:00
|
|
|
},
|
|
|
|
// Just hide the dropdown menu
|
|
|
|
hideDrop: function(item){
|
|
|
|
this.set('isDropdownVisible', false);
|
2014-04-25 20:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-25 17:49:36 +00:00
|
|
|
})
|
|
|
|
|
2014-05-05 13:05:30 +00:00
|
|
|
KvBaseController = Ember.ObjectController.extend({
|
2014-05-05 19:32:39 +00:00
|
|
|
getParentKeyRoute: function() {
|
|
|
|
if (this.get('isRoot')) {
|
|
|
|
return this.get('rootKey');
|
|
|
|
}
|
|
|
|
return this.get("parentKey");
|
|
|
|
},
|
|
|
|
|
2014-05-05 07:56:21 +00:00
|
|
|
transitionToNearestParent: function(parent) {
|
|
|
|
var controller = this;
|
|
|
|
var rootKey = controller.get('rootKey');
|
|
|
|
var dc = controller.get('dc').get('datacenter');
|
|
|
|
|
|
|
|
Ember.$.ajax({
|
|
|
|
url: ('/v1/kv/' + parent + '?keys&c=' + dc),
|
|
|
|
type: 'GET'
|
|
|
|
}).then(function(data) {
|
|
|
|
controller.transitionToRoute('kv.show', parent);
|
|
|
|
}).fail(function(response) {
|
|
|
|
if (response.status === 404) {
|
|
|
|
controller.transitionToRoute('kv.show', rootKey);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
controller.set('isLoading', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Add mixins
|
2014-05-05 13:05:30 +00:00
|
|
|
App.KvShowController = KvBaseController.extend(Ember.Validations.Mixin);
|
2014-04-29 20:16:22 +00:00
|
|
|
|
2014-04-30 14:09:41 +00:00
|
|
|
App.KvShowController.reopen({
|
2014-04-30 22:05:44 +00:00
|
|
|
needs: ["dc"],
|
|
|
|
dc: Ember.computed.alias("controllers.dc"),
|
2014-04-30 14:09:41 +00:00
|
|
|
isLoading: false,
|
|
|
|
|
|
|
|
actions: {
|
2014-04-30 21:31:40 +00:00
|
|
|
// Creates the key from the newKey model
|
|
|
|
// set on the route.
|
2014-04-30 14:09:41 +00:00
|
|
|
createKey: function() {
|
|
|
|
this.set('isLoading', true);
|
|
|
|
|
2014-04-30 20:30:14 +00:00
|
|
|
var controller = this;
|
2014-05-05 07:56:21 +00:00
|
|
|
var newKey = controller.get('newKey');
|
|
|
|
var parentKey = controller.get('parentKey');
|
|
|
|
var grandParentKey = controller.get('grandParentKey');
|
|
|
|
var dc = controller.get('dc').get('datacenter');
|
2014-04-30 14:09:41 +00:00
|
|
|
|
|
|
|
// If we don't have a previous model to base
|
2014-04-30 21:31:40 +00:00
|
|
|
// on our parent, or we're not at the root level,
|
2014-05-01 14:00:36 +00:00
|
|
|
// add the prefix
|
|
|
|
if (parentKey != undefined && parentKey != "/") {
|
2014-04-30 21:38:56 +00:00
|
|
|
newKey.set('Key', (parentKey + newKey.get('Key')));
|
2014-04-30 14:09:41 +00:00
|
|
|
}
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Put the Key and the Value retrieved from the form
|
2014-04-30 20:30:14 +00:00
|
|
|
Ember.$.ajax({
|
2014-04-30 22:05:44 +00:00
|
|
|
url: ("/v1/kv/" + newKey.get('Key') + '?dc=' + dc),
|
2014-04-30 20:30:14 +00:00
|
|
|
type: 'PUT',
|
|
|
|
data: newKey.get('Value')
|
|
|
|
}).then(function(response) {
|
2014-04-30 23:22:07 +00:00
|
|
|
// transition to the right place
|
|
|
|
if (newKey.get('isFolder') == true) {
|
2014-05-04 21:05:00 +00:00
|
|
|
controller.transitionToRoute('kv.show', newKey.get('Key'));
|
2014-04-30 23:22:07 +00:00
|
|
|
} else {
|
2014-05-04 21:05:00 +00:00
|
|
|
controller.transitionToRoute('kv.edit', newKey.get('Key'));
|
2014-04-30 23:22:07 +00:00
|
|
|
}
|
2014-05-01 14:00:36 +00:00
|
|
|
controller.set('isLoading', false)
|
2014-04-30 20:30:14 +00:00
|
|
|
}).fail(function(response) {
|
2014-04-30 21:31:40 +00:00
|
|
|
// Render the error message on the form if the request failed
|
2014-04-30 20:30:14 +00:00
|
|
|
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
|
|
|
});
|
2014-05-05 00:12:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteFolder: function() {
|
|
|
|
this.set('isLoading', true);
|
|
|
|
|
|
|
|
var controller = this;
|
2014-05-05 19:32:39 +00:00
|
|
|
var grandParent = controller.get('grandParentKey');
|
2014-04-30 14:09:41 +00:00
|
|
|
|
2014-05-05 00:12:24 +00:00
|
|
|
// Delete the folder
|
|
|
|
Ember.$.ajax({
|
2014-05-05 19:32:39 +00:00
|
|
|
url: ("/v1/kv/" + controller.get('parentKey') + '?recurse'),
|
2014-05-05 00:12:24 +00:00
|
|
|
type: 'DELETE'
|
|
|
|
}).then(function(response) {
|
2014-05-05 07:56:21 +00:00
|
|
|
controller.transitionToNearestParent(grandParent);
|
2014-05-05 00:12:24 +00:00
|
|
|
}).fail(function(response) {
|
|
|
|
// Render the error message on the form if the request failed
|
|
|
|
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
2014-05-05 07:56:21 +00:00
|
|
|
});
|
2014-04-30 14:09:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-04-29 20:16:22 +00:00
|
|
|
|
2014-05-05 13:05:30 +00:00
|
|
|
App.KvEditController = KvBaseController.extend({
|
2014-04-29 20:16:22 +00:00
|
|
|
isLoading: false,
|
2014-05-01 14:00:36 +00:00
|
|
|
needs: ["dc"],
|
|
|
|
dc: Ember.computed.alias("controllers.dc"),
|
2014-04-29 20:16:22 +00:00
|
|
|
|
|
|
|
actions: {
|
2014-04-30 21:31:40 +00:00
|
|
|
// Updates the key set as the model on the route.
|
2014-04-29 20:16:22 +00:00
|
|
|
updateKey: function() {
|
|
|
|
this.set('isLoading', true);
|
|
|
|
|
2014-05-01 14:00:36 +00:00
|
|
|
var dc = this.get('dc').get('datacenter');
|
2014-04-30 20:30:14 +00:00
|
|
|
var key = this.get("model");
|
|
|
|
var controller = this;
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Put the key and the decoded (plain text) value
|
|
|
|
// from the form.
|
2014-04-30 20:30:14 +00:00
|
|
|
Ember.$.ajax({
|
2014-05-01 14:00:36 +00:00
|
|
|
url: ("/v1/kv/" + key.get('Key') + '?dc=' + dc),
|
2014-04-30 20:30:14 +00:00
|
|
|
type: 'PUT',
|
|
|
|
data: key.get('valueDecoded')
|
|
|
|
}).then(function(response) {
|
2014-04-30 21:31:40 +00:00
|
|
|
// If success, just reset the loading state.
|
2014-04-30 20:30:14 +00:00
|
|
|
controller.set('isLoading', false)
|
|
|
|
}).fail(function(response) {
|
2014-04-30 21:31:40 +00:00
|
|
|
// Render the error message on the form if the request failed
|
2014-04-30 20:30:14 +00:00
|
|
|
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
|
|
|
})
|
2014-04-30 14:16:50 +00:00
|
|
|
},
|
|
|
|
|
2014-05-04 23:03:47 +00:00
|
|
|
cancelEdit: function() {
|
|
|
|
this.set('isLoading', true);
|
2014-05-05 19:32:39 +00:00
|
|
|
this.transitionToRoute('kv.show', this.getParentKeyRoute());
|
2014-05-04 23:03:47 +00:00
|
|
|
this.set('isLoading', false);
|
|
|
|
},
|
|
|
|
|
2014-04-30 14:16:50 +00:00
|
|
|
deleteKey: function() {
|
|
|
|
this.set('isLoading', true);
|
2014-05-05 00:12:24 +00:00
|
|
|
|
2014-04-30 20:30:14 +00:00
|
|
|
var controller = this;
|
2014-05-05 00:51:34 +00:00
|
|
|
var dc = controller.get('dc').get('datacenter');
|
|
|
|
var key = controller.get("model");
|
2014-05-05 19:32:39 +00:00
|
|
|
var parent = controller.getParentKeyRoute();
|
2014-04-30 20:30:14 +00:00
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Delete the key
|
2014-04-30 20:30:14 +00:00
|
|
|
Ember.$.ajax({
|
2014-05-01 14:00:36 +00:00
|
|
|
url: ("/v1/kv/" + key.get('Key') + '?dc=' + dc),
|
2014-04-30 20:30:14 +00:00
|
|
|
type: 'DELETE'
|
2014-05-05 07:56:21 +00:00
|
|
|
}).then(function(data) {
|
|
|
|
controller.transitionToNearestParent(parent);
|
2014-04-30 20:30:14 +00:00
|
|
|
}).fail(function(response) {
|
2014-04-30 21:31:40 +00:00
|
|
|
// Render the error message on the form if the request failed
|
2014-04-30 20:30:14 +00:00
|
|
|
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
|
|
|
})
|
2014-04-29 20:16:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2014-05-30 18:26:11 +00:00
|
|
|
|
2014-06-02 14:35:46 +00:00
|
|
|
ItemBaseController = Ember.ArrayController.extend({
|
|
|
|
needs: ["dc"],
|
|
|
|
dc: Ember.computed.alias("controllers.dc"),
|
|
|
|
condensedView: true,
|
2014-06-02 15:49:01 +00:00
|
|
|
filter: "", // default
|
|
|
|
filterStatus: "any status", // default
|
2014-06-02 16:05:13 +00:00
|
|
|
statuses: ["any status", "passing", "failing"],
|
2014-06-02 14:35:46 +00:00
|
|
|
|
|
|
|
filteredContent: function() {
|
|
|
|
var filter = this.get('filter');
|
2014-06-02 16:05:13 +00:00
|
|
|
var filterStatus = this.get('filterStatus');
|
2014-06-02 14:35:46 +00:00
|
|
|
|
2014-06-02 16:05:13 +00:00
|
|
|
var items = this.get('items').filter(function(item, index, enumerable){
|
2014-06-02 14:35:46 +00:00
|
|
|
return item.get('filterKey').toLowerCase().match(filter.toLowerCase());
|
|
|
|
});
|
2014-06-02 16:05:13 +00:00
|
|
|
|
|
|
|
switch (filterStatus) {
|
|
|
|
case "passing":
|
2014-06-03 17:53:22 +00:00
|
|
|
console.log(items)
|
2014-06-02 16:05:13 +00:00
|
|
|
return items.filterBy('hasFailingChecks', false)
|
|
|
|
break;
|
|
|
|
case "failing":
|
|
|
|
return items.filterBy('hasFailingChecks', true)
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return items
|
|
|
|
}
|
|
|
|
|
|
|
|
}.property('filter', 'filterStatus', 'items.@each'),
|
2014-06-02 15:49:01 +00:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
toggleCondensed: function() {
|
|
|
|
this.set('condensedView', !this.get('condensedView'))
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 18:26:11 +00:00
|
|
|
});
|
2014-06-02 14:35:46 +00:00
|
|
|
|
|
|
|
App.NodesController = ItemBaseController.extend({
|
|
|
|
items: Ember.computed.alias("nodes"),
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
App.ServicesController = ItemBaseController.extend({
|
|
|
|
items: Ember.computed.alias("services"),
|
|
|
|
});
|
|
|
|
|