Class: ODDB::Html::State::Drugs::Result

Inherits:
Global
  • Object
show all
Includes:
Util::PackageSort
Defined in:
lib/oddb/html/state/drugs/result.rb

Defined Under Namespace

Classes: Paginator

Constant Summary collapse

LIMIT =
true
VIEW =
View::Drugs::Result

Constants inherited from Global

Global::GLOBAL_MAP

Instance Attribute Summary

Attributes inherited from Global

#passed_turing_test

Attributes included from LoginMethods

#desired_input

Instance Method Summary collapse

Methods included from Util::PackageSort

#sort_proc

Methods included from Util::Sort

#_sort, #sort, #sort_by, #sort_proc

Methods inherited from Global

transparent_login

Methods included from Events

#_compare, #_complete, #_explain_ddd_price, #_explain_price, #_fachinfo, #_feedback, #_package, #_package_by_code, #_package_infos, #_patinfo, #_products, #_remote, #_remote_comparables, #_remote_infos, #_remote_package, #_remote_packages, #_search_append_products, #_search_append_sequences, #_search_by, #_search_local, #_search_remote, #_sequence_by_code, #_tax_factor, #compare_remote, #ddd, #limited?, #navigation, #search

Methods inherited from Global

#_download, #compare, #explain_ddd_price, #explain_price, #fachinfo, #feedback, #grant_download, #home, #limit_state, #limited?, #logout, #method_missing, #navigation, #package, #package_infos, #partitioned_keys, #patinfo, #proceed_download, #proceed_export, #proceed_poweruser, #product, #products, #remote_infos, #sequence

Methods included from PayPal::Checkout

#ajax_autofill, #checkout, #checkout_keys, #checkout_mandatory, #create_user

Methods included from PayPal::Download

#collect

Methods included from Util::Download

compressed_download, #compressed_download

Methods included from LoginMethods

#login_

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ODDB::Html::State::Global

Instance Method Details

#_search(query, dstype) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/oddb/html/state/drugs/result.rb', line 108

def _search(query, dstype)
  if(@model.query == query && @model.dstype == dstype)
    paginate
    sort
  else
    super
  end
end

#_sort_by(model, reverse, &sorter) ⇒ Object



116
117
118
119
120
# File 'lib/oddb/html/state/drugs/result.rb', line 116

def _sort_by(model, reverse, &sorter)
  model.collect! { |array|
    super(array, reverse, &sorter)
  }
end

#direct_eventObject



74
75
76
# File 'lib/oddb/html/state/drugs/result.rb', line 74

def direct_event
  [:search, :query, @model.query, :dstype, @model.dstype]
end

#initObject



65
66
67
68
69
70
71
72
73
# File 'lib/oddb/html/state/drugs/result.rb', line 65

def init
  partition!
  sort_by(:price_public, 0)
  sort_by(:size, 0)
  sort_by(:active_agents, [])
  sort_by(:product, nil)
  paginate
  sort
end

#paginateObject



77
78
79
80
81
82
83
84
85
# File 'lib/oddb/html/state/drugs/result.rb', line 77

def paginate
  if(@session.user_input(:page))
    @session.set_cookie_input(:display, 'paged')
  end
  @model.display = @session.cookie_set_or_get(:display)
  if(page = @session.user_input(:page))
    @model.page = page
  end
end

#partition!Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/oddb/html/state/drugs/result.rb', line 86

def partition!
  atcs = {}
  @model = Paginator.new(@model)
  @model.total = @model.size
  while(package = @model.shift)
    code = (atc = package.atc) ? atc.code : 'X'
    (atcs[code] ||= ODDB::Util::AnnotatedList.new(:atc => atc)).push(package)
  end
  count = 0
  limit = @session.pagelength
  atcs.sort.each { |code, array|
    count += array.size
    ## count > array.size: very large atc-classes may instantly get the count 
    #                      to be > limit
    if(count > array.size && count > limit)
      @model.next_page!
      count = array.size
    end
    @model.push(array)
  }
  @model.page = 0
end