changed default sort direction
This commit is contained in:
		@@ -3,8 +3,6 @@ module Admin
 | 
			
		||||
  class CandidateController < AdminController
 | 
			
		||||
    before_action :collect_quizzes, except: [:login, :auth]
 | 
			
		||||
 | 
			
		||||
    helper_method :sort_column
 | 
			
		||||
 | 
			
		||||
    def index
 | 
			
		||||
      @candidates = policy_scope Candidate.order("#{sort_column} #{sort_direction}")
 | 
			
		||||
                    .page(params[:page])
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,6 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
module Admin
 | 
			
		||||
  class ResultController < AdminController
 | 
			
		||||
    helper_method :sort_column
 | 
			
		||||
 | 
			
		||||
    # TODO: change context from Candidate to Quiz
 | 
			
		||||
    # bypass pundit lockdowns until completed
 | 
			
		||||
    after_action :skip_policy_scope
 | 
			
		||||
@@ -32,5 +30,9 @@ module Admin
 | 
			
		||||
      def sort_column
 | 
			
		||||
        @sort_col ||= 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
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@ class AdminController < ApplicationController
 | 
			
		||||
  after_action :verify_policy_scoped, only: :index
 | 
			
		||||
 | 
			
		||||
  helper_method :sort_direction
 | 
			
		||||
  helper_method :sort_column
 | 
			
		||||
 | 
			
		||||
  def current_user
 | 
			
		||||
    @current_user ||= User.find_by(id: session[:user]) if session[:user]
 | 
			
		||||
@@ -18,8 +19,12 @@ class AdminController < ApplicationController
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
    def sort_column
 | 
			
		||||
      :completed_at
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def sort_direction
 | 
			
		||||
      %w(asc desc).include?(params[:direction]) ? params[:direction] : 'desc'
 | 
			
		||||
      %w(asc desc).include?(params[:direction]) ? params[:direction] : 'asc'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def authorize_user
 | 
			
		||||
 
 | 
			
		||||
@@ -9,4 +9,11 @@ class AdminControllerTest < ActionDispatch::IntegrationTest
 | 
			
		||||
    assert_redirected_to admin_login_path
 | 
			
		||||
    assert_match 'not authorized', flash[:error]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  test 'sort_column present' do
 | 
			
		||||
    # a stupid coverage report thing.
 | 
			
		||||
    admin_controller = AdminController.new
 | 
			
		||||
 | 
			
		||||
    assert_equal :completed_at, admin_controller.send(:sort_column)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user