2021-12-29 22:53:19 +01:00
|
|
|
<template>
|
2022-11-26 06:11:45 +01:00
|
|
|
<div>
|
2022-11-26 18:08:09 +01:00
|
|
|
<app-settings-content :header-text="$strings.HeaderLibraryStats + ': ' + currentLibraryName">
|
2022-11-26 06:11:45 +01:00
|
|
|
<stats-preview-icons v-if="totalItems" :library-stats="libraryStats" />
|
2021-12-29 22:53:19 +01:00
|
|
|
|
2022-11-26 06:11:45 +01:00
|
|
|
<div class="flex lg:flex-row flex-wrap justify-between flex-col mt-8">
|
|
|
|
<div class="w-80 my-6 mx-auto">
|
2023-02-11 22:02:56 +01:00
|
|
|
<h1 class="text-2xl mb-4">{{ $strings.HeaderStatsTop5Genres }}</h1>
|
2022-11-26 06:11:45 +01:00
|
|
|
<p v-if="!top5Genres.length">{{ $strings.MessageNoGenres }}</p>
|
|
|
|
<template v-for="genre in top5Genres">
|
|
|
|
<div :key="genre.genre" class="w-full py-2">
|
|
|
|
<div class="flex items-end mb-1">
|
|
|
|
<p class="text-2xl font-bold">{{ Math.round((100 * genre.count) / totalItems) }} %</p>
|
|
|
|
<div class="flex-grow" />
|
2023-02-11 22:02:56 +01:00
|
|
|
<nuxt-link :to="`/library/${currentLibraryId}/bookshelf?filter=genres.${$encode(genre.genre)}`" class="text-base text-white text-opacity-70 hover:underline">
|
2022-11-26 06:11:45 +01:00
|
|
|
{{ genre.genre }}
|
|
|
|
</nuxt-link>
|
2021-12-29 22:53:19 +01:00
|
|
|
</div>
|
2022-11-26 06:11:45 +01:00
|
|
|
<div class="w-full rounded-full h-3 bg-primary bg-opacity-50 overflow-hidden">
|
|
|
|
<div class="bg-yellow-400 h-full rounded-full" :style="{ width: Math.round((100 * genre.count) / totalItems) + '%' }" />
|
2021-12-29 22:53:19 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-26 06:11:45 +01:00
|
|
|
</template>
|
|
|
|
</div>
|
2023-08-19 23:53:33 +02:00
|
|
|
<div v-if="isBookLibrary" class="w-80 my-6 mx-auto">
|
2023-02-11 22:02:56 +01:00
|
|
|
<h1 class="text-2xl mb-4">{{ $strings.HeaderStatsTop10Authors }}</h1>
|
2022-11-26 06:11:45 +01:00
|
|
|
<p v-if="!top10Authors.length">{{ $strings.MessageNoAuthors }}</p>
|
|
|
|
<template v-for="(author, index) in top10Authors">
|
|
|
|
<div :key="author.id" class="w-full py-2">
|
|
|
|
<div class="flex items-center mb-1">
|
2023-02-11 22:02:56 +01:00
|
|
|
<p class="text-sm text-white text-opacity-70 w-36 pr-2 truncate">
|
2022-11-26 06:11:45 +01:00
|
|
|
{{ index + 1 }}. <nuxt-link :to="`/library/${currentLibraryId}/bookshelf?filter=authors.${$encode(author.id)}`" class="hover:underline">{{ author.name }}</nuxt-link>
|
|
|
|
</p>
|
|
|
|
<div class="flex-grow rounded-full h-2.5 bg-primary bg-opacity-0 overflow-hidden">
|
|
|
|
<div class="bg-yellow-400 h-full rounded-full" :style="{ width: Math.round((100 * author.count) / mostUsedAuthorCount) + '%' }" />
|
|
|
|
</div>
|
|
|
|
<div class="w-4 ml-3">
|
|
|
|
<p class="text-sm font-bold">{{ author.count }}</p>
|
|
|
|
</div>
|
2021-12-29 22:53:19 +01:00
|
|
|
</div>
|
2022-11-26 06:11:45 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
<div class="w-80 my-6 mx-auto">
|
2023-02-11 22:02:56 +01:00
|
|
|
<h1 class="text-2xl mb-4">{{ $strings.HeaderStatsLongestItems }}</h1>
|
2022-11-26 06:11:45 +01:00
|
|
|
<p v-if="!top10LongestItems.length">{{ $strings.MessageNoItems }}</p>
|
|
|
|
<template v-for="(ab, index) in top10LongestItems">
|
|
|
|
<div :key="index" class="w-full py-2">
|
|
|
|
<div class="flex items-center mb-1">
|
2023-02-11 22:02:56 +01:00
|
|
|
<p class="text-sm text-white text-opacity-70 w-44 pr-2 truncate">
|
2022-11-26 06:11:45 +01:00
|
|
|
{{ index + 1 }}. <nuxt-link :to="`/item/${ab.id}`" class="hover:underline">{{ ab.title }}</nuxt-link>
|
|
|
|
</p>
|
|
|
|
<div class="flex-grow rounded-full h-2.5 bg-primary bg-opacity-0 overflow-hidden">
|
|
|
|
<div class="bg-yellow-400 h-full rounded-full" :style="{ width: Math.round((100 * ab.duration) / longestItemDuration) + '%' }" />
|
|
|
|
</div>
|
|
|
|
<div class="w-4 ml-3">
|
|
|
|
<p class="text-sm font-bold">{{ (ab.duration / 3600).toFixed(1) }}</p>
|
|
|
|
</div>
|
2021-12-29 22:53:19 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-26 06:11:45 +01:00
|
|
|
</template>
|
|
|
|
</div>
|
2023-02-19 22:39:28 +01:00
|
|
|
<div class="w-80 my-6 mx-auto">
|
|
|
|
<h1 class="text-2xl mb-4">{{ $strings.HeaderStatsLargestItems }}</h1>
|
|
|
|
<p v-if="!top10LargestItems.length">{{ $strings.MessageNoItems }}</p>
|
|
|
|
<template v-for="(ab, index) in top10LargestItems">
|
|
|
|
<div :key="index" class="w-full py-2">
|
|
|
|
<div class="flex items-center mb-1">
|
|
|
|
<p class="text-sm text-white text-opacity-70 w-44 pr-2 truncate">
|
|
|
|
{{ index + 1 }}. <nuxt-link :to="`/item/${ab.id}`" class="hover:underline">{{ ab.title }}</nuxt-link>
|
|
|
|
</p>
|
|
|
|
<div class="flex-grow rounded-full h-2.5 bg-primary bg-opacity-0 overflow-hidden">
|
|
|
|
<div class="bg-yellow-400 h-full rounded-full" :style="{ width: Math.round((100 * ab.size) / largestItemSize) + '%' }" />
|
|
|
|
</div>
|
|
|
|
<div class="w-4 ml-3">
|
|
|
|
<p class="text-sm font-bold">{{ $bytesPretty(ab.size) }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
2021-12-29 22:53:19 +01:00
|
|
|
</div>
|
2022-11-26 06:11:45 +01:00
|
|
|
</app-settings-content>
|
2021-12-29 22:53:19 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2022-05-15 00:23:22 +02:00
|
|
|
asyncData({ redirect, store }) {
|
2023-06-16 00:41:27 +02:00
|
|
|
if (!store.getters['user/getIsAdminOrUp']) {
|
|
|
|
redirect('/')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-15 00:23:22 +02:00
|
|
|
if (!store.state.libraries.currentLibraryId) {
|
|
|
|
return redirect('/config')
|
|
|
|
}
|
|
|
|
return {}
|
|
|
|
},
|
2021-12-29 22:53:19 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
libraryStats: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
currentLibraryId(newVal, oldVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
user() {
|
|
|
|
return this.$store.state.user.user
|
|
|
|
},
|
2022-03-13 23:33:50 +01:00
|
|
|
totalItems() {
|
2023-08-19 23:53:33 +02:00
|
|
|
return this.libraryStats?.totalItems || 0
|
2021-12-29 22:53:19 +01:00
|
|
|
},
|
|
|
|
genresWithCount() {
|
2023-08-19 23:53:33 +02:00
|
|
|
return this.libraryStats?.genresWithCount || []
|
2021-12-29 22:53:19 +01:00
|
|
|
},
|
|
|
|
top5Genres() {
|
2023-08-19 23:53:33 +02:00
|
|
|
return this.genresWithCount?.slice(0, 5) || []
|
2021-12-29 22:53:19 +01:00
|
|
|
},
|
2022-03-13 23:33:50 +01:00
|
|
|
top10LongestItems() {
|
2023-08-19 23:53:33 +02:00
|
|
|
return this.libraryStats?.longestItems || []
|
2021-12-29 22:53:19 +01:00
|
|
|
},
|
2022-03-13 23:33:50 +01:00
|
|
|
longestItemDuration() {
|
|
|
|
if (!this.top10LongestItems.length) return 0
|
|
|
|
return this.top10LongestItems[0].duration
|
2021-12-29 22:53:19 +01:00
|
|
|
},
|
2023-02-19 22:39:28 +01:00
|
|
|
top10LargestItems() {
|
2023-08-19 23:53:33 +02:00
|
|
|
return this.libraryStats?.largestItems || []
|
2023-02-19 22:39:28 +01:00
|
|
|
},
|
|
|
|
largestItemSize() {
|
|
|
|
if (!this.top10LargestItems.length) return 0
|
|
|
|
return this.top10LargestItems[0].size
|
|
|
|
},
|
2021-12-29 22:53:19 +01:00
|
|
|
authorsWithCount() {
|
2023-08-19 23:53:33 +02:00
|
|
|
return this.libraryStats?.authorsWithCount || []
|
2021-12-29 22:53:19 +01:00
|
|
|
},
|
|
|
|
mostUsedAuthorCount() {
|
|
|
|
if (!this.authorsWithCount.length) return 0
|
|
|
|
return this.authorsWithCount[0].count
|
|
|
|
},
|
|
|
|
top10Authors() {
|
2023-08-19 23:53:33 +02:00
|
|
|
return this.authorsWithCount?.slice(0, 10) || []
|
2021-12-29 22:53:19 +01:00
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
|
|
|
},
|
|
|
|
currentLibraryName() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryName']
|
2023-08-19 23:53:33 +02:00
|
|
|
},
|
|
|
|
currentLibraryMediaType() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryMediaType']
|
|
|
|
},
|
|
|
|
isBookLibrary() {
|
|
|
|
return this.currentLibraryMediaType === 'book'
|
2021-12-29 22:53:19 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async init() {
|
|
|
|
this.libraryStats = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/stats`).catch((err) => {
|
|
|
|
console.error('Failed to get library stats', err)
|
|
|
|
var errorMsg = err.response ? err.response.data || 'Unknown Error' : 'Unknown Error'
|
|
|
|
this.$toast.error(`Failed to get library stats: ${errorMsg}`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
}
|
2023-02-19 22:39:28 +01:00
|
|
|
</script>
|