clean up rendering and correct issues with topic list to raw commit

This commit is contained in:
Sam 2015-01-05 16:37:25 +11:00
parent fa9bbd554e
commit 69771562d7
17 changed files with 167 additions and 132 deletions

View File

@ -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'));
}
}
},
});

View File

@ -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();
});
}
});

View File

@ -6,7 +6,6 @@ var controllerOpts = {
bulkSelectEnabled: false, bulkSelectEnabled: false,
selected: [], selected: [],
period: null, period: null,
showPosters: true,
canStar: Em.computed.alias('controllers.discovery/topics.currentUser.id'), canStar: Em.computed.alias('controllers.discovery/topics.currentUser.id'),
showTopicPostBadges: Em.computed.not('controllers.discovery/topics.new'), showTopicPostBadges: Em.computed.not('controllers.discovery/topics.new'),

View File

@ -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 Re-pins a topic with a cleared pin

View File

@ -101,7 +101,10 @@ Discourse.User = Discourse.Model.extend({
@property path @property path
@type {String} @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 Path to this user's administration

View File

@ -1,26 +1,9 @@
{{#loading-spinner condition=loading}} {{#loading-spinner condition=loading}}
{{#if topics}} {{#if topics}}
<table class="topic-list"> {{topic-list
<thead> showParticipants=showParticipants
<tr> hideCategory=hideCategory
<th class="default">{{i18n 'topic.title'}}</th> topics=topics}}
{{#unless controller.hideCategory}}
<th class="category">{{i18n 'category_title'}}</th>
{{/unless}}
<th class="num posts">{{i18n 'posts'}}</th>
{{#if controller.showParticipants}}
<th class="posters">{{i18n 'users'}}</th>
{{/if}}
<th class="num views">{{i18n 'views'}}</th>
<th class="num activity">{{i18n 'activity'}}</th>
</tr>
</thead>
<tbody>
{{each t in topics itemViewClass='topic-list-item'}}
</tbody>
</table>
{{else}} {{else}}
<div class='alert alert-info'> <div class='alert alert-info'>
{{i18n 'choose_topic.none_found'}} {{i18n 'choose_topic.none_found'}}

View File

@ -5,9 +5,14 @@
{{/if}} {{/if}}
{{raw "components/topic-list-header-column" order='default' name='topic.title' showBulkToggle=toggleInTitle}} {{raw "components/topic-list-header-column" order='default' name='topic.title' showBulkToggle=toggleInTitle}}
{{#unless hideCategory}} {{#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}} {{/unless}}
{{raw "components/topic-list-header-column" order='posters' name='users'}} {{#if showPosters}}
{{raw "components/topic-list-header-column" sortable='true' number='true' order='posts' name='posts'}} {{raw "components/topic-list-header-column" order='posters' name='users'}}
{{raw "components/topic-list-header-column" sortable='true' number='true' order='views' name='views'}} {{/if}}
{{raw "components/topic-list-header-column" sortable='true' number='true' order='activity' name='activity'}} {{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'}}

View File

@ -0,0 +1,18 @@
{{#unless skipHeader}}
<thead>
{{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}}
</thead>
{{/unless}}
<tbody>
{{each topic in topics itemView="topic-list-item"}}
</tbody>

View File

@ -34,15 +34,20 @@
</div> </div>
</div> </div>
{{/if}} {{/if}}
{{#if hasTopics}} {{#if hasTopics}}
<table class='topic-list'> {{topic-list
<thead> showPosters=true
{{topic-list-header currentUser=currentUser canBulkSelect=canBulkSelect changeSort="changeSort" toggleBulkSelect="toggleBulkSelect" hideCategory=hideCategory order=order ascending=ascending bulkSelectEnabled=bulkSelectEnabled}} currentUser=currentUser
</thead> canBulkSelect=canBulkSelect
<tbody> changeSort="changeSort"
{{each content in topics itemView="topic-list-item"}} toggleBulkSelect="toggleBulkSelect"
</tbody> hideCategory=hideCategory
</table> order=order
ascending=ascending
bulkSelectEnabled=bulkSelectEnabled
selected=selected
topics=topics}}
{{/if}} {{/if}}
</div> </div>

View File

@ -1,3 +1,3 @@
<{{view.tagName}} class='num posts-map posts {{view.likesHeat}}' title='{{view.title}}'> <{{view.tagName}} class='num posts-map posts {{view.likesHeat}}' title='{{view.title}}'>
<a href class='posts-map badge-posts'>{{topic.posts_count}}</a> <a href class='posts-map badge-posts {{view.likesHeat}}'>{{topic.posts_count}}</a>
</{{view.tagName}}> </{{view.tagName}}>

View File

@ -4,30 +4,31 @@
</td> </td>
{{/if}} {{/if}}
<td class='main-link clearfix' colspan="{{titleColSpan}}"> <td class='main-link clearfix' colspan="{{titleColSpan}}">
{{raw "topic-status" topic=content}} {{raw "topic-status" topic=topic}}
{{topic-link content}} {{topic-link topic}}
{{#if controller.showTopicPostBadges}} {{#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}} {{/if}}
{{raw "list/topic-excerpt" topic=content}} {{raw "list/topic-excerpt" topic=topic}}
</td> </td>
{{#unless controller.hideCategory}} {{#unless controller.hideCategory}}
{{#unless content.isPinnedUncategorized}} {{#unless topic.isPinnedUncategorized}}
{{raw "list/category-column" category=content.category}} {{raw "list/category-column" category=topic.category}}
{{/unless}} {{/unless}}
{{/unless}} {{/unless}}
{{#if controller.showPosters}} {{#if controller.showPosters}}
{{raw "list/posters-column" posters=content.posters}} {{raw "list/posters-column" posters=topic.posters}}
{{/if}} {{/if}}
{{raw "list/posts-count-column" topic=topic}}
{{#if controller.showParticipants}} {{#if controller.showParticipants}}
{{raw "list/posters-column" posters=content.participants}} {{raw "list/posters-column" posters=topic.participants}}
{{/if}} {{/if}}
{{raw "list/posts-count-column" topic=content}} <td class="num views {{topic.viewsHeat}}">{{number topic.views numberKey="views_long"}}</td>
<td class="num views {{content.viewsHeat}}">{{number content.views numberKey="views_long"}}</td>
{{raw "list/activity-column" topic=content class="num" tagName="td"}} {{raw "list/activity-column" topic=topic class="num" tagName="td"}}

View File

@ -4,22 +4,21 @@
{{top-period-chooser period=period}} {{top-period-chooser period=period}}
</div> </div>
{{/if}} {{/if}}
{{#if topicTrackingState.hasIncoming}}
<div class='alert alert-info' {{action "showInserted"}}>
{{countI18n topic_count_ suffix=topicTrackingState.filter count=topicTrackingState.incomingCount}}
{{i18n 'click_to_show'}}
</div>
{{/if}}
{{#if hasTopics}} {{#if hasTopics}}
<table class='topic-list'> {{topic-list
{{#if topicTrackingState.hasIncoming}} skipHeader=true
<tbody> showPosters=true
<tr> currentUser=currentUser
<td> hideCategory=hideCategory
<div class='alert alert-info' {{action "showInserted"}}> topics=topics}}
{{countI18n topic_count_ suffix=topicTrackingState.filter count=topicTrackingState.incomingCount}}
{{i18n 'click_to_show'}}
</div>
</td>
</tr>
</tbody>
{{/if}}
{{collection contentBinding="topics" tagName="tbody" itemView="topic-list-item"}}
</table>
{{/if}} {{/if}}
</div> </div>

View File

@ -1,39 +0,0 @@
<td>
<div class='main-link clearfix'>
{{topic-status topic=this}}
{{topic-link this}}
{{topic-post-badges unread=unread
newPosts=displayNewPosts
unseen=unseen
url=lastUnreadUrl}}
{{#if hasExcerpt}}
<div class="topic-excerpt">
{{{excerpt}}}
{{#if excerptTruncated}}
{{#unless canClearPin}}<a href="{{unbound url}}">{{i18n 'read_more'}}</a>{{/unless}}
{{/if}}
{{#if canClearPin}}
<a href="#" {{action "clearPin" this}} title="{{i18n 'topic.clear_pin.help'}}">{{i18n 'topic.clear_pin.title'}}</a>
{{/if}}
</div>
{{/if}}
</div>
<div class="topic-item-stats clearfix">
{{#unless controller.hideCategory}}
<div class='category'>
{{category-link category showParent="true"}}
</div>
{{/unless}}
<div class="pull-right">
{{raw "list/posts-count-column" topic=this tagName="div"}}
<div class='num activity last'>
<a href="{{unbound lastPostUrl}}" title='{{i18n 'last_post'}}: {{{raw-date bumped_at}}}'>{{last_poster_username}}</a>
{{raw "list/activity-column" topic=this tagName="span" class="age"}}
</div>
</div>
<div class="clearfix"></div>
</div>
</td>

View File

@ -0,0 +1,27 @@
<td>
<div class='main-link clearfix'>
{{raw "topic-status" topic=content}}
{{topic-link content}}
{{#if controller.showTopicPostBadges}}
{{raw "topic-post-badges" unread=content.unread newPosts=content.displayNewPosts unseen=content.unseen url=content.lastUnreadUrl}}
{{/if}}
{{raw "list/topic-excerpt" topic=content}}
</div>
<div class="topic-item-stats clearfix">
{{#unless controller.hideCategory}}
<div class='category'>
{{category-link content.category showParent="true"}}
</div>
{{/unless}}
<div class="pull-right">
{{raw "list/posts-count-column" topic=content tagName="div"}}
<div class='num activity last'>
<a href="{{content.lastPostUrl}}" title='{{i18n 'last_post'}}: {{{raw-date content.bumped_at}}}'>{{content.last_poster_username}}</a>
{{raw "list/activity-column" topic=content tagName="span" class="age"}}
</div>
</div>
<div class="clearfix"></div>
</div>
</td>

View File

@ -9,11 +9,11 @@ export default Ember.Object.extend({
}.property(), }.property(),
sortClass: function(){ sortClass: function(){
return "fa fa-chevron-" + (this.parent.get("ascending") ? "up" : "down"); return "fa fa-chevron-" + (this.parent.ascending ? "up" : "down");
}.property(), }.property(),
isSorting: function(){ isSorting: function(){
return this.sortable && this.parent.get("order") === this.order; return this.sortable && this.parent.order === this.order;
}.property(), }.property(),
className: function(){ className: function(){

View File

@ -1,7 +1,7 @@
import StringBuffer from 'discourse/mixins/string-buffer'; import StringBuffer from 'discourse/mixins/string-buffer';
export default Discourse.View.extend(StringBuffer, { export default Discourse.View.extend(StringBuffer, {
rerenderTriggers: ['controller.bulkSelectEnabled'], rerenderTriggers: ['controller.bulkSelectEnabled', 'topic.pinned'],
tagName: 'tr', tagName: 'tr',
rawTemplate: 'list/topic_list_item.raw', rawTemplate: 'list/topic_list_item.raw',
classNameBindings: ['controller.checked', 'content.archived', ':topic-list-item', 'content.hasExcerpt:has-excerpt'], 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); this.get('content.isPinnedUncategorized') ? 2 : 1);
}.property(), }.property(),
topic: Em.computed.alias("content"),
click: function(e){ click: function(e){
var target = $(e.target); 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()}); this.container.lookup('controller:application').send("showTopicEntrance", {topic: this.get('content'), position: target.offset()});
return false; 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() { highlight: function() {

View File

@ -25,7 +25,7 @@ export default Ember.Object.extend({
results.push({icon: 'thumb-tack', key: 'pinned'}); results.push({icon: 'thumb-tack', key: 'pinned'});
} }
if(topic.get('unpinnned')){ if(topic.get('unpinned')){
results.push({icon: 'thumb-tack unpinned', key: 'unpinned'}); results.push({icon: 'thumb-tack unpinned', key: 'unpinned'});
} }