Skip to content

Commit

Permalink
Edit Scheduling Subpart: Subpart Credit
Browse files Browse the repository at this point in the history
- Max Units made editable when editing Variable Min/Max credit without the need to change the credit type first (when editing existing credit information)
- fixed an issue when no units or max units are provided (for a type that requires units/max units) or when the provided units are not a number
  • Loading branch information
tomas-muller committed Nov 25, 2024
1 parent d8d8a58 commit 0474d51
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ private void doLoad(SchedulingSubpart ss, String subpartId ) {
form.setCreditType(credit.getCreditType().getUniqueId());
form.setCreditUnitType(credit.getCreditUnitType().getUniqueId());
if (credit instanceof FixedCreditUnitConfig){
form.setUnits(((FixedCreditUnitConfig) credit).getFixedUnits());
form.setUnits(toString(((FixedCreditUnitConfig) credit).getFixedUnits()));
} else if (credit instanceof VariableFixedCreditUnitConfig){
form.setUnits(((VariableFixedCreditUnitConfig) credit).getMinUnits());
form.setMaxUnits(((VariableFixedCreditUnitConfig) credit).getMaxUnits());
form.setUnits(toString(((VariableFixedCreditUnitConfig) credit).getMinUnits()));
form.setMaxUnits(toString(((VariableFixedCreditUnitConfig) credit).getMaxUnits()));
if (credit instanceof VariableRangeCreditUnitConfig){
form.setFractionalIncrementsAllowed(((VariableRangeCreditUnitConfig) credit).isFractionalIncrementsAllowed());
}
Expand Down Expand Up @@ -444,18 +444,27 @@ private void doUpdate(SchedulingSubpart ss, SchedulingSubpartDAO sdao, boolean t
CourseCreditUnitConfig origConfig = ss.getCredit();
ss.setCredit(null);
sdao.getSession().remove(origConfig);
ss.setCredit(CourseCreditUnitConfig.createCreditUnitConfigOfFormat(form.getCreditFormat(), form.getCreditType(), form.getCreditUnitType(), form.getUnits(), form.getMaxUnits(), form.getFractionalIncrementsAllowed(), Boolean.valueOf(false)));
ss.setCredit(CourseCreditUnitConfig.createCreditUnitConfigOfFormat(
form.getCreditFormat(), form.getCreditType(), form.getCreditUnitType(),
toFloat(form.getUnits()), toFloat(form.getMaxUnits()),
form.getFractionalIncrementsAllowed(), Boolean.valueOf(false)));
ss.getCredit().setOwner(ss);
}
} else {
CourseCreditUnitConfig origConfig = ss.getCredit();
ss.setCredit(null);
sdao.getSession().remove(origConfig);
ss.setCredit(CourseCreditUnitConfig.createCreditUnitConfigOfFormat(form.getCreditFormat(), form.getCreditType(), form.getCreditUnitType(), form.getUnits(), form.getMaxUnits(), form.getFractionalIncrementsAllowed(), Boolean.valueOf(false)));
ss.setCredit(CourseCreditUnitConfig.createCreditUnitConfigOfFormat(
form.getCreditFormat(), form.getCreditType(), form.getCreditUnitType(),
toFloat(form.getUnits()), toFloat(form.getMaxUnits()),
form.getFractionalIncrementsAllowed(), Boolean.valueOf(false)));
ss.getCredit().setOwner(ss);
}
} else {
ss.setCredit(CourseCreditUnitConfig.createCreditUnitConfigOfFormat(form.getCreditFormat(), form.getCreditType(), form.getCreditUnitType(), form.getUnits(), form.getMaxUnits(), form.getFractionalIncrementsAllowed(), Boolean.valueOf(false)));
ss.setCredit(CourseCreditUnitConfig.createCreditUnitConfigOfFormat(
form.getCreditFormat(), form.getCreditType(), form.getCreditUnitType(),
toFloat(form.getUnits()), toFloat(form.getMaxUnits()),
form.getFractionalIncrementsAllowed(), Boolean.valueOf(false)));
ss.getCredit().setOwner(ss);
}
}
Expand Down Expand Up @@ -485,6 +494,19 @@ private void doUpdate(SchedulingSubpart ss, SchedulingSubpartDAO sdao, boolean t
sdao.getSession().flush();
}

protected static Float toFloat(String value) {
try {
return Float.valueOf(value);
} catch (Exception e) {
return 0f;
}
}

protected static String toString(Float value) {
if (value == null) return "";
return value.toString();
}

protected void setupChildren(SchedulingSubpart ss) {
DatePattern selectedDatePattern = (form.getDatePattern() < 0 ? (ss.canInheritParentPreferences() ? ss.getParentSubpart().effectiveDatePattern() : ss.getSession().getDefaultDatePatternNotNull()) : DatePatternDAO.getInstance().get(form.getDatePattern()));
try {
Expand Down
7 changes: 7 additions & 0 deletions WebContent/help/Release-Notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
</line>
</description>
</item>
<item>
<name>Edit Scheduling Subpart: Subpart Credit</name>
<description>
<line>Max Units made editable when editing Variable Min/Max credit without the need to change the credit type first (when editing existing credit information).</line>
<line>Fixed an issue when no units or max units are provided (for a type that requires units/max units) or when the provided units are not a number.</line>
</description>
</item>
<item>
<name>Course Timetabling Solver: Optimization</name>
<description>
Expand Down
2 changes: 1 addition & 1 deletion WebContent/user/schedulingSubpartEdit.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
<td nowrap><loc:message name="propertyMaxUnits"/></td>
<td>
<s:textfield name="form.maxUnits" maxlength="4" size="4"
disabled="%{form.creditFormat != 'variableRange'}"/>
disabled="%{form.creditFormat != 'variableRange' && form.creditFormat != 'variableMinMax'}"/>
</td>
</tr>
<tr>
Expand Down

0 comments on commit 0474d51

Please sign in to comment.