summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server.js32
-rw-r--r--views/games_active.pug23
-rw-r--r--views/user.pug14
3 files changed, 42 insertions, 27 deletions
diff --git a/server.js b/server.js
index 0afdac9..1e4a2bd 100644
--- a/server.js
+++ b/server.js
@@ -1419,37 +1419,37 @@ const QUERY_LIST_PUBLIC_GAMES_REPLACEMENT = SQL(`
const QUERY_LIST_PUBLIC_GAMES_ACTIVE = SQL(`
select * from game_view_public where status = 1 and join_count = player_count
- order by mtime desc, ctime desc
+ order by mtime desc
limit 12
`)
const QUERY_LIST_PUBLIC_GAMES_FINISHED = SQL(`
select * from game_view_public where status = 2
- order by mtime desc, ctime desc
+ order by mtime desc
limit 12
`)
const QUERY_LIST_GAMES_OF_TITLE_OPEN = SQL(`
select * from game_view_public where title_id=? and status = 0 and join_count < player_count
and not exists ( select 1 from contacts where me = owner_id and you = ? and relation < 0 )
- order by mtime desc, ctime desc
+ order by game_id desc
`)
const QUERY_LIST_GAMES_OF_TITLE_REPLACEMENT = SQL(`
select * from game_view_public where title_id=? and status = 1 and join_count < player_count
and not exists ( select 1 from contacts where me = owner_id and you = ? and relation < 0 )
- order by mtime desc, ctime desc
+ order by game_id desc
`)
const QUERY_LIST_GAMES_OF_TITLE_ACTIVE = SQL(`
select * from game_view_public where title_id=? and status = 1 and join_count = player_count
- order by mtime desc, ctime desc
+ order by mtime desc
limit 12
`)
const QUERY_LIST_GAMES_OF_TITLE_FINISHED = SQL(`
select * from game_view_public where title_id=? and status = 2
- order by mtime desc, ctime desc
+ order by mtime desc
limit 12
`)
@@ -1482,7 +1482,7 @@ const QUERY_LIST_ACTIVE_GAMES_OF_USER = SQL(`
( owner_id=$user_id or game_id in ( select game_id from players where players.user_id=$user_id ) )
and
( status <= ${STATUS_FINISHED} )
- order by status asc, mtime desc
+ order by game_id desc
`)
const QUERY_LIST_FINISHED_GAMES_OF_USER = SQL(`
@@ -1600,14 +1600,6 @@ app.get("/games", function (_req, res) {
res.redirect("/games/public")
})
-function sort_your_turn(a, b) {
- if (a.is_opposed && b.is_opposed) {
- if (a.your_turn && !b.your_turn) return -1
- if (!a.your_turn && b.your_turn) return 1
- }
- return 0
-}
-
app.get("/games/next", must_be_logged_in, function (req, res) {
let next = QUERY_NEXT_GAME_OF_USER.get(req.user.user_id)
if (next !== undefined)
@@ -1617,11 +1609,11 @@ app.get("/games/next", must_be_logged_in, function (req, res) {
})
app.get("/games/active", must_be_logged_in, function (req, res) {
- let games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({ user_id: req.user.user_id })
- let unread = SQL_SELECT_UNREAD_CHAT_GAMES.all(req.user.user_id)
- annotate_games(games, req.user.user_id, unread)
- games.sort(sort_your_turn)
- res.render("games_active.pug", { user: req.user, who: req.user, games })
+ let user_id = req.user.user_id
+ let games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({ user_id })
+ let unread = SQL_SELECT_UNREAD_CHAT_GAMES.all(user_id)
+ annotate_games(games, user_id, unread)
+ res.render("games_active.pug", { user: req.user, who: req.user, games, seeds, active_pools, finished_pools })
})
app.get("/games/finished", must_be_logged_in, function (req, res) {
diff --git a/views/games_active.pug b/views/games_active.pug
index a65f9be..76ac030 100644
--- a/views/games_active.pug
+++ b/views/games_active.pug
@@ -1,7 +1,11 @@
//- vim:ts=4:sw=4:
-- let open_games = games.filter(game => game.status === 0)
-- let active_games = games.filter(game => game.status === 1)
+- let open_games = games.filter(game => game.status === 0 && !game.is_match)
+- let future_games = games.filter(game => game.status === 0 && game.is_match)
+- let active_games = games.filter(game => game.status === 1 && game.is_opposed && !game.your_turn)
+- let move_games = games.filter(game => game.status === 1 && game.is_opposed && game.your_turn)
+- let solo_games = games.filter(game => game.status === 1 && !game.is_opposed)
- let finished_games = games.filter(game => game.status === 2)
+- move_games.sort((a,b)=>a.time_left-b.time_left)
doctype html
html
head
@@ -21,16 +25,25 @@ html
p
a(href="/create") Create a new game
+ if move_games.length > 0
+ h2 Move
+ +gamelist(move_games)
+
if active_games.length > 0
h2 Active
+gamelist(active_games)
+ if solo_games.length > 0
+ h2 Solo
+ +gamelist(solo_games)
+
+ if future_games.length > 0
+ h2 Future
+ +gamelist(future_games)
+
if finished_games.length > 0
h2 Recently finished
+gamelist(finished_games)
- if open_games.length === 0 && active_games.length === 0 && finished_games.length === 0
- p Nothing here.
-
p
a(href="/games/finished") All your finished games
diff --git a/views/user.pug b/views/user.pug
index dbadd36..ce5b5f0 100644
--- a/views/user.pug
+++ b/views/user.pug
@@ -1,6 +1,8 @@
//- vim:ts=4:sw=4:
-- let open_games = games.filter(game => game.status === 0)
-- let active_games = games.filter(game => game.status === 1)
+- let open_games = games.filter(game => game.status === 0 && !game.is_match)
+- let future_games = games.filter(game => game.status === 0 && game.is_match)
+- let active_games = games.filter(game => game.status === 1 && game.is_opposed)
+- let solo_games = games.filter(game => game.status === 1 && !game.is_opposed)
- let finished_games = games.filter(game => game.status === 2)
doctype html
html
@@ -48,6 +50,14 @@ html
h2 Active
+gamelist(active_games)
+ if solo_games.length > 0
+ h2 Solo
+ +gamelist(solo_games)
+
+ if future_games.length > 0
+ h2 Future
+ +gamelist(future_games)
+
if finished_games.length > 0
h2 Recently finished
+gamelist(finished_games)