Skip to content

Commit

Permalink
added admin to delete dangling games (no pwd yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Legg committed Feb 13, 2014
1 parent 8f1fac1 commit 62984f9
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ CLIENT = js/avalon.js
STATSSRC = client/stats.coffee
STATS = js/stats.js

ADMINSRC = client/admin.coffee
ADMIN = js/admin.js

.PHONY: all
all: $(SERVER) $(CLIENT) $(STATS)
all: $(SERVER) $(CLIENT) $(STATS) $(ADMIN)

$(STATS): $(STATSSRC)
coffee -j $(STATS) -c $(STATSSRC)

$(ADMIN): $(ADMINSRC)
coffee -j $(ADMIN) -c $(ADMINSRC)

$(CLIENT): $(CLIENTSRC)
coffee -j $(CLIENT) -c $(CLIENTSRC)

Expand Down
37 changes: 37 additions & 0 deletions client/admin.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
formatDate = (d) ->
d = new Date(d)
d_names = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
ampm = if (d.getHours() < 13) then "am" else "pm"
h = d.getHours() % 12
h = if h == 0 then 12 else h
s = d_names[d.getDay()] + " " +
d.getDate() + "/" +
(d.getMonth() + 1) + "/" +
d.getFullYear() + " " +
h + ":" + d.getMinutes() + ampm

jQuery ->
gamesReq = $.ajax
url : '/api?type=games&gamestate=0'

gamesReq.done (res, status, jqXHR) ->
if not res then return

for r in res
do (r) ->
li = $("<a>")
.addClass("list-group-item")
.html($("<b>").text(formatDate(r.date)))
.append($("<br>"))
.append(r.name)
.click () ->
delete_game(r.id)
$("#gamelist").append(li)
$("#gamelist").show()

delete_game = (id) ->
deleteReq = $.ajax
url : '/api?type=deletegame&id=' + id

deleteReq.done (res, status, jqXHR) ->
location.reload()
6 changes: 6 additions & 0 deletions css/stats.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
background-color: #eee;
}
.container {
max-width: 330px;
}
22 changes: 22 additions & 0 deletions html/admin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<head>
<script src="jquery.min.js"></script>
<script src="jquery.cookie.js"></script>
<script src="admin.js"></script>
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-theme.min.css">
<script src="bootstrap.min.js"></script>
<link rel="stylesheet" href="stats.css">
<title>Avalon</title>
</head>

<body>
<div class="container">
<h2 style="text-align: center">Games</h2>

<div id="gamelist" class="list-group"></div>
</div>
</body>
</html>
20 changes: 20 additions & 0 deletions html/game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<head>
<script src="jquery.min.js"></script>
<script src="jquery.cookie.js"></script>
<script src="stats.js"></script>
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-theme.min.css">
<script src="bootstrap.min.js"></script>
<link rel="stylesheet" href="stats.css">
<title>Avalon</title>
</head>

<body>
<div class="container">
<h2 style="text-align: center">Game</h2>
</div>
</body>
</html>
22 changes: 22 additions & 0 deletions html/games.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<head>
<script src="jquery.min.js"></script>
<script src="jquery.cookie.js"></script>
<script src="stats.js"></script>
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-theme.min.css">
<script src="bootstrap.min.js"></script>
<link rel="stylesheet" href="stats.css">
<title>Avalon</title>
</head>

<body>
<div class="container">
<h2 style="text-align: center">Games</h2>

<div id="gamelist" class="list-group"></div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions server/default_config.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PORT = 80
IP = "192.168.1.1"
DEBUG = true
ADMINPW = "adminpassword_changeme"
15 changes: 14 additions & 1 deletion server/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@ app.get '/games', (req, res) ->
app.get '/game', (req, res) ->
res.sendfile(__dirname + '/html/game.html')

app.get '/admin', (req, res) ->
res.sendfile(__dirname + '/html/admin.html')

app.get '/api', (req, res) ->
return if not req.query['type']
switch req.query['type']
when "games"
req_state = req.query['gamestate']
if not req_state
req_state = GAME_FINISHED
else
req_state = parseInt(req_state)

Game.find {}, (err, games) ->
response = []
for g in games
if g.state != GAME_FINISHED
if g.state != req_state
continue

response.push
Expand All @@ -37,6 +46,10 @@ app.get '/api', (req, res) ->
when "game"
Game.findById req.query['id'], (err, game) ->
res.send(game)
when "deletegame"
Game.findByIdAndRemove req.query['id'], () ->
console.log "removed"
res.send("{success: true}")
else
res.send("{blah: 'blah'}")

Expand Down

0 comments on commit 62984f9

Please sign in to comment.