mirror of https://github.com/status-im/consul.git
Merge pull request #124 from tiwilliam/delete-folders
Add delete folder button to web UI
This commit is contained in:
commit
d5a74e913a
|
@ -151,6 +151,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<button {{ action "createKey"}} {{bind-attr disabled=newKey.isInvalid }} {{ bind-attr class=":btn newKey.isValid:btn-success:btn-default" }}>Create</button>
|
<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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -211,7 +212,7 @@
|
||||||
</div>
|
</div>
|
||||||
<button {{ action "updateKey"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn isLoading:btn-warning:btn-success" }}>Update</button>
|
<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 "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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</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
|
// Add mixins
|
||||||
App.KvShowController = Ember.ObjectController.extend(Ember.Validations.Mixin);
|
App.KvShowController = KvBaseController.extend(Ember.Validations.Mixin);
|
||||||
|
|
||||||
App.KvShowController.reopen({
|
App.KvShowController.reopen({
|
||||||
needs: ["dc"],
|
needs: ["dc"],
|
||||||
|
@ -79,11 +100,11 @@ App.KvShowController.reopen({
|
||||||
createKey: function() {
|
createKey: function() {
|
||||||
this.set('isLoading', true);
|
this.set('isLoading', true);
|
||||||
|
|
||||||
var newKey = this.get('newKey');
|
|
||||||
var parentKey = this.get('parentKey');
|
|
||||||
var grandParentKey = this.get('grandParentKey');
|
|
||||||
var controller = this;
|
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
|
// If we don't have a previous model to base
|
||||||
// on our parent, or we're not at the root level,
|
// 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
|
// Render the error message on the form if the request failed
|
||||||
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
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,
|
isLoading: false,
|
||||||
needs: ["dc"],
|
needs: ["dc"],
|
||||||
dc: Ember.computed.alias("controllers.dc"),
|
dc: Ember.computed.alias("controllers.dc"),
|
||||||
|
@ -151,27 +190,23 @@ App.KvEditController = Ember.Controller.extend({
|
||||||
|
|
||||||
deleteKey: function() {
|
deleteKey: function() {
|
||||||
this.set('isLoading', true);
|
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
|
var controller = this;
|
||||||
// after the delete
|
var dc = controller.get('dc').get('datacenter');
|
||||||
var parent = key.get('parentKey');
|
var key = controller.get("model");
|
||||||
|
var isRoot = controller.get('isRoot');
|
||||||
|
var parent = isRoot ? controller.get('rootKey') : key.get('parentKey');
|
||||||
|
|
||||||
// Delete the key
|
// Delete the key
|
||||||
Ember.$.ajax({
|
Ember.$.ajax({
|
||||||
url: ("/v1/kv/" + key.get('Key') + '?dc=' + dc),
|
url: ("/v1/kv/" + key.get('Key') + '?dc=' + dc),
|
||||||
type: 'DELETE'
|
type: 'DELETE'
|
||||||
}).then(function(response) {
|
}).then(function(data) {
|
||||||
// Tranisiton back up a level
|
controller.transitionToNearestParent(parent);
|
||||||
controller.transitionToRoute('kv.show', parent);
|
|
||||||
controller.set('isLoading', false);
|
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
// Render the error message on the form if the request failed
|
// Render the error message on the form if the request failed
|
||||||
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,11 @@ App.BaseRoute = Ember.Route.extend({
|
||||||
grandParentKey = parts.join("/") + "/";
|
grandParentKey = parts.join("/") + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
return {grandParent: grandParentKey, parent: parentKey}
|
return {
|
||||||
|
parent: parentKey,
|
||||||
|
grandParent: grandParentKey,
|
||||||
|
isRoot: parentKey === '/'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
removeDuplicateKeys: function(keys, matcher) {
|
removeDuplicateKeys: function(keys, matcher) {
|
||||||
|
@ -131,7 +135,9 @@ App.KvShowRoute = App.BaseRoute.extend({
|
||||||
controller.set('content', models.keys);
|
controller.set('content', models.keys);
|
||||||
controller.set('parentKey', parentKeys.parent);
|
controller.set('parentKey', parentKeys.parent);
|
||||||
controller.set('grandParentKey', parentKeys.grandParent);
|
controller.set('grandParentKey', parentKeys.grandParent);
|
||||||
|
controller.set('isRoot', parentKeys.isRoot);
|
||||||
controller.set('newKey', App.Key.create());
|
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('content', models.key);
|
||||||
controller.set('parentKey', parentKeys.parent);
|
controller.set('parentKey', parentKeys.parent);
|
||||||
controller.set('grandParentKey', parentKeys.grandParent);
|
controller.set('grandParentKey', parentKeys.grandParent);
|
||||||
|
controller.set('isRoot', parentKeys.isRoot);
|
||||||
controller.set('siblings', models.keys);
|
controller.set('siblings', models.keys);
|
||||||
|
controller.set('rootKey', this.rootKey);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue