RfCs: Allow filtering for any states
We want to differentiate between those RfCs explicitly marked as solved, those potentially solved since the author reached the maximum score, and those being unsolved where the author has not yet reached the full score yet.
This commit is contained in:

committed by
Dominic Sauer

parent
d72139cf04
commit
7cc4fb00c6
@ -33,4 +33,8 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
def self.ransackable_attributes(_auth_object = nil)
|
||||
[]
|
||||
end
|
||||
|
||||
def self.ransackable_scopes(_auth_object = nil)
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,8 @@ class RequestForComment < ApplicationRecord
|
||||
# SOLVED: The author explicitly marked the RfC as solved.
|
||||
# SOFT_SOLVED: The author did not mark the RfC as solved but reached the maximum score in the corresponding exercise at any time.
|
||||
# ONGOING: The author did not mark the RfC as solved and did not reach the maximum score in the corresponding exercise yet.
|
||||
STATE = [SOLVED = :solved, SOFT_SOLVED = :soft_solved, ONGOING = :unsolved].freeze
|
||||
# ALL: Any RfC, regardless of the author marking it as solved or reaching the maximum score in the corresponding exercise.
|
||||
STATE = [SOLVED = :solved, SOFT_SOLVED = :soft_solved, ONGOING = :unsolved, ALL = :all].freeze
|
||||
|
||||
belongs_to :submission
|
||||
belongs_to :exercise
|
||||
@ -59,6 +60,21 @@ class RequestForComment < ApplicationRecord
|
||||
end
|
||||
|
||||
class << self
|
||||
def state(filter = RequestForComment::ALL)
|
||||
# This method is used as a scope filter for Ransack
|
||||
|
||||
case filter.to_sym
|
||||
when RequestForComment::SOLVED
|
||||
where(solved: true)
|
||||
when RequestForComment::SOFT_SOLVED
|
||||
unsolved.where(full_score_reached: true)
|
||||
when RequestForComment::ONGOING
|
||||
unsolved.where(full_score_reached: false)
|
||||
else # 'all'
|
||||
all
|
||||
end
|
||||
end
|
||||
|
||||
def with_last_activity
|
||||
joins('join "submissions" s on s.id = request_for_comments.submission_id ' \
|
||||
'left outer join "files" f on f.context_id = s.id ' \
|
||||
@ -81,8 +97,8 @@ class RequestForComment < ApplicationRecord
|
||||
%w[exercise submission]
|
||||
end
|
||||
|
||||
def ransackable_attributes(_auth_object = nil)
|
||||
%w[solved]
|
||||
def ransackable_scopes(_auth_object = nil)
|
||||
%w[state]
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -9,7 +9,7 @@ h1 = RequestForComment.model_name.human(count: 2)
|
||||
= f.search_field(:exercise_title_cont, class: 'form-control', placeholder: t('activerecord.attributes.request_for_comments.exercise'))
|
||||
.col-auto.mt-3.mt-md-0
|
||||
= f.label(:title_cont, t('request_for_comments.solved'), class: 'visually-hidden form-label')
|
||||
= f.select(:solved_not_eq, [[t('request_for_comments.show_all'), 2], [t('request_for_comments.show_unsolved'), 1], [t('request_for_comments.show_solved'), 0]])
|
||||
= f.select(:state, [[t('request_for_comments.show_all'), RequestForComment::ALL], [t('request_for_comments.show_unsolved'), RequestForComment::ONGOING], [t('request_for_comments.show_soft_solved'), RequestForComment::SOFT_SOLVED], [t('request_for_comments.show_solved'), RequestForComment::SOLVED]])
|
||||
- unless current_user.consumer.rfc_visibility_study_group?
|
||||
.row
|
||||
.col
|
||||
|
Reference in New Issue
Block a user