diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-04-15 14:34:49 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-04-15 14:34:49 +0200 |
commit | 8eb1b2f8c4565be28531a057a747cda14512f444 (patch) | |
tree | 7fd4cb45adbc35fb3214284791ce6b646f324e83 /server.js | |
parent | dadc4ca510d5e45e270faa04775f377d8ff40412 (diff) | |
download | server-8eb1b2f8c4565be28531a057a747cda14512f444.tar.gz |
Separate profile and active game list pages.
Also show number of games where it is your turn in the header.
Only show finished games from last week on active games page.
Add separate finished games page to see all of them.
# Conflicts:
# views/tournament-games.pug
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 95 |
1 files changed, 71 insertions, 24 deletions
@@ -250,7 +250,19 @@ const SQL_SELECT_USER_INFO = SQL(` to_id = user_id and is_read = 0 and is_deleted_from_inbox = 0 - ) as unread + ) as unread, + ( + select + count(*) + from + players + join games using(game_id) + join game_state using(game_id) + where + status = 1 + and players.user_id = users.user_id + and active in ( players.role, 'Both', 'All' ) + ) as active from users where user_id = ? @@ -942,10 +954,22 @@ const QUERY_LIST_GAMES_OF_TITLE = SQL(` LIMIT ? `); -const QUERY_LIST_GAMES_OF_USER = SQL(` - SELECT * FROM game_view - WHERE owner_id=$user_id OR game_id IN ( SELECT game_id FROM players WHERE players.user_id=$user_id ) - ORDER BY status ASC, mtime DESC +const QUERY_LIST_ACTIVE_GAMES_OF_USER = SQL(` + select * from game_view + where + ( owner_id=$user_id or game_id in ( select game_id from players where players.user_id=$user_id ) ) + and + ( status < 2 or mtime > datetime('now', '-7 days') ) + order by status asc, mtime desc + `); + +const QUERY_LIST_FINISHED_GAMES_OF_USER = SQL(` + select * from game_view + where + ( owner_id=$user_id or game_id in ( select game_id from players where players.user_id=$user_id ) ) + and + status = 2 + order by status asc, mtime desc `); function is_active(game, players, user_id) { @@ -1020,35 +1044,29 @@ function annotate_games(games, user_id) { } } -app.get('/games', function (req, res) { - let open_games = QUERY_LIST_GAMES.all(0); - let active_games = QUERY_LIST_GAMES.all(1); - if (req.user) { - annotate_games(open_games, req.user.user_id); - annotate_games(active_games, req.user.user_id); - } else { - annotate_games(open_games, 0); - annotate_games(active_games, 0); - } - res.render('games.pug', { +app.get('/profile', must_be_logged_in, function (req, res) { + req.user.notify = SQL_SELECT_USER_NOTIFY.get(req.user.user_id); + let avatar = get_avatar(req.user.mail); + res.render('profile.pug', { user: req.user, - open_games: open_games.filter(g => !g.is_ready), - ready_games: open_games.filter(g => g.is_ready), - active_games: active_games, + avatar: avatar, }); }); -app.get('/profile', must_be_logged_in, function (req, res) { +app.get('/games', function (req, res) { + res.redirect('/games/public'); +}); + +app.get('/games/active', must_be_logged_in, function (req, res) { req.user.notify = SQL_SELECT_USER_NOTIFY.get(req.user.user_id); - let avatar = get_avatar(req.user.mail); - let games = QUERY_LIST_GAMES_OF_USER.all({user_id: req.user.user_id}); + let games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({user_id: req.user.user_id}); annotate_games(games, req.user.user_id); let open_games = games.filter(game => game.status === 0); let active_games = games.filter(game => game.status === 1); let finished_games = games.filter(game => game.status === 2); - res.render('profile.pug', { + res.render('games_active.pug', { + title: "Your Active Games", user: req.user, - avatar: avatar, open_games: open_games.filter(g => !g.is_ready), ready_games: open_games.filter(g => g.is_ready), active_games: active_games, @@ -1056,6 +1074,35 @@ app.get('/profile', must_be_logged_in, function (req, res) { }); }); +app.get('/games/finished', must_be_logged_in, function (req, res) { + req.user.notify = SQL_SELECT_USER_NOTIFY.get(req.user.user_id); + let games = QUERY_LIST_FINISHED_GAMES_OF_USER.all({user_id: req.user.user_id}); + annotate_games(games, req.user.user_id); + res.render('games_finished.pug', { + title: "Your Finished Games", + user: req.user, + finished_games: games, + }); +}); + +app.get('/games/public', function (req, res) { + let open_games = QUERY_LIST_GAMES.all(0); + let active_games = QUERY_LIST_GAMES.all(1); + if (req.user) { + annotate_games(open_games, req.user.user_id); + annotate_games(active_games, req.user.user_id); + } else { + annotate_games(open_games, 0); + annotate_games(active_games, 0); + } + res.render('games_public.pug', { + user: req.user, + open_games: open_games.filter(g => !g.is_ready), + ready_games: open_games.filter(g => g.is_ready), + active_games: active_games, + }); +}); + app.get('/info/:title_id', function (req, res) { return res.redirect('/' + req.params.title_id); }); |