Merge pull request #119 from tiwilliam/dash-in-keys

Allow keys with dashes in web UI
This commit is contained in:
Jack Pearkes 2014-05-04 17:37:17 -04:00
commit b9ed600069
5 changed files with 21 additions and 43 deletions

View File

@ -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"}}
<div {{bind-attr class=":panel-bar item.isFolder:bg-gray:bg-light-gray" }}></div>
<div class="panel-heading">
<h3 class="panel-title">
@ -172,7 +172,7 @@
<div class="col-md-5">
<div class="row">
{{#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"}}
<div {{bind-attr class=":panel-bar item.isFolder:bg-gray:bg-light-gray" }}></div>
<div class="panel-heading">
<h3 class="panel-title">

View File

@ -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({

View File

@ -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'

View File

@ -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" });
})
});

View File

@ -2,22 +2,19 @@
// Superclass to be used by all of the main routes below.
//
App.BaseRoute = Ember.Route.extend({
rootKey: '',
getParentAndGrandparent: function(key) {
var parentKey, grandParentKey, isFolder;
var parentKey = this.rootKey,
grandParentKey = this.rootKey,
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.rootKey) {
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.rootKey)
}
});
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)