Skip to content

Commit

Permalink
introduce the new SidebarPopulatorMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
mindcrime committed May 2, 2012
1 parent 46c297c commit 2e7034a
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 159 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.fogbeam.quoddy

import org.codehaus.jackson.map.ObjectMapper
import org.fogbeam.quoddy.controller.mixins.SidebarPopulatorMixin
import org.fogbeam.quoddy.integration.activitystream.ActivityStreamEntry


Expand All @@ -13,7 +14,7 @@ class ActivityStreamController
def eventQueueService;

def getQueueSize =
{
{
// check and see how many queued up messages are waiting for this user...
// we'll call this on a timer basis and build up a message that says
// XXX more recent updates waiting
Expand Down
38 changes: 11 additions & 27 deletions grails-app/controllers/org/fogbeam/quoddy/HomeController.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.fogbeam.quoddy

import org.fogbeam.quoddy.controller.mixins.SidebarPopulatorMixin

@Mixin(SidebarPopulatorMixin)
class HomeController {

def userService;
Expand All @@ -12,13 +15,8 @@ class HomeController {
def index = {

def userId = params.userId;
def user = null;
User user = null;
def activities = new ArrayList<Activity>();
def systemDefinedStreams = new ArrayList<UserStream>();
def userDefinedStreams = new ArrayList<UserStream>();
def userLists = new ArrayList<UserList>();
def userGroups = new ArrayList<UserGroup>();
def eventSubscriptions = new ArrayList<EventSubscription>();

if( userId != null )
{
Expand All @@ -40,34 +38,20 @@ class HomeController {
}
}

Map model = [:];
if( user )
{
// TODO: this should take the selected UserStream into account when
// determining what activities to include in the activities list

activities = eventStreamService.getRecentActivitiesForUser( user, 25 );

def tempSysStreams = userStreamService.getSystemDefinedStreamsForUser( user );
systemDefinedStreams.addAll( tempSysStreams );
def tempUserStreams = userStreamService.getUserDefinedStreamsForUser( user );
userDefinedStreams.addAll( tempUserStreams );

def tempUserLists = userListService.getListsForUser( user );
userLists.addAll( tempUserLists );

def tempUserGroups = userGroupService.getAllGroupsForUser( user );
userGroups.addAll( tempUserGroups );
model.putAll( [user:user, activities:activities] );

Map sidebarCollections = populateSidebarCollections( this, user );
model.putAll( sidebarCollections );

def tempEventSubscriptions = eventSubscriptionService.getAllSubscriptionsForUser( user );
eventSubscriptions.addAll( tempEventSubscriptions );
}

[user:user,
activities:activities,
sysDefinedStreams:systemDefinedStreams,
userDefinedStreams:userDefinedStreams,
userLists:userLists,
userGroups:userGroups,
eventSubscriptions:eventSubscriptions];

return model;
}
}
118 changes: 50 additions & 68 deletions grails-app/controllers/org/fogbeam/quoddy/UserGroupController.groovy
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package org.fogbeam.quoddy

import org.fogbeam.quoddy.controller.mixins.SidebarPopulatorMixin


@Mixin(SidebarPopulatorMixin)
class UserGroupController
{
def eventStreamService;
def userService;
def userStreamService;
def userListService;
def userGroupService;
def eventSubscriptionService;

def index =
{
Expand All @@ -15,48 +20,35 @@ class UserGroupController
def userOwnedGroups = new ArrayList<UserGroup>();
def userMembershipGroups = new ArrayList<UserGroup>();

def systemDefinedStreams = new ArrayList<UserStream>();
def userDefinedStreams = new ArrayList<UserStream>();
def userLists = new ArrayList<UserList>();
def userGroups = new ArrayList<UserGroup>();

if( session.user != null )
{
user = userService.findUserByUserId( session.user.userId );


def tempUserOwnedGroups = userGroupService.getGroupsOwnedByUser( user );
if( tempUserOwnedGroups )

Map model = [:];
if( user )
{
userOwnedGroups.addAll( tempUserOwnedGroups );
def tempUserOwnedGroups = userGroupService.getGroupsOwnedByUser( user );
if( tempUserOwnedGroups )
{
userOwnedGroups.addAll( tempUserOwnedGroups );
}

def tempUserMembershipGroups = userGroupService.getGroupsWhereUserIsMember(user);
if( tempUserMembershipGroups )
{
userMembershipGroups.addAll( tempUserMembershipGroups );
}

model.putAll( [user:user,
userOwnedGroups:userOwnedGroups,
userMembershipGroups:userMembershipGroups] );

Map sidebarCollections = populateSidebarCollections( this, user );
model.putAll( sidebarCollections );
}

def tempUserMembershipGroups = userGroupService.getGroupsWhereUserIsMember(user);
if( tempUserMembershipGroups )
{
userMembershipGroups.addAll( tempUserMembershipGroups );
}

def tempSysStreams = userStreamService.getSystemDefinedStreamsForUser( user );
systemDefinedStreams.addAll( tempSysStreams );
def tempUserStreams = userStreamService.getUserDefinedStreamsForUser( user );
userDefinedStreams.addAll( tempUserStreams );

def tempUserLists = userListService.getListsForUser( user );
userLists.addAll( tempUserLists );

def tempUserGroups = userGroupService.getAllGroupsForUser( user );
userGroups.addAll( tempUserGroups );


[user:user,
userOwnedGroups:userOwnedGroups,
userMembershipGroups:userMembershipGroups,
sysDefinedStreams:systemDefinedStreams,
userDefinedStreams:userDefinedStreams,
userLists:userLists,
userGroups:userGroups ];

return model;
}
else
{
Expand All @@ -72,7 +64,6 @@ class UserGroupController
def save =
{

// TODO: implement this...
println "save using params: ${params}"
if( session.user != null )
{
Expand Down Expand Up @@ -144,43 +135,34 @@ class UserGroupController
// println "Doing display with params: ${params}";
def activities = new ArrayList<Activity>();

def systemDefinedStreams = new ArrayList<UserStream>();
def userDefinedStreams = new ArrayList<UserStream>();
def userLists = new ArrayList<UserList>();
def userGroups = new ArrayList<UserGroup>();

def tempSysStreams = userStreamService.getSystemDefinedStreamsForUser( user );
systemDefinedStreams.addAll( tempSysStreams );
def tempUserStreams = userStreamService.getUserDefinedStreamsForUser( user );
userDefinedStreams.addAll( tempUserStreams );

def tempUserLists = userListService.getListsForUser( user );
userLists.addAll( tempUserLists );
Map model = [:];
if( user )
{
UserGroup group = UserGroup.findById( params.groupId );

List<UserGroup> tempUserGroups = userGroupService.getAllGroupsForUser( user );
userGroups.addAll( tempUserGroups );
// check that this group is not one of the ones that the user either
// owns or is a member of
boolean userIsGroupMember = false;
userGroups.each {
if( it.id == group.id ){
userIsGroupMember = true;
return;
}
}

UserGroup group = UserGroup.findById( params.groupId );
activities = userGroupService.getRecentActivitiesForGroup( group, 25 );

// check that this group is not one of the ones that the user either
// owns or is a member of
boolean userIsGroupMember = false;
userGroups.each {
if( it.id == group.id ){
userIsGroupMember = true;
return;
}
model.putAll( [ group:group,
user: user,
userIsGroupMember:userIsGroupMember,
activities:activities] );

Map sidebarCollections = populateSidebarCollections( this, user );
model.putAll( sidebarCollections );
}

activities = userGroupService.getRecentActivitiesForGroup( group, 25 );

[ group:group,
userIsGroupMember:userIsGroupMember,
activities:activities,
sysDefinedStreams:systemDefinedStreams,
userDefinedStreams:userDefinedStreams,
userLists:userLists,
userGroups:userGroups ];
return model;
}
else
{
Expand Down
67 changes: 23 additions & 44 deletions grails-app/controllers/org/fogbeam/quoddy/UserListController.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.fogbeam.quoddy

import org.fogbeam.quoddy.controller.mixins.SidebarPopulatorMixin

@Mixin(SidebarPopulatorMixin)
class UserListController
{
def userService;
Expand All @@ -11,32 +14,18 @@ class UserListController
{
User user = null;

def systemDefinedStreams = new ArrayList<UserStream>();
def userDefinedStreams = new ArrayList<UserStream>();
def userLists = new ArrayList<UserList>();
def userGroups = new ArrayList<UserGroup>();

if( session.user != null )
{
user = userService.findUserByUserId( session.user.userId );


def tempSysStreams = userStreamService.getSystemDefinedStreamsForUser( user );
systemDefinedStreams.addAll( tempSysStreams );
def tempUserStreams = userStreamService.getUserDefinedStreamsForUser( user );
userDefinedStreams.addAll( tempUserStreams );

def tempUserLists = userListService.getListsForUser( user );
userLists.addAll( tempUserLists );

def tempUserGroups = userGroupService.getAllGroupsForUser( user );
userGroups.addAll( tempUserGroups );

[user:user,
sysDefinedStreams:systemDefinedStreams,
userDefinedStreams:userDefinedStreams,
userLists:userLists,
userGroups:userGroups ];
Map model = [:];
if( user )
{
Map sidebarCollections = populateSidebarCollections( this, user );
model.putAll( sidebarCollections );
}

return model;

}
else
Expand All @@ -53,32 +42,22 @@ class UserListController
def user = userService.findUserByUserId( session.user.userId );
// println "Doing display with params: ${params}";
def activities = new ArrayList<Activity>();

def systemDefinedStreams = new ArrayList<UserStream>();
def userDefinedStreams = new ArrayList<UserStream>();
def userLists = new ArrayList<UserList>();
def userGroups = new ArrayList<UserGroup>();

def tempSysStreams = userStreamService.getSystemDefinedStreamsForUser( user );
systemDefinedStreams.addAll( tempSysStreams );
def tempUserStreams = userStreamService.getUserDefinedStreamsForUser( user );
userDefinedStreams.addAll( tempUserStreams );

def tempUserLists = userListService.getListsForUser( user );
userLists.addAll( tempUserLists );

List<UserGroup> tempUserGroups = userGroupService.getAllGroupsForUser( user );
userGroups.addAll( tempUserGroups );


UserList list = UserList.findById( params.listId );

activities = userListService.getRecentActivitiesForList( list, 25 );
Map model = [:];
if( user )
{
activities = userListService.getRecentActivitiesForList( list, 25 );
model.putAll( [ activities:activities] );

Map sidebarCollections = populateSidebarCollections( this, user );
model.putAll( sidebarCollections );

}

[ activities:activities,
sysDefinedStreams:systemDefinedStreams,
userDefinedStreams:userDefinedStreams,
userLists:userLists,
userGroups:userGroups ];
return model;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.fogbeam.quoddy

import org.fogbeam.quoddy.controller.mixins.SidebarPopulatorMixin

@Mixin(SidebarPopulatorMixin)
class UserStreamController
{
def userService;
Expand All @@ -22,26 +25,15 @@ class UserStreamController
if( session.user != null )
{
user = userService.findUserByUserId( session.user.userId );


def tempSysStreams = userStreamService.getSystemDefinedStreamsForUser( user );
systemDefinedStreams.addAll( tempSysStreams );
def tempUserStreams = userStreamService.getUserDefinedStreamsForUser( user );
userDefinedStreams.addAll( tempUserStreams );


def tempUserLists = userListService.getListsForUser( user );
userLists.addAll( tempUserLists );

def tempUserGroups = userGroupService.getAllGroupsForUser( user );
userGroups.addAll( tempUserGroups );

[user:user,
sysDefinedStreams:systemDefinedStreams,
userDefinedStreams:userDefinedStreams,
userLists:userLists,
userGroups:userGroups];

Map model = [:];
if( user )
{
Map sidebarCollections = populateSidebarCollections( this, user );
model.putAll( sidebarCollections );
}

return model;
}
else
{
Expand Down
Loading

0 comments on commit 2e7034a

Please sign in to comment.