diff --git a/app/assets/javascripts/discourse/components/topic-list-header.js.es6 b/app/assets/javascripts/discourse/components/topic-list-header.js.es6 deleted file mode 100644 index e8c612904..000000000 --- a/app/assets/javascripts/discourse/components/topic-list-header.js.es6 +++ /dev/null @@ -1,26 +0,0 @@ -import StringBuffer from 'discourse/mixins/string-buffer'; - -export default Ember.Component.extend(StringBuffer, { - tagName: 'tr', - - rerenderTriggers: ['order', 'ascending', 'bulkSelectEnabled'], - toggleInTitle: function(){ - return !this.get('bulkSelectEnabled') && this.get('canBulkSelect'); - }.property('bulkSelectEnabled'), - - rawTemplate: 'components/topic-list-header.raw', - - click: function(e) { - var target = $(e.target); - - if(target.parents().andSelf().hasClass('bulk-select')){ - this.sendAction('toggleBulkSelect'); - } else { - var th = target.closest('th.sortable'); - if(th.length > 0) { - this.sendAction('changeSort', th.data('sort-order')); - } - } - - }, -}); diff --git a/app/assets/javascripts/discourse/components/topic-list.js.es6 b/app/assets/javascripts/discourse/components/topic-list.js.es6 new file mode 100644 index 000000000..62a888006 --- /dev/null +++ b/app/assets/javascripts/discourse/components/topic-list.js.es6 @@ -0,0 +1,34 @@ + +export default Ember.Component.extend({ + tagName: 'table', + classNames: ['topic-list'], + + toggleInTitle: function(){ + return !this.get('bulkSelectEnabled') && this.get('canBulkSelect'); + }.property('bulkSelectEnabled'), + + sortable: function(){ + return !!this.get('changeSort'); + }.property(), + + click: function(e){ + var self = this; + var on = function(sel, callback){ + var target = $(e.target).closest(sel); + + if(target.length === 1){ + callback.apply(self, [target]); + } + }; + + on('button.bulk-select', function(){ + this.sendAction('toggleBulkSelect'); + this.rerender(); + }); + + on('th.sortable', function(e){ + this.sendAction('changeSort', e.data('sort-order')); + this.rerender(); + }); + } +}); diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index 9372e57d9..2f9c73c60 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -6,7 +6,6 @@ var controllerOpts = { bulkSelectEnabled: false, selected: [], period: null, - showPosters: true, canStar: Em.computed.alias('controllers.discovery/topics.currentUser.id'), showTopicPostBadges: Em.computed.not('controllers.discovery/topics.new'), diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 767c0fed6..bcacd8014 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -280,6 +280,14 @@ Discourse.Topic = Discourse.Model.extend({ }); }, + togglePinnedForUser: function() { + if (this.get('pinned')) { + this.clearPin(); + } else { + this.rePin(); + } + }, + /** Re-pins a topic with a cleared pin diff --git a/app/assets/javascripts/discourse/models/user.js b/app/assets/javascripts/discourse/models/user.js index 47e36a415..857b3840e 100644 --- a/app/assets/javascripts/discourse/models/user.js +++ b/app/assets/javascripts/discourse/models/user.js @@ -101,7 +101,10 @@ Discourse.User = Discourse.Model.extend({ @property path @type {String} **/ - path: Discourse.computed.url('username_lower', "/users/%@"), + path: function(){ + return Discourse.getURL('/users/' + this.get('username_lower')); + // no need to observe, requires a hard refresh to update + }.property(), /** Path to this user's administration diff --git a/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs index 81b5dc896..9fa600c9b 100644 --- a/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs @@ -1,26 +1,9 @@ {{#loading-spinner condition=loading}} {{#if topics}} - - - - - {{#unless controller.hideCategory}} - - {{/unless}} - - {{#if controller.showParticipants}} - - {{/if}} - - - - - - - {{each t in topics itemViewClass='topic-list-item'}} - - -
{{i18n 'topic.title'}}{{i18n 'category_title'}}{{i18n 'posts'}}{{i18n 'users'}}{{i18n 'views'}}{{i18n 'activity'}}
+ {{topic-list + showParticipants=showParticipants + hideCategory=hideCategory + topics=topics}} {{else}}
{{i18n 'choose_topic.none_found'}} diff --git a/app/assets/javascripts/discourse/templates/components/topic-list-header.raw.hbs b/app/assets/javascripts/discourse/templates/components/topic-list-header.raw.hbs index bd71eb43a..fd565395d 100644 --- a/app/assets/javascripts/discourse/templates/components/topic-list-header.raw.hbs +++ b/app/assets/javascripts/discourse/templates/components/topic-list-header.raw.hbs @@ -5,9 +5,14 @@ {{/if}} {{raw "components/topic-list-header-column" order='default' name='topic.title' showBulkToggle=toggleInTitle}} {{#unless hideCategory}} - {{raw "components/topic-list-header-column" sortable='true' order='category' name='category_title'}} + {{raw "components/topic-list-header-column" sortable=sortable order='category' name='category_title'}} {{/unless}} -{{raw "components/topic-list-header-column" order='posters' name='users'}} -{{raw "components/topic-list-header-column" sortable='true' number='true' order='posts' name='posts'}} -{{raw "components/topic-list-header-column" sortable='true' number='true' order='views' name='views'}} -{{raw "components/topic-list-header-column" sortable='true' number='true' order='activity' name='activity'}} +{{#if showPosters}} + {{raw "components/topic-list-header-column" order='posters' name='users'}} +{{/if}} +{{raw "components/topic-list-header-column" sortable=sortable number='true' order='posts' name='posts'}} +{{#if showParticipants}} + {{raw "components/topic-list-header-column" order='participants' name='users'}} +{{/if}} +{{raw "components/topic-list-header-column" sortable=sortable number='true' order='views' name='views'}} +{{raw "components/topic-list-header-column" sortable=sortable number='true' order='activity' name='activity'}} diff --git a/app/assets/javascripts/discourse/templates/components/topic-list.hbs b/app/assets/javascripts/discourse/templates/components/topic-list.hbs new file mode 100644 index 000000000..41b1b4672 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/topic-list.hbs @@ -0,0 +1,18 @@ +{{#unless skipHeader}} + + {{raw "components/topic-list-header" + currentUser=currentUser + canBulkSelect=canBulkSelect + toggleInTitle=toggleInTitle + hideCategory=hideCategory + showPosters=showPosters + showParticipants=showParticipants + order=order + ascending=ascending + sortable=sortable + bulkSelectEnabled=bulkSelectEnabled}} + +{{/unless}} + + {{each topic in topics itemView="topic-list-item"}} + diff --git a/app/assets/javascripts/discourse/templates/discovery/topics.hbs b/app/assets/javascripts/discourse/templates/discovery/topics.hbs index 08be578c0..8c9c54e8e 100644 --- a/app/assets/javascripts/discourse/templates/discovery/topics.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/topics.hbs @@ -34,15 +34,20 @@
{{/if}} + {{#if hasTopics}} - - - {{topic-list-header currentUser=currentUser canBulkSelect=canBulkSelect changeSort="changeSort" toggleBulkSelect="toggleBulkSelect" hideCategory=hideCategory order=order ascending=ascending bulkSelectEnabled=bulkSelectEnabled}} - - - {{each content in topics itemView="topic-list-item"}} - -
+ {{topic-list + showPosters=true + currentUser=currentUser + canBulkSelect=canBulkSelect + changeSort="changeSort" + toggleBulkSelect="toggleBulkSelect" + hideCategory=hideCategory + order=order + ascending=ascending + bulkSelectEnabled=bulkSelectEnabled + selected=selected + topics=topics}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/list/posts-count-column.raw.hbs b/app/assets/javascripts/discourse/templates/list/posts-count-column.raw.hbs index ac06a02a5..511345e3b 100644 --- a/app/assets/javascripts/discourse/templates/list/posts-count-column.raw.hbs +++ b/app/assets/javascripts/discourse/templates/list/posts-count-column.raw.hbs @@ -1,3 +1,3 @@ <{{view.tagName}} class='num posts-map posts {{view.likesHeat}}' title='{{view.title}}'> - {{topic.posts_count}} + {{topic.posts_count}} 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 9088467fb..319c46095 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 @@ -4,30 +4,31 @@ {{/if}} - {{raw "topic-status" topic=content}} - {{topic-link content}} + {{raw "topic-status" topic=topic}} + {{topic-link topic}} {{#if controller.showTopicPostBadges}} - {{raw "topic-post-badges" unread=content.unread newPosts=content.displayNewPosts unseen=content.unseen url=content.lastUnreadUrl}} + {{raw "topic-post-badges" unread=topic.unread newPosts=topic.displayNewPosts unseen=topic.unseen url=topic.lastUnreadUrl}} {{/if}} - {{raw "list/topic-excerpt" topic=content}} + {{raw "list/topic-excerpt" topic=topic}} {{#unless controller.hideCategory}} - {{#unless content.isPinnedUncategorized}} - {{raw "list/category-column" category=content.category}} + {{#unless topic.isPinnedUncategorized}} + {{raw "list/category-column" category=topic.category}} {{/unless}} {{/unless}} {{#if controller.showPosters}} - {{raw "list/posters-column" posters=content.posters}} + {{raw "list/posters-column" posters=topic.posters}} {{/if}} +{{raw "list/posts-count-column" topic=topic}} + {{#if controller.showParticipants}} - {{raw "list/posters-column" posters=content.participants}} + {{raw "list/posters-column" posters=topic.participants}} {{/if}} -{{raw "list/posts-count-column" topic=content}} -{{number content.views numberKey="views_long"}} +{{number topic.views numberKey="views_long"}} -{{raw "list/activity-column" topic=content class="num" tagName="td"}} +{{raw "list/activity-column" topic=topic class="num" tagName="td"}} diff --git a/app/assets/javascripts/discourse/templates/mobile/discovery/topics.hbs b/app/assets/javascripts/discourse/templates/mobile/discovery/topics.hbs index 59940fdaa..c09ae8a68 100644 --- a/app/assets/javascripts/discourse/templates/mobile/discovery/topics.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/discovery/topics.hbs @@ -4,22 +4,21 @@ {{top-period-chooser period=period}} {{/if}} + + {{#if topicTrackingState.hasIncoming}} +
+ {{countI18n topic_count_ suffix=topicTrackingState.filter count=topicTrackingState.incomingCount}} + {{i18n 'click_to_show'}} +
+ {{/if}} + {{#if hasTopics}} - - {{#if topicTrackingState.hasIncoming}} - - - - - - {{/if}} - {{collection contentBinding="topics" tagName="tbody" itemView="topic-list-item"}} -
-
- {{countI18n topic_count_ suffix=topicTrackingState.filter count=topicTrackingState.incomingCount}} - {{i18n 'click_to_show'}} -
-
+ {{topic-list + skipHeader=true + showPosters=true + currentUser=currentUser + hideCategory=hideCategory + topics=topics}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs deleted file mode 100644 index 6967b56d2..000000000 --- a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs +++ /dev/null @@ -1,39 +0,0 @@ - - - -
- {{#unless controller.hideCategory}} -
- {{category-link category showParent="true"}} -
- {{/unless}} - -
- {{raw "list/posts-count-column" topic=this tagName="div"}} -
- {{last_poster_username}} - {{raw "list/activity-column" topic=this tagName="span" class="age"}} -
-
-
-
- diff --git a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.raw.hbs b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.raw.hbs new file mode 100644 index 000000000..6f8fbbe5b --- /dev/null +++ b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.raw.hbs @@ -0,0 +1,27 @@ + + + +
+ {{#unless controller.hideCategory}} +
+ {{category-link content.category showParent="true"}} +
+ {{/unless}} + +
+ {{raw "list/posts-count-column" topic=content tagName="div"}} +
+ {{content.last_poster_username}} + {{raw "list/activity-column" topic=content tagName="span" class="age"}} +
+
+
+
+ diff --git a/app/assets/javascripts/discourse/views/topic-list-header-column.js.es6 b/app/assets/javascripts/discourse/views/topic-list-header-column.js.es6 index 2e0703c9d..723160115 100644 --- a/app/assets/javascripts/discourse/views/topic-list-header-column.js.es6 +++ b/app/assets/javascripts/discourse/views/topic-list-header-column.js.es6 @@ -9,11 +9,11 @@ export default Ember.Object.extend({ }.property(), sortClass: function(){ - return "fa fa-chevron-" + (this.parent.get("ascending") ? "up" : "down"); + return "fa fa-chevron-" + (this.parent.ascending ? "up" : "down"); }.property(), isSorting: function(){ - return this.sortable && this.parent.get("order") === this.order; + return this.sortable && this.parent.order === this.order; }.property(), className: function(){ 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 0a9cc8998..656b2fd1a 100644 --- a/app/assets/javascripts/discourse/views/topic-list-item.js.es6 +++ b/app/assets/javascripts/discourse/views/topic-list-item.js.es6 @@ -1,7 +1,7 @@ import StringBuffer from 'discourse/mixins/string-buffer'; export default Discourse.View.extend(StringBuffer, { - rerenderTriggers: ['controller.bulkSelectEnabled'], + rerenderTriggers: ['controller.bulkSelectEnabled', 'topic.pinned'], tagName: 'tr', rawTemplate: 'list/topic_list_item.raw', classNameBindings: ['controller.checked', 'content.archived', ':topic-list-item', 'content.hasExcerpt:has-excerpt'], @@ -12,6 +12,8 @@ export default Discourse.View.extend(StringBuffer, { this.get('content.isPinnedUncategorized') ? 2 : 1); }.property(), + topic: Em.computed.alias("content"), + click: function(e){ var target = $(e.target); @@ -22,6 +24,22 @@ export default Discourse.View.extend(StringBuffer, { this.container.lookup('controller:application').send("showTopicEntrance", {topic: this.get('content'), position: target.offset()}); return false; } + + if(target.hasClass('bulk-select')){ + var selected = this.get('controller.selected'); + var topic = this.get('content'); + + if(target.is(':checked')){ + selected.addObject(topic); + } else { + selected.removeObject(topic); + } + } + + if(target.closest('a.topic-status').length === 1){ + this.get('topic').togglePinnedForUser(); + return false; + } }, highlight: function() { diff --git a/app/assets/javascripts/discourse/views/topic-status.js.es6 b/app/assets/javascripts/discourse/views/topic-status.js.es6 index 394fbd2aa..7c4e4c37c 100644 --- a/app/assets/javascripts/discourse/views/topic-status.js.es6 +++ b/app/assets/javascripts/discourse/views/topic-status.js.es6 @@ -25,7 +25,7 @@ export default Ember.Object.extend({ results.push({icon: 'thumb-tack', key: 'pinned'}); } - if(topic.get('unpinnned')){ + if(topic.get('unpinned')){ results.push({icon: 'thumb-tack unpinned', key: 'unpinned'}); }