-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into annotation-tool
- Loading branch information
Showing
41 changed files
with
487 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
$(document).on("turbolinks:load", () => { | ||
if (!shouldRegisterFeedback()) { | ||
return; | ||
} | ||
registerToasts(); | ||
registerSubmitButtonHandler(); | ||
registerFeedbackBodyValidator(); | ||
}); | ||
|
||
var SUBMIT_FEEDBACK_ID = "#submit-feedback"; | ||
|
||
var TOAST_OPTIONS = { | ||
animation: true, | ||
autohide: true, | ||
delay: 6000, // autohide after ... milliseconds | ||
}; | ||
|
||
function shouldRegisterFeedback() { | ||
return $(SUBMIT_FEEDBACK_ID).length > 0; | ||
} | ||
|
||
function registerToasts() { | ||
const toastElements = document.querySelectorAll(".toast"); | ||
[...toastElements].map((toast) => { | ||
new bootstrap.Toast(toast, TOAST_OPTIONS); | ||
}); | ||
} | ||
|
||
function registerSubmitButtonHandler() { | ||
// Invoke the hidden submit button inside the actual Rails form | ||
$("#submit-feedback-form-btn-outside").click(() => { | ||
submitFeedback(); | ||
}); | ||
|
||
// Submit form by pressing Ctrl + Enter | ||
document.addEventListener("keydown", (event) => { | ||
const isModalOpen = $(SUBMIT_FEEDBACK_ID).is(":visible"); | ||
if (isModalOpen && event.ctrlKey && event.key == "Enter") { | ||
submitFeedback(); | ||
} | ||
}); | ||
} | ||
|
||
function registerFeedbackBodyValidator() { | ||
const feedbackBody = document.getElementById("feedback_feedback"); | ||
feedbackBody.addEventListener("input", () => { | ||
validateFeedback(); | ||
}); | ||
} | ||
|
||
function validateFeedback() { | ||
const feedbackBody = document.getElementById("feedback_feedback"); | ||
const validityState = feedbackBody.validity; | ||
if (validityState.tooShort) { | ||
const tooShortMessage = feedbackBody.dataset.tooShortMessage; | ||
feedbackBody.setCustomValidity(tooShortMessage); | ||
} | ||
else if (validityState.valueMissing) { | ||
const valueMissingMessage = feedbackBody.dataset.valueMissingMessage; | ||
feedbackBody.setCustomValidity(valueMissingMessage); | ||
} | ||
else { | ||
// render input valid, so that form will submit | ||
feedbackBody.setCustomValidity(""); | ||
} | ||
|
||
feedbackBody.reportValidity(); | ||
} | ||
|
||
function submitFeedback() { | ||
const submitButton = $("#submit-feedback-form-btn"); | ||
validateFeedback(); | ||
submitButton.click(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,3 +305,7 @@ a { | |
text-decoration: underline; | ||
} | ||
} | ||
|
||
.toast { | ||
background-color: white; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#feedback-btn { | ||
color: white; | ||
|
||
&:focus { | ||
box-shadow: none; | ||
} | ||
|
||
&:hover { | ||
color: #ffc107; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class FeedbacksController < ApplicationController | ||
authorize_resource except: [:create] | ||
|
||
def create | ||
feedback = Feedback.new(feedback_params) | ||
feedback.user_id = current_user.id | ||
@feedback_success = feedback.save | ||
|
||
if @feedback_success | ||
FeedbackMailer.with(feedback: feedback).new_user_feedback_email.deliver_later | ||
end | ||
|
||
respond_to(&:js) | ||
end | ||
|
||
private | ||
|
||
def feedback_params | ||
params.require(:feedback).permit(:title, :feedback, :can_contact) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class FeedbackMailer < ApplicationMailer | ||
default from: DefaultSetting::FEEDBACK_EMAIL | ||
layout false | ||
|
||
# Mail to the MaMpf developers including the new feedback of a user. | ||
def new_user_feedback_email | ||
@feedback = params[:feedback] | ||
reply_to_mail = @feedback.can_contact ? @feedback.user.email : "" | ||
subject = "Feedback: #{@feedback.title}" | ||
mail(to: DefaultSetting::FEEDBACK_EMAIL, | ||
subject: subject, | ||
content_type: "text/plain", | ||
reply_to: reply_to_mail) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Feedback from users regarding MaMpf itself. | ||
class Feedback < ApplicationRecord | ||
belongs_to :user | ||
|
||
BODY_MIN_LENGTH = 10 | ||
BODY_MAX_LENGTH = 10_000 | ||
validates :feedback, length: { minimum: BODY_MIN_LENGTH, | ||
maximum: BODY_MAX_LENGTH }, | ||
allow_blank: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.