Skip to content

Commit

Permalink
Merge pull request sakaiproject#119 from payten/fix-move-column-with-…
Browse files Browse the repository at this point in the history
…categories

Add new 'Move (left | right) within Category' menu options
  • Loading branch information
steveswinsburg committed Jun 23, 2015
2 parents ca0cc1b + 1695ceb commit 2003de2
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,20 @@ public void updateAssignmentOrder(String siteId, long assignmentId, int order) {
this.gradebookService.updateAssignmentOrder(gradebook.getUid(), assignmentId, order);
}

/**
* Update the categorized order of an assignment.
*
* @param assignmentId the assignment we are reordering
* @param order the new order
* @throws JAXBException
* @throws IdUnusedException
* @throws PermissionException
*/
public void updateCategorizedAssignmentOrder(long assignmentId, int order) throws JAXBException, IdUnusedException, PermissionException {
String siteId = this.getCurrentSiteId();
updateCategorizedAssignmentOrder(siteId, assignmentId, order);
}


/**
* Update the categorized order of an assignment.
Expand Down Expand Up @@ -634,7 +648,7 @@ public void updateCategorizedAssignmentOrder(String siteId, long assignmentId, i

String category = assignmentToMove.getCategoryName();

Map<String, List<Long>> orderedAssignments = getCategorizedAssignmentOrder(siteId);
Map<String, List<Long>> orderedAssignments = getCategorizedAssignmentsOrder(siteId);

if (!orderedAssignments.containsKey(category)) {
orderedAssignments.put(category, new ArrayList<Long>());
Expand All @@ -651,9 +665,9 @@ public void updateCategorizedAssignmentOrder(String siteId, long assignmentId, i
/**
* Get the ordered categorized assignment ids for the current site
*/
public Map<String, List<Long>> getCategorizedAssignmentOrder() {
public Map<String, List<Long>> getCategorizedAssignmentsOrder() {
try {
return getCategorizedAssignmentOrder(getCurrentSiteId());
return getCategorizedAssignmentsOrder(getCurrentSiteId());
} catch (JAXBException e) {
e.printStackTrace();
} catch(IdUnusedException e) {
Expand All @@ -673,7 +687,7 @@ public Map<String, List<Long>> getCategorizedAssignmentOrder() {
* @throws IdUnusedException
* @throws PermissionException
*/
private Map<String, List<Long>> getCategorizedAssignmentOrder(String siteId) throws JAXBException, IdUnusedException, PermissionException {
private Map<String, List<Long>> getCategorizedAssignmentsOrder(String siteId) throws JAXBException, IdUnusedException, PermissionException {
Site site = null;
try {
site = this.siteService.getSite(siteId);
Expand Down Expand Up @@ -724,6 +738,29 @@ private Map<String, List<Long>> getCategorizedAssignmentOrder(String siteId) thr
}


/**
* Get the categorized order for an assignment
*
* @param assignmentId the assignment id
* @throws JAXBException
* @throws IdUnusedException
* @throws PermissionException
*/
public int getCategorizedSortOrder(Long assignmentId) throws JAXBException, IdUnusedException, PermissionException {
String siteId = this.getCurrentSiteId();
Gradebook gradebook = getGradebook(siteId);

if(gradebook != null) {
Assignment assignment = gradebookService.getAssignment(gradebook.getUid(), assignmentId);

Map<String, List<Long>> categorizedOrder = getCategorizedAssignmentsOrder(siteId);
return categorizedOrder.get(assignment.getCategoryName()).indexOf(assignmentId);
}

return -1;
}


/**
* Set up initial Categorized Assignment Order
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.sakaiproject.gradebookng.tool.model;

import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;

import lombok.Getter;
import lombok.Setter;
Expand All @@ -17,6 +19,12 @@ public class GradebookUiSettings implements Serializable {

private static final long serialVersionUID = 1L;

public GradebookUiSettings() {
this.categoriesEnabled = false;
assignmentVisibility = new HashMap<Long, Boolean>();
}


@Getter @Setter
private String groupFilter;

Expand All @@ -26,4 +34,20 @@ public class GradebookUiSettings implements Serializable {
@Getter @Setter
private GbAssignmentGradeSortOrder assignmentSortOrder;

@Getter @Setter
private boolean categoriesEnabled;

private Map<Long, Boolean> assignmentVisibility;

public boolean isAssignmentVisible(Long assignmentId) {
if (assignmentVisibility.containsKey(assignmentId)) {
return assignmentVisibility.get(assignmentId);
}

return true;
}

public void setAssignmentVisibility(Long assignmentId, Boolean visible) {
assignmentVisibility.put(assignmentId, visible);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<button id="toggleGradeItemsToolbarItem">Show/Hide Items</button>
</li>
<li>
<button id="toggleCategoriesToolbarItem">Group By Category</button>
<button wicket:id="toggleCategoriesToolbarItem" id="toggleCategoriesToolbarItem">Group By Category</button>
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public GradebookPage() {
StopWatch stopwatch = new StopWatch();
stopwatch.start();
Temp.time("GradebookPage init", stopwatch.getTime());

form = new Form<Void>("form");
add(form);

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

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

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

//this could potentially be a sortable data provider
final ListDataProvider<GbStudentGradeInfo> studentGradeMatrix = new ListDataProvider<GbStudentGradeInfo>(grades);
Expand Down Expand Up @@ -259,6 +260,35 @@ public void populateItem(Item cellItem, String componentId, IModel rowModel) {
gradeItemSummary.setEscapeModelStrings(false);
form.add(gradeItemSummary);

AjaxButton toggleCategoriesToolbarItem = new AjaxButton("toggleCategoriesToolbarItem") {
@Override
protected void onInitialize() {
super.onInitialize();
GradebookUiSettings settings = getUiSettings();
if (settings != null && settings.isCategoriesEnabled()) {
add(new AttributeModifier("class", "on"));
}
}
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
GradebookUiSettings settings = getUiSettings();
if (settings == null) {
settings = new GradebookUiSettings();
}
settings.setCategoriesEnabled(!settings.isCategoriesEnabled());
setUiSettings(settings);

if (settings.isCategoriesEnabled()) {
add(new AttributeModifier("class", "on"));
} else {
add(new AttributeModifier("class", ""));
}
target.add(this);
target.appendJavaScript("sakai.gradebookng.spreadsheet.toggleCategories();");
}
};
form.add(toggleCategoriesToolbarItem);

//section and group dropdown
final List<GbGroup> groups = this.businessService.getSiteSectionsAndGroups();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.text.SimpleDateFormat;
import java.util.Date;
import java.lang.Exception;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class AssignmentColumnHeaderPanel extends Panel {
public AssignmentColumnHeaderPanel(String id, IModel<Assignment> modelData) {
super(id);
this.modelData = modelData;

}

@Override
Expand Down Expand Up @@ -84,7 +86,7 @@ public void onClick() {
//set the class based on the sortOrder. May not be set for this assignment
GradebookPage gradebookPage = (GradebookPage) this.getPage();
GradebookUiSettings settings = gradebookPage.getUiSettings();
if(settings != null) {
if(settings != null && settings.getAssignmentSortOrder() != null) {
title.add(new AttributeModifier("class", "gb-sort-" + settings.getAssignmentSortOrder().getDirection().toString().toLowerCase()));
}

Expand Down Expand Up @@ -159,9 +161,27 @@ public void onClick() {
//so we just make sure we get it fresh

long assignmentId = this.getModelObject();

int order = businessService.getAssignmentSortOrder(assignmentId);
businessService.updateAssignmentOrder(assignmentId, (order-1));

GradebookPage gradebookPage = (GradebookPage) this.getPage();
GradebookUiSettings settings = gradebookPage.getUiSettings();

if (settings == null) {
settings = new GradebookUiSettings();
gradebookPage.setUiSettings(settings);
}

if (settings.isCategoriesEnabled()) {
try {
int order = businessService.getCategorizedSortOrder(assignmentId);
businessService.updateCategorizedAssignmentOrder(assignmentId, (order - 1));
} catch (Exception e) {
e.printStackTrace();
error("error reordering within category");
}
} else {
int order = businessService.getAssignmentSortOrder(assignmentId);
businessService.updateAssignmentOrder(assignmentId, (order-1));
}

setResponsePage(new GradebookPage());
}
Expand All @@ -174,9 +194,28 @@ public void onClick() {
public void onClick() {

long assignmentId = this.getModelObject();

GradebookPage gradebookPage = (GradebookPage) this.getPage();
GradebookUiSettings settings = gradebookPage.getUiSettings();

if (settings == null) {
settings = new GradebookUiSettings();
gradebookPage.setUiSettings(settings);
}

if (settings.isCategoriesEnabled()) {
try {
int order = businessService.getCategorizedSortOrder(assignmentId);
businessService.updateCategorizedAssignmentOrder(assignmentId, (order + 1));
} catch (Exception e) {
e.printStackTrace();
error("error reordering within category");
}
} else {
int order = businessService.getAssignmentSortOrder(assignmentId);
businessService.updateAssignmentOrder(assignmentId, (order+1));
}

int order = businessService.getAssignmentSortOrder(assignmentId);
businessService.updateAssignmentOrder(assignmentId, (order+1));

setResponsePage(new GradebookPage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.sakaiproject.gradebookng.tool.panels;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.list.ListItem;
Expand All @@ -9,9 +11,12 @@
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.xmlbeans.impl.piccolo.xml.Piccolo;
import org.sakaiproject.gradebookng.business.model.GbGradeInfo;
import org.sakaiproject.gradebookng.tool.model.GradebookUiSettings;
import org.sakaiproject.gradebookng.tool.pages.GradebookPage;
import org.sakaiproject.service.gradebook.shared.Assignment;

import java.util.Collections;
Expand Down Expand Up @@ -53,8 +58,11 @@ public ToggleGradeItemsToolbarPanel(String id, final List<Assignment> assignment
@Override
protected void populateItem(ListItem<String> categoryItem) {
String category = categoryItem.getModelObject();


final GradebookPage gradebookPage = (GradebookPage) this.getPage();

categoryItem.add(new Label("category", category));

CheckBox categoryCheckbox = new CheckBox("categoryCheckbox");
categoryCheckbox.add(new AttributeModifier("value", category));
categoryCheckbox.add(new AttributeModifier("checked", "checked"));
Expand All @@ -65,13 +73,32 @@ protected void populateItem(ListItem<String> categoryItem) {

@Override
protected void populateItem(ListItem<Assignment> assignmentItem) {
Assignment assignment = assignmentItem.getModelObject();

final Assignment assignment = assignmentItem.getModelObject();

GradebookUiSettings settings = gradebookPage.getUiSettings();
if (settings == null) {
settings = new GradebookUiSettings();
gradebookPage.setUiSettings(settings);
}

assignmentItem.add(new Label("assignmentTitle", assignment.getName()));
CheckBox assignmentCheckbox = new CheckBox("assignmentCheckbox");

CheckBox assignmentCheckbox = new AjaxCheckBox("assignmentCheckbox", Model.of(Boolean.valueOf(settings.isAssignmentVisible(assignment.getId())))) {
@Override
protected void onUpdate(AjaxRequestTarget target) {
GradebookUiSettings settings = gradebookPage.getUiSettings();
if (settings == null) {
settings = new GradebookUiSettings();
}

Boolean value = getModelObject();
settings.setAssignmentVisibility(assignment.getId(), value);

gradebookPage.setUiSettings(settings);
}
};
assignmentCheckbox.add(new AttributeModifier("value", assignment.getId().toString()));
assignmentCheckbox.add(new AttributeModifier("data-colidx", assignments.indexOf(assignment)));
assignmentCheckbox.add(new AttributeModifier("checked", "checked"));
assignmentItem.add(assignmentCheckbox);
}
});
Expand Down
Loading

0 comments on commit 2003de2

Please sign in to comment.