0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Merge pull request #2933 from novaugust/editor-resource-routing

Refactored Editor Routes
This commit is contained in:
Hannah Wolfe 2014-06-11 23:07:59 +02:00
commit 26d62fe775
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.resource('posts', { path: '/' }, function () {
this.route('post', { path: ':post_id' }); this.route('post', { path: ':post_id' });
}); });
this.resource('editor', { path: '/editor/:post_id' }); this.resource('editor', function () {
this.route('new', { path: '/editor' }); this.route('new', { path: '' });
this.route('edit', { path: ':post_id' });
});
this.resource('settings', function () { this.resource('settings', function () {
this.route('general'); this.route('general');
this.route('user'); this.route('user');

View file

@ -1,14 +1,13 @@
import styleBody from 'ghost/mixins/style-body'; import styleBody from 'ghost/mixins/style-body';
import AuthenticatedRoute from 'ghost/routes/authenticated'; import AuthenticatedRoute from 'ghost/routes/authenticated';
var EditorRoute = AuthenticatedRoute.extend(styleBody, { var EditorEditRoute = AuthenticatedRoute.extend(styleBody, {
classNames: ['editor'], classNames: ['editor'],
model: function (params) { model: function (params) {
var self = this, var self = this,
post, post,
postId; postId;
postId = Number(params.post_id); postId = Number(params.post_id);
if (!Number.isInteger(postId) || !Number.isFinite(postId) || postId <= 0) { 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 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) { }).then(function (records) {
var post = records.get('firstObject'); var post = records.get('firstObject');
@ -32,7 +32,10 @@ var EditorRoute = AuthenticatedRoute.extend(styleBody, {
return self.transitionTo('posts.index'); return self.transitionTo('posts.index');
}); });
},
serialize: function (model) {
return {post_id: model.get('id')};
} }
}); });
export default EditorRoute; export default EditorEditRoute;

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 AuthenticatedRoute from 'ghost/routes/authenticated';
import styleBody from 'ghost/mixins/style-body'; import styleBody from 'ghost/mixins/style-body';
var NewRoute = AuthenticatedRoute.extend(styleBody, { var EditorNewRoute = AuthenticatedRoute.extend(styleBody, {
classNames: ['editor'], classNames: ['editor'],
model: function () { 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> <span class="author">{{#if author.name}}{{author.name}}{{else}}{{author.email}}{{/if}}</span>
</small> </small>
<section class="post-controls"> <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> <span class="hidden">Edit Post</span>
{{/link-to}} {{/link-to}}
{{#gh-popover-button popoverName="post-settings-menu" tagName="a" classNames="post-settings" title="Post Settings"}} {{#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"> <nav id="global-nav" role="navigation">
<ul id="main-menu" > <ul id="main-menu" >
{{gh-activating-list-item route="posts" title="Content" classNames="content"}} {{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"}} {{gh-activating-list-item route="settings" title="Settings" classNames="settings"}}
<li id="usermenu" class="usermenu subnav"> <li id="usermenu" class="usermenu subnav">

View file

@ -4,7 +4,7 @@
<section class="content-filter"> <section class="content-filter">
<small>All Posts</small> <small>All Posts</small>
</section> </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> </header>
{{#view "content-list-content-view" tagName="section"}} {{#view "content-list-content-view" tagName="section"}}
<ol class="posts-list"> <ol class="posts-list">

View file

@ -14,7 +14,7 @@
<div class="no-posts-box"> <div class="no-posts-box">
<div class="no-posts"> <div class="no-posts">
<h3>You Haven't Written Any Posts Yet!</h3> <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>
</div> </div>

View file

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