refactored libraries-stats and changed path

This commit is contained in:
Vito0912 2024-08-25 13:49:51 +02:00
parent 0e205b59d8
commit cbd042dd8e
No known key found for this signature in database
GPG key ID: 29A3D509FE70B237
2 changed files with 38 additions and 42 deletions

View file

@ -113,7 +113,7 @@ export default {
{ {
id: 'all-libraries-stats', id: 'all-libraries-stats',
title: this.$strings.HeaderAllLibrariesStats, title: this.$strings.HeaderAllLibrariesStats,
path: '/libraries/stats' path: '/config/libraries-stats'
} }
] ]

View file

@ -1,7 +1,5 @@
<template> <template>
<div class="page relative" :class="streamLibraryItem ? 'streaming' : ''"> <app-settings-content :header-text="$strings.HeaderAllLibrariesStats" class="!mb-4">
<app-book-shelf-toolbar page="all-libraries-stats" is-home />
<div id="bookshelf" class="w-full h-full px-1 py-4 md:p-8 relative overflow-y-auto">
<div class="w-full max-w-4xl mx-auto"> <div class="w-full max-w-4xl mx-auto">
<stats-preview-icons v-if="totalItems" :library-stats="combinedLibraryStats" /> <stats-preview-icons v-if="totalItems" :library-stats="combinedLibraryStats" />
@ -24,7 +22,7 @@
</div> </div>
</template> </template>
</div> </div>
<div v-if="isBookLibrary" class="w-80 my-6 mx-auto"> <div v-if="top10Authors.length" class="w-80 my-6 mx-auto">
<h1 class="text-2xl mb-4">{{ $strings.HeaderStatsTop10Authors }}</h1> <h1 class="text-2xl mb-4">{{ $strings.HeaderStatsTop10Authors }}</h1>
<p v-if="!top10Authors.length">{{ $strings.MessageNoAuthors }}</p> <p v-if="!top10Authors.length">{{ $strings.MessageNoAuthors }}</p>
<template v-for="(author, index) in top10Authors"> <template v-for="(author, index) in top10Authors">
@ -83,8 +81,7 @@
</div> </div>
</div> </div>
</div> </div>
</div> </app-settings-content>
</div>
</template> </template>
<script> <script>
@ -102,36 +99,39 @@ export default {
}, },
data() { data() {
return { return {
libraryStats: [], // Now an array of stats objects libraryStats: []
}
},
watch: {
currentLibraryId(newVal, oldVal) {
if (newVal) {
this.init()
}
} }
}, },
computed: { computed: {
combinedLibraryStats() { combinedLibraryStats() {
return this.libraryStats.reduce((combined, stats) => { return this.libraryStats.reduce(
// Combine stats from all objects in the array (combined, stats) => {
combined.totalItems += stats.totalItems || 0; combined.totalItems += stats.totalItems || 0
combined.genresWithCount = [...combined.genresWithCount, ...(stats.genresWithCount || [])]; combined.totalDuration += stats.totalDuration || 0
combined.longestItems = [...combined.longestItems, ...(stats.longestItems || [])]; combined.totalAuthors += stats.totalAuthors || 0
combined.largestItems = [...combined.largestItems, ...(stats.largestItems || [])]; combined.totalSize += stats.totalSize || 0
combined.authorsWithCount = [...combined.authorsWithCount, ...(stats.authorsWithCount || [])]; combined.numAudioTracks += stats.numAudioTracks || 0
return combined; combined.genresWithCount = [...combined.genresWithCount, ...(stats.genresWithCount || [])].sort((a, b) => b.count - a.count).slice(0, 10)
}, { combined.longestItems = [...combined.longestItems, ...(stats.longestItems || [])].sort((a, b) => b.duration - a.duration).slice(0, 10)
combined.largestItems = [...combined.largestItems, ...(stats.largestItems || [])].sort((a, b) => b.size - a.size).slice(0, 10)
combined.authorsWithCount = [...combined.authorsWithCount, ...(stats.authorsWithCount || [])].sort((a, b) => b.count - a.count).slice(0, 10)
return combined
},
{
totalItems: 0, totalItems: 0,
totalDuration: 0,
totalAuthors: 0,
totalSize: 0,
numAudioTracks: 0,
genresWithCount: [], genresWithCount: [],
longestItems: [], longestItems: [],
largestItems: [], largestItems: [],
authorsWithCount: [], authorsWithCount: []
}); }
)
}, },
totalItems() { totalItems() {
return this.combinedLibraryStats.totalItems || 0; return this.combinedLibraryStats.totalItems || 0
}, },
top5Genres() { top5Genres() {
return this.combinedLibraryStats.genresWithCount?.slice(0, 5) || [] return this.combinedLibraryStats.genresWithCount?.slice(0, 5) || []
@ -156,23 +156,19 @@ export default {
currentLibraryId() { currentLibraryId() {
return this.$store.state.libraries.currentLibraryId return this.$store.state.libraries.currentLibraryId
}, },
currentLibraryName() { mostUsedAuthorCount() {
return this.$store.getters['libraries/getCurrentLibraryName'] if (!this.combinedLibraryStats.authorsWithCount.length) return 0
return this.combinedLibraryStats.authorsWithCount[0].count
}, },
currentLibraryMediaType() {
return this.$store.getters['libraries/getCurrentLibraryMediaType']
},
isBookLibrary() {
return this.currentLibraryMediaType === 'book'
}
}, },
methods: { methods: {
async init() { async init() {
this.libraryStats = await this.$axios.$get(`/api/libraries/stats`).catch((err) => { this.libraryStatsInformation = await this.$axios.$get(`/api/libraries/stats`).catch((err) => {
console.error('Failed to get library stats', 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}`)
}) })
this.libraryStats = this.libraryStatsInformation.map(entry => {
return { ...entry.stats };
});
} }
}, },
mounted() { mounted() {