Module: EffectiveSearchAdminSearch

Extended by:
ActiveSupport::Concern
Included in:
Effective::AdminSearch
Defined in:
app/models/concerns/effective_search_admin_search.rb

Overview

EffectiveSearchAdminSearch Mark your search model with include EffectiveSearchAdminSearch

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#applicant_results(page: nil) ⇒ Object



85
86
87
# File 'app/models/concerns/effective_search_admin_search.rb', line 85

def applicant_results(page: nil)
  results(applicants, page: page)
end

#applicantsObject



47
48
49
# File 'app/models/concerns/effective_search_admin_search.rb', line 47

def applicants
  @applicants ||= EffectiveMemberships.Applicant.where(user: users).order(created_at: :desc)
end

#event_results(page: nil) ⇒ Object



93
94
95
# File 'app/models/concerns/effective_search_admin_search.rb', line 93

def event_results(page: nil)
  results(events, page: page)
end

#eventsObject



51
52
53
# File 'app/models/concerns/effective_search_admin_search.rb', line 51

def events
  @events ||= Effective::Resource.new(Effective::Event).search_any(term, columns: [:title]).reorder(start_at: :desc)
end

#order_results(page: nil) ⇒ Object



81
82
83
# File 'app/models/concerns/effective_search_admin_search.rb', line 81

def order_results(page: nil)
  results(orders, page: page)
end

#ordersObject



43
44
45
# File 'app/models/concerns/effective_search_admin_search.rb', line 43

def orders
  @orders ||= Effective::Resource.new(Effective::Order).search_any(term, columns: [:id])
end

#organization_results(page: nil) ⇒ Object



89
90
91
# File 'app/models/concerns/effective_search_admin_search.rb', line 89

def organization_results(page: nil)
  results(organizations, page: page)
end

#organizationsObject



39
40
41
# File 'app/models/concerns/effective_search_admin_search.rb', line 39

def organizations
  @organizations ||= Effective::Resource.new(EffectiveMemberships.Organization).search_any(term, columns: [:title, :email])
end

#page_results(page: nil) ⇒ Object



97
98
99
# File 'app/models/concerns/effective_search_admin_search.rb', line 97

def page_results(page: nil)
  results(pages, page: page)
end

#pagesObject



55
56
57
# File 'app/models/concerns/effective_search_admin_search.rb', line 55

def pages
  @pages ||= Effective::Resource.new(Effective::Page).search_any(term, columns: [:title])
end

#per_pageObject



27
28
29
# File 'app/models/concerns/effective_search_admin_search.rb', line 27

def per_page
  5
end

#post_results(page: nil) ⇒ Object



101
102
103
# File 'app/models/concerns/effective_search_admin_search.rb', line 101

def post_results(page: nil)
  results(posts, page: page)
end

#postsObject



59
60
61
# File 'app/models/concerns/effective_search_admin_search.rb', line 59

def posts
  @posts ||= Effective::Resource.new(Effective::Post).search_any(term, columns: [:title]).reorder(published_start_at: :desc)
end

#present?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/models/concerns/effective_search_admin_search.rb', line 31

def present?
  term.present?
end

#search!Object

Search and assigns the collection Assigns the entire collection() if there are no search terms Otherwise validate the search terms



66
67
68
69
70
71
72
73
74
# File 'app/models/concerns/effective_search_admin_search.rb', line 66

def search!
  @users = users()
  @orders = orders()
  @applicants = applicants()
  @organizations = organizations()
  @events = events()
  @pages = pages()
  @posts = posts()
end

#to_sObject



23
24
25
# File 'app/models/concerns/effective_search_admin_search.rb', line 23

def to_s
  term.to_s
end

#user_results(page: nil) ⇒ Object

The paginated results



77
78
79
# File 'app/models/concerns/effective_search_admin_search.rb', line 77

def user_results(page: nil)
  results(users, page: page)
end

#usersObject



35
36
37
# File 'app/models/concerns/effective_search_admin_search.rb', line 35

def users
  @users ||= Effective::Resource.new(current_user.class).search_any(term, columns: [:first_name, :last_name, :email])
end