From 14649c13983868711ae596d78ca9878834b8ca13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Mon, 5 May 2014 02:12:24 +0200 Subject: [PATCH 1/7] Add delete folder button to web UI --- ui/index.html | 3 ++- ui/javascripts/app/controllers.js | 29 ++++++++++++++++++++++------- ui/javascripts/app/routes.js | 7 ++++++- 3 files changed, 30 insertions(+), 9 deletions(-) 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..8b04a55e6 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -109,7 +109,26 @@ 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 key = this.get("model"); + var controller = this; + + // Delete the folder + Ember.$.ajax({ + url: ("/v1/kv/" + key.get('parentKey') + '?recurse'), + type: 'DELETE' + }).then(function(response) { + // Tranisiton back up a level + controller.transitionToRoute('kv.show', key.get('grandParentKey')); + controller.set('isLoading', false); + }).fail(function(response) { + // Render the error message on the form if the request failed + controller.set('errorMessage', 'Received error while processing: ' + response.statusText) + }) } } }); @@ -151,13 +170,10 @@ App.KvEditController = Ember.Controller.extend({ deleteKey: function() { this.set('isLoading', true); + + var dc = this.get('dc').get('datacenter'); 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'); // Delete the key Ember.$.ajax({ @@ -165,13 +181,12 @@ App.KvEditController = Ember.Controller.extend({ type: 'DELETE' }).then(function(response) { // Tranisiton back up a level - controller.transitionToRoute('kv.show', parent); + controller.transitionToRoute('kv.show', key.get('parentKey')); controller.set('isLoading', false); }).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..f31e04d98 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,6 +135,7 @@ 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()); } }); From 21ad67fc4ff8dc6fdbce65117734298f3cb13469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Mon, 5 May 2014 02:21:40 +0200 Subject: [PATCH 2/7] Revert modifications to `getParentAndGrandparent` --- ui/javascripts/app/routes.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ui/javascripts/app/routes.js b/ui/javascripts/app/routes.js index f31e04d98..0daa17d1d 100644 --- a/ui/javascripts/app/routes.js +++ b/ui/javascripts/app/routes.js @@ -19,11 +19,7 @@ App.BaseRoute = Ember.Route.extend({ grandParentKey = parts.join("/") + "/"; } - return { - parent: parentKey, - grandParent: grandParentKey, - isRoot: parentKey === '/' - } + return {grandParent: grandParentKey, parent: parentKey} }, removeDuplicateKeys: function(keys, matcher) { @@ -135,7 +131,7 @@ 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('isRoot', parentKeys.parent === '/'); controller.set('newKey', App.Key.create()); } }); From e174d1062c26094feaabf2c68bc82c515c67b9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Mon, 5 May 2014 02:51:34 +0200 Subject: [PATCH 3/7] Redirect to correct root path when deleting keys --- ui/javascripts/app/controllers.js | 11 ++++++++--- ui/javascripts/app/routes.js | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js index 8b04a55e6..3b70d8115 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -171,9 +171,14 @@ App.KvEditController = Ember.Controller.extend({ deleteKey: function() { this.set('isLoading', true); - var dc = this.get('dc').get('datacenter'); - var key = this.get("model"); var controller = this; + var dc = controller.get('dc').get('datacenter'); + var key = controller.get("model"); + var parent = key.get('parentKey'); + + if (parent === '/') { + parent = controller.get('rootKey'); + } // Delete the key Ember.$.ajax({ @@ -181,7 +186,7 @@ App.KvEditController = Ember.Controller.extend({ type: 'DELETE' }).then(function(response) { // Tranisiton back up a level - controller.transitionToRoute('kv.show', key.get('parentKey')); + controller.transitionToRoute('kv.show', parent); controller.set('isLoading', false); }).fail(function(response) { // Render the error message on the form if the request failed diff --git a/ui/javascripts/app/routes.js b/ui/javascripts/app/routes.js index 0daa17d1d..12d867ade 100644 --- a/ui/javascripts/app/routes.js +++ b/ui/javascripts/app/routes.js @@ -167,6 +167,7 @@ App.KvEditRoute = App.BaseRoute.extend({ controller.set('parentKey', parentKeys.parent); controller.set('grandParentKey', parentKeys.grandParent); controller.set('siblings', models.keys); + controller.set('rootKey', this.rootKey); } }); From a730174f0c44b9388268af9c8cedba1578102165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Mon, 5 May 2014 02:58:27 +0200 Subject: [PATCH 4/7] Clean up root check --- ui/javascripts/app/controllers.js | 7 ++----- ui/javascripts/app/routes.js | 9 +++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js index 3b70d8115..ba820a0b3 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -174,11 +174,8 @@ App.KvEditController = Ember.Controller.extend({ var controller = this; var dc = controller.get('dc').get('datacenter'); var key = controller.get("model"); - var parent = key.get('parentKey'); - - if (parent === '/') { - parent = controller.get('rootKey'); - } + var isRoot = controller.get('isRoot'); + var parent = isRoot ? controller.get('rootKey') : key.get('parentKey'); // Delete the key Ember.$.ajax({ diff --git a/ui/javascripts/app/routes.js b/ui/javascripts/app/routes.js index 12d867ade..2a525ec9c 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,7 @@ App.KvShowRoute = App.BaseRoute.extend({ controller.set('content', models.keys); controller.set('parentKey', parentKeys.parent); controller.set('grandParentKey', parentKeys.grandParent); - controller.set('isRoot', parentKeys.parent === '/'); + controller.set('isRoot', parentKeys.isRoot); controller.set('newKey', App.Key.create()); } }); @@ -168,6 +172,7 @@ App.KvEditRoute = App.BaseRoute.extend({ controller.set('grandParentKey', parentKeys.grandParent); controller.set('siblings', models.keys); controller.set('rootKey', this.rootKey); + controller.set('isRoot', parentKeys.isRoot); } }); From f4c4b5ace8177e874165a676f3f6fe103db07f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Mon, 5 May 2014 09:56:21 +0200 Subject: [PATCH 5/7] Transition to nearest parent on key delete --- ui/javascripts/app/controllers.js | 50 +++++++++++++++++++++---------- ui/javascripts/app/routes.js | 3 +- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js index ba820a0b3..92ca462ea 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -65,8 +65,29 @@ App.DcController = Ember.Controller.extend({ } }) +KvHelpController = 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 = KvHelpController.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, @@ -114,26 +135,27 @@ App.KvShowController.reopen({ deleteFolder: function() { this.set('isLoading', true); - var key = this.get("model"); 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) { - // Tranisiton back up a level - controller.transitionToRoute('kv.show', key.get('grandParentKey')); - controller.set('isLoading', false); + 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) - }) + }); + + controller.set('isLoading', false); } } }); -App.KvEditController = Ember.Controller.extend({ +App.KvEditController = KvHelpController.extend({ isLoading: false, needs: ["dc"], dc: Ember.computed.alias("controllers.dc"), @@ -181,10 +203,8 @@ App.KvEditController = Ember.Controller.extend({ 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 2a525ec9c..308a2b964 100644 --- a/ui/javascripts/app/routes.js +++ b/ui/javascripts/app/routes.js @@ -137,6 +137,7 @@ App.KvShowRoute = App.BaseRoute.extend({ controller.set('grandParentKey', parentKeys.grandParent); controller.set('isRoot', parentKeys.isRoot); controller.set('newKey', App.Key.create()); + controller.set('rootKey', this.rootKey); } }); @@ -170,9 +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); - controller.set('isRoot', parentKeys.isRoot); } }); From 570728f6b02f4ed5680b9049791621779b17a1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Mon, 5 May 2014 09:59:33 +0200 Subject: [PATCH 6/7] Drop duplicate isLoading set to false --- ui/javascripts/app/controllers.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js index 92ca462ea..ec52dd7e4 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -149,8 +149,6 @@ App.KvShowController.reopen({ // Render the error message on the form if the request failed controller.set('errorMessage', 'Received error while processing: ' + response.statusText) }); - - controller.set('isLoading', false); } } }); From 700d304d1533a25238c951a1c1dcca31927410a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Mon, 5 May 2014 15:05:30 +0200 Subject: [PATCH 7/7] Rename `KvHelpController` to `KvBaseController` --- ui/javascripts/app/controllers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js index ec52dd7e4..debb9aff5 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -65,7 +65,7 @@ App.DcController = Ember.Controller.extend({ } }) -KvHelpController = Ember.ObjectController.extend({ +KvBaseController = Ember.ObjectController.extend({ transitionToNearestParent: function(parent) { var controller = this; var rootKey = controller.get('rootKey'); @@ -87,7 +87,7 @@ KvHelpController = Ember.ObjectController.extend({ }); // Add mixins -App.KvShowController = KvHelpController.extend(Ember.Validations.Mixin); +App.KvShowController = KvBaseController.extend(Ember.Validations.Mixin); App.KvShowController.reopen({ needs: ["dc"], @@ -153,7 +153,7 @@ App.KvShowController.reopen({ } }); -App.KvEditController = KvHelpController.extend({ +App.KvEditController = KvBaseController.extend({ isLoading: false, needs: ["dc"], dc: Ember.computed.alias("controllers.dc"),