From 67af71ef38078e8a405b2f98f87839672b6004b3 Mon Sep 17 00:00:00 2001 From: Payten Giles Date: Mon, 22 Jun 2015 12:40:43 +1000 Subject: [PATCH 1/4] Add new 'Move (left | right) within Category' to the header menu options to reorder within the category sort order. Only show these menu options when categories are enabled. --- .../GradebookNgApplication.properties | 2 + .../business/GradebookNgBusinessService.java | 45 +++++++++++++++++-- .../gradebookng/tool/pages/GradebookPage.java | 3 +- .../panels/AssignmentColumnHeaderPanel.html | 2 + .../panels/AssignmentColumnHeaderPanel.java | 40 ++++++++++++++++- tool/src/webapp/scripts/gradebook-grades.js | 8 ++++ 6 files changed, 94 insertions(+), 6 deletions(-) diff --git a/tool/src/java/org/sakaiproject/gradebookng/GradebookNgApplication.properties b/tool/src/java/org/sakaiproject/gradebookng/GradebookNgApplication.properties index 12ab1800a75d..6966d34697a9 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/GradebookNgApplication.properties +++ b/tool/src/java/org/sakaiproject/gradebookng/GradebookNgApplication.properties @@ -137,6 +137,8 @@ assignment.option.edit = Edit Item Details assignment.option.viewgradestatistics = View Grade Statistics assignment.option.moveleft = Move Left assignment.option.moveright = Move Right +assignment.option.moveleftwithincategory = Move Left in Category +assignment.option.moverightwithincategory = Move Right in Category assignment.option.hide = Hide Item assignment.option.setungraded = Set Score for Empty Cells diff --git a/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java b/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java index 7b2237d98528..d54db951320b 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java +++ b/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java @@ -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. @@ -634,7 +648,7 @@ public void updateCategorizedAssignmentOrder(String siteId, long assignmentId, i String category = assignmentToMove.getCategoryName(); - Map> orderedAssignments = getCategorizedAssignmentOrder(siteId); + Map> orderedAssignments = getCategorizedAssignmentsOrder(siteId); if (!orderedAssignments.containsKey(category)) { orderedAssignments.put(category, new ArrayList()); @@ -651,9 +665,9 @@ public void updateCategorizedAssignmentOrder(String siteId, long assignmentId, i /** * Get the ordered categorized assignment ids for the current site */ - public Map> getCategorizedAssignmentOrder() { + public Map> getCategorizedAssignmentsOrder() { try { - return getCategorizedAssignmentOrder(getCurrentSiteId()); + return getCategorizedAssignmentsOrder(getCurrentSiteId()); } catch (JAXBException e) { e.printStackTrace(); } catch(IdUnusedException e) { @@ -673,7 +687,7 @@ public Map> getCategorizedAssignmentOrder() { * @throws IdUnusedException * @throws PermissionException */ - private Map> getCategorizedAssignmentOrder(String siteId) throws JAXBException, IdUnusedException, PermissionException { + private Map> getCategorizedAssignmentsOrder(String siteId) throws JAXBException, IdUnusedException, PermissionException { Site site = null; try { site = this.siteService.getSite(siteId); @@ -724,6 +738,29 @@ private Map> 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> categorizedOrder = getCategorizedAssignmentsOrder(siteId); + return categorizedOrder.get(assignment.getCategoryName()).indexOf(assignmentId); + } + + return -1; + } + + /** * Set up initial Categorized Assignment Order */ diff --git a/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java b/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java index 7e9b7cb1e4c9..b62e3dc8cc6a 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java +++ b/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java @@ -137,7 +137,8 @@ public void onSubmit(AjaxRequestTarget target, Form form) { throw new RestartResponseException(NoDataPage.class); } - final Map> categorizedAssignmentOrder = businessService.getCategorizedAssignmentOrder(); + + final Map> categorizedAssignmentOrder = businessService.getCategorizedAssignmentsOrder(); //this could potentially be a sortable data provider final ListDataProvider studentGradeMatrix = new ListDataProvider(grades); diff --git a/tool/src/java/org/sakaiproject/gradebookng/tool/panels/AssignmentColumnHeaderPanel.html b/tool/src/java/org/sakaiproject/gradebookng/tool/panels/AssignmentColumnHeaderPanel.html index 45e6319ba935..aa384690e04f 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/tool/panels/AssignmentColumnHeaderPanel.html +++ b/tool/src/java/org/sakaiproject/gradebookng/tool/panels/AssignmentColumnHeaderPanel.html @@ -33,7 +33,9 @@ diff --git a/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java b/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java index b62e3dc8cc6a..d84c9d3caeea 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java +++ b/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java @@ -37,6 +37,7 @@ import org.sakaiproject.gradebookng.business.model.GbStudentGradeInfo; import org.sakaiproject.gradebookng.business.util.Temp; import org.sakaiproject.gradebookng.tool.model.GradebookUiSettings; +import org.sakaiproject.gradebookng.tool.model.GbSpreadsheetState; import org.sakaiproject.gradebookng.tool.panels.AddGradeItemPanel; import org.sakaiproject.gradebookng.tool.panels.AssignmentColumnHeaderPanel; import org.sakaiproject.gradebookng.tool.panels.GradeItemCellPanel; @@ -62,6 +63,7 @@ public class GradebookPage extends BasePage { ModalWindow gradeCommentWindow; Form form; + GbSpreadsheetState state; @SuppressWarnings({ "rawtypes", "unchecked", "serial" }) public GradebookPage() { @@ -70,7 +72,9 @@ public GradebookPage() { StopWatch stopwatch = new StopWatch(); stopwatch.start(); Temp.time("GradebookPage init", stopwatch.getTime()); - + + state = new GbSpreadsheetState(); + form = new Form("form"); add(form); @@ -203,7 +207,7 @@ public String getCssClass() { @Override public Component getHeader(String componentId) { - AssignmentColumnHeaderPanel panel = new AssignmentColumnHeaderPanel(componentId, new Model(assignment)); + AssignmentColumnHeaderPanel panel = new AssignmentColumnHeaderPanel(componentId, new Model(assignment), new Model(state)); String category = assignment.getCategoryName(); int order = -1; if (categorizedAssignmentOrder.containsKey(category)) { @@ -260,6 +264,29 @@ 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(); + if (state.isCategoriesEnabled()) { + add(new AttributeModifier("class", "on")); + } + } + @Override + protected void onSubmit(AjaxRequestTarget target, Form form) { + state.setCategoriesEnabled(!state.isCategoriesEnabled()); + + if (state.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 groups = this.businessService.getSiteSectionsAndGroups(); diff --git a/tool/src/java/org/sakaiproject/gradebookng/tool/panels/AssignmentColumnHeaderPanel.html b/tool/src/java/org/sakaiproject/gradebookng/tool/panels/AssignmentColumnHeaderPanel.html index aa384690e04f..45e6319ba935 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/tool/panels/AssignmentColumnHeaderPanel.html +++ b/tool/src/java/org/sakaiproject/gradebookng/tool/panels/AssignmentColumnHeaderPanel.html @@ -33,9 +33,7 @@