open-consul/ui/javascripts/app/controllers.js

174 lines
5.1 KiB
JavaScript
Raw Normal View History

2014-04-25 17:49:36 +00:00
App.DcController = Ember.Controller.extend({
// 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() {
var nodes = this.get('nodes');
2014-04-25 20:24:36 +00:00
var checks = Ember.A()
// 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'),
// 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
//
// Returns the human formatted message for the button state
//
2014-04-25 20:24:36 +00:00
checkMessage: function() {
var checks = this.get('checks')
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) {
return failingChecks + ' checks failing';
2014-04-25 20:24:36 +00:00
} else {
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
//
// Boolean if the datacenter has any failing checks.
//
2014-04-25 20:24:36 +00:00
hasFailingChecks: function() {
var checks = this.get('checks')
2014-05-01 16:51:23 +00:00
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
actions: {
// 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
})
// Add mixins
App.KvShowController = Ember.ObjectController.extend(Ember.Validations.Mixin);
App.KvShowController.reopen({
2014-04-30 22:05:44 +00:00
needs: ["dc"],
dc: Ember.computed.alias("controllers.dc"),
isLoading: false,
actions: {
// Creates the key from the newKey model
// set on the route.
createKey: function() {
this.set('isLoading', true);
var newKey = this.get('newKey');
var parentKey = this.get('parentKey');
var grandParentKey = this.get('grandParentKey');
2014-04-30 20:30:14 +00:00
var controller = this;
2014-04-30 22:05:44 +00:00
var dc = this.get('dc').get('datacenter');
// If we don't have a previous model to base
// on our parent, or we're not at the root level,
// add the prefix
if (parentKey != undefined && parentKey != "/") {
newKey.set('Key', (parentKey + newKey.get('Key')));
}
// 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) {
// transition to the right place
if (newKey.get('isFolder') == true) {
controller.transitionToRoute('kv.show', newKey.get('urlSafeKey'));
} else {
controller.transitionToRoute('kv.edit', newKey.get('urlSafeKey'));
}
controller.set('isLoading', false)
2014-04-30 20:30:14 +00:00
}).fail(function(response) {
// 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)
});
}
}
});
App.KvEditController = Ember.Controller.extend({
isLoading: false,
needs: ["dc"],
dc: Ember.computed.alias("controllers.dc"),
actions: {
// Updates the key set as the model on the route.
updateKey: function() {
this.set('isLoading', true);
var dc = this.get('dc').get('datacenter');
2014-04-30 20:30:14 +00:00
var key = this.get("model");
var controller = this;
// Put the key and the decoded (plain text) value
// from the form.
2014-04-30 20:30:14 +00:00
Ember.$.ajax({
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) {
// If success, just reset the loading state.
2014-04-30 20:30:14 +00:00
controller.set('isLoading', false)
}).fail(function(response) {
// 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
},
deleteKey: function() {
this.set('isLoading', true);
2014-04-30 20:30:14 +00:00
var key = this.get("model");
var controller = this;
var dc = this.get('dc').get('datacenter');
// Get the parent for the transition back up a level
// after the delete
2014-04-30 20:30:14 +00:00
var parent = key.get('urlSafeParentKey');
// Delete the key
2014-04-30 20:30:14 +00:00
Ember.$.ajax({
url: ("/v1/kv/" + key.get('Key') + '?dc=' + dc),
2014-04-30 20:30:14 +00:00
type: 'DELETE'
}).then(function(response) {
// Tranisiton back up a level
2014-04-30 20:30:14 +00:00
controller.transitionToRoute('kv.show', parent);
controller.set('isLoading', false);
2014-04-30 20:30:14 +00:00
}).fail(function(response) {
// 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
}
}
});