Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 3fb42e7

Browse files
add Leaderboard popup component, update Ballot
1 parent 860035b commit 3fb42e7

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

src/components/Leaderboard.vue

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<template>
2+
<div class="text-center">
3+
<v-dialog v-model="dialog" width="500">
4+
<template v-slot:activator="{ on, attrs }">
5+
<v-btn color="#fdc743" dark v-bind="attrs" v-on="on">
6+
See Full Leaderboard
7+
</v-btn>
8+
</template>
9+
10+
<v-card>
11+
<v-card-title class="headline grey lighten-2">
12+
Our Vote Leaders
13+
</v-card-title>
14+
15+
<v-card-text>
16+
<v-data-table :headers="headers" :items="pageData.items"
17+
:items-per-page="5" class="elevation-1" width: />
18+
</v-card-text>
19+
20+
<v-divider></v-divider>
21+
22+
<v-card-actions>
23+
<v-spacer></v-spacer>
24+
<v-btn color="cancel" text @click="dialog = false">
25+
Close
26+
</v-btn>
27+
</v-card-actions>
28+
</v-card>
29+
</v-dialog>
30+
</div>
31+
</template>
32+
33+
<script>
34+
import Vue from "vue";
35+
import { voting } from "@/api";
36+
export default {
37+
name: "Leaderboard",
38+
data() {
39+
return {
40+
dialog: false,
41+
headers: [
42+
{ text: "Rank", sortable: true, value: "rank" },
43+
{ text: "First Name", sortable: false, value: "firstName" },
44+
{ text: "Last Name", sortable: false, value: "lastName" },
45+
{ text: "Votes", sortable: true, value: "numVotes" }
46+
],
47+
entries: [],
48+
pageData: {
49+
hasNext: false,
50+
hasPrev: false,
51+
nextNum: false,
52+
page: 1,
53+
items: [],
54+
prevNum: null,
55+
totalItems: 0,
56+
totalPages: 0
57+
}
58+
};
59+
},
60+
mounted() {
61+
this.fetchData();
62+
},
63+
methods: {
64+
async fetchData() {
65+
const results = await voting.getBallot(1, 1000);
66+
await this.setResult(results);
67+
},
68+
async setResult(result) {
69+
await new Promise(resolve => {
70+
setTimeout(async () => {
71+
for (const [key, value] of Object.entries(result)) {
72+
if (key !== "items") {
73+
Vue.set(this.pageData, key, value);
74+
}
75+
}
76+
77+
const items = result.items
78+
.filter(i => i.disqualified === null)
79+
.sort((a, b) => {
80+
return a.numVotes < b.numVotes ? 1 : -1;
81+
});
82+
83+
// add rank
84+
let counter = 1;
85+
for (let i = 0; i < items.length; i++) {
86+
items[i] = {
87+
...items[i],
88+
rank: counter
89+
};
90+
counter++;
91+
}
92+
93+
Vue.set(this.pageData, "items", items);
94+
resolve();
95+
}, 500);
96+
});
97+
}
98+
}
99+
};
100+
</script>
101+
102+
<style></style>

src/views/Voting/Ballot.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<v-row>
3333
<v-col>
3434
<BallotLeaders />
35+
<Leaderboard />
3536
</v-col>
3637
</v-row>
3738
</v-container>
@@ -68,12 +69,14 @@
6869

6970
<script>
7071
import BallotLeaders from "./BallotLeaders";
72+
import Leaderboard from "@/components/Leaderboard";
7173
import VoteLeaderboardSearch from "@/components/VoteLeaderboardSearch";
7274
7375
export default {
7476
name: "Ballot",
7577
components: {
7678
BallotLeaders,
79+
Leaderboard,
7780
VoteLeaderboardSearch
7881
},
7982
methods: {

src/views/Voting/VoteOverLeaderboard.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
</template>
4949

5050
<script>
51+
// TODO: this component is not being used
5152
// TODO: this component is largely copy pasted from Ballot - they should be consolidated at some point
5253
import VoteLeaderboardSearch from "@/components/VoteLeaderboardSearch";
5354

0 commit comments

Comments
 (0)