Class: UiHelper::Summary

Inherits:
Object
  • Object
show all
Defined in:
app/models/ui_helper/summary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Summary

Returns a new instance of Summary


10
11
12
13
14
# File 'app/models/ui_helper/summary.rb', line 10

def initialize(options = {})
  @summary_items = []
  @current_page  = options[:page].to_i || 1
  @item_per_page = options[:per_page].to_i || 10
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page


8
9
10
# File 'app/models/ui_helper/summary.rb', line 8

def current_page
  @current_page
end

#summary_itemsObject

Returns the value of attribute summary_items


7
8
9
# File 'app/models/ui_helper/summary.rb', line 7

def summary_items
  @summary_items
end

Instance Method Details

#add(item) ⇒ Object


66
67
68
# File 'app/models/ui_helper/summary.rb', line 66

def add(item)
  @summary_items << item
end

#load(study) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'app/models/ui_helper/summary.rb', line 16

def load(study)
  study.submissions.each do |submission|
    submission.events.where('message LIKE "Run%"').find_each do |event|
      load_event(event)
    end
  end
  load_study(study)
  summaries
end

#load_asset(asset) ⇒ Object


28
29
30
31
32
# File 'app/models/ui_helper/summary.rb', line 28

def load_asset(asset)
  asset.events_on_requests.where('message LIKE "Run%"').find_each do |event|
    load_event(event)
  end
end

#load_event(event) ⇒ Object


40
41
42
43
44
45
46
47
48
# File 'app/models/ui_helper/summary.rb', line 40

def load_event(event)
  add(SummaryItem.new(
        message: event.message,
        object: event.eventful,
        timestamp: event.created_at,
        external_message: "Run #{event.identifier}",
        external_link: "#{configatron.run_information_url}#{event.identifier}"
      ))
end

#load_request(request) ⇒ Object


34
35
36
37
38
# File 'app/models/ui_helper/summary.rb', line 34

def load_request(request)
  request.run_events.each do |event|
    load_event(event)
  end
end

#load_study(study) ⇒ Object


50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/ui_helper/summary.rb', line 50

def load_study(study)
  study.events.find_each do |event|
    add(SummaryItem.new(
          message: event.message,
          object: study,
          timestamp: event.created_at,
          external_message: "Study #{study.id}",
          external_link: ''
        ))
  end
end

#sizeObject


70
71
72
# File 'app/models/ui_helper/summary.rb', line 70

def size
  @summary_items.size
end

#summariesObject


62
63
64
# File 'app/models/ui_helper/summary.rb', line 62

def summaries
  summary_items.sort_by(&:timestamp).reverse
end