2022-05-27 02:09:46 +02:00
|
|
|
<template>
|
|
|
|
<div class="w-full h-full">
|
|
|
|
<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/${user.id}`" 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">
|
|
|
|
<div class="flex items-center">
|
|
|
|
<div class="h-10 w-10 flex items-center justify-center">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols text-2xl">arrow_back</span>
|
2022-05-27 02:09:46 +02:00
|
|
|
</div>
|
2022-11-08 01:27:17 +01:00
|
|
|
<p class="pl-1">{{ $strings.LabelBackToUser }}</p>
|
2022-05-27 02:09:46 +02:00
|
|
|
</div>
|
|
|
|
</nuxt-link>
|
|
|
|
<div class="flex items-center mb-2 mt-4 px-2 sm:px-0">
|
|
|
|
<widgets-online-indicator :value="!!userOnline" />
|
|
|
|
<h1 class="text-xl pl-2">{{ username }}</h1>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="w-full h-px bg-white bg-opacity-10 my-2" />
|
|
|
|
|
|
|
|
<div class="py-2">
|
2022-11-08 01:27:17 +01:00
|
|
|
<h1 class="text-lg mb-2 text-white text-opacity-90 px-2 sm:px-0">{{ $strings.HeaderListeningSessions }}</h1>
|
2022-06-04 17:52:37 +02:00
|
|
|
<div v-if="listeningSessions.length">
|
|
|
|
<table class="userSessionsTable">
|
|
|
|
<tr class="bg-primary bg-opacity-40">
|
2022-11-08 01:27:17 +01:00
|
|
|
<th class="w-48 min-w-48 text-left">{{ $strings.LabelItem }}</th>
|
|
|
|
<th class="w-32 min-w-32 text-left hidden md:table-cell">{{ $strings.LabelPlayMethod }}</th>
|
|
|
|
<th class="w-32 min-w-32 text-left hidden sm:table-cell">{{ $strings.LabelDeviceInfo }}</th>
|
|
|
|
<th class="w-32 min-w-32">{{ $strings.LabelTimeListened }}</th>
|
|
|
|
<th class="w-16 min-w-16">{{ $strings.LabelLastTime }}</th>
|
|
|
|
<th class="flex-grow hidden sm:table-cell">{{ $strings.LabelLastUpdate }}</th>
|
2022-06-04 17:52:37 +02:00
|
|
|
</tr>
|
|
|
|
<tr v-for="session in listeningSessions" :key="session.id" class="cursor-pointer" @click="showSession(session)">
|
2022-06-04 22:51:00 +02:00
|
|
|
<td class="py-1 max-w-48">
|
|
|
|
<p class="text-xs text-gray-200 truncate">{{ session.displayTitle }}</p>
|
|
|
|
<p class="text-xs text-gray-400 truncate">{{ session.displayAuthor }}</p>
|
2022-06-04 17:52:37 +02:00
|
|
|
</td>
|
|
|
|
<td class="hidden md:table-cell">
|
|
|
|
<p class="text-xs">{{ getPlayMethodName(session.playMethod) }}</p>
|
|
|
|
</td>
|
2024-04-05 23:50:15 +02:00
|
|
|
<td class="hidden sm:table-cell min-w-32 max-w-32">
|
|
|
|
<p class="text-xs truncate" v-html="getDeviceInfoString(session.deviceInfo)" />
|
2022-06-04 17:52:37 +02:00
|
|
|
</td>
|
|
|
|
<td class="text-center">
|
|
|
|
<p class="text-xs font-mono">{{ $elapsedPretty(session.timeListening) }}</p>
|
|
|
|
</td>
|
2022-07-31 01:20:15 +02:00
|
|
|
<td class="text-center hover:underline" @click.stop="clickCurrentTime(session)">
|
2022-06-04 17:52:37 +02:00
|
|
|
<p class="text-xs font-mono">{{ $secondsToTimestamp(session.currentTime) }}</p>
|
|
|
|
</td>
|
|
|
|
<td class="text-center hidden sm:table-cell">
|
2023-02-27 19:04:26 +01:00
|
|
|
<ui-tooltip v-if="session.updatedAt" direction="top" :text="$formatDatetime(session.updatedAt, dateFormat, timeFormat)">
|
2022-06-04 22:51:00 +02:00
|
|
|
<p class="text-xs text-gray-200">{{ $dateDistanceFromNow(session.updatedAt) }}</p>
|
2022-06-04 17:52:37 +02:00
|
|
|
</ui-tooltip>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<div class="flex items-center justify-end py-1">
|
|
|
|
<ui-icon-btn icon="arrow_back_ios_new" :size="7" icon-font-size="1rem" class="mx-1" :disabled="currentPage === 0" @click="prevPage" />
|
|
|
|
<p class="text-sm mx-1">Page {{ currentPage + 1 }} of {{ numPages }}</p>
|
|
|
|
<ui-icon-btn icon="arrow_forward_ios" :size="7" icon-font-size="1rem" class="mx-1" :disabled="currentPage >= numPages - 1" @click="nextPage" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-27 02:09:46 +02:00
|
|
|
<p v-else class="text-white text-opacity-50">No sessions yet...</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-28 00:39:24 +02:00
|
|
|
|
2022-08-13 19:24:19 +02:00
|
|
|
<modals-listening-session-modal v-model="showSessionModal" :session="selectedSession" @removedSession="removedSession" />
|
2022-05-27 02:09:46 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
async asyncData({ params, redirect, app }) {
|
|
|
|
var user = await app.$axios.$get(`/api/users/${params.id}`).catch((error) => {
|
|
|
|
console.error('Failed to get user', error)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
if (!user) return redirect('/config/users')
|
|
|
|
return {
|
|
|
|
user
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-05-28 00:39:24 +02:00
|
|
|
showSessionModal: false,
|
|
|
|
selectedSession: null,
|
2022-06-04 17:52:37 +02:00
|
|
|
listeningSessions: [],
|
|
|
|
numPages: 0,
|
|
|
|
total: 0,
|
2022-07-31 01:20:15 +02:00
|
|
|
currentPage: 0,
|
2022-11-16 23:28:46 +01:00
|
|
|
itemsPerPage: 10,
|
2022-07-31 01:20:15 +02:00
|
|
|
processingGoToTimestamp: false
|
2022-05-27 02:09:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
username() {
|
|
|
|
return this.user.username
|
|
|
|
},
|
|
|
|
userOnline() {
|
|
|
|
return this.$store.getters['users/getIsUserOnline'](this.user.id)
|
2023-02-27 19:04:26 +01:00
|
|
|
},
|
|
|
|
dateFormat() {
|
|
|
|
return this.$store.state.serverSettings.dateFormat
|
|
|
|
},
|
|
|
|
timeFormat() {
|
|
|
|
return this.$store.state.serverSettings.timeFormat
|
2022-05-27 02:09:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-08-13 19:24:19 +02:00
|
|
|
removedSession() {
|
2022-11-16 23:28:46 +01:00
|
|
|
// If on last page and this was the last session then load prev page
|
|
|
|
if (this.currentPage == this.numPages - 1) {
|
|
|
|
const newTotal = this.total - 1
|
|
|
|
const newNumPages = Math.ceil(newTotal / this.itemsPerPage)
|
|
|
|
if (newNumPages < this.numPages) {
|
|
|
|
this.prevPage()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-13 19:24:19 +02:00
|
|
|
this.loadSessions(this.currentPage)
|
|
|
|
},
|
2022-07-31 01:20:15 +02:00
|
|
|
async clickCurrentTime(session) {
|
|
|
|
if (this.processingGoToTimestamp) return
|
|
|
|
this.processingGoToTimestamp = true
|
|
|
|
const libraryItem = await this.$axios.$get(`/api/items/${session.libraryItemId}`).catch((error) => {
|
|
|
|
console.error('Failed to get library item', error)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!libraryItem) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastFailedToLoadData)
|
2022-07-31 01:20:15 +02:00
|
|
|
this.processingGoToTimestamp = false
|
|
|
|
return
|
|
|
|
}
|
2022-11-12 23:48:35 +01:00
|
|
|
if (session.episodeId && !libraryItem.media.episodes.some((ep) => ep.id === session.episodeId)) {
|
2024-08-31 00:47:49 +02:00
|
|
|
console.error('Episode not found in library item', session.episodeId, libraryItem.media.episodes)
|
|
|
|
this.$toast.error(this.$strings.ToastFailedToLoadData)
|
2022-07-31 01:20:15 +02:00
|
|
|
this.processingGoToTimestamp = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-12 23:48:35 +01:00
|
|
|
var queueItem = {}
|
|
|
|
if (session.episodeId) {
|
|
|
|
var episode = libraryItem.media.episodes.find((ep) => ep.id === session.episodeId)
|
|
|
|
queueItem = {
|
|
|
|
libraryItemId: libraryItem.id,
|
|
|
|
libraryId: libraryItem.libraryId,
|
|
|
|
episodeId: episode.id,
|
|
|
|
title: episode.title,
|
|
|
|
subtitle: libraryItem.media.metadata.title,
|
2024-08-31 00:47:49 +02:00
|
|
|
caption: episode.publishedAt ? this.$getString('LabelPublishedDate', [this.$formatDate(episode.publishedAt, this.dateFormat)]) : this.$strings.LabelUnknownPublishDate,
|
2022-11-12 23:48:35 +01:00
|
|
|
duration: episode.audioFile.duration || null,
|
|
|
|
coverPath: libraryItem.media.coverPath || null
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
queueItem = {
|
|
|
|
libraryItemId: libraryItem.id,
|
|
|
|
libraryId: libraryItem.libraryId,
|
|
|
|
episodeId: null,
|
|
|
|
title: libraryItem.media.metadata.title,
|
|
|
|
subtitle: libraryItem.media.metadata.authors.map((au) => au.name).join(', '),
|
|
|
|
caption: '',
|
|
|
|
duration: libraryItem.media.duration || null,
|
|
|
|
coverPath: libraryItem.media.coverPath || null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 01:20:15 +02:00
|
|
|
const payload = {
|
2022-11-08 01:27:17 +01:00
|
|
|
message: this.$getString('MessageStartPlaybackAtTime', [session.displayTitle, this.$secondsToTimestamp(session.currentTime)]),
|
2022-07-31 01:20:15 +02:00
|
|
|
callback: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.$eventBus.$emit('play-item', {
|
|
|
|
libraryItemId: libraryItem.id,
|
|
|
|
episodeId: session.episodeId || null,
|
2022-11-12 23:48:35 +01:00
|
|
|
startTime: session.currentTime,
|
|
|
|
queueItems: [queueItem]
|
2022-07-31 01:20:15 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
this.processingGoToTimestamp = false
|
|
|
|
},
|
|
|
|
type: 'yesNo'
|
|
|
|
}
|
|
|
|
this.$store.commit('globals/setConfirmPrompt', payload)
|
|
|
|
},
|
2022-06-04 17:52:37 +02:00
|
|
|
prevPage() {
|
|
|
|
this.loadSessions(this.currentPage - 1)
|
|
|
|
},
|
|
|
|
nextPage() {
|
|
|
|
this.loadSessions(this.currentPage + 1)
|
|
|
|
},
|
2022-05-28 00:39:24 +02:00
|
|
|
showSession(session) {
|
|
|
|
this.selectedSession = session
|
|
|
|
this.showSessionModal = true
|
|
|
|
},
|
2022-05-27 02:09:46 +02:00
|
|
|
getDeviceInfoString(deviceInfo) {
|
|
|
|
if (!deviceInfo) return ''
|
|
|
|
var lines = []
|
2024-04-05 23:50:15 +02:00
|
|
|
if (deviceInfo.clientName) lines.push(`${deviceInfo.clientName} ${deviceInfo.clientVersion || ''}`)
|
2022-05-27 02:09:46 +02:00
|
|
|
if (deviceInfo.osName) lines.push(`${deviceInfo.osName} ${deviceInfo.osVersion}`)
|
|
|
|
if (deviceInfo.browserName) lines.push(deviceInfo.browserName)
|
|
|
|
|
|
|
|
if (deviceInfo.manufacturer && deviceInfo.model) lines.push(`${deviceInfo.manufacturer} ${deviceInfo.model}`)
|
|
|
|
if (deviceInfo.sdkVersion) lines.push(`SDK Version: ${deviceInfo.sdkVersion}`)
|
|
|
|
return lines.join('<br>')
|
|
|
|
},
|
|
|
|
getPlayMethodName(playMethod) {
|
|
|
|
if (playMethod === this.$constants.PlayMethod.DIRECTPLAY) return 'Direct Play'
|
|
|
|
else if (playMethod === this.$constants.PlayMethod.TRANSCODE) return 'Transcode'
|
|
|
|
else if (playMethod === this.$constants.PlayMethod.DIRECTSTREAM) return 'Direct Stream'
|
|
|
|
else if (playMethod === this.$constants.PlayMethod.LOCAL) return 'Local'
|
|
|
|
return 'Unknown'
|
|
|
|
},
|
2022-06-04 17:52:37 +02:00
|
|
|
async loadSessions(page) {
|
2022-11-16 23:28:46 +01:00
|
|
|
const data = await this.$axios.$get(`/api/users/${this.user.id}/listening-sessions?page=${page}&itemsPerPage=${this.itemsPerPage}`).catch((err) => {
|
2022-05-27 02:09:46 +02:00
|
|
|
console.error('Failed to load listening sesions', err)
|
2022-06-04 17:52:37 +02:00
|
|
|
return null
|
2022-05-27 02:09:46 +02:00
|
|
|
})
|
2022-06-04 17:52:37 +02:00
|
|
|
if (!data) {
|
2024-05-13 23:58:41 +02:00
|
|
|
this.$toast.error(this.$strings.ToastFailedToLoadData)
|
2022-06-04 17:52:37 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.numPages = data.numPages
|
|
|
|
this.total = data.total
|
|
|
|
this.currentPage = data.page
|
|
|
|
this.listeningSessions = data.sessions
|
|
|
|
},
|
|
|
|
init() {
|
|
|
|
this.loadSessions(0)
|
2022-05-27 02:09:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-06-04 22:51:00 +02:00
|
|
|
<style scoped>
|
2022-05-27 02:09:46 +02:00
|
|
|
.userSessionsTable {
|
|
|
|
border-collapse: collapse;
|
|
|
|
width: 100%;
|
2022-06-04 22:51:00 +02:00
|
|
|
max-width: 100%;
|
2022-05-27 02:09:46 +02:00
|
|
|
border: 1px solid #474747;
|
|
|
|
}
|
2022-05-28 00:39:24 +02:00
|
|
|
.userSessionsTable tr:first-child {
|
|
|
|
background-color: #272727;
|
2022-05-27 02:09:46 +02:00
|
|
|
}
|
|
|
|
.userSessionsTable tr:not(:first-child) {
|
|
|
|
background-color: #373838;
|
|
|
|
}
|
2022-05-28 00:39:24 +02:00
|
|
|
.userSessionsTable tr:not(:first-child):nth-child(odd) {
|
|
|
|
background-color: #2f2f2f;
|
|
|
|
}
|
2022-05-27 02:09:46 +02:00
|
|
|
.userSessionsTable tr:hover:not(:first-child) {
|
|
|
|
background-color: #474747;
|
|
|
|
}
|
|
|
|
.userSessionsTable td {
|
|
|
|
padding: 4px 8px;
|
|
|
|
}
|
|
|
|
.userSessionsTable th {
|
|
|
|
padding: 4px 8px;
|
|
|
|
font-size: 0.75rem;
|
|
|
|
}
|
2023-02-27 19:04:26 +01:00
|
|
|
</style>
|