Class: BBMB::Html::State::Customers
- 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?, #initialize, #logout, mandatory, #requested_event, #trigger, #user_input
Constructor Details
This class inherits a constructor from BBMB::Html::State::Global
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 37 38 39 40 41 42 43 44 45 |
# 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| input = @session.event_bound_user_input(:filter) if input pattern = Regexp.new(input.gsub('*', '.*'), 'ui') model = model.select { |customer| FILTER.any? { |key| value = customer.send(key).to_s next if value.empty? begin pattern.match(value) rescue ArgumentError false end } } end get_sortby! model.sort! { |a, b| compare_entries(a, b) } @sort_reverse && model.reverse! page(model) } end |
#page(model) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bbmb/html/state/customers.rb', line 46 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 |