Some topic list re-organization.

This commit is contained in:
Robin Ward 2013-11-11 15:01:42 -05:00
parent 2f8866add5
commit e5fd2946e0
14 changed files with 67 additions and 61 deletions

View file

@ -0,0 +1,9 @@
/**
This view is used for rendering a basic list of topics.
@class BasicTopicListView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.BasicTopicListComponent = Ember.Component.extend({});

View file

@ -88,7 +88,7 @@ Discourse.ListTopicsController = Discourse.ObjectController.extend({
loadMore: function() { loadMore: function() {
var topicList = this.get('model'); var topicList = this.get('model');
return topicList.loadMoreTopics().then(function(moreUrl) { return topicList.loadMore().then(function(moreUrl) {
if (!Em.isEmpty(moreUrl)) { if (!Em.isEmpty(moreUrl)) {
Discourse.URL.replaceState(Discourse.getURL("/") + topicList.get('filter') + "/more"); Discourse.URL.replaceState(Discourse.getURL("/") + topicList.get('filter') + "/more");
} }

View file

@ -0,0 +1,17 @@
/**
Lists of topics on a user's page.
@class UserTopicsListController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.UserTopicsListController = Discourse.ObjectController.extend({
actions: {
loadMore: function() {
this.get('model').loadMore();
}
}
});

View file

@ -8,25 +8,21 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.LoadMore = Em.Mixin.create(Discourse.Scrolling, { Discourse.LoadMore = Em.Mixin.create(Ember.ViewTargetActionSupport, Discourse.Scrolling, {
scrolled: function(e) { scrolled: function(e) {
var eyeline = this.get('eyeline'); var eyeline = this.get('eyeline');
if (eyeline) { eyeline.update(); } if (eyeline) { eyeline.update(); }
}, },
loadMore: function() {
console.error('loadMore() not defined');
},
didInsertElement: function() { didInsertElement: function() {
this._super(); this._super();
var eyeline = new Discourse.Eyeline(this.get('eyelineSelector')); var eyeline = new Discourse.Eyeline(this.get('eyelineSelector'));
this.set('eyeline', eyeline); this.set('eyeline', eyeline);
var paginatedTopicListView = this; var self = this;
eyeline.on('sawBottom', function() { eyeline.on('sawBottom', function() {
paginatedTopicListView.loadMore(); self.send('loadMore');
}); });
this.bindScrolling(); this.bindScrolling();
}, },

View file

@ -22,7 +22,7 @@ Discourse.TopicList = Discourse.Model.extend({
}); });
}, },
loadMoreTopics: function() { loadMore: function() {
if (this.get('loadingMore')) { return Ember.RSVP.reject(); } if (this.get('loadingMore')) { return Ember.RSVP.reject(); }

View file

@ -1,12 +1,11 @@
Discourse.UserTopicListRoute = Discourse.Route.extend({ Discourse.UserTopicListRoute = Discourse.Route.extend({
renderTemplate: function() { renderTemplate: function() {
this.render('paginated_topic_list', {into: 'user', outlet: 'userOutlet'}); this.render('user_topics_list', {into: 'user', outlet: 'userOutlet'});
}, },
setupController: function(controller, model) { setupController: function(controller, model) {
this.controllerFor('user_activity').set('userActionType', this.get('userActionType')); this.controllerFor('user_activity').set('userActionType', this.get('userActionType'));
controller.set('model', model); this.controllerFor('user_topics_list').set('model', model);
this.controllerFor('user').set('indexStream', false); this.controllerFor('user').set('indexStream', false);
} }
}); });
@ -21,7 +20,6 @@ function createPMRoute(viewName, path, type) {
setupController: function(controller, model) { setupController: function(controller, model) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
controller.set('hideCategories', true);
this.controllerFor('user').setProperties({ this.controllerFor('user').setProperties({
pmView: viewName, pmView: viewName,
indexStream: false indexStream: false

View file

@ -1,10 +1,10 @@
{{#if view.topics}} {{#if topics}}
<table id="topic-list"> <table id="topic-list">
<tr> <tr>
<th> <th>
{{i18n topic.title}} {{i18n topic.title}}
</th> </th>
{{#unless controller.hideCategories}} {{#unless hideCategories}}
<th>{{i18n category_title}}</th> <th>{{i18n category_title}}</th>
{{/unless}} {{/unless}}
<th class='num posts'>{{i18n posts}}</th> <th class='num posts'>{{i18n posts}}</th>
@ -13,7 +13,7 @@
<th class='num activity' colspan='2'>{{i18n activity}}</th> <th class='num activity' colspan='2'>{{i18n activity}}</th>
</tr> </tr>
{{#groupedEach topic in view.topics}} {{#groupedEach topic in topics}}
<tr {{bindAttr class="archived"}}> <tr {{bindAttr class="archived"}}>
<td class='main-link'> <td class='main-link'>
{{topicStatus topic=topic}} {{topicStatus topic=topic}}
@ -28,7 +28,7 @@
<a href="{{unbound topic.lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a> <a href="{{unbound topic.lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
{{/if}} {{/if}}
</td> </td>
{{#unless controller.hideCategories}} {{#unless view.hideCategories}}
<td class='category'> <td class='category'>
{{categoryLink topic.category}} {{categoryLink topic.category}}
</td> </td>

View file

@ -0,0 +1 @@
{{discourse-basic-topic-list topics=model.topics hideCategories="true"}}

View file

@ -83,7 +83,7 @@
<div id='suggested-topics'> <div id='suggested-topics'>
<h3>{{i18n suggested_topics.title}}</h3> <h3>{{i18n suggested_topics.title}}</h3>
<div class='topics'> <div class='topics'>
{{basicTopicList topics=details.suggested_topics}} {{discourse-basic-topic-list topics=details.suggested_topics}}
</div> </div>
<br/> <br/>
<h3>{{{view.browseMoreMessage}}}</h3> <h3>{{{view.browseMoreMessage}}}</h3>

View file

@ -1,12 +0,0 @@
/**
This view is used for rendering a basic list of topics.
@class BasicTopicListView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.BasicTopicListView = Discourse.View.extend({
templateName: 'list/basic_topic_list'
});
Discourse.View.registerHelper('basicTopicList', Discourse.BasicTopicListView);

View file

@ -34,17 +34,19 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.LoadMore, {
Discourse.notifyTitle(this.get('topicTrackingState.incomingCount')); Discourse.notifyTitle(this.get('topicTrackingState.incomingCount'));
}.observes('topicTrackingState.incomingCount'), }.observes('topicTrackingState.incomingCount'),
actions: {
loadMore: function() { loadMore: function() {
var listTopicsView = this; var self = this;
Discourse.notifyTitle(0); Discourse.notifyTitle(0);
listTopicsView.get('controller').loadMore().then(function (hasMoreResults) { self.get('controller').loadMore().then(function (hasMoreResults) {
Em.run.schedule('afterRender', function() { Em.run.schedule('afterRender', function() {
listTopicsView.saveScrollPosition(); self.saveScrollPosition();
}); });
if (!hasMoreResults) { if (!hasMoreResults) {
listTopicsView.get('eyeline').flushRest(); self.get('eyeline').flushRest();
} }
}); });
}
}, },
// Remember where we were scrolled to // Remember where we were scrolled to

View file

@ -1,20 +0,0 @@
/**
This view is used for rendering a basic list of topics.
@class PaginatedTopicListView
@extends Discourse.View
@namespace Discourse
@uses Discourse.LoadMore
@module Discourse
**/
Discourse.PaginatedTopicListView = Discourse.BasicTopicListView.extend(Discourse.LoadMore, {
topics: Em.computed.alias('controller.model.topics'),
classNames: ['paginated-topics-list'],
eyelineSelector: '.paginated-topics-list #topic-list tr',
loadMore: function() {
this.get('controller.model').loadMoreTopics();
}
});

View file

@ -0,0 +1,15 @@
/**
This view is used for rendering a basic list of topics on a user's page.
@class UserTopicsListView
@extends Discourse.View
@namespace Discourse
@uses Discourse.LoadMore
@module Discourse
**/
Discourse.UserTopicsListView = Discourse.View.extend(Discourse.LoadMore, {
classNames: ['paginated-topics-list'],
eyelineSelector: '.paginated-topics-list #topic-list tr',
templateName: 'list/user_topics_list'
});

View file

@ -65,8 +65,8 @@
//= require_tree ./discourse/controllers //= require_tree ./discourse/controllers
//= require_tree ./discourse/lib //= require_tree ./discourse/lib
//= require_tree ./discourse/models //= require_tree ./discourse/models
//= require_tree ./discourse/views
//= require_tree ./discourse/components //= require_tree ./discourse/components
//= require_tree ./discourse/views
//= require_tree ./discourse/helpers //= require_tree ./discourse/helpers
//= require_tree ./discourse/templates //= require_tree ./discourse/templates
//= require_tree ./discourse/routes //= require_tree ./discourse/routes