Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#create_percentage_table_for(collection) ⇒ Object


45
46
47
# File 'app/helpers/application_helper.rb', line 45

def create_percentage_table_for(collection)
  create_percentage_table_from_tallies(tally(collection))
end

#create_percentage_table_from_tallies(tallies, options = {}) ⇒ Object


56
57
58
59
60
61
62
# File 'app/helpers/application_helper.rb', line 56

def create_percentage_table_from_tallies(tallies, options={})
  total   = (options[:total] || total_from_tallies(tallies))
  percent = 100.0 / total.to_f
  rows    = tallies.map {|value, count| [(count.to_f * percent), value]} \
                   .sort {|a, b| b[0] <=> a[0]}
  render "problems/tally_table", :rows => rows
end

#generate_ical(deploys) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/application_helper.rb', line 22

def generate_ical(deploys)
  RiCal.Calendar { |cal|
    deploys.each_with_index do |deploy,idx|
      cal.event do |event|
        event.summary     = "#{idx+1} #{deploy.repository.to_s}"
        event.description = deploy.revision.to_s
        event.dtstart     = deploy.created_at.utc
        event.dtend       = deploy.created_at.utc + 60.minutes
        event.location    = deploy.environment.to_s
        event.organizer   = deploy.username.to_s
      end
    end
  }.to_s
end

#generate_problem_ical(notices) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/application_helper.rb', line 6

def generate_problem_ical(notices)
  RiCal.Calendar do |cal|
    notices.each_with_index do |notice,idx|
      cal.event do |event|
        event.summary     = "#{idx+1} #{notice.message.to_s}"
        event.description = notice.url if notice.url
        event.dtstart     = notice.created_at.utc
        event.dtend       = notice.created_at.utc + 60.minutes
        event.organizer   = notice.server_environment && notice.server_environment["hostname"]
        event.location    = notice.project_root
        event.url         = app_problem_url(:app_id => notice.problem.app.id, :id => notice.problem)
      end
    end
  end.to_s
end

#head(collection) ⇒ Object


64
65
66
# File 'app/helpers/application_helper.rb', line 64

def head(collection)
  collection.first(head_size)
end

#issue_tracker_typesObject


72
73
74
75
76
# File 'app/helpers/application_helper.rb', line 72

def issue_tracker_types
  ErrbitPlugin::Registry.issue_trackers.map do |_, object|
    IssueTrackerTypeDecorator.new(object)
  end
end

#message_graph(problem) ⇒ Object


2
3
4
# File 'app/helpers/application_helper.rb', line 2

def message_graph(problem)
  create_percentage_table_for(problem.messages)
end

#tail(collection) ⇒ Object


68
69
70
# File 'app/helpers/application_helper.rb', line 68

def tail(collection)
  collection.to_a[head_size..-1].to_a
end

#tally(collection) ⇒ Object


49
50
51
52
53
54
# File 'app/helpers/application_helper.rb', line 49

def tally(collection)
  collection.values.inject({}) do |tallies, tally|
    tallies[tally['value']] = tally['count']
    tallies
  end
end

#tenant_graph(problem) ⇒ Object


41
42
43
# File 'app/helpers/application_helper.rb', line 41

def tenant_graph(problem)
  create_percentage_table_for(problem.hosts)
end

#user_agent_graph(problem) ⇒ Object


37
38
39
# File 'app/helpers/application_helper.rb', line 37

def user_agent_graph(problem)
  create_percentage_table_for(problem.user_agents)
end