From d036d461dc3ed864f21058d498175522f7ce8ea2 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 6 Jan 2015 07:43:05 +1100 Subject: [PATCH] FEATURE: only expand globally pinned topics on front page --- .../routes/build-category-route.js.es6 | 1 + .../discourse/routes/build-topic-route.js.es6 | 1 + .../discourse/templates/discovery/topics.hbs | 2 ++ .../templates/list/topic_list_item.raw.hbs | 4 +++- .../discourse/views/topic-list-item.js.es6 | 17 +++++++++++++++++ app/serializers/topic_list_item_serializer.rb | 3 ++- 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 index 2c3a79dc6..2cbef30cf 100644 --- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 @@ -82,6 +82,7 @@ export default function(filter, params) { noSubcategories: params && !!params.no_subcategories, order: topics.get('params.order'), ascending: topics.get('params.ascending'), + expandAllPinned: true }); this.controllerFor('search').set('searchContext', model.get('searchContext')); diff --git a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 index 9b7c7c37c..d8cb0e02c 100644 --- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 @@ -53,6 +53,7 @@ export default function(filter, extras) { category: null, period: periods.findBy('id', periodId), selected: [], + expandGloballyPinned: true }; var params = model.get('params'); diff --git a/app/assets/javascripts/discourse/templates/discovery/topics.hbs b/app/assets/javascripts/discourse/templates/discovery/topics.hbs index 8c9c54e8e..b5417dfde 100644 --- a/app/assets/javascripts/discourse/templates/discovery/topics.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/topics.hbs @@ -47,6 +47,8 @@ ascending=ascending bulkSelectEnabled=bulkSelectEnabled selected=selected + expandGloballyPinned=expandGloballyPinned + expandAllPinned=expandAllPinned topics=topics}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/list/topic_list_item.raw.hbs b/app/assets/javascripts/discourse/templates/list/topic_list_item.raw.hbs index 83eedde3a..1b5f225a7 100644 --- a/app/assets/javascripts/discourse/templates/list/topic_list_item.raw.hbs +++ b/app/assets/javascripts/discourse/templates/list/topic_list_item.raw.hbs @@ -10,7 +10,9 @@ {{raw "topic-post-badges" unread=topic.unread newPosts=topic.displayNewPosts unseen=topic.unseen url=topic.lastUnreadUrl}} {{/if}} - {{raw "list/topic-excerpt" topic=topic}} + {{#if expandPinned}} + {{raw "list/topic-excerpt" topic=topic}} + {{/if}} {{#unless controller.hideCategory}} diff --git a/app/assets/javascripts/discourse/views/topic-list-item.js.es6 b/app/assets/javascripts/discourse/views/topic-list-item.js.es6 index 941913264..6a4391ad4 100644 --- a/app/assets/javascripts/discourse/views/topic-list-item.js.es6 +++ b/app/assets/javascripts/discourse/views/topic-list-item.js.es6 @@ -22,6 +22,23 @@ export default Discourse.View.extend(StringBuffer, { return this.get('topic.op_like_count') > 0; }, + expandPinned: function(){ + var pinned = this.get('topic.pinned'); + if(!pinned){ + return false; + } + + if(this.get('controller.expandGloballyPinned') && this.get('topic.pinned_globally')){ + return true; + } + + if(this.get('controller.expandAllPinned')){ + return true; + } + + return false; + }.property(), + click: function(e){ var target = $(e.target); diff --git a/app/serializers/topic_list_item_serializer.rb b/app/serializers/topic_list_item_serializer.rb index 91da032a8..97adc464f 100644 --- a/app/serializers/topic_list_item_serializer.rb +++ b/app/serializers/topic_list_item_serializer.rb @@ -7,7 +7,8 @@ class TopicListItemSerializer < ListableTopicSerializer :archetype, :last_poster_username, :category_id, - :op_like_count + :op_like_count, + :pinned_globally has_many :posters, serializer: TopicPosterSerializer, embed: :objects has_many :participants, serializer: TopicPosterSerializer, embed: :objects