TryGhost/Ghost

View on GitHub
ghost/admin/app/components/posts-list/list-item.hbs

Summary

Maintainability
Test Coverage
{{!-- template-lint-disable no-invalid-interactive --}}
<li class="gh-list-row gh-posts-list-item gh-post-list-plain-status"
    {{on "mouseover" this.mouseOver}}
    {{on "mouseleave" this.mouseLeave}}
    ...attributes
>

    {{!-- Title column --}}
    {{#if (and this.session.user.isContributor @post.isPublished)}}
        <a href={{@post.url}} class="permalink gh-list-data gh-post-list-title" target="_blank" rel="noopener noreferrer">
            <h3 class="gh-content-entry-title">
                {{@post.title}}
            </h3>
            {{#unless @hideAuthor }}
                <p class="gh-content-entry-meta">
                    <span class="gh-content-entry-author">
                        By {{post-author-names @post}}

                        {{#if @post.primaryTag}}
                            in <span class="midgrey-l2 fw5">{{@post.primaryTag.name}}</span>
                        {{/if}}

                        -
                    </span>
                    {{#if (or @post.isDraft @post.isScheduled)}}
                        <span class="gh-content-entry-date" title="Updated {{gh-format-post-time @post.updatedAtUTC absolute=true}}">
                            {{gh-format-post-time @post.updatedAtUTC absolute=true short=true}}
                        </span>
                    {{else}}
                        <span class="gh-content-entry-date" title="Published {{gh-format-post-time @post.publishedAtUTC absolute=true}}">
                            {{gh-format-post-time @post.publishedAtUTC absolute=true short=true}}
                        </span>
                    {{/if}}
                </p>
                <p class="gh-content-entry-status" data-test-editor-post-status>
                    <span class="published">
                        Published
                        {{#if @post.hasEmail}}
                            {{#if this.isHovered}}
                                and sent to {{gh-pluralize @post.email.emailCount "member"}}
                            {{else}}
                                and sent
                            {{/if}}
                        {{/if}}
                    </span>
                </p>
            {{/unless}}
        </a>
    {{else}}
        <LinkTo @route="lexical-editor.edit" @models={{array this.post.displayName this.post.id}} class="permalink gh-list-data gh-post-list-title">
            <h3 class="gh-content-entry-title">
                {{#if @post.featured}}
                    {{svg-jar "star-fill" class="gh-featured-post"}}
                {{/if}}
                {{@post.title}}

                {{! Display lexical/mobiledoc indicators for easier testing of the feature --}}
                {{#if (feature 'lexicalIndicators')}}
                    {{#if @post.lexical}}
                        <span class="gh-lexical-indicator">L</span>
                    {{else if @post.mobiledoc}}
                        <span class="gh-lexical-indicator">M</span>
                    {{/if}}
                {{/if}}

            </h3>
            {{#unless @hideAuthor }}
                <p class="gh-content-entry-meta">
                    <span class="gh-content-entry-author">
                        By {{post-author-names @post}}

                        {{#if @post.primaryTag}}
                            in <span class="midgrey-l2 fw5">{{@post.primaryTag.name}}</span>
                        {{/if}}
                        -
                    </span>
                    {{#if (or @post.isDraft @post.isScheduled)}}
                        <span class="gh-content-entry-date" title="Updated {{gh-format-post-time @post.updatedAtUTC absolute=true}}">
                            {{gh-format-post-time @post.updatedAtUTC absolute=true short=true}}
                        </span>
                    {{else}}
                        <span class="gh-content-entry-date" title="Published {{gh-format-post-time @post.publishedAtUTC absolute=true}}">
                            {{gh-format-post-time @post.publishedAtUTC absolute=true short=true}}
                        </span>
                    {{/if}}
                    {{!-- {{#if @post.lexical}}
                        <span class="gh-content-entry-date">– Lexical</span>
                    {{/if}} --}}
                </p>
                <p class="gh-content-entry-status" data-test-editor-post-status>
                    {{#if @post.isScheduled}}
                        <span class="scheduled">
                            Scheduled
                            {{#if this.isHovered}}
                                <span class="schedule-details" {{css-transition "anim-fade-in-scale"}}>
                                    {{#if @post.emailOnly}}
                                        to be sent
                                        {{this.scheduledText}} to {{humanize-recipient-filter @post.emailSegment}}
                                    {{else}}
                                        to be published {{if @post.newsletter "and sent "}}
                                        {{this.scheduledText}}
                                        {{#if @post.newsletter}}
                                            to {{humanize-recipient-filter @post.emailSegment}}
                                        {{/if}}
                                    {{/if}}
                                </span>
                            {{/if}}
                        </span>
                    {{/if}}

                    {{#if @post.isDraft}}
                        <span class="draft">
                            Draft
                        </span>
                    {{/if}}

                    {{#if @post.isPublished}}
                        <span class="published {{this.errorClass}}">
                            Published
                            {{#if @post.didEmailFail}}
                                but failed to send newsletter
                            {{else if @post.hasBeenEmailed}}
                                and sent
                                {{#if this.isHovered}}
                                    <span {{css-transition "anim-fade-in-scale"}}>to {{gh-pluralize @post.email.emailCount "member"}}</span>
                                {{/if}}
                            {{/if}}
                        </span>
                    {{/if}}

                    {{#if @post.isSent}}
                        <span class="sent {{this.errorClass}}">
                            {{#if @post.didEmailFail}}
                                Failed to send newsletter
                            {{else}}
                                Sent
                                {{#if this.isHovered}}
                                    <span {{css-transition "anim-fade-in-scale"}}>to {{gh-pluralize @post.email.emailCount "member"}}</span>
                                {{/if}}
                            {{/if}}
                        </span>
                    {{/if}}
                </p>
            {{/unless}}
        </LinkTo>
    {{/if}}

    {{!-- Opened / Signups column --}}
    {{#if (and @post.showEmailOpenAnalytics @post.showEmailClickAnalytics) }}
        <LinkTo @route="members" @query={{hash filterParam=(concat "opened_emails.post_id:" @post.id) }} class="permalink gh-list-data gh-post-list-metrics">
            <span class="gh-content-email-stats-value">
                {{#if this.isHovered}}
                    {{format-number @post.email.openedCount}}
                {{else}}
                    {{@post.email.openRate}}<sup>%</sup>
                {{/if}}
            </span>
            <span class="gh-content-email-stats">
                opened
            </span>
        </LinkTo>
    {{else}}
        <LinkTo @route={{this.editorRoute}} @models={{array this.post.displayName this.post.id}} class="permalink gh-list-data">
            {{!-- Empty on purpose --}}
        </LinkTo>
    {{/if}}

    {{!-- Clicked / Conversions column --}}
    {{#if @post.showEmailClickAnalytics }}
        <LinkTo @route="members" @query={{hash filterParam=(concat "clicked_links.post_id:" @post.id) }} class="permalink gh-list-data gh-post-list-metrics">
            <span class="gh-content-email-stats-value">
                {{#if this.isHovered}}
                    {{format-number @post.count.clicks}}
                {{else}}
                    {{@post.clickRate}}<sup>%</sup>
                {{/if}}
            </span>
            <span class="gh-content-email-stats">
                clicked
            </span>
        </LinkTo>
    {{else}}
        {{#if @post.showEmailOpenAnalytics }}
            <LinkTo @route="members" @query={{hash filterParam=(concat "opened_emails.post_id:" @post.id) }} class="permalink gh-list-data gh-post-list-metrics">
                <span class="gh-content-email-stats-value">
                    {{#if this.isHovered}}
                        {{format-number @post.email.openedCount}}
                    {{else}}
                        {{@post.email.openRate}}<sup>%</sup>
                    {{/if}}
                </span>
                <span class="gh-content-email-stats">
                    opened
                </span>
            </LinkTo>
        {{else}}
            <LinkTo @route={{this.editorRoute}} @models={{array this.post.displayName this.post.id}} class="permalink gh-list-data">
                {{!-- Empty on purpose --}}
            </LinkTo>
        {{/if}}
    {{/if}}

    {{!-- Button column --}}
    {{#if @post.hasAnalyticsPage }}
        <LinkTo @route="posts.analytics" @model={{@post.id}} class="permalink gh-list-data gh-post-list-button" title="">
            <span class="gh-post-list-cta stats {{if this.isHovered "is-hovered"}}" title="Go to Analytics" data-ignore-select>
                {{svg-jar "stats" title="Go to Analytics"}}
            </span>
        </LinkTo>
    {{else}}
        {{#if (and this.session.user.isContributor @post.isPublished)}}
            <a href={{@post.url}} class="permalink gh-list-data gh-post-list-button" target="_blank" rel="noopener noreferrer">
                <span class="gh-post-list-cta view {{if this.isHovered "is-hovered"}}" title="View post" data-ignore-select>
                    {{svg-jar "arrow-top-right" title="View post"}}
                </span>
            </a>
        {{else}}
            <LinkTo @route="lexical-editor.edit" @models={{array this.post.displayName this.post.id}} class="permalink gh-list-data gh-post-list-button" title="">
                <span class="gh-post-list-cta edit {{if this.isHovered "is-hovered"}}" title="Go to Editor" data-ignore-select>
                    {{svg-jar "pen" title="Go to Editor"}}
                </span>
            </LinkTo>
        {{/if}}
    {{/if}}
</li>