Use {{outlets}} for user activity views so we can swap some out.

This commit is contained in:
Robin Ward 2013-07-24 15:54:02 -04:00
parent e0b9117f15
commit 9132931aa9
4 changed files with 20 additions and 51 deletions

View File

@ -35,30 +35,17 @@ Discourse.UserActivityRoute = Discourse.Route.extend({
} }
}); });
/**
A route for showing a user's activity
@class UserIndexRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.UserActivityIndexRoute = Discourse.Route.extend({ 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() { model: function() {
return this.modelFor('user').findStream(this.get('userActionType')); return this.modelFor('user').findStream(this.get('userActionType'));
}, },
setupController: function(controller, model) { renderTemplate: function() {
this.controllerFor('userActivity').setProperties({ this.render('user_stream', {into: 'user_activity', outlet: 'activity'});
model: this.modelFor('user'), },
stream: model,
privateMessageView: this.get('privateMessageRoute') setupController: function() {
}); this.controllerFor('user_activity').set('userActionType', this.get('userActionType'));
} }
}); });
@ -69,35 +56,11 @@ Object.keys(Discourse.UserAction.TYPES).forEach(function (userAction) {
}); });
}); });
// Build the private message routes // // Build the private message routes
Discourse.UserPrivateMessagesRoute = Discourse.UserActivityRoute.extend({}); Discourse.UserPrivateMessagesRoute = Discourse.UserActivityRoute.extend({});
Discourse.UserPrivateMessagesIndexRoute = Discourse.UserActivityMessagesReceivedRoute; Discourse.UserPrivateMessagesIndexRoute = Discourse.UserActivityMessagesReceivedRoute;
Discourse.UserPrivateMessagesSentRoute = Discourse.UserActivityMessagesSentRoute; Discourse.UserPrivateMessagesSentRoute = Discourse.UserActivityMessagesSentRoute;
/**
Show the user's default route
@class UserIndexRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.UserIndexRoute = Discourse.Route.extend({
renderTemplate: function() {
this.render('user_activity', {into: 'user', outlet: 'userOutlet' });
},
model: function() {
return this.modelFor('user').findStream();
},
setupController: function(controller, stream) {
var userActivity = this.controllerFor('userActivity');
userActivity.setProperties({ model: this.modelFor('user'), stream: stream });
}
});
/** /**
This controller supports all actions on a user's activity stream This controller supports all actions on a user's activity stream
@ -109,6 +72,11 @@ Discourse.UserIndexRoute = Discourse.Route.extend({
Discourse.UserActivityController = Discourse.ObjectController.extend({ Discourse.UserActivityController = Discourse.ObjectController.extend({
needs: ['composer'], needs: ['composer'],
privateMessageView: function() {
return (this.get('userActionType') === Discourse.UserAction.TYPES.messages_sent) ||
(this.get('userActionType') === Discourse.UserAction.TYPES.messages_received);
}.property('userActionType'),
composePrivateMessage: function() { composePrivateMessage: function() {
return this.get('controllers.composer').open({ return this.get('controllers.composer').open({
action: Discourse.Composer.PRIVATE_MESSAGE, action: Discourse.Composer.PRIVATE_MESSAGE,

View File

@ -58,4 +58,5 @@
</div> </div>
{{userStream stream=stream}} {{outlet activity}}

View File

@ -1,5 +1,5 @@
/** /**
This view handles rendering of an activity in a user's stream This view handles rendering of an activity in a user's profile
@class ActivityFilterView @class ActivityFilterView
@extends Discourse.View @extends Discourse.View
@ -10,18 +10,18 @@ Discourse.ActivityFilterView = Discourse.View.extend({
tagName: 'li', tagName: 'li',
classNameBindings: ['active', 'noGlyph'], classNameBindings: ['active', 'noGlyph'],
stream: Em.computed.alias('controller.stream'), userActionType: Em.computed.alias('controller.userActionType'),
shouldRerender: Discourse.View.renderIfChanged('count'), shouldRerender: Discourse.View.renderIfChanged('count'),
noGlyph: Em.computed.empty('icon'), noGlyph: Em.computed.empty('icon'),
active: function() { active: function() {
var content = this.get('content'); var content = this.get('content');
if (content) { if (content) {
return parseInt(this.get('stream.filter'), 10) === parseInt(Em.get(content, 'action_type'), 10); return parseInt(this.get('userActionType'), 10) === parseInt(Em.get(content, 'action_type'), 10);
} else { } else {
return this.blank('stream.filter'); return this.blank('userActionType');
} }
}.property('stream.filter', 'content.action_type'), }.property('userActionType', 'content.action_type'),
activityCount: function() { activityCount: function() {
return this.get('content.count') || this.get('count'); return this.get('content.count') || this.get('count');

View File

@ -10,7 +10,7 @@
Discourse.UserStreamView = Ember.CollectionView.extend(Discourse.Scrolling, { Discourse.UserStreamView = Ember.CollectionView.extend(Discourse.Scrolling, {
loading: false, loading: false,
elementId: 'user-stream', elementId: 'user-stream',
content: Em.computed.alias('controller.stream.content'), content: Em.computed.alias('controller.model.content'),
itemViewClass: Ember.View.extend({ templateName: 'user/stream_item' }), itemViewClass: Ember.View.extend({ templateName: 'user/stream_item' }),
scrolled: function(e) { scrolled: function(e) {