Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sakaiproject/sakai
Browse files Browse the repository at this point in the history
  • Loading branch information
steveswinsburg committed Feb 12, 2018
2 parents 0ba2dd9 + 28a0e35 commit 2de2c16
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ settingspage.gradingschema.type = Grade Type
settingspage.gradingschema.grade = Grade
settingspage.gradingschema.minpercent = Minimum %
settingspage.gradingschema.emptychart = There are no students with course grades.
settingspage.gradingschema.add = Add a mapping


settingspage.update.success = The settings were successfully updated
settingspage.update.failure.categorymissingweight = No weight specified for a category, but weightings enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ protected void onSubmit(final AjaxRequestTarget target, final Form<?> f) {
private CategoryDefinition stubCategoryDefinition() {
final CategoryDefinition cd = new CategoryDefinition();
cd.setExtraCredit(false);
cd.setWeight(new Double(0));
cd.setWeight(Double.valueOf(0));
cd.setAssignmentList(Collections.<Assignment>emptyList());
cd.setDropHighest(0);
cd.setDropLowest(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ <h3 class="panel-title">
</tr>
</tbody>
</table>

<div>
<button wicket:id="addMapping" type="submit" class="btn-add-category btn btn-default btn-sm"><wicket:message key="settingspage.gradingschema.add" /></button>
</div>
</div>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IFormModelUpdateListener;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
Expand All @@ -47,6 +48,7 @@
import org.sakaiproject.gradebookng.business.FirstNameComparator;
import org.sakaiproject.gradebookng.business.model.GbUser;
import org.sakaiproject.gradebookng.business.util.FormatHelper;
import org.sakaiproject.gradebookng.tool.component.GbAjaxButton;
import org.sakaiproject.gradebookng.tool.model.GbGradingSchemaEntry;
import org.sakaiproject.gradebookng.tool.model.GbSettings;
import org.sakaiproject.service.gradebook.shared.CourseGrade;
Expand Down Expand Up @@ -221,7 +223,7 @@ protected void populateItem(final ListItem<GbGradingSchemaEntry> item) {
final TextField<Double> minPercent = new TextField<>("minPercent", new PropertyModel<Double>(entry, "minPercent"));
item.add(minPercent);

// attach the onchange behaviour
// attach the onchange behaviours
minPercent.add(new GradingSchemaChangeBehaviour(GradingSchemaChangeBehaviour.ONCHANGE));
grade.add(new GradingSchemaChangeBehaviour(GradingSchemaChangeBehaviour.ONCHANGE));

Expand Down Expand Up @@ -255,6 +257,28 @@ protected void onUpdate(final AjaxRequestTarget target) {
}
});

// button to add a mapping
final GbAjaxButton addMapping = new GbAjaxButton("addMapping") {
private static final long serialVersionUID = 1L;

@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> f) {

// add a new empty mapping to the model data
final List<GbGradingSchemaEntry> entries = getGradingSchemaList();
entries.add(stubGradingSchemaMapping());
SettingsGradingSchemaPanel.this.model.getObject().setGradingSchemaEntries(entries);

// repaint table
target.add(SettingsGradingSchemaPanel.this.schemaWrap);

// Note that we don't need to worry about showing warnings about modifications here as the change notifications will handle
// that once a value has been added to the schema
}
};
addMapping.setDefaultFormProcessing(false);
this.schemaWrap.add(addMapping);

// if there are no grades, display message instead of chart
settingsGradingSchemaPanel
.add(new Label("noStudentsWithGradesMessage", new ResourceModel("settingspage.gradingschema.emptychart")) {
Expand Down Expand Up @@ -533,11 +557,13 @@ private List<GbGradingSchemaEntry> asList(final Map<String, Double> bottomPercen
}

/**
* Convert list of {@link GbGradingSchemaEntry} into a map
* Convert list of {@link GbGradingSchemaEntry} into a map. Note that new entries may be null so they need to be excluded
*/
private Map<String, Double> asMap(final List<GbGradingSchemaEntry> gbGradingSchemaEntries) {
return gbGradingSchemaEntries.stream()
.collect(Collectors.toMap(GbGradingSchemaEntry::getGrade, GbGradingSchemaEntry::getMinPercent));
.filter(e -> StringUtils.isNotBlank(e.getGrade()))
.filter(e -> e.getMinPercent() != null)
.collect(Collectors.toMap(GbGradingSchemaEntry::getGrade, GbGradingSchemaEntry::getMinPercent));
}

/**
Expand Down Expand Up @@ -666,17 +692,27 @@ private void refreshMessages() {
this.target.add(SettingsGradingSchemaPanel.this.unsavedSchema);
}

/**
* Helper to get the gradingschema list from the model
*
* @return
*/
private List<GbGradingSchemaEntry> getGradingSchemaList() {
final List<GbGradingSchemaEntry> schemaList = SettingsGradingSchemaPanel.this.model.getObject().getGradingSchemaEntries();
schemaList.sort(Collections.reverseOrder());
return schemaList;
}
}

/**
* Helper to get the gradingschema list from the model
*
* @return
*/
private List<GbGradingSchemaEntry> getGradingSchemaList() {
final List<GbGradingSchemaEntry> schemaList = SettingsGradingSchemaPanel.this.model.getObject().getGradingSchemaEntries();
schemaList.sort(Collections.reverseOrder());
return schemaList;
}

/**
* Create a new grading schema entry stub
*
* @return {@link GbGradingSchemaEntry}
*/
private GbGradingSchemaEntry stubGradingSchemaMapping() {
final GbGradingSchemaEntry entry = new GbGradingSchemaEntry(null, null);
return entry;
}

}
2 changes: 1 addition & 1 deletion library/src/webapp/content/myworkspace_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<body>
<div class="portletBody">
<h3> Welcome to your personal workspace.</h3>
<p>In Sakai each user has his or her own individual worksite called "Home".
<p>In Sakai each user has an individual worksite called "Home".
Home is a place where you can keep personal documents, create new sites, maintain a
schedule, store resources, and much more.</p>
<p class="instruction">The default information displayed here for a new user can be modified by the Sakai
Expand Down

0 comments on commit 2de2c16

Please sign in to comment.