Skip to content

Commit 61924b3

Browse files
author
travis
committed
cleaning up
moving methods into Issue Helper to clean up view templates.
1 parent d6e3a1b commit 61924b3

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

app/views/spent_time/_javascript_report.html.erb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,11 @@
1313
<% @issue.time_entries.last( Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i ).each_with_index do |entry, index| %>
1414
<%= "," if index > 0 %> {
1515

16-
<% if Setting.plugin_redmine_spent_time_in_issue_description['time_format'].eql? "human"
17-
time_spent = humanized_time( entry.hours )
18-
else
19-
time_spent = entry.hours
20-
end
21-
%>
22-
23-
<%=raw '"spent_on":"' << entry.spent_on.strftime("%m/%d/%Y") << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'spentOn' %>
24-
<%=raw '"user":"' << entry.user.to_s << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'user' %>
25-
<%=raw '"hours":"' << time_spent << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'hours' %>
26-
<%=raw '"activity":"' << entry.activity.to_s << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'activity' %>
27-
<%=raw '"comments":"' << entry.comments << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'comments' %>
16+
<%=raw '"spent_on":"' << entry.spent_on.strftime("%m/%d/%Y") << '",' if is_spent_on_shown( entry ) %>
17+
<%=raw '"user":"' << entry.user.to_s << '",' if is_user_shown( entry ) %>
18+
<%=raw '"hours":"' << report_time_spent( entry ) << '",' if is_report_time_shown( entry ) %>
19+
<%=raw '"activity":"' << entry.activity.to_s << '",' if is_activity_shown( entry ) %>
20+
<%=raw '"comments":"' << entry.comments << '",' if is_comment_shown( entry ) %>
2821

2922
}
3023
<% end %>

app/views/spent_time/_report.html.erb

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,11 @@
1717
<tbody>
1818
<% @issue.time_entries.last( Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i ).each do |entry| %>
1919
<tr>
20-
<%= content_tag(:td, entry.spent_on.strftime("%m/%d/%Y") ) if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'spentOn' %>
21-
<%= content_tag(:td, link_to_user( entry.user )) if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'user' %>
22-
<% if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'hours'
23-
24-
if Setting.plugin_redmine_spent_time_in_issue_description['time_format'].eql? "human"
25-
time_spent = humanized_time( entry.hours )
26-
else
27-
time_spent = entry.hours
28-
end
29-
30-
%>
31-
32-
<%= content_tag(:td, time_spent ) %>
33-
34-
<% end %>
35-
<%= content_tag(:td, entry.comments ) if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'comments' %>
36-
<%= content_tag(:td, entry.activity ) if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'activity' %>
20+
<%= content_tag(:td, entry.spent_on.strftime("%m/%d/%Y") ) if is_spent_on_shown( entry ) %>
21+
<%= content_tag(:td, link_to_user( entry.user )) if is_user_shown( entry ) %>
22+
<%= content_tag(:td, report_time_spent( entry ) ) if is_report_time_shown( entry ) %>
23+
<%= content_tag(:td, entry.comments ) if is_comment_shown( entry ) %>
24+
<%= content_tag(:td, entry.activity ) if is_activity_shown( entry ) %>
3725
</tr>
3826
<% end %>
3927
</tbody>

lib/issue_helper_patch.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ def humanized_time(entry_hours)
2626

2727
end
2828

29+
def report_time_spent(entry)
30+
if Setting.plugin_redmine_spent_time_in_issue_description['time_format'].eql? "human"
31+
time_spent = humanized_time( entry.hours )
32+
else
33+
time_spent = entry.hours
34+
end
35+
end
36+
37+
def is_report_time_shown( entry )
38+
Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'hours'
39+
end
40+
41+
def is_spent_on_shown( entry )
42+
Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'spentOn'
43+
end
44+
45+
def is_user_shown( entry )
46+
Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'user'
47+
end
48+
49+
def is_comment_shown( entry )
50+
Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'comments'
51+
end
52+
53+
def is_activity_shown( entry )
54+
Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'activity'
55+
end
56+
2957
def self.included(receiver)
3058
receiver.send :include, InstanceMethods
3159
end

0 commit comments

Comments
 (0)