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