ui: kv load from url

This commit is contained in:
Jack Pearkes 2014-04-29 14:49:07 -04:00
parent 2c22cb833c
commit b8a13ac721
4 changed files with 48 additions and 14 deletions

View File

@ -63,8 +63,11 @@
</script> </script>
<script type="text/x-handlebars" data-template-name="kv/show"> <script type="text/x-handlebars" data-template-name="kv/show">
<a {{action 'linkToKey' parent }}>{{parent}}</a> <div class="row">
<a {{action 'linkToKey' parent }} class="btn btn-default">{{parent}}</a>
</div>
<div class="row">
<div class="col-md-5"> <div class="col-md-5">
<div class="row"> <div class="row">
@ -84,11 +87,15 @@
<div class="col-md-5 col-md-offset-1"> <div class="col-md-5 col-md-offset-1">
</div> </div>
</div>
</script> </script>
<script type="text/x-handlebars" data-template-name="kv/edit"> <script type="text/x-handlebars" data-template-name="kv/edit">
<a {{action 'linkToKey' parent }}>{{parent}}</a> <div class="row">
<a {{action 'linkToKey' parent }} class="btn btn-default">{{parent}}</a>
</div>
<div class="row">
<div class="col-md-5"> <div class="col-md-5">
<div class="row"> <div class="row">
{{#each item in siblings }} {{#each item in siblings }}
@ -109,6 +116,7 @@
<div class="col-md-5 col-md-offset-1"> <div class="col-md-5 col-md-offset-1">
{{ input value=model.value class="form-control"}} {{ input value=model.value class="form-control"}}
</div> </div>
</div>
</script> </script>
<script type="text/x-handlebars" id="services"> <script type="text/x-handlebars" id="services">

View File

@ -85,14 +85,29 @@ App.Key = Ember.Object.extend({
return (this.get('key').slice(-1) == "/") return (this.get('key').slice(-1) == "/")
}.property('isFolder'), }.property('isFolder'),
parentKeys: function() { keyParts: function() {
var parts = this.get('key').split('/') var key = this.get('key');
console.log(parts) if (key.slice(-1) == "/") {
part = parts.slice(2) key = key.substring(0, key.length - 1);
}
return key.split('/');
}.property('keyParts'),
console.log(part) parentKey: function() {
var parts = this.get('keyParts');
return '/' parts.pop();
}.property('parentKey')
return parts.join("/") + "/";
}.property('parentKey'),
grandParentKey: function() {
var parts = this.get('keyParts');
parts.pop();
parts.pop();
return parts.join("/") + "/";
}.property('grandParentKey')
}); });

View File

@ -13,6 +13,7 @@ App.Router.map(function() {
this.route("show", { path: "/:name" }); this.route("show", { path: "/:name" });
}); });
this.resource("kv", { path: "/kv" }, function(){ this.resource("kv", { path: "/kv" }, function(){
this.route("index", { path: "/" });
this.route("show", { path: "/:key" }); this.route("show", { path: "/:key" });
this.route("edit", { path: "/:key/edit" }); this.route("edit", { path: "/:key/edit" });
}) })

View File

@ -62,7 +62,7 @@ App.DcRoute = App.BaseRoute.extend({
}); });
App.KvRoute = App.BaseRoute.extend({ App.KvIndexRoute = App.BaseRoute.extend({
beforeModel: function() { beforeModel: function() {
this.transitionTo('kv.show', '-') this.transitionTo('kv.show', '-')
} }
@ -82,7 +82,7 @@ App.KvShowRoute = App.BaseRoute.extend({
setupController: function(controller, model) { setupController: function(controller, model) {
controller.set('content', model); controller.set('content', model);
controller.set('parent', model[0].get('parentKeys')); controller.set('parent', model[0].get('grandParentKey'));
} }
}); });
@ -94,9 +94,19 @@ App.KvEditRoute = App.BaseRoute.extend({
setupController: function(controller, model) { setupController: function(controller, model) {
controller.set('content', model); controller.set('content', model);
controller.set('siblings', this.modelFor('kv.show'));
console.log(this.modelFor('kv.show')) if (this.modelFor('kv.show') == undefined ) {
controller.set('parent', model.get('parentKeys')); var key = model.get('parentKey')
objs = [];
window.fixtures.keys_full[key].map(function(obj){
objs.push(App.Key.create({key: obj}));
});
controller.set('siblings', objs);
} else {
controller.set('siblings', this.modelFor('kv.show'));
}
controller.set('parent', controller.get('siblings')[0].get('grandParentKey'));
} }
}); });