Permalink
Browse files

introduce the new SidebarPopulatorMixin

  • Loading branch information...
1 parent 46c297c commit 2e7034a91ac8271e2661afb9c47d9312a863386d @mindcrime mindcrime committed May 2, 2012
@@ -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
@@ -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
@@ -1,5 +1,8 @@
package org.fogbeam.quoddy
+import org.fogbeam.quoddy.controller.mixins.SidebarPopulatorMixin
+
+@Mixin(SidebarPopulatorMixin)
class HomeController {
def userService;
@@ -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 )
{
@@ -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;
}
}
@@ -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 =
{
@@ -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
{
@@ -72,7 +64,6 @@ class UserGroupController
def save =
{
- // TODO: implement this...
println "save using params: ${params}"
if( session.user != null )
{
@@ -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
{
@@ -1,5 +1,8 @@
package org.fogbeam.quoddy
+import org.fogbeam.quoddy.controller.mixins.SidebarPopulatorMixin
+
+@Mixin(SidebarPopulatorMixin)
class UserListController
{
def userService;
@@ -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
@@ -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
{
@@ -1,5 +1,8 @@
package org.fogbeam.quoddy
+import org.fogbeam.quoddy.controller.mixins.SidebarPopulatorMixin
+
+@Mixin(SidebarPopulatorMixin)
class UserStreamController
{
def userService;
@@ -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
{
Oops, something went wrong.

0 comments on commit 2e7034a

Please sign in to comment.