1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<!--
- SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<span role="img"
:aria-label="title"
:title="title"
class="app-score__wrapper">
<NcIconSvgWrapper v-for="index in fullStars"
:key="`full-star-${index}`"
:path="mdiStar"
inline />
<NcIconSvgWrapper v-if="hasHalfStar" :path="mdiStarHalfFull" inline />
<NcIconSvgWrapper v-for="index in emptyStars"
:key="`empty-star-${index}`"
:path="mdiStarOutline"
inline />
</span>
</template>
<script lang="ts">
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
import { mdiStar, mdiStarHalfFull, mdiStarOutline } from '@mdi/js'
import { translate as t } from '@nextcloud/l10n'
import { defineComponent } from 'vue'
export default defineComponent({
name: 'AppScore',
components: {
NcIconSvgWrapper,
},
props: {
score: {
type: Number,
required: true,
},
},
setup() {
return {
mdiStar,
mdiStarHalfFull,
mdiStarOutline,
}
},
computed: {
title() {
const appScore = (this.score * 5).toFixed(1)
return t('settings', 'Community rating: {score}/5', { score: appScore })
},
fullStars() {
return Math.floor(this.score * 5 + 0.25)
},
emptyStars() {
return Math.min(Math.floor((1 - this.score) * 5 + 0.25), 5 - this.fullStars)
},
hasHalfStar() {
return (this.fullStars + this.emptyStars) < 5
},
},
})
</script>
<style scoped>
.app-score__wrapper {
display: inline-flex;
color: var(--color-favorite, #a08b00);
> * {
vertical-align: text-bottom;
}
}
</style>
|