-
Notifications
You must be signed in to change notification settings - Fork 0
/
rawCoprData.php
127 lines (112 loc) · 3.18 KB
/
rawCoprData.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
<title>Raw COPR Data</title>
<?php include("header.php") ?>
<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">
<h1 id="COPRHeader">COPR Data: ???</h1>
<div>
<div class="input-group mb-3">
<input id="eventCode" type="text" class="form-control" placeholder="eventCode" aria-label="eventCode">
<button id="loadEvent" type="button" class="btn btn-primary">Load Event</button>
</div>
</div>
<div class="table-responsive">
<div id="freezeTableDiv">
<table id="dataTable" class="table table-striped table-hover">
<thead>
<tr id="tableKeys">
</tr>
</thead>
<tbody id="tableData">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<style>
th:first-child,
td:first-child,
tr {
position: sticky;
left: 0px;
z-index: 1;
background: rgba(255, 255, 255, 1);
}
</style>
<?php include("footer.php") ?>
<script>
var frozenTable = null;
function dataToTable(dataObj, keys) {
$("#tableData").html("");
for (let team in dataObj) {
var row = '<tr>';
row += '<td>' + team + '</td>';
for (let j = 0; j < keys.length; j++) {
row += '<td>' + dataObj[team][keys[j]] + '</td>';
}
row += '</tr>';
$("#tableData").append(row);
}
}
function keysToTable(keys) {
var header = '<th scope="col">Team</th>';
for (let i = 0; i < keys.length; i++) {
header += '<th scope="col">' + keys[i] + '</th>'
}
$("#tableKeys").html(header);
}
function setHeader(ec) {
$("#COPRHeader").html("COPR Data: " + ec);
}
function processData(data) {
var dataObj = JSON.parse(data);
var data = dataObj["data"];
var keys = dataObj["keys"];
var ec = dataObj["eventCode"];
setHeader(ec);
keysToTable(keys);
dataToTable(data, keys);
// sorttable.makeSortable($("#dataTable"));
// sorttable.makeSortable(document.getElementById("dataTable"));
}
function requestAPI() {
//output: gets the API data from our server
$.get("tbaAPI.php", {
getCOPRs: 1
}).done(function(data) {
processData(data);
sorttable.makeSortable(document.getElementById("dataTable"));
frozenTable = $('#freezeTableDiv').freezeTable({
'backgroundColor': "white",
'columnNum': 1,
'frozenColVerticalOffset': 0
});
});
}
$(document).ready(function() {
requestAPI();
$("#loadEvent").click(function() {
$.get("tbaAPI.php", {
getCOPRs: 1,
eventcode: $("#eventCode").val()
}).done(function(data) {
processData(data);
setTimeout(function() {
sorttable.makeSortable(document.getElementById("dataTable"));
frozenTable = $('#freezeTableDiv').freezeTable({
'backgroundColor': "white",
'columnNum': 1,
'frozenColVerticalOffset': 0
});
}, 200);
});
});
$("#dataTable").click(function() {
if (frozenTable) {
frozenTable.update();
}
});
});
</script>