Module: EffectiveMembershipsDirectory

Extended by:
ActiveSupport::Concern
Included in:
Effective::MembershipDirectory
Defined in:
app/models/concerns/effective_memberships_directory.rb

Overview

This is a search model for the MembershipDirectories screen

EffectiveMembershipsDirectory Mark your directory search model with include EffectiveMembershipsDirectory

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#categoriesObject



38
39
40
# File 'app/models/concerns/effective_memberships_directory.rb', line 38

def categories
  EffectiveMemberships.Category.membership_directory.all
end

#collectionObject

Base collection to search. Can be configured per tenant.



43
44
45
46
47
48
# File 'app/models/concerns/effective_memberships_directory.rb', line 43

def collection
  Effective::Membership.deep.sorted
    .in_good_standing
    .without_archived_owners
    .with_category(categories)
end

#membershipsObject

The unpaginated results of the search



74
75
76
# File 'app/models/concerns/effective_memberships_directory.rb', line 74

def memberships
  @memberships || collection
end

#per_pageObject



56
57
58
# File 'app/models/concerns/effective_memberships_directory.rb', line 56

def per_page
  24
end

#present?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/concerns/effective_memberships_directory.rb', line 60

def present?
  term.present? || first_name.present? || last_name.present? || title.present? || category.present?
end

#results(page: nil) ⇒ Object

The paginated results



79
80
81
82
83
84
# File 'app/models/concerns/effective_memberships_directory.rb', line 79

def results(page: nil)
  page = (page || 1).to_i
  offset = [(page - 1), 0].max * per_page

  memberships.limit(per_page).offset(offset)
end

#search!Object

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



67
68
69
70
71
# File 'app/models/concerns/effective_memberships_directory.rb', line 67

def search!
  @memberships = build_collection()
  @memberships = @memberships.none if present? && !valid?
  @memberships
end

#search_any_columnsObject

Search Users and Organizations for only these fields. Passed into search_any. Return nil for all. Should this include email?



52
53
54
# File 'app/models/concerns/effective_memberships_directory.rb', line 52

def search_any_columns
  [:title, :name, :first_name, :middle_name, :last_name, :number]
end