From 82465caf97730fa2415db206caab81f4d529fe7e Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 23 Jul 2013 16:33:33 -0400 Subject: [PATCH] Clean up user activity code in preparation for topic rendering --- .../controllers/user_activity_controller.js | 74 ++++--------------- ...s.handlebars => stream_item.js.handlebars} | 4 +- .../discourse/views/user/user_stream_view.js | 6 +- 3 files changed, 20 insertions(+), 64 deletions(-) rename app/assets/javascripts/discourse/templates/user/{stream.js.handlebars => stream_item.js.handlebars} (95%) diff --git a/app/assets/javascripts/discourse/controllers/user_activity_controller.js b/app/assets/javascripts/discourse/controllers/user_activity_controller.js index 0d37c446aef..0328b7a1051 100644 --- a/app/assets/javascripts/discourse/controllers/user_activity_controller.js +++ b/app/assets/javascripts/discourse/controllers/user_activity_controller.js @@ -33,7 +33,6 @@ Discourse.UserActivityRoute = Discourse.Route.extend({ }); } } - }); /** @@ -45,8 +44,13 @@ Discourse.UserActivityRoute = Discourse.Route.extend({ @module Discourse **/ Discourse.UserActivityIndexRoute = Discourse.Route.extend({ + privateMessageRoute: function() { + return (this.get('userActionType') === Discourse.UserAction.TYPES.messages_sent) || + (this.get('userActionType') === Discourse.UserAction.TYPES.messages_received); + }.property('userActionType'), + model: function() { - return this.modelFor('user').findStream(); + return this.modelFor('user').findStream(this.get('userActionType')); }, setupController: function(controller, model) { @@ -61,12 +65,15 @@ Discourse.UserActivityIndexRoute = Discourse.Route.extend({ // Build all the filter routes Object.keys(Discourse.UserAction.TYPES).forEach(function (userAction) { Discourse["UserActivity" + userAction.classify() + "Route"] = Discourse.UserActivityIndexRoute.extend({ - model: function() { - return this.modelFor('user').findStream(Discourse.UserAction.TYPES[userAction]); - } + userActionType: Discourse.UserAction.TYPES[userAction] }); }); +// Build the private message routes +Discourse.UserPrivateMessagesRoute = Discourse.UserActivityRoute.extend({}); +Discourse.UserPrivateMessagesIndexRoute = Discourse.UserActivityMessagesReceivedRoute; +Discourse.UserPrivateMessagesSentRoute = Discourse.UserActivityMessagesSentRoute; + /** Show the user's default route @@ -82,62 +89,15 @@ Discourse.UserIndexRoute = Discourse.Route.extend({ }, model: function() { - var user = this.modelFor('user'); - return user.findStream(); + return this.modelFor('user').findStream(); }, setupController: function(controller, stream) { var userActivity = this.controllerFor('userActivity'); - userActivity.setProperties({ - model: this.modelFor('user'), - stream: stream - }); + userActivity.setProperties({ model: this.modelFor('user'), stream: stream }); } }); -/** - Base route for showing private messages - - @class UserPrivateMessagesRoute - @extends Discourse.UserActivityRoute - @namespace Discourse - @module Discourse -**/ -Discourse.UserPrivateMessagesRoute = Discourse.UserActivityRoute.extend({}); - -/** - Default private messages route - - @class UserPrivateMessagesIndexRoute - @extends Discourse.UserActivityIndexRoute - @namespace Discourse - @module Discourse -**/ -Discourse.UserPrivateMessagesIndexRoute = Discourse.UserActivityIndexRoute.extend({ - privateMessageRoute: true, - - model: function() { - return this.modelFor('user').findStream(Discourse.UserAction.TYPES.messages_received); - } -}); - -/** - Private messages sent route - - @class UserPrivateMessagesSentRoute - @extends Discourse.UserActivityIndexRoute - @namespace Discourse - @module Discourse -**/ -Discourse.UserPrivateMessagesSentRoute = Discourse.UserActivityIndexRoute.extend({ - privateMessageRoute: true, - - model: function() { - return this.modelFor('user').findStream(Discourse.UserAction.TYPES.messages_sent); - } -}); - - /** This controller supports all actions on a user's activity stream @@ -149,12 +109,6 @@ Discourse.UserPrivateMessagesSentRoute = Discourse.UserActivityIndexRoute.extend Discourse.UserActivityController = Discourse.ObjectController.extend({ needs: ['composer'], - kickOffPrivateMessage: (function() { - if (this.get('content.openPrivateMessage')) { - this.composePrivateMessage(); - } - }).observes('content.openPrivateMessage'), - composePrivateMessage: function() { return this.get('controllers.composer').open({ action: Discourse.Composer.PRIVATE_MESSAGE, diff --git a/app/assets/javascripts/discourse/templates/user/stream.js.handlebars b/app/assets/javascripts/discourse/templates/user/stream_item.js.handlebars similarity index 95% rename from app/assets/javascripts/discourse/templates/user/stream.js.handlebars rename to app/assets/javascripts/discourse/templates/user/stream_item.js.handlebars index 180d610decf..bd54a73287c 100644 --- a/app/assets/javascripts/discourse/templates/user/stream.js.handlebars +++ b/app/assets/javascripts/discourse/templates/user/stream_item.js.handlebars @@ -1,4 +1,4 @@ -{{#each view.stream.content}} +{{#with view.content}} -{{/each}} +{{/with}} diff --git a/app/assets/javascripts/discourse/views/user/user_stream_view.js b/app/assets/javascripts/discourse/views/user/user_stream_view.js index 216db69f8db..91d07b4cc9e 100644 --- a/app/assets/javascripts/discourse/views/user/user_stream_view.js +++ b/app/assets/javascripts/discourse/views/user/user_stream_view.js @@ -7,10 +7,11 @@ @uses Discourse.Scrolling @module Discourse **/ -Discourse.UserStreamView = Discourse.View.extend(Discourse.Scrolling, { - templateName: 'user/stream', +Discourse.UserStreamView = Ember.CollectionView.extend(Discourse.Scrolling, { loading: false, elementId: 'user-stream', + content: Em.computed.alias('controller.stream.content'), + itemViewClass: Ember.View.extend({ templateName: 'user/stream_item' }), scrolled: function(e) { var eyeline = this.get('eyeline'); @@ -33,6 +34,7 @@ Discourse.UserStreamView = Discourse.View.extend(Discourse.Scrolling, { }, didInsertElement: function() { + console.log(this.get('content')); this.bindScrolling(); var eyeline = new Discourse.Eyeline('#user-stream .item');