add feedback for exercises

This commit is contained in:
Thomas Hille
2017-03-30 22:06:17 +02:00
parent ed485f32e6
commit 3f398c6047
7 changed files with 95 additions and 5 deletions

View File

@ -32,6 +32,10 @@ class RequestForCommentsController < ApplicationController
end
end
def submit
end
# GET /request_for_comments/1
# GET /request_for_comments/1.json
def show
@ -63,6 +67,20 @@ class RequestForCommentsController < ApplicationController
authorize!
end
def create_comment_exercise
old = UserExerciseFeedback.find_by(exercise_id: params[:exercise_id], user_id: current_user.id, user_type: current_user.class.name)
if old
old.delete
end
uef = UserExerciseFeedback.new(comment_params)
if uef.save
render(json: {success: "true"})
else
render(json: {success: "false"})
end
end
# DELETE /request_for_comments/1
# DELETE /request_for_comments/1.json
def destroy
@ -74,6 +92,10 @@ class RequestForCommentsController < ApplicationController
authorize!
end
def comment_params
params.permit(:exercise_id, :feedback_text).merge(user_id: current_user.id, user_type: current_user.class.name)
end
private
# Use callbacks to share common setup or constraints between actions.
def set_request_for_comment
@ -85,4 +107,5 @@ class RequestForCommentsController < ApplicationController
# we are using the current_user.id here, since internal users are not able to create comments. The external_user.id is a primary key and does not require the consumer_id to be unique.
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(user_id: current_user.id, user_type: current_user.class.name)
end
end

View File

@ -27,4 +27,8 @@ class RequestForCommentPolicy < ApplicationPolicy
def index?
everyone
end
def create_comment_exercise?
everyone
end
end

View File

@ -0,0 +1,5 @@
h5 =t('exercises.implement.comment.addComment')
textarea#commentOnExercise.form-control(style='resize:none;')
p=''
button#addCommentExerciseButton.btn.btn-block.btn-primary(type='button') =t('exercises.implement.comment.addCommentButton')

View File

@ -1,5 +1,5 @@
<div class="list-group">
<h4 id ="exercise_caption" class="list-group-item-heading" data-rfc-id = "<%= @request_for_comment.id %>" ><%= link_to(@request_for_comment.exercise.title, [:implement, @request_for_comment.exercise]) %></h4>
<h4 id ="exercise_caption" class="list-group-item-heading" data-exercise-id="<%=@request_for_comment.exercise.id%>" data-comment-exercise-url="<%=create_comment_exercise_request_for_comment_path%>" data-rfc-id = "<%= @request_for_comment.id %>" ><%= link_to(@request_for_comment.exercise.title, [:implement, @request_for_comment.exercise]) %></h4>
<p class="list-group-item-text">
<%
user = @request_for_comment.user
@ -20,14 +20,18 @@
<u><%= t('activerecord.attributes.request_for_comments.question')%>:</u> <%= t('request_for_comments.no_question') %>
<% end %>
</h5>
<button class="btn btn-block btn-primary" id="comment-exercise-button"><%= t('request_for_comments.comment_exercise') %></button>
<% if (policy(@request_for_comment).mark_as_solved? and not @request_for_comment.solved?) %>
<button class="btn btn-default" id="mark-as-solved-button"><%= t('request_for_comments.mark_as_solved') %></button>
<button class="btn btn-block btn-primary" id="mark-as-solved-button"><%= t('request_for_comments.mark_as_solved') %></button>
<% elsif (@request_for_comment.solved?) %>
<button type="button" class="btn btn-success"><%= t('request_for_comments.solved') %></button>
<button type="button" class="btn btn-block btn-success"><%= t('request_for_comments.solved') %></button>
<% else %>
<% end %>
<% if @current_user.admin? && user.is_a?(ExternalUser) %>
<br>
<br>
@ -58,10 +62,13 @@ also, all settings from the rails model needed for the editor configuration in t
<% end %>
<%= render('shared/modal', id: 'comment-modal', title: t('exercises.implement.comment.dialogtitle'), template: 'exercises/_comment_dialogcontent') %>
<%= render('shared/modal', id: 'comment-exercise-modal', title: t('exercises.implement.comment.addCommentExercise'), template: 'exercises/_comment_exercise_dialogcontent') %>
<script type="text/javascript">
var solvedButton = $('#mark-as-solved-button');
var commentOnExerciseButton = $('#comment-exercise-button');
var addCommentExerciseButton = $('#addCommentExerciseButton')
solvedButton.on('click', function(event){
var jqrequest = $.ajax({
@ -77,6 +84,29 @@ also, all settings from the rails model needed for the editor configuration in t
});
});
// comment exercise
commentOnExerciseButton.on('click', function(){
$('#comment-exercise-modal').modal('show');
})
addCommentExerciseButton.on('click', function(event){
var comment = $('#commentOnExercise').val();
var url = $('#exercise_caption').data('comment-exercise-url');
var jqrequest = $.ajax({
dataType: 'json',
method: 'POST',
url: url,
data: {
exercise_id: $('#exercise_caption').data('exercise-id'),
feedback_text: comment
},
dataType: 'json'
});
$('#comment-exercise-modal').modal('hide');
});
// set file paths for ace
var ACE_FILES_PATH = '/assets/ace/';
_.each(['modePath', 'themePath', 'workerPath'], function(attribute) {
@ -165,6 +195,27 @@ also, all settings from the rails model needed for the editor configuration in t
jqxhr.fail(ajaxError);
}
function createCommentOnExercise(file_id, row, editor, commenttext){
var jqxhr = $.ajax({
data: {
comment: {
file_id: file_id,
row: row,
column: 0,
text: commenttext,
request_id: $('h4#exercise_caption').data('rfc-id')
}
},
dataType: 'json',
method: 'POST',
url: "/comments"
});
jqxhr.done(function(response){
setAnnotations(editor, file_id);
});
jqxhr.fail(ajaxError);
}
function handleSidebarClick(e) {
var target = e.domEvent.target;
var editor = e.editor;

View File

@ -270,8 +270,10 @@ de:
line: Zeile
dialogtitle: Kommentar hinzufügen
others: Andere Kommentare auf dieser Zeile
addCommentExercise: Aufgabe kommentieren
addyours: Fügen Sie Ihren Kommentar hinzu
addComment: Kommentieren
addComment: Hier haben Sie die Möglichkeit Ihr Feedback zu dieser Aufgabe zu geben. Fanden Sie die Aufgabe zu leicht oder schwer? War die Beschreibung eventuell nicht gut?
addCommentButton: Kommentar abschicken
removeAllOnLine: Meine Kommentare auf dieser Zeile löschen
listing: Die neuesten Kommentaranfragen
request: "Kommentaranfrage stellen"
@ -399,6 +401,7 @@ de:
no_question: "Der Autor hat keine Frage zu dieser Anfrage gestellt."
mark_as_solved: "Diese Frage als beantwortet markieren"
solved: "Diese Frage wurde erfolgreich beantwortet"
comment_exercise: "Ich möchte die Aufgabenstellung kommentieren"
sessions:
create:
failure: Fehlerhafte E-Mail oder Passwort.

View File

@ -292,7 +292,9 @@ en:
dialogtitle: Comment on this line
others: Other comments on this line
addyours: Add your comment
addComment: Comment this
addCommentExercise: Comment this exercise
addComment: You can give feedback to this exercise. Did you find this exercise particulary easy or difficult? Was the description easy to understand?
addCommentButton: Comment this
removeAllOnLine: Remove my comments on this line
listing: Listing the newest comment requests
request: "Request Comments"
@ -420,6 +422,7 @@ en:
no_question: "The author did not enter a question for this request."
mark_as_solved: "Mark this question as answered"
solved: "This question has been answered"
comment_exercise: "I would like to give feedback for this exercise"
sessions:
create:
failure: Invalid email or password.

View File

@ -10,6 +10,7 @@ Rails.application.routes.draw do
resources :request_for_comments do
member do
get :mark_as_solved
post :create_comment_exercise
end
end
resources :comments, except: [:destroy] do