From 0f8610a6e92629a1b2576b0d31909f409f90a89f Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 15 Jan 2020 15:15:20 +0000 Subject: [PATCH] Extracted duplicated posts/pages filter into a component no issue - posts and pages (and their corresponding `-loading` counterparts) templates were all duplicating a lengthy section of handlebars - extracted the duplicated handlebars into a template for easier design changes or upgrading of `ember-power-select` - moved generation of the "selected" CSS classes into the template to clean up code in the controller --- .../admin/app/components/gh-contentfilter.js | 6 ++ ghost/admin/app/controllers/pages.js | 12 --- ghost/admin/app/controllers/posts.js | 25 ------ .../templates/components/gh-contentfilter.hbs | 74 ++++++++++++++++ ghost/admin/app/templates/pages-loading.hbs | 88 +++---------------- ghost/admin/app/templates/pages.hbs | 88 +++---------------- ghost/admin/app/templates/posts-loading.hbs | 88 +++---------------- ghost/admin/app/templates/posts.hbs | 88 +++---------------- 8 files changed, 136 insertions(+), 333 deletions(-) create mode 100644 ghost/admin/app/components/gh-contentfilter.js create mode 100644 ghost/admin/app/templates/components/gh-contentfilter.hbs diff --git a/ghost/admin/app/components/gh-contentfilter.js b/ghost/admin/app/components/gh-contentfilter.js new file mode 100644 index 0000000000..5c596ef0a3 --- /dev/null +++ b/ghost/admin/app/components/gh-contentfilter.js @@ -0,0 +1,6 @@ +import Component from '@glimmer/component'; +import {inject as service} from '@ember/service'; + +export default class GhContentfilterComponent extends Component { + @service session +} diff --git a/ghost/admin/app/controllers/pages.js b/ghost/admin/app/controllers/pages.js index c4f5abc8fb..043b653096 100644 --- a/ghost/admin/app/controllers/pages.js +++ b/ghost/admin/app/controllers/pages.js @@ -17,23 +17,11 @@ const TYPES = [{ value: 'featured' }]; -const ORDERS = [{ - name: 'Newest', - value: null -}, { - name: 'Oldest', - value: 'published_at asc' -}, { - name: 'Recently updated', - value: 'updated_at desc' -}]; - /* eslint-disable ghost/ember/alias-model-in-controller */ export default PostsController.extend({ init() { this._super(...arguments); this.availableTypes = TYPES; - this.availableOrders = ORDERS; }, actions: { diff --git a/ghost/admin/app/controllers/posts.js b/ghost/admin/app/controllers/posts.js index e2b0311846..4ee85ea2d7 100644 --- a/ghost/admin/app/controllers/posts.js +++ b/ghost/admin/app/controllers/posts.js @@ -34,7 +34,6 @@ const ORDERS = [{ export default Controller.extend({ - session: service(), store: service(), queryParams: ['type', 'author', 'tag', 'order'], @@ -116,30 +115,6 @@ export default Controller.extend({ return authors.findBy('slug', author); }), - typeClassNames: computed('type', function () { - let classNames = 'gh-contentfilter-menu gh-contentfilter-type'; - if (this.get('type')) { - classNames = classNames + ' gh-contentfilter-selected'; - } - return classNames; - }), - - authorClassNames: computed('author', function () { - let classNames = 'gh-contentfilter-menu gh-contentfilter-author'; - if (this.get('author')) { - classNames = classNames + ' gh-contentfilter-selected'; - } - return classNames; - }), - - tagClassNames: computed('tag', function () { - let classNames = 'gh-contentfilter-menu gh-contentfilter-tag'; - if (this.get('tag')) { - classNames = classNames + ' gh-contentfilter-selected'; - } - return classNames; - }), - actions: { changeType(type) { this.set('type', get(type, 'value')); diff --git a/ghost/admin/app/templates/components/gh-contentfilter.hbs b/ghost/admin/app/templates/components/gh-contentfilter.hbs new file mode 100644 index 0000000000..4cf0012e79 --- /dev/null +++ b/ghost/admin/app/templates/components/gh-contentfilter.hbs @@ -0,0 +1,74 @@ +
+ {{#unless this.session.user.isContributor}} + + {{type.name}} + + {{/unless}} + + {{#unless this.session.user.isAuthorOrContributor}} + + {{author.name}} + + {{/unless}} + + {{#unless this.session.user.isContributor}} + + {{tag.name}} + + {{/unless}} + + + {{order.name}} + +
\ No newline at end of file diff --git a/ghost/admin/app/templates/pages-loading.hbs b/ghost/admin/app/templates/pages-loading.hbs index b44a85a7ab..2c26199339 100644 --- a/ghost/admin/app/templates/pages-loading.hbs +++ b/ghost/admin/app/templates/pages-loading.hbs @@ -2,80 +2,20 @@

Pages

-
- {{#unless this.session.user.isContributor}} - - {{type.name}} - - {{/unless}} - - {{#unless this.session.user.isAuthorOrContributor}} - - {{author.name}} - - {{/unless}} - - {{#unless this.session.user.isContributor}} - - {{tag.name}} - - {{/unless}} - - - {{order.name}} - -
+ {{#link-to "editor.new" "page" class="gh-btn gh-btn-green" data-test-new-page-button=true}}New page{{/link-to}}
diff --git a/ghost/admin/app/templates/pages.hbs b/ghost/admin/app/templates/pages.hbs index 5ff685fc12..51d03269a0 100644 --- a/ghost/admin/app/templates/pages.hbs +++ b/ghost/admin/app/templates/pages.hbs @@ -2,80 +2,20 @@

Pages

-
- {{#unless this.session.user.isContributor}} - - {{type.name}} - - {{/unless}} - - {{#unless this.session.user.isAuthorOrContributor}} - - {{author.name}} - - {{/unless}} - - {{#unless this.session.user.isContributor}} - - {{tag.name}} - - {{/unless}} - - - {{order.name}} - -
+ {{#link-to "editor.new" "page" class="gh-btn gh-btn-green" data-test-new-page-button=true}}New page{{/link-to}}
diff --git a/ghost/admin/app/templates/posts-loading.hbs b/ghost/admin/app/templates/posts-loading.hbs index 5c772aff93..0110fec917 100644 --- a/ghost/admin/app/templates/posts-loading.hbs +++ b/ghost/admin/app/templates/posts-loading.hbs @@ -2,80 +2,20 @@

Posts

-
- {{#unless this.session.user.isContributor}} - - {{type.name}} - - {{/unless}} - - {{#unless this.session.user.isAuthorOrContributor}} - - {{author.name}} - - {{/unless}} - - {{#unless this.session.user.isContributor}} - - {{tag.name}} - - {{/unless}} - - - {{order.name}} - -
+ {{#link-to "editor.new" "post" class="gh-btn gh-btn-green" data-test-new-post-button=true}}New post{{/link-to}}
diff --git a/ghost/admin/app/templates/posts.hbs b/ghost/admin/app/templates/posts.hbs index bae7636775..c5b4b4b231 100644 --- a/ghost/admin/app/templates/posts.hbs +++ b/ghost/admin/app/templates/posts.hbs @@ -2,80 +2,20 @@

Posts

-
- {{#unless this.session.user.isContributor}} - - {{type.name}} - - {{/unless}} - - {{#unless this.session.user.isAuthorOrContributor}} - - {{author.name}} - - {{/unless}} - - {{#unless this.session.user.isContributor}} - - {{tag.name}} - - {{/unless}} - - - {{order.name}} - -
+ {{#link-to "editor.new" "post" class="gh-btn gh-btn-green" data-test-new-post-button=true}}New post{{/link-to}}