From ff6c7455f59956e42a7c2eb030424acf6fc0a148 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 7 Jan 2015 17:22:34 +1030 Subject: [PATCH] Rework discussion/post components --- .../discussions/{post.js => post-full.js} | 4 +- ember/app/components/ui/controls/item-list.js | 2 +- ember/app/models/discussion.js | 40 +------------------ .../discussions/discussion-listing.hbs | 2 +- .../components/discussions/post-comment.hbs | 26 ------------ .../discussions/post-content-comment.hbs | 23 +++++++++++ .../discussions/post-content-title.hbs | 4 ++ .../components/discussions/post-full.hbs | 3 ++ .../components/discussions/post-title.hbs | 4 -- .../templates/components/discussions/post.hbs | 12 ------ ember/app/templates/discussion.hbs | 18 ++++----- ember/app/templates/discussions.hbs | 2 +- .../templates/partials/discussion-header.hbs | 0 13 files changed, 45 insertions(+), 95 deletions(-) rename ember/app/components/discussions/{post.js => post-full.js} (92%) delete mode 100644 ember/app/templates/components/discussions/post-comment.hbs create mode 100644 ember/app/templates/components/discussions/post-content-comment.hbs create mode 100644 ember/app/templates/components/discussions/post-content-title.hbs create mode 100644 ember/app/templates/components/discussions/post-full.hbs delete mode 100644 ember/app/templates/components/discussions/post-title.hbs delete mode 100644 ember/app/templates/components/discussions/post.hbs delete mode 100644 ember/app/templates/partials/discussion-header.hbs diff --git a/ember/app/components/discussions/post.js b/ember/app/components/discussions/post-full.js similarity index 92% rename from ember/app/components/discussions/post.js rename to ember/app/components/discussions/post-full.js index 5e1bf63ad..a42a018d4 100644 --- a/ember/app/components/discussions/post.js +++ b/ember/app/components/discussions/post-full.js @@ -5,12 +5,12 @@ import ActionButton from '../ui/controls/action-button'; export default Ember.Component.extend({ tagName: 'article', - templateName: 'components/discussions/post', + layoutName: 'components/discussions/post-full', // controls: null, contentComponent: function() { - return 'discussions/post-'+this.get('post.type'); + return 'discussions/post-content-'+this.get('post.type'); }.property('post.type'), classNames: ['post'], diff --git a/ember/app/components/ui/controls/item-list.js b/ember/app/components/ui/controls/item-list.js index 72899f14e..99dd5f714 100644 --- a/ember/app/components/ui/controls/item-list.js +++ b/ember/app/components/ui/controls/item-list.js @@ -7,7 +7,7 @@ export default Ember.Component.extend({ layoutName: 'components/ui/controls/item-list', listItems: function() { - if (!this.get('items')) return []; + if (!Ember.isArray(this.get('items'))) return []; var listItems = []; this.get('items').forEach(function(item) { if (item.tagName != 'li') { diff --git a/ember/app/models/discussion.js b/ember/app/models/discussion.js index fb9fdd6d6..cff307ef8 100644 --- a/ember/app/models/discussion.js +++ b/ember/app/models/discussion.js @@ -34,48 +34,12 @@ var Discussion = DS.Model.extend({ return this.get('posts').split(','); }.property('posts'), + readTime: DS.attr('date'), readNumber: DS.attr('number'), unreadCount: function() { return this.get('lastPostNumber') - this.get('readNumber'); }.property('lastPostNumber', 'readNumber'), - - //-------------------------------- - // Prototype generated properties - - // category: function() { - // var categories = [null, 'Announcements', 'General', 'Support', 'Feedback', 'Core', 'Plugins', 'Themes']; - // return categories[Math.floor(Math.random() * categories.length)]; - // }.property(), - category: DS.attr('string'), - - _recent: function() { - var cutoff = new Date('September 19, 2014'); - return this.get('lastTime') > cutoff; - }.property('lastTime'), - - unread: function() { - return Math.round(Math.random() * (this.get('_recent') ? 0.8 : 0) * this.get('postsCount')); - }.property(), - - // sticky: function() { - // return Math.random() > (this.get('_recent') ? 0.95 : 0.99); - // }.property(), - sticky: DS.attr('boolean'), - - excerpt: function() { - // return 'I want to get your thoughts on this one TV Addicts: what new show have you been getting into this year, and why?'; - // return 'Here\'s the near-final game list, in no particular order. The list may be subject to amendments, as we\'re still chasing up copies of some games.'; - // return 'Nominating for the Annual General Meeting is easy. Read this to find out how.' - return 'There are many apps made with Ninetech in the Mac App Store. If you\'d like, take a moment to share your Nintech-made apps in this thread.'; - }.property(), - - locked: function() { - return Math.random() > 0.95; - }.property(), - - following: function() { - return Math.random() > 0.95; - }.property() + isUnread: Ember.computed.bool('unreadCount') }); export default Discussion; diff --git a/ember/app/templates/components/discussions/discussion-listing.hbs b/ember/app/templates/components/discussions/discussion-listing.hbs index 096e67475..967931c0c 100644 --- a/ember/app/templates/components/discussions/discussion-listing.hbs +++ b/ember/app/templates/components/discussions/discussion-listing.hbs @@ -26,7 +26,7 @@ {{/link-to}}
- {{#if discussion.unread}} + {{#if discussion.isUnread}} {{abbreviate-number discussion.unreadCount}} unread {{else}} {{abbreviate-number discussion.repliesCount}} replies diff --git a/ember/app/templates/components/discussions/post-comment.hbs b/ember/app/templates/components/discussions/post-comment.hbs deleted file mode 100644 index 8af1bacd7..000000000 --- a/ember/app/templates/components/discussions/post-comment.hbs +++ /dev/null @@ -1,26 +0,0 @@ -{{#if post.deleteTime}} - -{{/if}} - -
-

- {{#link-to "user" post.user}}{{user-avatar post.user}} {{post.user.username}}{{/link-to}} -

-
- -
- {{{post.contentHtml}}} -
- - diff --git a/ember/app/templates/components/discussions/post-content-comment.hbs b/ember/app/templates/components/discussions/post-content-comment.hbs new file mode 100644 index 000000000..cbfef68a6 --- /dev/null +++ b/ember/app/templates/components/discussions/post-content-comment.hbs @@ -0,0 +1,23 @@ +{{#if post.deleteTime}} + {{fa-icon "trash-o" class="post-icon"}} +{{/if}} + +
+

+ {{#link-to "user" post.user}}{{user-avatar post.user}} {{post.user.username}}{{/link-to}} +

+ {{#link-to "discussion" post.discussion (query-params start=post.number) class="time"}} + {{abbreviate-time post.time}} + {{/link-to}} + {{#if post.editTime}} + {{fa-icon "pencil"}} + {{/if}} +
+ +
+ {{{post.contentHtml}}} +
+ + diff --git a/ember/app/templates/components/discussions/post-content-title.hbs b/ember/app/templates/components/discussions/post-content-title.hbs new file mode 100644 index 000000000..b74045598 --- /dev/null +++ b/ember/app/templates/components/discussions/post-content-title.hbs @@ -0,0 +1,4 @@ +
+ {{fa-icon "pencil" class="post-icon"}} + {{#link-to "user" post.user}}{{post.user.username}}{{/link-to}} changed the title from {{post.oldTitle}} to {{post.newTitle}}. +
diff --git a/ember/app/templates/components/discussions/post-full.hbs b/ember/app/templates/components/discussions/post-full.hbs new file mode 100644 index 000000000..fc7df099f --- /dev/null +++ b/ember/app/templates/components/discussions/post-full.hbs @@ -0,0 +1,3 @@ +{{ui/controls/dropdown-button items=controls}} + +{{dynamic-component type=contentComponent post=post}} diff --git a/ember/app/templates/components/discussions/post-title.hbs b/ember/app/templates/components/discussions/post-title.hbs deleted file mode 100644 index f87bdd2f7..000000000 --- a/ember/app/templates/components/discussions/post-title.hbs +++ /dev/null @@ -1,4 +0,0 @@ -
- - {{#link-to "user" post.user}}{{post.user.username}}{{/link-to}} named the discussion: {{post.content}}. -
diff --git a/ember/app/templates/components/discussions/post.hbs b/ember/app/templates/components/discussions/post.hbs deleted file mode 100644 index 33b8bb121..000000000 --- a/ember/app/templates/components/discussions/post.hbs +++ /dev/null @@ -1,12 +0,0 @@ -{{!-- {{#if view.controls}} -
- - {{menu-list items=controls class="dropdown-menu pull-right"}} -
-{{/if}} --}} - -{{#link-to "discussion" post.discussion (query-params start=post.number) class="time"}} - {{abbreviate-time post.time}} -{{/link-to}} - -{{dynamic-component type=contentComponent post=post}} diff --git a/ember/app/templates/discussion.hbs b/ember/app/templates/discussion.hbs index 232547901..7dc434675 100644 --- a/ember/app/templates/discussion.hbs +++ b/ember/app/templates/discussion.hbs @@ -1,17 +1,15 @@ -
-{{#each item in postStream}} - - {{#discussion-item item=item}} - {{#if item.post}}{{discussion-post post=item.post}}{{/if}} - {{/discussion-item}} - -{{/each}} +
+ {{#each item in stream}} + {{#discussions/stream-item item=item loadRange="loadRange"}} + {{#if item.post}}{{discussions/post-full post=item.post}}{{/if}} + {{/discussions/stream-item}} + {{/each}}
\ No newline at end of file diff --git a/ember/app/templates/discussions.hbs b/ember/app/templates/discussions.hbs index c940cd9f5..e7346d187 100644 --- a/ember/app/templates/discussions.hbs +++ b/ember/app/templates/discussions.hbs @@ -25,7 +25,7 @@ {{else}}
    {{#each discussion in content}} - {{discussions/discussion-listing discussion=discussion}} + {{discussions/discussion-listing discussion=discussion searchQuery=searchQuery}} {{/each}}
diff --git a/ember/app/templates/partials/discussion-header.hbs b/ember/app/templates/partials/discussion-header.hbs deleted file mode 100644 index e69de29bb..000000000