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

Inherits:
Global show all
Includes:
ResultStateSort
Defined in:
src/state/drugs/result.rb,
test/test_state/drugs/result.rb

Constant Summary

SNAPBACK_EVENT =
:result
VIEW =
View::Drugs::Result
LIMITED =
true
ITEM_LIMIT =
100
REVERSE_MAP =
{
  :size   => true,
  :price  => false,
  :mice   => false,
}

Constants inherited from Global

HOME_STATE, ZONE, ZONE_NAVIGATION

Constants inherited from Global

DIRECT_EVENT, GLOBAL_MAP, HOME_STATE, LIMITED, PRINT_STATES, READONLY_STATES, RESOLVE_STATES, REVERSE_MAP, VIEW, ZONE_NAVIGATION

Constants included from UmlautSort

FILTER_PAIRS

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from ResultStateSort

#sort

Methods inherited from Global

#_search_drugs, #_search_drugs_state, #_trigger, #add_to_interaction_basket, #allowed?, #atc_chooser, #checkout, #clear_interaction_basket, #creditable?, #direct_request_path, #doctorlist, #download, #extend, #fachinfo, #feedbacks, #help_navigation, #home_navigation, #home_state, #hospitallist, #interaction_basket, #limited?, #logout, #navigation, #notify, #password_reset, #paypal_return, #powerlink, #print, #proceed_download, #proceed_poweruser, #resolve, #resolve_state, #rss, #show, #snapback_event, #sort, #sponsorlink, #suggest_address, #switch, #unique_email, #user_input, #user_navigation, #ywesee_contact, #zone_navigation, #zones

Methods included from Admin::LoginMethods

#autologin, #login

Methods included from UmlautSort

#sort_model, #umlaut_filter

Instance Attribute Details

- (Object) default_view (readonly)

Returns the value of attribute default_view



16
17
18
# File 'test/test_state/drugs/result.rb', line 16

def default_view
  @default_view
end

- (Object) filter (readonly)

Returns the value of attribute filter



16
17
18
# File 'test/test_state/drugs/result.rb', line 16

def filter
  @filter
end

- (Object) model

Returns the value of attribute model



16
17
18
# File 'test/test_state/drugs/result.rb', line 16

def model
  @model
end

- (Object) pages (readonly)

Returns the value of attribute pages



24
25
26
# File 'src/state/drugs/result.rb', line 24

def pages
  @pages
end

- (Object) search_query

Returns the value of attribute search_query



23
24
25
# File 'src/state/drugs/result.rb', line 23

def search_query
  @search_query
end

- (Object) search_type

Returns the value of attribute search_type



23
24
25
# File 'src/state/drugs/result.rb', line 23

def search_type
  @search_type
end

- (Object) session

Returns the value of attribute session



15
16
17
# File 'test/test_state/drugs/result.rb', line 15

def session
  @session
end

- (Object) sortby

Returns the value of attribute sortby



15
16
17
# File 'test/test_state/drugs/result.rb', line 15

def sortby
  @sortby
end

Instance Method Details

- (Object) export_csv



54
55
56
57
58
59
60
# File 'src/state/drugs/result.rb', line 54

def export_csv
  if(creditable?('org.oddb.download'))
    PaymentMethod.new(@session, @model)
  else
    RegisterDownload.new(@session, @model)
  end
end

- (Object) get_sortby!



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'src/state/drugs/result.rb', line 61

def get_sortby!
  super
  if(@sortby.first == :dsp)
    sortvalue = [:most_precise_dose, :comparable_size, :price_public]
    if(@sortby[1,3] == sortvalue)
      ## @sort_reverse has already been reset at this stage, 
      ## correct it with dedicated instance variable
      @sort_reverse = @sort_reverse_dsp = !@sort_reverse_dsp
      @sortby.shift
    else
      @sort_reverse_dsp = @sort_reverse
      @sortby[0,1] = sortvalue
    end
  end
  @sortby.uniq!
end

- (Object) init



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'src/state/drugs/result.rb', line 26

def init
  @pages = []
  @model.session = @session
  @model.atc_classes.delete_if { |atc| atc.package_count == 0 }
  if(@model.atc_classes.nil? || @model.atc_classes.empty?)
    @default_view = View::Drugs::EmptyResult
  elsif(@model.overflow?)
    query = @session.persistent_user_input(:search_query).to_s.downcase
    page  = 0
    count = 0
    @model.each { |atc|
      @pages[page] ||= State::PageFacade.new(page) 
      @pages[page].push(atc)
      count += atc.package_count
      if(count >= ITEM_LIMIT)
        page += 1
        count = 0
      end 
    }
    @filter = Proc.new { |model|
      if(@session.cookie_set_or_get(:resultview) == 'pages')
        page()
      else
        @model
      end
    }
  end
end

- (Object) limit_state



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'src/state/drugs/result.rb', line 77

def limit_state
  model = if(@search_type == "st_sequence")
    @model
  else
    _search_drugs(@search_query, "st_sequence")
  end
  result = model.atc_classes.inject([]) { |mdl, atc|
    mdl += atc.active_packages
  }
  state = State::Drugs::ResultLimit.new(@session, result)
  state.package_count = @model.package_count
  state
end

- (Object) package_count



90
91
92
# File 'src/state/drugs/result.rb', line 90

def package_count
  @model.package_count
end

- (Object) page



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'src/state/drugs/result.rb', line 93

def page
  pge = nil
  if(@session.event == :search)
    ## reset page-input
    pge = @session.user_input(:page)
    @session.set_persistent_user_input(:page, pge)
  else
    pge = @session.persistent_user_input(:page)
  end
  page = @pages[pge || 0]
  page.model = @model
  page
end

- (Object) request_path



106
107
108
109
110
111
# File 'src/state/drugs/result.rb', line 106

def request_path
  if(@request_path)
    suffix = @session.lookandfeel.disabled?(:best_result) ? '' : '#best_result'
    @request_path + suffix
  end
end

- (Object) search



112
113
114
115
116
117
118
119
120
121
# File 'src/state/drugs/result.rb', line 112

def search
  query = @session.persistent_user_input(:search_query).to_s.downcase
  stype = @session.user_input(:search_type) 
  if(@search_type != stype || @search_query != query)
    super
  else
    @request_path = @session.request_path
    self
  end
end