Commit | Line | Data |
---|---|---|
85e5b5c1 | 1 | <template lang="pug"> |
7aa548e7 BA |
2 | div |
3 | table | |
4f887105 BA |
4 | thead |
5 | tr | |
6 | th Variant | |
7 | th White | |
8 | th Black | |
9 | th Time control | |
10 | th(v-if="showResult") Result | |
11 | tbody | |
12 | tr(v-for="g in sortedGames" @click="$emit('show-game',g)" | |
13 | :class="{'my-turn': g.myTurn}") | |
14 | td(data-label="Variant") {{ g.vname }} | |
15 | td(data-label="White") {{ g.players[0].name || "@nonymous" }} | |
16 | td(data-label="Black") {{ g.players[1].name || "@nonymous" }} | |
17 | td(data-label="Time control") {{ g.timeControl }} | |
18 | td(v-if="showResult" data-label="Result") {{ g.score }} | |
85e5b5c1 BA |
19 | </template> |
20 | ||
21 | <script> | |
0b0dc040 BA |
22 | import { store } from "@/store"; |
23 | ||
85e5b5c1 BA |
24 | export default { |
25 | name: "my-game-list", | |
26 | props: ["games"], | |
0b0dc040 BA |
27 | data: function() { |
28 | return { | |
29 | st: store.state, | |
30 | showResult: false, | |
31 | }; | |
32 | }, | |
85e5b5c1 | 33 | computed: { |
0b0dc040 BA |
34 | sortedGames: function() { |
35 | // Show in order: games where it's my turn, my running games, my games, other games | |
36 | this.showResult = this.games.some(g => g.score != "*"); | |
37 | let augmentedGames = this.games.map(g => { | |
38 | let priority = 0; | |
39 | if (g.players.some(p => p.uid == this.st.user.id || p.sid == this.st.user.sid)) | |
40 | { | |
41 | priority++; | |
42 | if (g.score == "*") | |
43 | { | |
44 | priority++; | |
45 | const myColor = g.players[0].uid == this.st.user.id | |
46 | || g.players[0].sid == this.st.user.sid | |
47 | ? "w" | |
48 | : "b"; | |
49 | if (!!g.fen.match(" " + myColor + " ")) | |
50 | priority++; | |
51 | } | |
52 | } | |
41c80bb6 | 53 | return Object.assign({}, g, {priority: priority, myTurn: priority==3}); |
0b0dc040 BA |
54 | }); |
55 | return augmentedGames.sort((g1,g2) => { return g2.priority - g1.priority; }); | |
56 | }, | |
57 | }, | |
85e5b5c1 BA |
58 | }; |
59 | </script> | |
0b0dc040 | 60 | |
41c80bb6 BA |
61 | <style lang="sass" scoped> |
62 | // TODO: understand why the style applied to <tr> element doesn't work | |
63 | tr.my-turn > td | |
64 | background-color: #fcd785 | |
0b0dc040 | 65 | </style> |