Class: Workarea::Admin::SearchViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Admin::SearchViewModel
show all
- Defined in:
- app/view_models/workarea/admin/search_view_model.rb
Instance Method Summary
collapse
Instance Method Details
#applied_filters? ⇒ Boolean
57
58
59
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 57
def applied_filters?
facet_selections.any? || filters.any?
end
|
#facet_selections ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 40
def facet_selections
@facet_selections ||= facets.reduce({}) do |selected, facet|
facet.results.keys.each do |key|
if facet.selected?(key)
selected[facet] ||= []
selected[facet] << key
end
end
selected
end
end
|
#facets ⇒ Object
34
35
36
37
38
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 34
def facets
results = model.facets.reject(&:useless?)
results.reject! { |f| f.system_name == 'type' } unless options[:show_type]
results
end
|
#filters ⇒ Object
53
54
55
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 53
def filters
@filters ||= model.filters.reject(&:useless?)
end
|
#results ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 4
def results
@results ||= PagedArray.from(
persisted_results.map do |model|
ApplicationController.wrap_in_view_model(
model,
view_model_options_for(model)
)
end,
model.results.page,
model.results.per_page,
total
)
end
|
#sort ⇒ Object
22
23
24
25
26
27
28
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 22
def sort
if options[:sort].blank?
options[:q].present? ? Sort.relevance : Sort.modified
else
Search::AdminSearch.available_sorts.find(options[:sort])
end
end
|
#sorts ⇒ Object
30
31
32
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 30
def sorts
Search::AdminSearch.available_sorts.map { |s| [s.name, s.slug] }
end
|
#toggle_facets? ⇒ Boolean
61
62
63
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 61
def toggle_facets?
facets.length > 2
end
|
#total ⇒ Object
18
19
20
|
# File 'app/view_models/workarea/admin/search_view_model.rb', line 18
def total
model.results.total - (model.results.length - persisted_results.length)
end
|