-
Notifications
You must be signed in to change notification settings - Fork 0
/
coprs.php
135 lines (114 loc) · 3.21 KB
/
coprs.php
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
<title>COPRS</title>
<html lang="en">
<?php include('navbar.php'); ?>
<body class="bg-body">
<div class="container row-offcanvas row-offcanvas-left">
<div class="well column col-lg-12 col-sm-12 col-xs-12" id="content">
<div class="row pt-3 pb-3 mb-3">
<div class="input-group mb-3">
<input id="eventCode" type="text" class="form-control" placeholder="Event Code" aria-label="eventCode">
<button id="loadEvent" type="button" class="btn btn-primary">Load Event</button>
</div>
<!-- Left column -->
<div class="col-lg-12 col-sm-12 col-xs-12 gx-3">
<div class="card">
<div class="card-header" id="cardHeader"></div>
<div class="card-body">
<div class="table-responsive">
<table id="dataTable" class="table table-striped table-hover sortable">
<thead>
<tr id="tableKeys">
</tr>
</thead>
<tbody id="tableData">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<?php include("footer.php"); ?>
<script>
function createRow(headers, team, rowData){
/*Create HTML row for data.
Args:
rowData: Dictionary of keys and values needed for row.
Returns:
HTML row for table.
*/
var list_row = []
list_row.push('<tr>');
list_row.push(` <td scope="row">${team}</td>`);
for (var i = 0; i != headers.length; i++){
list_row.push(` <td scope="row">${rowData[headers[i]]}</td>`);
}
list_row.push('</tr>');
return list_row.join('')
}
function createHeaderRow(headers){
var list_row = [];
list_row.push(' <th scope="col">Team</th>');
for (var i = 0; i != headers.length; i++){
list_row.push(` <th scope="col">${headers[i]}</th>`);
}
return list_row.join('')
}
function getKeyListFromDict(data){
var out = [];
for (let key in data){
out.push(key);
}
return out;
}
function updateTable(data){
/*Update table from API.
Args:
List of dictionaries of rows.
*/
$('#tableKeys').empty();
$('#tableData').empty();
$('#cardHeader').html(data['eventCode']);
var coprData = data['data'];
var headers = null;
for (let team in coprData){
if (headers == null){
headers = getKeyListFromDict(coprData[team]);
$('#tableKeys').append(createHeaderRow(headers));
}
$('#tableData').append(createRow(headers, team, coprData[team]));
}
var newTableObject = document.getElementById('dataTable');
sorttable.makeSortable(newTableObject);
}
function loadInputData(){
/* Loads data using input event code and populate table. */
$.post('tbaAPI.php', {
'getCOPR': 1,
'eventCode': $('#eventCode').val()
}, function(data) {
data = JSON.parse(data);
console.log(data);
updateTable(data);
});
}
function loadDefaultData(){
/* Load data from inbuilt event. */
$.post('tbaAPI.php', {
'getCOPR': 1
}, function(data) {
data = JSON.parse(data);
console.log(data);
updateTable(data);
});
}
$(document).ready(function() {
loadDefaultData();
});
$("#loadEvent").on('click', function(event) {
loadInputData();
});
</script>
</html>