Skip to content

Commit e39b9e8

Browse files
author
travis
committed
custom columns and human time
Included custom display columns and human time format for floating report.
1 parent 1e8795a commit e39b9e8

File tree

3 files changed

+130
-17
lines changed

3 files changed

+130
-17
lines changed

'

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<% if params[:controller].eql? "issues" and params[:action].eql? "show" and ( Setting.plugin_redmine_spent_time_in_issue_description['report_location'].eql? "below_revisions" or Setting.plugin_redmine_spent_time_in_issue_description['report_location'].eql? "above_revisions") and User.current.allowed_to?(:view_time_entries, @project) and @issue.present? and @issue.time_entries.present? %>
2+
3+
<script type="text/javascript">
4+
$(document).ready(function() {
5+
6+
<% if @issue.changesets.present? %>
7+
lonely_spenttime = ""
8+
<% else %>
9+
lonely_spenttime = " lonely_spenttime"
10+
<% end %>
11+
12+
var spent_time = [
13+
<% @issue.time_entries.last( Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i ).each_with_index do |entry, index| %>
14+
<%= "," if index > 0 %> {
15+
16+
<% # Repeating code from _report.html.erb
17+
18+
if Setting.plugin_redmine_spent_time_in_issue_description['time_format'].eql? "human"
19+
hours = entry.hours.to_i
20+
minutes = entry.hours * 60
21+
minutes = (minutes - hours * 60 ).to_i
22+
23+
time_spent = ""
24+
25+
if hours == 1
26+
time_spent = t('plugin_spent_time_in_issue.datetime.hours.one')
27+
elsif hours > 1
28+
time_spent = t('plugin_spent_time_in_issue.datetime.hours.other', hours: hours )
29+
end
30+
31+
if minutes == 1
32+
time_spent << " " << t('plugin_spent_time_in_issue.datetime.minutes.one')
33+
elsif minutes > 1
34+
time_spent << " " << t('plugin_spent_time_in_issue.datetime.minutes.other', minutes: minutes )
35+
end
36+
else
37+
time_spent = entry.hours
38+
end
39+
40+
%>
41+
42+
<%# =raw '"spent_on":"' << entry.spent_on.strftime("%m/%d/%Y") << '",' %>
43+
<%=raw '"user":"' << entry.user.to_s << '",' %>
44+
<%=raw '"hours":"' << time_spent << '",' %>
45+
<%=raw '"activity":"' << entry.activity.to_s << '",' %>
46+
<%=raw '"comments":"' << entry.comments << '",' %>
47+
48+
}
49+
<% end %>
50+
];
51+
52+
var toggle = "odd"
53+
var time_entries = ' <div id="issue-spenttime" class="'+lonely_spenttime+'"><h3>Spent Time Report</h3>'
54+
$.each( spent_time, function(idnex,entry){
55+
time_entries += '<div class="spenttimeentry '+toggle+'">'
56+
time_entries += '<p>'
57+
time_entries += '<span>' + entry.spent_on + '</span>'
58+
time_entries += '<span>' + entry.user + '</span>'
59+
time_entries += '<span>' + entry.hours + '</span>'
60+
time_entries += '<br /> ' + entry.comments
61+
time_entries += '</p>'
62+
time_entries += '</div>'
63+
64+
if( toggle === "odd" ){
65+
toggle = "even"
66+
}else{
67+
toggle = "odd"
68+
}
69+
70+
});
71+
time_entries += '</div>'
72+
73+
<% if @issue.changesets.present? and Setting.plugin_redmine_spent_time_in_issue_description['report_location'].eql? "below_revisions" %>
74+
$("#issue-changesets").append(time_entries)
75+
<% elsif @issue.changesets.present? %>
76+
$("#issue-changesets").prepend(time_entries)
77+
<% else %>
78+
if ( $("#history").length < 0 ){
79+
$("#history").before(time_entries)
80+
}else{
81+
$("div.issue:first").after(time_entries)
82+
}
83+
<% end %>
84+
});
85+
86+
</script>
87+
<% end %>

app/views/settings/_spent_time_settings.html.erb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161
</tbody>
6262
</table>
6363

64-
<%= settings %>
65-
66-
6764

6865
<% content_for :header_tags do %>
6966
<%= javascript_include_tag 'jquery.validate.js', :plugin => 'redmine_spent_time_in_issue_description' %>

app/views/spent_time/_javascript_report.html.erb

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% if params[:controller].eql? "IssueController" and ( Setting.plugin_redmine_spent_time_in_issue_description['report_location'].eql? "below_revisions" or Setting.plugin_redmine_spent_time_in_issue_description['report_location'].eql? "above_revisions") and params[:action].eql? "show" and User.current.allowed_to?(:view_time_entries, @project) and @issue.present? and @issue.time_entries.present? %>
1+
<% if params[:controller].eql? "issues" and params[:action].eql? "show" and ( Setting.plugin_redmine_spent_time_in_issue_description['report_location'].eql? "below_revisions" or Setting.plugin_redmine_spent_time_in_issue_description['report_location'].eql? "above_revisions") and User.current.allowed_to?(:view_time_entries, @project) and @issue.present? and @issue.time_entries.present? %>
22

33
<script type="text/javascript">
44
$(document).ready(function() {
@@ -12,11 +12,38 @@
1212
var spent_time = [
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 %> {
15-
"spent_on":"<%= entry.spent_on.strftime("%m/%d/%Y") %>",
16-
"user":" <%= entry.user %>",
17-
"hours":"<%= entry.hours %>",
18-
"activity":"<%= entry.activity %>",
19-
"comments":"<%= entry.comments %>",
15+
16+
<% # Repeating code from _report.html.erb
17+
18+
if Setting.plugin_redmine_spent_time_in_issue_description['time_format'].eql? "human"
19+
hours = entry.hours.to_i
20+
minutes = entry.hours * 60
21+
minutes = (minutes - hours * 60 ).to_i
22+
23+
time_spent = ""
24+
25+
if hours == 1
26+
time_spent = t('plugin_spent_time_in_issue.datetime.hours.one')
27+
elsif hours > 1
28+
time_spent = t('plugin_spent_time_in_issue.datetime.hours.other', hours: hours )
29+
end
30+
31+
if minutes == 1
32+
time_spent << " " << t('plugin_spent_time_in_issue.datetime.minutes.one')
33+
elsif minutes > 1
34+
time_spent << " " << t('plugin_spent_time_in_issue.datetime.minutes.other', minutes: minutes )
35+
end
36+
else
37+
time_spent = entry.hours
38+
end
39+
40+
%>
41+
42+
<%=raw '"spent_on":"' << entry.spent_on.strftime("%m/%d/%Y") << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'spentOn' %>
43+
<%=raw '"user":"' << entry.user.to_s << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'user' %>
44+
<%=raw '"hours":"' << time_spent << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'hours' %>
45+
<%=raw '"activity":"' << entry.activity.to_s << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'activity' %>
46+
<%=raw '"comments":"' << entry.comments << '",' if Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'comments' %>
2047

2148
}
2249
<% end %>
@@ -27,10 +54,11 @@
2754
$.each( spent_time, function(idnex,entry){
2855
time_entries += '<div class="spenttimeentry '+toggle+'">'
2956
time_entries += '<p>'
30-
time_entries += '<span>' + entry.spent_on + '</span>'
31-
time_entries += '<span>' + entry.user + '</span>'
32-
time_entries += '<span>' + entry.hours + '</span>'
33-
time_entries += '<br /> ' + entry.comments
57+
if ( entry.spent_on !== undefined){ time_entries += '<span>' + entry.spent_on + '</span>' }
58+
if ( entry.user !== undefined){ time_entries += '<span>' + entry.user + '</span>' }
59+
if ( entry.activity !== undefined){ time_entries += '<span>' + entry.activity + '</span>' }
60+
if ( entry.hours !== undefined){ time_entries += '<span>' + entry.hours + '</span>' }
61+
if ( entry.comments !== undefined){ time_entries += '<br /> ' + entry.comments }
3462
time_entries += '</p>'
3563
time_entries += '</div>'
3664

@@ -45,15 +73,16 @@
4573

4674
<% if @issue.changesets.present? and Setting.plugin_redmine_spent_time_in_issue_description['report_location'].eql? "below_revisions" %>
4775
$("#issue-changesets").append(time_entries)
48-
console.log("below revisions");
4976
<% elsif @issue.changesets.present? %>
5077
$("#issue-changesets").prepend(time_entries)
51-
console.log("above revisions");
5278
<% else %>
53-
$("#history").before(time_entries)
79+
if ( $("#history").length < 0 ){
80+
$("#history").before(time_entries)
81+
}else{
82+
$("div.issue:first").after(time_entries)
83+
}
5484
<% end %>
5585
});
5686

5787
</script>
58-
5988
<% end %>

0 commit comments

Comments
 (0)