From fbbc0edebe1039574014c640d182b977b10b57f8 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Fri, 24 Feb 2017 15:54:11 -0600 Subject: [PATCH] paginate and sort candidates list comletes #99 --- app/controllers/admin/candidate_controller.rb | 9 ++++++++- app/controllers/admin/result_controller.rb | 6 +----- app/controllers/admin_controller.rb | 6 ++++++ app/views/admin/candidate/index.html.erb | 13 +++++++------ 4 files changed, 22 insertions(+), 12 deletions(-) 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 @@ - - - - + + + + - - + + @@ -36,4 +36,5 @@ <% end %>
CandidateTest IDEmailExperience<%= sortable "name", "Candidate" %><%= sortable "test_hash", "Test ID" %><%= sortable "email" %><%= sortable "experience" %> ProgressCompletedReminded<%= sortable "completed_at", "Completed" %><%= sortable "reminded" %> Interview?
+ <%= paginate @candidates %>