1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/* Redmine - project management software
Copyright (C) 2006-2023 Jean-Philippe Lang */
var draw_gantt = null;
var draw_top;
var draw_right;
var draw_left;
var rels_stroke_width = 2;
function setDrawArea() {
draw_top = $("#gantt_draw_area").position().top;
draw_right = $("#gantt_draw_area").width();
draw_left = $("#gantt_area").scrollLeft();
}
function getRelationsArray() {
var arr = new Array();
$.each($('div.task_todo[data-rels]'), function(index_div, element) {
if(!$(element).is(':visible')) return true;
var element_id = $(element).attr("id");
if (element_id != null) {
var issue_id = element_id.replace("task-todo-issue-", "");
var data_rels = $(element).data("rels");
for (rel_type_key in data_rels) {
$.each(data_rels[rel_type_key], function(index_issue, element_issue) {
arr.push({issue_from: issue_id, issue_to: element_issue,
rel_type: rel_type_key});
});
}
}
});
return arr;
}
function drawRelations() {
var arr = getRelationsArray();
$.each(arr, function(index_issue, element_issue) {
var issue_from = $("#task-todo-issue-" + element_issue["issue_from"]);
var issue_to = $("#task-todo-issue-" + element_issue["issue_to"]);
if (issue_from.length == 0 || issue_to.length == 0) {
return;
}
var issue_height = issue_from.height();
var issue_from_top = issue_from.position().top + (issue_height / 2) - draw_top;
var issue_from_right = issue_from.position().left + issue_from.width();
var issue_to_top = issue_to.position().top + (issue_height / 2) - draw_top;
var issue_to_left = issue_to.position().left;
var color = issue_relation_type[element_issue["rel_type"]]["color"];
var landscape_margin = issue_relation_type[element_issue["rel_type"]]["landscape_margin"];
var issue_from_right_rel = issue_from_right + landscape_margin;
var issue_to_left_rel = issue_to_left - landscape_margin;
draw_gantt.path(["M", issue_from_right + draw_left, issue_from_top,
"L", issue_from_right_rel + draw_left, issue_from_top])
.attr({stroke: color,
"stroke-width": rels_stroke_width
});
if (issue_from_right_rel < issue_to_left_rel) {
draw_gantt.path(["M", issue_from_right_rel + draw_left, issue_from_top,
"L", issue_from_right_rel + draw_left, issue_to_top])
.attr({stroke: color,
"stroke-width": rels_stroke_width
});
draw_gantt.path(["M", issue_from_right_rel + draw_left, issue_to_top,
"L", issue_to_left + draw_left, issue_to_top])
.attr({stroke: color,
"stroke-width": rels_stroke_width
});
} else {
var issue_middle_top = issue_to_top +
(issue_height *
((issue_from_top > issue_to_top) ? 1 : -1));
draw_gantt.path(["M", issue_from_right_rel + draw_left, issue_from_top,
"L", issue_from_right_rel + draw_left, issue_middle_top])
.attr({stroke: color,
"stroke-width": rels_stroke_width
});
draw_gantt.path(["M", issue_from_right_rel + draw_left, issue_middle_top,
"L", issue_to_left_rel + draw_left, issue_middle_top])
.attr({stroke: color,
"stroke-width": rels_stroke_width
});
draw_gantt.path(["M", issue_to_left_rel + draw_left, issue_middle_top,
"L", issue_to_left_rel + draw_left, issue_to_top])
.attr({stroke: color,
"stroke-width": rels_stroke_width
});
draw_gantt.path(["M", issue_to_left_rel + draw_left, issue_to_top,
"L", issue_to_left + draw_left, issue_to_top])
.attr({stroke: color,
"stroke-width": rels_stroke_width
});
}
draw_gantt.path(["M", issue_to_left + draw_left, issue_to_top,
"l", -4 * rels_stroke_width, -2 * rels_stroke_width,
"l", 0, 4 * rels_stroke_width, "z"])
.attr({stroke: "none",
fill: color,
"stroke-linecap": "butt",
"stroke-linejoin": "miter"
});
});
}
function getProgressLinesArray() {
var arr = new Array();
var today_left = $('#today_line').position().left;
arr.push({left: today_left, top: 0});
$.each($('div.issue-subject, div.version-name'), function(index, element) {
if(!$(element).is(':visible')) return true;
var t = $(element).position().top - draw_top ;
var h = ($(element).height() / 9);
var element_top_upper = t - h;
var element_top_center = t + (h * 3);
var element_top_lower = t + (h * 8);
var issue_closed = $(element).children('span').hasClass('issue-closed');
var version_closed = $(element).children('span').hasClass('version-closed');
if (issue_closed || version_closed) {
arr.push({left: today_left, top: element_top_center});
} else {
var issue_done = $("#task-done-" + $(element).attr("id"));
var is_behind_start = $(element).children('span').hasClass('behind-start-date');
var is_over_end = $(element).children('span').hasClass('over-end-date');
if (is_over_end) {
arr.push({left: draw_right, top: element_top_upper, is_right_edge: true});
arr.push({left: draw_right, top: element_top_lower, is_right_edge: true, none_stroke: true});
} else if (issue_done.length > 0) {
var done_left = issue_done.first().position().left +
issue_done.first().width();
arr.push({left: done_left, top: element_top_center});
} else if (is_behind_start) {
arr.push({left: 0 , top: element_top_upper, is_left_edge: true});
arr.push({left: 0 , top: element_top_lower, is_left_edge: true, none_stroke: true});
} else {
var todo_left = today_left;
var issue_todo = $("#task-todo-" + $(element).attr("id"));
if (issue_todo.length > 0){
todo_left = issue_todo.first().position().left;
}
arr.push({left: Math.min(today_left, todo_left), top: element_top_center});
}
}
});
return arr;
}
function drawGanttProgressLines() {
var arr = getProgressLinesArray();
var color = $("#today_line")
.css("border-left-color");
var i;
for(i = 1 ; i < arr.length ; i++) {
if (!("none_stroke" in arr[i]) &&
(!("is_right_edge" in arr[i - 1] && "is_right_edge" in arr[i]) &&
!("is_left_edge" in arr[i - 1] && "is_left_edge" in arr[i]))
) {
var x1 = (arr[i - 1].left == 0) ? 0 : arr[i - 1].left + draw_left;
var x2 = (arr[i].left == 0) ? 0 : arr[i].left + draw_left;
draw_gantt.path(["M", x1, arr[i - 1].top,
"L", x2, arr[i].top])
.attr({stroke: color, "stroke-width": 2});
}
}
}
function drawSelectedColumns(){
if ($("#draw_selected_columns").prop('checked')) {
if(isMobile()) {
$('td.gantt_selected_column').each(function(i) {
$(this).hide();
});
}else{
$('.gantt_subjects_container').addClass('draw_selected_columns');
$('td.gantt_selected_column').each(function() {
$(this).show();
var column_name = $(this).attr('id');
$(this).resizable({
alsoResize: '.gantt_' + column_name + '_container, .gantt_' + column_name + '_container > .gantt_hdr',
minWidth: 20,
handles: "e",
create: function() {
$(".ui-resizable-e").css("cursor","ew-resize");
}
}).on('resize', function (e) {
e.stopPropagation();
});
});
}
}else{
$('td.gantt_selected_column').each(function (i) {
$(this).hide();
$('.gantt_subjects_container').removeClass('draw_selected_columns');
});
}
}
function drawGanttHandler() {
var folder = document.getElementById('gantt_draw_area');
if(draw_gantt != null)
draw_gantt.clear();
else
draw_gantt = Raphael(folder);
setDrawArea();
drawSelectedColumns();
if ($("#draw_progress_line").prop('checked'))
try{drawGanttProgressLines();}catch(e){}
if ($("#draw_relations").prop('checked'))
drawRelations();
$('#content').addClass('gantt_content');
}
function resizableSubjectColumn(){
$('.issue-subject, .project-name, .version-name').each(function(){
$(this).width($(".gantt_subjects_column").width()-$(this).position().left);
});
$('td.gantt_subjects_column').resizable({
alsoResize: '.gantt_subjects_container, .gantt_subjects_container>.gantt_hdr, .project-name, .issue-subject, .version-name',
minWidth: 100,
handles: 'e',
create: function( event, ui ) {
$('.ui-resizable-e').css('cursor','ew-resize');
}
}).on('resize', function (e) {
e.stopPropagation();
});
if(isMobile()) {
$('td.gantt_subjects_column').resizable('disable');
}else{
$('td.gantt_subjects_column').resizable('enable');
};
}
ganttEntryClick = function(e){
var icon_expander = e.target;
var subject = $(icon_expander.parentElement);
var subject_left = parseInt(subject.css('left')) + parseInt(icon_expander.offsetWidth);
var target_shown = null;
var target_top = 0;
var total_height = 0;
var out_of_hierarchy = false;
var iconChange = null;
if(subject.hasClass('open'))
iconChange = function(element){
$(element).find('.expander').switchClass('icon-expended', 'icon-collapsed');
$(element).removeClass('open');
};
else
iconChange = function(element){
$(element).find('.expander').switchClass('icon-collapsed', 'icon-expended');
$(element).addClass('open');
};
iconChange(subject);
subject.nextAll('div').each(function(_, element){
var el = $(element);
var json = el.data('collapse-expand');
var number_of_rows = el.data('number-of-rows');
var el_task_bars = '#gantt_area form > div[data-collapse-expand="' + json.obj_id + '"][data-number-of-rows="' + number_of_rows + '"]';
var el_selected_columns = 'td.gantt_selected_column div[data-collapse-expand="' + json.obj_id + '"][data-number-of-rows="' + number_of_rows + '"]';
if(out_of_hierarchy || parseInt(el.css('left')) <= subject_left){
out_of_hierarchy = true;
if(target_shown == null) return false;
var new_top_val = parseInt(el.css('top')) + total_height * (target_shown ? -1 : 1);
el.css('top', new_top_val);
$([el_task_bars, el_selected_columns].join()).each(function(_, el){
$(el).css('top', new_top_val);
});
return true;
}
var is_shown = el.is(':visible');
if(target_shown == null){
target_shown = is_shown;
target_top = parseInt(el.css('top'));
total_height = 0;
}
if(is_shown == target_shown){
$(el_task_bars).each(function(_, task) {
var el_task = $(task);
if(!is_shown)
el_task.css('top', target_top + total_height);
if(!el_task.hasClass('tooltip'))
el_task.toggle(!is_shown);
});
$(el_selected_columns).each(function (_, attr) {
var el_attr = $(attr);
if (!is_shown)
el_attr.css('top', target_top + total_height);
el_attr.toggle(!is_shown);
});
if(!is_shown)
el.css('top', target_top + total_height);
iconChange(el);
el.toggle(!is_shown);
total_height += parseInt(json.top_increment);
}
});
drawGanttHandler();
};
function disable_unavailable_columns(unavailable_columns) {
$.each(unavailable_columns, function (index, value) {
$('#available_c, #selected_c').children("[value='" + value + "']").prop('disabled', true);
});
}
|