paginate and sort candidates list

comletes #99
This commit is contained in:
Mark Moser 2017-02-24 15:54:11 -06:00
parent b871285c75
commit fbbc0edebe
4 changed files with 22 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -9,13 +9,13 @@
<table cellspacing="0" cellpadding="0">
<tr>
<th>Candidate</th>
<th>Test ID</th>
<th>Email</th>
<th>Experience</th>
<th><%= sortable "name", "Candidate" %></th>
<th><%= sortable "test_hash", "Test ID" %></th>
<th><%= sortable "email" %></th>
<th><%= sortable "experience" %></th>
<th>Progress</th>
<th>Completed</th>
<th>Reminded</th>
<th><%= sortable "completed_at", "Completed" %></th>
<th><%= sortable "reminded" %></th>
<th>Interview?</th>
</tr>
@ -36,4 +36,5 @@
</tr>
<% end %>
</table>
<%= paginate @candidates %>
</main>