diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index f9e7137e..90e7f871 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -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 diff --git a/app/policies/request_for_comment_policy.rb b/app/policies/request_for_comment_policy.rb index f592e3bd..a0762abf 100644 --- a/app/policies/request_for_comment_policy.rb +++ b/app/policies/request_for_comment_policy.rb @@ -27,4 +27,8 @@ class RequestForCommentPolicy < ApplicationPolicy def index? everyone end + + def create_comment_exercise? + everyone + end end diff --git a/app/views/exercises/_comment_exercise_dialogcontent.html.slim b/app/views/exercises/_comment_exercise_dialogcontent.html.slim new file mode 100644 index 00000000..89d1fd41 --- /dev/null +++ b/app/views/exercises/_comment_exercise_dialogcontent.html.slim @@ -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') diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb index 28574ade..592ceb6b 100644 --- a/app/views/request_for_comments/show.html.erb +++ b/app/views/request_for_comments/show.html.erb @@ -1,5 +1,5 @@
<%
user = @request_for_comment.user
@@ -20,14 +20,18 @@
<%= t('activerecord.attributes.request_for_comments.question')%>: <%= t('request_for_comments.no_question') %>
<% end %>
+
+
<% if (policy(@request_for_comment).mark_as_solved? and not @request_for_comment.solved?) %>
-
+
<% elsif (@request_for_comment.solved?) %>
-
+
<% else %>
<% end %>
+
+
<% if @current_user.admin? && user.is_a?(ExternalUser) %>
@@ -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') %>