Index: lams_monitoring/build.xml =================================================================== diff -u -r58d2f351a3c416c0d0b3418a063160bb62fd5fb1 -r7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15 --- lams_monitoring/build.xml (.../build.xml) (revision 58d2f351a3c416c0d0b3418a063160bb62fd5fb1) +++ lams_monitoring/build.xml (.../build.xml) (revision 7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15) @@ -131,7 +131,7 @@ - + Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java =================================================================== diff -u -r9481bb9c6f8c0e4d6fbed6b230a41c77feda64c6 -r7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 9481bb9c6f8c0e4d6fbed6b230a41c77feda64c6) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15) @@ -484,28 +484,50 @@ */ public abstract int deleteAllOldPreviewLessons(); - /* ************ Supports the Chosen Groupings **********************************/ - public abstract SortedSet getClassMembersNotGrouped(Long lessonID, Long activityID); + /* ************ Supports the Chosen Groupings and Branching **********************************/ + /** Get all the active learners in the lesson who are not in a group. + * + * If the activity is a grouping activity, then set useCreatingGrouping = true to + * base the list on the create grouping. Otherwise leave it false and it will use the + * grouping applied to the activity - this is used for branching activities. + * + * @param activityID + * @param lessonID + * @param useCreateGrouping true/false for GroupingActivities, always false for non-GroupingActivities + * @return Sorted set of Users, sorted by surname + */ + public SortedSet getClassMembersNotGrouped(Long lessonID, Long activityID, boolean useCreateGrouping); + /** Add a new group to a grouping activity. If name already exists or the name is blank, does not add a new group. - * @param activityID id of the grouping activity + * + * If the activity is a grouping activity, then set useCreatingGrouping = true to + * base the list on the create grouping. Otherwise leave it false and it will use the + * grouping applied to the activity - this is used for branching activities. + * + * @param activityID id of the activity * @param name group name * @throws LessonServiceException */ - public abstract void addGroup(Long activityID, String name) throws LessonServiceException; + public abstract void addGroup(Long activityID, String name, boolean useCreateGrouping) throws LessonServiceException; /** Remove a group to from a grouping activity. If the group does not exists then nothing happens. * If the group is already used (e.g. a tool session exists) then it throws a LessonServiceException. - * @param activityID id of the grouping activity + * + * If the activity is a grouping activity, then set useCreatingGrouping = true to + * base the list on the create grouping. Otherwise leave it false and it will use the + * grouping applied to the activity - this is used for branching activities. + * + * @param activityID id of the activity * @param name group name * @throws LessonServiceException **/ - public abstract void removeGroup(Long activityID, Long groupID) throws LessonServiceException; + public abstract void removeGroup(Long activityID, Long groupID, boolean useCreateGrouping) throws LessonServiceException; /** Add learners to a group. Doesn't necessarily check if the user is already in another group. */ - public abstract void addUsersToGroup(Long activityID, Long groupID, String learnerIDs[]) throws LessonServiceException ; + public abstract void addUsersToGroup(Long activityID, Long groupID, String learnerIDs[], boolean useCreateGrouping) throws LessonServiceException ; /** Remove a user to a group. If the user is not in the group, then nothing is changed. * @throws LessonServiceException */ - public abstract void removeUsersFromGroup(Long activityID, Long groupID, String learnerIDs[]) throws LessonServiceException; + public abstract void removeUsersFromGroup(Long activityID, Long groupID, String learnerIDs[], boolean useCreateGrouping) throws LessonServiceException; } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r9481bb9c6f8c0e4d6fbed6b230a41c77feda64c6 -r7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 9481bb9c6f8c0e4d6fbed6b230a41c77feda64c6) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15) @@ -49,6 +49,7 @@ import org.lamsfoundation.lams.dao.IBaseDAO; import org.lamsfoundation.lams.learning.service.ICoreLearnerService; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ChosenGrouping; import org.lamsfoundation.lams.learningdesign.ComplexActivity; import org.lamsfoundation.lams.learningdesign.GateActivity; import org.lamsfoundation.lams.learningdesign.Group; @@ -1817,26 +1818,26 @@ /* ************** Grouping related calls ***************************************/ /** Get all the active learners in the lesson who are not in a group. * + * If the activity is a grouping activity, then set useCreatingGrouping = true to + * base the list on the create grouping. Otherwise leave it false and it will use the + * grouping applied to the activity - this is used for branching activities. + * * TODO Optimise the database query. Do a single query rather then large collection access * * @param activityID + * @param lessonID + * @param useCreateGrouping true/false for GroupingActivities, always false for non-GroupingActivities * @return Sorted set of Users, sorted by surname */ - public SortedSet getClassMembersNotGrouped(Long lessonID, Long activityID) { + public SortedSet getClassMembersNotGrouped(Long lessonID, Long activityID, boolean useCreateGrouping) { - GroupingActivity activity = getGroupingActivityById(activityID); - Grouping grouping = activity.getCreateGrouping(); - if ( grouping == null ) { - String error = "Grouping activity missing grouping. Activity was "+activity+" Grouping was "+grouping; - log.error(error); - throw new MonitoringServiceException(error); - } - + Grouping grouping = getGroupingForActivity(activityID, useCreateGrouping,"getClassMembersNotGrouped"); + // get all the learners in the class, irrespective of whether they have joined the lesson or not. // then go through each group and remove the grouped users from the activeLearners set. Lesson lesson = lessonDAO.getLesson(lessonID); if ( lesson == null ) { - String error = "Lesson missing. LessonID was "+lessonID+" Activity was "+activity; + String error = "Lesson missing. LessonID was "+lessonID+" Activity id was "+activityID; log.error(error); throw new MonitoringServiceException(error); } @@ -1864,36 +1865,92 @@ return sortedUsers; } - - /** Add a new group to a grouping activity. If name already exists or the name is blank, does not add a new group. - * @param activityID id of the grouping activity - * @param name group name - * @throws LessonServiceException - */ - public void addGroup(Long activityID, String name) throws LessonServiceException { - GroupingActivity groupingActivity = getGroupingActivityById(activityID); - lessonService.createGroup(groupingActivity, name); + /** Get the grouping appropriate for this activity. + * + * If the activity is a grouping activity, then set useCreatingGrouping = true to + * base the list on the create grouping. Otherwise leave it false and it will use the + * grouping applied to the activity - this is used for branching activities. + * + * If it is a teacher chosen branching activity and the grouping doesn't exist, it creates + * one. + */ + private Grouping getGroupingForActivity(Long activityID, boolean useCreateGrouping, String methodName) { + Activity activity = getActivityById(activityID); + if ( useCreateGrouping && (activity == null || !activity.isGroupingActivity()) ) { + String error = methodName+": Trying to use the create grouping option but the activity isn't a grouping activity. Activity was "+activity; + log.error(error); + throw new MonitoringServiceException(error); } - /** Remove a group to from a grouping activity. If the group does not exists then nothing happens. - * If the group is already used (e.g. a tool session exists) then it throws a LessonServiceException. - * @param activityID id of the grouping activity - * @param name group name - * @throws LessonServiceException - **/ - public void removeGroup(Long activityID, Long groupId) throws LessonServiceException { - GroupingActivity groupingActivity = getGroupingActivityById(activityID); - lessonService.removeGroup(groupingActivity, groupId); + Grouping grouping = null; + + if ( useCreateGrouping ) { + GroupingActivity groupingActivity = (GroupingActivity) activity; + grouping = groupingActivity.getCreateGrouping(); + } else { + grouping = activity.getGrouping(); + if ( grouping == null && activity.isChosenBranchingActivity() ) { + // for chosen, create one on the fly the first time required + grouping = new ChosenGrouping(null, null, null); + grouping.getActivities().add(activity); + groupingDAO.insert(grouping); + if ( log.isDebugEnabled() ) { + log.debug( methodName+": Created chosen grouping "+grouping+" for branching activity "+activity); + } + } } - /** Add learners to a group. Doesn't necessarily check if the user is already in another group. */ - public void addUsersToGroup(Long activityID, Long groupId, String learnerIDs[]) throws LessonServiceException { - - GroupingActivity groupingActivity = getGroupingActivityById(activityID); - ArrayList learners = createUserList(activityID, learnerIDs,"add"); - lessonService.performGrouping(groupingActivity, groupId, learners); + if ( grouping == null ) { + String error = methodName+": Grouping activity missing grouping. Activity was "+activity; + log.error(error); + throw new MonitoringServiceException(error); } + return grouping; + } + + + /** Add a new group to a grouping activity. If name already exists or the name is blank, does not add a new group. + * If the activity is a grouping activity, then set useCreatingGrouping = true to + * base the list on the create grouping. Otherwise leave it false and it will use the + * grouping applied to the activity - this is used for branching activities. + * + * If it is a teacher chosen branching activity and the grouping doesn't exist, it creates + * one. + * @param activityID id of the grouping activity + * @param name group name + * @throws LessonServiceException + */ + public void addGroup(Long activityID, String name, boolean useCreateGrouping) throws LessonServiceException { + Grouping grouping = getGroupingForActivity(activityID, useCreateGrouping,"addGroup"); + lessonService.createGroup(grouping, name); + } + /** Remove a group to from a grouping activity. If the group does not exists then nothing happens. + * If the group is already used (e.g. a tool session exists) then it throws a LessonServiceException. + * + * If the activity is a grouping activity, then set useCreatingGrouping = true to + * base the list on the create grouping. Otherwise leave it false and it will use the + * grouping applied to the activity - this is used for branching activities. + * + * If it is a teacher chosen branching activity and the grouping doesn't exist, it creates + * one. + * @param activityID id of the grouping activity + * @param name group name + * @throws LessonServiceException + **/ + public void removeGroup(Long activityID, Long groupId, boolean useCreateGrouping) throws LessonServiceException { + Grouping grouping = getGroupingForActivity(activityID, useCreateGrouping,"removeGroup"); + lessonService.removeGroup(grouping, groupId); + } + + /** Add learners to a group. Doesn't necessarily check if the user is already in another group. */ + public void addUsersToGroup(Long activityID, Long groupId, String learnerIDs[], boolean useCreateGrouping) throws LessonServiceException { + + Grouping grouping = getGroupingForActivity(activityID, useCreateGrouping,"addUsersToGroup"); + ArrayList learners = createUserList(activityID, learnerIDs,"add"); + lessonService.performGrouping(grouping, groupId, learners); + } + private ArrayList createUserList(Long activityID, String[] learnerIDs, String addRemoveText) { ArrayList learners = new ArrayList(); for ( String strlearnerID: learnerIDs ) { @@ -1915,10 +1972,10 @@ /** Remove a user to a group. If the user is not in the group, then nothing is changed. * @throws LessonServiceException */ - public void removeUsersFromGroup(Long activityID, Long groupId, String learnerIDs[]) throws LessonServiceException { + public void removeUsersFromGroup(Long activityID, Long groupId, String learnerIDs[], boolean useCreateGrouping) throws LessonServiceException { - GroupingActivity groupingActivity = getGroupingActivityById(activityID); + Grouping grouping = getGroupingForActivity(activityID, useCreateGrouping,"removeUsersFromGroup"); ArrayList learners = createUserList(activityID, learnerIDs,"remove"); - lessonService.removeLearnersFromGroup(groupingActivity, groupId, learners); + lessonService.removeLearnersFromGroup(grouping, groupId, learners); } } \ No newline at end of file Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/ChosenBranchingAJAXAction.java =================================================================== diff -u --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/ChosenBranchingAJAXAction.java (revision 0) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/ChosenBranchingAJAXAction.java (revision 7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15) @@ -0,0 +1,392 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.monitoring.web; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Iterator; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.BranchingActivity; +import org.lamsfoundation.lams.learningdesign.ChosenBranchingActivity; +import org.lamsfoundation.lams.learningdesign.ChosenGrouping; +import org.lamsfoundation.lams.learningdesign.Group; +import org.lamsfoundation.lams.learningdesign.GroupComparator; +import org.lamsfoundation.lams.learningdesign.Grouping; +import org.lamsfoundation.lams.learningdesign.GroupingActivity; +import org.lamsfoundation.lams.learningdesign.SequenceActivity; +import org.lamsfoundation.lams.lesson.service.LessonServiceException; +import org.lamsfoundation.lams.monitoring.service.IMonitoringService; +import org.lamsfoundation.lams.monitoring.service.MonitoringServiceException; +import org.lamsfoundation.lams.monitoring.service.MonitoringServiceProxy; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.util.LastNameAlphabeticComparator; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.action.LamsDispatchAction; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; + +/** +* The action servlet that provides the support for the +*
    +*
  • AJAX based Chosen Branching screen
  • +*
  • View only screen for Group Based and Tool Based branching
  • +*
+* +* @author Fiona Malikoff + +* ----------------XDoclet Tags-------------------- +* +* @struts:action path="/branching" +* parameter="method" +* validate="false" +* @struts.action-forward name = "chosenSelection" path = "/branching/chosenSelection.jsp" +* @struts.action-forward name = "viewBranches" path = "/branching/viewBranches.jsp" +* +* ----------------XDoclet Tags-------------------- +*/ +public class ChosenBranchingAJAXAction extends LamsDispatchAction { + + //--------------------------------------------------------------------- + + private static final String CHOSEN_SELECTION_SCREEN = "chosenSelection"; + private static final String VIEW_BRANCHES_SCREEN = "viewBranches"; + private static final String PARAM_ACTIVITY_DESCRIPTION = "description"; + public static final String PARAM_TYPE = "type"; +// public static final String PARAM_MAX_NUM_GROUPS = "maxNumberOfGroups"; + public static final String PARAM_NAME = "name"; + public static final String PARAM_BRANCHES = "branches"; + public static final String PARAM_MEMBERS = "members"; + public static final String PARAM_MAY_DELETE = "mayDelete"; + + private Integer getUserId(HttpServletRequest request) { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user != null ? user.getUserID() : null; + } + + + private void writeAJAXResponse(HttpServletResponse response, String output) throws IOException { + response.setContentType("text/html"); + PrintWriter writer = response.getWriter(); + // set it to unicode + if (output.length()>0) { + writer.println(output); + } + } + + private void writeAJAXOKResponse(HttpServletResponse response) throws IOException { + writeAJAXResponse(response, "OK"); + } + + private Grouping getGrouping(ChosenBranchingActivity activity) { + Grouping grouping = activity.getGrouping(); + if ( grouping == null ) { + String error = "Chosen branching activity missing grouping. Activity was "+activity+" Grouping was "+grouping; + log.error(error); + throw new MonitoringServiceException(error); + } + return grouping; + } + + /** + * Start the process of doing the chosen grouping + * + * Input parameters: activityID + */ + public ActionForward assignBranch(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + + String type = WebUtil.readStrParam(request, PARAM_TYPE); + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); + + IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + Activity activity = monitoringService.getActivityById(activityID); + if ( activity == null || !activity.isBranchingActivity() ) { + String error = "Activity is not a branching activity. Activity was "+activity; + log.error(error); + throw new MonitoringServiceException(error); + } + Grouping grouping = activity.getGrouping(); + if ( grouping == null ) { + // need to create the grouping for a chosen branching activity + String error = "Grouping for branching activity missing. Activity was "+activity; + log.error(error); + throw new MonitoringServiceException(error); + } + + request.setAttribute(AttributeNames.PARAM_ACTIVITY_ID, activityID); + request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId); + request.setAttribute(AttributeNames.PARAM_TITLE, activity.getTitle()); + request.setAttribute(PARAM_ACTIVITY_DESCRIPTION, activity.getDescription()); + + if ( activity.isBranchingActivity() ) { +// request.setAttribute(PARAM_MAX_NUM_GROUPS, grouping.getMaxNumberOfGroups()); + // can I remove groups/users - can't if tool sessions have been created + Set groups = grouping.getGroups(); + Iterator iter = groups.iterator(); + boolean mayDelete = true; + while (mayDelete && iter.hasNext()) { + Group group = (Group) iter.next(); + mayDelete = group.mayBeDeleted(); + } + request.setAttribute(PARAM_MAY_DELETE, mayDelete); + return mapping.findForward(CHOSEN_SELECTION_SCREEN); + + } else { + + // go to a view only screen for group based and tool based grouping + // view all the branches, along with the groups for each branch and each groups members + SortedSet branches = new TreeSet(); + branches.addAll(((BranchingActivity)activity).getActivities()); + request.setAttribute(PARAM_BRANCHES,branches); + return mapping.findForward(VIEW_BRANCHES_SCREEN); + } + + } + + /** + * Get a list of group names and the number of users in each group. Designed to respond to an AJAX call. + * + * Input parameters: activityID + * + * Output format: "groupid,name,num users;groupid,name,num users" + */ + public ActionForward getGroups(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + + // get the grouping data and sort it. + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + ChosenBranchingActivity activity = (ChosenBranchingActivity) monitoringService.getActivityById(activityID); + Grouping grouping = getGrouping(activity); + Set sortedGroups = new TreeSet(new GroupComparator()); + sortedGroups.addAll(grouping.getGroups()); + + // build the output string to return to the chosen grouping page. + String groupOutput = ""; + boolean first = true; + for ( Group group: sortedGroups ) { + Long groupId = group.getGroupId(); + String name = group.getGroupName(); + Integer numberOfMembers = group.getUsers().size(); + if ( ! first ) { + groupOutput=groupOutput+";"; + } else { + first = false; + } + groupOutput=groupOutput+groupId+","+name+","+numberOfMembers; + } + writeAJAXResponse(response, groupOutput); + return null; + } + + /** + * Get a list of all the class members who aren't grouped yet. Designed to respond to an AJAX call. + * + * Input parameters: activityID + * + * Output format: "groupid,name,num users;groupid,name,num users" + */ + public ActionForward getClassMembersNotGrouped(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + + // get the grouping data and sort it. + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Long lessonID = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); + IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + SortedSet users = monitoringService.getClassMembersNotGrouped(lessonID, activityID, false); + String groupOutput = buildUserString(users); + writeAJAXResponse(response, groupOutput); + return null; + + } + + /** + * Get a list of group names and the number of users in each group. Designed to respond to an AJAX call. + * + * Input parameters: activityID, groupID + * + * Output format: "userid,lastname,firstname;" + */ + public ActionForward getGroupMembers(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + + // TODO optimise this call - we don't really need the activity and the grouping - go straight to the group in the db + // get the group, and from there the user data and sort the user data. + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); + IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + ChosenBranchingActivity activity = (ChosenBranchingActivity) monitoringService.getActivityById(activityID); + Grouping grouping = getGrouping(activity); + Set groups = grouping.getGroups(); + Iterator iter = groups.iterator(); + Group group = null; + while (group==null && iter.hasNext()) { + Group candidateGroup = (Group) iter.next(); + if ( groupID.equals(candidateGroup.getGroupId()) ) + group = candidateGroup; + } + if ( group == null ) { + String error = "Group cannot be found. Activity was "+activity+" Grouping was "+grouping+" Grouping ID was "+groupID; + log.error(error); + throw new MonitoringServiceException(error); + } + + Set users = group.getUsers(); + SortedSet sortedUsers = new TreeSet(new LastNameAlphabeticComparator()); + sortedUsers.addAll(users); + String userOutput = buildUserString(sortedUsers); + writeAJAXResponse(response, userOutput); + return null; + } + + + /** + * Output format: "userid,lastname,firstname;" + * @param sortedUsers + * @return String of users + */ + private String buildUserString(SortedSet sortedUsers) { + String userOutput = ""; + boolean first = true; + for ( User user : sortedUsers ) { + Integer userID = user.getUserId(); + String lastName = user.getLastName(); + String firstName = user.getFirstName(); + if ( ! first ) { + userOutput=userOutput+";"; + } else { + first = false; + } + userOutput=userOutput+userID+","+lastName+","+firstName; + } + return userOutput; + } + + /** + * Add a new group. Designed to respond to an AJAX call. + * + * Input parameters: activityID, name (group name) + * + * Output format: no data returned - just the header + */ + public ActionForward addGroup(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, LessonServiceException { + + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + String name = WebUtil.readStrParam(request, PARAM_NAME); + IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + monitoringService.addGroup(activityID, name, false); + writeAJAXResponse(response,""); + return null; + } + + /** + * Remove a group. Cannot remove the group if it is in use (tool session ids exist). Designed to respond to an AJAX call. + * + * Input parameters: activityID, name: group name + * + * Output format: no data returned - just the header + */ + public ActionForward removeGroup(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, LessonServiceException { + + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); + + IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + monitoringService.removeGroup(activityID, groupID, false); + writeAJAXOKResponse(response); + return null; + } + + /** + * Add learners to a group. Designed to respond to an AJAX call. + * + * Input parameters: activityID, name: group name, members: comma separated list of users + * + * Output format: no data returned - just the header + */ + public ActionForward addMembers(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, LessonServiceException { + + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); + String members = WebUtil.readStrParam(request, PARAM_MEMBERS, true); + if ( members != null ) { + String[] membersSplit = members.split(","); + IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + monitoringService.addUsersToGroup(activityID, groupID, membersSplit, false); + } + writeAJAXOKResponse(response); + return null; + } + + /** + * Remove a list of users from a group. Designed to respond to an AJAX call. + * + * Input parameters: activityID, name: group name, members: comma separated list of users + * + * Output format: no data returned - just the header + */ + public ActionForward removeMembers(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, LessonServiceException { + + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); + String members = WebUtil.readStrParam(request, PARAM_MEMBERS, true); + if ( members != null ) { + String[] membersSplit = members.split(","); + IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + monitoringService.removeUsersFromGroup(activityID, groupID, membersSplit, false); + } + writeAJAXOKResponse(response); + return null; + } + +} Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingAJAXAction.java =================================================================== diff -u -r5a3cc53aed2cf49f4a82ff155bb7394eb82dc656 -r7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingAJAXAction.java (.../GroupingAJAXAction.java) (revision 5a3cc53aed2cf49f4a82ff155bb7394eb82dc656) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingAJAXAction.java (.../GroupingAJAXAction.java) (revision 7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15) @@ -222,7 +222,7 @@ Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); Long lessonID = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); - SortedSet users = monitoringService.getClassMembersNotGrouped(lessonID, activityID); + SortedSet users = monitoringService.getClassMembersNotGrouped(lessonID, activityID, true); String groupOutput = buildUserString(users); writeAJAXResponse(response, groupOutput); return null; @@ -306,7 +306,7 @@ Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); String name = WebUtil.readStrParam(request, PARAM_NAME); IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); - monitoringService.addGroup(activityID, name); + monitoringService.addGroup(activityID, name, true); writeAJAXResponse(response,""); return null; } @@ -326,7 +326,7 @@ Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); - monitoringService.removeGroup(activityID, groupID); + monitoringService.removeGroup(activityID, groupID, true); writeAJAXOKResponse(response); return null; } @@ -348,7 +348,7 @@ if ( members != null ) { String[] membersSplit = members.split(","); IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); - monitoringService.addUsersToGroup(activityID, groupID, membersSplit); + monitoringService.addUsersToGroup(activityID, groupID, membersSplit, true); } writeAJAXOKResponse(response); return null; @@ -371,7 +371,7 @@ if ( members != null ) { String[] membersSplit = members.split(","); IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); - monitoringService.removeUsersFromGroup(activityID, groupID, membersSplit); + monitoringService.removeUsersFromGroup(activityID, groupID, membersSplit, true); } writeAJAXOKResponse(response); return null; Index: lams_monitoring/web/branching/chosenSelection.jsp =================================================================== diff -u --- lams_monitoring/web/branching/chosenSelection.jsp (revision 0) +++ lams_monitoring/web/branching/chosenSelection.jsp (revision 7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15) @@ -0,0 +1,477 @@ + <%-- +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) +License Information: http://lamsfoundation.org/licensing/lams/2.0/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + + http://www.gnu.org/licenses/gpl.txt +--%> +<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> + +<%@ taglib uri="tags-tiles" prefix="tiles" %> +<%@ taglib uri="tags-html" prefix="html" %> +<%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="tags-core" prefix="c" %> +<%@ taglib uri="tags-lams" prefix="lams" %> + + + + + + + <c:out value="${title}"/> + + + + + + + + + + + + +
+ +

+ +

+ +
+ + +

+
+ +

+

+ +

+ +

+ + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ " onclick="removeGroup()" disabled="true"/> + + " onclick="addMembersToGroup()" disabled="true"/> + + " onclick="removeMembersFromGroup()" disabled="true"/> +
+
+ " onclick="addGroup()" /> +
+ <%@ include file="../template/finishbutton.jsp" %> +
+ +
+ + + + + + +