Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion frontend/src/components/Vote/VoteRating.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@
</span>
</div>

<template v-if="round.show_stats && votesStats?.stats">
<h3 class="vote-section-title">{{ $t('montage-vote-my-stats') }}</h3>
<div class="vote-stats">
<div
v-for="(count, label) in votesStats.stats"
:key="label"
class="vote-stats-item"
>
<span class="vote-stats-label">{{ label }} <star class="icon-small" /></span>
<span class="vote-stats-count">{{ count }}</span>
</div>
</div>
</template>

<h3 class="vote-section-title">{{ $t('montage-vote-actions') }}</h3>
<div class="vote-actions">
<div>
Expand Down Expand Up @@ -166,7 +180,7 @@
</template>

<script setup>
import { ref, watch, computed } from 'vue'
import { ref, watch, computed, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import jurorService from '@/services/jurorService'
import { useRouter } from 'vue-router'
Expand Down Expand Up @@ -200,6 +214,8 @@ const voteContainer = ref(null)
const showSidebar = ref(true)
const imageCache = new Map()
const isLoading = ref(false)
const votesStats = ref(null)
let votesStatsRequestId = 0

const props = defineProps({
round: Object,
Expand Down Expand Up @@ -263,6 +279,22 @@ function getTasks() {
})
}

function fetchVotesStats() {
const requestId = ++votesStatsRequestId
jurorService
.getRoundVotesStats(props.round.id)
.then((response) => {
if (requestId === votesStatsRequestId) {
votesStats.value = response
}
})
.catch((error) => {
if (requestId === votesStatsRequestId) {
alertService.error(error)
}
})
}

function setRate(rate) {
if (imageLoading.value) return
if (isLoading.value) return
Expand All @@ -279,6 +311,7 @@ function setRate(rate) {
if (stats.value.total_open_tasks <= 10) {
skips.value = 0
}
if (props.round.show_stats) fetchVotesStats()
if (counter.value === 4 || !stats.value.total_open_tasks) {
counter.value = 0
getTasks()
Expand Down Expand Up @@ -417,6 +450,12 @@ watch(voteContainer, () => {
voteContainer.value.focus()
}
})

onMounted(() => {
if (props.round.show_stats) {
fetchVotesStats()
}
})
</script>

<style scoped>
Expand Down Expand Up @@ -605,4 +644,34 @@ watch(voteContainer, () => {
margin-top: 24px;
width: 232px;
}

.vote-stats {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 8px;
}

.vote-stats-item {
display: flex;
align-items: center;
gap: 6px;
background: #f0f0f0;
border-radius: 4px;
padding: 4px 10px;
font-size: 13px;
}

.vote-stats-label {
display: flex;
align-items: center;
gap: 4px;
font-weight: 500;
color: rgba(0, 0, 0, 0.6);
}

.vote-stats-count {
font-weight: 700;
color: rgba(0, 0, 0, 0.87);
}
</style>
70 changes: 69 additions & 1 deletion frontend/src/components/Vote/VoteYesNo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@
</span>
</div>

<template v-if="round.show_stats && votesStats?.stats">
<h3 class="vote-section-title">{{ $t('montage-vote-my-stats') }}</h3>
<div class="vote-stats">
<div
v-for="(count, label) in votesStats.stats"
:key="label"
class="vote-stats-item"
>
<span class="vote-stats-label">
{{ $t(label === 'yes' ? 'montage-vote-accept' : 'montage-vote-decline') }}
</span>
<span class="vote-stats-count">{{ count }}</span>
</div>
</div>
</template>

<h3 class="vote-section-title">{{ $t('montage-vote-actions') }}</h3>
<div class="vote-actions">
<div>
Expand Down Expand Up @@ -170,7 +186,7 @@
</template>

<script setup>
import { ref, watch, computed } from 'vue'
import { ref, watch, computed, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import jurorService from '@/services/jurorService'
import { useRouter } from 'vue-router'
Expand Down Expand Up @@ -215,6 +231,8 @@ const roundLink = [props.round.id, props.round.canonical_url_name].join('-')
const isLoading = ref(false)
const images = ref(null)
const stats = ref(null)
const votesStats = ref(null)
let votesStatsRequestId = 0

const rating = ref({
current: null,
Expand Down Expand Up @@ -268,6 +286,22 @@ const getTasks = () => {
})
}

function fetchVotesStats() {
const requestId = ++votesStatsRequestId
jurorService
.getRoundVotesStats(props.round.id)
.then((response) => {
if (requestId === votesStatsRequestId) {
votesStats.value = response
}
})
.catch((error) => {
if (requestId === votesStatsRequestId) {
alertService.error(error)
}
})
}

function setRate(rate) {
if (imageLoading.value) return
if (isLoading.value) return
Expand All @@ -284,6 +318,7 @@ function setRate(rate) {
if (stats.value.total_open_tasks <= 10) {
skips.value = 0
}
if (props.round.show_stats) fetchVotesStats()
if (counter.value === 4 || !stats.value.total_open_tasks) {
counter.value = 0
getTasks()
Expand Down Expand Up @@ -424,6 +459,12 @@ watch(voteContainer, () => {
voteContainer.value.focus()
}
})

onMounted(() => {
if (props.round.show_stats) {
fetchVotesStats()
}
})
</script>

<style scoped>
Expand Down Expand Up @@ -612,4 +653,31 @@ watch(voteContainer, () => {
margin-top: 24px;
width: 232px;
}

.vote-stats {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 8px;
}

.vote-stats-item {
display: flex;
align-items: center;
gap: 6px;
background: #f0f0f0;
border-radius: 4px;
padding: 4px 10px;
font-size: 13px;
}

.vote-stats-label {
font-weight: 500;
color: rgba(0, 0, 0, 0.6);
}

.vote-stats-count {
font-weight: 700;
color: rgba(0, 0, 0, 0.87);
}
</style>
1 change: 1 addition & 0 deletions frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"montage-vote-grid-size-large": "Large",
"montage-vote-grid-size-medium": "Medium",
"montage-vote-grid-size-small": "Small",
"montage-vote-my-stats": "My voting statistics",
"montage-vote-image-review": "Image review #{0}",
"montage-vote-ordinal-place": "{0} place",
"montage-vote-order-by": "Order by:",
Expand Down