mirror of https://github.com/status-im/consul.git
Merge pull request #119 from tiwilliam/dash-in-keys
Allow keys with dashes in web UI
This commit is contained in:
commit
34d5c94e5f
|
@ -101,7 +101,7 @@
|
||||||
|
|
||||||
{{#each item in model }}
|
{{#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 {{bind-attr class=":panel-bar item.isFolder:bg-gray:bg-light-gray" }}></div>
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title">
|
<h3 class="panel-title">
|
||||||
|
@ -172,7 +172,7 @@
|
||||||
<div class="col-md-5">
|
<div class="col-md-5">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{{#each item in siblings }}
|
{{#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 {{bind-attr class=":panel-bar item.isFolder:bg-gray:bg-light-gray" }}></div>
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title">
|
<h3 class="panel-title">
|
||||||
|
|
|
@ -100,9 +100,9 @@ App.KvShowController.reopen({
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
// transition to the right place
|
// transition to the right place
|
||||||
if (newKey.get('isFolder') == true) {
|
if (newKey.get('isFolder') == true) {
|
||||||
controller.transitionToRoute('kv.show', newKey.get('urlSafeKey'));
|
controller.transitionToRoute('kv.show', newKey.get('Key'));
|
||||||
} else {
|
} else {
|
||||||
controller.transitionToRoute('kv.edit', newKey.get('urlSafeKey'));
|
controller.transitionToRoute('kv.edit', newKey.get('Key'));
|
||||||
}
|
}
|
||||||
controller.set('isLoading', false)
|
controller.set('isLoading', false)
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
|
@ -151,7 +151,7 @@ App.KvEditController = Ember.Controller.extend({
|
||||||
|
|
||||||
// Get the parent for the transition back up a level
|
// Get the parent for the transition back up a level
|
||||||
// after the delete
|
// after the delete
|
||||||
var parent = key.get('urlSafeParentKey');
|
var parent = key.get('parentKey');
|
||||||
|
|
||||||
// Delete the key
|
// Delete the key
|
||||||
Ember.$.ajax({
|
Ember.$.ajax({
|
||||||
|
|
|
@ -124,26 +124,13 @@ App.Key = Ember.Object.extend(Ember.Validations.Mixin, {
|
||||||
if (this.get('Key') === undefined) {
|
if (this.get('Key') === undefined) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
return (this.get('Key').slice(-1) == "/")
|
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, "-")
|
|
||||||
}.property('Key'),
|
}.property('Key'),
|
||||||
|
|
||||||
// Determines what route to link to. If it's a folder,
|
// Determines what route to link to. If it's a folder,
|
||||||
// it will link to kv.show. Otherwise, kv.edit
|
// it will link to kv.show. Otherwise, kv.edit
|
||||||
linkToRoute: function() {
|
linkToRoute: function() {
|
||||||
var key = this.get('urlSafeKey')
|
if (this.get('Key').slice(-1) === '/') {
|
||||||
|
|
||||||
// If the key ends in - it's a folder
|
|
||||||
if (key.slice(-1) === "-") {
|
|
||||||
return 'kv.show'
|
return 'kv.show'
|
||||||
} else {
|
} else {
|
||||||
return 'kv.edit'
|
return 'kv.edit'
|
||||||
|
|
|
@ -19,12 +19,11 @@ App.Router.map(function() {
|
||||||
});
|
});
|
||||||
// Key/Value
|
// Key/Value
|
||||||
this.resource("kv", { path: "/kv" }, function(){
|
this.resource("kv", { path: "/kv" }, function(){
|
||||||
// This route just redirects to /-
|
|
||||||
this.route("index", { path: "/" });
|
this.route("index", { path: "/" });
|
||||||
// List keys. This is more like an index
|
// List keys. This is more like an index
|
||||||
this.route("show", { path: "/:key" });
|
this.route("show", { path: "/*key" });
|
||||||
// Edit a specific key
|
// Edit a specific key
|
||||||
this.route("edit", { path: "/:key/edit" });
|
this.route("edit", { path: "/*key/edit" });
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,22 +2,19 @@
|
||||||
// Superclass to be used by all of the main routes below.
|
// Superclass to be used by all of the main routes below.
|
||||||
//
|
//
|
||||||
App.BaseRoute = Ember.Route.extend({
|
App.BaseRoute = Ember.Route.extend({
|
||||||
getParentAndGrandparent: function(key) {
|
rootKey: '',
|
||||||
var parentKey, grandParentKey, isFolder;
|
|
||||||
|
|
||||||
|
getParentAndGrandparent: function(key) {
|
||||||
|
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
|
if (parts.length > 0) {
|
||||||
// root.
|
|
||||||
if (key == "/") {
|
|
||||||
parentKey = "/";
|
|
||||||
grandParentKey ="/"
|
|
||||||
} else {
|
|
||||||
// Go one level up
|
|
||||||
parts.pop();
|
parts.pop();
|
||||||
parentKey = parts.join("/") + "/";
|
parentKey = parts.join("/") + "/";
|
||||||
|
}
|
||||||
|
|
||||||
// Go two levels up
|
if (parts.length > 1) {
|
||||||
parts.pop();
|
parts.pop();
|
||||||
grandParentKey = parts.join("/") + "/";
|
grandParentKey = parts.join("/") + "/";
|
||||||
}
|
}
|
||||||
|
@ -41,9 +38,7 @@ App.BaseRoute = Ember.Route.extend({
|
||||||
// Used to link to keys that are not objects,
|
// Used to link to keys that are not objects,
|
||||||
// like parents and grandParents
|
// like parents and grandParents
|
||||||
linkToKey: function(key) {
|
linkToKey: function(key) {
|
||||||
key = key.replace(/\//g, "-")
|
if (key.slice(-1) === '/' || key === this.rootKey) {
|
||||||
|
|
||||||
if (key.slice(-1) === "-") {
|
|
||||||
this.transitionTo('kv.show', key)
|
this.transitionTo('kv.show', key)
|
||||||
} else {
|
} else {
|
||||||
this.transitionTo('kv.edit', key)
|
this.transitionTo('kv.edit', key)
|
||||||
|
@ -103,18 +98,15 @@ App.DcRoute = App.BaseRoute.extend({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
App.KvIndexRoute = App.BaseRoute.extend({
|
App.KvIndexRoute = App.BaseRoute.extend({
|
||||||
// If they hit /kv we want to just move them to /kv/-
|
|
||||||
beforeModel: function() {
|
beforeModel: function() {
|
||||||
this.transitionTo('kv.show', '-')
|
this.transitionTo('kv.show', this.rootKey)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
App.KvShowRoute = App.BaseRoute.extend({
|
App.KvShowRoute = App.BaseRoute.extend({
|
||||||
model: function(params) {
|
model: function(params) {
|
||||||
// Convert the key back to the format consul understands
|
var key = params.key;
|
||||||
var key = params.key.replace(/-/g, "/")
|
|
||||||
var dc = this.modelFor('dc').dc;
|
var dc = this.modelFor('dc').dc;
|
||||||
|
|
||||||
// Return a promise has with the ?keys for that namespace
|
// Return a promise has with the ?keys for that namespace
|
||||||
|
@ -145,7 +137,7 @@ App.KvShowRoute = App.BaseRoute.extend({
|
||||||
|
|
||||||
App.KvEditRoute = App.BaseRoute.extend({
|
App.KvEditRoute = App.BaseRoute.extend({
|
||||||
model: function(params) {
|
model: function(params) {
|
||||||
var key = params.key.replace(/-/g, "/");
|
var key = params.key;
|
||||||
var dc = this.modelFor('dc').dc;
|
var dc = this.modelFor('dc').dc;
|
||||||
var parentKeys = this.getParentAndGrandparent(key)
|
var parentKeys = this.getParentAndGrandparent(key)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue