From 227daf1fea3bdd07b1ce2be7a6c3beb17b1f023a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Sun, 4 May 2014 23:05:00 +0200 Subject: [PATCH] Allow using dashes in keys --- ui/index.html | 4 ++-- ui/javascripts/app/controllers.js | 6 +++--- ui/javascripts/app/models.js | 17 ++-------------- ui/javascripts/app/router.js | 5 ++--- ui/javascripts/app/routes.js | 32 ++++++++++++------------------- 5 files changed, 21 insertions(+), 43 deletions(-) diff --git a/ui/index.html b/ui/index.html index c78fadb8b..0e7f5dac3 100644 --- a/ui/index.html +++ b/ui/index.html @@ -101,7 +101,7 @@ {{#each item in model }} - {{#link-to item.linkToRoute item.urlSafeKey href=false tagName="div" class="panel panel-link panel-short"}} + {{#link-to item.linkToRoute item.Key href=false tagName="div" class="panel panel-link panel-short"}}

@@ -172,7 +172,7 @@
{{#each item in siblings }} - {{#link-to item.linkToRoute item.urlSafeKey href=false tagName="div" class="panel panel-link panel-short"}} + {{#link-to item.linkToRoute item.Key href=false tagName="div" class="panel panel-link panel-short"}}

diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js index 61183efe3..1fd78ba85 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -100,9 +100,9 @@ App.KvShowController.reopen({ }).then(function(response) { // transition to the right place if (newKey.get('isFolder') == true) { - controller.transitionToRoute('kv.show', newKey.get('urlSafeKey')); + controller.transitionToRoute('kv.show', newKey.get('Key')); } else { - controller.transitionToRoute('kv.edit', newKey.get('urlSafeKey')); + controller.transitionToRoute('kv.edit', newKey.get('Key')); } controller.set('isLoading', false) }).fail(function(response) { @@ -151,7 +151,7 @@ App.KvEditController = Ember.Controller.extend({ // Get the parent for the transition back up a level // after the delete - var parent = key.get('urlSafeParentKey'); + var parent = key.get('parentKey'); // Delete the key Ember.$.ajax({ diff --git a/ui/javascripts/app/models.js b/ui/javascripts/app/models.js index 6583d2f24..60734f0c6 100644 --- a/ui/javascripts/app/models.js +++ b/ui/javascripts/app/models.js @@ -124,26 +124,13 @@ App.Key = Ember.Object.extend(Ember.Validations.Mixin, { if (this.get('Key') === undefined) { return false; }; - return (this.get('Key').slice(-1) == "/") - }.property('Key'), - - // The dasherized URL safe version of the key for routing - urlSafeKey: function() { - return this.get('Key').replace(/\//g, "-") - }.property('Key'), - - // The dasherized URL safe version of the parent key for routing - urlSafeParentKey: function() { - return this.get('parentKey').replace(/\//g, "-") + return (this.get('Key').slice(-1) === '/') }.property('Key'), // Determines what route to link to. If it's a folder, // it will link to kv.show. Otherwise, kv.edit linkToRoute: function() { - var key = this.get('urlSafeKey') - - // If the key ends in - it's a folder - if (key.slice(-1) === "-") { + if (this.get('Key').slice(-1) === '/') { return 'kv.show' } else { return 'kv.edit' diff --git a/ui/javascripts/app/router.js b/ui/javascripts/app/router.js index a4011b809..d86921915 100644 --- a/ui/javascripts/app/router.js +++ b/ui/javascripts/app/router.js @@ -19,12 +19,11 @@ App.Router.map(function() { }); // Key/Value this.resource("kv", { path: "/kv" }, function(){ - // This route just redirects to /- this.route("index", { path: "/" }); // List keys. This is more like an index - this.route("show", { path: "/:key" }); + this.route("show", { path: "/*key" }); // Edit a specific key - this.route("edit", { path: "/:key/edit" }); + this.route("edit", { path: "/*key/edit" }); }) }); diff --git a/ui/javascripts/app/routes.js b/ui/javascripts/app/routes.js index 49ac9fa09..e642ea58f 100644 --- a/ui/javascripts/app/routes.js +++ b/ui/javascripts/app/routes.js @@ -2,22 +2,19 @@ // Superclass to be used by all of the main routes below. // App.BaseRoute = Ember.Route.extend({ + rootRoute: '', + getParentAndGrandparent: function(key) { - var parentKey, grandParentKey, isFolder; + var parentKey = this.rootRoute, + grandParentKey = this.rootRoute, + parts = key.split('/'); - parts = key.split('/'); - - // If we are the root, set the parent and grandparent to the - // root. - if (key == "/") { - parentKey = "/"; - grandParentKey ="/" - } else { - // Go one level up + if (parts.length > 0) { parts.pop(); parentKey = parts.join("/") + "/"; + } - // Go two levels up + if (parts.length > 1) { parts.pop(); grandParentKey = parts.join("/") + "/"; } @@ -41,9 +38,7 @@ App.BaseRoute = Ember.Route.extend({ // Used to link to keys that are not objects, // like parents and grandParents linkToKey: function(key) { - key = key.replace(/\//g, "-") - - if (key.slice(-1) === "-") { + if (key.slice(-1) === '/' || key === this.rootRoute) { this.transitionTo('kv.show', key) } else { this.transitionTo('kv.edit', key) @@ -103,18 +98,15 @@ App.DcRoute = App.BaseRoute.extend({ }, }); - App.KvIndexRoute = App.BaseRoute.extend({ - // If they hit /kv we want to just move them to /kv/- beforeModel: function() { - this.transitionTo('kv.show', '-') + this.transitionTo('kv.show', this.rootRoute) } }); App.KvShowRoute = App.BaseRoute.extend({ model: function(params) { - // Convert the key back to the format consul understands - var key = params.key.replace(/-/g, "/") + var key = params.key; var dc = this.modelFor('dc').dc; // Return a promise has with the ?keys for that namespace @@ -145,7 +137,7 @@ App.KvShowRoute = App.BaseRoute.extend({ App.KvEditRoute = App.BaseRoute.extend({ model: function(params) { - var key = params.key.replace(/-/g, "/"); + var key = params.key; var dc = this.modelFor('dc').dc; var parentKeys = this.getParentAndGrandparent(key)