menu
diff --git a/client/components/tables/podcast/EpisodesTable.vue b/client/components/tables/podcast/EpisodesTable.vue
index 98f5b586..c216558d 100644
--- a/client/components/tables/podcast/EpisodesTable.vue
+++ b/client/components/tables/podcast/EpisodesTable.vue
@@ -1,6 +1,13 @@
-
Episodes
+
No Episodes
@@ -29,15 +36,14 @@ export default {
},
data() {
return {
+ sortKey: 'index',
+ sortDesc: true,
drag: false,
- dragOptions: {
- animation: 200,
- group: 'description',
- ghostClass: 'ghost'
- },
episodesCopy: [],
selectedEpisode: null,
- showEditEpisodeModal: false
+ showEditEpisodeModal: false,
+ orderChanged: false,
+ savingOrder: false
}
},
watch: {
@@ -48,6 +54,17 @@ export default {
}
},
computed: {
+ dragOptions() {
+ return {
+ animation: 200,
+ group: 'description',
+ ghostClass: 'ghost',
+ disabled: !this.userCanUpdate
+ }
+ },
+ userCanUpdate() {
+ return this.$store.getters['user/getUserCanUpdate']
+ },
media() {
return this.libraryItem.media || {}
},
@@ -59,23 +76,53 @@ export default {
}
},
methods: {
+ changeSort() {
+ this.episodesCopy.sort((a, b) => {
+ if (this.sortDesc) {
+ return String(b[this.sortKey]).localeCompare(String(a[this.sortKey]), undefined, { numeric: true, sensitivity: 'base' })
+ }
+ return String(a[this.sortKey]).localeCompare(String(b[this.sortKey]), undefined, { numeric: true, sensitivity: 'base' })
+ })
+
+ this.orderChanged = this.checkHasOrderChanged()
+ },
+ checkHasOrderChanged() {
+ for (let i = 0; i < this.episodesCopy.length; i++) {
+ var epc = this.episodesCopy[i]
+ var ep = this.episodes[i]
+ if (epc.index != ep.index) {
+ return true
+ }
+ }
+ return false
+ },
editEpisode(episode) {
this.selectedEpisode = episode
this.showEditEpisodeModal = true
},
draggableUpdate() {
+ this.orderChanged = this.checkHasOrderChanged()
+ },
+ async saveOrder() {
+ if (!this.userCanUpdate) return
+
+ this.savingOrder = true
+
var episodesUpdate = {
episodes: this.episodesCopy.map((b) => b.id)
}
- this.$axios
+ await this.$axios
.$patch(`/api/items/${this.libraryItem.id}/episodes`, episodesUpdate)
.then((podcast) => {
console.log('Podcast updated', podcast)
+ this.$toast.success('Saved episode order')
+ this.orderChanged = false
})
.catch((error) => {
console.error('Failed to update podcast', error)
this.$toast.error('Failed to save podcast episode order')
})
+ this.savingOrder = false
},
init() {
this.episodesCopy = this.episodes.map((ep) => {