diff --git a/ui/index.html b/ui/index.html index d56bc4d249..a699575fe7 100644 --- a/ui/index.html +++ b/ui/index.html @@ -62,23 +62,49 @@ {{outlet}} - + + diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js index 9c40337d5b..1cb348c7db 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -70,14 +70,3 @@ App.ServicesController = Ember.ArrayController.extend({ App.ServicesShowController = Ember.Controller.extend({ needs: ['services'] }); - - -// Key value controller -App.KvController = Ember.Controller.extend({ - actions: { - linkToKey: function(top, child) { - var route = top + "/" + child - this.transitionToRoute('kv.key', route) - } - } -}); diff --git a/ui/javascripts/app/models.js b/ui/javascripts/app/models.js index a8dcc645e3..792f025adf 100644 --- a/ui/javascripts/app/models.js +++ b/ui/javascripts/app/models.js @@ -76,3 +76,20 @@ App.Node = Ember.Object.extend({ }.property('hasFailingChecks') }); + +// +// A key/value object +// +App.Key = Ember.Object.extend({ + isFolder: function() { + return (this.get('key').slice(-1) == "/") + }.property('isFolder'), + + parentKeys: function() { + var parts = this.get('key').split('/') + parts.pop() + console.log(parts) + + return parts + }.property('parentKey') +}); diff --git a/ui/javascripts/app/router.js b/ui/javascripts/app/router.js index 591aae6b94..b84b59bc58 100644 --- a/ui/javascripts/app/router.js +++ b/ui/javascripts/app/router.js @@ -12,9 +12,9 @@ App.Router.map(function() { this.resource("nodes", { path: "/nodes" }, function() { this.route("show", { path: "/:name" }); }); - this.resource("kv", { path: "/kv" }, function() { - this.route("key", { path: "/*wildcard" }); - }); + this.resource("kv", { path: "/kv" }); + this.resource("kv.show", { path: "/kv/:key" }); + this.resource("kv.edit", { path: "/kv/:key/edit" }); }); this.route("index", { path: "/" }); diff --git a/ui/javascripts/app/routes.js b/ui/javascripts/app/routes.js index b5f7cac91b..3b3d4cd2bc 100644 --- a/ui/javascripts/app/routes.js +++ b/ui/javascripts/app/routes.js @@ -4,6 +4,17 @@ // // App.BaseRoute = Ember.Route.extend({ + actions: { + linkToKey: function(key) { + key = key.replace(/\//g, "-") + + if (key.slice(-1) === "-") { + this.transitionTo('kv.show', key) + } else { + this.transitionTo('kv.edit', key) + } + } + } }); // @@ -19,7 +30,6 @@ App.IndexRoute = Ember.Route.extend({ setupController: function(controller, model) { controller.set('content', model); - controller.set('dcs', window.fixtures.dcs); }, @@ -51,23 +61,39 @@ App.DcRoute = App.BaseRoute.extend({ } }); -// -// The route for for browsing and editing k/v data -// -// -App.KvRoute = Ember.Route.extend({ + +App.KvRoute = App.BaseRoute.extend({ + beforeModel: function() { + this.transitionTo('kv.show', '-') + } +}); + +App.KvShowRoute = App.BaseRoute.extend({ model: function(params) { - var parts = window.location.hash.split("/").slice(3) + var key = params.key.replace(/-/g, "/") + objs = []; - var key = parts.join("/") + window.fixtures.keys_full[key].map(function(obj){ + objs.push(App.Key.create({key: obj})); + }); - console.log(key); - - return window.fixtures.keys_full[key]; + return objs }, setupController: function(controller, model) { controller.set('content', model); + controller.set('parent', model[0].get('parentKeys')); + } +}); + +App.KvEditRoute = App.BaseRoute.extend({ + model: function(params) { + var key = params.key.replace(/-/g, "/") + return App.Key.create().setProperties(window.fixtures.keys_full[key]); + }, + setupController: function(controller, model) { + controller.set('content', model); + controller.set('parent', model.get('parentKeys')); } }); diff --git a/ui/javascripts/app/views.js b/ui/javascripts/app/views.js index ee3a94921d..fa40441ef7 100644 --- a/ui/javascripts/app/views.js +++ b/ui/javascripts/app/views.js @@ -47,3 +47,9 @@ App.NodesShowView = Ember.View.extend({ // templateName: 'node' }) + + + +App.KvListView = Ember.View.extend({ + templateName: 'kv' +}) diff --git a/ui/javascripts/fixtures.js b/ui/javascripts/fixtures.js index 2209c19d08..76ed44193c 100644 --- a/ui/javascripts/fixtures.js +++ b/ui/javascripts/fixtures.js @@ -286,31 +286,27 @@ fixtures.nodes_full = { fixtures.dcs = ['nyc1', 'sf1', 'sg1'] fixtures.keys_full = { + "/": [ + 'foobar', + 'application', + 'web/' + ], "application": { 'key': 'application', - 'value': '', - 'children': [ - 'secrets', - 'foobar', - 'baz' - ] + 'value': 'foobarz' }, - "application/foobar": { - 'key': 'application/foobar', - 'value': 'baz', - 'children': [] - } + "foobar": { + 'key': 'foobar', + 'value': 'baz' + }, + "web/foo/bar": { + 'key': 'web/foo/bar', + 'value': 'baz' + }, + "web/": [ + "web/foo/" + ], + "web/foo/": [ + "web/foo/bar" + ] }; - -// represents the root index key '/' -fixtures.keys = [ - { - 'key': 'application', - 'value': '', - 'children': [ - 'secrets', - 'foobar', - 'baz' - ] - } -];