@@ -0,0 +1,114 | |||||
|
1 | var draw_gantt = null; | |||
|
2 | var draw_top; | |||
|
3 | var draw_right; | |||
|
4 | var draw_left; | |||
|
5 | ||||
|
6 | var rels_stroke_width = 2; | |||
|
7 | ||||
|
8 | function setDrawArea() { | |||
|
9 | draw_top = $("#gantt_draw_area").position().top; | |||
|
10 | draw_right = $("#gantt_draw_area").width(); | |||
|
11 | draw_left = $("#gantt_area").scrollLeft(); | |||
|
12 | } | |||
|
13 | ||||
|
14 | function getRelationsArray() { | |||
|
15 | var arr = new Array(); | |||
|
16 | $.each($('div.task_todo'), function(index_div, element) { | |||
|
17 | var element_id = $(element).attr("id"); | |||
|
18 | if (element_id != null) { | |||
|
19 | var issue_id = element_id.replace("task-todo-issue-", ""); | |||
|
20 | var data_rels = $(element).data("rels"); | |||
|
21 | if (data_rels != null) { | |||
|
22 | for (rel_type_key in issue_relation_type) { | |||
|
23 | if (rel_type_key in data_rels) { | |||
|
24 | var issue_arr = data_rels[rel_type_key].toString().split(","); | |||
|
25 | $.each(issue_arr, function(index_issue, element_issue) { | |||
|
26 | arr.push({issue_from: issue_id, issue_to: element_issue, | |||
|
27 | rel_type: rel_type_key}); | |||
|
28 | }); | |||
|
29 | } | |||
|
30 | } | |||
|
31 | } | |||
|
32 | } | |||
|
33 | }); | |||
|
34 | return arr; | |||
|
35 | } | |||
|
36 | ||||
|
37 | function drawRelations() { | |||
|
38 | var arr = getRelationsArray(); | |||
|
39 | $.each(arr, function(index_issue, element_issue) { | |||
|
40 | var issue_from = $("#task-todo-issue-" + element_issue["issue_from"]); | |||
|
41 | var issue_to = $("#task-todo-issue-" + element_issue["issue_to"]); | |||
|
42 | if (issue_from.size() == 0 || issue_to.size() == 0) { | |||
|
43 | return; | |||
|
44 | } | |||
|
45 | var issue_height = issue_from.height(); | |||
|
46 | var issue_from_top = issue_from.position().top + (issue_height / 2) - draw_top; | |||
|
47 | var issue_from_right = issue_from.position().left + issue_from.width(); | |||
|
48 | var issue_to_top = issue_to.position().top + (issue_height / 2) - draw_top; | |||
|
49 | var issue_to_left = issue_to.position().left; | |||
|
50 | var color = issue_relation_type[element_issue["rel_type"]]["color"]; | |||
|
51 | var landscape_margin = issue_relation_type[element_issue["rel_type"]]["landscape_margin"]; | |||
|
52 | var issue_from_right_rel = issue_from_right + landscape_margin; | |||
|
53 | var issue_to_left_rel = issue_to_left - landscape_margin; | |||
|
54 | draw_gantt.path(["M", issue_from_right + draw_left, issue_from_top, | |||
|
55 | "L", issue_from_right_rel + draw_left, issue_from_top]) | |||
|
56 | .attr({stroke: color, | |||
|
57 | "stroke-width": rels_stroke_width | |||
|
58 | }); | |||
|
59 | if (issue_from_right_rel < issue_to_left_rel) { | |||
|
60 | draw_gantt.path(["M", issue_from_right_rel + draw_left, issue_from_top, | |||
|
61 | "L", issue_from_right_rel + draw_left, issue_to_top]) | |||
|
62 | .attr({stroke: color, | |||
|
63 | "stroke-width": rels_stroke_width | |||
|
64 | }); | |||
|
65 | draw_gantt.path(["M", issue_from_right_rel + draw_left, issue_to_top, | |||
|
66 | "L", issue_to_left + draw_left, issue_to_top]) | |||
|
67 | .attr({stroke: color, | |||
|
68 | "stroke-width": rels_stroke_width | |||
|
69 | }); | |||
|
70 | } else { | |||
|
71 | var issue_middle_top = issue_to_top + | |||
|
72 | (issue_height * | |||
|
73 | ((issue_from_top > issue_to_top) ? 1 : -1)); | |||
|
74 | draw_gantt.path(["M", issue_from_right_rel + draw_left, issue_from_top, | |||
|
75 | "L", issue_from_right_rel + draw_left, issue_middle_top]) | |||
|
76 | .attr({stroke: color, | |||
|
77 | "stroke-width": rels_stroke_width | |||
|
78 | }); | |||
|
79 | draw_gantt.path(["M", issue_from_right_rel + draw_left, issue_middle_top, | |||
|
80 | "L", issue_to_left_rel + draw_left, issue_middle_top]) | |||
|
81 | .attr({stroke: color, | |||
|
82 | "stroke-width": rels_stroke_width | |||
|
83 | }); | |||
|
84 | draw_gantt.path(["M", issue_to_left_rel + draw_left, issue_middle_top, | |||
|
85 | "L", issue_to_left_rel + draw_left, issue_to_top]) | |||
|
86 | .attr({stroke: color, | |||
|
87 | "stroke-width": rels_stroke_width | |||
|
88 | }); | |||
|
89 | draw_gantt.path(["M", issue_to_left_rel + draw_left, issue_to_top, | |||
|
90 | "L", issue_to_left + draw_left, issue_to_top]) | |||
|
91 | .attr({stroke: color, | |||
|
92 | "stroke-width": rels_stroke_width | |||
|
93 | }); | |||
|
94 | } | |||
|
95 | draw_gantt.path(["M", issue_to_left + draw_left, issue_to_top, | |||
|
96 | "l", -4 * rels_stroke_width, -2 * rels_stroke_width, | |||
|
97 | "l", 0, 4 * rels_stroke_width, "z"]) | |||
|
98 | .attr({stroke: "none", | |||
|
99 | fill: color, | |||
|
100 | "stroke-linecap": "butt", | |||
|
101 | "stroke-linejoin": "miter", | |||
|
102 | }); | |||
|
103 | }); | |||
|
104 | } | |||
|
105 | ||||
|
106 | function drawGanttHandler() { | |||
|
107 | var folder = document.getElementById('gantt_draw_area'); | |||
|
108 | if(draw_gantt != null) | |||
|
109 | draw_gantt.clear(); | |||
|
110 | else | |||
|
111 | draw_gantt = Raphael(folder); | |||
|
112 | setDrawArea(); | |||
|
113 | drawRelations(); | |||
|
114 | } |
@@ -1,263 +1,282 | |||||
1 | <% @gantt.view = self %> |
|
1 | <% @gantt.view = self %> | |
2 | <h2><%= @query.new_record? ? l(:label_gantt) : h(@query.name) %></h2> |
|
2 | <h2><%= @query.new_record? ? l(:label_gantt) : h(@query.name) %></h2> | |
3 |
|
3 | |||
4 | <%= form_tag({:controller => 'gantts', :action => 'show', |
|
4 | <%= form_tag({:controller => 'gantts', :action => 'show', | |
5 | :project_id => @project, :month => params[:month], |
|
5 | :project_id => @project, :month => params[:month], | |
6 | :year => params[:year], :months => params[:months]}, |
|
6 | :year => params[:year], :months => params[:months]}, | |
7 | :method => :get, :id => 'query_form') do %> |
|
7 | :method => :get, :id => 'query_form') do %> | |
8 | <%= hidden_field_tag 'set_filter', '1' %> |
|
8 | <%= hidden_field_tag 'set_filter', '1' %> | |
9 | <fieldset id="filters" class="collapsible <%= @query.new_record? ? "" : "collapsed" %>"> |
|
9 | <fieldset id="filters" class="collapsible <%= @query.new_record? ? "" : "collapsed" %>"> | |
10 | <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend> |
|
10 | <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend> | |
11 | <div style="<%= @query.new_record? ? "" : "display: none;" %>"> |
|
11 | <div style="<%= @query.new_record? ? "" : "display: none;" %>"> | |
12 | <%= render :partial => 'queries/filters', :locals => {:query => @query} %> |
|
12 | <%= render :partial => 'queries/filters', :locals => {:query => @query} %> | |
13 | </div> |
|
13 | </div> | |
14 | </fieldset> |
|
14 | </fieldset> | |
15 |
|
15 | |||
16 | <p class="contextual"> |
|
16 | <p class="contextual"> | |
17 | <%= gantt_zoom_link(@gantt, :in) %> |
|
17 | <%= gantt_zoom_link(@gantt, :in) %> | |
18 | <%= gantt_zoom_link(@gantt, :out) %> |
|
18 | <%= gantt_zoom_link(@gantt, :out) %> | |
19 | </p> |
|
19 | </p> | |
20 |
|
20 | |||
21 | <p class="buttons"> |
|
21 | <p class="buttons"> | |
22 | <%= text_field_tag 'months', @gantt.months, :size => 2 %> |
|
22 | <%= text_field_tag 'months', @gantt.months, :size => 2 %> | |
23 | <%= l(:label_months_from) %> |
|
23 | <%= l(:label_months_from) %> | |
24 | <%= select_month(@gantt.month_from, :prefix => "month", :discard_type => true) %> |
|
24 | <%= select_month(@gantt.month_from, :prefix => "month", :discard_type => true) %> | |
25 | <%= select_year(@gantt.year_from, :prefix => "year", :discard_type => true) %> |
|
25 | <%= select_year(@gantt.year_from, :prefix => "year", :discard_type => true) %> | |
26 | <%= hidden_field_tag 'zoom', @gantt.zoom %> |
|
26 | <%= hidden_field_tag 'zoom', @gantt.zoom %> | |
27 |
|
27 | |||
28 | <%= link_to_function l(:button_apply), '$("#query_form").submit()', |
|
28 | <%= link_to_function l(:button_apply), '$("#query_form").submit()', | |
29 | :class => 'icon icon-checked' %> |
|
29 | :class => 'icon icon-checked' %> | |
30 | <%= link_to l(:button_clear), { :project_id => @project, :set_filter => 1 }, |
|
30 | <%= link_to l(:button_clear), { :project_id => @project, :set_filter => 1 }, | |
31 | :class => 'icon icon-reload' %> |
|
31 | :class => 'icon icon-reload' %> | |
32 | </p> |
|
32 | </p> | |
33 | <% end %> |
|
33 | <% end %> | |
34 |
|
34 | |||
35 | <%= error_messages_for 'query' %> |
|
35 | <%= error_messages_for 'query' %> | |
36 | <% if @query.valid? %> |
|
36 | <% if @query.valid? %> | |
37 | <% |
|
37 | <% | |
38 | zoom = 1 |
|
38 | zoom = 1 | |
39 | @gantt.zoom.times { zoom = zoom * 2 } |
|
39 | @gantt.zoom.times { zoom = zoom * 2 } | |
40 |
|
40 | |||
41 | subject_width = 330 |
|
41 | subject_width = 330 | |
42 | header_heigth = 18 |
|
42 | header_heigth = 18 | |
43 |
|
43 | |||
44 | headers_height = header_heigth |
|
44 | headers_height = header_heigth | |
45 | show_weeks = false |
|
45 | show_weeks = false | |
46 | show_days = false |
|
46 | show_days = false | |
47 |
|
47 | |||
48 | if @gantt.zoom > 1 |
|
48 | if @gantt.zoom > 1 | |
49 | show_weeks = true |
|
49 | show_weeks = true | |
50 | headers_height = 2 * header_heigth |
|
50 | headers_height = 2 * header_heigth | |
51 | if @gantt.zoom > 2 |
|
51 | if @gantt.zoom > 2 | |
52 | show_days = true |
|
52 | show_days = true | |
53 | headers_height = 3 * header_heigth |
|
53 | headers_height = 3 * header_heigth | |
54 | end |
|
54 | end | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | # Width of the entire chart |
|
57 | # Width of the entire chart | |
58 | g_width = ((@gantt.date_to - @gantt.date_from + 1) * zoom).to_i |
|
58 | g_width = ((@gantt.date_to - @gantt.date_from + 1) * zoom).to_i | |
59 | @gantt.render(:top => headers_height + 8, |
|
59 | @gantt.render(:top => headers_height + 8, | |
60 | :zoom => zoom, |
|
60 | :zoom => zoom, | |
61 | :g_width => g_width, |
|
61 | :g_width => g_width, | |
62 | :subject_width => subject_width) |
|
62 | :subject_width => subject_width) | |
63 | g_height = [(20 * (@gantt.number_of_rows + 6)) + 150, 206].max |
|
63 | g_height = [(20 * (@gantt.number_of_rows + 6)) + 150, 206].max | |
64 | t_height = g_height + headers_height |
|
64 | t_height = g_height + headers_height | |
65 | %> |
|
65 | %> | |
66 |
|
66 | |||
67 | <% if @gantt.truncated %> |
|
67 | <% if @gantt.truncated %> | |
68 | <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p> |
|
68 | <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p> | |
69 | <% end %> |
|
69 | <% end %> | |
70 |
|
70 | |||
71 | <table style="width:100%; border:0; border-collapse: collapse;"> |
|
71 | <table style="width:100%; border:0; border-collapse: collapse;"> | |
72 | <tr> |
|
72 | <tr> | |
73 | <td style="width:<%= subject_width %>px; padding:0px;"> |
|
73 | <td style="width:<%= subject_width %>px; padding:0px;"> | |
74 | <% |
|
74 | <% | |
75 | style = "" |
|
75 | style = "" | |
76 | style += "position:relative;" |
|
76 | style += "position:relative;" | |
77 | style += "height: #{t_height + 24}px;" |
|
77 | style += "height: #{t_height + 24}px;" | |
78 | style += "width: #{subject_width + 1}px;" |
|
78 | style += "width: #{subject_width + 1}px;" | |
79 | %> |
|
79 | %> | |
80 | <%= content_tag(:div, :style => style) do %> |
|
80 | <%= content_tag(:div, :style => style) do %> | |
81 | <% |
|
81 | <% | |
82 | style = "" |
|
82 | style = "" | |
83 | style += "right:-2px;" |
|
83 | style += "right:-2px;" | |
84 | style += "width: #{subject_width}px;" |
|
84 | style += "width: #{subject_width}px;" | |
85 | style += "height: #{headers_height}px;" |
|
85 | style += "height: #{headers_height}px;" | |
86 | style += 'background: #eee;' |
|
86 | style += 'background: #eee;' | |
87 | %> |
|
87 | %> | |
88 | <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %> |
|
88 | <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %> | |
89 | <% |
|
89 | <% | |
90 | style = "" |
|
90 | style = "" | |
91 | style += "right:-2px;" |
|
91 | style += "right:-2px;" | |
92 | style += "width: #{subject_width}px;" |
|
92 | style += "width: #{subject_width}px;" | |
93 | style += "height: #{t_height}px;" |
|
93 | style += "height: #{t_height}px;" | |
94 | style += 'border-left: 1px solid #c0c0c0;' |
|
94 | style += 'border-left: 1px solid #c0c0c0;' | |
95 | style += 'overflow: hidden;' |
|
95 | style += 'overflow: hidden;' | |
96 | %> |
|
96 | %> | |
97 | <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %> |
|
97 | <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %> | |
98 | <%= content_tag(:div, :class => "gantt_subjects") do %> |
|
98 | <%= content_tag(:div, :class => "gantt_subjects") do %> | |
99 | <%= @gantt.subjects.html_safe %> |
|
99 | <%= @gantt.subjects.html_safe %> | |
100 | <% end %> |
|
100 | <% end %> | |
101 | <% end %> |
|
101 | <% end %> | |
102 | </td> |
|
102 | </td> | |
103 |
|
103 | |||
104 | <td> |
|
104 | <td> | |
105 | <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;"> |
|
105 | <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;" id="gantt_area"> | |
106 | <% |
|
106 | <% | |
107 | style = "" |
|
107 | style = "" | |
108 | style += "width: #{g_width - 1}px;" |
|
108 | style += "width: #{g_width - 1}px;" | |
109 | style += "height: #{headers_height}px;" |
|
109 | style += "height: #{headers_height}px;" | |
110 | style += 'background: #eee;' |
|
110 | style += 'background: #eee;' | |
111 | %> |
|
111 | %> | |
112 | <%= content_tag(:div, ' '.html_safe, :style => style, :class => "gantt_hdr") %> |
|
112 | <%= content_tag(:div, ' '.html_safe, :style => style, :class => "gantt_hdr") %> | |
113 |
|
113 | |||
114 | <% ###### Months headers ###### %> |
|
114 | <% ###### Months headers ###### %> | |
115 | <% |
|
115 | <% | |
116 | month_f = @gantt.date_from |
|
116 | month_f = @gantt.date_from | |
117 | left = 0 |
|
117 | left = 0 | |
118 | height = (show_weeks ? header_heigth : header_heigth + g_height) |
|
118 | height = (show_weeks ? header_heigth : header_heigth + g_height) | |
119 | %> |
|
119 | %> | |
120 | <% @gantt.months.times do %> |
|
120 | <% @gantt.months.times do %> | |
121 | <% |
|
121 | <% | |
122 | width = (((month_f >> 1) - month_f) * zoom - 1).to_i |
|
122 | width = (((month_f >> 1) - month_f) * zoom - 1).to_i | |
123 | style = "" |
|
123 | style = "" | |
124 | style += "left: #{left}px;" |
|
124 | style += "left: #{left}px;" | |
125 | style += "width: #{width}px;" |
|
125 | style += "width: #{width}px;" | |
126 | style += "height: #{height}px;" |
|
126 | style += "height: #{height}px;" | |
127 | %> |
|
127 | %> | |
128 | <%= content_tag(:div, :style => style, :class => "gantt_hdr") do %> |
|
128 | <%= content_tag(:div, :style => style, :class => "gantt_hdr") do %> | |
129 | <%= link_to h("#{month_f.year}-#{month_f.month}"), |
|
129 | <%= link_to h("#{month_f.year}-#{month_f.month}"), | |
130 | @gantt.params.merge(:year => month_f.year, :month => month_f.month), |
|
130 | @gantt.params.merge(:year => month_f.year, :month => month_f.month), | |
131 | :title => "#{month_name(month_f.month)} #{month_f.year}" %> |
|
131 | :title => "#{month_name(month_f.month)} #{month_f.year}" %> | |
132 | <% end %> |
|
132 | <% end %> | |
133 | <% |
|
133 | <% | |
134 | left = left + width + 1 |
|
134 | left = left + width + 1 | |
135 | month_f = month_f >> 1 |
|
135 | month_f = month_f >> 1 | |
136 | %> |
|
136 | %> | |
137 | <% end %> |
|
137 | <% end %> | |
138 |
|
138 | |||
139 | <% ###### Weeks headers ###### %> |
|
139 | <% ###### Weeks headers ###### %> | |
140 | <% if show_weeks %> |
|
140 | <% if show_weeks %> | |
141 | <% |
|
141 | <% | |
142 | left = 0 |
|
142 | left = 0 | |
143 | height = (show_days ? header_heigth - 1 : header_heigth - 1 + g_height) |
|
143 | height = (show_days ? header_heigth - 1 : header_heigth - 1 + g_height) | |
144 | %> |
|
144 | %> | |
145 | <% if @gantt.date_from.cwday == 1 %> |
|
145 | <% if @gantt.date_from.cwday == 1 %> | |
146 | <% |
|
146 | <% | |
147 | # @date_from is monday |
|
147 | # @date_from is monday | |
148 | week_f = @gantt.date_from |
|
148 | week_f = @gantt.date_from | |
149 | %> |
|
149 | %> | |
150 | <% else %> |
|
150 | <% else %> | |
151 | <% |
|
151 | <% | |
152 | # find next monday after @date_from |
|
152 | # find next monday after @date_from | |
153 | week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1) |
|
153 | week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1) | |
154 | width = (7 - @gantt.date_from.cwday + 1) * zoom - 1 |
|
154 | width = (7 - @gantt.date_from.cwday + 1) * zoom - 1 | |
155 | style = "" |
|
155 | style = "" | |
156 | style += "left: #{left}px;" |
|
156 | style += "left: #{left}px;" | |
157 | style += "top: 19px;" |
|
157 | style += "top: 19px;" | |
158 | style += "width: #{width}px;" |
|
158 | style += "width: #{width}px;" | |
159 | style += "height: #{height}px;" |
|
159 | style += "height: #{height}px;" | |
160 | %> |
|
160 | %> | |
161 | <%= content_tag(:div, ' '.html_safe, |
|
161 | <%= content_tag(:div, ' '.html_safe, | |
162 | :style => style, :class => "gantt_hdr") %> |
|
162 | :style => style, :class => "gantt_hdr") %> | |
163 | <% left = left + width + 1 %> |
|
163 | <% left = left + width + 1 %> | |
164 | <% end %> |
|
164 | <% end %> | |
165 | <% while week_f <= @gantt.date_to %> |
|
165 | <% while week_f <= @gantt.date_to %> | |
166 | <% |
|
166 | <% | |
167 | width = ((week_f + 6 <= @gantt.date_to) ? |
|
167 | width = ((week_f + 6 <= @gantt.date_to) ? | |
168 | 7 * zoom - 1 : |
|
168 | 7 * zoom - 1 : | |
169 | (@gantt.date_to - week_f + 1) * zoom - 1).to_i |
|
169 | (@gantt.date_to - week_f + 1) * zoom - 1).to_i | |
170 | style = "" |
|
170 | style = "" | |
171 | style += "left: #{left}px;" |
|
171 | style += "left: #{left}px;" | |
172 | style += "top: 19px;" |
|
172 | style += "top: 19px;" | |
173 | style += "width: #{width}px;" |
|
173 | style += "width: #{width}px;" | |
174 | style += "height: #{height}px;" |
|
174 | style += "height: #{height}px;" | |
175 | %> |
|
175 | %> | |
176 | <%= content_tag(:div, :style => style, :class => "gantt_hdr") do %> |
|
176 | <%= content_tag(:div, :style => style, :class => "gantt_hdr") do %> | |
177 | <%= content_tag(:small) do %> |
|
177 | <%= content_tag(:small) do %> | |
178 | <%= week_f.cweek if width >= 16 %> |
|
178 | <%= week_f.cweek if width >= 16 %> | |
179 | <% end %> |
|
179 | <% end %> | |
180 | <% end %> |
|
180 | <% end %> | |
181 | <% |
|
181 | <% | |
182 | left = left + width + 1 |
|
182 | left = left + width + 1 | |
183 | week_f = week_f + 7 |
|
183 | week_f = week_f + 7 | |
184 | %> |
|
184 | %> | |
185 | <% end %> |
|
185 | <% end %> | |
186 | <% end %> |
|
186 | <% end %> | |
187 |
|
187 | |||
188 | <% ###### Days headers ####### %> |
|
188 | <% ###### Days headers ####### %> | |
189 | <% if show_days %> |
|
189 | <% if show_days %> | |
190 | <% |
|
190 | <% | |
191 | left = 0 |
|
191 | left = 0 | |
192 | height = g_height + header_heigth - 1 |
|
192 | height = g_height + header_heigth - 1 | |
193 | wday = @gantt.date_from.cwday |
|
193 | wday = @gantt.date_from.cwday | |
194 | %> |
|
194 | %> | |
195 | <% (@gantt.date_to - @gantt.date_from + 1).to_i.times do %> |
|
195 | <% (@gantt.date_to - @gantt.date_from + 1).to_i.times do %> | |
196 | <% |
|
196 | <% | |
197 | width = zoom - 1 |
|
197 | width = zoom - 1 | |
198 | style = "" |
|
198 | style = "" | |
199 | style += "left: #{left}px;" |
|
199 | style += "left: #{left}px;" | |
200 | style += "top:37px;" |
|
200 | style += "top:37px;" | |
201 | style += "width: #{width}px;" |
|
201 | style += "width: #{width}px;" | |
202 | style += "height: #{height}px;" |
|
202 | style += "height: #{height}px;" | |
203 | style += "font-size:0.7em;" |
|
203 | style += "font-size:0.7em;" | |
204 | clss = "gantt_hdr" |
|
204 | clss = "gantt_hdr" | |
205 | clss << " nwday" if @gantt.non_working_week_days.include?(wday) |
|
205 | clss << " nwday" if @gantt.non_working_week_days.include?(wday) | |
206 | %> |
|
206 | %> | |
207 | <%= content_tag(:div, :style => style, :class => clss) do %> |
|
207 | <%= content_tag(:div, :style => style, :class => clss) do %> | |
208 | <%= day_letter(wday) %> |
|
208 | <%= day_letter(wday) %> | |
209 | <% end %> |
|
209 | <% end %> | |
210 | <% |
|
210 | <% | |
211 | left = left + width + 1 |
|
211 | left = left + width + 1 | |
212 | wday = wday + 1 |
|
212 | wday = wday + 1 | |
213 | wday = 1 if wday > 7 |
|
213 | wday = 1 if wday > 7 | |
214 | %> |
|
214 | %> | |
215 | <% end %> |
|
215 | <% end %> | |
216 | <% end %> |
|
216 | <% end %> | |
217 |
|
217 | |||
218 | <%= @gantt.lines.html_safe %> |
|
218 | <%= @gantt.lines.html_safe %> | |
219 |
|
219 | |||
220 | <% ###### Today red line (excluded from cache) ###### %> |
|
220 | <% ###### Today red line (excluded from cache) ###### %> | |
221 | <% if Date.today >= @gantt.date_from and Date.today <= @gantt.date_to %> |
|
221 | <% if Date.today >= @gantt.date_from and Date.today <= @gantt.date_to %> | |
222 | <% |
|
222 | <% | |
223 | today_left = (((Date.today - @gantt.date_from + 1) * zoom).floor() - 1).to_i |
|
223 | today_left = (((Date.today - @gantt.date_from + 1) * zoom).floor() - 1).to_i | |
224 | style = "" |
|
224 | style = "" | |
225 | style += "position: absolute;" |
|
225 | style += "position: absolute;" | |
226 | style += "height: #{g_height}px;" |
|
226 | style += "height: #{g_height}px;" | |
227 | style += "top: #{headers_height + 1}px;" |
|
227 | style += "top: #{headers_height + 1}px;" | |
228 | style += "left: #{today_left}px;" |
|
228 | style += "left: #{today_left}px;" | |
229 | style += "width:10px;" |
|
229 | style += "width:10px;" | |
230 | style += "border-left: 1px dashed red;" |
|
230 | style += "border-left: 1px dashed red;" | |
231 | %> |
|
231 | %> | |
232 | <%= content_tag(:div, ' '.html_safe, :style => style) %> |
|
232 | <%= content_tag(:div, ' '.html_safe, :style => style) %> | |
233 | <% end %> |
|
233 | <% end %> | |
234 |
|
234 | <% | ||
|
235 | style = "" | |||
|
236 | style += "position: absolute;" | |||
|
237 | style += "height: #{g_height}px;" | |||
|
238 | style += "top: #{headers_height + 1}px;" | |||
|
239 | style += "left: 0px;" | |||
|
240 | style += "width: #{g_width - 1}px;" | |||
|
241 | %> | |||
|
242 | <%= content_tag(:div, '', :style => style, :id => "gantt_draw_area") %> | |||
235 | </div> |
|
243 | </div> | |
236 | </td> |
|
244 | </td> | |
237 | </tr> |
|
245 | </tr> | |
238 | </table> |
|
246 | </table> | |
239 |
|
247 | |||
240 | <table style="width:100%"> |
|
248 | <table style="width:100%"> | |
241 | <tr> |
|
249 | <tr> | |
242 | <td align="left"> |
|
250 | <td align="left"> | |
243 | <%= link_to_content_update("\xc2\xab " + l(:label_previous), |
|
251 | <%= link_to_content_update("\xc2\xab " + l(:label_previous), | |
244 | params.merge(@gantt.params_previous)) %> |
|
252 | params.merge(@gantt.params_previous)) %> | |
245 | </td> |
|
253 | </td> | |
246 | <td align="right"> |
|
254 | <td align="right"> | |
247 | <%= link_to_content_update(l(:label_next) + " \xc2\xbb", |
|
255 | <%= link_to_content_update(l(:label_next) + " \xc2\xbb", | |
248 | params.merge(@gantt.params_next)) %> |
|
256 | params.merge(@gantt.params_next)) %> | |
249 | </td> |
|
257 | </td> | |
250 | </tr> |
|
258 | </tr> | |
251 | </table> |
|
259 | </table> | |
252 |
|
260 | |||
253 | <% other_formats_links do |f| %> |
|
261 | <% other_formats_links do |f| %> | |
254 | <%= f.link_to 'PDF', :url => params.merge(@gantt.params) %> |
|
262 | <%= f.link_to 'PDF', :url => params.merge(@gantt.params) %> | |
255 | <%= f.link_to('PNG', :url => params.merge(@gantt.params)) if @gantt.respond_to?('to_image') %> |
|
263 | <%= f.link_to('PNG', :url => params.merge(@gantt.params)) if @gantt.respond_to?('to_image') %> | |
256 | <% end %> |
|
264 | <% end %> | |
257 | <% end # query.valid? %> |
|
265 | <% end # query.valid? %> | |
258 |
|
266 | |||
259 | <% content_for :sidebar do %> |
|
267 | <% content_for :sidebar do %> | |
260 | <%= render :partial => 'issues/sidebar' %> |
|
268 | <%= render :partial => 'issues/sidebar' %> | |
261 | <% end %> |
|
269 | <% end %> | |
262 |
|
270 | |||
263 | <% html_title(l(:label_gantt)) -%> |
|
271 | <% html_title(l(:label_gantt)) -%> | |
|
272 | ||||
|
273 | <% content_for :header_tags do %> | |||
|
274 | <%= javascript_include_tag 'raphael' %> | |||
|
275 | <%= javascript_include_tag 'gantt' %> | |||
|
276 | <% end %> | |||
|
277 | ||||
|
278 | <%= javascript_tag do %> | |||
|
279 | var issue_relation_type = <%= raw Redmine::Helpers::Gantt::DRAW_TYPES.to_json %>; | |||
|
280 | $(document).ready(drawGanttHandler); | |||
|
281 | $(window).resize(drawGanttHandler); | |||
|
282 | <% end %> |
@@ -1,883 +1,922 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module Redmine |
|
18 | module Redmine | |
19 | module Helpers |
|
19 | module Helpers | |
20 | # Simple class to handle gantt chart data |
|
20 | # Simple class to handle gantt chart data | |
21 | class Gantt |
|
21 | class Gantt | |
22 | include ERB::Util |
|
22 | include ERB::Util | |
23 | include Redmine::I18n |
|
23 | include Redmine::I18n | |
24 | include Redmine::Utils::DateCalculation |
|
24 | include Redmine::Utils::DateCalculation | |
25 |
|
25 | |||
|
26 | # Relation types that are rendered | |||
|
27 | DRAW_TYPES = { | |||
|
28 | IssueRelation::TYPE_BLOCKS => { :landscape_margin => 16, :color => '#F34F4F' }, | |||
|
29 | IssueRelation::TYPE_PRECEDES => { :landscape_margin => 20, :color => '#628FEA' } | |||
|
30 | }.freeze | |||
|
31 | ||||
26 | # :nodoc: |
|
32 | # :nodoc: | |
27 | # Some utility methods for the PDF export |
|
33 | # Some utility methods for the PDF export | |
28 | class PDF |
|
34 | class PDF | |
29 | MaxCharactorsForSubject = 45 |
|
35 | MaxCharactorsForSubject = 45 | |
30 | TotalWidth = 280 |
|
36 | TotalWidth = 280 | |
31 | LeftPaneWidth = 100 |
|
37 | LeftPaneWidth = 100 | |
32 |
|
38 | |||
33 | def self.right_pane_width |
|
39 | def self.right_pane_width | |
34 | TotalWidth - LeftPaneWidth |
|
40 | TotalWidth - LeftPaneWidth | |
35 | end |
|
41 | end | |
36 | end |
|
42 | end | |
37 |
|
43 | |||
38 | attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows |
|
44 | attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows | |
39 | attr_accessor :query |
|
45 | attr_accessor :query | |
40 | attr_accessor :project |
|
46 | attr_accessor :project | |
41 | attr_accessor :view |
|
47 | attr_accessor :view | |
42 |
|
48 | |||
43 | def initialize(options={}) |
|
49 | def initialize(options={}) | |
44 | options = options.dup |
|
50 | options = options.dup | |
45 | if options[:year] && options[:year].to_i >0 |
|
51 | if options[:year] && options[:year].to_i >0 | |
46 | @year_from = options[:year].to_i |
|
52 | @year_from = options[:year].to_i | |
47 | if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12 |
|
53 | if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12 | |
48 | @month_from = options[:month].to_i |
|
54 | @month_from = options[:month].to_i | |
49 | else |
|
55 | else | |
50 | @month_from = 1 |
|
56 | @month_from = 1 | |
51 | end |
|
57 | end | |
52 | else |
|
58 | else | |
53 | @month_from ||= Date.today.month |
|
59 | @month_from ||= Date.today.month | |
54 | @year_from ||= Date.today.year |
|
60 | @year_from ||= Date.today.year | |
55 | end |
|
61 | end | |
56 | zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i |
|
62 | zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i | |
57 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 |
|
63 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 | |
58 | months = (options[:months] || User.current.pref[:gantt_months]).to_i |
|
64 | months = (options[:months] || User.current.pref[:gantt_months]).to_i | |
59 | @months = (months > 0 && months < 25) ? months : 6 |
|
65 | @months = (months > 0 && months < 25) ? months : 6 | |
60 | # Save gantt parameters as user preference (zoom and months count) |
|
66 | # Save gantt parameters as user preference (zoom and months count) | |
61 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || |
|
67 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || | |
62 | @months != User.current.pref[:gantt_months])) |
|
68 | @months != User.current.pref[:gantt_months])) | |
63 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months |
|
69 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months | |
64 | User.current.preference.save |
|
70 | User.current.preference.save | |
65 | end |
|
71 | end | |
66 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
72 | @date_from = Date.civil(@year_from, @month_from, 1) | |
67 | @date_to = (@date_from >> @months) - 1 |
|
73 | @date_to = (@date_from >> @months) - 1 | |
68 | @subjects = '' |
|
74 | @subjects = '' | |
69 | @lines = '' |
|
75 | @lines = '' | |
70 | @number_of_rows = nil |
|
76 | @number_of_rows = nil | |
71 | @issue_ancestors = [] |
|
77 | @issue_ancestors = [] | |
72 | @truncated = false |
|
78 | @truncated = false | |
73 | if options.has_key?(:max_rows) |
|
79 | if options.has_key?(:max_rows) | |
74 | @max_rows = options[:max_rows] |
|
80 | @max_rows = options[:max_rows] | |
75 | else |
|
81 | else | |
76 | @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i |
|
82 | @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i | |
77 | end |
|
83 | end | |
78 | end |
|
84 | end | |
79 |
|
85 | |||
80 | def common_params |
|
86 | def common_params | |
81 | { :controller => 'gantts', :action => 'show', :project_id => @project } |
|
87 | { :controller => 'gantts', :action => 'show', :project_id => @project } | |
82 | end |
|
88 | end | |
83 |
|
89 | |||
84 | def params |
|
90 | def params | |
85 | common_params.merge({:zoom => zoom, :year => year_from, |
|
91 | common_params.merge({:zoom => zoom, :year => year_from, | |
86 | :month => month_from, :months => months}) |
|
92 | :month => month_from, :months => months}) | |
87 | end |
|
93 | end | |
88 |
|
94 | |||
89 | def params_previous |
|
95 | def params_previous | |
90 | common_params.merge({:year => (date_from << months).year, |
|
96 | common_params.merge({:year => (date_from << months).year, | |
91 | :month => (date_from << months).month, |
|
97 | :month => (date_from << months).month, | |
92 | :zoom => zoom, :months => months}) |
|
98 | :zoom => zoom, :months => months}) | |
93 | end |
|
99 | end | |
94 |
|
100 | |||
95 | def params_next |
|
101 | def params_next | |
96 | common_params.merge({:year => (date_from >> months).year, |
|
102 | common_params.merge({:year => (date_from >> months).year, | |
97 | :month => (date_from >> months).month, |
|
103 | :month => (date_from >> months).month, | |
98 | :zoom => zoom, :months => months}) |
|
104 | :zoom => zoom, :months => months}) | |
99 | end |
|
105 | end | |
100 |
|
106 | |||
101 | # Returns the number of rows that will be rendered on the Gantt chart |
|
107 | # Returns the number of rows that will be rendered on the Gantt chart | |
102 | def number_of_rows |
|
108 | def number_of_rows | |
103 | return @number_of_rows if @number_of_rows |
|
109 | return @number_of_rows if @number_of_rows | |
104 | rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)} |
|
110 | rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)} | |
105 | rows > @max_rows ? @max_rows : rows |
|
111 | rows > @max_rows ? @max_rows : rows | |
106 | end |
|
112 | end | |
107 |
|
113 | |||
108 | # Returns the number of rows that will be used to list a project on |
|
114 | # Returns the number of rows that will be used to list a project on | |
109 | # the Gantt chart. This will recurse for each subproject. |
|
115 | # the Gantt chart. This will recurse for each subproject. | |
110 | def number_of_rows_on_project(project) |
|
116 | def number_of_rows_on_project(project) | |
111 | return 0 unless projects.include?(project) |
|
117 | return 0 unless projects.include?(project) | |
112 | count = 1 |
|
118 | count = 1 | |
113 | count += project_issues(project).size |
|
119 | count += project_issues(project).size | |
114 | count += project_versions(project).size |
|
120 | count += project_versions(project).size | |
115 | count |
|
121 | count | |
116 | end |
|
122 | end | |
117 |
|
123 | |||
118 | # Renders the subjects of the Gantt chart, the left side. |
|
124 | # Renders the subjects of the Gantt chart, the left side. | |
119 | def subjects(options={}) |
|
125 | def subjects(options={}) | |
120 | render(options.merge(:only => :subjects)) unless @subjects_rendered |
|
126 | render(options.merge(:only => :subjects)) unless @subjects_rendered | |
121 | @subjects |
|
127 | @subjects | |
122 | end |
|
128 | end | |
123 |
|
129 | |||
124 | # Renders the lines of the Gantt chart, the right side |
|
130 | # Renders the lines of the Gantt chart, the right side | |
125 | def lines(options={}) |
|
131 | def lines(options={}) | |
126 | render(options.merge(:only => :lines)) unless @lines_rendered |
|
132 | render(options.merge(:only => :lines)) unless @lines_rendered | |
127 | @lines |
|
133 | @lines | |
128 | end |
|
134 | end | |
129 |
|
135 | |||
130 | # Returns issues that will be rendered |
|
136 | # Returns issues that will be rendered | |
131 | def issues |
|
137 | def issues | |
132 | @issues ||= @query.issues( |
|
138 | @issues ||= @query.issues( | |
133 | :include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
|
139 | :include => [:assigned_to, :tracker, :priority, :category, :fixed_version], | |
134 | :order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC", |
|
140 | :order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC", | |
135 | :limit => @max_rows |
|
141 | :limit => @max_rows | |
136 | ) |
|
142 | ) | |
137 | end |
|
143 | end | |
138 |
|
144 | |||
|
145 | # Returns a hash of the relations between the issues that are present on the gantt | |||
|
146 | # and that should be displayed, grouped by issue ids. | |||
|
147 | def relations | |||
|
148 | return @relations if @relations | |||
|
149 | if issues.any? | |||
|
150 | issue_ids = issues.map(&:id) | |||
|
151 | @relations = IssueRelation. | |||
|
152 | where(:issue_from_id => issue_ids, :issue_to_id => issue_ids, :relation_type => DRAW_TYPES.keys). | |||
|
153 | group_by(&:issue_from_id) | |||
|
154 | else | |||
|
155 | @relations = {} | |||
|
156 | end | |||
|
157 | end | |||
|
158 | ||||
139 | # Return all the project nodes that will be displayed |
|
159 | # Return all the project nodes that will be displayed | |
140 | def projects |
|
160 | def projects | |
141 | return @projects if @projects |
|
161 | return @projects if @projects | |
142 | ids = issues.collect(&:project).uniq.collect(&:id) |
|
162 | ids = issues.collect(&:project).uniq.collect(&:id) | |
143 | if ids.any? |
|
163 | if ids.any? | |
144 | # All issues projects and their visible ancestors |
|
164 | # All issues projects and their visible ancestors | |
145 | @projects = Project.visible.all( |
|
165 | @projects = Project.visible.all( | |
146 | :joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt", |
|
166 | :joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt", | |
147 | :conditions => ["child.id IN (?)", ids], |
|
167 | :conditions => ["child.id IN (?)", ids], | |
148 | :order => "#{Project.table_name}.lft ASC" |
|
168 | :order => "#{Project.table_name}.lft ASC" | |
149 | ).uniq |
|
169 | ).uniq | |
150 | else |
|
170 | else | |
151 | @projects = [] |
|
171 | @projects = [] | |
152 | end |
|
172 | end | |
153 | end |
|
173 | end | |
154 |
|
174 | |||
155 | # Returns the issues that belong to +project+ |
|
175 | # Returns the issues that belong to +project+ | |
156 | def project_issues(project) |
|
176 | def project_issues(project) | |
157 | @issues_by_project ||= issues.group_by(&:project) |
|
177 | @issues_by_project ||= issues.group_by(&:project) | |
158 | @issues_by_project[project] || [] |
|
178 | @issues_by_project[project] || [] | |
159 | end |
|
179 | end | |
160 |
|
180 | |||
161 | # Returns the distinct versions of the issues that belong to +project+ |
|
181 | # Returns the distinct versions of the issues that belong to +project+ | |
162 | def project_versions(project) |
|
182 | def project_versions(project) | |
163 | project_issues(project).collect(&:fixed_version).compact.uniq |
|
183 | project_issues(project).collect(&:fixed_version).compact.uniq | |
164 | end |
|
184 | end | |
165 |
|
185 | |||
166 | # Returns the issues that belong to +project+ and are assigned to +version+ |
|
186 | # Returns the issues that belong to +project+ and are assigned to +version+ | |
167 | def version_issues(project, version) |
|
187 | def version_issues(project, version) | |
168 | project_issues(project).select {|issue| issue.fixed_version == version} |
|
188 | project_issues(project).select {|issue| issue.fixed_version == version} | |
169 | end |
|
189 | end | |
170 |
|
190 | |||
171 | def render(options={}) |
|
191 | def render(options={}) | |
172 | options = {:top => 0, :top_increment => 20, |
|
192 | options = {:top => 0, :top_increment => 20, | |
173 | :indent_increment => 20, :render => :subject, |
|
193 | :indent_increment => 20, :render => :subject, | |
174 | :format => :html}.merge(options) |
|
194 | :format => :html}.merge(options) | |
175 | indent = options[:indent] || 4 |
|
195 | indent = options[:indent] || 4 | |
176 | @subjects = '' unless options[:only] == :lines |
|
196 | @subjects = '' unless options[:only] == :lines | |
177 | @lines = '' unless options[:only] == :subjects |
|
197 | @lines = '' unless options[:only] == :subjects | |
178 | @number_of_rows = 0 |
|
198 | @number_of_rows = 0 | |
179 | Project.project_tree(projects) do |project, level| |
|
199 | Project.project_tree(projects) do |project, level| | |
180 | options[:indent] = indent + level * options[:indent_increment] |
|
200 | options[:indent] = indent + level * options[:indent_increment] | |
181 | render_project(project, options) |
|
201 | render_project(project, options) | |
182 | break if abort? |
|
202 | break if abort? | |
183 | end |
|
203 | end | |
184 | @subjects_rendered = true unless options[:only] == :lines |
|
204 | @subjects_rendered = true unless options[:only] == :lines | |
185 | @lines_rendered = true unless options[:only] == :subjects |
|
205 | @lines_rendered = true unless options[:only] == :subjects | |
186 | render_end(options) |
|
206 | render_end(options) | |
187 | end |
|
207 | end | |
188 |
|
208 | |||
189 | def render_project(project, options={}) |
|
209 | def render_project(project, options={}) | |
190 | subject_for_project(project, options) unless options[:only] == :lines |
|
210 | subject_for_project(project, options) unless options[:only] == :lines | |
191 | line_for_project(project, options) unless options[:only] == :subjects |
|
211 | line_for_project(project, options) unless options[:only] == :subjects | |
192 | options[:top] += options[:top_increment] |
|
212 | options[:top] += options[:top_increment] | |
193 | options[:indent] += options[:indent_increment] |
|
213 | options[:indent] += options[:indent_increment] | |
194 | @number_of_rows += 1 |
|
214 | @number_of_rows += 1 | |
195 | return if abort? |
|
215 | return if abort? | |
196 | issues = project_issues(project).select {|i| i.fixed_version.nil?} |
|
216 | issues = project_issues(project).select {|i| i.fixed_version.nil?} | |
197 | sort_issues!(issues) |
|
217 | sort_issues!(issues) | |
198 | if issues |
|
218 | if issues | |
199 | render_issues(issues, options) |
|
219 | render_issues(issues, options) | |
200 | return if abort? |
|
220 | return if abort? | |
201 | end |
|
221 | end | |
202 | versions = project_versions(project) |
|
222 | versions = project_versions(project) | |
203 | versions.each do |version| |
|
223 | versions.each do |version| | |
204 | render_version(project, version, options) |
|
224 | render_version(project, version, options) | |
205 | end |
|
225 | end | |
206 | # Remove indent to hit the next sibling |
|
226 | # Remove indent to hit the next sibling | |
207 | options[:indent] -= options[:indent_increment] |
|
227 | options[:indent] -= options[:indent_increment] | |
208 | end |
|
228 | end | |
209 |
|
229 | |||
210 | def render_issues(issues, options={}) |
|
230 | def render_issues(issues, options={}) | |
211 | @issue_ancestors = [] |
|
231 | @issue_ancestors = [] | |
212 | issues.each do |i| |
|
232 | issues.each do |i| | |
213 | subject_for_issue(i, options) unless options[:only] == :lines |
|
233 | subject_for_issue(i, options) unless options[:only] == :lines | |
214 | line_for_issue(i, options) unless options[:only] == :subjects |
|
234 | line_for_issue(i, options) unless options[:only] == :subjects | |
215 | options[:top] += options[:top_increment] |
|
235 | options[:top] += options[:top_increment] | |
216 | @number_of_rows += 1 |
|
236 | @number_of_rows += 1 | |
217 | break if abort? |
|
237 | break if abort? | |
218 | end |
|
238 | end | |
219 | options[:indent] -= (options[:indent_increment] * @issue_ancestors.size) |
|
239 | options[:indent] -= (options[:indent_increment] * @issue_ancestors.size) | |
220 | end |
|
240 | end | |
221 |
|
241 | |||
222 | def render_version(project, version, options={}) |
|
242 | def render_version(project, version, options={}) | |
223 | # Version header |
|
243 | # Version header | |
224 | subject_for_version(version, options) unless options[:only] == :lines |
|
244 | subject_for_version(version, options) unless options[:only] == :lines | |
225 | line_for_version(version, options) unless options[:only] == :subjects |
|
245 | line_for_version(version, options) unless options[:only] == :subjects | |
226 | options[:top] += options[:top_increment] |
|
246 | options[:top] += options[:top_increment] | |
227 | @number_of_rows += 1 |
|
247 | @number_of_rows += 1 | |
228 | return if abort? |
|
248 | return if abort? | |
229 | issues = version_issues(project, version) |
|
249 | issues = version_issues(project, version) | |
230 | if issues |
|
250 | if issues | |
231 | sort_issues!(issues) |
|
251 | sort_issues!(issues) | |
232 | # Indent issues |
|
252 | # Indent issues | |
233 | options[:indent] += options[:indent_increment] |
|
253 | options[:indent] += options[:indent_increment] | |
234 | render_issues(issues, options) |
|
254 | render_issues(issues, options) | |
235 | options[:indent] -= options[:indent_increment] |
|
255 | options[:indent] -= options[:indent_increment] | |
236 | end |
|
256 | end | |
237 | end |
|
257 | end | |
238 |
|
258 | |||
239 | def render_end(options={}) |
|
259 | def render_end(options={}) | |
240 | case options[:format] |
|
260 | case options[:format] | |
241 | when :pdf |
|
261 | when :pdf | |
242 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) |
|
262 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) | |
243 | end |
|
263 | end | |
244 | end |
|
264 | end | |
245 |
|
265 | |||
246 | def subject_for_project(project, options) |
|
266 | def subject_for_project(project, options) | |
247 | case options[:format] |
|
267 | case options[:format] | |
248 | when :html |
|
268 | when :html | |
249 | html_class = "" |
|
269 | html_class = "" | |
250 | html_class << 'icon icon-projects ' |
|
270 | html_class << 'icon icon-projects ' | |
251 | html_class << (project.overdue? ? 'project-overdue' : '') |
|
271 | html_class << (project.overdue? ? 'project-overdue' : '') | |
252 | s = view.link_to_project(project).html_safe |
|
272 | s = view.link_to_project(project).html_safe | |
253 | subject = view.content_tag(:span, s, |
|
273 | subject = view.content_tag(:span, s, | |
254 | :class => html_class).html_safe |
|
274 | :class => html_class).html_safe | |
255 | html_subject(options, subject, :css => "project-name") |
|
275 | html_subject(options, subject, :css => "project-name") | |
256 | when :image |
|
276 | when :image | |
257 | image_subject(options, project.name) |
|
277 | image_subject(options, project.name) | |
258 | when :pdf |
|
278 | when :pdf | |
259 | pdf_new_page?(options) |
|
279 | pdf_new_page?(options) | |
260 | pdf_subject(options, project.name) |
|
280 | pdf_subject(options, project.name) | |
261 | end |
|
281 | end | |
262 | end |
|
282 | end | |
263 |
|
283 | |||
264 | def line_for_project(project, options) |
|
284 | def line_for_project(project, options) | |
265 | # Skip versions that don't have a start_date or due date |
|
285 | # Skip versions that don't have a start_date or due date | |
266 | if project.is_a?(Project) && project.start_date && project.due_date |
|
286 | if project.is_a?(Project) && project.start_date && project.due_date | |
267 | options[:zoom] ||= 1 |
|
287 | options[:zoom] ||= 1 | |
268 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] |
|
288 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] | |
269 | coords = coordinates(project.start_date, project.due_date, nil, options[:zoom]) |
|
289 | coords = coordinates(project.start_date, project.due_date, nil, options[:zoom]) | |
270 | label = h(project) |
|
290 | label = h(project) | |
271 | case options[:format] |
|
291 | case options[:format] | |
272 | when :html |
|
292 | when :html | |
273 | html_task(options, coords, :css => "project task", :label => label, :markers => true) |
|
293 | html_task(options, coords, :css => "project task", :label => label, :markers => true) | |
274 | when :image |
|
294 | when :image | |
275 | image_task(options, coords, :label => label, :markers => true, :height => 3) |
|
295 | image_task(options, coords, :label => label, :markers => true, :height => 3) | |
276 | when :pdf |
|
296 | when :pdf | |
277 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) |
|
297 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) | |
278 | end |
|
298 | end | |
279 | else |
|
299 | else | |
280 | ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date" |
|
300 | ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date" | |
281 | '' |
|
301 | '' | |
282 | end |
|
302 | end | |
283 | end |
|
303 | end | |
284 |
|
304 | |||
285 | def subject_for_version(version, options) |
|
305 | def subject_for_version(version, options) | |
286 | case options[:format] |
|
306 | case options[:format] | |
287 | when :html |
|
307 | when :html | |
288 | html_class = "" |
|
308 | html_class = "" | |
289 | html_class << 'icon icon-package ' |
|
309 | html_class << 'icon icon-package ' | |
290 | html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " " |
|
310 | html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " " | |
291 | html_class << (version.overdue? ? 'version-overdue' : '') |
|
311 | html_class << (version.overdue? ? 'version-overdue' : '') | |
292 | s = view.link_to_version(version).html_safe |
|
312 | s = view.link_to_version(version).html_safe | |
293 | subject = view.content_tag(:span, s, |
|
313 | subject = view.content_tag(:span, s, | |
294 | :class => html_class).html_safe |
|
314 | :class => html_class).html_safe | |
295 | html_subject(options, subject, :css => "version-name") |
|
315 | html_subject(options, subject, :css => "version-name") | |
296 | when :image |
|
316 | when :image | |
297 | image_subject(options, version.to_s_with_project) |
|
317 | image_subject(options, version.to_s_with_project) | |
298 | when :pdf |
|
318 | when :pdf | |
299 | pdf_new_page?(options) |
|
319 | pdf_new_page?(options) | |
300 | pdf_subject(options, version.to_s_with_project) |
|
320 | pdf_subject(options, version.to_s_with_project) | |
301 | end |
|
321 | end | |
302 | end |
|
322 | end | |
303 |
|
323 | |||
304 | def line_for_version(version, options) |
|
324 | def line_for_version(version, options) | |
305 | # Skip versions that don't have a start_date |
|
325 | # Skip versions that don't have a start_date | |
306 | if version.is_a?(Version) && version.start_date && version.due_date |
|
326 | if version.is_a?(Version) && version.start_date && version.due_date | |
307 | options[:zoom] ||= 1 |
|
327 | options[:zoom] ||= 1 | |
308 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] |
|
328 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] | |
309 | coords = coordinates(version.start_date, |
|
329 | coords = coordinates(version.start_date, | |
310 | version.due_date, version.completed_percent, |
|
330 | version.due_date, version.completed_percent, | |
311 | options[:zoom]) |
|
331 | options[:zoom]) | |
312 | label = "#{h version} #{h version.completed_percent.to_i.to_s}%" |
|
332 | label = "#{h version} #{h version.completed_percent.to_i.to_s}%" | |
313 | label = h("#{version.project} -") + label unless @project && @project == version.project |
|
333 | label = h("#{version.project} -") + label unless @project && @project == version.project | |
314 | case options[:format] |
|
334 | case options[:format] | |
315 | when :html |
|
335 | when :html | |
316 | html_task(options, coords, :css => "version task", :label => label, :markers => true) |
|
336 | html_task(options, coords, :css => "version task", :label => label, :markers => true) | |
317 | when :image |
|
337 | when :image | |
318 | image_task(options, coords, :label => label, :markers => true, :height => 3) |
|
338 | image_task(options, coords, :label => label, :markers => true, :height => 3) | |
319 | when :pdf |
|
339 | when :pdf | |
320 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) |
|
340 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) | |
321 | end |
|
341 | end | |
322 | else |
|
342 | else | |
323 | ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date" |
|
343 | ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date" | |
324 | '' |
|
344 | '' | |
325 | end |
|
345 | end | |
326 | end |
|
346 | end | |
327 |
|
347 | |||
328 | def subject_for_issue(issue, options) |
|
348 | def subject_for_issue(issue, options) | |
329 | while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last) |
|
349 | while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last) | |
330 | @issue_ancestors.pop |
|
350 | @issue_ancestors.pop | |
331 | options[:indent] -= options[:indent_increment] |
|
351 | options[:indent] -= options[:indent_increment] | |
332 | end |
|
352 | end | |
333 | output = case options[:format] |
|
353 | output = case options[:format] | |
334 | when :html |
|
354 | when :html | |
335 | css_classes = '' |
|
355 | css_classes = '' | |
336 | css_classes << ' issue-overdue' if issue.overdue? |
|
356 | css_classes << ' issue-overdue' if issue.overdue? | |
337 | css_classes << ' issue-behind-schedule' if issue.behind_schedule? |
|
357 | css_classes << ' issue-behind-schedule' if issue.behind_schedule? | |
338 | css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to |
|
358 | css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to | |
339 | s = "".html_safe |
|
359 | s = "".html_safe | |
340 | if issue.assigned_to.present? |
|
360 | if issue.assigned_to.present? | |
341 | assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name |
|
361 | assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name | |
342 | s << view.avatar(issue.assigned_to, |
|
362 | s << view.avatar(issue.assigned_to, | |
343 | :class => 'gravatar icon-gravatar', |
|
363 | :class => 'gravatar icon-gravatar', | |
344 | :size => 10, |
|
364 | :size => 10, | |
345 | :title => assigned_string).to_s.html_safe |
|
365 | :title => assigned_string).to_s.html_safe | |
346 | end |
|
366 | end | |
347 | s << view.link_to_issue(issue).html_safe |
|
367 | s << view.link_to_issue(issue).html_safe | |
348 | subject = view.content_tag(:span, s, :class => css_classes).html_safe |
|
368 | subject = view.content_tag(:span, s, :class => css_classes).html_safe | |
349 | html_subject(options, subject, :css => "issue-subject", |
|
369 | html_subject(options, subject, :css => "issue-subject", | |
350 | :title => issue.subject) + "\n" |
|
370 | :title => issue.subject) + "\n" | |
351 | when :image |
|
371 | when :image | |
352 | image_subject(options, issue.subject) |
|
372 | image_subject(options, issue.subject) | |
353 | when :pdf |
|
373 | when :pdf | |
354 | pdf_new_page?(options) |
|
374 | pdf_new_page?(options) | |
355 | pdf_subject(options, issue.subject) |
|
375 | pdf_subject(options, issue.subject) | |
356 | end |
|
376 | end | |
357 | unless issue.leaf? |
|
377 | unless issue.leaf? | |
358 | @issue_ancestors << issue |
|
378 | @issue_ancestors << issue | |
359 | options[:indent] += options[:indent_increment] |
|
379 | options[:indent] += options[:indent_increment] | |
360 | end |
|
380 | end | |
361 | output |
|
381 | output | |
362 | end |
|
382 | end | |
363 |
|
383 | |||
364 | def line_for_issue(issue, options) |
|
384 | def line_for_issue(issue, options) | |
365 | # Skip issues that don't have a due_before (due_date or version's due_date) |
|
385 | # Skip issues that don't have a due_before (due_date or version's due_date) | |
366 | if issue.is_a?(Issue) && issue.due_before |
|
386 | if issue.is_a?(Issue) && issue.due_before | |
367 | coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) |
|
387 | coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) | |
368 | label = "#{issue.status.name} #{issue.done_ratio}%" |
|
388 | label = "#{issue.status.name} #{issue.done_ratio}%" | |
369 | case options[:format] |
|
389 | case options[:format] | |
370 | when :html |
|
390 | when :html | |
371 | html_task(options, coords, |
|
391 | html_task(options, coords, | |
372 | :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), |
|
392 | :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), | |
373 | :label => label, :issue => issue, |
|
393 | :label => label, :issue => issue, | |
374 | :markers => !issue.leaf?) |
|
394 | :markers => !issue.leaf?) | |
375 | when :image |
|
395 | when :image | |
376 | image_task(options, coords, :label => label) |
|
396 | image_task(options, coords, :label => label) | |
377 | when :pdf |
|
397 | when :pdf | |
378 | pdf_task(options, coords, :label => label) |
|
398 | pdf_task(options, coords, :label => label) | |
379 | end |
|
399 | end | |
380 | else |
|
400 | else | |
381 | ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" |
|
401 | ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" | |
382 | '' |
|
402 | '' | |
383 | end |
|
403 | end | |
384 | end |
|
404 | end | |
385 |
|
405 | |||
386 | # Generates a gantt image |
|
406 | # Generates a gantt image | |
387 | # Only defined if RMagick is avalaible |
|
407 | # Only defined if RMagick is avalaible | |
388 | def to_image(format='PNG') |
|
408 | def to_image(format='PNG') | |
389 | date_to = (@date_from >> @months) - 1 |
|
409 | date_to = (@date_from >> @months) - 1 | |
390 | show_weeks = @zoom > 1 |
|
410 | show_weeks = @zoom > 1 | |
391 | show_days = @zoom > 2 |
|
411 | show_days = @zoom > 2 | |
392 | subject_width = 400 |
|
412 | subject_width = 400 | |
393 | header_height = 18 |
|
413 | header_height = 18 | |
394 | # width of one day in pixels |
|
414 | # width of one day in pixels | |
395 | zoom = @zoom * 2 |
|
415 | zoom = @zoom * 2 | |
396 | g_width = (@date_to - @date_from + 1) * zoom |
|
416 | g_width = (@date_to - @date_from + 1) * zoom | |
397 | g_height = 20 * number_of_rows + 30 |
|
417 | g_height = 20 * number_of_rows + 30 | |
398 | headers_height = (show_weeks ? 2 * header_height : header_height) |
|
418 | headers_height = (show_weeks ? 2 * header_height : header_height) | |
399 | height = g_height + headers_height |
|
419 | height = g_height + headers_height | |
400 | imgl = Magick::ImageList.new |
|
420 | imgl = Magick::ImageList.new | |
401 | imgl.new_image(subject_width + g_width + 1, height) |
|
421 | imgl.new_image(subject_width + g_width + 1, height) | |
402 | gc = Magick::Draw.new |
|
422 | gc = Magick::Draw.new | |
403 | gc.font = Redmine::Configuration['rmagick_font_path'] || "" |
|
423 | gc.font = Redmine::Configuration['rmagick_font_path'] || "" | |
404 | # Subjects |
|
424 | # Subjects | |
405 | gc.stroke('transparent') |
|
425 | gc.stroke('transparent') | |
406 | subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image) |
|
426 | subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image) | |
407 | # Months headers |
|
427 | # Months headers | |
408 | month_f = @date_from |
|
428 | month_f = @date_from | |
409 | left = subject_width |
|
429 | left = subject_width | |
410 | @months.times do |
|
430 | @months.times do | |
411 | width = ((month_f >> 1) - month_f) * zoom |
|
431 | width = ((month_f >> 1) - month_f) * zoom | |
412 | gc.fill('white') |
|
432 | gc.fill('white') | |
413 | gc.stroke('grey') |
|
433 | gc.stroke('grey') | |
414 | gc.stroke_width(1) |
|
434 | gc.stroke_width(1) | |
415 | gc.rectangle(left, 0, left + width, height) |
|
435 | gc.rectangle(left, 0, left + width, height) | |
416 | gc.fill('black') |
|
436 | gc.fill('black') | |
417 | gc.stroke('transparent') |
|
437 | gc.stroke('transparent') | |
418 | gc.stroke_width(1) |
|
438 | gc.stroke_width(1) | |
419 | gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}") |
|
439 | gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}") | |
420 | left = left + width |
|
440 | left = left + width | |
421 | month_f = month_f >> 1 |
|
441 | month_f = month_f >> 1 | |
422 | end |
|
442 | end | |
423 | # Weeks headers |
|
443 | # Weeks headers | |
424 | if show_weeks |
|
444 | if show_weeks | |
425 | left = subject_width |
|
445 | left = subject_width | |
426 | height = header_height |
|
446 | height = header_height | |
427 | if @date_from.cwday == 1 |
|
447 | if @date_from.cwday == 1 | |
428 | # date_from is monday |
|
448 | # date_from is monday | |
429 | week_f = date_from |
|
449 | week_f = date_from | |
430 | else |
|
450 | else | |
431 | # find next monday after date_from |
|
451 | # find next monday after date_from | |
432 | week_f = @date_from + (7 - @date_from.cwday + 1) |
|
452 | week_f = @date_from + (7 - @date_from.cwday + 1) | |
433 | width = (7 - @date_from.cwday + 1) * zoom |
|
453 | width = (7 - @date_from.cwday + 1) * zoom | |
434 | gc.fill('white') |
|
454 | gc.fill('white') | |
435 | gc.stroke('grey') |
|
455 | gc.stroke('grey') | |
436 | gc.stroke_width(1) |
|
456 | gc.stroke_width(1) | |
437 | gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1) |
|
457 | gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1) | |
438 | left = left + width |
|
458 | left = left + width | |
439 | end |
|
459 | end | |
440 | while week_f <= date_to |
|
460 | while week_f <= date_to | |
441 | width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom |
|
461 | width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom | |
442 | gc.fill('white') |
|
462 | gc.fill('white') | |
443 | gc.stroke('grey') |
|
463 | gc.stroke('grey') | |
444 | gc.stroke_width(1) |
|
464 | gc.stroke_width(1) | |
445 | gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1) |
|
465 | gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1) | |
446 | gc.fill('black') |
|
466 | gc.fill('black') | |
447 | gc.stroke('transparent') |
|
467 | gc.stroke('transparent') | |
448 | gc.stroke_width(1) |
|
468 | gc.stroke_width(1) | |
449 | gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s) |
|
469 | gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s) | |
450 | left = left + width |
|
470 | left = left + width | |
451 | week_f = week_f + 7 |
|
471 | week_f = week_f + 7 | |
452 | end |
|
472 | end | |
453 | end |
|
473 | end | |
454 | # Days details (week-end in grey) |
|
474 | # Days details (week-end in grey) | |
455 | if show_days |
|
475 | if show_days | |
456 | left = subject_width |
|
476 | left = subject_width | |
457 | height = g_height + header_height - 1 |
|
477 | height = g_height + header_height - 1 | |
458 | wday = @date_from.cwday |
|
478 | wday = @date_from.cwday | |
459 | (date_to - @date_from + 1).to_i.times do |
|
479 | (date_to - @date_from + 1).to_i.times do | |
460 | width = zoom |
|
480 | width = zoom | |
461 | gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white') |
|
481 | gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white') | |
462 | gc.stroke('#ddd') |
|
482 | gc.stroke('#ddd') | |
463 | gc.stroke_width(1) |
|
483 | gc.stroke_width(1) | |
464 | gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1) |
|
484 | gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1) | |
465 | left = left + width |
|
485 | left = left + width | |
466 | wday = wday + 1 |
|
486 | wday = wday + 1 | |
467 | wday = 1 if wday > 7 |
|
487 | wday = 1 if wday > 7 | |
468 | end |
|
488 | end | |
469 | end |
|
489 | end | |
470 | # border |
|
490 | # border | |
471 | gc.fill('transparent') |
|
491 | gc.fill('transparent') | |
472 | gc.stroke('grey') |
|
492 | gc.stroke('grey') | |
473 | gc.stroke_width(1) |
|
493 | gc.stroke_width(1) | |
474 | gc.rectangle(0, 0, subject_width + g_width, headers_height) |
|
494 | gc.rectangle(0, 0, subject_width + g_width, headers_height) | |
475 | gc.stroke('black') |
|
495 | gc.stroke('black') | |
476 | gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1) |
|
496 | gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1) | |
477 | # content |
|
497 | # content | |
478 | top = headers_height + 20 |
|
498 | top = headers_height + 20 | |
479 | gc.stroke('transparent') |
|
499 | gc.stroke('transparent') | |
480 | lines(:image => gc, :top => top, :zoom => zoom, |
|
500 | lines(:image => gc, :top => top, :zoom => zoom, | |
481 | :subject_width => subject_width, :format => :image) |
|
501 | :subject_width => subject_width, :format => :image) | |
482 | # today red line |
|
502 | # today red line | |
483 | if Date.today >= @date_from and Date.today <= date_to |
|
503 | if Date.today >= @date_from and Date.today <= date_to | |
484 | gc.stroke('red') |
|
504 | gc.stroke('red') | |
485 | x = (Date.today - @date_from + 1) * zoom + subject_width |
|
505 | x = (Date.today - @date_from + 1) * zoom + subject_width | |
486 | gc.line(x, headers_height, x, headers_height + g_height - 1) |
|
506 | gc.line(x, headers_height, x, headers_height + g_height - 1) | |
487 | end |
|
507 | end | |
488 | gc.draw(imgl) |
|
508 | gc.draw(imgl) | |
489 | imgl.format = format |
|
509 | imgl.format = format | |
490 | imgl.to_blob |
|
510 | imgl.to_blob | |
491 | end if Object.const_defined?(:Magick) |
|
511 | end if Object.const_defined?(:Magick) | |
492 |
|
512 | |||
493 | def to_pdf |
|
513 | def to_pdf | |
494 | pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language) |
|
514 | pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language) | |
495 | pdf.SetTitle("#{l(:label_gantt)} #{project}") |
|
515 | pdf.SetTitle("#{l(:label_gantt)} #{project}") | |
496 | pdf.alias_nb_pages |
|
516 | pdf.alias_nb_pages | |
497 | pdf.footer_date = format_date(Date.today) |
|
517 | pdf.footer_date = format_date(Date.today) | |
498 | pdf.AddPage("L") |
|
518 | pdf.AddPage("L") | |
499 | pdf.SetFontStyle('B', 12) |
|
519 | pdf.SetFontStyle('B', 12) | |
500 | pdf.SetX(15) |
|
520 | pdf.SetX(15) | |
501 | pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s) |
|
521 | pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s) | |
502 | pdf.Ln |
|
522 | pdf.Ln | |
503 | pdf.SetFontStyle('B', 9) |
|
523 | pdf.SetFontStyle('B', 9) | |
504 | subject_width = PDF::LeftPaneWidth |
|
524 | subject_width = PDF::LeftPaneWidth | |
505 | header_height = 5 |
|
525 | header_height = 5 | |
506 | headers_height = header_height |
|
526 | headers_height = header_height | |
507 | show_weeks = false |
|
527 | show_weeks = false | |
508 | show_days = false |
|
528 | show_days = false | |
509 | if self.months < 7 |
|
529 | if self.months < 7 | |
510 | show_weeks = true |
|
530 | show_weeks = true | |
511 | headers_height = 2 * header_height |
|
531 | headers_height = 2 * header_height | |
512 | if self.months < 3 |
|
532 | if self.months < 3 | |
513 | show_days = true |
|
533 | show_days = true | |
514 | headers_height = 3 * header_height |
|
534 | headers_height = 3 * header_height | |
515 | end |
|
535 | end | |
516 | end |
|
536 | end | |
517 | g_width = PDF.right_pane_width |
|
537 | g_width = PDF.right_pane_width | |
518 | zoom = (g_width) / (self.date_to - self.date_from + 1) |
|
538 | zoom = (g_width) / (self.date_to - self.date_from + 1) | |
519 | g_height = 120 |
|
539 | g_height = 120 | |
520 | t_height = g_height + headers_height |
|
540 | t_height = g_height + headers_height | |
521 | y_start = pdf.GetY |
|
541 | y_start = pdf.GetY | |
522 | # Months headers |
|
542 | # Months headers | |
523 | month_f = self.date_from |
|
543 | month_f = self.date_from | |
524 | left = subject_width |
|
544 | left = subject_width | |
525 | height = header_height |
|
545 | height = header_height | |
526 | self.months.times do |
|
546 | self.months.times do | |
527 | width = ((month_f >> 1) - month_f) * zoom |
|
547 | width = ((month_f >> 1) - month_f) * zoom | |
528 | pdf.SetY(y_start) |
|
548 | pdf.SetY(y_start) | |
529 | pdf.SetX(left) |
|
549 | pdf.SetX(left) | |
530 | pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") |
|
550 | pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") | |
531 | left = left + width |
|
551 | left = left + width | |
532 | month_f = month_f >> 1 |
|
552 | month_f = month_f >> 1 | |
533 | end |
|
553 | end | |
534 | # Weeks headers |
|
554 | # Weeks headers | |
535 | if show_weeks |
|
555 | if show_weeks | |
536 | left = subject_width |
|
556 | left = subject_width | |
537 | height = header_height |
|
557 | height = header_height | |
538 | if self.date_from.cwday == 1 |
|
558 | if self.date_from.cwday == 1 | |
539 | # self.date_from is monday |
|
559 | # self.date_from is monday | |
540 | week_f = self.date_from |
|
560 | week_f = self.date_from | |
541 | else |
|
561 | else | |
542 | # find next monday after self.date_from |
|
562 | # find next monday after self.date_from | |
543 | week_f = self.date_from + (7 - self.date_from.cwday + 1) |
|
563 | week_f = self.date_from + (7 - self.date_from.cwday + 1) | |
544 | width = (7 - self.date_from.cwday + 1) * zoom-1 |
|
564 | width = (7 - self.date_from.cwday + 1) * zoom-1 | |
545 | pdf.SetY(y_start + header_height) |
|
565 | pdf.SetY(y_start + header_height) | |
546 | pdf.SetX(left) |
|
566 | pdf.SetX(left) | |
547 | pdf.RDMCell(width + 1, height, "", "LTR") |
|
567 | pdf.RDMCell(width + 1, height, "", "LTR") | |
548 | left = left + width + 1 |
|
568 | left = left + width + 1 | |
549 | end |
|
569 | end | |
550 | while week_f <= self.date_to |
|
570 | while week_f <= self.date_to | |
551 | width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom |
|
571 | width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom | |
552 | pdf.SetY(y_start + header_height) |
|
572 | pdf.SetY(y_start + header_height) | |
553 | pdf.SetX(left) |
|
573 | pdf.SetX(left) | |
554 | pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") |
|
574 | pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") | |
555 | left = left + width |
|
575 | left = left + width | |
556 | week_f = week_f + 7 |
|
576 | week_f = week_f + 7 | |
557 | end |
|
577 | end | |
558 | end |
|
578 | end | |
559 | # Days headers |
|
579 | # Days headers | |
560 | if show_days |
|
580 | if show_days | |
561 | left = subject_width |
|
581 | left = subject_width | |
562 | height = header_height |
|
582 | height = header_height | |
563 | wday = self.date_from.cwday |
|
583 | wday = self.date_from.cwday | |
564 | pdf.SetFontStyle('B', 7) |
|
584 | pdf.SetFontStyle('B', 7) | |
565 | (self.date_to - self.date_from + 1).to_i.times do |
|
585 | (self.date_to - self.date_from + 1).to_i.times do | |
566 | width = zoom |
|
586 | width = zoom | |
567 | pdf.SetY(y_start + 2 * header_height) |
|
587 | pdf.SetY(y_start + 2 * header_height) | |
568 | pdf.SetX(left) |
|
588 | pdf.SetX(left) | |
569 | pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C") |
|
589 | pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C") | |
570 | left = left + width |
|
590 | left = left + width | |
571 | wday = wday + 1 |
|
591 | wday = wday + 1 | |
572 | wday = 1 if wday > 7 |
|
592 | wday = 1 if wday > 7 | |
573 | end |
|
593 | end | |
574 | end |
|
594 | end | |
575 | pdf.SetY(y_start) |
|
595 | pdf.SetY(y_start) | |
576 | pdf.SetX(15) |
|
596 | pdf.SetX(15) | |
577 | pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1) |
|
597 | pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1) | |
578 | # Tasks |
|
598 | # Tasks | |
579 | top = headers_height + y_start |
|
599 | top = headers_height + y_start | |
580 | options = { |
|
600 | options = { | |
581 | :top => top, |
|
601 | :top => top, | |
582 | :zoom => zoom, |
|
602 | :zoom => zoom, | |
583 | :subject_width => subject_width, |
|
603 | :subject_width => subject_width, | |
584 | :g_width => g_width, |
|
604 | :g_width => g_width, | |
585 | :indent => 0, |
|
605 | :indent => 0, | |
586 | :indent_increment => 5, |
|
606 | :indent_increment => 5, | |
587 | :top_increment => 5, |
|
607 | :top_increment => 5, | |
588 | :format => :pdf, |
|
608 | :format => :pdf, | |
589 | :pdf => pdf |
|
609 | :pdf => pdf | |
590 | } |
|
610 | } | |
591 | render(options) |
|
611 | render(options) | |
592 | pdf.Output |
|
612 | pdf.Output | |
593 | end |
|
613 | end | |
594 |
|
614 | |||
595 | private |
|
615 | private | |
596 |
|
616 | |||
597 | def coordinates(start_date, end_date, progress, zoom=nil) |
|
617 | def coordinates(start_date, end_date, progress, zoom=nil) | |
598 | zoom ||= @zoom |
|
618 | zoom ||= @zoom | |
599 | coords = {} |
|
619 | coords = {} | |
600 | if start_date && end_date && start_date < self.date_to && end_date > self.date_from |
|
620 | if start_date && end_date && start_date < self.date_to && end_date > self.date_from | |
601 | if start_date > self.date_from |
|
621 | if start_date > self.date_from | |
602 | coords[:start] = start_date - self.date_from |
|
622 | coords[:start] = start_date - self.date_from | |
603 | coords[:bar_start] = start_date - self.date_from |
|
623 | coords[:bar_start] = start_date - self.date_from | |
604 | else |
|
624 | else | |
605 | coords[:bar_start] = 0 |
|
625 | coords[:bar_start] = 0 | |
606 | end |
|
626 | end | |
607 | if end_date < self.date_to |
|
627 | if end_date < self.date_to | |
608 | coords[:end] = end_date - self.date_from |
|
628 | coords[:end] = end_date - self.date_from | |
609 | coords[:bar_end] = end_date - self.date_from + 1 |
|
629 | coords[:bar_end] = end_date - self.date_from + 1 | |
610 | else |
|
630 | else | |
611 | coords[:bar_end] = self.date_to - self.date_from + 1 |
|
631 | coords[:bar_end] = self.date_to - self.date_from + 1 | |
612 | end |
|
632 | end | |
613 | if progress |
|
633 | if progress | |
614 | progress_date = start_date + (end_date - start_date + 1) * (progress / 100.0) |
|
634 | progress_date = start_date + (end_date - start_date + 1) * (progress / 100.0) | |
615 | if progress_date > self.date_from && progress_date > start_date |
|
635 | if progress_date > self.date_from && progress_date > start_date | |
616 | if progress_date < self.date_to |
|
636 | if progress_date < self.date_to | |
617 | coords[:bar_progress_end] = progress_date - self.date_from |
|
637 | coords[:bar_progress_end] = progress_date - self.date_from | |
618 | else |
|
638 | else | |
619 | coords[:bar_progress_end] = self.date_to - self.date_from + 1 |
|
639 | coords[:bar_progress_end] = self.date_to - self.date_from + 1 | |
620 | end |
|
640 | end | |
621 | end |
|
641 | end | |
622 | if progress_date < Date.today |
|
642 | if progress_date < Date.today | |
623 | late_date = [Date.today, end_date].min |
|
643 | late_date = [Date.today, end_date].min | |
624 | if late_date > self.date_from && late_date > start_date |
|
644 | if late_date > self.date_from && late_date > start_date | |
625 | if late_date < self.date_to |
|
645 | if late_date < self.date_to | |
626 | coords[:bar_late_end] = late_date - self.date_from + 1 |
|
646 | coords[:bar_late_end] = late_date - self.date_from + 1 | |
627 | else |
|
647 | else | |
628 | coords[:bar_late_end] = self.date_to - self.date_from + 1 |
|
648 | coords[:bar_late_end] = self.date_to - self.date_from + 1 | |
629 | end |
|
649 | end | |
630 | end |
|
650 | end | |
631 | end |
|
651 | end | |
632 | end |
|
652 | end | |
633 | end |
|
653 | end | |
634 | # Transforms dates into pixels witdh |
|
654 | # Transforms dates into pixels witdh | |
635 | coords.keys.each do |key| |
|
655 | coords.keys.each do |key| | |
636 | coords[key] = (coords[key] * zoom).floor |
|
656 | coords[key] = (coords[key] * zoom).floor | |
637 | end |
|
657 | end | |
638 | coords |
|
658 | coords | |
639 | end |
|
659 | end | |
640 |
|
660 | |||
641 | # Sorts a collection of issues by start_date, due_date, id for gantt rendering |
|
661 | # Sorts a collection of issues by start_date, due_date, id for gantt rendering | |
642 | def sort_issues!(issues) |
|
662 | def sort_issues!(issues) | |
643 | issues.sort! { |a, b| gantt_issue_compare(a, b) } |
|
663 | issues.sort! { |a, b| gantt_issue_compare(a, b) } | |
644 | end |
|
664 | end | |
645 |
|
665 | |||
646 | # TODO: top level issues should be sorted by start date |
|
666 | # TODO: top level issues should be sorted by start date | |
647 | def gantt_issue_compare(x, y) |
|
667 | def gantt_issue_compare(x, y) | |
648 | if x.root_id == y.root_id |
|
668 | if x.root_id == y.root_id | |
649 | x.lft <=> y.lft |
|
669 | x.lft <=> y.lft | |
650 | else |
|
670 | else | |
651 | x.root_id <=> y.root_id |
|
671 | x.root_id <=> y.root_id | |
652 | end |
|
672 | end | |
653 | end |
|
673 | end | |
654 |
|
674 | |||
655 | def current_limit |
|
675 | def current_limit | |
656 | if @max_rows |
|
676 | if @max_rows | |
657 | @max_rows - @number_of_rows |
|
677 | @max_rows - @number_of_rows | |
658 | else |
|
678 | else | |
659 | nil |
|
679 | nil | |
660 | end |
|
680 | end | |
661 | end |
|
681 | end | |
662 |
|
682 | |||
663 | def abort? |
|
683 | def abort? | |
664 | if @max_rows && @number_of_rows >= @max_rows |
|
684 | if @max_rows && @number_of_rows >= @max_rows | |
665 | @truncated = true |
|
685 | @truncated = true | |
666 | end |
|
686 | end | |
667 | end |
|
687 | end | |
668 |
|
688 | |||
669 | def pdf_new_page?(options) |
|
689 | def pdf_new_page?(options) | |
670 | if options[:top] > 180 |
|
690 | if options[:top] > 180 | |
671 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) |
|
691 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) | |
672 | options[:pdf].AddPage("L") |
|
692 | options[:pdf].AddPage("L") | |
673 | options[:top] = 15 |
|
693 | options[:top] = 15 | |
674 | options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) |
|
694 | options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) | |
675 | end |
|
695 | end | |
676 | end |
|
696 | end | |
677 |
|
697 | |||
678 | def html_subject(params, subject, options={}) |
|
698 | def html_subject(params, subject, options={}) | |
679 | style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;" |
|
699 | style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;" | |
680 | style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width] |
|
700 | style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width] | |
681 | output = view.content_tag('div', subject, |
|
701 | output = view.content_tag('div', subject, | |
682 | :class => options[:css], :style => style, |
|
702 | :class => options[:css], :style => style, | |
683 | :title => options[:title]) |
|
703 | :title => options[:title]) | |
684 | @subjects << output |
|
704 | @subjects << output | |
685 | output |
|
705 | output | |
686 | end |
|
706 | end | |
687 |
|
707 | |||
688 | def pdf_subject(params, subject, options={}) |
|
708 | def pdf_subject(params, subject, options={}) | |
689 | params[:pdf].SetY(params[:top]) |
|
709 | params[:pdf].SetY(params[:top]) | |
690 | params[:pdf].SetX(15) |
|
710 | params[:pdf].SetX(15) | |
691 | char_limit = PDF::MaxCharactorsForSubject - params[:indent] |
|
711 | char_limit = PDF::MaxCharactorsForSubject - params[:indent] | |
692 | params[:pdf].RDMCell(params[:subject_width] - 15, 5, |
|
712 | params[:pdf].RDMCell(params[:subject_width] - 15, 5, | |
693 | (" " * params[:indent]) + |
|
713 | (" " * params[:indent]) + | |
694 | subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), |
|
714 | subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), | |
695 | "LR") |
|
715 | "LR") | |
696 | params[:pdf].SetY(params[:top]) |
|
716 | params[:pdf].SetY(params[:top]) | |
697 | params[:pdf].SetX(params[:subject_width]) |
|
717 | params[:pdf].SetX(params[:subject_width]) | |
698 | params[:pdf].RDMCell(params[:g_width], 5, "", "LR") |
|
718 | params[:pdf].RDMCell(params[:g_width], 5, "", "LR") | |
699 | end |
|
719 | end | |
700 |
|
720 | |||
701 | def image_subject(params, subject, options={}) |
|
721 | def image_subject(params, subject, options={}) | |
702 | params[:image].fill('black') |
|
722 | params[:image].fill('black') | |
703 | params[:image].stroke('transparent') |
|
723 | params[:image].stroke('transparent') | |
704 | params[:image].stroke_width(1) |
|
724 | params[:image].stroke_width(1) | |
705 | params[:image].text(params[:indent], params[:top] + 2, subject) |
|
725 | params[:image].text(params[:indent], params[:top] + 2, subject) | |
706 | end |
|
726 | end | |
707 |
|
727 | |||
|
728 | def issue_relations(issue) | |||
|
729 | rels = {} | |||
|
730 | if relations[issue.id] | |||
|
731 | relations[issue.id].each do |relation| | |||
|
732 | (rels[relation.relation_type] ||= []) << relation.issue_to_id | |||
|
733 | end | |||
|
734 | end | |||
|
735 | rels | |||
|
736 | end | |||
|
737 | ||||
708 | def html_task(params, coords, options={}) |
|
738 | def html_task(params, coords, options={}) | |
709 | output = '' |
|
739 | output = '' | |
710 | # Renders the task bar, with progress and late |
|
740 | # Renders the task bar, with progress and late | |
711 | if coords[:bar_start] && coords[:bar_end] |
|
741 | if coords[:bar_start] && coords[:bar_end] | |
712 | width = coords[:bar_end] - coords[:bar_start] - 2 |
|
742 | width = coords[:bar_end] - coords[:bar_start] - 2 | |
713 | style = "" |
|
743 | style = "" | |
714 | style << "top:#{params[:top]}px;" |
|
744 | style << "top:#{params[:top]}px;" | |
715 | style << "left:#{coords[:bar_start]}px;" |
|
745 | style << "left:#{coords[:bar_start]}px;" | |
716 | style << "width:#{width}px;" |
|
746 | style << "width:#{width}px;" | |
717 | output << view.content_tag(:div, ' '.html_safe, |
|
747 | html_id = "task-todo-issue-#{options[:issue].id}" if options[:issue] | |
718 | :style => style, |
|
748 | content_opt = {:style => style, | |
719 |
|
|
749 | :class => "#{options[:css]} task_todo", | |
|
750 | :id => html_id} | |||
|
751 | if options[:issue] | |||
|
752 | rels_hash = {} | |||
|
753 | issue_relations(options[:issue]).each do |k, v| | |||
|
754 | rels_hash[k] = v.join(',') | |||
|
755 | end | |||
|
756 | content_opt[:data] = {"rels" => rels_hash} | |||
|
757 | end | |||
|
758 | output << view.content_tag(:div, ' '.html_safe, content_opt) | |||
720 | if coords[:bar_late_end] |
|
759 | if coords[:bar_late_end] | |
721 | width = coords[:bar_late_end] - coords[:bar_start] - 2 |
|
760 | width = coords[:bar_late_end] - coords[:bar_start] - 2 | |
722 | style = "" |
|
761 | style = "" | |
723 | style << "top:#{params[:top]}px;" |
|
762 | style << "top:#{params[:top]}px;" | |
724 | style << "left:#{coords[:bar_start]}px;" |
|
763 | style << "left:#{coords[:bar_start]}px;" | |
725 | style << "width:#{width}px;" |
|
764 | style << "width:#{width}px;" | |
726 | output << view.content_tag(:div, ' '.html_safe, |
|
765 | output << view.content_tag(:div, ' '.html_safe, | |
727 | :style => style, |
|
766 | :style => style, | |
728 | :class => "#{options[:css]} task_late") |
|
767 | :class => "#{options[:css]} task_late") | |
729 | end |
|
768 | end | |
730 | if coords[:bar_progress_end] |
|
769 | if coords[:bar_progress_end] | |
731 | width = coords[:bar_progress_end] - coords[:bar_start] - 2 |
|
770 | width = coords[:bar_progress_end] - coords[:bar_start] - 2 | |
732 | style = "" |
|
771 | style = "" | |
733 | style << "top:#{params[:top]}px;" |
|
772 | style << "top:#{params[:top]}px;" | |
734 | style << "left:#{coords[:bar_start]}px;" |
|
773 | style << "left:#{coords[:bar_start]}px;" | |
735 | style << "width:#{width}px;" |
|
774 | style << "width:#{width}px;" | |
736 | output << view.content_tag(:div, ' '.html_safe, |
|
775 | output << view.content_tag(:div, ' '.html_safe, | |
737 | :style => style, |
|
776 | :style => style, | |
738 | :class => "#{options[:css]} task_done") |
|
777 | :class => "#{options[:css]} task_done") | |
739 | end |
|
778 | end | |
740 | end |
|
779 | end | |
741 | # Renders the markers |
|
780 | # Renders the markers | |
742 | if options[:markers] |
|
781 | if options[:markers] | |
743 | if coords[:start] |
|
782 | if coords[:start] | |
744 | style = "" |
|
783 | style = "" | |
745 | style << "top:#{params[:top]}px;" |
|
784 | style << "top:#{params[:top]}px;" | |
746 | style << "left:#{coords[:start]}px;" |
|
785 | style << "left:#{coords[:start]}px;" | |
747 | style << "width:15px;" |
|
786 | style << "width:15px;" | |
748 | output << view.content_tag(:div, ' '.html_safe, |
|
787 | output << view.content_tag(:div, ' '.html_safe, | |
749 | :style => style, |
|
788 | :style => style, | |
750 | :class => "#{options[:css]} marker starting") |
|
789 | :class => "#{options[:css]} marker starting") | |
751 | end |
|
790 | end | |
752 | if coords[:end] |
|
791 | if coords[:end] | |
753 | style = "" |
|
792 | style = "" | |
754 | style << "top:#{params[:top]}px;" |
|
793 | style << "top:#{params[:top]}px;" | |
755 | style << "left:#{coords[:end] + params[:zoom]}px;" |
|
794 | style << "left:#{coords[:end] + params[:zoom]}px;" | |
756 | style << "width:15px;" |
|
795 | style << "width:15px;" | |
757 | output << view.content_tag(:div, ' '.html_safe, |
|
796 | output << view.content_tag(:div, ' '.html_safe, | |
758 | :style => style, |
|
797 | :style => style, | |
759 | :class => "#{options[:css]} marker ending") |
|
798 | :class => "#{options[:css]} marker ending") | |
760 | end |
|
799 | end | |
761 | end |
|
800 | end | |
762 | # Renders the label on the right |
|
801 | # Renders the label on the right | |
763 | if options[:label] |
|
802 | if options[:label] | |
764 | style = "" |
|
803 | style = "" | |
765 | style << "top:#{params[:top]}px;" |
|
804 | style << "top:#{params[:top]}px;" | |
766 | style << "left:#{(coords[:bar_end] || 0) + 8}px;" |
|
805 | style << "left:#{(coords[:bar_end] || 0) + 8}px;" | |
767 | style << "width:15px;" |
|
806 | style << "width:15px;" | |
768 | output << view.content_tag(:div, options[:label], |
|
807 | output << view.content_tag(:div, options[:label], | |
769 | :style => style, |
|
808 | :style => style, | |
770 | :class => "#{options[:css]} label") |
|
809 | :class => "#{options[:css]} label") | |
771 | end |
|
810 | end | |
772 | # Renders the tooltip |
|
811 | # Renders the tooltip | |
773 | if options[:issue] && coords[:bar_start] && coords[:bar_end] |
|
812 | if options[:issue] && coords[:bar_start] && coords[:bar_end] | |
774 | s = view.content_tag(:span, |
|
813 | s = view.content_tag(:span, | |
775 | view.render_issue_tooltip(options[:issue]).html_safe, |
|
814 | view.render_issue_tooltip(options[:issue]).html_safe, | |
776 | :class => "tip") |
|
815 | :class => "tip") | |
777 | style = "" |
|
816 | style = "" | |
778 | style << "position: absolute;" |
|
817 | style << "position: absolute;" | |
779 | style << "top:#{params[:top]}px;" |
|
818 | style << "top:#{params[:top]}px;" | |
780 | style << "left:#{coords[:bar_start]}px;" |
|
819 | style << "left:#{coords[:bar_start]}px;" | |
781 | style << "width:#{coords[:bar_end] - coords[:bar_start]}px;" |
|
820 | style << "width:#{coords[:bar_end] - coords[:bar_start]}px;" | |
782 | style << "height:12px;" |
|
821 | style << "height:12px;" | |
783 | output << view.content_tag(:div, s.html_safe, |
|
822 | output << view.content_tag(:div, s.html_safe, | |
784 | :style => style, |
|
823 | :style => style, | |
785 | :class => "tooltip") |
|
824 | :class => "tooltip") | |
786 | end |
|
825 | end | |
787 | @lines << output |
|
826 | @lines << output | |
788 | output |
|
827 | output | |
789 | end |
|
828 | end | |
790 |
|
829 | |||
791 | def pdf_task(params, coords, options={}) |
|
830 | def pdf_task(params, coords, options={}) | |
792 | height = options[:height] || 2 |
|
831 | height = options[:height] || 2 | |
793 | # Renders the task bar, with progress and late |
|
832 | # Renders the task bar, with progress and late | |
794 | if coords[:bar_start] && coords[:bar_end] |
|
833 | if coords[:bar_start] && coords[:bar_end] | |
795 | params[:pdf].SetY(params[:top] + 1.5) |
|
834 | params[:pdf].SetY(params[:top] + 1.5) | |
796 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
835 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
797 | params[:pdf].SetFillColor(200, 200, 200) |
|
836 | params[:pdf].SetFillColor(200, 200, 200) | |
798 | params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
837 | params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
799 | if coords[:bar_late_end] |
|
838 | if coords[:bar_late_end] | |
800 | params[:pdf].SetY(params[:top] + 1.5) |
|
839 | params[:pdf].SetY(params[:top] + 1.5) | |
801 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
840 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
802 | params[:pdf].SetFillColor(255, 100, 100) |
|
841 | params[:pdf].SetFillColor(255, 100, 100) | |
803 | params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
842 | params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
804 | end |
|
843 | end | |
805 | if coords[:bar_progress_end] |
|
844 | if coords[:bar_progress_end] | |
806 | params[:pdf].SetY(params[:top] + 1.5) |
|
845 | params[:pdf].SetY(params[:top] + 1.5) | |
807 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
846 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
808 | params[:pdf].SetFillColor(90, 200, 90) |
|
847 | params[:pdf].SetFillColor(90, 200, 90) | |
809 | params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
848 | params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
810 | end |
|
849 | end | |
811 | end |
|
850 | end | |
812 | # Renders the markers |
|
851 | # Renders the markers | |
813 | if options[:markers] |
|
852 | if options[:markers] | |
814 | if coords[:start] |
|
853 | if coords[:start] | |
815 | params[:pdf].SetY(params[:top] + 1) |
|
854 | params[:pdf].SetY(params[:top] + 1) | |
816 | params[:pdf].SetX(params[:subject_width] + coords[:start] - 1) |
|
855 | params[:pdf].SetX(params[:subject_width] + coords[:start] - 1) | |
817 | params[:pdf].SetFillColor(50, 50, 200) |
|
856 | params[:pdf].SetFillColor(50, 50, 200) | |
818 | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) |
|
857 | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) | |
819 | end |
|
858 | end | |
820 | if coords[:end] |
|
859 | if coords[:end] | |
821 | params[:pdf].SetY(params[:top] + 1) |
|
860 | params[:pdf].SetY(params[:top] + 1) | |
822 | params[:pdf].SetX(params[:subject_width] + coords[:end] - 1) |
|
861 | params[:pdf].SetX(params[:subject_width] + coords[:end] - 1) | |
823 | params[:pdf].SetFillColor(50, 50, 200) |
|
862 | params[:pdf].SetFillColor(50, 50, 200) | |
824 | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) |
|
863 | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) | |
825 | end |
|
864 | end | |
826 | end |
|
865 | end | |
827 | # Renders the label on the right |
|
866 | # Renders the label on the right | |
828 | if options[:label] |
|
867 | if options[:label] | |
829 | params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5) |
|
868 | params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5) | |
830 | params[:pdf].RDMCell(30, 2, options[:label]) |
|
869 | params[:pdf].RDMCell(30, 2, options[:label]) | |
831 | end |
|
870 | end | |
832 | end |
|
871 | end | |
833 |
|
872 | |||
834 | def image_task(params, coords, options={}) |
|
873 | def image_task(params, coords, options={}) | |
835 | height = options[:height] || 6 |
|
874 | height = options[:height] || 6 | |
836 | # Renders the task bar, with progress and late |
|
875 | # Renders the task bar, with progress and late | |
837 | if coords[:bar_start] && coords[:bar_end] |
|
876 | if coords[:bar_start] && coords[:bar_end] | |
838 | params[:image].fill('#aaa') |
|
877 | params[:image].fill('#aaa') | |
839 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
|
878 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], | |
840 | params[:top], |
|
879 | params[:top], | |
841 | params[:subject_width] + coords[:bar_end], |
|
880 | params[:subject_width] + coords[:bar_end], | |
842 | params[:top] - height) |
|
881 | params[:top] - height) | |
843 | if coords[:bar_late_end] |
|
882 | if coords[:bar_late_end] | |
844 | params[:image].fill('#f66') |
|
883 | params[:image].fill('#f66') | |
845 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
|
884 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], | |
846 | params[:top], |
|
885 | params[:top], | |
847 | params[:subject_width] + coords[:bar_late_end], |
|
886 | params[:subject_width] + coords[:bar_late_end], | |
848 | params[:top] - height) |
|
887 | params[:top] - height) | |
849 | end |
|
888 | end | |
850 | if coords[:bar_progress_end] |
|
889 | if coords[:bar_progress_end] | |
851 | params[:image].fill('#00c600') |
|
890 | params[:image].fill('#00c600') | |
852 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
|
891 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], | |
853 | params[:top], |
|
892 | params[:top], | |
854 | params[:subject_width] + coords[:bar_progress_end], |
|
893 | params[:subject_width] + coords[:bar_progress_end], | |
855 | params[:top] - height) |
|
894 | params[:top] - height) | |
856 | end |
|
895 | end | |
857 | end |
|
896 | end | |
858 | # Renders the markers |
|
897 | # Renders the markers | |
859 | if options[:markers] |
|
898 | if options[:markers] | |
860 | if coords[:start] |
|
899 | if coords[:start] | |
861 | x = params[:subject_width] + coords[:start] |
|
900 | x = params[:subject_width] + coords[:start] | |
862 | y = params[:top] - height / 2 |
|
901 | y = params[:top] - height / 2 | |
863 | params[:image].fill('blue') |
|
902 | params[:image].fill('blue') | |
864 | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) |
|
903 | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) | |
865 | end |
|
904 | end | |
866 | if coords[:end] |
|
905 | if coords[:end] | |
867 | x = params[:subject_width] + coords[:end] + params[:zoom] |
|
906 | x = params[:subject_width] + coords[:end] + params[:zoom] | |
868 | y = params[:top] - height / 2 |
|
907 | y = params[:top] - height / 2 | |
869 | params[:image].fill('blue') |
|
908 | params[:image].fill('blue') | |
870 | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) |
|
909 | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) | |
871 | end |
|
910 | end | |
872 | end |
|
911 | end | |
873 | # Renders the label on the right |
|
912 | # Renders the label on the right | |
874 | if options[:label] |
|
913 | if options[:label] | |
875 | params[:image].fill('black') |
|
914 | params[:image].fill('black') | |
876 | params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5, |
|
915 | params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5, | |
877 | params[:top] + 1, |
|
916 | params[:top] + 1, | |
878 | options[:label]) |
|
917 | options[:label]) | |
879 | end |
|
918 | end | |
880 | end |
|
919 | end | |
881 | end |
|
920 | end | |
882 | end |
|
921 | end | |
883 | end |
|
922 | end |
@@ -1,107 +1,123 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class GanttsControllerTest < ActionController::TestCase |
|
20 | class GanttsControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
22 | :enumerations, :users, :issue_categories, |
|
22 | :enumerations, :users, :issue_categories, | |
23 | :projects_trackers, |
|
23 | :projects_trackers, | |
24 | :roles, |
|
24 | :roles, | |
25 | :member_roles, |
|
25 | :member_roles, | |
26 | :members, |
|
26 | :members, | |
27 | :enabled_modules, |
|
27 | :enabled_modules, | |
28 | :workflows, |
|
28 | :workflows, | |
29 | :versions |
|
29 | :versions | |
30 |
|
30 | |||
31 | def test_gantt_should_work |
|
31 | def test_gantt_should_work | |
32 | i2 = Issue.find(2) |
|
32 | i2 = Issue.find(2) | |
33 | i2.update_attribute(:due_date, 1.month.from_now) |
|
33 | i2.update_attribute(:due_date, 1.month.from_now) | |
34 | get :show, :project_id => 1 |
|
34 | get :show, :project_id => 1 | |
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_template 'gantts/show' |
|
36 | assert_template 'gantts/show' | |
37 | assert_not_nil assigns(:gantt) |
|
37 | assert_not_nil assigns(:gantt) | |
38 | # Issue with start and due dates |
|
38 | # Issue with start and due dates | |
39 | i = Issue.find(1) |
|
39 | i = Issue.find(1) | |
40 | assert_not_nil i.due_date |
|
40 | assert_not_nil i.due_date | |
41 | assert_select "div a.issue", /##{i.id}/ |
|
41 | assert_select "div a.issue", /##{i.id}/ | |
42 | # Issue with on a targeted version should not be in the events but loaded in the html |
|
42 | # Issue with on a targeted version should not be in the events but loaded in the html | |
43 | i = Issue.find(2) |
|
43 | i = Issue.find(2) | |
44 | assert_select "div a.issue", /##{i.id}/ |
|
44 | assert_select "div a.issue", /##{i.id}/ | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def test_gantt_should_work_without_issue_due_dates |
|
47 | def test_gantt_should_work_without_issue_due_dates | |
48 | Issue.update_all("due_date = NULL") |
|
48 | Issue.update_all("due_date = NULL") | |
49 | get :show, :project_id => 1 |
|
49 | get :show, :project_id => 1 | |
50 | assert_response :success |
|
50 | assert_response :success | |
51 | assert_template 'gantts/show' |
|
51 | assert_template 'gantts/show' | |
52 | assert_not_nil assigns(:gantt) |
|
52 | assert_not_nil assigns(:gantt) | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_gantt_should_work_without_issue_and_version_due_dates |
|
55 | def test_gantt_should_work_without_issue_and_version_due_dates | |
56 | Issue.update_all("due_date = NULL") |
|
56 | Issue.update_all("due_date = NULL") | |
57 | Version.update_all("effective_date = NULL") |
|
57 | Version.update_all("effective_date = NULL") | |
58 | get :show, :project_id => 1 |
|
58 | get :show, :project_id => 1 | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'gantts/show' |
|
60 | assert_template 'gantts/show' | |
61 | assert_not_nil assigns(:gantt) |
|
61 | assert_not_nil assigns(:gantt) | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_gantt_should_work_cross_project |
|
64 | def test_gantt_should_work_cross_project | |
65 | get :show |
|
65 | get :show | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_template 'gantts/show' |
|
67 | assert_template 'gantts/show' | |
68 | assert_not_nil assigns(:gantt) |
|
68 | assert_not_nil assigns(:gantt) | |
69 | assert_not_nil assigns(:gantt).query |
|
69 | assert_not_nil assigns(:gantt).query | |
70 | assert_nil assigns(:gantt).project |
|
70 | assert_nil assigns(:gantt).project | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_gantt_should_not_disclose_private_projects |
|
73 | def test_gantt_should_not_disclose_private_projects | |
74 | get :show |
|
74 | get :show | |
75 | assert_response :success |
|
75 | assert_response :success | |
76 | assert_template 'gantts/show' |
|
76 | assert_template 'gantts/show' | |
77 | assert_tag 'a', :content => /eCookbook/ |
|
77 | assert_tag 'a', :content => /eCookbook/ | |
78 | # Root private project |
|
78 | # Root private project | |
79 | assert_no_tag 'a', {:content => /OnlineStore/} |
|
79 | assert_no_tag 'a', {:content => /OnlineStore/} | |
80 | # Private children of a public project |
|
80 | # Private children of a public project | |
81 | assert_no_tag 'a', :content => /Private child of eCookbook/ |
|
81 | assert_no_tag 'a', :content => /Private child of eCookbook/ | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
|
84 | def test_gantt_should_display_relations | |||
|
85 | IssueRelation.delete_all | |||
|
86 | issue1 = Issue.generate!(:start_date => 1.day.from_now, :due_date => 3.day.from_now) | |||
|
87 | issue2 = Issue.generate!(:start_date => 1.day.from_now, :due_date => 3.day.from_now) | |||
|
88 | IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => 'precedes') | |||
|
89 | ||||
|
90 | get :show | |||
|
91 | assert_response :success | |||
|
92 | ||||
|
93 | relations = assigns(:gantt).relations | |||
|
94 | assert_kind_of Hash, relations | |||
|
95 | assert relations.present? | |||
|
96 | assert_select 'div.task_todo[id=?][data-rels*=?]', "task-todo-issue-#{issue1.id}", issue2.id.to_s | |||
|
97 | assert_select 'div.task_todo[id=?][data-rels=?]', "task-todo-issue-#{issue2.id}", '{}' | |||
|
98 | end | |||
|
99 | ||||
84 | def test_gantt_should_export_to_pdf |
|
100 | def test_gantt_should_export_to_pdf | |
85 | get :show, :project_id => 1, :format => 'pdf' |
|
101 | get :show, :project_id => 1, :format => 'pdf' | |
86 | assert_response :success |
|
102 | assert_response :success | |
87 | assert_equal 'application/pdf', @response.content_type |
|
103 | assert_equal 'application/pdf', @response.content_type | |
88 | assert @response.body.starts_with?('%PDF') |
|
104 | assert @response.body.starts_with?('%PDF') | |
89 | assert_not_nil assigns(:gantt) |
|
105 | assert_not_nil assigns(:gantt) | |
90 | end |
|
106 | end | |
91 |
|
107 | |||
92 | def test_gantt_should_export_to_pdf_cross_project |
|
108 | def test_gantt_should_export_to_pdf_cross_project | |
93 | get :show, :format => 'pdf' |
|
109 | get :show, :format => 'pdf' | |
94 | assert_response :success |
|
110 | assert_response :success | |
95 | assert_equal 'application/pdf', @response.content_type |
|
111 | assert_equal 'application/pdf', @response.content_type | |
96 | assert @response.body.starts_with?('%PDF') |
|
112 | assert @response.body.starts_with?('%PDF') | |
97 | assert_not_nil assigns(:gantt) |
|
113 | assert_not_nil assigns(:gantt) | |
98 | end |
|
114 | end | |
99 |
|
115 | |||
100 | if Object.const_defined?(:Magick) |
|
116 | if Object.const_defined?(:Magick) | |
101 | def test_gantt_should_export_to_png |
|
117 | def test_gantt_should_export_to_png | |
102 | get :show, :project_id => 1, :format => 'png' |
|
118 | get :show, :project_id => 1, :format => 'png' | |
103 | assert_response :success |
|
119 | assert_response :success | |
104 | assert_equal 'image/png', @response.content_type |
|
120 | assert_equal 'image/png', @response.content_type | |
105 | end |
|
121 | end | |
106 | end |
|
122 | end | |
107 | end |
|
123 | end |
General Comments 0
You need to be logged in to leave comments.
Login now