From d0175eec70debe3fbabf1869f420e92c7313c2ad Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 10 Jul 2021 00:53:29 +0200 Subject: Fix yellow "your turn" coloring in join and profile pages. --- public/join.js | 8 +++++++- server.js | 8 ++++---- views/games.ejs | 10 ++-------- views/info.ejs | 10 ++-------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/public/join.js b/public/join.js index b0b93cf..19efcde 100644 --- a/public/join.js +++ b/public/join.js @@ -71,6 +71,12 @@ function start_event_source() { } } +function is_your_turn(player, role) { + if (player.user_id === user_id) + return (game.active_role === role || game.active_role === "Both" || game.active_role === "All"); + return false; +} + function update() { window.game_status.textContent = ["Open","Active","Finished","Abandoned"][game.status]; window.game_result.textContent = game.result || "\u2014"; @@ -85,7 +91,7 @@ function update() { let element = document.getElementById(role_id); if (player) { if (game.status > 0) { - if (game.active_role === role || game.active_role === "Both" || game.active_role === "All") + if (is_your_turn(player, role)) element.className = "is_your_turn"; else element.className = ""; diff --git a/server.js b/server.js index 65aacae..56e9ce7 100644 --- a/server.js +++ b/server.js @@ -554,7 +554,7 @@ for (let title_id of db.prepare("SELECT * FROM titles").pluck().all()) { const QUERY_GAME = db.prepare("SELECT * FROM game_view WHERE game_id = ?"); const QUERY_LIST_GAMES_OF_TITLE = db.prepare(` - SELECT *, ( active_id = ? OR active_role = 'Both' OR active_role = 'All' ) AS is_your_turn FROM game_view + SELECT * FROM game_view WHERE title_id = ? AND private = 0 ORDER BY status ASC, mtime DESC `); @@ -644,7 +644,7 @@ app.get('/info/:title_id', function (req, res) { return res.redirect('/'); } if (req.isAuthenticated()) { - let games = QUERY_LIST_GAMES_OF_TITLE.all(req.user.user_id, title_id); + let games = QUERY_LIST_GAMES_OF_TITLE.all(title_id); humanize(games); let open_games = games.filter(game => game.status === 0); let active_games = games.filter(game => game.status === 1); @@ -1375,11 +1375,11 @@ app.get('/users', function (req, res) { res.render('users.ejs', { user: req.user, message: req.flash('message'), userList: rows }); }); -const QUERY_LIST_GAMES = db.prepare("SELECT *, ( active_id = ? OR active_role = 'Both' OR active_role = 'All' ) AS is_your_turn FROM game_view WHERE private = 0 AND status < 2"); +const QUERY_LIST_GAMES = db.prepare("SELECT * FROM game_view WHERE private = 0 AND status < 2"); app.get('/games', must_be_logged_in, function (req, res) { LOG(req, "GET /join"); - let games = QUERY_LIST_GAMES.all(req.user.user_id); + let games = QUERY_LIST_GAMES.all(); humanize(games); let open_games = games.filter(game => game.status === 0); let active_games = games.filter(game => game.status === 1); diff --git a/views/games.ejs b/views/games.ejs index 4e6f2a4..a355910 100644 --- a/views/games.ejs +++ b/views/games.ejs @@ -33,14 +33,8 @@ td.nowrap a { color: black; text-decoration: none; } <%= row.player_names %> <%= row.description %> <%= row.mtime %> -<% - if (row.is_your_turn) { - %><%= row.active_role %><% - } else { - %><%= row.active_role %><% - } - %>Enter<% -%> +<%= row.active_role %> +Enter <% }); } else { %> No active games. <% } %> diff --git a/views/info.ejs b/views/info.ejs index 02ce2dd..fdfc974 100644 --- a/views/info.ejs +++ b/views/info.ejs @@ -38,14 +38,8 @@ Read more about the game on <%= row.player_names %> <%= row.description %> <%= row.mtime %> -<% - if (row.is_your_turn) { - %><%= row.active_role %><% - } else { - %><%= row.active_role %><% - } - %>Enter<% -%> +<%= row.active_role %> +Enter <% }); %> <% } %> -- cgit v1.2.3