ui: handle "folders", directory browsing with parents

This commit is contained in:
Jack Pearkes 2014-04-30 19:22:07 -04:00
parent 3e1bc7dbad
commit 23dc417055
4 changed files with 21 additions and 11 deletions

View file

@ -114,7 +114,6 @@
<div class="panel-body"> <div class="panel-body">
<form class="form"> <form class="form">
<div {{ bind-attr class=":form-group newKey.keyValid:valid" }}> <div {{ bind-attr class=":form-group newKey.keyValid:valid" }}>
<div class="input-group"> <div class="input-group">
<span class="input-group-addon">{{parentKey}}</span> <span class="input-group-addon">{{parentKey}}</span>
@ -122,9 +121,13 @@
</div> </div>
</div> </div>
<div {{ bind-attr class=":form-group newKey.valueValid:valid" }}> {{#if newKey.isFolder }}
<p>No value needed for nested keys.</p>
{{else}}
<div class="form-group">
{{ textarea value=newKey.Value class="form-control"}} {{ textarea value=newKey.Value class="form-control"}}
</div> </div>
{{/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>
</form> </form>
@ -137,7 +140,7 @@
<script type="text/x-handlebars" data-template-name="kv/edit"> <script type="text/x-handlebars" data-template-name="kv/edit">
<div class="row"> <div class="row">
<h5><a class="subtle" href="" {{action 'linkToKey' model.grandParentKey }}>{{model.parentKey}}</a></h5> <h5><a class="subtle" href="" {{action 'linkToKey' grandParentKey }}>{{parentKey}}</a></h5>
</div> </div>
<div class="row"> <div class="row">

View file

@ -80,12 +80,11 @@ App.KvShowController.reopen({
var grandParentKey = this.get('grandParentKey'); var grandParentKey = this.get('grandParentKey');
var controller = this; var controller = this;
var dc = this.get('dc').get('datacenter'); var dc = this.get('dc').get('datacenter');
console.log(dc)
// 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,
// strip the leading slash. // strip the leading slash.
if (parentKey != undefined || parentKey != "/") { if (parentKey != undefined && parentKey != "/") {
newKey.set('Key', (parentKey + newKey.get('Key'))); newKey.set('Key', (parentKey + newKey.get('Key')));
} }
@ -96,8 +95,13 @@ App.KvShowController.reopen({
data: newKey.get('Value') data: newKey.get('Value')
}).then(function(response) { }).then(function(response) {
controller.set('isLoading', false) controller.set('isLoading', false)
// Transition to edit the key // transition to the right place
controller.transitionToRoute('kv.edit', newKey.get('urlSafeKey')); console.log(newKey.get('Key'));
if (newKey.get('isFolder') == true) {
controller.transitionToRoute('kv.show', newKey.get('urlSafeKey'));
} else {
controller.transitionToRoute('kv.edit', newKey.get('urlSafeKey'));
}
// Reload the keys in the left column // Reload the keys in the left column
controller.get('keys').reload() controller.get('keys').reload()
}).fail(function(response) { }).fail(function(response) {

View file

@ -103,8 +103,7 @@ App.Node = Ember.Object.extend({
App.Key = Ember.Object.extend(Ember.Validations.Mixin, { App.Key = Ember.Object.extend(Ember.Validations.Mixin, {
// Validates using the Ember.Valdiations library // Validates using the Ember.Valdiations library
validations: { validations: {
Key: { presence: true }, Key: { presence: true }
Value: { presence: true }
}, },
// Boolean if the key is valid // Boolean if the key is valid
@ -122,6 +121,9 @@ App.Key = Ember.Object.extend(Ember.Validations.Mixin, {
// Boolean if the key is a "folder" or not, i.e is a nested key // Boolean if the key is a "folder" or not, i.e is a nested key
// that feels like a folder. Used for UI // that feels like a folder. Used for UI
isFolder: function() { isFolder: function() {
if (this.get('Key') === undefined) {
return false;
};
return (this.get('Key').slice(-1) == "/") return (this.get('Key').slice(-1) == "/")
}.property('Key'), }.property('Key'),

View file

@ -105,8 +105,9 @@ App.KvShowRoute = App.BaseRoute.extend({
// Loop over the keys // Loop over the keys
models.keys.forEach(function(item, index) { models.keys.forEach(function(item, index) {
if (item.get('Key') == key) { if (item.get('Key') == key) {
// Handle having only one key as a sub-parent
parentKey = item.get('Key'); parentKey = item.get('Key');
grandParentKey = item.get('grandParentKey'); grandParentKey = item.get('parentKey');
// Remove the dupe // Remove the dupe
models.keys.splice(index, 1); models.keys.splice(index, 1);
} }
@ -167,7 +168,7 @@ App.KvEditRoute = App.BaseRoute.extend({
models.keys.forEach(function(item, index) { models.keys.forEach(function(item, index) {
if (item.get('Key') == models.key.get('parentKey')) { if (item.get('Key') == models.key.get('parentKey')) {
parentKey = item.get('Key'); parentKey = item.get('Key');
grandParentKey = item.get('grandParentKey'); grandParentKey = item.get('parentKey');
// Remove the dupe // Remove the dupe
models.keys.splice(index, 1); models.keys.splice(index, 1);
} }