-
Notifications
You must be signed in to change notification settings - Fork 20
/
pit-reports.html
100 lines (84 loc) · 3.15 KB
/
pit-reports.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
---
layout: page
title: View Team Details
permalink: /pit-reports/
---
<div class="container">
<div class="row">
<div class="col-md-12">
<form id="reportForm" class="form-horizontal">
<fieldset>
<div class="row">
<div class="col-md-12" style="text-align:center;">
<a id="details-link" style="color:#ccc;font-weight:bold;font-size:18px;" href="/rate-pit"><i class="fa fa-files-o">Pit Scout a Team</i></a>
</div>
</div>
<div class="row">
<div id="reports" class="col-md-12"></div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<script>
$(function() {
ParadoxScout.getPitReports(null, null, null, function (reportSnapshot, prevReportKey) {
// if nothing returned
if (!reportSnapshot) return;
// build <div> for report and then append
var rpt = reportSnapshot.val();
rpt.rptKey = reportSnapshot.key;
var data = { rpt: rpt };
var htmlReport = [
'<div id="' + data.rpt.rptKey + '" class="col-sm-12 ps-scouting-report">',
' <h4>Team: ' + data.rpt.team_id + '<br>',
' <small><span class="fb-ts" data-fb-ts="' + data.rpt.scored_at + '">' + moment(new Date(data.rpt.scored_at)).fromNow() + '</span> by ' + data.rpt.scored_by.name + '</small></h4>',
buildOverall(data),
buildColumns(data),
'</div>',
'<hr style="width:100%;border-color:#fff;">'
];
function buildOverall(data) {
var html=[];
app_pit_reports_config.overall.forEach(function(el){
html.push(el.title + ' <span class="badge">' + (data.rpt[el.id] || el.defaultValue) + '</span> ');
});
return '<h5>' + html.join('') + '</h5>';
}
function buildColumns(data) {
var html=[];
var colNumber= 12 / app_pit_reports_config.cols.length;
app_pit_reports_config.cols.forEach(function(el){
html = html.concat(['<div class="col-sm-' + colNumber + '">',
'<div class="table-responsive">',
'<table class="table">',
'<tr><th colspan="2">' + el.header_title + '</th></tr>',
buildColumnData(el.col_data, data),
'</table>',
'</div>',
'</div>']);
});
return html.join('');
}
function buildColumnData(colData, data) {
var html=[];
colData.forEach(function(el){
var titleTd = el.title == ''? '' : '<td style="background-color:#000;">' + el.title + '</td>'
html.push('<tr>'+titleTd+'<td style="background-color:#000;">' + (data.rpt[el.id] || el.defaultValue).replace(/\r\n/g, '<br>') + '</td></tr>');
});
return html.join('');
}
$('#reports').append($(htmlReport.join('\n')));
});
// 2. prepare report _template
var reportTemplate = _.template($('#reportTemplate').html());
// 3. update relative time report was made every 5 seconds
setInterval(function () {
$('.fb-ts').each(function () {
var relativeTime = moment(new Date($(this).data('fb-ts'))).fromNow();
$(this).html(relativeTime);
})
}, 5000)
});
</script>