|
| 1 | +# Helper Patch to be include in Issue Helper |
1 | 2 | module IssuesHelperPatch
|
2 |
| - |
3 | 3 | def self.included(base) # :nodoc:
|
4 | 4 | base.send(:include, InstanceMethods)
|
5 | 5 | end
|
6 | 6 |
|
| 7 | + # Helper provides shorter conditional calls and humanized_time format |
7 | 8 | module InstanceMethods
|
8 |
| - |
9 | 9 | def humanized_time(entry_hours)
|
10 | 10 | hours = entry_hours.to_i
|
11 | 11 | minutes = entry_hours * 60
|
12 |
| - minutes = (minutes - hours * 60 ).to_i |
| 12 | + minutes = (minutes - hours * 60).to_i |
13 | 13 |
|
14 |
| - time_spent = case |
15 |
| - when hours == 1 |
16 |
| - t('plugin_spent_time_in_issue.datetime.hours.one') |
17 |
| - when hours > 1 |
18 |
| - t('plugin_spent_time_in_issue.datetime.hours.other', hours: hours) |
19 |
| - else |
20 |
| - "" |
21 |
| - end |
| 14 | + time_spent = humanized_hour(hours) |
| 15 | + time_spent << ' ' << humanized_minute(minutes) unless minutes < 1 |
| 16 | + end |
| 17 | + end |
22 | 18 |
|
23 |
| - if minutes == 1 |
24 |
| - time_spent << " " << t('plugin_spent_time_in_issue.datetime.minutes.one') |
25 |
| - elsif minutes > 1 |
26 |
| - time_spent << " " << t('plugin_spent_time_in_issue.datetime.minutes.other', minutes: minutes) |
27 |
| - else |
28 |
| - time_spent |
29 |
| - end |
| 19 | + def humanized_hour(hours) |
| 20 | + if hours == 1 |
| 21 | + t('plugin_spent_time_in_issue.datetime.hours.one') |
| 22 | + elsif hours > 1 |
| 23 | + t('plugin_spent_time_in_issue.datetime.hours.other', hours: hours) |
| 24 | + else |
| 25 | + '' |
30 | 26 | end
|
| 27 | + end |
31 | 28 |
|
| 29 | + def humanized_minute(minutes) |
| 30 | + if minutes == 1 |
| 31 | + ' ' << t('plugin_spent_time_in_issue.datetime.minutes.one') |
| 32 | + elsif minutes > 1 |
| 33 | + ' ' << t('plugin_spent_time_in_issue.datetime.minutes.other', minutes: minutes) |
| 34 | + else |
| 35 | + '' |
| 36 | + end |
32 | 37 | end
|
33 | 38 |
|
34 | 39 | def report_time_spent(entry)
|
35 |
| - if Setting.plugin_redmine_spent_time_in_issue_description['time_format'].eql? "human" |
36 |
| - time_spent = humanized_time( entry.hours ) |
| 40 | + if Setting.plugin_redmine_spent_time_in_issue_description['time_format'].eql? 'human' |
| 41 | + humanized_time(entry.hours) |
37 | 42 | else
|
38 |
| - time_spent = entry.hours |
| 43 | + entry.hours |
39 | 44 | end
|
40 | 45 | end
|
41 | 46 |
|
42 |
| - def is_report_time_shown( entry ) |
| 47 | + def report_time_shown? |
43 | 48 | Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'hours'
|
44 | 49 | end
|
45 | 50 |
|
46 |
| - def is_spent_on_shown( entry ) |
| 51 | + def spent_on_shown? |
47 | 52 | Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'spentOn'
|
48 | 53 | end
|
49 | 54 |
|
50 |
| - def is_user_shown( entry ) |
| 55 | + def user_shown? |
51 | 56 | Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'user'
|
52 | 57 | end
|
53 | 58 |
|
54 |
| - def is_comment_shown( entry ) |
| 59 | + def comment_shown? |
55 | 60 | Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'comments'
|
56 | 61 | end
|
57 | 62 |
|
58 |
| - def is_activity_shown( entry ) |
| 63 | + def activity_shown? |
59 | 64 | Setting.plugin_redmine_spent_time_in_issue_description['display_columns'].include? 'activity'
|
60 | 65 | end
|
61 | 66 |
|
|
0 commit comments