Module: TicketHelper

Defined in:
app/helpers/ticket_helper.rb

Constant Summary collapse

MINUTE =
60
HOUR =
MINUTE * 60
DAY =
HOUR * 24

Instance Method Summary collapse

Instance Method Details

#class_for_age(seconds) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'app/helpers/ticket_helper.rb', line 60

def class_for_age(seconds)
  if    seconds < 6.hours;        'infant'
  elsif seconds < 2.days;         'child'
  elsif seconds < 7.days;         'adult'
  elsif seconds < 4.weeks;        'senior'
  elsif seconds < 26.weeks;       'old'
  else                            'ancient'
  end
end

#format_antecedent(antecedent) ⇒ Object



27
28
29
30
31
32
# File 'app/helpers/ticket_helper.rb', line 27

def format_antecedent(antecedent)
  case antecedent.kind
  when "Goldmine"; "Goldmine #{link_to_goldmine_case(antecedent.id)}".html_safe
  when "Errbit"; "Errbit #{link_to_err(antecedent.project, antecedent.id)}".html_safe
  end
end

#format_duration(seconds) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'app/helpers/ticket_helper.rb', line 44

def format_duration(seconds)
  if seconds < HOUR
    format_duration_with_units(seconds / MINUTE, 'minute')
  elsif seconds < DAY
    format_duration_with_units(seconds / HOUR, 'hour')
  else
    format_duration_with_units(seconds / DAY, 'day')
  end
end

#format_duration_with_units(quantity, unit) ⇒ Object



54
55
56
57
58
# File 'app/helpers/ticket_helper.rb', line 54

def format_duration_with_units(quantity, unit)
  quantity = quantity.floor
  unit << 's' unless quantity == 1
  "#{quantity} #{unit}"
end

#format_ticket(ticket) ⇒ Object



3
4
5
# File 'app/helpers/ticket_helper.rb', line 3

def format_ticket(ticket)
  "<span class=\"ticket-number\">[##{ticket.number}]</span> <span class=\"ticket-summary\">#{format_with_feature_bolded ticket.summary}</span>".html_safe
end

#format_with_feature_bolded(message) ⇒ Object



16
17
18
19
20
21
22
23
# File 'app/helpers/ticket_helper.rb', line 16

def format_with_feature_bolded(message)
  feature = (message.match(/^([^\{:]+):/) || [])[1]
  if feature
    message = h(message[feature.length..-1])
    feature = "<b>#{h feature}</b>"
  end
  "#{feature}#{message}".html_safe
end


34
35
36
# File 'app/helpers/ticket_helper.rb', line 34

def link_to_goldmine_case(number)
  link_to "##{number}", goldmine_case_number_url(number), target: "_blank"
end


7
8
9
10
11
12
13
14
# File 'app/helpers/ticket_helper.rb', line 7

def link_to_ticket(ticket)
  contents = block_given? ? yield : format_ticket(ticket)
  if ticket.project
    link_to contents, ticket.ticket_tracker_ticket_url, target: "_blank", rel: "ticket", "data-number" => ticket.number, "data-project" => ticket.project.slug
  else
    contents
  end
end