diff options
-rw-r--r-- | public/style.css | 18 | ||||
-rw-r--r-- | server.js | 27 | ||||
-rw-r--r-- | views/games_active.pug | 11 | ||||
-rw-r--r-- | views/games_finished.pug | 7 | ||||
-rw-r--r-- | views/games_public.pug | 8 | ||||
-rw-r--r-- | views/head.pug | 15 | ||||
-rw-r--r-- | views/info.pug | 10 | ||||
-rw-r--r-- | views/user.pug | 10 |
8 files changed, 75 insertions, 31 deletions
diff --git a/public/style.css b/public/style.css index e7a87c8..fc70bb7 100644 --- a/public/style.css +++ b/public/style.css @@ -173,15 +173,15 @@ article hr + p { font-style: italic; } } .game_head { background-color: gainsboro } .game_main { background-color: whitesmoke } -.game_list.open .game_head { background-color: lightskyblue } -.game_list.open .game_main { background-color: aliceblue } -.game_list.replacement .game_head { background-color: thistle } -.game_list.replacement .game_main { background-color: lavenderblush } -.game_list.finished .game_head { background-color: silver } -.game_list.finished .game_main { background-color: gainsboro } +.game_item.open .game_head { background-color: lightskyblue } +.game_item.open .game_main { background-color: aliceblue } +.game_item.replacement .game_head { background-color: thistle } +.game_item.replacement .game_main { background-color: lavenderblush } +.game_item.finished .game_head { background-color: silver } +.game_item.finished .game_main { background-color: gainsboro } .game_item.your_turn .game_head { background-color: gold } .game_item.your_turn .game_main { background-color: ivory } -.game_list a:hover { color: navy } -.game_list.open a:hover { color: blue } -.game_list.replacement a:hover { color: purple } +.game_item a:hover { color: navy } +.game_item.open a:hover { color: blue } +.game_item.replacement a:hover { color: purple } .game_item.your_turn a:hover { color: maroon } @@ -567,7 +567,14 @@ app.get('/user/:who_name', function (req, res) { who.avatar = get_avatar(who.mail) who.ctime = human_date(who.ctime) who.atime = human_date(who.atime) - res.render('user.pug', { user: req.user, who: who }) + let games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({ user_id: who.user_id }) + annotate_games(games, 0) + res.render('user.pug', { + user: req.user, + who: who, + active_games: games.filter(game => !is_finished_game(game)), + finished_games: games.filter(is_finished_game), + }) } else { return res.status(404).send("Invalid user name.") } @@ -1098,7 +1105,7 @@ app.get('/games', 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 games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({ user_id: req.user.user_id }) annotate_games(games, req.user.user_id) res.render('games_active.pug', { user: req.user, @@ -1115,10 +1122,26 @@ app.get('/games/finished', must_be_logged_in, function (req, res) { annotate_games(games, req.user.user_id) res.render('games_finished.pug', { user: req.user, + who: req.user, finished_games: games, }) }) +app.get('/games/finished/:who_name', function (req, res) { + let who = SQL_SELECT_USER_BY_NAME.get(req.params.who_name) + if (who) { + let games = QUERY_LIST_FINISHED_GAMES_OF_USER.all({ user_id: who.user_id }) + annotate_games(games, 0) + res.render('games_finished.pug', { + user: req.user, + who: who, + finished_games: games, + }) + } else { + return res.status(404).send("Invalid user name.") + } +}) + app.get('/games/public', function (req, res) { let games = QUERY_LIST_PUBLIC_GAMES.all() if (req.user) diff --git a/views/games_active.pug b/views/games_active.pug index 16d8ceb..a72a203 100644 --- a/views/games_active.pug +++ b/views/games_active.pug @@ -13,24 +13,23 @@ html if ready_games.length > 0 h2 Ready to start - +gamelist(ready_games, "ready") + +gamelist(ready_games) if open_games.length > 0 h2 Open - +gamelist(open_games, "open") + +gamelist(open_games) if replacement_games.length > 0 h2 Need replacement - +gamelist(replacement_games, "replacement") + +gamelist(replacement_games) if active_games.length > 0 h2 Active - +gamelist(active_games, "active") - + +gamelist(active_games) if finished_games.length > 0 h2 Recently finished - +gamelist(finished_games, "finished") + +gamelist(finished_games) p <a href="/games/finished">All your finished games</a> diff --git a/views/games_finished.pug b/views/games_finished.pug index c6fa66d..df7f038 100644 --- a/views/games_finished.pug +++ b/views/games_finished.pug @@ -7,9 +7,12 @@ html body include header article - h1 Your finished games + if user && user.user_id === who.user_id + h1 Your finished games + else + h1 #{who.name}’s finished games if finished_games.length > 0 - +gamelist(finished_games, "finished") + +gamelist(finished_games) else p Nothing here. diff --git a/views/games_public.pug b/views/games_public.pug index a681419..9c56402 100644 --- a/views/games_public.pug +++ b/views/games_public.pug @@ -13,20 +13,20 @@ html h2 Open if open_games.length > 0 - +gamelist(open_games, "open") + +gamelist(open_games) else p No open games. if replacement_games.length > 0 h2 Need replacement - +gamelist(replacement_games, "replacement") + +gamelist(replacement_games) if ready_games.length > 0 h2 Ready to start - +gamelist(ready_games, "ready") + +gamelist(ready_games) h2 Active if active_games.length > 0 - +gamelist(active_games, "active") + +gamelist(active_games) else p No open games. diff --git a/views/head.pug b/views/head.pug index 911def4..748d417 100644 --- a/views/head.pug +++ b/views/head.pug @@ -34,11 +34,20 @@ mixin forumpost(row,show_buttons) | | #[a(href="/forum/reply/"+row.post_id) Reply] -mixin gamelist(list,status,hide_title=0) - div.game_list(class=status) +mixin gamelist(list,hide_title=0) + div.game_list each item in list div - div.game_item(class=item.your_turn ? "your_turn" : "") + - + let className = "game_item" + if (item.your_turn) className += " your_turn" + if (item.status === 0 && !item.is_ready) className += " open" + else if (item.status === 0 && item.is_ready) className += " ready" + else if (item.status === 1 && !item.is_ready) className += " replacement" + else if (item.status === 1 && item.is_ready) className += " active" + else if (item.status === 2) className += " finished" + + div(class=className) div.game_head if item.scenario.length <= 2 div diff --git a/views/info.pug b/views/info.pug index c7083ef..24425e5 100644 --- a/views/info.pug +++ b/views/info.pug @@ -21,25 +21,25 @@ html h2 Open if open_games.length > 0 - +gamelist(open_games, "open", true) + +gamelist(open_games, true) else p No open games. if replacement_games.length > 0 h2 Need replacement - +gamelist(replacement_games, "replacement", true) + +gamelist(replacement_games, true) p a(href="/create/"+title.title_id) Create a new game if ready_games.length > 0 h2 Ready to start - +gamelist(ready_games, "ready", true) + +gamelist(ready_games, true) if active_games.length > 0 h2 Active - +gamelist(active_games, "active", true) + +gamelist(active_games, true) if finished_games.length > 0 h2 Recently finished - +gamelist(finished_games, "finished", true) + +gamelist(finished_games, true) diff --git a/views/user.pug b/views/user.pug index 99420cc..73c2e2d 100644 --- a/views/user.pug +++ b/views/user.pug @@ -21,3 +21,13 @@ html if user p a(href="/message/send/"+who.name) Send message + + if active_games.length > 0 + h2 Playing + +gamelist(active_games) + + if finished_games.length > 0 + h2 Recently finished + +gamelist(finished_games) + + p <a href="/games/finished/#{who.name}">All #{who.name}'s finished games</a> |