Added helper + minor UI changes
[rails.git] / app / helpers / issues_helper.rb
1 module IssuesHelper
2
3         def reportable_url(reportable)
4                 class_name = reportable.class.name
5                 case class_name
6                 when "DiaryEntry"
7                         link_to reportable.title,       :controller => reportable.class.name.underscore,
8                                                                                 :action => :view,
9                                                                                 :display_name => reportable.user.display_name,
10                                                                                 :id => reportable.id
11                 when "User"
12                         link_to reportable.display_name.to_s,   :controller => reportable.class.name.underscore,
13                                                                                                         :action => :view,
14                                                                                                         :display_name => reportable.display_name
15                 when "DiaryComment"
16                         link_to "#{reportable.diary_entry.title}, Comment id ##{reportable.id}",        :controller => reportable.diary_entry.class.name.underscore,
17                                                                                                                 :action => :view,
18                                                                                                                 :display_name => reportable.diary_entry.user.display_name,
19                                                                                                                 :id => reportable.diary_entry.id,
20                                                                                                                 :comment_id => reportable.id
21                 when "Changeset"
22                         link_to "Changeset ##{reportable.id}",          :controller => :browse,
23                                                                                                                 :action => :changeset,
24                                                                                                                 :id => reportable.id
25                 when "Note"
26                         link_to "Note ##{reportable.id}",       :controller => :browse,
27                                                                                                 :action => :note,
28                                                                                                 :id => reportable.id
29                 else
30                         nil
31                 end
32         end
33
34         def reports_url(issue)
35                 class_name = issue.reportable.class.name
36                 case class_name
37                 when "DiaryEntry"
38                         link_to issue.reportable.title, issue
39                 when "User"
40                         link_to issue.reportable.display_name.to_s, issue
41                 when "DiaryComment"
42                         link_to "#{issue.reportable.diary_entry.title}, Comment id ##{issue.reportable.id}", issue
43                 when "Changeset"
44                         link_to "Changeset ##{issue.reportable.id}",issue
45                 when "Note"
46                         link_to "Note ##{issue.reportable.id}", issue
47                 else
48                         nil
49                 end
50         end
51
52         def instance_url(reportable)
53                 class_name = reportable.class.name
54                 case class_name
55                 when "DiaryEntry"
56                         link_to "Show Instance",        :controller => reportable.class.name.underscore,
57                                                                                 :action => :view,
58                                                                                 :display_name => reportable.user.display_name,
59                                                                                 :id => reportable.id
60                 when "User"
61                         link_to "Show Instance",        :controller => reportable.class.name.underscore,
62                                                                                 :action => :view,
63                                                                                 :display_name => reportable.display_name
64                 when "DiaryComment"
65                         link_to "Show Instance",        :controller => reportable.diary_entry.class.name.underscore,
66                                                 :action => :view,
67                                                 :display_name => reportable.diary_entry.user.display_name,
68                                                 :id => reportable.diary_entry.id,
69                                                 :comment_id => reportable.id
70                 when "Changeset"
71                         link_to "Show Instance", :controller => :browse,
72                                                                          :action => :changeset,
73                                                                          :id => reportable.id
74                 when "Note"
75                         link_to "Show Instance", :controller => :browse,
76                                                                          :action => :note,
77                                                                          :id => reportable.id
78                 else
79                         nil
80                 end
81         end
82
83         def sortable(column,title=nil)
84                 title ||= column.titleize
85                 direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
86                 if column == sort_column
87                         arrow = direction == "desc" ? ["25B2".hex].pack("U") : ["25BC".hex].pack("U")
88                         title = title + arrow
89                 end
90                 link_to title, params.merge(:sort => column, :direction => direction)
91         end
92
93         def report_type(report_class) 
94                 case report_class
95                 when "DiaryEntry"
96                         t('activerecord.models.diary_entry')
97                 when "User"
98                         t('activerecord.models.user')
99                 when "DiaryComment"
100                         t('activerecord.models.diary_comment')
101                 when "Changeset"
102                         t('activerecord.models.changeset')
103                 when "Note"
104                         t('activerecord.models.note')                           
105                 else
106                         nil
107                 end
108         end
109 end