From 1f87c59055a1c820389d0a419d02f3da7f7a27e3 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 1 Jul 2020 18:30:00 +0100 Subject: [PATCH] Refactored no issue - moved `primaryTag` CP into the post model as per `primaryAuthor` - removed all unnecessary or unused CPs in the component's backing class - switched to using `@post` for direct argument access rather than `this.post` --- .../app/components/gh-posts-list-item.hbs | 34 ++++++++-------- .../app/components/gh-posts-list-item.js | 39 ------------------- ghost/admin/app/models/post.js | 1 + 3 files changed, 18 insertions(+), 56 deletions(-) diff --git a/ghost/admin/app/components/gh-posts-list-item.hbs b/ghost/admin/app/components/gh-posts-list-item.hbs index 10589d6d17..168a11b75f 100644 --- a/ghost/admin/app/components/gh-posts-list-item.hbs +++ b/ghost/admin/app/components/gh-posts-list-item.hbs @@ -1,56 +1,56 @@ - - {{#if this.isFeatured}} + + {{#if @post.isFeatured}} {{svg-jar "star-filled" class="fill-blue w3 h3"}} {{/if}} - +

- {{this.post.title}} + {{@post.title}}

- +
- {{#if this.isScheduled}} + {{#if @post.isScheduled}} Scheduled {{/if}} - {{#if this.isDraft}} + {{#if @post.isDraft}} Draft {{/if}} - {{#if (and this.isPublished (not this.post.page))}} + {{#if @post.isPublished}} Published {{/if}} {{#if this.session.user.isOwnerOrAdmin}} - {{#if (or this.post.email (and this.post.isScheduled this.post.sendEmailWhenPublished))}} - {{#if (eq this.post.email.status "failed")}} + {{#if (or @post.email (and @post.isScheduled @post.sendEmailWhenPublished))}} + {{#if (eq @post.email.status "failed")}} {{svg-jar "send-email" class="stroke-red"}} {{else}} - {{#if this.isScheduled}} + {{#if @post.isScheduled}} {{svg-jar "send-email" class="stroke-green-d2"}} @@ -65,6 +65,6 @@
- - {{gh-format-post-time this.post.updatedAtUTC draft=true}} + + {{gh-format-post-time @post.updatedAtUTC draft=true}} \ No newline at end of file diff --git a/ghost/admin/app/components/gh-posts-list-item.js b/ghost/admin/app/components/gh-posts-list-item.js index 81ef2a56ad..144ff06509 100644 --- a/ghost/admin/app/components/gh-posts-list-item.js +++ b/ghost/admin/app/components/gh-posts-list-item.js @@ -1,55 +1,16 @@ import Component from '@ember/component'; -import {alias, equal} from '@ember/object/computed'; import {computed} from '@ember/object'; -import {isBlank} from '@ember/utils'; import {inject as service} from '@ember/service'; export default Component.extend({ - ghostPaths: service(), session: service(), tagName: 'li', classNames: ['gh-list-row', 'gh-posts-list-item'], - post: null, - - isFeatured: alias('post.featured'), - isPage: alias('post.page'), - isDraft: equal('post.status', 'draft'), - isPublished: equal('post.status', 'published'), - isScheduled: equal('post.status', 'scheduled'), - authorNames: computed('post.authors.[]', function () { let authors = this.get('post.authors'); return authors.map(author => author.get('name') || author.get('email')).join(', '); - }), - - primaryTag: computed('post.authors.[]', function () { - let primaryTag = this.get('post.tags.firstObject'); - - if (primaryTag) { - return primaryTag.get('name'); - } else { - return false; - } - }), - - subText: computed('post.{excerpt,customExcerpt,metaDescription}', function () { - let text = this.get('post.excerpt') || ''; - let customExcerpt = this.get('post.customExcerpt'); - let metaDescription = this.get('post.metaDescription'); - - if (!isBlank(customExcerpt)) { - text = customExcerpt; - } else if (!isBlank(metaDescription)) { - text = metaDescription; - } - - if (this.isScheduled) { - return `${text.slice(0, 35)}...`; - } else { - return `${text.slice(0, 80)}...`; - } }) }); diff --git a/ghost/admin/app/models/post.js b/ghost/admin/app/models/post.js index 781fa98ada..55d0ab3e27 100644 --- a/ghost/admin/app/models/post.js +++ b/ghost/admin/app/models/post.js @@ -115,6 +115,7 @@ export default Model.extend(Comparable, ValidationEngine, { tags: hasMany('tag', {embedded: 'always', async: false}), primaryAuthor: reads('authors.firstObject'), + primaryTag: reads('tags.firstObject'), scratch: null, titleScratch: null,