Module: Workarea::Search::AdminSorting

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_sortsObject



4
5
6
7
8
9
10
11
12
# File 'app/queries/workarea/search/admin_sorting.rb', line 4

def self.available_sorts
  Sort::Collection.new(
    Sort.relevance,
    Sort.modified,
    Sort.name_asc,
    Sort.newest,
    Sort.oldest
  )
end

Instance Method Details

#current_sortObject



14
15
16
# File 'app/queries/workarea/search/admin_sorting.rb', line 14

def current_sort
  AdminSorting.available_sorts.find(params[:sort])
end

#default_admin_sortObject



18
19
20
# File 'app/queries/workarea/search/admin_sorting.rb', line 18

def default_admin_sort
  [{ _score: :desc },  { updated_at: :desc }]
end

#sortObject



26
27
28
29
30
31
32
33
34
35
# File 'app/queries/workarea/search/admin_sorting.rb', line 26

def sort
  sort = super
  return sort unless sort.blank?

  if current_sort.field.present?
    user_selected_sort
  else
    default_admin_sort
  end
end

#user_selected_sortObject



22
23
24
# File 'app/queries/workarea/search/admin_sorting.rb', line 22

def user_selected_sort
  [{ current_sort.field => current_sort.direction }]
end