2022-03-26 23:41:26 +01:00
|
|
|
<template>
|
|
|
|
<div class="w-full py-6">
|
2023-07-11 00:37:35 +02:00
|
|
|
<div class="flex flex-wrap flex-col md:flex-row md:items-center mb-4">
|
|
|
|
<div class="flex items-center flex-nowrap whitespace-nowrap mb-2 md:mb-0">
|
|
|
|
<p class="text-lg mb-0 font-semibold">{{ $strings.HeaderEpisodes }}</p>
|
|
|
|
<div class="inline-flex bg-white/5 px-1 mx-2 rounded-md text-sm text-gray-100">
|
|
|
|
<p v-if="episodesList.length === episodes.length">{{ episodes.length }}</p>
|
|
|
|
<p v-else>{{ episodesList.length }} / {{ episodes.length }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-01-05 01:13:46 +01:00
|
|
|
<div class="flex-grow hidden md:block" />
|
2023-07-11 00:37:35 +02:00
|
|
|
<div class="flex items-center">
|
|
|
|
<template v-if="isSelectionMode">
|
|
|
|
<ui-tooltip :text="selectedIsFinished ? $strings.MessageMarkAsNotFinished : $strings.MessageMarkAsFinished" direction="bottom">
|
|
|
|
<ui-read-icon-btn :disabled="processing" :is-read="selectedIsFinished" @click="toggleBatchFinished" class="mx-1.5" />
|
|
|
|
</ui-tooltip>
|
|
|
|
<ui-btn color="error" :disabled="processing" small class="h-9" @click="removeSelectedEpisodes">{{ $getString('MessageRemoveEpisodes', [selectedEpisodes.length]) }}</ui-btn>
|
|
|
|
<ui-btn :disabled="processing" small class="ml-2 h-9" @click="clearSelected">{{ $strings.ButtonCancel }}</ui-btn>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<controls-filter-select v-model="filterKey" :items="filterItems" class="w-36 h-9 md:ml-4" />
|
|
|
|
<controls-sort-select v-model="sortKey" :descending.sync="sortDesc" :items="sortItems" class="w-44 md:w-48 h-9 ml-1 sm:ml-4" />
|
|
|
|
<div class="flex-grow md:hidden" />
|
|
|
|
<ui-context-menu-dropdown v-if="contextMenuItems.length" :items="contextMenuItems" class="ml-1" @action="contextMenuAction" />
|
|
|
|
</template>
|
|
|
|
</div>
|
2022-04-13 01:07:13 +02:00
|
|
|
</div>
|
2022-11-08 15:37:39 +01:00
|
|
|
<p v-if="!episodes.length" class="py-4 text-center text-lg">{{ $strings.MessageNoEpisodes }}</p>
|
2023-02-19 21:48:39 +01:00
|
|
|
<div v-if="episodes.length" class="w-full py-3 mx-auto flex">
|
|
|
|
<form @submit.prevent="submit" class="flex flex-grow">
|
2023-02-21 20:30:42 +01:00
|
|
|
<ui-text-input v-model="search" @input="inputUpdate" type="search" :placeholder="$strings.PlaceholderSearchEpisode" class="flex-grow mr-2 text-sm md:text-base" />
|
2023-02-19 21:48:39 +01:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<template v-for="episode in episodesList">
|
2022-11-27 19:33:38 +01:00
|
|
|
<tables-podcast-episode-table-row ref="episodeRow" :key="episode.id" :episode="episode" :library-item-id="libraryItem.id" :selection-mode="isSelectionMode" class="item" @play="playEpisode" @remove="removeEpisode" @edit="editEpisode" @view="viewEpisode" @selected="episodeSelected" @addToQueue="addEpisodeToQueue" @addToPlaylist="addToPlaylist" />
|
2022-05-24 02:28:00 +02:00
|
|
|
</template>
|
2022-05-25 01:38:25 +02:00
|
|
|
|
2022-08-14 19:34:21 +02:00
|
|
|
<modals-podcast-remove-episode v-model="showPodcastRemoveModal" @input="removeEpisodeModalToggled" :library-item="libraryItem" :episodes="episodesToRemove" @clearSelected="clearSelected" />
|
2022-03-26 23:41:26 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
libraryItem: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-05-25 01:38:25 +02:00
|
|
|
episodesCopy: [],
|
2022-10-25 00:57:08 +02:00
|
|
|
filterKey: 'incomplete',
|
2022-05-24 02:28:00 +02:00
|
|
|
sortKey: 'publishedAt',
|
2022-05-25 01:38:25 +02:00
|
|
|
sortDesc: true,
|
|
|
|
selectedEpisode: null,
|
2022-08-14 19:34:21 +02:00
|
|
|
showPodcastRemoveModal: false,
|
|
|
|
selectedEpisodes: [],
|
2022-08-28 21:47:31 +02:00
|
|
|
episodesToRemove: [],
|
2023-01-05 01:13:46 +01:00
|
|
|
processing: false,
|
2023-02-19 21:48:39 +01:00
|
|
|
quickMatchingEpisodes: false,
|
|
|
|
search: null,
|
|
|
|
searchTimeout: null,
|
2023-04-10 00:20:56 +02:00
|
|
|
searchText: null
|
2022-11-09 00:10:08 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2023-01-05 01:13:46 +01:00
|
|
|
libraryItem: {
|
|
|
|
handler() {
|
|
|
|
this.init()
|
|
|
|
}
|
2022-11-09 00:10:08 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2023-01-05 01:13:46 +01:00
|
|
|
contextMenuItems() {
|
|
|
|
if (!this.userIsAdminOrUp) return []
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
text: 'Quick match all episodes',
|
|
|
|
action: 'quick-match-episodes'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2022-11-09 00:10:08 +01:00
|
|
|
sortItems() {
|
|
|
|
return [
|
2022-10-29 01:10:19 +02:00
|
|
|
{
|
2022-11-09 00:10:08 +01:00
|
|
|
text: this.$strings.LabelPubDate,
|
2022-10-29 01:10:19 +02:00
|
|
|
value: 'publishedAt'
|
|
|
|
},
|
|
|
|
{
|
2022-11-09 00:10:08 +01:00
|
|
|
text: this.$strings.LabelTitle,
|
2022-10-29 01:10:19 +02:00
|
|
|
value: 'title'
|
|
|
|
},
|
|
|
|
{
|
2022-11-09 00:10:08 +01:00
|
|
|
text: this.$strings.LabelSeason,
|
2022-10-29 01:10:19 +02:00
|
|
|
value: 'season'
|
|
|
|
},
|
|
|
|
{
|
2022-11-09 00:10:08 +01:00
|
|
|
text: this.$strings.LabelEpisode,
|
2022-10-29 01:10:19 +02:00
|
|
|
value: 'episode'
|
|
|
|
}
|
2022-11-09 00:10:08 +01:00
|
|
|
]
|
|
|
|
},
|
|
|
|
filterItems() {
|
|
|
|
return [
|
2022-10-29 22:33:38 +02:00
|
|
|
{
|
|
|
|
value: 'all',
|
2022-11-09 00:10:08 +01:00
|
|
|
text: this.$strings.LabelShowAll
|
2022-10-29 22:33:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'incomplete',
|
2022-11-09 00:10:08 +01:00
|
|
|
text: this.$strings.LabelIncomplete
|
2022-10-29 22:33:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'complete',
|
2022-11-09 00:10:08 +01:00
|
|
|
text: this.$strings.LabelComplete
|
2022-10-29 22:33:38 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'in_progress',
|
2022-11-09 00:10:08 +01:00
|
|
|
text: this.$strings.LabelInProgress
|
2022-10-29 22:33:38 +02:00
|
|
|
}
|
2022-10-29 01:10:19 +02:00
|
|
|
]
|
2022-11-09 00:10:08 +01:00
|
|
|
},
|
2022-08-14 19:34:21 +02:00
|
|
|
isSelectionMode() {
|
|
|
|
return this.selectedEpisodes.length > 0
|
|
|
|
},
|
2023-01-05 01:13:46 +01:00
|
|
|
userIsAdminOrUp() {
|
|
|
|
return this.$store.getters['user/getIsAdminOrUp']
|
2022-04-13 01:07:13 +02:00
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
media() {
|
|
|
|
return this.libraryItem.media || {}
|
|
|
|
},
|
|
|
|
mediaMetadata() {
|
|
|
|
return this.media.metadata || {}
|
|
|
|
},
|
|
|
|
episodes() {
|
|
|
|
return this.media.episodes || []
|
2022-05-25 01:38:25 +02:00
|
|
|
},
|
|
|
|
episodesSorted() {
|
2022-10-25 00:57:08 +02:00
|
|
|
return this.episodesCopy
|
|
|
|
.filter((ep) => {
|
|
|
|
if (this.filterKey === 'all') return true
|
|
|
|
const episodeProgress = this.$store.getters['user/getUserMediaProgress'](this.libraryItem.id, ep.id)
|
|
|
|
if (this.filterKey === 'incomplete') return !episodeProgress || !episodeProgress.isFinished
|
|
|
|
if (this.filterKey === 'complete') return episodeProgress && episodeProgress.isFinished
|
|
|
|
return episodeProgress && !episodeProgress.isFinished
|
|
|
|
})
|
|
|
|
.sort((a, b) => {
|
2023-04-10 00:20:56 +02:00
|
|
|
let aValue = a[this.sortKey]
|
|
|
|
let bValue = b[this.sortKey]
|
|
|
|
|
|
|
|
// Sort episodes with no pub date as the oldest
|
|
|
|
if (this.sortKey === 'publishedAt') {
|
|
|
|
if (!aValue) aValue = Number.MAX_VALUE
|
|
|
|
if (!bValue) bValue = Number.MAX_VALUE
|
|
|
|
}
|
|
|
|
|
2022-10-25 00:57:08 +02:00
|
|
|
if (this.sortDesc) {
|
2023-04-10 00:20:56 +02:00
|
|
|
return String(bValue).localeCompare(String(aValue), undefined, { numeric: true, sensitivity: 'base' })
|
2022-10-25 00:57:08 +02:00
|
|
|
}
|
2023-04-10 00:20:56 +02:00
|
|
|
return String(aValue).localeCompare(String(bValue), undefined, { numeric: true, sensitivity: 'base' })
|
2022-10-25 00:57:08 +02:00
|
|
|
})
|
2022-08-28 21:47:31 +02:00
|
|
|
},
|
2023-02-19 21:48:39 +01:00
|
|
|
episodesList() {
|
|
|
|
return this.episodesSorted.filter((episode) => {
|
|
|
|
if (!this.searchText) return true
|
2023-07-11 00:37:35 +02:00
|
|
|
return episode.title?.toLowerCase().includes(this.searchText) || episode.subtitle?.toLowerCase().includes(this.searchText)
|
2023-02-19 21:48:39 +01:00
|
|
|
})
|
|
|
|
},
|
2022-08-28 21:47:31 +02:00
|
|
|
selectedIsFinished() {
|
|
|
|
// Find an item that is not finished, if none then all items finished
|
|
|
|
return !this.selectedEpisodes.find((episode) => {
|
|
|
|
var itemProgress = this.$store.getters['user/getUserMediaProgress'](this.libraryItem.id, episode.id)
|
|
|
|
return !itemProgress || !itemProgress.isFinished
|
|
|
|
})
|
2023-02-27 19:04:26 +01:00
|
|
|
},
|
|
|
|
dateFormat() {
|
|
|
|
return this.$store.state.serverSettings.dateFormat
|
|
|
|
},
|
|
|
|
timeFormat() {
|
|
|
|
return this.$store.state.serverSettings.timeFormat
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-02-19 21:48:39 +01:00
|
|
|
inputUpdate() {
|
|
|
|
clearTimeout(this.searchTimeout)
|
|
|
|
this.searchTimeout = setTimeout(() => {
|
|
|
|
if (!this.search || !this.search.trim()) {
|
|
|
|
this.searchText = ''
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.searchText = this.search.toLowerCase().trim()
|
|
|
|
}, 500)
|
|
|
|
},
|
2023-05-30 00:38:38 +02:00
|
|
|
contextMenuAction({ action }) {
|
2023-01-05 01:13:46 +01:00
|
|
|
if (action === 'quick-match-episodes') {
|
|
|
|
if (this.quickMatchingEpisodes) return
|
|
|
|
|
|
|
|
this.quickMatchAllEpisodes()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
quickMatchAllEpisodes() {
|
|
|
|
if (!this.mediaMetadata.feedUrl) {
|
|
|
|
this.$toast.error(this.$strings.MessagePodcastHasNoRSSFeedForMatching)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.quickMatchingEpisodes = true
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
message: 'Quick matching episodes will overwrite details if a match is found. Only unmatched episodes will be updated. Are you sure?',
|
|
|
|
callback: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.$axios
|
|
|
|
.$post(`/api/podcasts/${this.libraryItem.id}/match-episodes?override=1`)
|
|
|
|
.then((data) => {
|
|
|
|
if (data.numEpisodesUpdated) {
|
|
|
|
this.$toast.success(`${data.numEpisodesUpdated} episodes updated`)
|
|
|
|
} else {
|
|
|
|
this.$toast.info('No changes were made')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to request match episodes', error)
|
|
|
|
this.$toast.error('Failed to match episodes')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.quickMatchingEpisodes = false
|
|
|
|
},
|
|
|
|
type: 'yesNo'
|
|
|
|
}
|
|
|
|
this.$store.commit('globals/setConfirmPrompt', payload)
|
|
|
|
},
|
2022-11-27 19:33:38 +01:00
|
|
|
addToPlaylist(episode) {
|
|
|
|
this.$store.commit('globals/setSelectedPlaylistItems', [{ libraryItem: this.libraryItem, episode }])
|
|
|
|
this.$store.commit('globals/setShowPlaylistsModal', true)
|
|
|
|
},
|
2022-11-12 22:41:41 +01:00
|
|
|
addEpisodeToQueue(episode) {
|
|
|
|
const queueItem = {
|
|
|
|
libraryItemId: this.libraryItem.id,
|
|
|
|
libraryId: this.libraryItem.libraryId,
|
|
|
|
episodeId: episode.id,
|
|
|
|
title: episode.title,
|
|
|
|
subtitle: this.mediaMetadata.title,
|
2023-02-27 19:04:26 +01:00
|
|
|
caption: episode.publishedAt ? `Published ${this.$formatDate(episode.publishedAt, this.dateFormat)}` : 'Unknown publish date',
|
2022-11-12 22:41:41 +01:00
|
|
|
duration: episode.audioFile.duration || null,
|
|
|
|
coverPath: this.media.coverPath || null
|
|
|
|
}
|
|
|
|
this.$store.commit('addItemToQueue', queueItem)
|
|
|
|
},
|
2022-08-28 21:47:31 +02:00
|
|
|
toggleBatchFinished() {
|
|
|
|
this.processing = true
|
|
|
|
var newIsFinished = !this.selectedIsFinished
|
|
|
|
var updateProgressPayloads = this.selectedEpisodes.map((episode) => {
|
|
|
|
return {
|
|
|
|
libraryItemId: this.libraryItem.id,
|
|
|
|
episodeId: episode.id,
|
|
|
|
isFinished: newIsFinished
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
this.$axios
|
|
|
|
.patch(`/api/me/progress/batch/update`, updateProgressPayloads)
|
|
|
|
.then(() => {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.success(this.$strings.ToastBatchUpdateSuccess)
|
2022-08-28 21:47:31 +02:00
|
|
|
this.processing = false
|
|
|
|
this.clearSelected()
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.error(this.$strings.ToastBatchUpdateFailed)
|
2022-08-28 21:47:31 +02:00
|
|
|
console.error('Failed to batch update read/not read', error)
|
|
|
|
this.processing = false
|
|
|
|
})
|
|
|
|
},
|
2022-08-14 19:34:21 +02:00
|
|
|
removeEpisodeModalToggled(val) {
|
|
|
|
if (!val) this.episodesToRemove = []
|
|
|
|
},
|
|
|
|
clearSelected() {
|
|
|
|
const episodeRows = this.$refs.episodeRow
|
|
|
|
if (episodeRows && episodeRows.length) {
|
|
|
|
for (const epRow of episodeRows) {
|
|
|
|
if (epRow) epRow.isSelected = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.selectedEpisodes = []
|
|
|
|
},
|
|
|
|
removeSelectedEpisodes() {
|
|
|
|
this.episodesToRemove = this.selectedEpisodes
|
|
|
|
this.showPodcastRemoveModal = true
|
|
|
|
},
|
|
|
|
episodeSelected({ isSelected, episode }) {
|
|
|
|
if (isSelected) {
|
|
|
|
this.selectedEpisodes.push(episode)
|
|
|
|
} else {
|
|
|
|
this.selectedEpisodes = this.selectedEpisodes.filter((ep) => ep.id !== episode.id)
|
|
|
|
}
|
|
|
|
},
|
2022-08-28 20:12:38 +02:00
|
|
|
playEpisode(episode) {
|
|
|
|
const queueItems = []
|
2022-09-02 00:11:57 +02:00
|
|
|
|
|
|
|
const episodesInListeningOrder = this.episodesCopy.map((ep) => ({ ...ep })).sort((a, b) => String(a.publishedAt).localeCompare(String(b.publishedAt), undefined, { numeric: true, sensitivity: 'base' }))
|
|
|
|
const episodeIndex = episodesInListeningOrder.findIndex((e) => e.id === episode.id)
|
|
|
|
for (let i = episodeIndex; i < episodesInListeningOrder.length; i++) {
|
|
|
|
const episode = episodesInListeningOrder[i]
|
|
|
|
const podcastProgress = this.$store.getters['user/getUserMediaProgress'](this.libraryItem.id, episode.id)
|
|
|
|
if (!podcastProgress || !podcastProgress.isFinished) {
|
|
|
|
queueItems.push({
|
|
|
|
libraryItemId: this.libraryItem.id,
|
2022-11-12 22:41:41 +01:00
|
|
|
libraryId: this.libraryItem.libraryId,
|
2022-09-02 00:11:57 +02:00
|
|
|
episodeId: episode.id,
|
|
|
|
title: episode.title,
|
|
|
|
subtitle: this.mediaMetadata.title,
|
2023-02-27 19:04:26 +01:00
|
|
|
caption: episode.publishedAt ? `Published ${this.$formatDate(episode.publishedAt, this.dateFormat)}` : 'Unknown publish date',
|
2022-09-02 00:11:57 +02:00
|
|
|
duration: episode.audioFile.duration || null,
|
|
|
|
coverPath: this.media.coverPath || null
|
|
|
|
})
|
|
|
|
}
|
2022-08-28 20:12:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$eventBus.$emit('play-item', {
|
|
|
|
libraryItemId: this.libraryItem.id,
|
|
|
|
episodeId: episode.id,
|
|
|
|
queueItems
|
|
|
|
})
|
|
|
|
},
|
2022-05-25 01:38:25 +02:00
|
|
|
removeEpisode(episode) {
|
2022-08-14 19:34:21 +02:00
|
|
|
this.episodesToRemove = [episode]
|
2022-05-25 01:38:25 +02:00
|
|
|
this.showPodcastRemoveModal = true
|
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
editEpisode(episode) {
|
2023-03-04 20:04:55 +01:00
|
|
|
const episodeIds = this.episodesSorted.map((e) => e.id)
|
|
|
|
this.$store.commit('setEpisodeTableEpisodeIds', episodeIds)
|
2022-04-23 02:31:11 +02:00
|
|
|
this.$store.commit('setSelectedLibraryItem', this.libraryItem)
|
|
|
|
this.$store.commit('globals/setSelectedEpisode', episode)
|
|
|
|
this.$store.commit('globals/setShowEditPodcastEpisodeModal', true)
|
2022-05-25 01:38:25 +02:00
|
|
|
},
|
2022-05-28 18:38:51 +02:00
|
|
|
viewEpisode(episode) {
|
|
|
|
this.$store.commit('setSelectedLibraryItem', this.libraryItem)
|
|
|
|
this.$store.commit('globals/setSelectedEpisode', episode)
|
|
|
|
this.$store.commit('globals/setShowViewPodcastEpisodeModal', true)
|
|
|
|
},
|
2022-05-25 01:38:25 +02:00
|
|
|
init() {
|
|
|
|
this.episodesCopy = this.episodes.map((ep) => ({ ...ep }))
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
|
|
|
},
|
2022-05-25 01:38:25 +02:00
|
|
|
mounted() {
|
|
|
|
this.init()
|
|
|
|
}
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.episode-item {
|
|
|
|
transition: all 0.4s ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
.episode-enter-from,
|
|
|
|
.episode-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateX(30px);
|
|
|
|
}
|
|
|
|
|
|
|
|
.episode-leave-active {
|
|
|
|
position: absolute;
|
|
|
|
}
|
2023-02-19 21:48:39 +01:00
|
|
|
</style>
|