]> git.openstreetmap.org Git - rails.git/blob - app/helpers/issues_helper.rb
Add frozen_string_literal comments to ruby files
[rails.git] / app / helpers / issues_helper.rb
1 # frozen_string_literal: true
2
3 module IssuesHelper
4   def reportable_url(reportable)
5     case reportable
6     when DiaryEntry
7       diary_entry_url(reportable.user, reportable)
8     when User
9       user_url(reportable)
10     when DiaryComment
11       diary_entry_url(reportable.diary_entry.user, reportable.diary_entry, :anchor => "comment#{reportable.id}")
12     when Note
13       note_url(reportable)
14     end
15   end
16
17   def reportable_title(reportable)
18     case reportable
19     when DiaryEntry
20       reportable.title
21     when User
22       reportable.display_name
23     when DiaryComment
24       I18n.t("issues.helper.reportable_title.diary_comment", :entry_title => reportable.diary_entry.title, :comment_id => reportable.id)
25     when Note
26       I18n.t("issues.helper.reportable_title.note", :note_id => reportable.id)
27     end
28   end
29
30   def reportable_heading(reportable)
31     heading_params = { :title => link_to(reportable_title(reportable), reportable_url(reportable)) }
32     heading_params[:datetime_created] = reportable_heading_time(reportable.created_at)
33     heading_params[:datetime_updated] = reportable_heading_time(reportable.updated_at) unless reportable.is_a? User
34
35     case reportable
36     when DiaryComment
37       t "issues.helper.reportable_heading.diary_comment_html", **heading_params
38     when DiaryEntry
39       t "issues.helper.reportable_heading.diary_entry_html", **heading_params
40     when Note
41       t "issues.helper.reportable_heading.note_html", **heading_params
42     when User
43       t "issues.helper.reportable_heading.user_html", **heading_params
44     end
45   end
46
47   def open_issues_count
48     count = Issue.visible_to(current_user).open.limit(Settings.max_issues_count).size
49     if count >= Settings.max_issues_count
50       tag.span(I18n.t("count.at_least_pattern", :count => Settings.max_issues_count), :class => "badge count-number")
51     elsif count.positive?
52       tag.span(count, :class => "badge count-number")
53     end
54   end
55
56   private
57
58   def reportable_heading_time(datetime)
59     tag.time l(datetime.to_datetime, :format => :friendly), :datetime => datetime.xmlschema
60   end
61 end