-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
279 lines (246 loc) · 8.78 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html>
<head>
<title>Planning poker</title>
<style>
body {
margin: 0;
padding-bottom: 3rem;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
input[type=text],
select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
background-color: #f2f2f2;
padding: 20px;
}
.center {
margin: auto;
width: fit-content;
padding: 10px;
}
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
/* Style the header */
.header {
background-color: darkgrey;
height: 80px;
}
/* Container for flexboxes */
.row {
display: -webkit-flex;
display: flex;
}
/* Create three unequal columns that sits next to each other */
.column {
padding: 10px;
}
/* Left and right column */
.column.side {
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
}
/* Middle column */
.column.middle {
-webkit-flex: 2;
-ms-flex: 2;
flex: 2;
}
/* Style the footer */
.footer {
background-color: #f1f1f1;
padding: 10px;
text-align: center;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
@media (max-width: 600px) {
.row {
-webkit-flex-direction: column;
flex-direction: column;
}
}
button.vote-button {
width: 100px;
height: 60px;
float: left;
margin: 15px;
}
button.menu-button {
float: right;
width: 90px;
height: 30px;
margin: 5px;
}
</style>
</head>
<body>
<div id="menu-section" class="header" hidden>
<p id="welcome" style="float:left;"></p>
<form id="form-clear" action="">
<button class="menu-button">Reset</button>
</form>
<form id="form-force" action="">
<button class="menu-button">Force votes</button>
</form>
<form id="form-votes-clear" action="">
<button class="menu-button">Clear votes</button>
</form>
<form id="form-exit" action="">
<button class="menu-button">Disconnect</button>
</form>
</div>
<div class="row">
<div id="result-section" hidden class="column side">
<p>Awaiting</p>
<ul id="awaiting"></ul>
</div>
<div class="column middle">
<div id="login-section" class="center">
<form id="form-username" action="">
<input id="input" type="text" placeholder="Your name.." autocomplete="off" /><input type="submit"
value="Connect">
</form>
</div>
<div id="voting-section" hidden>
<p id="last_result"></p>
<p id="your_vote"></p>
<div id="votes"></div>
</div>
</div>
<div id="connected-section" hidden class="column side">
<p>Connected users</p>
<ul id="connected"></ul>
</div>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
var loginSection = document.getElementById('login-section');
var menuSection = document.getElementById('menu-section');
var votingSection = document.getElementById('voting-section');
var resultSection = document.getElementById('result-section');
var connectedSection = document.getElementById('connected-section');
var messages = document.getElementById('messages');
var usernameForm = document.getElementById('form-username');
var clearForm = document.getElementById('form-clear');
var exitForm = document.getElementById('form-exit');
var forceForm = document.getElementById('form-force');
var clearVotesForm = document.getElementById('form-votes-clear');
var input = document.getElementById('input');
var welcome = document.getElementById('welcome');
var connected = document.getElementById('connected');
var voteContainer = document.getElementById('votes');
var youVoted = document.getElementById('your_vote');
var awaiting = document.getElementById('awaiting');
var lastResult = document.getElementById('last_result');
var username = "empoyee";
var validVotes = ["0.5", "1", "2", "3", "5", "8", "13", "20", "40", "100", "?"];
for (index in validVotes) {
var voteItem = document.createElement('form');
voteItem.id = "vote-for-" + validVotes[index];
voteItem.action = "";
var voteItemButton = document.createElement('button');
voteItemButton.innerText = validVotes[index];
voteItemButton.className = "vote-button";
voteItem.appendChild(voteItemButton);
voteItem.addEventListener('submit', function (e) {
e.preventDefault();
var yourVote = e.target[0].innerText;
youVoted.innerText = "You voted: " + yourVote
socket.emit('vote', username, yourVote);
});
voteContainer.appendChild(voteItem);
}
usernameForm.addEventListener('submit', function (e) {
e.preventDefault();
if (input.value) {
socket.emit('username', input.value);
username = input.value;
loginSection.hidden = true;
welcome.textContent = "Welcome, " + username;
menuSection.hidden = false;
votingSection.hidden = false;
resultSection.hidden = false;
connectedSection.hidden = false;
}
});
clearForm.addEventListener('submit', function (e) {
e.preventDefault();
socket.emit('clear', username);
});
exitForm.addEventListener('submit', function (e) {
e.preventDefault();
socket.emit('exit', username);
loginSection.hidden = false;
menuSection.hidden = true;
votingSection.hidden = true;
resultSection.hidden = true;
connectedSection.hidden = true;
});
forceForm.addEventListener('submit', function (e) {
e.preventDefault();
socket.emit('force-vote', username);
});
clearVotesForm.addEventListener('submit', function (e) {
e.preventDefault();
awaiting.textContent = "";
lastResult.textContent = "";
socket.emit('clear-vote', username);
});
socket.on('usernames', function (usernames) {
connected.textContent = "";
for (index in usernames) {
var item = document.createElement('li');
item.innerText = usernames[index];
connected.appendChild(item);
}
});
socket.on('vote-result', function (result, votes) {
awaiting.textContent = "";
var sorted = "" + votes.sort(function(a, b) {if (a === "?") { return 1; } if (b === "?") { return -1; } return parseInt(a) - parseInt(b);});
lastResult.textContent = "Last result: " + result + " (" + sorted.replace(',', ', ') + ")";
});
socket.on('waiting-on', function (usernames) {
awaiting.textContent = "";
for (index in usernames) {
var item = document.createElement('li');
item.innerText = usernames[index];
awaiting.appendChild(item);
}
});
socket.on('vote-cleared', function () {
loginSection.hidden = false;
menuSection.hidden = true;
votingSection.hidden = true;
resultSection.hidden = true;
connectedSection.hidden = true;
});
</script>
</body>
</html>