Commit | Line | Data |
---|---|---|
85e5b5c1 | 1 | <template lang="pug"> |
7aa548e7 BA |
2 | div |
3 | table | |
4f887105 BA |
4 | thead |
5 | tr | |
602d6bef BA |
6 | th {{ st.tr["Variant"] }} |
7 | th {{ st.tr["From"] }} | |
f44fd3bf | 8 | th {{ st.tr["Cadence"] }} |
4f887105 | 9 | tbody |
bd76b456 BA |
10 | tr(v-for="c in sortedChallenges" :class="{toyou:c.priority==1,fromyou:c.priority==2}" @click="$emit('click-challenge',c)") |
11 | td {{ c.vname }} | |
12 | td {{ c.from.name || "@nonymous" }} | |
13 | td {{ c.cadence }} | |
85e5b5c1 BA |
14 | </template> |
15 | ||
16 | <script> | |
0b0dc040 | 17 | import { store } from "@/store"; |
85e5b5c1 BA |
18 | export default { |
19 | name: "my-challenge-list", | |
dac39588 | 20 | props: ["challenges"], |
0b0dc040 BA |
21 | data: function() { |
22 | return { | |
23 | st: store.state, | |
24 | }; | |
25 | }, | |
26 | computed: { | |
27 | sortedChallenges: function() { | |
28 | // Show in order: challenges I sent, challenges I received, other challenges | |
bd76b456 BA |
29 | let minAdded = Number.MAX_SAFE_INTEGER |
30 | let maxAdded = 0 | |
0b0dc040 BA |
31 | let augmentedChalls = this.challenges.map(c => { |
32 | let priority = 0; | |
33 | if (c.to == this.st.user.name) | |
34 | priority = 1; | |
bd76b456 | 35 | else if (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id) |
0b0dc040 | 36 | priority = 2; |
bd76b456 BA |
37 | if (c.added < minAdded) |
38 | minAdded = c.added; | |
39 | if (c.added > maxAdded) | |
40 | maxAdded = c.added | |
0b0dc040 BA |
41 | return Object.assign({}, c, {priority: priority}); |
42 | }); | |
bd76b456 BA |
43 | const deltaAdded = maxAdded - minAdded; |
44 | return augmentedChalls.sort((c1,c2) => { | |
45 | return c2.priority - c1.priority + (c2.added - c1.added) / deltaAdded; | |
46 | }); | |
0b0dc040 BA |
47 | }, |
48 | }, | |
85e5b5c1 | 49 | }; |
85e5b5c1 | 50 | </script> |
bd76b456 BA |
51 | |
52 | <style lang="sass" scoped> | |
53 | // TODO: understand why the style applied to <tr> element doesn't work | |
54 | tr.fromyou > td | |
55 | font-style: italic | |
56 | tr.toyou > td | |
57 | background-color: #fcd785 | |
58 | </style> |