-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_index.html
449 lines (398 loc) · 16.5 KB
/
master_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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css"/>
<link rel="stylesheet" href="https://cdn.datatables.net/rowreorder/1.2.8/css/rowReorder.dataTables.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"/>
<style>
#reposTable td:first-child, #reposTable td:nth-child(2) {
padding-right: 40px;
white-space: nowrap;
width: 20px;
}
#reposTable a:hover {
text-decoration: none;
}
#logsTbl thead th {
white-space: nowrap;
}
#logsTbl td:first-child {
width: 70px;
}
#logsTbl td:nth-child(2) {
white-space: nowrap;
width: 250px;
}
#logsTbl td:nth-child(3) {
white-space: nowrap;
width: 110px;
}
#logsTbl td:nth-child(4) {
text-align: center;
}
h3 small {
font-size: 1.2rem;
}
.white {
background-color: white;
color: #bebebe;
}
.success {
color: #28a745;
}
.warning {
color: #ffc107;
}
.danger {
color: #dc3545;
}
.primary {
color: #007bff;
}
.info {
color: #17a2b8;
}
.secondary {
color: #6c757d;
}
.highlightTable {
background-color: #f3f3f3;
}
.fa, .fa-solid, .fa-regular, .fa-brands {
font-size: 1.2em;
}
td:has(div.userCommits){
padding-top:0px !important;
padding-left:0px !important;
padding-right:0px !important;
}
div.userCommits{
background-color: #f2f2f2;
padding-left: 2vw;
padding-right: 2vw;
padding-top: 20px;
margin-bottom: 2rem;
overflow: auto;
}
.tmBlue{
color: #009cab;
}
.tmOrange{
color: #f04c25;
}
.top-grid{
display: grid;
grid-template-columns: 1fr 1fr;
}
.grid-graph{
grid-row: span 3;
}
</style>
<title>{{reposTitle}}</title>
</head>
<body>
<div class="container pt-2">
<h1><i class="fa-brands fa-github"></i> TM Github Assistant</h1>
<h2 class="text-info my-3"><span class="tmBlue">Repositories Webdesign Essentials</span> <span class="tmOrange">{{reposTitle}}</span> </h2>
<table class="table table-sm" id="reposTable">
<thead>
<tr>
<th scope="col" id="seqCol">#</th>
<th scope="col" id="nameCol">Name</th>
<th scope="col" id="repoCol">Repo</th>
<th scope="col" id="hostingCol">Hosting</th>
<th scope="col" id="pexelsCol">Pexels</th>
<th scope="col" id="localCol">Local</th>
<th scope="col" id="githubCol">GitHub</th>
</tr>
</thead>
</table>
<p><span class="text-danger">{{lastUpdate}}</span></p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/rowreorder/1.2.8/js/dataTables.rowReorder.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const githubUrl = '{{githubUrl}}';
const students = [];
let lastClickedUser = null;
let showPullRequests = $('#btnInclPullRequests').prop('checked');
// table repos
$('#reposTable .fa-solid, #reposTable .fa-brands, #reposTable .fa-regular')
.addClass('fa-lg mr-2 text-muted')
.click(function () {
$('#reposTable tr').removeClass();
$(this).closest('tr').addClass('highlightTable');
});
// show local site + logs
$('.fa-chrome').click(function () {
$(this).siblings('.getLogs').click();
});
function format(d) {
// `d` is the original data object for the row
const tblColors = ['success', 'warning', 'danger', 'primary', 'info', 'secondary', 'success', 'warning'];
const tblNames = [];
const rows = d.commits;
let logsTbl = '';
let btnGroup = []
rows.forEach((crow, i) => {
const hash = crow.hash;
const name = crow.name;
const date = crow.date;
const commit = crow.commit;
let shortPush = "";
const beforeDeadline = crow.beforeDeadline;
let icon = "fa-code-commit";
// indien 'name' eerste maal voorkomt: voeg 'name' toe aan tblNames[] en maak button
if (!tblNames.includes(name)) {
tblNames.push(name);
const bntColor = tblColors[tblNames.indexOf(name)];
btnGroup.push(`<button type="button" class="btn btn-sm btn-${bntColor} mr-2 mb-2 showOnlyThisUser" data-user="${tblNames.indexOf(name)}" data-username="${d.username}">${name}</button>`);
}
// haal positie van 'name' in tblNames[] op en selecteer een kleur in tblColors[];
let classColor = tblColors[tblNames.indexOf(name)];
// indien 'commit' begint met "Merge ...": class .white
if (commit.startsWith('Merge '))
icon = 'fa-code-merge';
if(crow.shortPush == true){
shortPush = "<i style='color:red;' class='fa-solid fa-circle-exclamation' title='Commit less than 5 min apart from previous'></i>"
}
logsTbl += `<tr data-user="${tblNames.indexOf(name)}" data-pullrequest="${(commit.startsWith('Merge '))}">
<td ><i class="commiticon ${classColor} fa-solid ${icon}"></i></td>
<td><a href="${d.repo}/commit/${hash}" target="github">${hash}</a></td>
<td class="commitUser">${name}</td>
<td>${date}</td>
<td>${beforeDeadline}</td>
<td class="commitInfo">${commit} ${shortPush}</td>
</tr>`;
});
return (
`<div class="userCommits container">
<h3 id="logsName">Logs ${d.name + " " + d.surname}</h3>
<div class="top-grid">
<div>
<div class="custom-control custom-switch">
<input type="checkbox" checked class="custom-control-input btnInclPullRequests" data-username="${d.username}" id="btnInclPullRequests${d.username}">
<label class="custom-control-label btnInclPullRequests" for="btnInclPullRequests${d.username}">Incl. pull request</label>
</div>
<div class="custom-control custom-switch">
<input type="checkbox" checked class="custom-control-input btnShowAllUsers" data-username="${d.username}" id="btnShowAllUsers${d.username}">
<label class="custom-control-label" for="btnShowAllUsers${d.username}">Show all users</label>
</div>
</div>
<div class="grid-graph">
<div id="chart-container" style="position: relative; width: 100%;">
<canvas id="myChart${d.username}" style="width:100%; height: 20em;"></canvas>
</div>
</div>
<div class="">
<div class="btnGroup" id="btnGroup${d.username}">${btnGroup.join(" ")}</div>
</div>
<div>
<p class="col">Rows visible: <b><span id="visibleRows${d.username}"></span></b></p>
</div>
</div>
<table class="table table-sm mt-4" id="logsTbl${d.username}">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Date</th>
<th scope="col">Before dl</th>
<th scope="col">Commit</th>
</tr>
</thead>
<tbody>${logsTbl}</tbody>
</table>
</div>`
);
}
// render logs table
function renderLogs(username) {
// show/hide rows
$(`#logsTbl${username} tbody tr`).show();
if (lastClickedUser !== null) {
$(`#logsTbl${username} tbody tr:not([data-user=${lastClickedUser}])`).hide();
}
/*if (!showPullRequests) {
$(`#logsTbl${username} tbody tr[data-pullrequest=true]`).hide();
}*/
// count visible rows
const totalRows = $(`#logsTbl${username} tbody tr`).length;
const visibleRows = $(`#logsTbl${username} tbody tr:visible`).length;
$(`#visibleRows${username}`).text(`${visibleRows} of ${totalRows}`);
const datasets = [];
const fillColors = ["rgba(40, 167, 69, .7)", "rgba(255, 193, 7, .7)", "rgba(220, 53, 69, .7)", "rgba(0, 123, 255, .7)", "rgba(23, 162, 184, .7)", "rgba(108, 117, 125, .7)", "rgba(40, 167, 69, .7)", "rgba(255, 193, 7, .7)"];
const chartColors = ["rgba(40, 167, 69, 1)", "rgba(255, 193, 7, 1)", "rgba(220, 53, 69, 1)", "rgba(0, 123, 255, 1)", "rgba(23, 162, 184, 1)", "rgba(108, 117, 125, 1)", "rgba(40, 167, 69, 1)", "rgba(255, 193, 7, 1)"];
students.find(x => x.username === username).contributions.forEach((pcon, i) => {
datasets.push(
{
label: pcon.name,
backgroundColor: fillColors[i],
borderColor: chartColors[i],
data: pcon.contributions,
parsing: {
xAxisKey: 'week',
yAxisKey: 'commits'
},
}
);
})
const data = {
labels: students.find(x => x.username === username).contributions.map(x => x.week),
datasets: datasets
};
const config = {
type: 'line',
data: data,
options: {
tension: 0.3,
fill: true,
interaction: {
mode: 'nearest',
axis: 'x',
intersect: false
},
elements: {
line: {
borderWidth: 2,
},
point:{
radius: 1
}
},
scales: {
y: {
grace: '10%',
stacked: true,
title: {
display: true,
text: 'Number of commits'
},
ticks: {
precision: 0
}
},
x: {
title: {
display: true,
text: 'Week #'
},
}
}
}
};
const myChart = new Chart(
document.getElementById('myChart'+username),
config
);
}
$(document).ready( function () {
let webColumns = [
{ data: 'sequence'
},
{ data: 'name',
render: function(data, type, row){
return row.surname + " " + row.name;
},
className: 'reorder-item'
},
{ data: 'repo',
render: function(data, type, row){
return "<a href='" + row.repo + "' target='_blank'>" + row.username + "</a>";
}
},
{ data: 'hosting',
render: function(data, type, row){
if(row.hosting && row.hosting.toLocaleLowerCase().indexOf("https") == 0) {
return "<a href='" + row.hosting + "' target='_blank'>" + row.hosting + "</a>";
}else{
return "<i class='fa-solid fa-question text-muted' title='Missing' />";
}
}},
{ data: 'pexels',
render: function(data, type, row){
if(row.pexels && row.pexels.toLocaleLowerCase().indexOf("https") == 0){
return "<a href='" + row.pexels + "' target='_blank'><span style='display:none;'>" + row.pexels+ "</span><i class='fa-solid fa-camera text-muted' title='Pexels Account'/></a>";
}else{
return "<i class='fa-solid fa-question text-muted' title='Missing'/>";
}
}},
{ data: 'username',
render: function(data, type, row){
return `
<a title="Local Repo" href="${row.username}/student_index.html" class="fa-brands fa-chrome text-muted" target="local"></a>
<a title="View Logs" href="#!" class="getLogs fa-solid fa-clipboard-list text-muted" data-giturl="${row.repo}" data-id="${row.index}"></a>
<a title="Portfolio" href="${row.username}/3_WebDesignPortfolio/index.html" class="fa-solid fa-briefcase text-muted" target="local"></a>
`
}},
{ data: 'username',
render: function(data, type, row){
return `
<a title="Github repo" href="${row.repo}" class="fa-brands fa-github text-muted" target="github"></a>
<a title="Github commits" href="${row.repo}/commits/main" class="fa-solid fa-code text-muted" target="github"></a>
<a title="Github branches" href="${row.repo}/branches/all" class="fa-solid fa-code-branch text-muted" target="github"></a>
<a title="Github issues" href="${row.repo}/issues" class="fa-solid fa-exclamation-circle text-muted" target="github"></a>
<a title="Github contributions" href="${row.repo}/graphs/contributors" class="fa-regular fa-chart-bar text-muted" target="github"></a>
<a title="Github settings" href="${row.repo}/settings/access" class="fa-solid fa-users-cog text-muted" target="github"></a>
`
}}
];
columns = webColumns;
var table = $('#reposTable').DataTable({
rowReorder: {
selector: '.reorder-item',
dataSrc: 'sequence'
},
data: students,
columns: columns,
columnDefs: [
{
target: 0,
visible: false,
}]
});
$('#reposTable tbody').on('click', 'td .getLogs', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
} else {
// Open this row
row.child(format(row.data())).show();
renderLogs(row.data().username);
$(`.btnInclPullRequests${row.data().username}`).click(function () {
showPullRequests = $(this).prop('checked');
let tableUser = $(this).data('username');
renderLogs(tableUser);
})
// click switch #btnShowAllUsers
$(`.btnShowAllUsers`).click(function () {
lastClickedUser = null;
console.log($(this));
let tableUser = $(this).data('username');
$(this).prop('disabled', true);
renderLogs(tableUser);
})
// click button .showOnlyThisUser
$(`.btnGroup`).on('click', '.showOnlyThisUser', function () {
lastClickedUser = $(this).data('user');
let tableUser = $(this).data('username');
$(`#btnShowAllUsers${tableUser}`).removeAttr('disabled').prop('checked', false);
renderLogs(tableUser);
})
tr.addClass('shown');
}
});
} );
</script>
</body>
</html>