2021-10-23 03:08:02 +02:00
|
|
|
<template>
|
|
|
|
<div class="w-full h-full">
|
2021-11-04 23:35:59 +01:00
|
|
|
<div class="bg-bg rounded-md shadow-lg border border-white border-opacity-5 p-0 sm:p-4 mb-8">
|
|
|
|
<nuxt-link to="/config/users" class="text-white text-opacity-70 hover:text-opacity-100 hover:bg-white hover:bg-opacity-5 cursor-pointer rounded-full px-2 sm:px-0">
|
2021-10-23 03:08:02 +02:00
|
|
|
<div class="flex items-center">
|
|
|
|
<div class="h-10 w-10 flex items-center justify-center">
|
|
|
|
<span class="material-icons text-2xl">arrow_back</span>
|
|
|
|
</div>
|
|
|
|
<p class="pl-1">All Users</p>
|
|
|
|
</div>
|
|
|
|
</nuxt-link>
|
2021-11-04 23:35:59 +01:00
|
|
|
<div class="flex items-center mb-2 mt-4 px-2 sm:px-0">
|
2021-10-23 03:08:02 +02:00
|
|
|
<widgets-online-indicator :value="!!userOnline" />
|
|
|
|
<h1 class="text-xl pl-2">{{ username }}</h1>
|
|
|
|
</div>
|
2022-03-17 15:28:31 +01:00
|
|
|
<div class="cursor-pointer text-gray-400 hover:text-white" @click="copyToClipboard(userToken)">
|
2022-03-18 01:10:47 +01:00
|
|
|
<p class="py-2 text-xs">
|
|
|
|
<strong class="text-white">API Token: </strong><br /><span class="text-white">{{ userToken }}</span
|
|
|
|
><span class="material-icons pl-2 text-base">content_copy</span>
|
|
|
|
</p>
|
2022-03-17 15:28:31 +01:00
|
|
|
</div>
|
2021-11-13 02:43:16 +01:00
|
|
|
<div v-if="showExperimentalFeatures" class="w-full h-px bg-white bg-opacity-10 my-2" />
|
|
|
|
<div v-if="showExperimentalFeatures" class="py-2">
|
2022-03-05 17:10:42 +01:00
|
|
|
<h1 class="text-lg mb-2 text-white text-opacity-90 px-2 sm:px-0">Listening Stats <span class="pl-2 text-xs text-error">(experimental)</span></h1>
|
2021-11-13 02:43:16 +01:00
|
|
|
<p class="text-sm text-gray-300">
|
|
|
|
Total Time Listened:
|
|
|
|
<span class="font-mono text-base">{{ listeningTimePretty }}</span>
|
|
|
|
</p>
|
2022-03-05 17:10:42 +01:00
|
|
|
<p v-if="timeListenedToday" class="text-sm text-gray-300">
|
2021-11-13 02:43:16 +01:00
|
|
|
Time Listened Today:
|
|
|
|
<span class="font-mono text-base">{{ $elapsedPrettyExtended(timeListenedToday) }}</span>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<div v-if="latestSession" class="mt-4">
|
2022-03-05 17:10:42 +01:00
|
|
|
<h1 class="text-lg mb-2 text-white text-opacity-90 px-2 sm:px-0">Last Listening Session</h1>
|
2021-11-13 02:43:16 +01:00
|
|
|
<p class="text-sm text-gray-300">{{ latestSession.audiobookTitle }} {{ $dateDistanceFromNow(latestSession.lastUpdate) }} for {{ $elapsedPrettyExtended(this.latestSession.timeListening) }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-23 03:08:02 +02:00
|
|
|
<div class="w-full h-px bg-white bg-opacity-10 my-2" />
|
|
|
|
<div class="py-2">
|
2022-03-18 01:10:47 +01:00
|
|
|
<h1 class="text-lg mb-2 text-white text-opacity-90 px-2 sm:px-0">Item Progress</h1>
|
|
|
|
<table v-if="libraryItemProgress.length" class="userAudiobooksTable">
|
2021-10-23 03:08:02 +02:00
|
|
|
<tr class="bg-primary bg-opacity-40">
|
2022-03-18 01:10:47 +01:00
|
|
|
<th class="w-16 text-left">Item</th>
|
2021-10-23 03:08:02 +02:00
|
|
|
<th class="text-left"></th>
|
|
|
|
<th class="w-32">Progress</th>
|
2021-11-04 23:35:59 +01:00
|
|
|
<th class="w-40 hidden sm:table-cell">Started At</th>
|
|
|
|
<th class="w-40 hidden sm:table-cell">Last Update</th>
|
2021-10-23 03:08:02 +02:00
|
|
|
</tr>
|
2022-03-18 01:10:47 +01:00
|
|
|
<tr v-for="item in libraryItemProgress" :key="item.id" :class="!item.isFinished ? '' : 'isFinished'">
|
2021-10-23 03:08:02 +02:00
|
|
|
<td>
|
2022-03-18 01:10:47 +01:00
|
|
|
<covers-book-cover :width="50" :library-item="item" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2021-10-23 03:08:02 +02:00
|
|
|
</td>
|
|
|
|
<td class="font-book">
|
2022-03-18 01:10:47 +01:00
|
|
|
<p>{{ item.media && item.media.metadata ? item.media.metadata.title : 'Unknown' }}</p>
|
|
|
|
<p v-if="item.media && item.media.metadata && item.media.metadata.authorName" class="text-white text-opacity-50 text-sm font-sans">by {{ item.media.metadata.authorName }}</p>
|
2021-10-23 03:08:02 +02:00
|
|
|
</td>
|
2022-03-18 01:10:47 +01:00
|
|
|
<td class="text-center">{{ Math.floor(item.progress * 100) }}%</td>
|
2021-11-04 23:35:59 +01:00
|
|
|
<td class="text-center hidden sm:table-cell">
|
2022-03-18 01:10:47 +01:00
|
|
|
<ui-tooltip v-if="item.startedAt" direction="top" :text="$formatDate(item.startedAt, 'MMMM do, yyyy HH:mm')">
|
|
|
|
<p class="text-sm">{{ $dateDistanceFromNow(item.startedAt) }}</p>
|
2021-10-23 03:08:02 +02:00
|
|
|
</ui-tooltip>
|
|
|
|
</td>
|
2021-11-04 23:35:59 +01:00
|
|
|
<td class="text-center hidden sm:table-cell">
|
2022-03-18 01:10:47 +01:00
|
|
|
<ui-tooltip v-if="item.lastUpdate" direction="top" :text="$formatDate(item.lastUpdate, 'MMMM do, yyyy HH:mm')">
|
|
|
|
<p class="text-sm">{{ $dateDistanceFromNow(item.lastUpdate) }}</p>
|
2021-10-23 03:08:02 +02:00
|
|
|
</ui-tooltip>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<p v-else class="text-white text-opacity-50">Nothing read yet...</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
async asyncData({ params, redirect, app }) {
|
2021-11-22 03:00:40 +01:00
|
|
|
var user = await app.$axios.$get(`/api/users/${params.id}`).catch((error) => {
|
2021-10-23 03:08:02 +02:00
|
|
|
console.error('Failed to get user', error)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
if (!user) return redirect('/config/users')
|
|
|
|
return {
|
|
|
|
user
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
2021-11-13 02:43:16 +01:00
|
|
|
return {
|
|
|
|
listeningSessions: [],
|
|
|
|
listeningStats: {}
|
|
|
|
}
|
2021-10-23 03:08:02 +02:00
|
|
|
},
|
|
|
|
computed: {
|
2022-03-17 15:28:31 +01:00
|
|
|
userToken() {
|
|
|
|
return this.user.token
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
coverAspectRatio() {
|
|
|
|
return this.$store.getters['getServerSetting']('coverAspectRatio')
|
|
|
|
},
|
|
|
|
bookCoverAspectRatio() {
|
|
|
|
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE ? 1 : 1.6
|
|
|
|
},
|
2021-11-13 02:43:16 +01:00
|
|
|
showExperimentalFeatures() {
|
|
|
|
return this.$store.state.showExperimentalFeatures
|
|
|
|
},
|
2021-10-23 03:08:02 +02:00
|
|
|
username() {
|
|
|
|
return this.user.username
|
|
|
|
},
|
|
|
|
userOnline() {
|
|
|
|
return this.$store.getters['users/getIsUserOnline'](this.user.id)
|
|
|
|
},
|
2022-03-18 01:10:47 +01:00
|
|
|
libraryItemProgress() {
|
|
|
|
return this.user.libraryItemProgress.sort((a, b) => b.lastUpdate - a.lastUpdate)
|
2021-11-13 02:43:16 +01:00
|
|
|
},
|
|
|
|
totalListeningTime() {
|
|
|
|
return this.listeningStats.totalTime || 0
|
|
|
|
},
|
|
|
|
listeningTimePretty() {
|
|
|
|
return this.$elapsedPrettyExtended(this.totalListeningTime)
|
|
|
|
},
|
|
|
|
timeListenedToday() {
|
|
|
|
return this.listeningStats.today || 0
|
|
|
|
},
|
|
|
|
latestSession() {
|
|
|
|
if (!this.listeningSessions.length) return null
|
|
|
|
return this.listeningSessions[0]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-03-17 15:28:31 +01:00
|
|
|
copyToClipboard(str) {
|
|
|
|
this.$copyToClipboard(str, this)
|
|
|
|
},
|
2021-11-13 02:43:16 +01:00
|
|
|
async init() {
|
2021-11-22 03:00:40 +01:00
|
|
|
this.listeningSessions = await this.$axios.$get(`/api/users/${this.user.id}/listening-sessions`).catch((err) => {
|
2021-11-13 02:43:16 +01:00
|
|
|
console.error('Failed to load listening sesions', err)
|
|
|
|
return []
|
|
|
|
})
|
2021-11-22 03:00:40 +01:00
|
|
|
this.listeningStats = await this.$axios.$get(`/api/users/${this.user.id}/listening-stats`).catch((err) => {
|
2021-11-13 02:43:16 +01:00
|
|
|
console.error('Failed to load listening sesions', err)
|
|
|
|
return []
|
|
|
|
})
|
|
|
|
console.log('Loaded user listening data', this.listeningSessions, this.listeningStats)
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
|
|
|
},
|
2021-11-13 02:43:16 +01:00
|
|
|
mounted() {
|
|
|
|
this.init()
|
|
|
|
}
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.userAudiobooksTable {
|
|
|
|
border-collapse: collapse;
|
|
|
|
width: 100%;
|
|
|
|
border: 1px solid #474747;
|
|
|
|
}
|
|
|
|
.userAudiobooksTable tr:nth-child(even) {
|
|
|
|
background-color: #2e2e2e;
|
|
|
|
}
|
|
|
|
.userAudiobooksTable tr:not(:first-child) {
|
|
|
|
background-color: #373838;
|
|
|
|
}
|
|
|
|
.userAudiobooksTable tr:hover:not(:first-child) {
|
|
|
|
background-color: #474747;
|
|
|
|
}
|
2022-03-18 01:10:47 +01:00
|
|
|
.userAudiobooksTable tr.isFinished {
|
2021-10-23 03:08:02 +02:00
|
|
|
background-color: rgba(76, 175, 80, 0.1);
|
|
|
|
}
|
|
|
|
.userAudiobooksTable td {
|
|
|
|
padding: 4px 8px;
|
|
|
|
}
|
|
|
|
.userAudiobooksTable th {
|
|
|
|
padding: 4px 8px;
|
|
|
|
font-size: 0.75rem;
|
|
|
|
}
|
|
|
|
</style>
|