2021-11-06 02:24:02 +01:00
|
|
|
<template>
|
2022-03-14 01:34:31 +01:00
|
|
|
<div id="page-wrapper" class="bg-bg page overflow-hidden" :class="streamLibraryItem ? 'streaming' : ''">
|
2021-11-06 02:24:02 +01:00
|
|
|
<div class="w-full h-full overflow-y-auto px-2 py-6 md:p-8">
|
|
|
|
<div class="flex flex-col sm:flex-row max-w-6xl mx-auto">
|
2021-11-07 02:31:46 +01:00
|
|
|
<div class="w-full flex justify-center md:block sm:w-32 md:w-52" style="min-width: 240px">
|
2021-11-06 02:24:02 +01:00
|
|
|
<div class="relative" style="height: fit-content">
|
2021-12-03 02:02:38 +01:00
|
|
|
<covers-collection-cover :book-items="bookItems" :width="240" :height="120 * bookCoverAspectRatio" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2021-11-06 02:24:02 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow px-2 py-6 md:py-0 md:px-10">
|
2022-08-05 01:06:39 +02:00
|
|
|
<div class="flex items-end flex-row flex-wrap md:flex-nowrap">
|
|
|
|
<h1 class="text-2xl md:text-3xl font-sans w-full md:w-fit mb-4 md:mb-0">
|
2021-11-07 02:31:46 +01:00
|
|
|
{{ collectionName }}
|
|
|
|
</h1>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
|
2021-11-08 01:11:29 +01:00
|
|
|
<ui-btn v-if="showPlayButton" :disabled="streaming" color="success" :padding-x="4" small class="flex items-center h-9 mr-2" @click="clickPlay">
|
2024-07-09 00:00:16 +02:00
|
|
|
<span v-show="!streaming" class="material-symbols fill text-2xl -ml-2 pr-1 text-white">play_arrow</span>
|
2022-11-09 00:10:08 +01:00
|
|
|
{{ streaming ? $strings.ButtonPlaying : $strings.ButtonPlay }}
|
2021-11-08 01:11:29 +01:00
|
|
|
</ui-btn>
|
|
|
|
|
2022-12-31 17:33:38 +01:00
|
|
|
<!-- RSS feed -->
|
2022-12-28 01:03:31 +01:00
|
|
|
<ui-tooltip v-if="rssFeed" :text="$strings.LabelOpenRSSFeed" direction="top">
|
2022-12-31 22:26:37 +01:00
|
|
|
<ui-icon-btn icon="rss_feed" class="mx-0.5" :bg-color="rssFeed ? 'success' : 'primary'" outlined @click="showRSSFeedModal" />
|
2022-12-28 01:03:31 +01:00
|
|
|
</ui-tooltip>
|
|
|
|
|
2022-12-18 00:31:19 +01:00
|
|
|
<button type="button" class="h-9 w-9 flex items-center justify-center shadow-sm pl-3 pr-3 text-left focus:outline-none cursor-pointer text-gray-100 hover:text-gray-200 rounded-full hover:bg-white/5 mx-px" @click.stop.prevent="editClick">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols text-xl">edit</span>
|
2022-12-18 00:31:19 +01:00
|
|
|
</button>
|
2021-11-07 02:31:46 +01:00
|
|
|
|
2022-12-18 00:31:19 +01:00
|
|
|
<ui-context-menu-dropdown :items="contextMenuItems" class="mx-px" @action="contextMenuAction" />
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="my-8 max-w-2xl">
|
|
|
|
<p class="text-base text-gray-100">{{ description }}</p>
|
2021-11-06 02:24:02 +01:00
|
|
|
</div>
|
2021-11-07 02:31:46 +01:00
|
|
|
|
2021-11-07 22:28:06 +01:00
|
|
|
<tables-collection-books-table :books="bookItems" :collection-id="collection.id" />
|
2021-11-06 02:24:02 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-12-18 00:31:19 +01:00
|
|
|
<div v-show="processing" class="absolute top-0 left-0 w-full h-full z-10 bg-black bg-opacity-40 flex items-center justify-center">
|
2021-11-07 02:31:46 +01:00
|
|
|
<ui-loading-indicator />
|
|
|
|
</div>
|
2021-11-06 02:24:02 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
async asyncData({ store, params, app, redirect, route }) {
|
|
|
|
if (!store.state.user.user) {
|
|
|
|
return redirect(`/login?redirect=${route.path}`)
|
|
|
|
}
|
2022-12-28 01:03:31 +01:00
|
|
|
const collection = await app.$axios.$get(`/api/collections/${params.id}?include=rssfeed`).catch((error) => {
|
2021-11-06 02:24:02 +01:00
|
|
|
console.error('Failed', error)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
if (!collection) {
|
|
|
|
return redirect('/')
|
|
|
|
}
|
2022-04-14 19:57:34 +02:00
|
|
|
|
2022-11-27 21:22:46 +01:00
|
|
|
// If collection is a different library then set library as current
|
|
|
|
if (collection.libraryId !== store.state.libraries.currentLibraryId) {
|
|
|
|
await store.dispatch('libraries/fetch', collection.libraryId)
|
|
|
|
}
|
|
|
|
|
2022-11-12 00:44:19 +01:00
|
|
|
store.commit('libraries/addUpdateCollection', collection)
|
2021-11-06 02:24:02 +01:00
|
|
|
return {
|
2022-12-28 01:03:31 +01:00
|
|
|
collectionId: collection.id,
|
|
|
|
rssFeed: collection.rssFeed || null
|
2021-11-06 02:24:02 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
2021-11-07 02:31:46 +01:00
|
|
|
return {
|
2022-12-31 22:26:37 +01:00
|
|
|
processing: false
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
2021-11-06 02:24:02 +01:00
|
|
|
},
|
|
|
|
computed: {
|
2021-12-03 02:02:38 +01:00
|
|
|
bookCoverAspectRatio() {
|
2022-08-13 20:56:37 +02:00
|
|
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
2022-03-14 01:34:31 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2021-11-06 02:24:02 +01:00
|
|
|
},
|
|
|
|
bookItems() {
|
|
|
|
return this.collection.books || []
|
|
|
|
},
|
|
|
|
collectionName() {
|
|
|
|
return this.collection.name || ''
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
|
|
|
description() {
|
|
|
|
return this.collection.description || ''
|
2021-11-07 22:28:06 +01:00
|
|
|
},
|
|
|
|
collection() {
|
2022-11-12 00:44:19 +01:00
|
|
|
return this.$store.getters['libraries/getCollection'](this.collectionId) || {}
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
|
|
|
playableBooks() {
|
|
|
|
return this.bookItems.filter((book) => {
|
2022-03-26 17:59:34 +01:00
|
|
|
return !book.isMissing && !book.isInvalid && book.media.tracks.length
|
2021-11-08 01:11:29 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
streaming() {
|
2022-11-27 21:22:46 +01:00
|
|
|
return !!this.playableBooks.some((b) => b.id === this.$store.getters['getLibraryItemIdStreaming'])
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
|
|
|
showPlayButton() {
|
|
|
|
return this.playableBooks.length
|
2022-08-31 22:46:10 +02:00
|
|
|
},
|
2022-12-28 01:03:31 +01:00
|
|
|
userIsAdminOrUp() {
|
|
|
|
return this.$store.getters['user/getIsAdminOrUp']
|
|
|
|
},
|
2022-08-31 22:46:10 +02:00
|
|
|
userCanUpdate() {
|
|
|
|
return this.$store.getters['user/getUserCanUpdate']
|
|
|
|
},
|
|
|
|
userCanDelete() {
|
|
|
|
return this.$store.getters['user/getUserCanDelete']
|
2022-12-18 00:31:19 +01:00
|
|
|
},
|
|
|
|
contextMenuItems() {
|
|
|
|
const items = [
|
|
|
|
{
|
2022-12-18 00:47:35 +01:00
|
|
|
text: this.$strings.MessagePlaylistCreateFromCollection,
|
2022-12-18 00:31:19 +01:00
|
|
|
action: 'create-playlist'
|
|
|
|
}
|
|
|
|
]
|
2022-12-31 17:33:38 +01:00
|
|
|
if (this.userIsAdminOrUp || this.rssFeed) {
|
2022-12-28 01:03:31 +01:00
|
|
|
items.push({
|
|
|
|
text: this.$strings.LabelOpenRSSFeed,
|
|
|
|
action: 'open-rss-feed'
|
|
|
|
})
|
|
|
|
}
|
2022-12-18 00:31:19 +01:00
|
|
|
if (this.userCanDelete) {
|
|
|
|
items.push({
|
2022-12-18 00:47:35 +01:00
|
|
|
text: this.$strings.ButtonDelete,
|
2022-12-18 00:31:19 +01:00
|
|
|
action: 'delete'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return items
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-12-31 22:26:37 +01:00
|
|
|
showRSSFeedModal() {
|
|
|
|
this.$store.commit('globals/setRSSFeedOpenCloseModal', {
|
|
|
|
id: this.collectionId,
|
|
|
|
name: this.collectionName,
|
|
|
|
type: 'collection',
|
|
|
|
feed: this.rssFeed
|
|
|
|
})
|
2022-12-28 01:03:31 +01:00
|
|
|
},
|
2023-05-30 00:38:38 +02:00
|
|
|
contextMenuAction({ action }) {
|
2022-12-18 00:31:19 +01:00
|
|
|
if (action === 'delete') {
|
|
|
|
this.removeClick()
|
|
|
|
} else if (action === 'create-playlist') {
|
|
|
|
this.createPlaylistFromCollection()
|
2022-12-28 01:03:31 +01:00
|
|
|
} else if (action === 'open-rss-feed') {
|
2022-12-31 22:26:37 +01:00
|
|
|
this.showRSSFeedModal()
|
2022-12-18 00:31:19 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
createPlaylistFromCollection() {
|
|
|
|
this.processing = true
|
|
|
|
this.$axios
|
|
|
|
.$post(`/api/playlists/collection/${this.collectionId}`)
|
|
|
|
.then((playlist) => {
|
|
|
|
if (playlist) {
|
2022-12-18 00:47:35 +01:00
|
|
|
this.$toast.success(this.$strings.ToastPlaylistCreateSuccess)
|
2022-12-18 00:31:19 +01:00
|
|
|
this.$router.push(`/playlist/${playlist.id}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
const errMsg = error.response ? error.response.data || '' : ''
|
2022-12-18 00:47:35 +01:00
|
|
|
this.$toast.error(errMsg || this.$strings.ToastPlaylistCreateFailed)
|
2022-12-18 00:31:19 +01:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.processing = false
|
|
|
|
})
|
|
|
|
},
|
2021-11-07 02:31:46 +01:00
|
|
|
editClick() {
|
|
|
|
this.$store.commit('globals/setEditCollection', this.collection)
|
|
|
|
},
|
|
|
|
removeClick() {
|
2022-11-27 21:19:22 +01:00
|
|
|
if (confirm(this.$getString('MessageConfirmRemoveCollection', [this.collectionName]))) {
|
2022-12-18 00:31:19 +01:00
|
|
|
this.processing = true
|
2021-11-07 02:31:46 +01:00
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$delete(`/api/collections/${this.collection.id}`)
|
2021-11-07 02:31:46 +01:00
|
|
|
.then(() => {
|
2022-11-27 21:19:22 +01:00
|
|
|
this.$toast.success(this.$strings.ToastCollectionRemoveSuccess)
|
2021-11-07 02:31:46 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to remove collection', error)
|
2022-11-27 21:19:22 +01:00
|
|
|
this.$toast.error(this.$strings.ToastCollectionRemoveFailed)
|
2021-11-07 02:31:46 +01:00
|
|
|
})
|
2022-11-27 21:22:46 +01:00
|
|
|
.finally(() => {
|
2022-12-18 00:31:19 +01:00
|
|
|
this.processing = false
|
2022-11-27 21:22:46 +01:00
|
|
|
})
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
2021-11-07 22:28:06 +01:00
|
|
|
},
|
2021-11-08 01:11:29 +01:00
|
|
|
clickPlay() {
|
2022-11-12 23:48:35 +01:00
|
|
|
const queueItems = []
|
|
|
|
|
|
|
|
// Collection queue will start at the first unfinished book
|
|
|
|
// if all books are finished then entire collection is queued
|
|
|
|
const itemsWithProgress = this.playableBooks.map((item) => {
|
|
|
|
return {
|
|
|
|
...item,
|
|
|
|
progress: this.$store.getters['user/getUserMediaProgress'](item.id)
|
|
|
|
}
|
2022-03-20 22:16:39 +01:00
|
|
|
})
|
2022-11-12 23:48:35 +01:00
|
|
|
|
|
|
|
const hasUnfinishedItems = itemsWithProgress.some((i) => !i.progress || !i.progress.isFinished)
|
|
|
|
if (!hasUnfinishedItems) {
|
|
|
|
console.warn('All items in collection are finished - starting at first item')
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < itemsWithProgress.length; i++) {
|
|
|
|
const libraryItem = itemsWithProgress[i]
|
|
|
|
if (!hasUnfinishedItems || !libraryItem.progress || !libraryItem.progress.isFinished) {
|
|
|
|
queueItems.push({
|
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (queueItems.length >= 0) {
|
2022-03-26 23:41:26 +01:00
|
|
|
this.$eventBus.$emit('play-item', {
|
2022-11-12 23:48:35 +01:00
|
|
|
libraryItemId: queueItems[0].libraryItemId,
|
|
|
|
queueItems
|
2022-03-26 23:41:26 +01:00
|
|
|
})
|
2021-11-08 01:11:29 +01:00
|
|
|
}
|
2022-12-28 01:03:31 +01:00
|
|
|
},
|
|
|
|
rssFeedOpen(data) {
|
|
|
|
if (data.entityId === this.collectionId) {
|
|
|
|
console.log('RSS Feed Opened', data)
|
|
|
|
this.rssFeed = data
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rssFeedClosed(data) {
|
|
|
|
if (data.entityId === this.collectionId) {
|
|
|
|
console.log('RSS Feed Closed', data)
|
|
|
|
this.rssFeed = null
|
|
|
|
}
|
2021-11-06 02:24:02 +01:00
|
|
|
}
|
|
|
|
},
|
2022-12-28 01:03:31 +01:00
|
|
|
mounted() {
|
|
|
|
this.$root.socket.on('rss_feed_open', this.rssFeedOpen)
|
|
|
|
this.$root.socket.on('rss_feed_closed', this.rssFeedClosed)
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$root.socket.off('rss_feed_open', this.rssFeedOpen)
|
|
|
|
this.$root.socket.off('rss_feed_closed', this.rssFeedClosed)
|
|
|
|
}
|
2021-11-06 02:24:02 +01:00
|
|
|
}
|
2022-11-22 05:51:37 +01:00
|
|
|
</script>
|