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

274 lines
6.7 KiB
JavaScript
Raw Normal View History

2014-04-23 22:51:06 +00:00
//
// Superclass to be used by all of the main routes below. All routes
// but the IndexRoute share the need to have a datacenter set.
//
//
2014-04-23 18:01:42 +00:00
App.BaseRoute = Ember.Route.extend({
2014-04-29 17:06:26 +00:00
actions: {
linkToKey: function(key) {
key = key.replace(/\//g, "-")
if (key.slice(-1) === "-") {
this.transitionTo('kv.show', key)
} else {
this.transitionTo('kv.edit', key)
}
}
}
2014-04-21 20:36:50 +00:00
});
2014-04-23 22:51:06 +00:00
//
// The route for choosing datacenters, typically the first route loaded.
//
// Note: This *does not* extend from BaseRoute as that could cause
// and loop of transitions.
//
2014-04-21 20:36:50 +00:00
App.IndexRoute = Ember.Route.extend({
2014-04-30 18:02:20 +00:00
model: function(params) {
return Ember.$.getJSON('/v1/catalog/datacenters').then(function(data) {
return data
});
2014-04-23 18:01:42 +00:00
},
2014-04-27 14:42:21 +00:00
setupController: function(controller, model) {
controller.set('content', model);
2014-04-30 18:02:20 +00:00
controller.set('dcs', model);
2014-04-27 14:42:21 +00:00
},
2014-04-23 18:01:42 +00:00
afterModel: function(dcs, transition) {
if (dcs.get('length') === 1) {
this.transitionTo('services', dcs[0]);
}
}
});
2014-04-25 17:49:36 +00:00
// The base DC route
2014-04-23 18:01:42 +00:00
2014-04-25 17:49:36 +00:00
App.DcRoute = App.BaseRoute.extend({
2014-04-23 22:51:06 +00:00
//
2014-04-25 17:49:36 +00:00
// Set the model on the route. We look up the specific service
// by it's identifier passed via the route
2014-04-23 22:51:06 +00:00
//
2014-04-25 17:49:36 +00:00
model: function(params) {
2014-04-30 18:02:20 +00:00
var object = Ember.Object.create();
object.set('dc', params.dc)
2014-04-25 20:24:36 +00:00
2014-04-30 18:02:20 +00:00
var nodesPromise = Ember.$.getJSON('/v1/internal/ui/nodes').then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Node.create(obj));
});
object.set('nodes', objs);
return object;
});
2014-04-25 20:24:36 +00:00
2014-04-30 18:02:20 +00:00
var datacentersPromise = Ember.$.getJSON('/v1/catalog/datacenters').then(function(data) {
object.set('dcs', data);
return object;
});
2014-04-25 20:24:36 +00:00
2014-04-30 18:02:20 +00:00
return nodesPromise.then(datacentersPromise);
},
setupController: function(controller, model) {
controller.set('content', model.get('dc'));
controller.set('nodes', model.get('nodes'));
controller.set('dcs', model.get('dcs'));
2014-04-25 17:49:36 +00:00
}
2014-04-23 18:01:42 +00:00
});
2014-04-28 22:23:01 +00:00
2014-04-29 18:49:07 +00:00
App.KvIndexRoute = App.BaseRoute.extend({
2014-04-29 17:06:26 +00:00
beforeModel: function() {
this.transitionTo('kv.show', '-')
}
});
App.KvShowRoute = App.BaseRoute.extend({
model: function(params) {
var key = params.key.replace(/-/g, "/")
2014-04-28 22:23:01 +00:00
2014-04-30 19:02:31 +00:00
return Ember.$.getJSON('/v1/kv/' + key + '?keys&seperator=' + '/').then(function(data) {
objs = [];
2014-04-28 22:23:01 +00:00
2014-04-30 19:02:31 +00:00
data.map(function(obj){
objs.push(App.Key.create({Key: obj}));
});
return objs;
});
2014-04-28 22:23:01 +00:00
},
setupController: function(controller, model) {
controller.set('content', model);
2014-04-29 19:24:32 +00:00
controller.set('topModel', model[0]);
controller.set('newKey', App.Key.create());
2014-04-29 17:06:26 +00:00
}
});
App.KvEditRoute = App.BaseRoute.extend({
model: function(params) {
2014-04-30 19:02:31 +00:00
var object = Ember.Object.create();
var keyName = params.key.replace(/-/g, "/")
var key = keyName;
var parentKey;
// Get the parent key
if (key.slice(-1) == "/") {
key = key.substring(0, key.length - 1);
}
parts = key.split('/');
parts.pop();
if (parts.length == 0) {
parentKey = ""
} else {
parentKey = parts.join("/") + "/";
}
var keyPromise = Ember.$.getJSON('/v1/kv/' + keyName).then(function(data) {
object.set('key', App.Key.create().setProperties(data[0]))
return object;
});
var keysPromise = Ember.$.getJSON('/v1/kv/' + parentKey + '?keys&seperator=' + '/').then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Key.create({Key: obj}));
});
object.set('keys', objs);
return object;
});
return keysPromise.then(keyPromise);
2014-04-29 17:06:26 +00:00
},
2014-04-29 17:34:13 +00:00
2014-04-29 17:06:26 +00:00
setupController: function(controller, model) {
2014-04-30 19:02:31 +00:00
controller.set('content', model.get('key'));
controller.set('siblings', model.get('keys'));
2014-04-29 18:49:07 +00:00
if (this.modelFor('kv.show') == undefined ) {
} else {
controller.set('siblings', this.modelFor('kv.show'));
}
2014-04-28 22:23:01 +00:00
}
});
2014-04-25 17:49:36 +00:00
/// services
2014-04-23 22:51:06 +00:00
//
// Display all the services, allow to drill down into the specific services.
//
2014-04-23 18:01:42 +00:00
App.ServicesRoute = App.BaseRoute.extend({
2014-04-30 18:02:20 +00:00
model: function(params) {
return Ember.$.getJSON('/v1/internal/ui/services').then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Service.create(obj));
});
return objs
});
},
//
// Set the services as the routes default model to be called in
// the template as {{model}}
//
setupController: function(controller, model) {
2014-04-28 15:56:07 +00:00
//
// Since we have 2 column layout, we need to also display the
// list of services on the left. Hence setting the attribute
// {{services}} on the controller.
//
2014-04-30 18:02:20 +00:00
controller.set('services', model);
}
});
2014-04-24 19:18:11 +00:00
//
// Display an individual service, as well as the global services in the left
// column.
//
App.ServicesShowRoute = App.BaseRoute.extend({
//
// Set the model on the route. We look up the specific service
// by it's identifier passed via the route
//
model: function(params) {
2014-04-30 18:02:20 +00:00
return Ember.$.getJSON('/v1/health/service/' + params.name).then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Node.create(obj));
});
console.log(objs)
return objs;
});
},
2014-04-21 20:36:50 +00:00
});
2014-04-23 18:01:42 +00:00
2014-04-24 19:18:11 +00:00
2014-04-25 17:49:36 +00:00
/// nodes
2014-04-24 19:18:11 +00:00
//
// Display an individual node, as well as the global nodes in the left
// column.
//
App.NodesShowRoute = App.BaseRoute.extend({
2014-04-24 19:18:11 +00:00
//
// Set the model on the route. We look up the specific node
// by it's identifier passed via the route
//
model: function(params) {
2014-04-30 19:25:31 +00:00
return Ember.RSVP.hash({
node: Ember.$.getJSON('/v1/internal/ui/node/' + params.name).then(function(data) {
return App.Node.create(data)
}),
nodes: Ember.$.getJSON('/v1/internal/ui/node/' + params.name).then(function(data) {
return App.Node.create(data)
})
2014-04-30 18:02:20 +00:00
});
2014-04-30 19:25:31 +00:00
2014-04-24 19:18:11 +00:00
},
2014-04-30 19:25:31 +00:00
setupController: function(controller, models) {
controller.set('content', models.node);
2014-04-24 19:18:11 +00:00
//
// Since we have 2 column layout, we need to also display the
2014-04-24 19:33:53 +00:00
// list of nodes on the left. Hence setting the attribute
// {{nodes}} on the controller.
2014-04-24 19:18:11 +00:00
//
2014-04-30 19:25:31 +00:00
controller.set('nodes', models.nodes);
2014-04-24 19:18:11 +00:00
}
});
//
2014-04-24 19:33:53 +00:00
// Display all the nodes, allow to drill down into the specific nodes.
2014-04-24 19:18:11 +00:00
//
App.NodesRoute = App.BaseRoute.extend({
2014-04-30 18:02:20 +00:00
model: function(params) {
return Ember.$.getJSON('/v1/internal/ui/nodes').then(function(data) {
objs = [];
data.map(function(obj){
objs.push(App.Node.create(obj));
});
return objs
});
},
2014-04-24 19:18:11 +00:00
//
2014-04-24 19:33:53 +00:00
// Set the node as the routes default model to be called in
// the template as {{model}}. This is the "expanded" view.
2014-04-24 19:18:11 +00:00
//
setupController: function(controller, model) {
//
// Since we have 2 column layout, we need to also display the
// list of nodes on the left. Hence setting the attribute
// {{nodes}} on the controller.
//
2014-04-30 18:02:20 +00:00
controller.set('nodes', model);
2014-04-24 19:18:11 +00:00
}
});