From e5fd2946e0cee2b6daca5537b3b2f0d990f3b3e1 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 11 Nov 2013 15:01:42 -0500 Subject: [PATCH] Some topic list re-organization. --- .../components/basic_topic_list_component.js | 9 ++++++++ .../controllers/list_topics_controller.js | 2 +- .../user_topics_list_controller.js | 17 ++++++++++++++ .../javascripts/discourse/mixins/load_more.js | 10 +++------ .../discourse/models/topic_list.js | 2 +- .../routes/user_topic_list_routes.js | 6 ++--- .../discourse-basic-topic-list.js.handlebars} | 8 +++---- .../list/user_topics_list.js.handlebars | 1 + .../discourse/templates/topic.js.handlebars | 2 +- .../views/list/basic_topic_list_view.js | 12 ---------- .../discourse/views/list/list_topics_view.js | 22 ++++++++++--------- .../views/list/paginated_topic_list_view.js | 20 ----------------- .../views/list/user_topics_list_view.js | 15 +++++++++++++ app/assets/javascripts/main_include.js | 2 +- 14 files changed, 67 insertions(+), 61 deletions(-) create mode 100644 app/assets/javascripts/discourse/components/basic_topic_list_component.js create mode 100644 app/assets/javascripts/discourse/controllers/user_topics_list_controller.js rename app/assets/javascripts/discourse/templates/{list/basic_topic_list.js.handlebars => components/discourse-basic-topic-list.js.handlebars} (94%) create mode 100644 app/assets/javascripts/discourse/templates/list/user_topics_list.js.handlebars delete mode 100644 app/assets/javascripts/discourse/views/list/basic_topic_list_view.js delete mode 100644 app/assets/javascripts/discourse/views/list/paginated_topic_list_view.js create mode 100644 app/assets/javascripts/discourse/views/list/user_topics_list_view.js diff --git a/app/assets/javascripts/discourse/components/basic_topic_list_component.js b/app/assets/javascripts/discourse/components/basic_topic_list_component.js new file mode 100644 index 000000000..51c92bae9 --- /dev/null +++ b/app/assets/javascripts/discourse/components/basic_topic_list_component.js @@ -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({}); diff --git a/app/assets/javascripts/discourse/controllers/list_topics_controller.js b/app/assets/javascripts/discourse/controllers/list_topics_controller.js index 1f99edac7..6c099a6b6 100644 --- a/app/assets/javascripts/discourse/controllers/list_topics_controller.js +++ b/app/assets/javascripts/discourse/controllers/list_topics_controller.js @@ -88,7 +88,7 @@ Discourse.ListTopicsController = Discourse.ObjectController.extend({ loadMore: function() { var topicList = this.get('model'); - return topicList.loadMoreTopics().then(function(moreUrl) { + return topicList.loadMore().then(function(moreUrl) { if (!Em.isEmpty(moreUrl)) { Discourse.URL.replaceState(Discourse.getURL("/") + topicList.get('filter') + "/more"); } diff --git a/app/assets/javascripts/discourse/controllers/user_topics_list_controller.js b/app/assets/javascripts/discourse/controllers/user_topics_list_controller.js new file mode 100644 index 000000000..2e13d91fd --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/user_topics_list_controller.js @@ -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(); + } + } + +}); diff --git a/app/assets/javascripts/discourse/mixins/load_more.js b/app/assets/javascripts/discourse/mixins/load_more.js index f698478bf..2839f0c89 100644 --- a/app/assets/javascripts/discourse/mixins/load_more.js +++ b/app/assets/javascripts/discourse/mixins/load_more.js @@ -8,25 +8,21 @@ @namespace Discourse @module Discourse **/ -Discourse.LoadMore = Em.Mixin.create(Discourse.Scrolling, { +Discourse.LoadMore = Em.Mixin.create(Ember.ViewTargetActionSupport, Discourse.Scrolling, { scrolled: function(e) { var eyeline = this.get('eyeline'); if (eyeline) { eyeline.update(); } }, - loadMore: function() { - console.error('loadMore() not defined'); - }, - didInsertElement: function() { this._super(); var eyeline = new Discourse.Eyeline(this.get('eyelineSelector')); this.set('eyeline', eyeline); - var paginatedTopicListView = this; + var self = this; eyeline.on('sawBottom', function() { - paginatedTopicListView.loadMore(); + self.send('loadMore'); }); this.bindScrolling(); }, diff --git a/app/assets/javascripts/discourse/models/topic_list.js b/app/assets/javascripts/discourse/models/topic_list.js index f27400cdd..ea0fb75e1 100644 --- a/app/assets/javascripts/discourse/models/topic_list.js +++ b/app/assets/javascripts/discourse/models/topic_list.js @@ -22,7 +22,7 @@ Discourse.TopicList = Discourse.Model.extend({ }); }, - loadMoreTopics: function() { + loadMore: function() { if (this.get('loadingMore')) { return Ember.RSVP.reject(); } diff --git a/app/assets/javascripts/discourse/routes/user_topic_list_routes.js b/app/assets/javascripts/discourse/routes/user_topic_list_routes.js index 21fb7c3bb..cbf9d60d7 100644 --- a/app/assets/javascripts/discourse/routes/user_topic_list_routes.js +++ b/app/assets/javascripts/discourse/routes/user_topic_list_routes.js @@ -1,12 +1,11 @@ Discourse.UserTopicListRoute = Discourse.Route.extend({ - renderTemplate: function() { - this.render('paginated_topic_list', {into: 'user', outlet: 'userOutlet'}); + this.render('user_topics_list', {into: 'user', outlet: 'userOutlet'}); }, setupController: function(controller, model) { 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); } }); @@ -21,7 +20,6 @@ function createPMRoute(viewName, path, type) { setupController: function(controller, model) { this._super.apply(this, arguments); - controller.set('hideCategories', true); this.controllerFor('user').setProperties({ pmView: viewName, indexStream: false diff --git a/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars b/app/assets/javascripts/discourse/templates/components/discourse-basic-topic-list.js.handlebars similarity index 94% rename from app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars rename to app/assets/javascripts/discourse/templates/components/discourse-basic-topic-list.js.handlebars index ce559ba74..2b3152da2 100644 --- a/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars +++ b/app/assets/javascripts/discourse/templates/components/discourse-basic-topic-list.js.handlebars @@ -1,10 +1,10 @@ -{{#if view.topics}} +{{#if topics}} - {{#unless controller.hideCategories}} + {{#unless hideCategories}} {{/unless}} @@ -13,7 +13,7 @@ - {{#groupedEach topic in view.topics}} + {{#groupedEach topic in topics}} - {{#unless controller.hideCategories}} + {{#unless view.hideCategories}} diff --git a/app/assets/javascripts/discourse/templates/list/user_topics_list.js.handlebars b/app/assets/javascripts/discourse/templates/list/user_topics_list.js.handlebars new file mode 100644 index 000000000..5cfef1025 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/list/user_topics_list.js.handlebars @@ -0,0 +1 @@ +{{discourse-basic-topic-list topics=model.topics hideCategories="true"}} diff --git a/app/assets/javascripts/discourse/templates/topic.js.handlebars b/app/assets/javascripts/discourse/templates/topic.js.handlebars index 3496ccc03..ee1e33296 100644 --- a/app/assets/javascripts/discourse/templates/topic.js.handlebars +++ b/app/assets/javascripts/discourse/templates/topic.js.handlebars @@ -83,7 +83,7 @@

{{i18n suggested_topics.title}}

- {{basicTopicList topics=details.suggested_topics}} + {{discourse-basic-topic-list topics=details.suggested_topics}}

{{{view.browseMoreMessage}}}

diff --git a/app/assets/javascripts/discourse/views/list/basic_topic_list_view.js b/app/assets/javascripts/discourse/views/list/basic_topic_list_view.js deleted file mode 100644 index d8c499cc6..000000000 --- a/app/assets/javascripts/discourse/views/list/basic_topic_list_view.js +++ /dev/null @@ -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); diff --git a/app/assets/javascripts/discourse/views/list/list_topics_view.js b/app/assets/javascripts/discourse/views/list/list_topics_view.js index 5149c6c19..1dd65f62d 100644 --- a/app/assets/javascripts/discourse/views/list/list_topics_view.js +++ b/app/assets/javascripts/discourse/views/list/list_topics_view.js @@ -34,17 +34,19 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.LoadMore, { Discourse.notifyTitle(this.get('topicTrackingState.incomingCount')); }.observes('topicTrackingState.incomingCount'), - loadMore: function() { - var listTopicsView = this; - Discourse.notifyTitle(0); - listTopicsView.get('controller').loadMore().then(function (hasMoreResults) { - Em.run.schedule('afterRender', function() { - listTopicsView.saveScrollPosition(); + actions: { + loadMore: function() { + var self = this; + Discourse.notifyTitle(0); + self.get('controller').loadMore().then(function (hasMoreResults) { + Em.run.schedule('afterRender', function() { + self.saveScrollPosition(); + }); + if (!hasMoreResults) { + self.get('eyeline').flushRest(); + } }); - if (!hasMoreResults) { - listTopicsView.get('eyeline').flushRest(); - } - }); + } }, // Remember where we were scrolled to diff --git a/app/assets/javascripts/discourse/views/list/paginated_topic_list_view.js b/app/assets/javascripts/discourse/views/list/paginated_topic_list_view.js deleted file mode 100644 index c61060ebe..000000000 --- a/app/assets/javascripts/discourse/views/list/paginated_topic_list_view.js +++ /dev/null @@ -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(); - } - -}); - diff --git a/app/assets/javascripts/discourse/views/list/user_topics_list_view.js b/app/assets/javascripts/discourse/views/list/user_topics_list_view.js new file mode 100644 index 000000000..6ba601ed5 --- /dev/null +++ b/app/assets/javascripts/discourse/views/list/user_topics_list_view.js @@ -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' +}); + diff --git a/app/assets/javascripts/main_include.js b/app/assets/javascripts/main_include.js index 5d0231038..e33a5628d 100644 --- a/app/assets/javascripts/main_include.js +++ b/app/assets/javascripts/main_include.js @@ -65,8 +65,8 @@ //= require_tree ./discourse/controllers //= require_tree ./discourse/lib //= require_tree ./discourse/models -//= require_tree ./discourse/views //= require_tree ./discourse/components +//= require_tree ./discourse/views //= require_tree ./discourse/helpers //= require_tree ./discourse/templates //= require_tree ./discourse/routes
{{i18n topic.title}} {{i18n category_title}}{{i18n posts}}{{i18n activity}}
{{categoryLink topic.category}}