From 52d8a28592412e6da5e646aaed2e342a275bd436 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Tue, 29 Apr 2014 13:06:26 -0400 Subject: [PATCH] ui: further k/v improvements --- ui/index.html | 46 ++++++++++++++++++++++------- ui/javascripts/app/controllers.js | 11 ------- ui/javascripts/app/models.js | 17 +++++++++++ ui/javascripts/app/router.js | 6 ++-- ui/javascripts/app/routes.js | 48 ++++++++++++++++++++++++------- ui/javascripts/app/views.js | 6 ++++ ui/javascripts/fixtures.js | 44 +++++++++++++--------------- 7 files changed, 119 insertions(+), 59 deletions(-) diff --git a/ui/index.html b/ui/index.html index d56bc4d24..a699575fe 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 9c40337d5..1cb348c7d 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 a8dcc645e..792f025ad 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 591aae6b9..b84b59bc5 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 b5f7cac91..3b3d4cd2b 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 ee3a94921..fa40441ef 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 2209c19d0..76ed44193 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' - ] - } -];