42 |
42 |
|
43 |
43 |
def initialize(options={})
|
44 |
44 |
options = options.dup
|
45 |
|
if options[:year] && options[:year].to_i >0
|
|
45 |
|
|
46 |
if options[:year] && options[:year].to_i > 0
|
46 |
47 |
@year_from = options[:year].to_i
|
47 |
|
if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
|
|
48 |
if options[:month] && options[:month].to_i >= 1 && options[:month].to_i <= 12
|
48 |
49 |
@month_from = options[:month].to_i
|
49 |
50 |
else
|
50 |
51 |
@month_from = 1
|
51 |
52 |
end
|
52 |
53 |
else
|
53 |
|
@month_from ||= Date.today.month
|
|
54 |
@month_from ||= Date.today.month - 1
|
54 |
55 |
@year_from ||= Date.today.year
|
|
56 |
@calculate_date_range = true
|
|
57 |
end
|
|
58 |
|
|
59 |
if @month_from <= 0
|
|
60 |
@month_from = 12
|
|
61 |
@year_from -= 1
|
|
62 |
end
|
|
63 |
if @month_from > 12
|
|
64 |
@month_from = 1
|
|
65 |
@year_from += 1
|
55 |
66 |
end
|
|
67 |
|
|
68 |
months = (options[:months] || User.current.pref[:gantt_months]).to_i
|
|
69 |
@months = (months > 0 && months < 48) ? months : 48
|
|
70 |
|
56 |
71 |
zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
|
57 |
72 |
@zoom = (zoom > 0 && zoom < 5) ? zoom : 2
|
58 |
|
months = (options[:months] || User.current.pref[:gantt_months]).to_i
|
59 |
|
@months = (months > 0 && months < 25) ? months : 6
|
|
73 |
|
60 |
74 |
# Save gantt parameters as user preference (zoom and months count)
|
61 |
75 |
if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] ||
|
62 |
76 |
@months != User.current.pref[:gantt_months]))
|
63 |
77 |
User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
|
64 |
78 |
User.current.preference.save
|
65 |
79 |
end
|
|
80 |
|
66 |
81 |
@date_from = Date.civil(@year_from, @month_from, 1)
|
67 |
82 |
@date_to = (@date_from >> @months) - 1
|
68 |
83 |
@subjects = ''
|
... | ... | |
70 |
85 |
@number_of_rows = nil
|
71 |
86 |
@issue_ancestors = []
|
72 |
87 |
@truncated = false
|
|
88 |
|
73 |
89 |
if options.has_key?(:max_rows)
|
74 |
90 |
@max_rows = options[:max_rows]
|
75 |
91 |
else
|
... | ... | |
77 |
93 |
end
|
78 |
94 |
end
|
79 |
95 |
|
|
96 |
def setup_dates
|
|
97 |
if @calculate_date_range
|
|
98 |
dates = issues_date_range
|
|
99 |
|
|
100 |
@date_from = dates[0]
|
|
101 |
if @date_from.day < 10
|
|
102 |
@date_from = dates[0] << 1
|
|
103 |
end
|
|
104 |
@date_to = dates[1]
|
|
105 |
if @date_to.day > 20
|
|
106 |
@date_to = dates[1] >> 1
|
|
107 |
end
|
|
108 |
@year_from = @date_from.year
|
|
109 |
@month_from = @date_from.month
|
|
110 |
months = (@date_to.year*12+@date_to.month) - (@date_from.year*12+@date_from.month) + 1
|
|
111 |
@months = months > 48 ? 48 : months
|
|
112 |
@date_from = Date.civil(@year_from, @month_from, 1)
|
|
113 |
@date_to = (@date_from >> @months) - 1
|
|
114 |
end
|
|
115 |
end
|
|
116 |
|
80 |
117 |
def common_params
|
81 |
118 |
{ :controller => 'gantts', :action => 'show', :project_id => @project }
|
82 |
119 |
end
|
... | ... | |
674 |
711 |
@truncated = true
|
675 |
712 |
end
|
676 |
713 |
end
|
|
714 |
|
|
715 |
def issues_date_range
|
|
716 |
min = nil
|
|
717 |
max = nil
|
|
718 |
projects.each do |p|
|
|
719 |
all_issues = project_issues(p)
|
|
720 |
|
|
721 |
all_issues.each do |i|
|
|
722 |
if min == nil || (i.start_date != nil && min > i.start_date)
|
|
723 |
min = i.start_date
|
|
724 |
end
|
|
725 |
if min == nil || (i.due_before != nil && min > i.due_before)
|
|
726 |
min = i.due_before
|
|
727 |
end
|
|
728 |
if max == nil || (i.start_date != nil && max < i.start_date)
|
|
729 |
max = i.start_date
|
|
730 |
end
|
|
731 |
if max == nil || (i.due_before != nil && max < i.due_before)
|
|
732 |
max = i.due_before
|
|
733 |
end
|
|
734 |
end
|
|
735 |
end
|
|
736 |
|
|
737 |
if min == nil && max == nil
|
|
738 |
min = Date.today
|
|
739 |
max = Date.today
|
|
740 |
end
|
|
741 |
|
|
742 |
[min, max]
|
|
743 |
end
|
677 |
744 |
|
678 |
745 |
def pdf_new_page?(options)
|
679 |
746 |
if options[:top] > 180
|