Refactored Editor Routing

- Moved `new` route into `editor` resource (`editor.new`)
- Moved the current editor controller, view, and route to `editor.edit`
- Added `editor.index`, which automatically transitions into `editor.new`
- Moved controllers, views, templates, and routes to match new router config. Also changed links to `editor` into `editor.new` and `editor.edit` as appropriate.
This commit is contained in:
Matt Enlow 2014-06-09 22:44:29 -06:00
parent 39e09d5dd1
commit 6bc93a8ce8
15 changed files with 37 additions and 25 deletions

View File

@ -1,5 +0,0 @@
import EditorControllerMixin from 'ghost/mixins/editor-base-controller';
var EditorController = Ember.ObjectController.extend(EditorControllerMixin);
export default EditorController;

View File

@ -0,0 +1,5 @@
import EditorControllerMixin from 'ghost/mixins/editor-base-controller';
var EditorEditController = Ember.ObjectController.extend(EditorControllerMixin);
export default EditorEditController;

View File

@ -0,0 +1,5 @@
import EditorControllerMixin from 'ghost/mixins/editor-base-controller';
var EditorNewController = Ember.ObjectController.extend(EditorControllerMixin);
export default EditorNewController;

View File

@ -1,5 +0,0 @@
import EditorControllerMixin from 'ghost/mixins/editor-base-controller';
var EditorController = Ember.ObjectController.extend(EditorControllerMixin);
export default EditorController;

View File

@ -17,8 +17,10 @@ Router.map(function () {
this.resource('posts', { path: '/' }, function () {
this.route('post', { path: ':post_id' });
});
this.resource('editor', { path: '/editor/:post_id' });
this.route('new', { path: '/editor' });
this.resource('editor', function () {
this.route('new', { path: '' });
this.route('edit', { path: ':post_id' });
});
this.resource('settings', function () {
this.route('general');
this.route('user');

View File

@ -1,14 +1,13 @@
import styleBody from 'ghost/mixins/style-body';
import AuthenticatedRoute from 'ghost/routes/authenticated';
var EditorRoute = AuthenticatedRoute.extend(styleBody, {
var EditorEditRoute = AuthenticatedRoute.extend(styleBody, {
classNames: ['editor'],
model: function (params) {
var self = this,
post,
postId;
postId = Number(params.post_id);
if (!Number.isInteger(postId) || !Number.isFinite(postId) || postId <= 0) {
@ -22,7 +21,8 @@ var EditorRoute = AuthenticatedRoute.extend(styleBody, {
}
return this.store.filter('post', { status: 'all', staticPages: 'all' }, function (post) {
return post.get('id') === postId;
//post.get('id') returns a string, so compare with params.post_id
return post.get('id') === params.post_id;
}).then(function (records) {
var post = records.get('firstObject');
@ -32,7 +32,10 @@ var EditorRoute = AuthenticatedRoute.extend(styleBody, {
return self.transitionTo('posts.index');
});
},
serialize: function (model) {
return {post_id: model.get('id')};
}
});
export default EditorRoute;
export default EditorEditRoute;

7
routes/editor/index.js Normal file
View File

@ -0,0 +1,7 @@
var EditorRoute = Ember.Route.extend({
beforeModel: function () {
this.transitionTo('editor.new');
}
});
export default EditorRoute;

View File

@ -1,7 +1,7 @@
import AuthenticatedRoute from 'ghost/routes/authenticated';
import styleBody from 'ghost/mixins/style-body';
var NewRoute = AuthenticatedRoute.extend(styleBody, {
var EditorNewRoute = AuthenticatedRoute.extend(styleBody, {
classNames: ['editor'],
model: function () {
@ -11,4 +11,4 @@ var NewRoute = AuthenticatedRoute.extend(styleBody, {
}
});
export default NewRoute;
export default EditorNewRoute;

View File

@ -11,7 +11,7 @@
<span class="author">{{#if author.name}}{{author.name}}{{else}}{{author.email}}{{/if}}</span>
</small>
<section class="post-controls">
{{#link-to "editor" this class="post-edit" title="Edit Post"}}
{{#link-to "editor.edit" this class="post-edit" title="Edit Post"}}
<span class="hidden">Edit Post</span>
{{/link-to}}
{{#gh-popover-button popoverName="post-settings-menu" tagName="a" classNames="post-settings" title="Post Settings"}}

View File

@ -5,7 +5,7 @@
<nav id="global-nav" role="navigation">
<ul id="main-menu" >
{{gh-activating-list-item route="posts" title="Content" classNames="content"}}
{{gh-activating-list-item route="new" title="New post" classNames="editor"}}
{{gh-activating-list-item route="editor.new" title="New post" classNames="editor"}}
{{gh-activating-list-item route="settings" title="Settings" classNames="settings"}}
<li id="usermenu" class="usermenu subnav">

View File

@ -4,7 +4,7 @@
<section class="content-filter">
<small>All Posts</small>
</section>
{{#link-to "new" class="button button-add" title="New Post"}}<span class="hidden">New Post</span>{{/link-to}}
{{#link-to "editor.new" class="button button-add" title="New Post"}}<span class="hidden">New Post</span>{{/link-to}}
</header>
{{#view "content-list-content-view" tagName="section"}}
<ol class="posts-list">

View File

@ -14,7 +14,7 @@
<div class="no-posts-box">
<div class="no-posts">
<h3>You Haven't Written Any Posts Yet!</h3>
{{#link-to "new"}}<button class="button-add large" title="New Post">Write a new Post</button>{{/link-to}}
{{#link-to "editor.new"}}<button class="button-add large" title="New Post">Write a new Post</button>{{/link-to}}
</div>
</div>

View File

@ -1,8 +1,8 @@
var NewView = Ember.View.extend({
var EditorNewView = Ember.View.extend({
tagName: 'section',
templateName: 'editor',
templateName: 'editor/edit',
classNames: ['entry-container'],
scrollPosition: 0 // percentage of scroll position
});
export default NewView;
export default EditorNewView;