diff --git a/app/controllers/admin/candidate_controller.rb b/app/controllers/admin/candidate_controller.rb index 7564886..a7d9615 100644 --- a/app/controllers/admin/candidate_controller.rb +++ b/app/controllers/admin/candidate_controller.rb @@ -3,8 +3,11 @@ module Admin class CandidateController < AdminController before_action :collect_quizzes, except: [:login, :auth] + helper_method :sort_column + def index - @candidates = policy_scope Candidate.order(:name) + @candidates = policy_scope Candidate.order("#{sort_column} #{sort_direction}") + .page(params[:page]) end def new @@ -65,5 +68,9 @@ module Admin CandidateMailer.welcome(candidate).deliver_later RecruiterMailer.candidate_created(candidate).deliver_later end + + def sort_column + Candidate.column_names.include?(params[:sort]) ? params[:sort] : 'name' + end end end diff --git a/app/controllers/admin/result_controller.rb b/app/controllers/admin/result_controller.rb index 8675567..697a352 100644 --- a/app/controllers/admin/result_controller.rb +++ b/app/controllers/admin/result_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Admin class ResultController < AdminController - helper_method :sort_column, :sort_direction + helper_method :sort_column # TODO: change context from Candidate to Quiz # bypass pundit lockdowns until completed @@ -30,9 +30,5 @@ module Admin def sort_column Candidate.column_names.include?(params[:sort]) ? params[:sort] : 'completed_at' end - - def sort_direction - %w(asc desc).include?(params[:direction]) ? params[:direction] : 'desc' - end end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 900fa44..f71567b 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -9,6 +9,8 @@ class AdminController < ApplicationController after_action :verify_authorized, except: :index after_action :verify_policy_scoped, only: :index + helper_method :sort_direction + def current_user @current_user ||= User.find_by(id: session[:user]) if session[:user] end @@ -16,6 +18,10 @@ class AdminController < ApplicationController private + def sort_direction + %w(asc desc).include?(params[:direction]) ? params[:direction] : 'desc' + end + def authorize_user session[:request] = request.fullpath redirect_to admin_login_path unless current_user diff --git a/app/views/admin/candidate/index.html.erb b/app/views/admin/candidate/index.html.erb index e2e2302..4dc2cfb 100644 --- a/app/views/admin/candidate/index.html.erb +++ b/app/views/admin/candidate/index.html.erb @@ -9,13 +9,13 @@
Candidate | -Test ID | -Experience | +<%= sortable "name", "Candidate" %> | +<%= sortable "test_hash", "Test ID" %> | +<%= sortable "email" %> | +<%= sortable "experience" %> | Progress | -Completed | -Reminded | +<%= sortable "completed_at", "Completed" %> | +<%= sortable "reminded" %> | Interview? |
---|