-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgantt.html
350 lines (300 loc) · 11.7 KB
/
gantt.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<!DOCTYPE html>
<html>
<head>
<title>Software & Computing Gantt Chart</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="frappe-gantt.css">
<script src="frappe-gantt.js" ></script>
</head>
<body>
<p>Software & Computing Gantt Chart</p>
<!--Add buttons to initiate auth sequence and sign out-->
<button id="authorize_button" style="display: none;">Authorize</button>
<button id="signout_button" style="display: none;">Sign Out</button>
<pre id="content" style="white-space: pre-wrap;"></pre>
<select name="year" id="year_select">
<option value="2020">2020</option>
<option value="2021" selected>2021</option>
</select>
<select name="wbs_area" id="wbs_area_select">
<option value="all" selected>All</option>
<option value="wbs1">WBS1</option>
<option value="wbs2">WBS2</option>
<option value="wbs3">WBS3</option>
<option value="wbs4">WBS4</option>
</select>
<!--<input type="checkbox" id="minor_filter">Include minor milestones?-->
<br>
<button id="update_button">Update</button>
<div class="card" style="overflow: scroll">
<svg id="gantt"></svg>
</div>
<script type="text/javascript" >
// Client ID and API key from the Developer Console
var CLIENT_ID = '300834940465-boa7n1fso9j0qgccnphp6fgk1kr4tok5.apps.googleusercontent.com';
var API_KEY = 'AIzaSyCKCfgiO7n8xMe3eKmU5F8kg5drWrdnIYQ';
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://sheets.googleapis.com/$discovery/rest?version=v4"];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = "https://www.googleapis.com/auth/spreadsheets.readonly";
var authorizeButton = document.getElementById('authorize_button');
var signoutButton = document.getElementById('signout_button');
var updateButton = document.getElementById('update_button');
var spreadsheets = {
"2020" : {
spreadsheetId: '1Qi3ksAf_36WEz92z8ZqzMnvB-6jD41rFcVyXagKbqW8',
range: 'CY20!A2:J'
},
"2021" : {
spreadsheetId: '1Qi3ksAf_36WEz92z8ZqzMnvB-6jD41rFcVyXagKbqW8',
range: 'CY21!A3:59'
}
};
var gantt;
/**
* On load, called to load the auth2 library and API client library.
*/
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
/**
* Initializes the API client library and sets up sign-in state
* listeners.
*/
function initClient() {
gapi.client.init({
apiKey: API_KEY,
clientId: CLIENT_ID,
discoveryDocs: DISCOVERY_DOCS,
scope: SCOPES
}).then(function () {
// Listen for sign-in state changes.
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state.
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
authorizeButton.onclick = handleAuthClick;
signoutButton.onclick = handleSignoutClick;
updateButton.onclick = handleUpdate;
}, function(error) {
appendPre(JSON.stringify(error, null, 2));
});
}
/**
* Called when the signed in status changes, to update the UI
* appropriately. After a sign-in, the API is called.
*/
function updateSigninStatus(isSignedIn) {
if (isSignedIn) {
authorizeButton.style.display = 'none';
signoutButton.style.display = 'block';
// listMajors();
makeGantt();
} else {
authorizeButton.style.display = 'block';
signoutButton.style.display = 'none';
}
}
/**
* Sign in the user upon button click.
*/
function handleAuthClick(event) {
gapi.auth2.getAuthInstance().signIn();
}
/**
* Sign out the user upon button click.
*/
function handleSignoutClick(event) {
gapi.auth2.getAuthInstance().signOut();
}
function handleUpdate(event) {
makeGantt();
}
/**
* Append a pre element to the body containing the given message
* as its text node. Used to display the results of the API call.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('content');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
function filterData(data) {
const byYear = document.getElementById('year_select');
var yearSelect = byYear.options[byYear.selectedIndex];
var chartYear = yearSelect.value;
const cb = false
const byWBS = document.getElementById('wbs_area_select');
var opt = byWBS.options[byWBS.selectedIndex];
var wbsFilter = opt.value;
if (wbsFilter != 'all') {
var wbs = data.reduce(function (res, value) {
var wbsGroup = value.custom_class.split("-");
if ("wbs" + wbsGroup[1] == wbsFilter) {
res.push(value)
}
return res;
}, []);
return wbs;
} else {
return data;
}
}
function filterData2020(data) {
// const cb = document.getElementById('minor_filter');
const byYear = document.getElementById('year_select');
var yearSelect = byYear.options[byYear.selectedIndex];
var chartYear = yearSelect.value;
const cb = false
const byWBS = document.getElementById('wbs_area_select');
var opt = byWBS.options[byWBS.selectedIndex];
var wbsFilter = opt.value;
// var major = [];
// if (cb.checked) {
if (cb || chartYear == "2020") {
var major = data.reduce(function (res, value) {
var major = value.id.split(".");
if ((major[2] == "00")) {
res.push(value);
}
return res;
}, []);
data = major
}
// var wbs = [];
if (wbsFilter != 'all') {
var wbs = data.reduce(function (res, value) {
var wbsGroup = value.custom_class.split("-");
if ("wbs" + wbsGroup[1] == wbsFilter) {
res.push(value)
}
return res;
}, []);
return wbs;
} else {
return data;
}
// return data;
}
function makeGantt() {
const byYear = document.getElementById('year_select');
var yearSelect = byYear.options[byYear.selectedIndex];
var chartYear = yearSelect.value;
if (chartYear == "2020") {
makeGantt2020(chartYear);
} else {
ganttSheetId = spreadsheets[chartYear].spreadsheetId;
ganttRange = spreadsheets[chartYear].range;
gapi.client.sheets.spreadsheets.values.get(
{
spreadsheetId: ganttSheetId,
range: ganttRange
}
).then(function (response) {
var range = response.result;
var data = range.values;
var tasks = data.reduce(function (res, value) {
if ((value[3] != null && value[3] != "")) {
var start_date = value[11] || new Date(chartYear, 0, 1);
var end_date = value[12] || value[13] || new Date(chartYear, 11, 31);
if (isNaN(Date.parse(start_date))) {
start_date = new Date(chartYear, 0, 1);
}
if (isNaN(Date.parse(end_date))) {
end_date = new Date(chartYear, 11, 31);
}
!isNaN(Date.parse())
var g_start_date = new Date(start_date).toISOString().split('T')[0];
var g_end_date = new Date(end_date).toISOString().split('T')[0];
var row = {
id: value[7],
name: value[7],
start: g_start_date,
end: g_end_date,
progress: 100,
dependencies: '',
custom_class: 'wbs-' + value[2] + '-color'
};
res.push(row);
}
return res;
}, []);
var filterTasks = filterData(tasks);
if (gantt == null) {
gantt = new Gantt('#gantt', filterTasks, {column_width: 5});
} else {
gantt.refresh(filterTasks)
}
gantt.change_view_mode('Month');
}, function (response) {
appendPre('Error: ' + response.result.error.message);
});
}
}
function makeGantt2020(chartYear) {
// gapi.client.sheets.spreadsheets.values.get({
// // spreadsheetId: '1astWf1jlEIF2PCziDdLZlTqyBxr88XCe4Nw5gEcG6VI',
// // range: 'CY20!A2:J',
// spreadsheetId: '1Qi3ksAf_36WEz92z8ZqzMnvB-6jD41rFcVyXagKbqW8',
// range: 'CY20!A2:J',
// })
ganttSheetId = spreadsheets[chartYear].spreadsheetId;
ganttRange = spreadsheets[chartYear].range;
gapi.client.sheets.spreadsheets.values.get(
{
spreadsheetId: ganttSheetId,
range: ganttRange
}
).then(function (response) {
var range = response.result;
var data = range.values;
var tasks = data.reduce(function (res, value) {
// var major = value[3].split(".");
if ((value[3] != null && value[3] != "") ) {
var start_date = value[7] || new Date(chartYear, 0, 1);
var end_date = value[9] || value[8] || new Date(chartYear, 11, 31);
if (isNaN(Date.parse(start_date))) {
start_date = new Date(chartYear, 0, 1);
}
if (isNaN(Date.parse(end_date))) {
end_date = new Date(chartYear, 11, 31);
}
!isNaN(Date.parse())
var g_start_date = new Date(start_date).toISOString().split('T')[0];
var g_end_date = new Date(end_date).toISOString().split('T')[0];
var row = {
id: value[3],
name: value[6],
start: g_start_date,
end: g_end_date,
progress: 100,
dependencies: '',
custom_class: 'wbs-' + value[0] + '-color'
};
res.push(row);
}
return res;
}, []);
var filterTasks = filterData2020(tasks);
if ( gantt == null ) {
gantt = new Gantt('#gantt', filterTasks, {column_width: 5});
} else {
gantt.refresh(filterTasks)
}
gantt.change_view_mode('Month');
}, function (response) {
appendPre('Error: ' + response.result.error.message);
});
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
<!--<script src="frappe-gantt.js" >-->
<!--var gantt = new Gantt('#gantt', [], {column_width: 5});-->
<!--</script>-->
</body>
</html>