@@ -1,500 +1,516 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module IssuesHelper |
|
20 | module IssuesHelper | |
21 | include ApplicationHelper |
|
21 | include ApplicationHelper | |
22 | include Redmine::Export::PDF::IssuesPdfHelper |
|
22 | include Redmine::Export::PDF::IssuesPdfHelper | |
23 |
|
23 | |||
24 | def issue_list(issues, &block) |
|
24 | def issue_list(issues, &block) | |
25 | ancestors = [] |
|
25 | ancestors = [] | |
26 | issues.each do |issue| |
|
26 | issues.each do |issue| | |
27 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) |
|
27 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) | |
28 | ancestors.pop |
|
28 | ancestors.pop | |
29 | end |
|
29 | end | |
30 | yield issue, ancestors.size |
|
30 | yield issue, ancestors.size | |
31 | ancestors << issue unless issue.leaf? |
|
31 | ancestors << issue unless issue.leaf? | |
32 | end |
|
32 | end | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def grouped_issue_list(issues, query, issue_count_by_group, &block) |
|
35 | def grouped_issue_list(issues, query, issue_count_by_group, &block) | |
36 | previous_group, first = false, true |
|
36 | previous_group, first = false, true | |
37 | issue_list(issues) do |issue, level| |
|
37 | issue_list(issues) do |issue, level| | |
38 | group_name = group_count = nil |
|
38 | group_name = group_count = nil | |
39 | if query.grouped? && ((group = query.group_by_column.value(issue)) != previous_group || first) |
|
39 | if query.grouped? && ((group = query.group_by_column.value(issue)) != previous_group || first) | |
40 | if group.blank? && group != false |
|
40 | if group.blank? && group != false | |
41 | group_name = "(#{l(:label_blank_value)})" |
|
41 | group_name = "(#{l(:label_blank_value)})" | |
42 | else |
|
42 | else | |
43 | group_name = column_content(query.group_by_column, issue) |
|
43 | group_name = column_content(query.group_by_column, issue) | |
44 | end |
|
44 | end | |
45 | group_name ||= "" |
|
45 | group_name ||= "" | |
46 | group_count = issue_count_by_group[group] |
|
46 | group_count = issue_count_by_group[group] | |
47 | end |
|
47 | end | |
48 | yield issue, level, group_name, group_count |
|
48 | yield issue, level, group_name, group_count | |
49 | previous_group, first = group, false |
|
49 | previous_group, first = group, false | |
50 | end |
|
50 | end | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | # Renders a HTML/CSS tooltip |
|
53 | # Renders a HTML/CSS tooltip | |
54 | # |
|
54 | # | |
55 | # To use, a trigger div is needed. This is a div with the class of "tooltip" |
|
55 | # To use, a trigger div is needed. This is a div with the class of "tooltip" | |
56 | # that contains this method wrapped in a span with the class of "tip" |
|
56 | # that contains this method wrapped in a span with the class of "tip" | |
57 | # |
|
57 | # | |
58 | # <div class="tooltip"><%= link_to_issue(issue) %> |
|
58 | # <div class="tooltip"><%= link_to_issue(issue) %> | |
59 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> |
|
59 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> | |
60 | # </div> |
|
60 | # </div> | |
61 | # |
|
61 | # | |
62 | def render_issue_tooltip(issue) |
|
62 | def render_issue_tooltip(issue) | |
63 | @cached_label_status ||= l(:field_status) |
|
63 | @cached_label_status ||= l(:field_status) | |
64 | @cached_label_start_date ||= l(:field_start_date) |
|
64 | @cached_label_start_date ||= l(:field_start_date) | |
65 | @cached_label_due_date ||= l(:field_due_date) |
|
65 | @cached_label_due_date ||= l(:field_due_date) | |
66 | @cached_label_assigned_to ||= l(:field_assigned_to) |
|
66 | @cached_label_assigned_to ||= l(:field_assigned_to) | |
67 | @cached_label_priority ||= l(:field_priority) |
|
67 | @cached_label_priority ||= l(:field_priority) | |
68 | @cached_label_project ||= l(:field_project) |
|
68 | @cached_label_project ||= l(:field_project) | |
69 |
|
69 | |||
70 | link_to_issue(issue) + "<br /><br />".html_safe + |
|
70 | link_to_issue(issue) + "<br /><br />".html_safe + | |
71 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + |
|
71 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + | |
72 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + |
|
72 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + | |
73 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + |
|
73 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + | |
74 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + |
|
74 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + | |
75 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + |
|
75 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + | |
76 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe |
|
76 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def issue_heading(issue) |
|
79 | def issue_heading(issue) | |
80 | h("#{issue.tracker} ##{issue.id}") |
|
80 | h("#{issue.tracker} ##{issue.id}") | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def render_issue_subject_with_tree(issue) |
|
83 | def render_issue_subject_with_tree(issue) | |
84 | s = '' |
|
84 | s = '' | |
85 | ancestors = issue.root? ? [] : issue.ancestors.visible.to_a |
|
85 | ancestors = issue.root? ? [] : issue.ancestors.visible.to_a | |
86 | ancestors.each do |ancestor| |
|
86 | ancestors.each do |ancestor| | |
87 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) |
|
87 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) | |
88 | end |
|
88 | end | |
89 | s << '<div>' |
|
89 | s << '<div>' | |
90 | subject = h(issue.subject) |
|
90 | subject = h(issue.subject) | |
91 | if issue.is_private? |
|
91 | if issue.is_private? | |
92 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject |
|
92 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject | |
93 | end |
|
93 | end | |
94 | s << content_tag('h3', subject) |
|
94 | s << content_tag('h3', subject) | |
95 | s << '</div>' * (ancestors.size + 1) |
|
95 | s << '</div>' * (ancestors.size + 1) | |
96 | s.html_safe |
|
96 | s.html_safe | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def render_descendants_tree(issue) |
|
99 | def render_descendants_tree(issue) | |
100 | s = '<form><table class="list issues">' |
|
100 | s = '<form><table class="list issues">' | |
101 | issue_list(issue.descendants.visible.preload(:status, :priority, :tracker).sort_by(&:lft)) do |child, level| |
|
101 | issue_list(issue.descendants.visible.preload(:status, :priority, :tracker).sort_by(&:lft)) do |child, level| | |
102 | css = "issue issue-#{child.id} hascontextmenu" |
|
102 | css = "issue issue-#{child.id} hascontextmenu" | |
103 | css << " idnt idnt-#{level}" if level > 0 |
|
103 | css << " idnt idnt-#{level}" if level > 0 | |
104 | s << content_tag('tr', |
|
104 | s << content_tag('tr', | |
105 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + |
|
105 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + | |
106 | content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') + |
|
106 | content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') + | |
107 | content_tag('td', h(child.status)) + |
|
107 | content_tag('td', h(child.status)) + | |
108 | content_tag('td', link_to_user(child.assigned_to)) + |
|
108 | content_tag('td', link_to_user(child.assigned_to)) + | |
109 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), |
|
109 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), | |
110 | :class => css) |
|
110 | :class => css) | |
111 | end |
|
111 | end | |
112 | s << '</table></form>' |
|
112 | s << '</table></form>' | |
113 | s.html_safe |
|
113 | s.html_safe | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | def issue_estimated_hours_details(issue) |
|
116 | def issue_estimated_hours_details(issue) | |
117 | s = issue.estimated_hours.present? ? l_hours(issue.estimated_hours) : "" |
|
117 | if issue.total_estimated_hours.present? | |
118 |
|
|
118 | if issue.total_estimated_hours == issue.estimated_hours | |
119 |
|
|
119 | l_hours_short(issue.estimated_hours) | |
|
120 | else | |||
|
121 | s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : "" | |||
|
122 | s << " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})" | |||
|
123 | s.html_safe | |||
|
124 | end | |||
|
125 | end | |||
120 |
|
|
126 | end | |
|
127 | ||||
|
128 | def issue_spent_hours_details(issue) | |||
|
129 | if issue.total_spent_hours > 0 | |||
|
130 | if issue.total_spent_hours == issue.spent_hours | |||
|
131 | link_to(l_hours_short(issue.spent_hours), issue_time_entries_path(issue)) | |||
|
132 | else | |||
|
133 | s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : "" | |||
|
134 | s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), issue_time_entries_path(issue)})" | |||
121 | s.html_safe |
|
135 | s.html_safe | |
122 | end |
|
136 | end | |
|
137 | end | |||
|
138 | end | |||
123 |
|
139 | |||
124 | # Returns an array of error messages for bulk edited issues |
|
140 | # Returns an array of error messages for bulk edited issues | |
125 | def bulk_edit_error_messages(issues) |
|
141 | def bulk_edit_error_messages(issues) | |
126 | messages = {} |
|
142 | messages = {} | |
127 | issues.each do |issue| |
|
143 | issues.each do |issue| | |
128 | issue.errors.full_messages.each do |message| |
|
144 | issue.errors.full_messages.each do |message| | |
129 | messages[message] ||= [] |
|
145 | messages[message] ||= [] | |
130 | messages[message] << issue |
|
146 | messages[message] << issue | |
131 | end |
|
147 | end | |
132 | end |
|
148 | end | |
133 | messages.map { |message, issues| |
|
149 | messages.map { |message, issues| | |
134 | "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ') |
|
150 | "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ') | |
135 | } |
|
151 | } | |
136 | end |
|
152 | end | |
137 |
|
153 | |||
138 | # Returns a link for adding a new subtask to the given issue |
|
154 | # Returns a link for adding a new subtask to the given issue | |
139 | def link_to_new_subtask(issue) |
|
155 | def link_to_new_subtask(issue) | |
140 | attrs = { |
|
156 | attrs = { | |
141 | :tracker_id => issue.tracker, |
|
157 | :tracker_id => issue.tracker, | |
142 | :parent_issue_id => issue |
|
158 | :parent_issue_id => issue | |
143 | } |
|
159 | } | |
144 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) |
|
160 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) | |
145 | end |
|
161 | end | |
146 |
|
162 | |||
147 | class IssueFieldsRows |
|
163 | class IssueFieldsRows | |
148 | include ActionView::Helpers::TagHelper |
|
164 | include ActionView::Helpers::TagHelper | |
149 |
|
165 | |||
150 | def initialize |
|
166 | def initialize | |
151 | @left = [] |
|
167 | @left = [] | |
152 | @right = [] |
|
168 | @right = [] | |
153 | end |
|
169 | end | |
154 |
|
170 | |||
155 | def left(*args) |
|
171 | def left(*args) | |
156 | args.any? ? @left << cells(*args) : @left |
|
172 | args.any? ? @left << cells(*args) : @left | |
157 | end |
|
173 | end | |
158 |
|
174 | |||
159 | def right(*args) |
|
175 | def right(*args) | |
160 | args.any? ? @right << cells(*args) : @right |
|
176 | args.any? ? @right << cells(*args) : @right | |
161 | end |
|
177 | end | |
162 |
|
178 | |||
163 | def size |
|
179 | def size | |
164 | @left.size > @right.size ? @left.size : @right.size |
|
180 | @left.size > @right.size ? @left.size : @right.size | |
165 | end |
|
181 | end | |
166 |
|
182 | |||
167 | def to_html |
|
183 | def to_html | |
168 | html = ''.html_safe |
|
184 | html = ''.html_safe | |
169 | blank = content_tag('th', '') + content_tag('td', '') |
|
185 | blank = content_tag('th', '') + content_tag('td', '') | |
170 | size.times do |i| |
|
186 | size.times do |i| | |
171 | left = @left[i] || blank |
|
187 | left = @left[i] || blank | |
172 | right = @right[i] || blank |
|
188 | right = @right[i] || blank | |
173 | html << content_tag('tr', left + right) |
|
189 | html << content_tag('tr', left + right) | |
174 | end |
|
190 | end | |
175 | html |
|
191 | html | |
176 | end |
|
192 | end | |
177 |
|
193 | |||
178 | def cells(label, text, options={}) |
|
194 | def cells(label, text, options={}) | |
179 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) |
|
195 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) | |
180 | end |
|
196 | end | |
181 | end |
|
197 | end | |
182 |
|
198 | |||
183 | def issue_fields_rows |
|
199 | def issue_fields_rows | |
184 | r = IssueFieldsRows.new |
|
200 | r = IssueFieldsRows.new | |
185 | yield r |
|
201 | yield r | |
186 | r.to_html |
|
202 | r.to_html | |
187 | end |
|
203 | end | |
188 |
|
204 | |||
189 | def render_custom_fields_rows(issue) |
|
205 | def render_custom_fields_rows(issue) | |
190 | values = issue.visible_custom_field_values |
|
206 | values = issue.visible_custom_field_values | |
191 | return if values.empty? |
|
207 | return if values.empty? | |
192 | ordered_values = [] |
|
208 | ordered_values = [] | |
193 | half = (values.size / 2.0).ceil |
|
209 | half = (values.size / 2.0).ceil | |
194 | half.times do |i| |
|
210 | half.times do |i| | |
195 | ordered_values << values[i] |
|
211 | ordered_values << values[i] | |
196 | ordered_values << values[i + half] |
|
212 | ordered_values << values[i + half] | |
197 | end |
|
213 | end | |
198 | s = "<tr>\n" |
|
214 | s = "<tr>\n" | |
199 | n = 0 |
|
215 | n = 0 | |
200 | ordered_values.compact.each do |value| |
|
216 | ordered_values.compact.each do |value| | |
201 | css = "cf_#{value.custom_field.id}" |
|
217 | css = "cf_#{value.custom_field.id}" | |
202 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
|
218 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 | |
203 | s << "\t<th class=\"#{css}\">#{ custom_field_name_tag(value.custom_field) }:</th><td class=\"#{css}\">#{ h(show_value(value)) }</td>\n" |
|
219 | s << "\t<th class=\"#{css}\">#{ custom_field_name_tag(value.custom_field) }:</th><td class=\"#{css}\">#{ h(show_value(value)) }</td>\n" | |
204 | n += 1 |
|
220 | n += 1 | |
205 | end |
|
221 | end | |
206 | s << "</tr>\n" |
|
222 | s << "</tr>\n" | |
207 | s.html_safe |
|
223 | s.html_safe | |
208 | end |
|
224 | end | |
209 |
|
225 | |||
210 | # Returns the path for updating the issue form |
|
226 | # Returns the path for updating the issue form | |
211 | # with project as the current project |
|
227 | # with project as the current project | |
212 | def update_issue_form_path(project, issue) |
|
228 | def update_issue_form_path(project, issue) | |
213 | options = {:format => 'js'} |
|
229 | options = {:format => 'js'} | |
214 | if issue.new_record? |
|
230 | if issue.new_record? | |
215 | if project |
|
231 | if project | |
216 | new_project_issue_path(project, options) |
|
232 | new_project_issue_path(project, options) | |
217 | else |
|
233 | else | |
218 | new_issue_path(options) |
|
234 | new_issue_path(options) | |
219 | end |
|
235 | end | |
220 | else |
|
236 | else | |
221 | edit_issue_path(issue, options) |
|
237 | edit_issue_path(issue, options) | |
222 | end |
|
238 | end | |
223 | end |
|
239 | end | |
224 |
|
240 | |||
225 | # Returns the number of descendants for an array of issues |
|
241 | # Returns the number of descendants for an array of issues | |
226 | def issues_descendant_count(issues) |
|
242 | def issues_descendant_count(issues) | |
227 | ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq |
|
243 | ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq | |
228 | ids -= issues.map(&:id) |
|
244 | ids -= issues.map(&:id) | |
229 | ids.size |
|
245 | ids.size | |
230 | end |
|
246 | end | |
231 |
|
247 | |||
232 | def issues_destroy_confirmation_message(issues) |
|
248 | def issues_destroy_confirmation_message(issues) | |
233 | issues = [issues] unless issues.is_a?(Array) |
|
249 | issues = [issues] unless issues.is_a?(Array) | |
234 | message = l(:text_issues_destroy_confirmation) |
|
250 | message = l(:text_issues_destroy_confirmation) | |
235 |
|
251 | |||
236 | descendant_count = issues_descendant_count(issues) |
|
252 | descendant_count = issues_descendant_count(issues) | |
237 | if descendant_count > 0 |
|
253 | if descendant_count > 0 | |
238 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) |
|
254 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) | |
239 | end |
|
255 | end | |
240 | message |
|
256 | message | |
241 | end |
|
257 | end | |
242 |
|
258 | |||
243 | # Returns an array of users that are proposed as watchers |
|
259 | # Returns an array of users that are proposed as watchers | |
244 | # on the new issue form |
|
260 | # on the new issue form | |
245 | def users_for_new_issue_watchers(issue) |
|
261 | def users_for_new_issue_watchers(issue) | |
246 | users = issue.watcher_users |
|
262 | users = issue.watcher_users | |
247 | if issue.project.users.count <= 20 |
|
263 | if issue.project.users.count <= 20 | |
248 | users = (users + issue.project.users.sort).uniq |
|
264 | users = (users + issue.project.users.sort).uniq | |
249 | end |
|
265 | end | |
250 | users |
|
266 | users | |
251 | end |
|
267 | end | |
252 |
|
268 | |||
253 | def sidebar_queries |
|
269 | def sidebar_queries | |
254 | unless @sidebar_queries |
|
270 | unless @sidebar_queries | |
255 | @sidebar_queries = IssueQuery.visible. |
|
271 | @sidebar_queries = IssueQuery.visible. | |
256 | order("#{Query.table_name}.name ASC"). |
|
272 | order("#{Query.table_name}.name ASC"). | |
257 | # Project specific queries and global queries |
|
273 | # Project specific queries and global queries | |
258 | where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). |
|
274 | where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). | |
259 | to_a |
|
275 | to_a | |
260 | end |
|
276 | end | |
261 | @sidebar_queries |
|
277 | @sidebar_queries | |
262 | end |
|
278 | end | |
263 |
|
279 | |||
264 | def query_links(title, queries) |
|
280 | def query_links(title, queries) | |
265 | return '' if queries.empty? |
|
281 | return '' if queries.empty? | |
266 | # links to #index on issues/show |
|
282 | # links to #index on issues/show | |
267 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params |
|
283 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params | |
268 |
|
284 | |||
269 | content_tag('h3', title) + "\n" + |
|
285 | content_tag('h3', title) + "\n" + | |
270 | content_tag('ul', |
|
286 | content_tag('ul', | |
271 | queries.collect {|query| |
|
287 | queries.collect {|query| | |
272 | css = 'query' |
|
288 | css = 'query' | |
273 | css << ' selected' if query == @query |
|
289 | css << ' selected' if query == @query | |
274 | content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css)) |
|
290 | content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css)) | |
275 | }.join("\n").html_safe, |
|
291 | }.join("\n").html_safe, | |
276 | :class => 'queries' |
|
292 | :class => 'queries' | |
277 | ) + "\n" |
|
293 | ) + "\n" | |
278 | end |
|
294 | end | |
279 |
|
295 | |||
280 | def render_sidebar_queries |
|
296 | def render_sidebar_queries | |
281 | out = ''.html_safe |
|
297 | out = ''.html_safe | |
282 | out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?)) |
|
298 | out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?)) | |
283 | out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?)) |
|
299 | out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?)) | |
284 | out |
|
300 | out | |
285 | end |
|
301 | end | |
286 |
|
302 | |||
287 | def email_issue_attributes(issue, user) |
|
303 | def email_issue_attributes(issue, user) | |
288 | items = [] |
|
304 | items = [] | |
289 | %w(author status priority assigned_to category fixed_version).each do |attribute| |
|
305 | %w(author status priority assigned_to category fixed_version).each do |attribute| | |
290 | unless issue.disabled_core_fields.include?(attribute+"_id") |
|
306 | unless issue.disabled_core_fields.include?(attribute+"_id") | |
291 | items << "#{l("field_#{attribute}")}: #{issue.send attribute}" |
|
307 | items << "#{l("field_#{attribute}")}: #{issue.send attribute}" | |
292 | end |
|
308 | end | |
293 | end |
|
309 | end | |
294 | issue.visible_custom_field_values(user).each do |value| |
|
310 | issue.visible_custom_field_values(user).each do |value| | |
295 | items << "#{value.custom_field.name}: #{show_value(value, false)}" |
|
311 | items << "#{value.custom_field.name}: #{show_value(value, false)}" | |
296 | end |
|
312 | end | |
297 | items |
|
313 | items | |
298 | end |
|
314 | end | |
299 |
|
315 | |||
300 | def render_email_issue_attributes(issue, user, html=false) |
|
316 | def render_email_issue_attributes(issue, user, html=false) | |
301 | items = email_issue_attributes(issue, user) |
|
317 | items = email_issue_attributes(issue, user) | |
302 | if html |
|
318 | if html | |
303 | content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe) |
|
319 | content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe) | |
304 | else |
|
320 | else | |
305 | items.map{|s| "* #{s}"}.join("\n") |
|
321 | items.map{|s| "* #{s}"}.join("\n") | |
306 | end |
|
322 | end | |
307 | end |
|
323 | end | |
308 |
|
324 | |||
309 | # Returns the textual representation of a journal details |
|
325 | # Returns the textual representation of a journal details | |
310 | # as an array of strings |
|
326 | # as an array of strings | |
311 | def details_to_strings(details, no_html=false, options={}) |
|
327 | def details_to_strings(details, no_html=false, options={}) | |
312 | options[:only_path] = (options[:only_path] == false ? false : true) |
|
328 | options[:only_path] = (options[:only_path] == false ? false : true) | |
313 | strings = [] |
|
329 | strings = [] | |
314 | values_by_field = {} |
|
330 | values_by_field = {} | |
315 | details.each do |detail| |
|
331 | details.each do |detail| | |
316 | if detail.property == 'cf' |
|
332 | if detail.property == 'cf' | |
317 | field = detail.custom_field |
|
333 | field = detail.custom_field | |
318 | if field && field.multiple? |
|
334 | if field && field.multiple? | |
319 | values_by_field[field] ||= {:added => [], :deleted => []} |
|
335 | values_by_field[field] ||= {:added => [], :deleted => []} | |
320 | if detail.old_value |
|
336 | if detail.old_value | |
321 | values_by_field[field][:deleted] << detail.old_value |
|
337 | values_by_field[field][:deleted] << detail.old_value | |
322 | end |
|
338 | end | |
323 | if detail.value |
|
339 | if detail.value | |
324 | values_by_field[field][:added] << detail.value |
|
340 | values_by_field[field][:added] << detail.value | |
325 | end |
|
341 | end | |
326 | next |
|
342 | next | |
327 | end |
|
343 | end | |
328 | end |
|
344 | end | |
329 | strings << show_detail(detail, no_html, options) |
|
345 | strings << show_detail(detail, no_html, options) | |
330 | end |
|
346 | end | |
331 | if values_by_field.present? |
|
347 | if values_by_field.present? | |
332 | multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value) |
|
348 | multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value) | |
333 | values_by_field.each do |field, changes| |
|
349 | values_by_field.each do |field, changes| | |
334 | if changes[:added].any? |
|
350 | if changes[:added].any? | |
335 | detail = multiple_values_detail.new('cf', field.id.to_s, field) |
|
351 | detail = multiple_values_detail.new('cf', field.id.to_s, field) | |
336 | detail.value = changes[:added] |
|
352 | detail.value = changes[:added] | |
337 | strings << show_detail(detail, no_html, options) |
|
353 | strings << show_detail(detail, no_html, options) | |
338 | end |
|
354 | end | |
339 | if changes[:deleted].any? |
|
355 | if changes[:deleted].any? | |
340 | detail = multiple_values_detail.new('cf', field.id.to_s, field) |
|
356 | detail = multiple_values_detail.new('cf', field.id.to_s, field) | |
341 | detail.old_value = changes[:deleted] |
|
357 | detail.old_value = changes[:deleted] | |
342 | strings << show_detail(detail, no_html, options) |
|
358 | strings << show_detail(detail, no_html, options) | |
343 | end |
|
359 | end | |
344 | end |
|
360 | end | |
345 | end |
|
361 | end | |
346 | strings |
|
362 | strings | |
347 | end |
|
363 | end | |
348 |
|
364 | |||
349 | # Returns the textual representation of a single journal detail |
|
365 | # Returns the textual representation of a single journal detail | |
350 | def show_detail(detail, no_html=false, options={}) |
|
366 | def show_detail(detail, no_html=false, options={}) | |
351 | multiple = false |
|
367 | multiple = false | |
352 | show_diff = false |
|
368 | show_diff = false | |
353 |
|
369 | |||
354 | case detail.property |
|
370 | case detail.property | |
355 | when 'attr' |
|
371 | when 'attr' | |
356 | field = detail.prop_key.to_s.gsub(/\_id$/, "") |
|
372 | field = detail.prop_key.to_s.gsub(/\_id$/, "") | |
357 | label = l(("field_" + field).to_sym) |
|
373 | label = l(("field_" + field).to_sym) | |
358 | case detail.prop_key |
|
374 | case detail.prop_key | |
359 | when 'due_date', 'start_date' |
|
375 | when 'due_date', 'start_date' | |
360 | value = format_date(detail.value.to_date) if detail.value |
|
376 | value = format_date(detail.value.to_date) if detail.value | |
361 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
377 | old_value = format_date(detail.old_value.to_date) if detail.old_value | |
362 |
|
378 | |||
363 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', |
|
379 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', | |
364 | 'priority_id', 'category_id', 'fixed_version_id' |
|
380 | 'priority_id', 'category_id', 'fixed_version_id' | |
365 | value = find_name_by_reflection(field, detail.value) |
|
381 | value = find_name_by_reflection(field, detail.value) | |
366 | old_value = find_name_by_reflection(field, detail.old_value) |
|
382 | old_value = find_name_by_reflection(field, detail.old_value) | |
367 |
|
383 | |||
368 | when 'estimated_hours' |
|
384 | when 'estimated_hours' | |
369 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
|
385 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? | |
370 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
|
386 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? | |
371 |
|
387 | |||
372 | when 'parent_id' |
|
388 | when 'parent_id' | |
373 | label = l(:field_parent_issue) |
|
389 | label = l(:field_parent_issue) | |
374 | value = "##{detail.value}" unless detail.value.blank? |
|
390 | value = "##{detail.value}" unless detail.value.blank? | |
375 | old_value = "##{detail.old_value}" unless detail.old_value.blank? |
|
391 | old_value = "##{detail.old_value}" unless detail.old_value.blank? | |
376 |
|
392 | |||
377 | when 'is_private' |
|
393 | when 'is_private' | |
378 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? |
|
394 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? | |
379 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? |
|
395 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? | |
380 |
|
396 | |||
381 | when 'description' |
|
397 | when 'description' | |
382 | show_diff = true |
|
398 | show_diff = true | |
383 | end |
|
399 | end | |
384 | when 'cf' |
|
400 | when 'cf' | |
385 | custom_field = detail.custom_field |
|
401 | custom_field = detail.custom_field | |
386 | if custom_field |
|
402 | if custom_field | |
387 | label = custom_field.name |
|
403 | label = custom_field.name | |
388 | if custom_field.format.class.change_as_diff |
|
404 | if custom_field.format.class.change_as_diff | |
389 | show_diff = true |
|
405 | show_diff = true | |
390 | else |
|
406 | else | |
391 | multiple = custom_field.multiple? |
|
407 | multiple = custom_field.multiple? | |
392 | value = format_value(detail.value, custom_field) if detail.value |
|
408 | value = format_value(detail.value, custom_field) if detail.value | |
393 | old_value = format_value(detail.old_value, custom_field) if detail.old_value |
|
409 | old_value = format_value(detail.old_value, custom_field) if detail.old_value | |
394 | end |
|
410 | end | |
395 | end |
|
411 | end | |
396 | when 'attachment' |
|
412 | when 'attachment' | |
397 | label = l(:label_attachment) |
|
413 | label = l(:label_attachment) | |
398 | when 'relation' |
|
414 | when 'relation' | |
399 | if detail.value && !detail.old_value |
|
415 | if detail.value && !detail.old_value | |
400 | rel_issue = Issue.visible.find_by_id(detail.value) |
|
416 | rel_issue = Issue.visible.find_by_id(detail.value) | |
401 | value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" : |
|
417 | value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" : | |
402 | (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path])) |
|
418 | (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path])) | |
403 | elsif detail.old_value && !detail.value |
|
419 | elsif detail.old_value && !detail.value | |
404 | rel_issue = Issue.visible.find_by_id(detail.old_value) |
|
420 | rel_issue = Issue.visible.find_by_id(detail.old_value) | |
405 | old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" : |
|
421 | old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" : | |
406 | (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path])) |
|
422 | (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path])) | |
407 | end |
|
423 | end | |
408 | relation_type = IssueRelation::TYPES[detail.prop_key] |
|
424 | relation_type = IssueRelation::TYPES[detail.prop_key] | |
409 | label = l(relation_type[:name]) if relation_type |
|
425 | label = l(relation_type[:name]) if relation_type | |
410 | end |
|
426 | end | |
411 | call_hook(:helper_issues_show_detail_after_setting, |
|
427 | call_hook(:helper_issues_show_detail_after_setting, | |
412 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) |
|
428 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) | |
413 |
|
429 | |||
414 | label ||= detail.prop_key |
|
430 | label ||= detail.prop_key | |
415 | value ||= detail.value |
|
431 | value ||= detail.value | |
416 | old_value ||= detail.old_value |
|
432 | old_value ||= detail.old_value | |
417 |
|
433 | |||
418 | unless no_html |
|
434 | unless no_html | |
419 | label = content_tag('strong', label) |
|
435 | label = content_tag('strong', label) | |
420 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
436 | old_value = content_tag("i", h(old_value)) if detail.old_value | |
421 | if detail.old_value && detail.value.blank? && detail.property != 'relation' |
|
437 | if detail.old_value && detail.value.blank? && detail.property != 'relation' | |
422 | old_value = content_tag("del", old_value) |
|
438 | old_value = content_tag("del", old_value) | |
423 | end |
|
439 | end | |
424 | if detail.property == 'attachment' && value.present? && |
|
440 | if detail.property == 'attachment' && value.present? && | |
425 | atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i} |
|
441 | atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i} | |
426 | # Link to the attachment if it has not been removed |
|
442 | # Link to the attachment if it has not been removed | |
427 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) |
|
443 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) | |
428 | if options[:only_path] != false && atta.is_text? |
|
444 | if options[:only_path] != false && atta.is_text? | |
429 | value += link_to( |
|
445 | value += link_to( | |
430 | image_tag('magnifier.png'), |
|
446 | image_tag('magnifier.png'), | |
431 | :controller => 'attachments', :action => 'show', |
|
447 | :controller => 'attachments', :action => 'show', | |
432 | :id => atta, :filename => atta.filename |
|
448 | :id => atta, :filename => atta.filename | |
433 | ) |
|
449 | ) | |
434 | end |
|
450 | end | |
435 | else |
|
451 | else | |
436 | value = content_tag("i", h(value)) if value |
|
452 | value = content_tag("i", h(value)) if value | |
437 | end |
|
453 | end | |
438 | end |
|
454 | end | |
439 |
|
455 | |||
440 | if show_diff |
|
456 | if show_diff | |
441 | s = l(:text_journal_changed_no_detail, :label => label) |
|
457 | s = l(:text_journal_changed_no_detail, :label => label) | |
442 | unless no_html |
|
458 | unless no_html | |
443 | diff_link = link_to 'diff', |
|
459 | diff_link = link_to 'diff', | |
444 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, |
|
460 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, | |
445 | :detail_id => detail.id, :only_path => options[:only_path]}, |
|
461 | :detail_id => detail.id, :only_path => options[:only_path]}, | |
446 | :title => l(:label_view_diff) |
|
462 | :title => l(:label_view_diff) | |
447 | s << " (#{ diff_link })" |
|
463 | s << " (#{ diff_link })" | |
448 | end |
|
464 | end | |
449 | s.html_safe |
|
465 | s.html_safe | |
450 | elsif detail.value.present? |
|
466 | elsif detail.value.present? | |
451 | case detail.property |
|
467 | case detail.property | |
452 | when 'attr', 'cf' |
|
468 | when 'attr', 'cf' | |
453 | if detail.old_value.present? |
|
469 | if detail.old_value.present? | |
454 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe |
|
470 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe | |
455 | elsif multiple |
|
471 | elsif multiple | |
456 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
472 | l(:text_journal_added, :label => label, :value => value).html_safe | |
457 | else |
|
473 | else | |
458 | l(:text_journal_set_to, :label => label, :value => value).html_safe |
|
474 | l(:text_journal_set_to, :label => label, :value => value).html_safe | |
459 | end |
|
475 | end | |
460 | when 'attachment', 'relation' |
|
476 | when 'attachment', 'relation' | |
461 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
477 | l(:text_journal_added, :label => label, :value => value).html_safe | |
462 | end |
|
478 | end | |
463 | else |
|
479 | else | |
464 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe |
|
480 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe | |
465 | end |
|
481 | end | |
466 | end |
|
482 | end | |
467 |
|
483 | |||
468 | # Find the name of an associated record stored in the field attribute |
|
484 | # Find the name of an associated record stored in the field attribute | |
469 | def find_name_by_reflection(field, id) |
|
485 | def find_name_by_reflection(field, id) | |
470 | unless id.present? |
|
486 | unless id.present? | |
471 | return nil |
|
487 | return nil | |
472 | end |
|
488 | end | |
473 | @detail_value_name_by_reflection ||= Hash.new do |hash, key| |
|
489 | @detail_value_name_by_reflection ||= Hash.new do |hash, key| | |
474 | association = Issue.reflect_on_association(key.first.to_sym) |
|
490 | association = Issue.reflect_on_association(key.first.to_sym) | |
475 | name = nil |
|
491 | name = nil | |
476 | if association |
|
492 | if association | |
477 | record = association.klass.find_by_id(key.last) |
|
493 | record = association.klass.find_by_id(key.last) | |
478 | if record |
|
494 | if record | |
479 | name = record.name.force_encoding('UTF-8') |
|
495 | name = record.name.force_encoding('UTF-8') | |
480 | end |
|
496 | end | |
481 | end |
|
497 | end | |
482 | hash[key] = name |
|
498 | hash[key] = name | |
483 | end |
|
499 | end | |
484 | @detail_value_name_by_reflection[[field, id]] |
|
500 | @detail_value_name_by_reflection[[field, id]] | |
485 | end |
|
501 | end | |
486 |
|
502 | |||
487 | # Renders issue children recursively |
|
503 | # Renders issue children recursively | |
488 | def render_api_issue_children(issue, api) |
|
504 | def render_api_issue_children(issue, api) | |
489 | return if issue.leaf? |
|
505 | return if issue.leaf? | |
490 | api.array :children do |
|
506 | api.array :children do | |
491 | issue.children.each do |child| |
|
507 | issue.children.each do |child| | |
492 | api.issue(:id => child.id) do |
|
508 | api.issue(:id => child.id) do | |
493 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? |
|
509 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? | |
494 | api.subject child.subject |
|
510 | api.subject child.subject | |
495 | render_api_issue_children(child, api) |
|
511 | render_api_issue_children(child, api) | |
496 | end |
|
512 | end | |
497 | end |
|
513 | end | |
498 | end |
|
514 | end | |
499 | end |
|
515 | end | |
500 | end |
|
516 | end |
@@ -1,160 +1,162 | |||||
1 | <%= render :partial => 'action_menu' %> |
|
1 | <%= render :partial => 'action_menu' %> | |
2 |
|
2 | |||
3 | <h2><%= issue_heading(@issue) %></h2> |
|
3 | <h2><%= issue_heading(@issue) %></h2> | |
4 |
|
4 | |||
5 | <div class="<%= @issue.css_classes %> details"> |
|
5 | <div class="<%= @issue.css_classes %> details"> | |
6 | <% if @prev_issue_id || @next_issue_id %> |
|
6 | <% if @prev_issue_id || @next_issue_id %> | |
7 | <div class="next-prev-links contextual"> |
|
7 | <div class="next-prev-links contextual"> | |
8 | <%= link_to_if @prev_issue_id, |
|
8 | <%= link_to_if @prev_issue_id, | |
9 | "\xc2\xab #{l(:label_previous)}", |
|
9 | "\xc2\xab #{l(:label_previous)}", | |
10 | (@prev_issue_id ? issue_path(@prev_issue_id) : nil), |
|
10 | (@prev_issue_id ? issue_path(@prev_issue_id) : nil), | |
11 | :title => "##{@prev_issue_id}", |
|
11 | :title => "##{@prev_issue_id}", | |
12 | :accesskey => accesskey(:previous) %> | |
|
12 | :accesskey => accesskey(:previous) %> | | |
13 | <% if @issue_position && @issue_count %> |
|
13 | <% if @issue_position && @issue_count %> | |
14 | <span class="position"><%= l(:label_item_position, :position => @issue_position, :count => @issue_count) %></span> | |
|
14 | <span class="position"><%= l(:label_item_position, :position => @issue_position, :count => @issue_count) %></span> | | |
15 | <% end %> |
|
15 | <% end %> | |
16 | <%= link_to_if @next_issue_id, |
|
16 | <%= link_to_if @next_issue_id, | |
17 | "#{l(:label_next)} \xc2\xbb", |
|
17 | "#{l(:label_next)} \xc2\xbb", | |
18 | (@next_issue_id ? issue_path(@next_issue_id) : nil), |
|
18 | (@next_issue_id ? issue_path(@next_issue_id) : nil), | |
19 | :title => "##{@next_issue_id}", |
|
19 | :title => "##{@next_issue_id}", | |
20 | :accesskey => accesskey(:next) %> |
|
20 | :accesskey => accesskey(:next) %> | |
21 | </div> |
|
21 | </div> | |
22 | <% end %> |
|
22 | <% end %> | |
23 |
|
23 | |||
24 | <%= avatar(@issue.author, :size => "50") %> |
|
24 | <%= avatar(@issue.author, :size => "50") %> | |
25 |
|
25 | |||
26 | <div class="subject"> |
|
26 | <div class="subject"> | |
27 | <%= render_issue_subject_with_tree(@issue) %> |
|
27 | <%= render_issue_subject_with_tree(@issue) %> | |
28 | </div> |
|
28 | </div> | |
29 | <p class="author"> |
|
29 | <p class="author"> | |
30 | <%= authoring @issue.created_on, @issue.author %>. |
|
30 | <%= authoring @issue.created_on, @issue.author %>. | |
31 | <% if @issue.created_on != @issue.updated_on %> |
|
31 | <% if @issue.created_on != @issue.updated_on %> | |
32 | <%= l(:label_updated_time, time_tag(@issue.updated_on)).html_safe %>. |
|
32 | <%= l(:label_updated_time, time_tag(@issue.updated_on)).html_safe %>. | |
33 | <% end %> |
|
33 | <% end %> | |
34 | </p> |
|
34 | </p> | |
35 |
|
35 | |||
36 | <table class="attributes"> |
|
36 | <table class="attributes"> | |
37 | <%= issue_fields_rows do |rows| |
|
37 | <%= issue_fields_rows do |rows| | |
38 | rows.left l(:field_status), @issue.status.name, :class => 'status' |
|
38 | rows.left l(:field_status), @issue.status.name, :class => 'status' | |
39 | rows.left l(:field_priority), @issue.priority.name, :class => 'priority' |
|
39 | rows.left l(:field_priority), @issue.priority.name, :class => 'priority' | |
40 |
|
40 | |||
41 | unless @issue.disabled_core_fields.include?('assigned_to_id') |
|
41 | unless @issue.disabled_core_fields.include?('assigned_to_id') | |
42 | rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to' |
|
42 | rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to' | |
43 | end |
|
43 | end | |
44 | unless @issue.disabled_core_fields.include?('category_id') |
|
44 | unless @issue.disabled_core_fields.include?('category_id') | |
45 | rows.left l(:field_category), (@issue.category ? @issue.category.name : "-"), :class => 'category' |
|
45 | rows.left l(:field_category), (@issue.category ? @issue.category.name : "-"), :class => 'category' | |
46 | end |
|
46 | end | |
47 | unless @issue.disabled_core_fields.include?('fixed_version_id') |
|
47 | unless @issue.disabled_core_fields.include?('fixed_version_id') | |
48 | rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version' |
|
48 | rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version' | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | unless @issue.disabled_core_fields.include?('start_date') |
|
51 | unless @issue.disabled_core_fields.include?('start_date') | |
52 | rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date' |
|
52 | rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date' | |
53 | end |
|
53 | end | |
54 | unless @issue.disabled_core_fields.include?('due_date') |
|
54 | unless @issue.disabled_core_fields.include?('due_date') | |
55 | rows.right l(:field_due_date), format_date(@issue.due_date), :class => 'due-date' |
|
55 | rows.right l(:field_due_date), format_date(@issue.due_date), :class => 'due-date' | |
56 | end |
|
56 | end | |
57 | unless @issue.disabled_core_fields.include?('done_ratio') |
|
57 | unless @issue.disabled_core_fields.include?('done_ratio') | |
58 | rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%"), :class => 'progress' |
|
58 | rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%"), :class => 'progress' | |
59 | end |
|
59 | end | |
60 | unless @issue.disabled_core_fields.include?('estimated_hours') |
|
60 | unless @issue.disabled_core_fields.include?('estimated_hours') | |
61 | unless @issue.total_estimated_hours.nil? |
|
61 | unless @issue.total_estimated_hours.nil? | |
62 | rows.right l(:field_estimated_hours), issue_estimated_hours_details(@issue), :class => 'estimated-hours' |
|
62 | rows.right l(:field_estimated_hours), issue_estimated_hours_details(@issue), :class => 'estimated-hours' | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 | if User.current.allowed_to?(:view_time_entries, @project) |
|
65 | if User.current.allowed_to?(:view_time_entries, @project) | |
66 | rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@issue.total_spent_hours), issue_time_entries_path(@issue)) : "-"), :class => 'spent-time' |
|
66 | if @issue.total_spent_hours > 0 | |
|
67 | rows.right l(:label_spent_time), issue_spent_hours_details(@issue), :class => 'spent-time' | |||
|
68 | end | |||
67 | end |
|
69 | end | |
68 | end %> |
|
70 | end %> | |
69 | <%= render_custom_fields_rows(@issue) %> |
|
71 | <%= render_custom_fields_rows(@issue) %> | |
70 | <%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %> |
|
72 | <%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %> | |
71 | </table> |
|
73 | </table> | |
72 |
|
74 | |||
73 | <% if @issue.description? || @issue.attachments.any? -%> |
|
75 | <% if @issue.description? || @issue.attachments.any? -%> | |
74 | <hr /> |
|
76 | <hr /> | |
75 | <% if @issue.description? %> |
|
77 | <% if @issue.description? %> | |
76 | <div class="description"> |
|
78 | <div class="description"> | |
77 | <div class="contextual"> |
|
79 | <div class="contextual"> | |
78 | <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %> |
|
80 | <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %> | |
79 | </div> |
|
81 | </div> | |
80 |
|
82 | |||
81 | <p><strong><%=l(:field_description)%></strong></p> |
|
83 | <p><strong><%=l(:field_description)%></strong></p> | |
82 | <div class="wiki"> |
|
84 | <div class="wiki"> | |
83 | <%= textilizable @issue, :description, :attachments => @issue.attachments %> |
|
85 | <%= textilizable @issue, :description, :attachments => @issue.attachments %> | |
84 | </div> |
|
86 | </div> | |
85 | </div> |
|
87 | </div> | |
86 | <% end %> |
|
88 | <% end %> | |
87 | <%= link_to_attachments @issue, :thumbnails => true %> |
|
89 | <%= link_to_attachments @issue, :thumbnails => true %> | |
88 | <% end -%> |
|
90 | <% end -%> | |
89 |
|
91 | |||
90 | <%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %> |
|
92 | <%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %> | |
91 |
|
93 | |||
92 | <% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %> |
|
94 | <% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %> | |
93 | <hr /> |
|
95 | <hr /> | |
94 | <div id="issue_tree"> |
|
96 | <div id="issue_tree"> | |
95 | <div class="contextual"> |
|
97 | <div class="contextual"> | |
96 | <%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) %> |
|
98 | <%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) %> | |
97 | </div> |
|
99 | </div> | |
98 | <p><strong><%=l(:label_subtask_plural)%></strong></p> |
|
100 | <p><strong><%=l(:label_subtask_plural)%></strong></p> | |
99 | <%= render_descendants_tree(@issue) unless @issue.leaf? %> |
|
101 | <%= render_descendants_tree(@issue) unless @issue.leaf? %> | |
100 | </div> |
|
102 | </div> | |
101 | <% end %> |
|
103 | <% end %> | |
102 |
|
104 | |||
103 | <% if @relations.present? || User.current.allowed_to?(:manage_issue_relations, @project) %> |
|
105 | <% if @relations.present? || User.current.allowed_to?(:manage_issue_relations, @project) %> | |
104 | <hr /> |
|
106 | <hr /> | |
105 | <div id="relations"> |
|
107 | <div id="relations"> | |
106 | <%= render :partial => 'relations' %> |
|
108 | <%= render :partial => 'relations' %> | |
107 | </div> |
|
109 | </div> | |
108 | <% end %> |
|
110 | <% end %> | |
109 |
|
111 | |||
110 | </div> |
|
112 | </div> | |
111 |
|
113 | |||
112 | <% if @changesets.present? %> |
|
114 | <% if @changesets.present? %> | |
113 | <div id="issue-changesets"> |
|
115 | <div id="issue-changesets"> | |
114 | <h3><%=l(:label_associated_revisions)%></h3> |
|
116 | <h3><%=l(:label_associated_revisions)%></h3> | |
115 | <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %> |
|
117 | <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %> | |
116 | </div> |
|
118 | </div> | |
117 | <% end %> |
|
119 | <% end %> | |
118 |
|
120 | |||
119 | <% if @journals.present? %> |
|
121 | <% if @journals.present? %> | |
120 | <div id="history"> |
|
122 | <div id="history"> | |
121 | <h3><%=l(:label_history)%></h3> |
|
123 | <h3><%=l(:label_history)%></h3> | |
122 | <%= render :partial => 'history', :locals => { :issue => @issue, :journals => @journals } %> |
|
124 | <%= render :partial => 'history', :locals => { :issue => @issue, :journals => @journals } %> | |
123 | </div> |
|
125 | </div> | |
124 | <% end %> |
|
126 | <% end %> | |
125 |
|
127 | |||
126 |
|
128 | |||
127 | <div style="clear: both;"></div> |
|
129 | <div style="clear: both;"></div> | |
128 | <%= render :partial => 'action_menu' %> |
|
130 | <%= render :partial => 'action_menu' %> | |
129 |
|
131 | |||
130 | <div style="clear: both;"></div> |
|
132 | <div style="clear: both;"></div> | |
131 | <% if @issue.editable? %> |
|
133 | <% if @issue.editable? %> | |
132 | <div id="update" style="display:none;"> |
|
134 | <div id="update" style="display:none;"> | |
133 | <h3><%= l(:button_edit) %></h3> |
|
135 | <h3><%= l(:button_edit) %></h3> | |
134 | <%= render :partial => 'edit' %> |
|
136 | <%= render :partial => 'edit' %> | |
135 | </div> |
|
137 | </div> | |
136 | <% end %> |
|
138 | <% end %> | |
137 |
|
139 | |||
138 | <% other_formats_links do |f| %> |
|
140 | <% other_formats_links do |f| %> | |
139 | <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> |
|
141 | <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> | |
140 | <%= f.link_to 'PDF' %> |
|
142 | <%= f.link_to 'PDF' %> | |
141 | <% end %> |
|
143 | <% end %> | |
142 |
|
144 | |||
143 | <% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> |
|
145 | <% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> | |
144 |
|
146 | |||
145 | <% content_for :sidebar do %> |
|
147 | <% content_for :sidebar do %> | |
146 | <%= render :partial => 'issues/sidebar' %> |
|
148 | <%= render :partial => 'issues/sidebar' %> | |
147 |
|
149 | |||
148 | <% if User.current.allowed_to?(:add_issue_watchers, @project) || |
|
150 | <% if User.current.allowed_to?(:add_issue_watchers, @project) || | |
149 | (@issue.watchers.present? && User.current.allowed_to?(:view_issue_watchers, @project)) %> |
|
151 | (@issue.watchers.present? && User.current.allowed_to?(:view_issue_watchers, @project)) %> | |
150 | <div id="watchers"> |
|
152 | <div id="watchers"> | |
151 | <%= render :partial => 'watchers/watchers', :locals => {:watched => @issue} %> |
|
153 | <%= render :partial => 'watchers/watchers', :locals => {:watched => @issue} %> | |
152 | </div> |
|
154 | </div> | |
153 | <% end %> |
|
155 | <% end %> | |
154 | <% end %> |
|
156 | <% end %> | |
155 |
|
157 | |||
156 | <% content_for :header_tags do %> |
|
158 | <% content_for :header_tags do %> | |
157 | <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %> |
|
159 | <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %> | |
158 | <% end %> |
|
160 | <% end %> | |
159 |
|
161 | |||
160 | <%= context_menu issues_context_menu_path %> |
|
162 | <%= context_menu issues_context_menu_path %> |
@@ -1,191 +1,195 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module Redmine |
|
18 | module Redmine | |
19 | module I18n |
|
19 | module I18n | |
20 | def self.included(base) |
|
20 | def self.included(base) | |
21 | base.extend Redmine::I18n |
|
21 | base.extend Redmine::I18n | |
22 | end |
|
22 | end | |
23 |
|
23 | |||
24 | def l(*args) |
|
24 | def l(*args) | |
25 | case args.size |
|
25 | case args.size | |
26 | when 1 |
|
26 | when 1 | |
27 | ::I18n.t(*args) |
|
27 | ::I18n.t(*args) | |
28 | when 2 |
|
28 | when 2 | |
29 | if args.last.is_a?(Hash) |
|
29 | if args.last.is_a?(Hash) | |
30 | ::I18n.t(*args) |
|
30 | ::I18n.t(*args) | |
31 | elsif args.last.is_a?(String) |
|
31 | elsif args.last.is_a?(String) | |
32 | ::I18n.t(args.first, :value => args.last) |
|
32 | ::I18n.t(args.first, :value => args.last) | |
33 | else |
|
33 | else | |
34 | ::I18n.t(args.first, :count => args.last) |
|
34 | ::I18n.t(args.first, :count => args.last) | |
35 | end |
|
35 | end | |
36 | else |
|
36 | else | |
37 | raise "Translation string with multiple values: #{args.first}" |
|
37 | raise "Translation string with multiple values: #{args.first}" | |
38 | end |
|
38 | end | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def l_or_humanize(s, options={}) |
|
41 | def l_or_humanize(s, options={}) | |
42 | k = "#{options[:prefix]}#{s}".to_sym |
|
42 | k = "#{options[:prefix]}#{s}".to_sym | |
43 | ::I18n.t(k, :default => s.to_s.humanize) |
|
43 | ::I18n.t(k, :default => s.to_s.humanize) | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def l_hours(hours) |
|
46 | def l_hours(hours) | |
47 | hours = hours.to_f |
|
47 | hours = hours.to_f | |
48 | l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f)) |
|
48 | l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f)) | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
|
51 | def l_hours_short(hours) | |||
|
52 | "%.2f h" % hours.to_f | |||
|
53 | end | |||
|
54 | ||||
51 | def ll(lang, str, value=nil) |
|
55 | def ll(lang, str, value=nil) | |
52 | ::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" }) |
|
56 | ::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" }) | |
53 | end |
|
57 | end | |
54 |
|
58 | |||
55 | def format_date(date) |
|
59 | def format_date(date) | |
56 | return nil unless date |
|
60 | return nil unless date | |
57 | options = {} |
|
61 | options = {} | |
58 | options[:format] = Setting.date_format unless Setting.date_format.blank? |
|
62 | options[:format] = Setting.date_format unless Setting.date_format.blank? | |
59 | ::I18n.l(date.to_date, options) |
|
63 | ::I18n.l(date.to_date, options) | |
60 | end |
|
64 | end | |
61 |
|
65 | |||
62 | def format_time(time, include_date = true) |
|
66 | def format_time(time, include_date = true) | |
63 | return nil unless time |
|
67 | return nil unless time | |
64 | options = {} |
|
68 | options = {} | |
65 | options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format) |
|
69 | options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format) | |
66 | time = time.to_time if time.is_a?(String) |
|
70 | time = time.to_time if time.is_a?(String) | |
67 | zone = User.current.time_zone |
|
71 | zone = User.current.time_zone | |
68 | local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) |
|
72 | local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) | |
69 | (include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options) |
|
73 | (include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options) | |
70 | end |
|
74 | end | |
71 |
|
75 | |||
72 | def day_name(day) |
|
76 | def day_name(day) | |
73 | ::I18n.t('date.day_names')[day % 7] |
|
77 | ::I18n.t('date.day_names')[day % 7] | |
74 | end |
|
78 | end | |
75 |
|
79 | |||
76 | def day_letter(day) |
|
80 | def day_letter(day) | |
77 | ::I18n.t('date.abbr_day_names')[day % 7].first |
|
81 | ::I18n.t('date.abbr_day_names')[day % 7].first | |
78 | end |
|
82 | end | |
79 |
|
83 | |||
80 | def month_name(month) |
|
84 | def month_name(month) | |
81 | ::I18n.t('date.month_names')[month] |
|
85 | ::I18n.t('date.month_names')[month] | |
82 | end |
|
86 | end | |
83 |
|
87 | |||
84 | def valid_languages |
|
88 | def valid_languages | |
85 | ::I18n.available_locales |
|
89 | ::I18n.available_locales | |
86 | end |
|
90 | end | |
87 |
|
91 | |||
88 | # Returns an array of languages names and code sorted by names, example: |
|
92 | # Returns an array of languages names and code sorted by names, example: | |
89 | # [["Deutsch", "de"], ["English", "en"] ...] |
|
93 | # [["Deutsch", "de"], ["English", "en"] ...] | |
90 | # |
|
94 | # | |
91 | # The result is cached to prevent from loading all translations files |
|
95 | # The result is cached to prevent from loading all translations files | |
92 | # unless :cache => false option is given |
|
96 | # unless :cache => false option is given | |
93 | def languages_options(options={}) |
|
97 | def languages_options(options={}) | |
94 | options = if options[:cache] == false |
|
98 | options = if options[:cache] == false | |
95 | valid_languages. |
|
99 | valid_languages. | |
96 | select {|locale| ::I18n.exists?(:general_lang_name, locale)}. |
|
100 | select {|locale| ::I18n.exists?(:general_lang_name, locale)}. | |
97 | map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}. |
|
101 | map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}. | |
98 | sort {|x,y| x.first <=> y.first } |
|
102 | sort {|x,y| x.first <=> y.first } | |
99 | else |
|
103 | else | |
100 | ActionController::Base.cache_store.fetch "i18n/languages_options/#{Redmine::VERSION}" do |
|
104 | ActionController::Base.cache_store.fetch "i18n/languages_options/#{Redmine::VERSION}" do | |
101 | languages_options :cache => false |
|
105 | languages_options :cache => false | |
102 | end |
|
106 | end | |
103 | end |
|
107 | end | |
104 | options.map {|name, lang| [name.force_encoding("UTF-8"), lang.force_encoding("UTF-8")]} |
|
108 | options.map {|name, lang| [name.force_encoding("UTF-8"), lang.force_encoding("UTF-8")]} | |
105 | end |
|
109 | end | |
106 |
|
110 | |||
107 | def find_language(lang) |
|
111 | def find_language(lang) | |
108 | @@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k } |
|
112 | @@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k } | |
109 | @@languages_lookup[lang.to_s.downcase] |
|
113 | @@languages_lookup[lang.to_s.downcase] | |
110 | end |
|
114 | end | |
111 |
|
115 | |||
112 | def set_language_if_valid(lang) |
|
116 | def set_language_if_valid(lang) | |
113 | if l = find_language(lang) |
|
117 | if l = find_language(lang) | |
114 | ::I18n.locale = l |
|
118 | ::I18n.locale = l | |
115 | end |
|
119 | end | |
116 | end |
|
120 | end | |
117 |
|
121 | |||
118 | def current_language |
|
122 | def current_language | |
119 | ::I18n.locale |
|
123 | ::I18n.locale | |
120 | end |
|
124 | end | |
121 |
|
125 | |||
122 | # Custom backend based on I18n::Backend::Simple with the following changes: |
|
126 | # Custom backend based on I18n::Backend::Simple with the following changes: | |
123 | # * lazy loading of translation files |
|
127 | # * lazy loading of translation files | |
124 | # * available_locales are determined by looking at translation file names |
|
128 | # * available_locales are determined by looking at translation file names | |
125 | class Backend |
|
129 | class Backend | |
126 | (class << self; self; end).class_eval { public :include } |
|
130 | (class << self; self; end).class_eval { public :include } | |
127 |
|
131 | |||
128 | module Implementation |
|
132 | module Implementation | |
129 | include ::I18n::Backend::Base |
|
133 | include ::I18n::Backend::Base | |
130 |
|
134 | |||
131 | # Stores translations for the given locale in memory. |
|
135 | # Stores translations for the given locale in memory. | |
132 | # This uses a deep merge for the translations hash, so existing |
|
136 | # This uses a deep merge for the translations hash, so existing | |
133 | # translations will be overwritten by new ones only at the deepest |
|
137 | # translations will be overwritten by new ones only at the deepest | |
134 | # level of the hash. |
|
138 | # level of the hash. | |
135 | def store_translations(locale, data, options = {}) |
|
139 | def store_translations(locale, data, options = {}) | |
136 | locale = locale.to_sym |
|
140 | locale = locale.to_sym | |
137 | translations[locale] ||= {} |
|
141 | translations[locale] ||= {} | |
138 | data = data.deep_symbolize_keys |
|
142 | data = data.deep_symbolize_keys | |
139 | translations[locale].deep_merge!(data) |
|
143 | translations[locale].deep_merge!(data) | |
140 | end |
|
144 | end | |
141 |
|
145 | |||
142 | # Get available locales from the translations filenames |
|
146 | # Get available locales from the translations filenames | |
143 | def available_locales |
|
147 | def available_locales | |
144 | @available_locales ||= ::I18n.load_path.map {|path| File.basename(path, '.*')}.uniq.sort.map(&:to_sym) |
|
148 | @available_locales ||= ::I18n.load_path.map {|path| File.basename(path, '.*')}.uniq.sort.map(&:to_sym) | |
145 | end |
|
149 | end | |
146 |
|
150 | |||
147 | # Clean up translations |
|
151 | # Clean up translations | |
148 | def reload! |
|
152 | def reload! | |
149 | @translations = nil |
|
153 | @translations = nil | |
150 | @available_locales = nil |
|
154 | @available_locales = nil | |
151 | super |
|
155 | super | |
152 | end |
|
156 | end | |
153 |
|
157 | |||
154 | protected |
|
158 | protected | |
155 |
|
159 | |||
156 | def init_translations(locale) |
|
160 | def init_translations(locale) | |
157 | locale = locale.to_s |
|
161 | locale = locale.to_s | |
158 | paths = ::I18n.load_path.select {|path| File.basename(path, '.*') == locale} |
|
162 | paths = ::I18n.load_path.select {|path| File.basename(path, '.*') == locale} | |
159 | load_translations(paths) |
|
163 | load_translations(paths) | |
160 | translations[locale] ||= {} |
|
164 | translations[locale] ||= {} | |
161 | end |
|
165 | end | |
162 |
|
166 | |||
163 | def translations |
|
167 | def translations | |
164 | @translations ||= {} |
|
168 | @translations ||= {} | |
165 | end |
|
169 | end | |
166 |
|
170 | |||
167 | # Looks up a translation from the translations hash. Returns nil if |
|
171 | # Looks up a translation from the translations hash. Returns nil if | |
168 | # eiher key is nil, or locale, scope or key do not exist as a key in the |
|
172 | # eiher key is nil, or locale, scope or key do not exist as a key in the | |
169 | # nested translations hash. Splits keys or scopes containing dots |
|
173 | # nested translations hash. Splits keys or scopes containing dots | |
170 | # into multiple keys, i.e. <tt>currency.format</tt> is regarded the same as |
|
174 | # into multiple keys, i.e. <tt>currency.format</tt> is regarded the same as | |
171 | # <tt>%w(currency format)</tt>. |
|
175 | # <tt>%w(currency format)</tt>. | |
172 | def lookup(locale, key, scope = [], options = {}) |
|
176 | def lookup(locale, key, scope = [], options = {}) | |
173 | init_translations(locale) unless translations.key?(locale) |
|
177 | init_translations(locale) unless translations.key?(locale) | |
174 | keys = ::I18n.normalize_keys(locale, key, scope, options[:separator]) |
|
178 | keys = ::I18n.normalize_keys(locale, key, scope, options[:separator]) | |
175 |
|
179 | |||
176 | keys.inject(translations) do |result, _key| |
|
180 | keys.inject(translations) do |result, _key| | |
177 | _key = _key.to_sym |
|
181 | _key = _key.to_sym | |
178 | return nil unless result.is_a?(Hash) && result.has_key?(_key) |
|
182 | return nil unless result.is_a?(Hash) && result.has_key?(_key) | |
179 | result = result[_key] |
|
183 | result = result[_key] | |
180 | result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol) |
|
184 | result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol) | |
181 | result |
|
185 | result | |
182 | end |
|
186 | end | |
183 | end |
|
187 | end | |
184 | end |
|
188 | end | |
185 |
|
189 | |||
186 | include Implementation |
|
190 | include Implementation | |
187 | # Adds fallback to default locale for untranslated strings |
|
191 | # Adds fallback to default locale for untranslated strings | |
188 | include ::I18n::Backend::Fallbacks |
|
192 | include ::I18n::Backend::Fallbacks | |
189 | end |
|
193 | end | |
190 | end |
|
194 | end | |
191 | end |
|
195 | end |
General Comments 0
You need to be logged in to leave comments.
Login now