Skip to content

Commit

Permalink
WIP - Filter for exercise id on programming group index page
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragrammel committed Sep 15, 2023
1 parent 45c640c commit 34ddb85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/controllers/programming_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class ProgrammingGroupsController < ApplicationController
before_action :set_programming_group, only: %i[destroy]

def index
@programming_groups = ProgrammingGroup.all.paginate(page: params[:page], per_page: per_page_param)
@search = ProgrammingGroup.ransack(params[:q], {auth_object: current_user})
@programming_groups = @search.result.includes(:exercise).order(:id).paginate(page: params[:page], per_page: per_page_param)
authorize!
end

Expand Down
3 changes: 2 additions & 1 deletion app/models/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Exercise < ApplicationRecord
has_many :programming_groups

scope :with_submissions, -> { where('id IN (SELECT exercise_id FROM submissions)') }
scope :with_programming_groups, -> { where('id IN (SELECT DISTINCT exercise_id FROM programming_groups)') }

validate :valid_main_file?
validate :valid_submission_deadlines?
Expand Down Expand Up @@ -612,7 +613,7 @@ def last_submission_per_contributor
end

def self.ransackable_attributes(_auth_object = nil)
%w[title]
%w[title id]
end

def self.ransackable_associations(_auth_object = nil)
Expand Down
8 changes: 8 additions & 0 deletions app/models/programming_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def users=(users)
end
end

def self.ransackable_attributes(_auth_object = nil)
%w[id exercise_id]
end

def self.ransackable_associations(_auth_object = nil)
%w[exercise]
end

private

def min_group_size
Expand Down

0 comments on commit 34ddb85

Please sign in to comment.