diff --git a/app/controllers/concerns/submission_scoring.rb b/app/controllers/concerns/submission_scoring.rb index 35de4ba5..7da26e8c 100644 --- a/app/controllers/concerns/submission_scoring.rb +++ b/app/controllers/concerns/submission_scoring.rb @@ -47,6 +47,14 @@ module SubmissionScoring end end submission.update(score: score) + if submission.normalized_score == 1.0 + Thread.new do + RequestForComment.where(exercise_id: submission.exercise_id, user_id: submission.user_id, user_type: submission.user_type).each{ |rfc| + rfc.full_score_reached = true + rfc.save + } + end + end outputs end end diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index 4fd19a92..2f8219a9 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -20,7 +20,7 @@ class RequestForCommentsController < ApplicationController .group('request_for_comments.id, request_for_comments.user_id, request_for_comments.exercise_id, request_for_comments.file_id, request_for_comments.question, request_for_comments.created_at, request_for_comments.updated_at, request_for_comments.user_type, request_for_comments.solved, - request_for_comments.submission_id, request_for_comments.row_number') # ugly, but rails wants it this way + request_for_comments.full_score_reached, request_for_comments.submission_id, request_for_comments.row_number') # ugly, but rails wants it this way .select('request_for_comments.*, max(comments.updated_at) as last_comment') .search(params[:q]) @request_for_comments = @search.result.order('created_at DESC').paginate(page: params[:page], total_entries: @search.result.length) diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb index 71a2fdd1..d0c300b6 100644 --- a/app/models/request_for_comment.rb +++ b/app/models/request_for_comment.rb @@ -52,6 +52,6 @@ class RequestForComment < ActiveRecord::Base private def self.row_number_user_sql - select("id, user_id, exercise_id, file_id, question, created_at, updated_at, user_type, solved, submission_id, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql + select("id, user_id, exercise_id, file_id, question, created_at, updated_at, user_type, solved, full_score_reached, submission_id, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql end end diff --git a/app/views/request_for_comments/index.html.slim b/app/views/request_for_comments/index.html.slim index a081dd55..585d518c 100644 --- a/app/views/request_for_comments/index.html.slim +++ b/app/views/request_for_comments/index.html.slim @@ -27,6 +27,9 @@ h1 = RequestForComment.model_name.human(count: 2) - if request_for_comment.solved? td span class="fa fa-check" aria-hidden="true" + - elsif request_for_comment.full_score_reached + td + span class="fa fa-check" style="color:darkgrey" aria-hidden="true" - else td = '' td = link_to(request_for_comment.exercise.title, request_for_comment) diff --git a/db/migrate/20180130172021_add_reached_full_score_to_request_for_comment.rb b/db/migrate/20180130172021_add_reached_full_score_to_request_for_comment.rb new file mode 100644 index 00000000..45a488b4 --- /dev/null +++ b/db/migrate/20180130172021_add_reached_full_score_to_request_for_comment.rb @@ -0,0 +1,15 @@ +class AddReachedFullScoreToRequestForComment < ActiveRecord::Migration + def up + add_column :request_for_comments, :full_score_reached, :boolean, default: false + RequestForComment.all.each { |rfc| + if (rfc.submission.exercise.has_user_solved(rfc.user)) + rfc.full_score_reached = true + rfc.save + end + } + end + + def down + remove_column :request_for_comments, :full_score_reached + end +end diff --git a/db/schema.rb b/db/schema.rb index 3ed07240..faeda040 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171120153705) do +ActiveRecord::Schema.define(version: 20180130172021) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -270,16 +270,17 @@ ActiveRecord::Schema.define(version: 20171120153705) do end create_table "request_for_comments", force: :cascade do |t| - t.integer "user_id", null: false - t.integer "exercise_id", null: false - t.integer "file_id", null: false + t.integer "user_id", null: false + t.integer "exercise_id", null: false + t.integer "file_id", null: false t.datetime "created_at" t.datetime "updated_at" - t.string "user_type", limit: 255 + t.string "user_type", limit: 255 t.text "question" - t.boolean "solved", default: false + t.boolean "solved", default: false t.integer "submission_id" t.text "thank_you_note" + t.boolean "full_score_reached", default: false end create_table "searches", force: :cascade do |t| @@ -354,8 +355,8 @@ ActiveRecord::Schema.define(version: 20171120153705) do t.integer "working_time_seconds" t.string "feedback_text" t.integer "user_estimated_worktime" - t.datetime "created_at", default: '2017-11-20 18:20:25', null: false - t.datetime "updated_at", default: '2017-11-20 18:20:25', null: false + t.datetime "created_at", default: '2018-01-30 17:39:22', null: false + t.datetime "updated_at", default: '2018-01-30 17:39:22', null: false end create_table "user_exercise_interventions", force: :cascade do |t|