This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
189 lines (163 loc) · 6.69 KB
/
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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>Pool split calculator</title>
</head>
<body>
<div id="app">
<!-- NAVBAR -->
<nav class="navbar navbar-light bg-light py-3">
<div class="container offset-lg-4 col-lg-4">
<span>
<span v-if="meta.emoji" class="small">
{{ meta.emoji }}
</span>
{{ meta.title }}
</span>
</div>
</nav>
<!-- The actual user part -->
<div class="mt-3 container offset-lg-4 col-lg-4">
<div>
<p class="lead">
A tool to help you split the cost of time-based services.
</p>
</div>
<!-- Player input -->
<div class="card card-body mt-2" v-if="numplayers">
</span>
<div class="row mb-2">
<div class="col-8">
{{ meta.namePrompt }}
</div>
<div class="col" style="white-space:nowrap; overflow:hidden;">
{{ meta.timePrompt }}
</div>
</div>
<div v-for="i in numplayers" class="row mb-2 person-row">
<div class="col-8 pr-0">
<input type="text" class="form-control person-name" placeholder="Name">
</div>
<div class="col">
<input type="number" class="form-control person-mins" placeholder="Mins">
</div>
</div>
<div class="mt-2 py-n1 d-block">
<button class="btn btn-sm btn-dark" v-on:click="addPlayer">+ Add person</button>
<button class="btn btn-sm btn-outline-danger" v-on:click="removePlayer">- Remove person</button>
</div>
</div>
<!-- Cost input -->
<div class="card card-body mt-2">
{{ meta.costPrompt }}
<input id="totalCost" class="mt-2 form-control form-control-lg" type="number" step="0.05" placeholder="20.00">
<button class="btn btn-primary mt-2" v-on:click="doCalc">Calculate</button>
</div>
<!-- Output -->
<div class="card card-body mt-3 bg-light">
<div v-if="calculated">
<div v-for="player of players">
<b>{{ player.name }}</b>: ${{ player.cost.toFixed(2) }}
</div>
</div>
<div v-else>
{{ meta.noCalcMsg }}
</div>
</div>
<!-- Footer -->
<hr>
<p class="small text-muted mt-auto">
A tool by <a href="https://kushagr.net/" class="link-unstyled">Kush Mittal</a>. Open source on <a href="https://github.com/theKKCD/pool-calc" class="link-unstyled">GitHub</a>.
</p>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.js"crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script>
var app = new Vue({
el: '#app',
data: {
// Title information
meta: {
emoji: '🎱',
title: 'Pool split calculator',
namePrompt: 'Person\'s name',
timePrompt: 'Time played',
costPrompt: 'Enter total price ($)',
noCalcMsg: 'Enter some information, then click \'Calculate\'!'
},
numplayers: 2, // Default amount of player rows to show
// Calculation storage
calculated: false,
players: [],
cost: 0,
totalTime: 0
},
methods: {
addPlayer: function() {
this.numplayers++;
},
removePlayer: function() {
if (this.numplayers > 1) {
this.numplayers--;
}
},
getPlayers: function() {
let arr = [];
let formplayers = $('.person-row');
for (let thisplayer of formplayers) {
let playerName = thisplayer.getElementsByClassName('person-name')[0].value;
let playTime = parseInt(thisplayer.getElementsByClassName('person-mins')[0].value);
if (playTime > 0)
arr.push({
name: playerName,
time: playTime,
cost: 0
});
}
this.players = arr;
},
getCost: function() {
this.cost = $('#totalCost').val();
},
setDefaults: function() {
this.calculated = false;
this.players = [];
this.cost = 0;
this.totalTime = 0;
},
doCalc: function() {
this.setDefaults();
this.getPlayers();
this.getCost();
if (this.players.length <= 0)
{
this.setDefaults();
return;
}
let totalTime = 0;
for (let player of this.players) {
totalTime += player.time;
}
this.totalTime = totalTime;
let minutePrice = this.cost / this.totalTime;
for (let player of this.players) {
player.cost = player.time * minutePrice;
}
this.calculated = true;
}
},
});
</script>
</body>
</html>