Skip to content

Commit

Permalink
Fix some compilation issues with the import work from recent merge.
Browse files Browse the repository at this point in the history
Wire up the sorting and toggling for the assignment name. Stored in session.
  • Loading branch information
steveswinsburg committed Jun 22, 2015
1 parent 1c64e5e commit 04d2cce
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,31 +338,30 @@ public List<GbStudentGradeInfo> buildGradeMatrix(List<Assignment> assignments) {
}

/**
* Build the matrix of assignments, students and grades for all students, with the specified sortOrder
* Build the matrix of assignments and grades for the given users.
* In general this is just one, as we use it for the student summary but could be more for paging etc
*
* @param assignments list of assignments
* @param sortOrder the sort order
* @param list of uuids
* @return
*/
public List<GbStudentGradeInfo> buildGradeMatrix(List<Assignment> assignments, GbAssignmentGradeSortOrder sortOrder) {
return this.buildGradeMatrix(assignments, this.getGradeableUsers(), sortOrder);
public List<GbStudentGradeInfo> buildGradeMatrix(List<Assignment> assignments, List<String> studentUuids) {
return this.buildGradeMatrix(assignments, studentUuids, null);
}

/**
* Build the matrix of assignments and grades for the given users.
* In general this is just one, as we use it for the student summary but could be more for paging etc
* Build the matrix of assignments, students and grades for all students, with the specified sortOrder
*
* @param assignments list of assignments
* @param list of uuids
* @param sortOrder the sort order
* @return
*/
public List<GbStudentGradeInfo> buildGradeMatrix(List<Assignment> assignments, List<String> studentUuids) {
return this.buildGradeMatrix(assignments, studentUuids, null);

public List<GbStudentGradeInfo> buildGradeMatrix(List<Assignment> assignments, GbAssignmentGradeSortOrder sortOrder) {
return this.buildGradeMatrix(assignments, this.getGradeableUsers(), sortOrder);
}

/**
* Build the matrix of assignments and grades for the given users.
* In general this is just one, as we use it for the student summary but could be more for paging etc
* Build the matrix of assignments and grades for the given users with the specified sort order
*
* @param assignments list of assignments
* @param list of uuids
Expand Down Expand Up @@ -432,9 +431,7 @@ public List<GbStudentGradeInfo> buildGradeMatrix(List<Assignment> assignments, L
//get the matrix as a list of GbStudentGradeInfo
ArrayList<GbStudentGradeInfo> items = new ArrayList<>(matrix.values());



//TODO extract this out into own method where it can do the checking
//sort the matrix based on the supplied sort order (if any)
if(sortOrder != null) {
GradeComparator comparator = new GradeComparator();
comparator.setAssignmentId(sortOrder.getAssignmentId());
Expand All @@ -448,13 +445,7 @@ public List<GbStudentGradeInfo> buildGradeMatrix(List<Assignment> assignments, L
if(direction == SortDirection.DESCENDING) {
Collections.reverse(items);
}

//TODO front end neds to know direction of the sort, maybe it can hold a value as to the sort direction
//store the sort order in the SESSION, then the frpnt end can just toggle it and its handled here.


}


return items;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*
*/
public enum SortDirection {

ASCENDING,
DESCENDING
DESCENDING;

// cycles the values
public SortDirection toggle() {
return values()[(ordinal() + 1) % values().length];
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package org.sakaiproject.gradebookng.business.helpers;


import au.com.bytecode.opencsv.CSVReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.extern.apachecommons.CommonsLog;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.gradebookng.business.model.GbGradeInfo;
import org.sakaiproject.gradebookng.business.model.GbStudentGradeInfo;
import org.sakaiproject.gradebookng.business.model.ImportColumn;
import org.sakaiproject.gradebookng.business.model.ImportedGrade;
import org.sakaiproject.gradebookng.business.model.ImportedGradeItem;
Expand All @@ -17,20 +29,10 @@
import org.sakaiproject.gradebookng.business.model.ProcessedGradeItemDetail;
import org.sakaiproject.gradebookng.business.model.ProcessedGradeItemStatus;
import org.sakaiproject.gradebookng.tool.model.AssignmentStudentGradeInfo;
import org.sakaiproject.gradebookng.tool.model.GradeInfo;
import org.sakaiproject.gradebookng.tool.model.StudentGradeInfo;
import org.sakaiproject.service.gradebook.shared.Assignment;
import org.sakaiproject.util.BaseResourcePropertiesEdit;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import au.com.bytecode.opencsv.CSVReader;

/**
* Created by chmaurer on 1/21/15.
Expand Down Expand Up @@ -249,7 +251,7 @@ private static ImportedGrade mapLine(String[] line, Map<Integer,ImportColumn> ma


public static List<ProcessedGradeItem> processImportedGrades(ImportedGradeWrapper importedGradeWrapper,
List<Assignment> assignments, List<StudentGradeInfo> currentGrades) {
List<Assignment> assignments, List<GbStudentGradeInfo> currentGrades) {
List<ProcessedGradeItem> processedGradeItems = new ArrayList<ProcessedGradeItem>();
Map<String, Assignment> assignmentNameMap = new HashMap<String, Assignment>();

Expand Down Expand Up @@ -328,7 +330,7 @@ private static ProcessedGradeItemStatus determineStatus(ImportColumn column, Ass
String actualComment = null;

if (assignmentStudentGradeInfo != null) {
GradeInfo actualGradeInfo = assignmentStudentGradeInfo.getStudentGrades().get(importedGrade.getStudentEid());
GbGradeInfo actualGradeInfo = assignmentStudentGradeInfo.getStudentGrades().get(importedGrade.getStudentEid());

if (actualGradeInfo != null) {
actualScore = actualGradeInfo.getGrade();
Expand Down Expand Up @@ -367,11 +369,11 @@ private static ProcessedGradeItemStatus determineStatus(ImportColumn column, Ass
return status;
}

private static Map<Long, AssignmentStudentGradeInfo> transformCurrentGrades(List<StudentGradeInfo> currentGrades) {
private static Map<Long, AssignmentStudentGradeInfo> transformCurrentGrades(List<GbStudentGradeInfo> currentGrades) {
Map<Long, AssignmentStudentGradeInfo> assignmentMap = new HashMap<Long, AssignmentStudentGradeInfo>();

for (StudentGradeInfo studentGradeInfo : currentGrades) {
for (Map.Entry<Long, GradeInfo> entry : studentGradeInfo.getGrades().entrySet()) {
for (GbStudentGradeInfo studentGradeInfo : currentGrades) {
for (Map.Entry<Long, GbGradeInfo> entry : studentGradeInfo.getGrades().entrySet()) {
Long assignmentId = entry.getKey();
AssignmentStudentGradeInfo assignmentStudentGradeInfo = assignmentMap.get(assignmentId);
if (assignmentStudentGradeInfo == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
package org.sakaiproject.gradebookng.business.model;

import org.sakaiproject.gradebookng.business.SortDirection;
import java.io.Serializable;

import lombok.Getter;
import lombok.Setter;

import org.sakaiproject.gradebookng.business.SortDirection;

/**
* Wrapper for the fields we need to know when sorting an assignment by its grades
*/
public class GbAssignmentGradeSortOrder {
public class GbAssignmentGradeSortOrder implements Serializable {

private static final long serialVersionUID = 1L;

@Getter @Setter
private long assignmentId;

@Getter @Setter
private SortDirection direction;

/**
* Constructor to set the values meaning this cannot be an empty object
* @param assignmentId
* @param direction
*/
public GbAssignmentGradeSortOrder(long assignmentId, SortDirection direction) {
this.assignmentId = assignmentId;
this.direction = direction;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;
import lombok.Setter;

import org.sakaiproject.gradebookng.business.SortDirection;
import org.sakaiproject.gradebookng.business.model.GbAssignmentGradeSortOrder;

/**
* DTO for storing data in the session so that state is preserved between requests.
Expand All @@ -24,9 +24,6 @@ public class GradebookUiSettings implements Serializable {
* For sorting based on assignment grades
*/
@Getter @Setter
private long assignmentSort;

@Getter @Setter
private SortDirection assignmentSortDirection;
private GbAssignmentGradeSortOrder assignmentSortOrder;

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public void onSubmit(AjaxRequestTarget target, Form form) {
final List<Assignment> assignments = this.businessService.getGradebookAssignments();
Temp.time("getGradebookAssignments", stopwatch.getTime());

//get the grade matrix
final List<GbStudentGradeInfo> grades = businessService.buildGradeMatrix(assignments);
//get the grade matrix. It should be sorted if we have that info
final List<GbStudentGradeInfo> grades = businessService.buildGradeMatrix(assignments, (settings != null) ? settings.getAssignmentSortOrder() : null);

Temp.time("buildGradeMatrix", stopwatch.getTime());

Expand All @@ -137,8 +137,6 @@ public void onSubmit(AjaxRequestTarget target, Form form) {
throw new RestartResponseException(NoDataPage.class);
}



final Map<String, List<Long>> categorizedAssignmentOrder = businessService.getCategorizedAssignmentOrder();

//this could potentially be a sortable data provider
Expand Down Expand Up @@ -319,12 +317,19 @@ public ModalWindow getGradeCommentWindow() {
}

/**
* Getter for the GradebookUiSettings. Used to store a few UI related settings for the current session only
* Getter for the GradebookUiSettings. Used to store a few UI related settings for the current session only.
* May return null if there are no current settings
*
* TODO move this to a helper
*/
public GradebookUiSettings getUiSettings() {
return (GradebookUiSettings) Session.get().getAttribute("GBNG_UI_SETTINGS");
}

public void setUiSettings(GradebookUiSettings settings) {
Session.get().setAttribute("GBNG_UI_SETTINGS", settings);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.sakaiproject.gradebookng.business.GradebookNgBusinessService;
import org.sakaiproject.gradebookng.business.SortDirection;
import org.sakaiproject.gradebookng.business.model.GbAssignmentGradeSortOrder;
import org.sakaiproject.gradebookng.tool.model.GradebookUiSettings;
import org.sakaiproject.gradebookng.tool.pages.EditGradebookItemPage;
import org.sakaiproject.gradebookng.tool.pages.GradebookPage;
import org.sakaiproject.service.gradebook.shared.Assignment;
Expand All @@ -38,9 +40,7 @@ public class AssignmentColumnHeaderPanel extends Panel {

public AssignmentColumnHeaderPanel(String id, IModel<Assignment> modelData) {
super(id);

this.modelData = modelData;

}

@Override
Expand All @@ -54,8 +54,27 @@ public void onInitialize() {

@Override
public void onClick() {
// TODO Auto-generated method stub

//toggle the sort direction on each click
GradebookPage gradebookPage = (GradebookPage) this.getPage();
GradebookUiSettings settings = gradebookPage.getUiSettings();

//if null, set a default sort, otherwise toggle, save, refresh.
if(settings == null) {
settings = new GradebookUiSettings();
settings.setAssignmentSortOrder(new GbAssignmentGradeSortOrder(assignment.getId(), SortDirection.ASCENDING));
} else {
GbAssignmentGradeSortOrder sortOrder = settings.getAssignmentSortOrder();
SortDirection direction = sortOrder.getDirection();
direction = direction.toggle();
sortOrder.setDirection(direction);
settings.setAssignmentSortOrder(sortOrder);
}

//save settings
gradebookPage.setUiSettings(settings);

setResponsePage(new GradebookPage());
}

};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.sakaiproject.gradebookng.tool.panels;

import java.util.List;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.BooleanUtils;
Expand All @@ -25,7 +25,7 @@
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.sakaiproject.gradebookng.business.GradeSaveResponse;
import org.sakaiproject.gradebookng.business.GradebookNgBusinessService;
import org.sakaiproject.gradebookng.tool.model.GradeInfo;
import org.sakaiproject.gradebookng.business.model.GbGradeInfo;
import org.sakaiproject.gradebookng.tool.pages.GradebookPage;

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ public void onInitialize() {
final Double assignmentPoints = (Double) modelData.get("assignmentPoints");
final String studentUuid = (String) modelData.get("studentUuid");
final Boolean isExternal = (Boolean) modelData.get("isExternal");
final GradeInfo gradeInfo = (GradeInfo) modelData.get("gradeInfo");
final GbGradeInfo gradeInfo = (GbGradeInfo) modelData.get("gradeInfo");

//note, gradeInfo may be null
String rawGrade;
Expand Down Expand Up @@ -118,7 +118,6 @@ protected String defaultNullLabel() {
}

@Override
//TODO - Is setting a string here overkill since this component is initialised for EVERY cell?
protected void onInitialize() {
//set original grade, once only
super.onInitialize();
Expand Down Expand Up @@ -319,9 +318,6 @@ public void onClose(AjaxRequestTarget target) {
if(StringUtils.isNotBlank(comment)) {
markHasComment(gradeCell);
target.add(getParentCellFor(gradeCell));

//TODO need to update self so the label on the dropdown gets updated

};

}
Expand Down Expand Up @@ -441,8 +437,6 @@ enum GradeCellSaveStyle {
public String getCss() {
return this.css;
}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

public class GradeItemCellPopoverPanel extends Panel {

private static final long serialVersionUID = 1L;

public GradeItemCellPopoverPanel(String id, IModel<Map<String,Object>> model, List<GradeItemCellPanel.GradeCellNotification> notifications) {
super(id, model);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ public void onSubmit() {
* @param grades
* @return Map where the user's eid is the key and the uuid is the value
*/
private Map<String, String> makeUserMap(List<StudentGradeInfo> grades) {
private Map<String, String> makeUserMap(List<GbStudentGradeInfo> grades) {
Map<String, String> userMap = new HashMap<String, String>();

for (StudentGradeInfo studentGradeInfo : grades) {
for (GbStudentGradeInfo studentGradeInfo : grades) {
userMap.put(studentGradeInfo.getStudentEid(), studentGradeInfo.getStudentUuid());
}
return userMap;
Expand Down

0 comments on commit 04d2cce

Please sign in to comment.