Refactored <GhPostsListItem>

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`
This commit is contained in:
Kevin Ansfield 2020-07-01 18:30:00 +01:00
parent a8a8487bd6
commit 1f87c59055
3 changed files with 18 additions and 56 deletions

View File

@ -1,56 +1,56 @@
<LinkTo @route="editor.edit" @models={{array this.post.displayName this.post.id}} class="permalink gh-list-data gh-post-list-featured" @title="Edit this post"> <LinkTo @route="editor.edit" @models={{array @post.displayName @post.id}} class="permalink gh-list-data gh-post-list-featured" @title="Edit this post">
{{#if this.isFeatured}} {{#if @post.isFeatured}}
<span data-tooltip="Featured" class="dib pl1 pr1 nr1 nl1">{{svg-jar "star-filled" class="fill-blue w3 h3"}}</span> <span data-tooltip="Featured" class="dib pl1 pr1 nr1 nl1">{{svg-jar "star-filled" class="fill-blue w3 h3"}}</span>
{{/if}} {{/if}}
</LinkTo> </LinkTo>
<LinkTo @route="editor.edit" @models={{array this.post.displayName this.post.id}} class="permalink gh-list-data gh-post-list-title" @title="Edit this post"> <LinkTo @route="editor.edit" @models={{array @post.displayName @post.id}} class="permalink gh-list-data gh-post-list-title" @title="Edit this post">
<h3 class="gh-content-entry-title"> <h3 class="gh-content-entry-title">
{{this.post.title}} {{@post.title}}
</h3> </h3>
<p> <p>
<span class="gh-content-entry-meta"> <span class="gh-content-entry-meta">
By <span class="midgrey-l2 fw5">{{this.authorNames}}</span> By <span class="midgrey-l2 fw5">{{this.authorNames}}</span>
{{#if this.primaryTag}} {{#if @post.primaryTag}}
in <span class="midgrey-l2 fw5">{{this.primaryTag}}</span> in <span class="midgrey-l2 fw5">{{@post.primaryTag.name}}</span>
{{/if}} {{/if}}
{{#if this.isScheduled}} {{#if @post.isScheduled}}
<span class="gh-schedule-time">Scheduled to be published and sent {{gh-format-post-time this.post.publishedAtUTC scheduled=true}}</span> <span class="gh-schedule-time">Will be published and sent {{gh-format-post-time @post.publishedAtUTC scheduled=true}}</span>
{{/if}} {{/if}}
</span> </span>
</p> </p>
</LinkTo> </LinkTo>
<LinkTo @route="editor.edit" @models={{array this.post.displayName this.post.id}} class="permalink gh-list-data gh-post-list-status" @title="Edit this post"> <LinkTo @route="editor.edit" @models={{array @post.displayName @post.id}} class="permalink gh-list-data gh-post-list-status" @title="Edit this post">
<div class="flex items-center"> <div class="flex items-center">
{{#if this.isScheduled}} {{#if @post.isScheduled}}
<span class="gh-content-status-draft gh-badge nowrap"> <span class="gh-content-status-draft gh-badge nowrap">
Scheduled Scheduled
</span> </span>
{{/if}} {{/if}}
{{#if this.isDraft}} {{#if @post.isDraft}}
<span class="gh-content-status-draft gh-badge gh-badge-purple nowrap"> <span class="gh-content-status-draft gh-badge gh-badge-purple nowrap">
Draft Draft
</span> </span>
{{/if}} {{/if}}
{{#if (and this.isPublished (not this.post.page))}} {{#if @post.isPublished}}
<span class="gh-content-status-published nowrap" title="Post has been sent by email"> <span class="gh-content-status-published nowrap" title="Post has been sent by email">
Published Published
</span> </span>
{{/if}} {{/if}}
{{#if this.session.user.isOwnerOrAdmin}} {{#if this.session.user.isOwnerOrAdmin}}
{{#if (or this.post.email (and this.post.isScheduled this.post.sendEmailWhenPublished))}} {{#if (or @post.email (and @post.isScheduled @post.sendEmailWhenPublished))}}
{{#if (eq this.post.email.status "failed")}} {{#if (eq @post.email.status "failed")}}
<span data-tooltip="Failed to send post by email" class="gh-content-status-emailed error"> <span data-tooltip="Failed to send post by email" class="gh-content-status-emailed error">
{{svg-jar "send-email" class="stroke-red"}} {{svg-jar "send-email" class="stroke-red"}}
</span> </span>
{{else}} {{else}}
{{#if this.isScheduled}} {{#if @post.isScheduled}}
<span data-tooltip="To be sent by email" class="gh-content-status-emailed scheduled"> <span data-tooltip="To be sent by email" class="gh-content-status-emailed scheduled">
{{svg-jar "send-email" class="stroke-green-d2"}} {{svg-jar "send-email" class="stroke-green-d2"}}
</span> </span>
@ -65,6 +65,6 @@
</div> </div>
</LinkTo> </LinkTo>
<LinkTo @route="editor.edit" @models={{array this.post.displayName this.post.id}} class="permalink gh-list-data gh-post-list-updated" @title="Edit this post"> <LinkTo @route="editor.edit" @models={{array @post.displayName @post.id}} class="permalink gh-list-data gh-post-list-updated" @title="Edit this post">
<span class="nowrap">{{gh-format-post-time this.post.updatedAtUTC draft=true}}</span> <span class="nowrap">{{gh-format-post-time @post.updatedAtUTC draft=true}}</span>
</LinkTo> </LinkTo>

View File

@ -1,55 +1,16 @@
import Component from '@ember/component'; import Component from '@ember/component';
import {alias, equal} from '@ember/object/computed';
import {computed} from '@ember/object'; import {computed} from '@ember/object';
import {isBlank} from '@ember/utils';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
export default Component.extend({ export default Component.extend({
ghostPaths: service(),
session: service(), session: service(),
tagName: 'li', tagName: 'li',
classNames: ['gh-list-row', 'gh-posts-list-item'], 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 () { authorNames: computed('post.authors.[]', function () {
let authors = this.get('post.authors'); let authors = this.get('post.authors');
return authors.map(author => author.get('name') || author.get('email')).join(', '); 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)}...`;
}
}) })
}); });

View File

@ -115,6 +115,7 @@ export default Model.extend(Comparable, ValidationEngine, {
tags: hasMany('tag', {embedded: 'always', async: false}), tags: hasMany('tag', {embedded: 'always', async: false}),
primaryAuthor: reads('authors.firstObject'), primaryAuthor: reads('authors.firstObject'),
primaryTag: reads('tags.firstObject'),
scratch: null, scratch: null,
titleScratch: null, titleScratch: null,