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,
selected: [],
period: null,
showPosters: true,
canStar: Em.computed.alias('controllers.discovery/topics.currentUser.id'),
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

View file

@ -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

View file

@ -1,26 +1,9 @@
{{#loading-spinner condition=loading}}
{{#if topics}}
<table class="topic-list">
<thead>
<tr>
<th class="default">{{i18n 'topic.title'}}</th>
{{#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>
{{topic-list
showParticipants=showParticipants
hideCategory=hideCategory
topics=topics}}
{{else}}
<div class='alert alert-info'>
{{i18n 'choose_topic.none_found'}}

View file

@ -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'}}

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>
{{/if}}
{{#if hasTopics}}
<table class='topic-list'>
<thead>
{{topic-list-header currentUser=currentUser canBulkSelect=canBulkSelect changeSort="changeSort" toggleBulkSelect="toggleBulkSelect" hideCategory=hideCategory order=order ascending=ascending bulkSelectEnabled=bulkSelectEnabled}}
</thead>
<tbody>
{{each content in topics itemView="topic-list-item"}}
</tbody>
</table>
{{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}}
</div>

View file

@ -1,3 +1,3 @@
<{{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 file

@ -4,30 +4,31 @@
</td>
{{/if}}
<td class='main-link clearfix' colspan="{{titleColSpan}}">
{{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}}
</td>
{{#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}}
<td class="num views {{content.viewsHeat}}">{{number content.views numberKey="views_long"}}</td>
<td class="num views {{topic.viewsHeat}}">{{number topic.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}}
</div>
{{/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}}
<table class='topic-list'>
{{#if topicTrackingState.hasIncoming}}
<tbody>
<tr>
<td>
<div class='alert alert-info' {{action "showInserted"}}>
{{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>
{{topic-list
skipHeader=true
showPosters=true
currentUser=currentUser
hideCategory=hideCategory
topics=topics}}
{{/if}}
</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(),
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(){

View file

@ -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() {

View file

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