Skip to content

Commit

Permalink
SAK-41175 Allow floating point numbers in rubrics points (sakaiprojec…
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored Feb 5, 2020
1 parent 91412fd commit 3218c84
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
.criterion {
&.sakai-rubric-criterion,
&.sakai-rubric-criterion-preview,
&.sakai-rubric-criterion-grading,
&.sakai-rubric-criteria-grading,
&.sakai-rubric-criterion-student,
&.sakai-rubric-criterion-readonly {
width: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CriterionOutcome implements Serializable {
private boolean pointsAdjusted;

@NonNull
private Integer points;
private Double points;

@Lob
@Column(length = 65535)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class Rating implements Modifiable, Serializable, Cloneable {

@Lob
private String description;
private Integer points;
private Double points;

@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ private String createCriterionJsonPayload(String associatedItemId, String evalua
int index = 0;
boolean pointsAdjusted = false;
String points = null;
String selectedRatingId = null;

String siteId = formPostParameters.get("siteId");

Expand All @@ -478,7 +477,8 @@ private String createCriterionJsonPayload(String associatedItemId, String evalua
}
index++;

final String selectedRatingPoints = criterionData.getValue().get(RubricsConstants.RBCS_PREFIX + evaluatedItemId + "-"+ associatedItemId + "-criterion");
String selectedRatingPoints = criterionData.getValue().get(RubricsConstants.RBCS_PREFIX + evaluatedItemId + "-"+ associatedItemId + "-criterion");
String selectedRatingId = criterionData.getValue().get(RubricsConstants.RBCS_PREFIX + evaluatedItemId + "-"+ associatedItemId + "-criterionrating");

if (StringUtils.isNotBlank(criterionData.getValue().get(RubricsConstants.RBCS_PREFIX + evaluatedItemId + "-" + associatedItemId + "-criterion-override"))) {
pointsAdjusted = true;
Expand All @@ -488,15 +488,8 @@ private String createCriterionJsonPayload(String associatedItemId, String evalua
points = selectedRatingPoints;
}

Criterion criterion = criterions.get(criterionData.getKey());
Optional<Rating> rating = criterion.getRatings().stream().filter(c -> String.valueOf(c.getPoints()).equals(selectedRatingPoints)).findFirst();

if (rating.isPresent()) {
selectedRatingId = String.valueOf(rating.get().getId());
}

if (StringUtils.isEmpty(points)){
points = "0";
points = "0.0";
}

criterionJsonData += String.format("{ \"criterionId\" : \"%s\", \"points\" : \"%s\", " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {RubricsElement} from "./rubrics-element.js";
import {html} from "/webcomponents/assets/lit-element/lit-element.js";
import {ifDefined} from '/webcomponents/assets/lit-html/directives/if-defined.js';
import {SakaiRubricGradingComment} from "./sakai-rubric-grading-comment.js";
import {tr} from "./sakai-rubrics-language.js";

Expand Down Expand Up @@ -98,17 +99,19 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
</strong>
</div>
${this.rubricAssociation.parameters.fineTunePoints ?
html`<input type="number" min="0" max="${c.pointrange.high}"
@keypress="${this.validateInput}"
title="${tr("point_override_details")}"
data-criterion-id="${c.id}"
class="fine-tune-points form-control hide-input-arrows"
id="rbcs-${this.evaluatedItemId}-${this.entityId}-criterion-override-${c.id}"
name="rbcs-${this.evaluatedItemId}-${this.entityId}-criterion-override-${c.id}"
@input="${this.finetuneRating}" .value="${c.pointoverride}">`
: html``
html`
<input type="number" step="0.01" min="0" max="${ifDefined(c.pointrange ? c.pointrange.high : undefined)}"
title="${tr("point_override_details")}"
data-criterion-id="${c.id}"
name="rbcs-${this.evaluatedItemId}-${this.entityId}-criterion-override-${c.id}"
class="fine-tune-points form-control hide-input-arrows"
@input=${this.fineTuneRating}
.value="${c.pointoverride}"
/>
` : ""
}
<input aria-labelledby="${tr("points")}" type="hidden" id="rbcs-${this.evaluatedItemId}-${this.entityId}-criterion-${c.id}" name="rbcs-${this.evaluatedItemId}-${this.entityId}-criterion-${c.id}" .value="${c.selectedvalue}">
<input type="hidden" name="rbcs-${this.evaluatedItemId}-${this.entityId}-criterionrating-${c.id}" .value="${c.selectedRatingId}">
</div>
</div>
`)}
Expand All @@ -124,14 +127,6 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
`;
}

validateInput(e) {

if (!(( e.charCode >= 48 && e.charCode <= 57 ) || e.charCode === 9 )){
e.preventDefault();
return false;
}
}

updateComment(e) {

this.criteria.forEach(c => {
Expand Down Expand Up @@ -192,9 +187,9 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
this.totalPoints = this.criteria.reduce((a, c) => {

if (c.pointoverride) {
return a + parseInt(c.pointoverride);
return a + parseFloat(c.pointoverride);
} else if (c.selectedvalue) {
return a + parseInt(c.selectedvalue);
return a + parseFloat(c.selectedvalue);
} else {
return a;
}
Expand Down Expand Up @@ -229,23 +224,17 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
this.updateTotalPoints();
}

finetuneRating(e) {

var max = parseInt(e.target.getAttribute("max"));
var value = parseInt(e.target.value);
fineTuneRating(e) {

if ( value > max){
e.target.value = max;
e.preventDefault();
}
var value = e.target.value;

var criterion = this.criteria.find(c => c.id == e.target.dataset.criterionId);

criterion.pointoverride = e.target.value;
criterion.pointoverride = value;
if (criterion.selectedvalue) {
this.totalPoints = this.totalPoints - criterion.selectedvalue + parseInt(criterion.pointoverride);
this.totalPoints = this.totalPoints - criterion.selectedvalue + parseFloat(criterion.pointoverride);
} else {
this.totalPoints = this.totalPoints + parseInt(criterion.pointoverride);
this.totalPoints = this.totalPoints + parseFloat(criterion.pointoverride);
}

this.dispatchEvent(new CustomEvent("rubric-ratings-changed", { bubbles: true, composed: true }));
Expand All @@ -263,7 +252,7 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {

criteria.forEach(c => {
let points = this.querySelector(`#criterion_row_${c.id} > .criterion-actions > div > .points-display`).innerHTML;
let detail = { evaluatedItemId: this.evaluatedItemId, entityId: this.entityId, criterionId: c.id, value: parseInt(points) };
let detail = { evaluatedItemId: this.evaluatedItemId, entityId: this.entityId, criterionId: c.id, value: parseFloat(points) };
this.dispatchEvent(new CustomEvent("rubric-rating-changed", {detail: detail, bubbles: true, composed: true}));
});
}
Expand All @@ -274,7 +263,7 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
return '';
}

if ((ovrdvl || ovrdvl === 0) && (parseInt(ovrdvl) !== parseInt(selected))) {
if ((ovrdvl || ovrdvl === 0) && (parseFloat(ovrdvl) !== parseFloat(selected))) {
return 'strike';
} else {
return '';
Expand All @@ -295,7 +284,7 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
var clickedRatingElement = this.querySelector(`#rating-item-${ratingId}`);
if (clickedRatingElement.classList.contains("selected")) {
clickedRatingElement.classList.remove("selected");
criterion.selectedvalue = 0;
criterion.selectedvalue = 0.0;
criterion.selectedRatingId = "";
criterion.pointoverride = "0";
} else {
Expand All @@ -316,7 +305,7 @@ export class SakaiRubricCriteriaGrading extends RubricsElement {
// remove the strike out from the clicked points value
this.querySelector(`#points-display-${criterionId}`).classList.remove("strike");

var detail = { evaluatedItemId: this.evaluatedItemId, entityId: this.entityId, criterionId: criterionId, value: criterion.selectedvalue };
var detail = { evaluatedItemId: this.evaluatedItemId, entityId: this.entityId, criterionId: criterionId, value: criterion.selectedvalue, ratingId: criterion.selectedRatingId };
this.dispatchEvent(new CustomEvent("rubric-rating-changed", {detail: detail, bubbles: true, composed: true}));

// Dispatch an event for each rating. We have to do this to give tools like
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {RubricsElement} from "./rubrics-element.js";
import {html} from "/webcomponents/assets/lit-element/lit-element.js";
import {ifDefined} from '/webcomponents/assets/lit-html/directives/if-defined.js';
import {tr} from "./sakai-rubrics-language.js";

export class SakaiRubricCriterionRatingEdit extends RubricsElement {
Expand All @@ -9,8 +10,8 @@ export class SakaiRubricCriterionRatingEdit extends RubricsElement {
return {
rating: { type: Object },
criterionId: { attribute: "criterion-id", type: String },
minpoints: { type: Number },
maxpoints: { type: Number },
minpoints: Number,
maxpoints: Number,
};
}

Expand Down Expand Up @@ -52,7 +53,7 @@ export class SakaiRubricCriterionRatingEdit extends RubricsElement {
</div>
<div class="form-group points">
<label for="rating-points-${this.rating.id}"><sr-lang key="points" /></label>
<input type="number" id="rating-points-${this.rating.id}" class="form-control hide-input-arrows" name="quantity" .value="${this.rating.points}" min="${this.minpoints}" max="${this.maxpoints}">
<input type="number" id="rating-points-${this.rating.id}" class="form-control hide-input-arrows" name="quantity" .value="${this.rating.points}" min="${ifDefined(this.minpoints)}" max="${ifDefined(this.maxpoints)}" />
</div>
</div>
<div class="form-group">
Expand Down
7 changes: 5 additions & 2 deletions samigo/samigo-app/src/webapp/js/samigo-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ $(function () {
inputs.appendChild(input);
}
}
input.setAttribute("value", e.detail.value);
input.setAttribute("value", "criterionrating" === type ? e.detail.ratingId : e.detail.value);
};

$('body').on('total-points-updated', function (e) {
Expand All @@ -170,7 +170,10 @@ $(function () {

$('body').on('rubric-rating-tuned', e => addRubricInputs(e, "criterion-override"));

$('body').on('rubric-rating-changed', e => addRubricInputs(e, "criterion"));
$('body').on('rubric-rating-changed', e => {
addRubricInputs(e, "criterion");
addRubricInputs(e, "criterionrating");
});

$('body').on('update-state-details', e => addRubricInputs(e, "state-details"));

Expand Down

0 comments on commit 3218c84

Please sign in to comment.