Skip to content

Commit 330313e

Browse files
committed
Fix bug of log_time entry
1 parent 1886b0b commit 330313e

File tree

7 files changed

+108
-20
lines changed

7 files changed

+108
-20
lines changed

app/views/issues/_list.rthml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<% content_for :header_tags do %>
2+
<%= stylesheet_link_tag 'advanced_issues.css', :plugin => 'redmine_advanced_issues' %>
3+
<% end %>
4+
5+
<% form_tag({}) do -%>
6+
<%= hidden_field_tag 'back_url', url_for(params) %>
7+
<div class="autoscroll">
8+
<table class="list issues">
9+
<thead><tr>
10+
<th class="checkbox hide-when-print"><%= link_to image_tag('toggle_check.png'), {}, :onclick => 'toggleIssuesSelection(Element.up(this, "form")); return false;',
11+
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %>
12+
</th>
13+
<%= sort_header_tag('id', :caption => '#', :default_order => 'desc') %>
14+
<% query.columns.each do |column| %>
15+
<%= column_header(column) %>
16+
<% end %>
17+
</tr></thead>
18+
<% previous_group = false %>
19+
<tbody>
20+
<% issue_list(issues) do |issue, level| -%>
21+
<% if @query.grouped? && (group = @query.group_by_column.value(issue)) != previous_group %>
22+
<% reset_cycle %>
23+
<tr class="group open">
24+
<td colspan="<%= query.columns.size + 2 %>">
25+
<span class="expander" onclick="toggleRowGroup(this); return false;">&nbsp;</span>
26+
<%= group.blank? ? 'None' : column_content(@query.group_by_column, issue) %> <span class="count">(<%= @issue_count_by_group[group] %>)</span>
27+
<%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}", "toggleAllRowGroups(this)", :class => 'toggle-all') %>
28+
</td>
29+
</tr>
30+
<% previous_group = group %>
31+
<% end %>
32+
<tr id="issue-<%= issue.id %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
33+
<td class="checkbox hide-when-print"><%= check_box_tag("ids[]", issue.id, false, :id => nil) %></td>
34+
<td class="id"><%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %></td>
35+
<% query.columns.each do |column| %><%= content_tag 'td', column_content(column, issue), :class => column.css_classes %><% end %>
36+
</tr>
37+
<% end -%>
38+
</tbody>
39+
</table>
40+
</div>
41+
<% end -%>

app/views/issues/_list_simple.rhtml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<% content_for :header_tags do %>
2+
<%= stylesheet_link_tag 'advanced_issues.css', :plugin => 'redmine_advanced_issues' %>
3+
<% end %>
4+
5+
<% if issues && issues.any? %>
6+
<% form_tag({}) do %>
7+
<table class="list issues">
8+
<thead><tr>
9+
<th>#</th>
10+
<th><%=l(:field_project)%></th>
11+
<th><%=l(:field_tracker)%></th>
12+
<th><%=l(:field_subject)%></th>
13+
</tr></thead>
14+
<tbody>
15+
<% for issue in issues %>
16+
<tr id="issue-<%= issue.id %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %>">
17+
<td class="id">
18+
<%= check_box_tag("ids[]", issue.id, false, :style => 'display:none;') %>
19+
<%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %>
20+
</td>
21+
<td class="project"><%= link_to_project(issue.project) %></td>
22+
<td class="tracker"><%=h issue.tracker %></td>
23+
<td class="subject">
24+
<%= link_to h(truncate(issue.subject, :length => 60)), :controller => 'issues', :action => 'show', :id => issue %> (<%=h issue.status %>)
25+
</td>
26+
</tr>
27+
<% end %>
28+
</tbody>
29+
</table>
30+
<% end %>
31+
<% else %>
32+
<p class="nodata"><%= l(:label_no_data) %></p>
33+
<% end %>

init.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
This is a plugin for Redmine, that add some advanced stuffs.
4040
Spent time columns, unit time customize
4141
'
42-
version '0.0.3'
42+
version '0.0.4'
4343
url 'http://blog.spikie.info/'
4444
author_url 'http://blog.spikie.info'
4545

@@ -53,7 +53,7 @@
5353
'days_in_week' => '5',
5454
'char_for_week' => 'w',
5555

56-
'weeks_in_month' => '21',
56+
'weeks_in_month' => '4',
5757
'char_for_month' => 'm',
5858

5959
'months_in_year' => '12',

lib/hooks/controller_issues_edit_before_save_hook.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class ControllerIssuesEditBeforeSaveHook < Redmine::Hook::ViewListener
2424
def controller_issues_edit_before_save(context={})
2525

2626
if context[:params] && context[:params][:issue] && context[:params][:issue][:estimated_hours].present?
27-
2827
value = context[:params][:issue][:estimated_hours]
2928
time_unit = ""
3029

@@ -38,10 +37,26 @@ def controller_issues_edit_before_save(context={})
3837
context[:issue][:estimated_hours] = RedmineAdvancedIssues::TimeManagement.calculateHours value.to_f, time_unit
3938
end #if
4039

41-
return ''
40+
end #if
41+
42+
if context[:time_entry] && context[:time_entry][:hours].present?
43+
value = context[:time_entry][:hours]
44+
time_unit = ""
45+
46+
if value.to_s =~ /^([0-9]+)\s*[a-z]{1}$/
47+
time_unit = RedmineAdvancedIssues::TimeManagement.getUnitTimeFromChar value.to_s[-1, 1]
48+
else
49+
time_unit = Setting.plugin_redmine_advanced_issues['default_unit']
50+
end #if
51+
52+
if !time_unit.empty?
53+
context[:time_entry][:hours] = RedmineAdvancedIssues::TimeManagement.calculateHours value.to_f, time_unit
54+
end #if
4255

4356
end #if
4457

58+
return ''
59+
4560
end #controller_issues_edit_before_save
4661

4762
alias_method :controller_issues_new_before_save, :controller_issues_edit_before_save

lib/redmine_advanced_issues/patches/issue_patch.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def self.included(base) # :nodoc:
3131
base.class_eval do
3232
unloadable
3333
alias_method_chain :css_classes, :more_css
34+
#alias_method_chain :save_issue_with_child_records, :time_entry_record
3435
end #base.class_eval
3536

3637
end #self.include(base)
@@ -61,7 +62,7 @@ def has_risk?
6162
# khim: Returns true if the issue will be late...
6263
# khim: ((time_estimated - worked_time) / 7.5) > due_date - Date.today
6364
def miss_time?
64-
!due_date.nil? && ((estimated_hours.to_f - spent_hours.to_f) / 7.5) > (due_date - Date.today)
65+
!due_date.nil? && ((estimated_hours.to_f - spent_hours.to_f) / Setting.plugin_redmine_advanced_issues['hours_in_day'].to_f) > (due_date - Date.today)
6566
end
6667

6768
def estimated_days
@@ -129,6 +130,17 @@ def css_classes_with_more_css
129130
s << ' over_estimated' if spent_time_over_estimated?
130131
return s
131132
end #css_classes
133+
134+
##
135+
#
136+
##
137+
def save_issue_with_child_records_with_time_entry_record(params, existing_time_entry=nil)
138+
if params[:time_entry] && params[:time_entry][:hours].present?
139+
params[:time_entry][:hours] = RedmineAdvancedIssues::TimeManagement.calculate params[:time_entry][:hours], Setting.plugin_redmine_advanced_issues['default_unit']
140+
end
141+
save_issue_with_child_records_without_time_entry_record(params, existing_time_entry)
142+
end #save_issue_with_child_records_with_time_entry_record
143+
132144
end #InstanceMethods
133145

134146
end #IssuePatch

lib/redmine_advanced_issues/patches/query_patch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def available_columns_with_spent_hours
4545

4646
columns << QueryColumn.new(:divergent_hours,
4747
:caption => :label_divergent_hours,
48-
:sortable => "((select sum(hours) from #{TimeEntry.table_name} where #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id) - (IF(#{Issue.table_name}.estimated_hours IS NULL,0,#{Issue.table_name}.estimated_hours) * #{Issue.table_name}.done_ratio / 100s))"
48+
:sortable => "((select sum(hours) from #{TimeEntry.table_name} where #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id) - (IF(#{Issue.table_name}.estimated_hours IS NULL,0,#{Issue.table_name}.estimated_hours) * #{Issue.table_name}.done_ratio / 100))"
4949
) unless columns.detect { |c| c.name == :divergent_hours }
5050

5151

lib/redmine_advanced_issues/patches/time_entry_patch.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,7 @@ def time
4545

4646
#TODO: refactoring
4747
def default_unit_time
48-
case Setting.plugin_redmine_advanced_issues['default_unit']
49-
when 'hours'
50-
return l(:hours)
51-
when 'days'
52-
return l(:days)
53-
when 'weeks'
54-
return l(:weeks)
55-
when 'months'
56-
return l(:months)
57-
when 'years'
58-
return l(:years)
59-
else
60-
return l(:hours)
61-
end #case
48+
return RedmineAdvancedIssues::TimeManagement.getDefaultTimeUnit(Setting.plugin_redmine_advanced_issues['default_unit'])
6249
end #default_unit_time
6350
end #InstanceMethods
6451
end #TimeEntryPatch

0 commit comments

Comments
 (0)