From aa54821e64164a1788890fd906c236b78543f956 Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Mon, 9 Jun 2014 22:44:29 -0600 Subject: [PATCH] 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. --- core/client/controllers/editor.js | 5 ----- core/client/controllers/editor/edit.js | 5 +++++ core/client/controllers/editor/new.js | 5 +++++ core/client/controllers/new.js | 5 ----- core/client/router.js | 6 ++++-- core/client/routes/{editor.js => editor/edit.js} | 11 +++++++---- core/client/routes/editor/index.js | 7 +++++++ core/client/routes/{ => editor}/new.js | 4 ++-- core/client/templates/-floating-header.hbs | 2 +- core/client/templates/-navbar.hbs | 2 +- core/client/templates/{editor.hbs => editor/edit.hbs} | 0 core/client/templates/posts.hbs | 2 +- core/client/templates/posts/post.hbs | 2 +- core/client/views/{editor.js => editor/edit.js} | 0 core/client/views/{ => editor}/new.js | 6 +++--- 15 files changed, 37 insertions(+), 25 deletions(-) delete mode 100644 core/client/controllers/editor.js create mode 100644 core/client/controllers/editor/edit.js create mode 100644 core/client/controllers/editor/new.js delete mode 100644 core/client/controllers/new.js rename core/client/routes/{editor.js => editor/edit.js} (73%) create mode 100644 core/client/routes/editor/index.js rename core/client/routes/{ => editor}/new.js (74%) rename core/client/templates/{editor.hbs => editor/edit.hbs} (100%) rename core/client/views/{editor.js => editor/edit.js} (100%) rename core/client/views/{ => editor}/new.js (54%) diff --git a/core/client/controllers/editor.js b/core/client/controllers/editor.js deleted file mode 100644 index 9d952ae634..0000000000 --- a/core/client/controllers/editor.js +++ /dev/null @@ -1,5 +0,0 @@ -import EditorControllerMixin from 'ghost/mixins/editor-base-controller'; - -var EditorController = Ember.ObjectController.extend(EditorControllerMixin); - -export default EditorController; diff --git a/core/client/controllers/editor/edit.js b/core/client/controllers/editor/edit.js new file mode 100644 index 0000000000..49d36f4a03 --- /dev/null +++ b/core/client/controllers/editor/edit.js @@ -0,0 +1,5 @@ +import EditorControllerMixin from 'ghost/mixins/editor-base-controller'; + +var EditorEditController = Ember.ObjectController.extend(EditorControllerMixin); + +export default EditorEditController; diff --git a/core/client/controllers/editor/new.js b/core/client/controllers/editor/new.js new file mode 100644 index 0000000000..0c5d6a07ca --- /dev/null +++ b/core/client/controllers/editor/new.js @@ -0,0 +1,5 @@ +import EditorControllerMixin from 'ghost/mixins/editor-base-controller'; + +var EditorNewController = Ember.ObjectController.extend(EditorControllerMixin); + +export default EditorNewController; diff --git a/core/client/controllers/new.js b/core/client/controllers/new.js deleted file mode 100644 index 9d952ae634..0000000000 --- a/core/client/controllers/new.js +++ /dev/null @@ -1,5 +0,0 @@ -import EditorControllerMixin from 'ghost/mixins/editor-base-controller'; - -var EditorController = Ember.ObjectController.extend(EditorControllerMixin); - -export default EditorController; diff --git a/core/client/router.js b/core/client/router.js index 6df1c926de..b1fae37578 100644 --- a/core/client/router.js +++ b/core/client/router.js @@ -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'); diff --git a/core/client/routes/editor.js b/core/client/routes/editor/edit.js similarity index 73% rename from core/client/routes/editor.js rename to core/client/routes/editor/edit.js index 9fec599d82..86d5a0ad5b 100644 --- a/core/client/routes/editor.js +++ b/core/client/routes/editor/edit.js @@ -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; diff --git a/core/client/routes/editor/index.js b/core/client/routes/editor/index.js new file mode 100644 index 0000000000..20f0e766f2 --- /dev/null +++ b/core/client/routes/editor/index.js @@ -0,0 +1,7 @@ +var EditorRoute = Ember.Route.extend({ + beforeModel: function () { + this.transitionTo('editor.new'); + } +}); + +export default EditorRoute; diff --git a/core/client/routes/new.js b/core/client/routes/editor/new.js similarity index 74% rename from core/client/routes/new.js rename to core/client/routes/editor/new.js index 04bba4e6aa..921bf4ddf5 100644 --- a/core/client/routes/new.js +++ b/core/client/routes/editor/new.js @@ -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; diff --git a/core/client/templates/-floating-header.hbs b/core/client/templates/-floating-header.hbs index 3198096f58..9b558be23d 100644 --- a/core/client/templates/-floating-header.hbs +++ b/core/client/templates/-floating-header.hbs @@ -11,7 +11,7 @@ {{#if author.name}}{{author.name}}{{else}}{{author.email}}{{/if}}
- {{#link-to "editor" this class="post-edit" title="Edit Post"}} + {{#link-to "editor.edit" this class="post-edit" title="Edit Post"}} {{/link-to}} {{#gh-popover-button popoverName="post-settings-menu" tagName="a" classNames="post-settings" title="Post Settings"}} diff --git a/core/client/templates/-navbar.hbs b/core/client/templates/-navbar.hbs index b296926537..cf71a6e008 100644 --- a/core/client/templates/-navbar.hbs +++ b/core/client/templates/-navbar.hbs @@ -5,7 +5,7 @@