Skip to content

Commit

Permalink
SAK-30835 Added multi user retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish committed May 25, 2016
1 parent 16399c0 commit 3f79fd3
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 35 deletions.
5 changes: 3 additions & 2 deletions roster2/src/java/org/sakaiproject/roster/api/RosterData.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class RosterData {

private List<RosterMember> members;
private int membersTotal;
private Map<String, Integer> roleCounts;
private int membersTotal;
private Map<String, Integer> roleCounts;
private String status;
}

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class RosterSiteEntityProvider extends AbstractEntityProvider implements
// key passed as parameters
public final static String KEY_GROUP_ID = "groupId";
public final static String KEY_ROLE_ID = "roleId";
public final static String KEY_USER_ID = "userId";
public final static String KEY_USER_IDS = "userIds";
public final static String KEY_PAGE = "page";
public final static String KEY_ENROLLMENT_SET_ID = "enrollmentSetId";
public final static String KEY_ENROLLMENT_STATUS = "enrollmentStatus";
Expand Down Expand Up @@ -205,22 +205,22 @@ public Object getMembership(EntityReference reference, Map<String, Object> param
}
}

@EntityCustomAction(action = "get-user", viewKey = EntityView.VIEW_SHOW)
public Object getUser(EntityReference reference, Map<String, Object> parameters) {
@EntityCustomAction(action = "get-users", viewKey = EntityView.VIEW_SHOW)
public Object getUsers(EntityReference reference, Map<String, Object> parameters) {

String siteId = reference.getId();
String siteId = reference.getId();

if (null == siteId || DEFAULT_ID.equals(siteId)) {
throw new EntityException(ERROR_INVALID_SITE, reference.getReference());
}

String userId = null;
if (parameters.containsKey(KEY_USER_ID)) {
userId = parameters.get(KEY_USER_ID).toString();
String[] userIds = null;
if (parameters.containsKey(KEY_USER_IDS)) {
userIds = parameters.get(KEY_USER_IDS).toString().split(",");
}

if (null == userId) {
throw new EntityException("No user id supplied", reference.getReference());
if (null == userIds) {
throw new EntityException("No user ids supplied", reference.getReference());
}

String enrollmentSetId = null;
Expand All @@ -229,25 +229,33 @@ public Object getUser(EntityReference reference, Map<String, Object> parameters)
}

List<RosterMember> membership = new ArrayList<RosterMember>();
Map<String, Integer> roleCounts = new HashMap<String, Integer>(1);

RosterMember member = sakaiProxy.getMember(siteId, userId, enrollmentSetId);

if (null == member) {
throw new EntityException("Unable to retrieve membership", reference.getReference());
}
for (String userId : userIds) {
RosterMember member = sakaiProxy.getMember(siteId, userId, enrollmentSetId);

if (null == member) {
throw new EntityException("Unable to retrieve membership", reference.getReference());
}

membership.add(member);

membership.add(member);
String role = member.getRole();
if (!roleCounts.containsKey(role)) {
roleCounts.put(role, 1);
} else {
roleCounts.put(role, roleCounts.get(role) + 1);
}
}

RosterData data = new RosterData();
data.setMembers(membership);
data.setMembersTotal(1);
Map<String, Integer> roleCounts = new HashMap<String, Integer>(1);
roleCounts.put(member.getRole(), 1);
data.setRoleCounts(roleCounts);
RosterData data = new RosterData();
data.setMembers(membership);
data.setMembersTotal(membership.size());
data.setRoleCounts(roleCounts);

return data;
return data;
}

@EntityCustomAction(action = "get-site", viewKey = EntityView.VIEW_SHOW)
public Object getSite(EntityReference reference) {

Expand All @@ -260,7 +268,7 @@ public Object getSite(EntityReference reference) {

@EntityCustomAction(action = "get-search-index", viewKey = EntityView.VIEW_SHOW)
public Object getSearchIndex(EntityReference reference) {

String siteId = reference.getId();

if (null == siteId || DEFAULT_ID.equals(siteId)) {
Expand All @@ -269,7 +277,7 @@ public Object getSearchIndex(EntityReference reference) {

return sakaiProxy.getSearchIndex(siteId);
}

/*
@EntityCustomAction(action = "get-enrollment", viewKey = EntityView.VIEW_SHOW)
public Object getEnrollment(EntityReference reference, Map<String, Object> parameters) {
Expand Down
5 changes: 5 additions & 0 deletions roster2/src/webapp/css/roster.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
margin-left: 2px;
}

#roster-information {
font-weight: bold;
margin-left: 15px;
}

/* Table display for large screen sizes */
@media only screen and (min-width: 800px) and (max-width: 1100px) {
.roster-groups-selector {
Expand Down
44 changes: 36 additions & 8 deletions roster2/src/webapp/js/roster.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@

var url = "/direct/roster-membership/" + roster.siteId;

if (options.userId) {
url += "/get-user.json?userId=" + options.userId;
if (options.userIds) {
url += "/get-users.json?userIds=" + options.userIds.join(',');
if (roster.enrollmentSetToView) {
url += "&enrollmentSetId=" + roster.enrollmentSetToView;
}
Expand Down Expand Up @@ -423,9 +423,12 @@
}
}

roster.nextPage += 1;

$(window).off('scroll.roster').on('scroll.roster', roster.getScrollFunction(options.forceOfficialPicture));
if (options.userIds) {
$(window).off('scroll.roster');
} else {
roster.nextPage += 1;
$(window).off('scroll.roster').on('scroll.roster', roster.getScrollFunction(options.forceOfficialPicture));
}

loadImage.hide();
},
Expand All @@ -448,10 +451,35 @@
roster.search = function (query) {

if (query !== roster.i18n.roster_search_text && query !== "") {
var userIds = [];
var userId = roster.searchIndex[query];
roster.renderMembership({ forceOfficialPicture: roster.rosterOfficialPictureMode,
replace: true,
userId: userId });
if (!userId) {
roster.searchIndexKeys.forEach(function (displayName) {

var regex = new RegExp(query, 'i');
if (regex.test(displayName)) {
userIds.push(roster.searchIndex[displayName]);
}
});

if (userIds.length > 5) {
// Limit to 5 users
userIds = userIds.slice(0, 5);
}
} else {
userIds.push(userId);
}

if (userIds.length > 0) {
roster.renderMembership({ showOfficialPictures: roster.rosterOfficialPictureMode,
replace: true,
userIds: userIds });
} else {
$('#roster-members').html('<div id="roster-information">' + roster.i18n.no_participants + '</div>');
$('#roster-members-total').hide();
$('#roster_type_selector').hide();
$('#summary').hide();
}
}
};

Expand Down

0 comments on commit 3f79fd3

Please sign in to comment.