diff --git a/ui/index.html b/ui/index.html
index f0cd71517..97d5b00f5 100644
--- a/ui/index.html
+++ b/ui/index.html
@@ -151,6 +151,7 @@
{{/if}}
+
@@ -211,7 +212,7 @@
-
+
diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js
index 29b4910e2..debb9aff5 100644
--- a/ui/javascripts/app/controllers.js
+++ b/ui/javascripts/app/controllers.js
@@ -65,8 +65,29 @@ App.DcController = Ember.Controller.extend({
}
})
+KvBaseController = Ember.ObjectController.extend({
+ transitionToNearestParent: function(parent) {
+ var controller = this;
+ var rootKey = controller.get('rootKey');
+ var dc = controller.get('dc').get('datacenter');
+
+ Ember.$.ajax({
+ url: ('/v1/kv/' + parent + '?keys&c=' + dc),
+ type: 'GET'
+ }).then(function(data) {
+ controller.transitionToRoute('kv.show', parent);
+ }).fail(function(response) {
+ if (response.status === 404) {
+ controller.transitionToRoute('kv.show', rootKey);
+ }
+ });
+
+ controller.set('isLoading', false);
+ }
+});
+
// Add mixins
-App.KvShowController = Ember.ObjectController.extend(Ember.Validations.Mixin);
+App.KvShowController = KvBaseController.extend(Ember.Validations.Mixin);
App.KvShowController.reopen({
needs: ["dc"],
@@ -79,11 +100,11 @@ App.KvShowController.reopen({
createKey: function() {
this.set('isLoading', true);
- var newKey = this.get('newKey');
- var parentKey = this.get('parentKey');
- var grandParentKey = this.get('grandParentKey');
var controller = this;
- var dc = this.get('dc').get('datacenter');
+ var newKey = controller.get('newKey');
+ var parentKey = controller.get('parentKey');
+ var grandParentKey = controller.get('grandParentKey');
+ var dc = controller.get('dc').get('datacenter');
// If we don't have a previous model to base
// on our parent, or we're not at the root level,
@@ -109,12 +130,30 @@ App.KvShowController.reopen({
// Render the error message on the form if the request failed
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
});
+ },
+ deleteFolder: function() {
+ this.set('isLoading', true);
+
+ var controller = this;
+ var key = controller.get("model");
+ var grandParent = key.get('grandParentKey');
+
+ // Delete the folder
+ Ember.$.ajax({
+ url: ("/v1/kv/" + key.get('parentKey') + '?recurse'),
+ type: 'DELETE'
+ }).then(function(response) {
+ controller.transitionToNearestParent(grandParent);
+ }).fail(function(response) {
+ // Render the error message on the form if the request failed
+ controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
+ });
}
}
});
-App.KvEditController = Ember.Controller.extend({
+App.KvEditController = KvBaseController.extend({
isLoading: false,
needs: ["dc"],
dc: Ember.computed.alias("controllers.dc"),
@@ -151,27 +190,23 @@ App.KvEditController = Ember.Controller.extend({
deleteKey: function() {
this.set('isLoading', true);
- var key = this.get("model");
- var controller = this;
- var dc = this.get('dc').get('datacenter');
- // Get the parent for the transition back up a level
- // after the delete
- var parent = key.get('parentKey');
+ var controller = this;
+ var dc = controller.get('dc').get('datacenter');
+ var key = controller.get("model");
+ var isRoot = controller.get('isRoot');
+ var parent = isRoot ? controller.get('rootKey') : key.get('parentKey');
// Delete the key
Ember.$.ajax({
url: ("/v1/kv/" + key.get('Key') + '?dc=' + dc),
type: 'DELETE'
- }).then(function(response) {
- // Tranisiton back up a level
- controller.transitionToRoute('kv.show', parent);
- controller.set('isLoading', false);
+ }).then(function(data) {
+ controller.transitionToNearestParent(parent);
}).fail(function(response) {
// Render the error message on the form if the request failed
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
})
-
}
}
diff --git a/ui/javascripts/app/routes.js b/ui/javascripts/app/routes.js
index a96a3d31e..308a2b964 100644
--- a/ui/javascripts/app/routes.js
+++ b/ui/javascripts/app/routes.js
@@ -19,7 +19,11 @@ App.BaseRoute = Ember.Route.extend({
grandParentKey = parts.join("/") + "/";
}
- return {grandParent: grandParentKey, parent: parentKey}
+ return {
+ parent: parentKey,
+ grandParent: grandParentKey,
+ isRoot: parentKey === '/'
+ }
},
removeDuplicateKeys: function(keys, matcher) {
@@ -131,7 +135,9 @@ App.KvShowRoute = App.BaseRoute.extend({
controller.set('content', models.keys);
controller.set('parentKey', parentKeys.parent);
controller.set('grandParentKey', parentKeys.grandParent);
+ controller.set('isRoot', parentKeys.isRoot);
controller.set('newKey', App.Key.create());
+ controller.set('rootKey', this.rootKey);
}
});
@@ -165,7 +171,9 @@ App.KvEditRoute = App.BaseRoute.extend({
controller.set('content', models.key);
controller.set('parentKey', parentKeys.parent);
controller.set('grandParentKey', parentKeys.grandParent);
+ controller.set('isRoot', parentKeys.isRoot);
controller.set('siblings', models.keys);
+ controller.set('rootKey', this.rootKey);
}
});