ui: datacenter support, kv fixes

This commit is contained in:
Jack Pearkes 2014-04-30 18:05:44 -04:00
parent f76d4acb45
commit d15dc21766
3 changed files with 37 additions and 21 deletions

View File

@ -19,7 +19,7 @@
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="error">
<script type="text/x-handlebars" data-template-name="errora">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="text-center">

View File

@ -2,6 +2,10 @@ 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()
@ -13,7 +17,7 @@ App.DcController = Ember.Controller.extend({
});
return checks
}.property('Checks'),
}.property('nodes'),
// Returns the total number of failing checks.
//
@ -23,7 +27,7 @@ App.DcController = Ember.Controller.extend({
var checks = this.get('checks')
return (checks.filterBy('Status', 'critical').get('length') +
checks.filterBy('Status', 'warning').get('length'))
}.property('Checks'),
}.property('nodes'),
//
// Returns the human formatted message for the button state
@ -39,7 +43,7 @@ App.DcController = Ember.Controller.extend({
return passingChecks + ' checks passing';
}
}.property('Checks'),
}.property('nodes'),
//
// Boolean if the datacenter has any failing checks.
@ -47,7 +51,7 @@ App.DcController = Ember.Controller.extend({
hasFailingChecks: function() {
var checks = this.get('checks')
return (checks.filterBy('Status', 'critical').get('length') > 0);
}.property('Checks'),
}.property('nodes'),
actions: {
// Hide and show the dropdown menu
@ -61,6 +65,8 @@ App.DcController = Ember.Controller.extend({
App.KvShowController = Ember.ObjectController.extend(Ember.Validations.Mixin);
App.KvShowController.reopen({
needs: ["dc"],
dc: Ember.computed.alias("controllers.dc"),
isLoading: false,
actions: {
@ -73,17 +79,19 @@ App.KvShowController.reopen({
var parentKey = this.get('parentKey');
var grandParentKey = this.get('grandParentKey');
var controller = this;
var dc = this.get('dc').get('datacenter');
console.log(dc)
// If we don't have a previous model to base
// on our parent, or we're not at the root level,
// strip the leading slash.
if (!parentKey || parentKey != "/") {
if (parentKey != undefined || parentKey != "/") {
newKey.set('Key', (parentKey + newKey.get('Key')));
}
// Put the Key and the Value retrieved from the form
Ember.$.ajax({
url: "/v1/kv/" + newKey.get('Key'),
url: ("/v1/kv/" + newKey.get('Key') + '?dc=' + dc),
type: 'PUT',
data: newKey.get('Value')
}).then(function(response) {

View File

@ -81,9 +81,10 @@ App.KvShowRoute = App.BaseRoute.extend({
model: function(params) {
// Convert the key back to the format consul understands
var key = params.key.replace(/-/g, "/")
var dc = this.modelFor('dc').dc;
// Return a promise to retrieve the ?keys for that namespace
return Ember.$.getJSON('/v1/kv/' + key + '?keys&seperator=' + '/').then(function(data) {
return Ember.$.getJSON('/v1/kv/' + key + '?keys&seperator=' + '/&dc=' + dc).then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Key.create({Key: obj}));
@ -93,16 +94,18 @@ App.KvShowRoute = App.BaseRoute.extend({
},
setupController: function(controller, model) {
var parentKey = "/";
var grandParentKey = "/";
// If we don't have any k/v, we need to set some basic
// stuff so we can create them
if (model.length == 0) {
var parentKey = "/";
var grandParentKey = "/";
} else {
var parentKey = model[0].parentKey;
var grandParentKey = model[0].grandParentKey;
if (model.length > 0) {
var parentKey = model[0].get('parentKey');
var grandParentKey = model[0].get('grandParentKey');
}
console.log(parentKey, grandParentKey)
controller.set('content', model);
controller.set('parentKey', parentKey);
controller.set('grandParentKey', grandParentKey);
@ -112,9 +115,10 @@ App.KvShowRoute = App.BaseRoute.extend({
App.KvEditRoute = App.BaseRoute.extend({
model: function(params) {
var keyName = params.key.replace(/-/g, "/")
var keyName = params.key.replace(/-/g, "/");
var key = keyName;
var parentKey;
var dc = this.modelFor('dc').dc;
// Get the parent key
if (key.slice(-1) == "/") {
@ -137,7 +141,7 @@ App.KvEditRoute = App.BaseRoute.extend({
// Convert the returned data to a Key
return App.Key.create().setProperties(data[0]);
}),
keys: keysPromise = Ember.$.getJSON('/v1/kv/' + parentKey + '?keys&seperator=' + '/').then(function(data) {
keys: keysPromise = Ember.$.getJSON('/v1/kv/' + parentKey + '?keys&seperator=' + '/' + '&dc=' + dc).then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Key.create({Key: obj}));
@ -163,8 +167,9 @@ App.KvEditRoute = App.BaseRoute.extend({
App.ServicesRoute = App.BaseRoute.extend({
model: function(params) {
var dc = this.modelFor('dc').dc
// Return a promise to retrieve all of the services
return Ember.$.getJSON('/v1/internal/ui/services').then(function(data) {
return Ember.$.getJSON('/v1/internal/ui/services?dc=' + dc).then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Service.create(obj));
@ -180,9 +185,10 @@ App.ServicesRoute = App.BaseRoute.extend({
App.ServicesShowRoute = App.BaseRoute.extend({
model: function(params) {
var dc = this.modelFor('dc').dc
// Here we just use the built-in health endpoint, as it gives us everything
// we need.
return Ember.$.getJSON('/v1/health/service/' + params.name).then(function(data) {
return Ember.$.getJSON('/v1/health/service/' + params.name + '?dc=' + dc).then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Node.create(obj));
@ -194,12 +200,13 @@ App.ServicesShowRoute = App.BaseRoute.extend({
App.NodesShowRoute = App.BaseRoute.extend({
model: function(params) {
var dc = this.modelFor('dc').dc
// Return a promise hash of the node and nodes
return Ember.RSVP.hash({
node: Ember.$.getJSON('/v1/internal/ui/node/' + params.name).then(function(data) {
node: Ember.$.getJSON('/v1/internal/ui/node/' + params.name + '?dc=' + dc).then(function(data) {
return App.Node.create(data)
}),
nodes: Ember.$.getJSON('/v1/internal/ui/node/' + params.name).then(function(data) {
nodes: Ember.$.getJSON('/v1/internal/ui/node/' + params.name + '?dc=' + dc).then(function(data) {
return App.Node.create(data)
})
});
@ -218,8 +225,9 @@ App.NodesShowRoute = App.BaseRoute.extend({
App.NodesRoute = App.BaseRoute.extend({
model: function(params) {
var dc = this.modelFor('dc').dc
// Return a promise containing the nodes
return Ember.$.getJSON('/v1/internal/ui/nodes').then(function(data) {
return Ember.$.getJSON('/v1/internal/ui/nodes?dc=' + dc).then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Node.create(obj));