Merge pull request #124 from tiwilliam/delete-folders
Add delete folder button to web UI
This commit is contained in:
commit
71897eda42
|
@ -151,6 +151,7 @@
|
|||
{{/if}}
|
||||
|
||||
<button {{ action "createKey"}} {{bind-attr disabled=newKey.isInvalid }} {{ bind-attr class=":btn newKey.isValid:btn-success:btn-default" }}>Create</button>
|
||||
<button {{ action "deleteFolder"}} {{bind-attr disabled=isRoot }} {{ bind-attr class=":btn :pull-right isLoading:btn-warning:btn-danger" }}>Delete folder</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -211,7 +212,7 @@
|
|||
</div>
|
||||
<button {{ action "updateKey"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn isLoading:btn-warning:btn-success" }}>Update</button>
|
||||
<button {{ action "cancelEdit"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn isLoading:btn-warning:btn-default" }}>Cancel</button>
|
||||
<button {{ action "deleteKey"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn :pull-right isLoading:btn-warning:btn-danger" }}>Delete</button>
|
||||
<button {{ action "deleteKey"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn :pull-right isLoading:btn-warning:btn-danger" }}>Delete key</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue