-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.html
303 lines (280 loc) · 9.58 KB
/
index.html
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
<!DOCTYPE html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
</head>
<script src="/static/dhtmlxgantt.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/ext/dhtmlxgantt_marker.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/ext/dhtmlxgantt_tooltip.js"></script>
<link rel="stylesheet" href="/static/skins/dhtmlxgantt_broadway.css" type="text/css" charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style type="text/css">
html, body {
height:100%;
padding:0px;
margin:0px;
overflow: hidden;
}
.weekend{
background: #BD7990!important;
color:white !important;
}
.buttonload {
background-color: #4CAF50;
border: none;
color: white;
width: 120px;
height: 100%;
font-size: 16px;
outline:none;
}
.fa {
margin-left: -12px;
margin-right: 8px;
}
.today_line {
background-color: #2b2b2b;
}
.status_line{
background-color: #0ca30a;
}
#container {
height: 40px;
width: 100%;
display: flex;
}
#legend {
height: 40px;
width: -moz-calc(100% - 120px);
width: -webkit-calc(100% - 120px);
width: -o-calc(100% - 120px);
width: calc(100% - 120px);
border-spacing:5px;
display: table;
color: white;
}
#legendItem {
display:table-cell;
text-align: center;
vertical-align: middle;
font: 14px system-ui;
width: 1%;
white-space: nowrap;
}
</style>
<body onresize="zoomToFit()">
<div id="container">
<div id="legend">
</div>
<div style="text-align: right;">
<button class="buttonload" onclick="refresh(this)" id="refreshButton">
Refresh
</button>
</div>
</div>
<div id="gantt_here" style='position: absolute;top: 40px;bottom: 0px;right: 0px;left: 0px;'></div>
<script type="text/javascript">
var HttpClient = function() {
this.get = function(aUrl, aCallback) {
var anHttpRequest = new XMLHttpRequest();
anHttpRequest.onreadystatechange = function() {
if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200)
aCallback(anHttpRequest.responseText);
}
anHttpRequest.open("GET", aUrl, true);
anHttpRequest.send(null);
}
this.postObject = function(aUrl, object, aCallback) {
var anHttpRequest = new XMLHttpRequest();
anHttpRequest.onreadystatechange = function() {
if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200)
aCallback(anHttpRequest.responseText);
}
anHttpRequest.open("POST", aUrl, true);
anHttpRequest.setRequestHeader('Content-Type', 'application/json');
anHttpRequest.send(JSON.stringify(object));
}
};
var client = new HttpClient();
gantt.config.xml_date = "%m-%d-%Y";
gantt.config.drag_links = false;
gantt.config.grid_width = 0;
gantt.config.columns = [
{name:"text",
label:"Task name",
tree:true,
width:'*' },
];
gantt.attachEvent("onTaskClick", function(id, e) {
var task = gantt.getTask(id);
var newWin = window.open(task.htmlUrl, '_blank');
});
gantt.attachEvent("onAfterTaskDrag", function(id, mode, e){
var task = gantt.getTask(id);
client.postObject("/updateIssue", task, function(response) {
console.log(response);
});
});
gantt.config.scale_unit = "week";
gantt.config.date_scale = "%F, %d";
gantt.config.subscales = [
{unit:"month", step:1, date:"%M"}
];
gantt.config.scale_height = 54;
gantt.attachEvent("onLoadStart", function(){
client.get('/additionalData', function(response) {
let data = JSON.parse(response);
// Handle Milestones
let milestones = data.milestones;
for (index in milestones) {
let milestone = JSON.parse(milestones[index]);
let date = new Date(milestone.dueOn);
gantt.addMarker({
start_date: date,
css: "status_line",
text: milestone.title,
title: milestone.description});
}
var date_to_str = gantt.date.date_to_str(gantt.config.task_date);
var today = new Date();
gantt.addMarker({ start_date: today, css: "today_line", text: "Today", title:date_to_str(today)});
gantt.renderMarkers();
// Handle labels
var legend = document.getElementById("legend");
while (legend.hasChildNodes()) {
legend.removeChild(legend.lastChild);
}
let labels = data.labels;
for (index in labels) {
let label = labels[index];
var div = document.createElement("DIV");
div.id = "legendItem";
div.innerHTML = label.name;
div.style.backgroundColor = label.color;
legend.appendChild(div);
}
});
});
gantt.init("gantt_here");
gantt.load("/data");
refresh(document.getElementById("refreshButton"));
function refresh(element) {
element.innerHTML = '<i class="fa fa-refresh fa-spin"></i>Working';
client.get("/refreshData", function(response) {
gantt.clearAll();
gantt.load("/data");
element.innerText = "Refresh";
});
};
function zoomToFit() {
var project = gantt.getSubtaskDates();
var areaWidth = gantt.$task.offsetWidth;
for (var i = 0; i < scaleConfigs.length; i++) {
var columnCount = getUnitsBetween(project.start_date, project.end_date, scaleConfigs[i].unit, scaleConfigs[i].step);
if ((columnCount + 2) * gantt.config.min_column_width <= areaWidth) {
break;
}
}
if (i == scaleConfigs.length) {
i--;
}
applyConfig(scaleConfigs[i], project);
gantt.render();
};
// Zoom to fit functionality
function applyConfig(config, dates) {
gantt.config.scale_unit = config.scale_unit;
if (config.date_scale) {
gantt.config.date_scale = config.date_scale;
gantt.templates.date_scale = null;
}
else {
gantt.templates.date_scale = config.template;
}
gantt.config.step = config.step;
gantt.config.subscales = config.subscales;
if (dates) {
gantt.config.start_date = gantt.date.add(dates.start_date, -1, config.unit);
gantt.config.end_date = gantt.date.add(gantt.date[config.unit + "_start"](dates.end_date), 2, config.unit);
}
else {
gantt.config.start_date = gantt.config.end_date = null;
}
};
// get number of columns in timeline
function getUnitsBetween(from, to, unit, step) {
var start = new Date(from);
var end = new Date(to);
var units = 0;
while (start.valueOf() < end.valueOf()) {
units++;
start = gantt.date.add(start, step, unit);
}
return units;
};
//Setting available scales
var scaleConfigs = [
// minutes
{ unit: "minute", step: 1, scale_unit: "hour", date_scale: "%H", subscales: [
{unit: "minute", step: 1, date: "%H:%i"}
]
},
// hours
{ unit: "hour", step: 1, scale_unit: "day", date_scale: "%j %M",
subscales: [
{unit: "hour", step: 1, date: "%H:%i"}
]
},
// days
{ unit: "day", step: 1, scale_unit: "month", date_scale: "%F",
subscales: [
{unit: "day", step: 1, date: "%j"}
]
},
// weeks
{unit: "week", step: 1, scale_unit: "month", date_scale: "%F",
subscales: [
{unit: "week", step: 1, template: function (date) {
var dateToStr = gantt.date.date_to_str("%d %M");
var endDate = gantt.date.add(gantt.date.add(date, 1, "week"), -1, "day");
return dateToStr(date) + " - " + dateToStr(endDate);
}}
]},
// months
{ unit: "month", step: 1, scale_unit: "year", date_scale: "%Y",
subscales: [
{unit: "month", step: 1, date: "%M"}
]},
// quarters
{ unit: "month", step: 3, scale_unit: "year", date_scale: "%Y",
subscales: [
{unit: "month", step: 3, template: function (date) {
var dateToStr = gantt.date.date_to_str("%M");
var endDate = gantt.date.add(gantt.date.add(date, 3, "month"), -1, "day");
return dateToStr(date) + " - " + dateToStr(endDate);
}}
]},
// years
{unit: "year", step: 1, scale_unit: "year", date_scale: "%Y",
subscales: [
{unit: "year", step: 5, template: function (date) {
var dateToStr = gantt.date.date_to_str("%Y");
var endDate = gantt.date.add(gantt.date.add(date, 5, "year"), -1, "day");
return dateToStr(date) + " - " + dateToStr(endDate);
}}
]},
// decades
{unit: "year", step: 10, scale_unit: "year", template: function (date) {
var dateToStr = gantt.date.date_to_str("%Y");
var endDate = gantt.date.add(gantt.date.add(date, 10, "year"), -1, "day");
return dateToStr(date) + " - " + dateToStr(endDate);
},
subscales: [
{unit: "year", step: 100, template: function (date) {
var dateToStr = gantt.date.date_to_str("%Y");
var endDate = gantt.date.add(gantt.date.add(date, 100, "year"), -1, "day");
return dateToStr(date) + " - " + dateToStr(endDate);
}}
]}
];
</script>
</body>