Skip to content

Commit

Permalink
extra feedback after submitting
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Jun 14, 2021
1 parent 7adf118 commit cba2b54
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
36 changes: 34 additions & 2 deletions app/assets/javascripts/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function initExerciseShow(exerciseId, programmingLanguage, loggedIn, editorShown
$("#activity-feedback-link").data("submission_id") === lastSubmission) {
loadFeedback(`/submissions/${lastSubmission}`, lastSubmission);
}
showFABStatus(status);
setTimeout(enableSubmitButton, 100);
new Toast(I18n.t("js.submission-processed"));
lastSubmission = null;
Expand All @@ -306,11 +307,42 @@ function initExerciseShow(exerciseId, programmingLanguage, loggedIn, editorShown
}

function enableSubmitButton() {
$("#editor-process-btn").prop("disabled", false).removeClass("busy mdi-timer-sand-empty mdi-spin").addClass("mdi-play");
$("#editor-process-btn")
.prop("disabled", false)
.removeClass("busy mdi-timer-sand-empty mdi-spin")
.addClass("mdi-play");
}

function disableSubmitButton() {
$("#editor-process-btn").prop("disabled", true).removeClass("mdi-play").addClass("busy mdi-timer-sand-empty mdi-spin");
$("#editor-process-btn")
.prop("disabled", true)
.removeClass("mdi-play")
.addClass("busy mdi-timer-sand-empty mdi-spin");
}

function showFABStatus(status) {
const fab = document.getElementById("submission-copy-btn");
const icon = fab.children[0];
icon.classList.remove("mdi-pencil");
if (status === "correct") {
fab.classList.add("correct");
icon.classList.add(getPositiveEmoji());
} else {
fab.classList.add("wrong");
icon.classList.add("mdi-emoticon-sad-outline");
}
setTimeout(resetFABStatus, 4000);
}
function resetFABStatus() {
const fab = document.getElementById("submission-copy-btn");
const icon = fab.children[0];
fab.classList.remove("correct", "wrong");
icon.classList.remove(...icon.classList);
icon.classList.add("mdi", "mdi-36", "mdi-pencil");
}
function getPositiveEmoji() {
const emojis = ["check-bold", "thumb-up-outline", "emoticon-happy-outline", "emoticon-excited-outline", "emoticon-cool-outline", "emoticon-kiss-outline", "robot-outline", "unicorn-variant", "cow", "emoticon-poop"];
return "mdi-" + emojis[Math.floor(Math.pow(Math.random(), 3) * emojis.length)];
}

function submissionSuccessful(data, userId) {
Expand Down
17 changes: 17 additions & 0 deletions app/assets/stylesheets/components/btn.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ button.btn-icon {
opacity: 1;
}

.btn-fab {
&.correct {
background-color: $brand-success;
border-color: $brand-success;
}

&.wrong {
background-color: $brand-danger;
border-color: $brand-danger;
}

&.warning {
background-color: $brand-warning;
border-color: $brand-warning;
}
}

.btn-fab + .btn-fab {
margin-left: 20px;
}
Expand Down

0 comments on commit cba2b54

Please sign in to comment.