Class: BBMB::Html::State::Customers
- Inherits:
-
Global
- Object
- SBSM::State
- Global
- BBMB::Html::State::Customers
show all
- Defined in:
- lib/bbmb/html/state/customers.rb
Constant Summary
collapse
- DIRECT_EVENT =
:customers
- VIEW =
View::Customers
- FILTER =
[ :customer_id, :organisation, :plz, :city, :email ]
Instance Method Summary
collapse
Methods inherited from Global
#direct_argument_keys, #direct_arguments, #direct_request?, #logout, mandatory, #requested_event, #trigger, #user_input
Instance Method Details
#init ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/bbmb/html/state/customers.rb', line 16
def init
start = Time.now
@model = BBMB.persistence.all(Model::Customer)
@sortby = [:organisation]
BBMB.logger.debug('State') {
sprintf("Customers#init: loaded %i customers in %1.5fs",
@model.size, Time.now - start)
}
@filter = Proc.new { |model|
if(filter = @session.event_bound_user_input(:filter))
pattern = Regexp.new(filter.gsub("*", ".*"), 'i')
model = model.select { |customer|
FILTER.any? { |key| pattern.match(customer.send(key).to_s) }
}
end
get_sortby!
model.sort! { |a, b| compare_entries(a, b) }
@sort_reverse && model.reverse!
page(model)
}
end
|
#page(model) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/bbmb/html/state/customers.rb', line 37
def page(model)
page = OpenStruct.new
index = @session.user_input(:index).to_i
step = @session.user.pagestep || BBMB.config.pagestep
page.index = index
page.first = index + 1
page.step = step
page.total = model.size
page.customers = model[index, step]
page.last = index + page.customers.size
page
end
|