This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.html
163 lines (147 loc) · 7.86 KB
/
history.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Bowling Tracker">
<meta name="author" content="graboskyc">
<title>Bowling Tracker</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/album.css" rel="stylesheet">
<link href="css/bowling.css" rel="stylesheet">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
</head>
<body>
<header>
<div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container d-flex justify-content-between" id="div_nav">
</div>
</div>
</header>
<section class="jumbotron text-center" style="background: url(assets/jumbotron.JPG); background-repeat: no-repeat; background-position: center center; background-size: cover;">
<div class="container">
<h1 class="jumbotron-heading" style="color:#ffffff;font-size:60px;font-weight: bold;">Bowling Scores</h1>
<button class="btn btn-primary btn-md btndateselector" data-days="2" onclick="loadDays(this)">Last Session</button>
<button class="btn btn-secondary btn-md btndateselector" data-days="7" onclick="loadDays(this)">Week</button>
<button class="btn btn-secondary btn-md btndateselector" data-days="8" onclick="loadDays(this)">8 Days</button>
<button class="btn btn-secondary btn-md btndateselector" data-days="30" onclick="loadDays(this)">30 Days</button>
<button class="btn btn-secondary btn-md btndateselector" data-days="90" onclick="loadDays(this)">90 Days</button>
<button class="btn btn-secondary btn-md btndateselector" data-days="0" onclick="loadDays(this)">All Time</button>
</div>
</section>
<div class="album text-muted">
<div class="bodyctr">
<h1 class="nameform"><i class="fa fa-user" aria-hidden="true"></i> Player: <span id="txt_player" style="font-weight:lighter !important;"></span></h1>
<h1 class="nameform"><i class="fa fa-table" aria-hidden="true"></i> Games: <span id="txt_games" style="font-weight:lighter !important;"></span></h1>
<h1 class="nameform"><i class="fa fa-line-chart" aria-hidden="true"></i> Average: <span id="txt_average" style="font-weight:lighter !important;"></span></h1>
<div id="mainctr">
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>
<script src="js/bowling.js"></script>
<script src="js/helpers.js"></script>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.13/stitch.js"></script>
<script src="js/secrets.js"></script>
<script>
// GLOBALS
var client = 0;
var db = 0;
var runningTotal = 0;
var totals = [];
var games=0;
function buildGrid(docs) {
docs.map(game=> {
if(game.hasOwnProperty("documents")) {
game=game.documents;
}
var w = 1;
wp = "33";
apStr = '<div class="row" style="margin-top:10px;">\
<div class="col-lg-12" style="text-align:center;font-size:20px;"><b>Game '+game.game+'</b> on '+game.played_on+'</div></div><div class="row">';
$.each(game.frames, function(i,f) {
if(i==9) { w = 2; wp = "25"; } else {w=1;wp="33";}
i=i+1;
var s = "";
var b1="";
var b2="";
var b3="";
var b3spare = false;
if(f.hasOwnProperty("b1")) { b1 = f.b1;}
if(f.hasOwnProperty("b2")) { b2 = f.b2;}
if(f.hasOwnProperty("b3")) { b3 = f.b3;}
if(f.hasOwnProperty("b3spare")) { b3spare = f.b3spare;}
if (f.split) { s = "S";}
if(b1*1 == 10) { b1 = "X";}
if(f.spare) { b2 = "/";}
if(b3spare) { b3 = "/";}
apStr = apStr+ '<div class="col-sm-'+w+' bowlingcellouter bowlingborder frame'+i+'"> \
<div class="bowlinginnerscore issplit frame'+i+'" style="width:'+wp+'%;"><input type="text" class="scorebox" data-frame="frame'+i+'" data-ball="split" value="'+s+'" readonly /></div> \
<div class="bowlinginnerscore bowlingborder ballone frame'+i+'" style="width:'+wp+'%;"><input type="text" class="scorebox" data-frame="frame'+i+'" data-ball="ball1" value="'+b1+'" readonly /></div>\
<div class="bowlinginnerscore bowlingborder balltwo frame'+i+'" style="width:'+wp+'%;"><input type="text" class="scorebox" data-frame="frame'+i+'" data-ball="ball2" value="'+b2+'" readonly /></div>';
if(i==10) {
apStr = apStr +'<div class="bowlinginnerscore bowlingborder ballthree frame'+i+'" style="width:'+wp+'%;"><input type="text" class="scorebox" data-frame="frame'+i+'" data-ball="ball3" value="'+b3+'" /></div>';
}
apStr = apStr + '<div class="framescore framescoreformat frame'+i+'"></div> \
</div>';
});
apStr = apStr + '<div class="col-sm-1 bowlingcellouter bowlingborder"> \
<div class="bowlingtotalscore bowlingtotalscoreformat">'+game.total+'</div> \
</div></div>';
$('#mainctr').append(apStr);
updateTotal();
trackTotal(game.total*1);
$('#txt_games').text(games);
$('#txt_average').text(Math.floor(runningTotal/games));
$('input').removeAttr('data-frame');
$('input').removeAttr('data-ball');
$('.bowlingtotalscore').text(game.total);
$('.framescore').removeClass('framescore');
$('.bowlingtotalscore').removeClass('bowlingtotalscore');
$('#txt_player').text(game.name);
});
}
function loadData(player,days) {
$('#mainctr').empty();
runningTotal = 0;
games = 0;
totals = [];
if(days == 1) {
var agg = [{"$match": {name:player}},
{"$group": {_id: {year: {"$year": "$played_on"}, doy: {"$dayOfYear": "$played_on"}}, documents: {"$push": "$$ROOT"}}},
{"$sort": {_id: -1}}, {"$limit": 1},
{"$unwind": {path: "$documents"}},
{"$sort": {"documents.played_on":-1, "documents.game":1}
}];
client.auth.loginWithCredential(new stitch.AnonymousCredential()).then(() =>
db.collection('games').aggregate(agg).asArray()).then(buildGrid).catch(err => {console.error(err)});
} else {
var find = {name:player};
if (days != 0 ) {
var d = new Date();
d.setDate(d.getDate()-days*1);
find = {name:player, played_on: { "$gt": d}}
}
client.auth.loginWithCredential(new stitch.AnonymousCredential()).then(() =>
db.collection('games').find(find,{ sort: {played_on: -1, game:1}}).asArray()).then(buildGrid).catch(err => {console.error(err)});
}
}
$(function() {
client = stitch.Stitch.initializeDefaultAppClient('bowling-sfeoc');
db = client.getServiceClient(stitch.RemoteMongoClient.factory, 'mongodb-atlas').db('bowling');
var p = getPlayer();
loadData(p,1)
});
</script>
</body>
</html>