Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make topic lists show last activity more intuitively #193

Merged
merged 1 commit into from
Mar 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/assets/javascripts/discourse/models/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ Discourse.Topic = Discourse.Model.extend({
return this.get('archetype') === 'private_message';
}).property('archetype'),

// Does this topic only have a single post?
singlePost: (function() {
return this.get('posts_count') === 1;
}).property('posts_count'),

toggleStatus: function(property) {
this.toggleProperty(property);
return $.post("" + (this.get('url')) + "/status", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@

<td class='num'>{{number views numberKey="views_long"}}</td>

{{#if singlePost}}
<td class='num activity'>
<a href="{{url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{{age}}}</a>
</td>
<td></td>
{{else}}
{{#if bumped}}
<td class='num activity'>
<a href="{{url}}" {{{bindAttr class=":age ageCold"}}} title='{{i18n first_post}}: {{{unboundDate created_at}}}' >{{{age}}}</a>
</td>
<td class='num activity last'>
<a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate last_posted_at}}}'>{{{last_post_age}}}</a>
<a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate bumped_at}}}'>{{{bumped_age}}}</a>
</td>
{{else}}
<td class='num activity'>
<a href="{{url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{{age}}}</a>
</td>
<td></td>
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@

<td class='num'>{{number views numberKey="views_long"}}</td>

{{#if singlePost}}
<td class='num activity'>
<a href="{{url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{{age}}}</a>
</td>
<td></td>
{{else}}
{{#if bumped}}
<td class='num activity'>
<a href="{{url}}" {{{bindAttr class=":age ageCold"}}} title='{{i18n first_post}}: {{{unboundDate created_at}}}' >{{{age}}}</a>
</td>
<td class='num activity last'>
<a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate last_posted_at}}}'>{{{last_post_age}}}</a>
<a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate bumped_at}}}'>{{{bumped_age}}}</a>
</td>
{{else}}
<td class='num activity'>
<a href="{{url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{{age}}}</a>
</td>
<td></td>
{{/if}}

{{/group}}
Expand Down
13 changes: 13 additions & 0 deletions app/serializers/listable_topic_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class ListableTopicSerializer < BasicTopicSerializer
:image_url,
:created_at,
:last_posted_at,
:bumped,
:bumped_at,
:bumped_age,
:age,
:unseen,
:last_read_post_number,
Expand All @@ -18,6 +21,16 @@ class ListableTopicSerializer < BasicTopicSerializer
def age
AgeWords.age_words(Time.now - (object.created_at || Time.now))
end

def bumped
object.created_at < object.bumped_at
end

def bumped_age
return nil if object.bumped_at.blank?
AgeWords.age_words(Time.now - object.bumped_at)
end
alias include_bumped_age? :bumped

def seen
object.user_data.present?
Expand Down
7 changes: 1 addition & 6 deletions app/serializers/suggested_topic_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
class SuggestedTopicSerializer < ListableTopicSerializer

attributes :archetype, :like_count, :views, :last_post_age
attributes :archetype, :like_count, :views
has_one :category, embed: :objects

def last_post_age
return nil if object.last_posted_at.blank?
AgeWords.age_words(Time.now - object.last_posted_at)
end

end
6 changes: 0 additions & 6 deletions app/serializers/topic_list_item_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ class TopicListItemSerializer < ListableTopicSerializer
:pinned,
:closed,
:archived,
:last_post_age,
:starred,
:has_best_of,
:archetype

has_one :category
has_many :posters, serializer: TopicPosterSerializer, embed: :objects

def last_post_age
return nil if object.last_posted_at.blank?
AgeWords.age_words(Time.now - object.last_posted_at)
end

def starred
object.user_data.starred?
end
Expand Down