Sha256: 1a25e81ebb303cb35eded877b73fd12a090eae2047450e9c6e6ca49da005a3f7

Contents?: true

Size: 1003 Bytes

Versions: 3

Compression:

Stored size: 1003 Bytes

Contents

require_dependency "customer_vault/application_controller"
require 'handles_sortable_columns'

module CustomerVault
  class PeopleController < ApplicationController
    handles_sortable_columns
    
    def index
      authorize! :list, Person
      
      sorted_people = sortable_column_order do |column, direction|
        case column
        when 'name'
          (direction == :asc) ? get_index_people.sort_by(&:name)
                              : get_index_people.sort_by(&:name).reverse
        when 'zip'
          (direction == :asc) ? get_index_people.sort_by{ |p| p.address.zip.to_s }
                              : get_index_people.sort_by{ |p| p.address.zip.to_s }.reverse
        else
          get_index_people.sort_by(&:name)
        end
      end
      
      @people = Kaminari.paginate_array(sorted_people).page(params[:page]).per(8)
    end
    
    private
    
    def get_index_people
      Individual.search(params[:q]) + Corporation.search(params[:q])
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
customer_vault-1.2.5 app/controllers/customer_vault/people_controller.rb
customer_vault-1.2.4 app/controllers/customer_vault/people_controller.rb
customer_vault-1.2.3 app/controllers/customer_vault/people_controller.rb