mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Fix:Remove collections when removing library
This commit is contained in:
parent
6f901defd6
commit
28feed6ea2
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<modals-modal v-model="show" name="collections" :processing="processing" :width="500" :height="'unset'">
|
<modals-modal v-model="show" name="collections" :processing="processing" :width="500" :height="'unset'">
|
||||||
<template #outer>
|
<template #outer>
|
||||||
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden">
|
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden pointer-events-none">
|
||||||
<p class="font-book text-3xl text-white truncate">{{ title }}</p>
|
<p class="font-book text-3xl text-white truncate">{{ title }}</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -41,8 +41,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
newCollectionName: '',
|
newCollectionName: '',
|
||||||
processing: false,
|
processing: false
|
||||||
collections: []
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -70,6 +69,9 @@ export default {
|
|||||||
}
|
}
|
||||||
return this.selectedLibraryItem ? this.selectedLibraryItem.media.metadata.title : ''
|
return this.selectedLibraryItem ? this.selectedLibraryItem.media.metadata.title : ''
|
||||||
},
|
},
|
||||||
|
collections() {
|
||||||
|
return this.$store.state.libraries.collections || []
|
||||||
|
},
|
||||||
bookCoverAspectRatio() {
|
bookCoverAspectRatio() {
|
||||||
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
||||||
},
|
},
|
||||||
@ -110,11 +112,14 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadCollections() {
|
loadCollections() {
|
||||||
|
if (!this.collections.length) {
|
||||||
this.processing = true
|
this.processing = true
|
||||||
this.$axios
|
this.$axios
|
||||||
.$get(`/api/libraries/${this.currentLibraryId}/collections`)
|
.$get(`/api/libraries/${this.currentLibraryId}/collections`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
this.collections = data.results || []
|
if (data.results) {
|
||||||
|
this.$store.commit('libraries/setCollections', data.results || [])
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Failed to get collections', error)
|
console.error('Failed to get collections', error)
|
||||||
@ -123,6 +128,7 @@ export default {
|
|||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.processing = false
|
this.processing = false
|
||||||
})
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
removeFromCollection(collection) {
|
removeFromCollection(collection) {
|
||||||
if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return
|
if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return
|
||||||
|
@ -298,10 +298,10 @@ export default {
|
|||||||
this.$store.commit('user/updateMediaProgress', payload)
|
this.$store.commit('user/updateMediaProgress', payload)
|
||||||
},
|
},
|
||||||
collectionAdded(collection) {
|
collectionAdded(collection) {
|
||||||
this.$store.commit('user/addUpdateCollection', collection)
|
this.$store.commit('libraries/addUpdateCollection', collection)
|
||||||
},
|
},
|
||||||
collectionUpdated(collection) {
|
collectionUpdated(collection) {
|
||||||
this.$store.commit('user/addUpdateCollection', collection)
|
this.$store.commit('libraries/addUpdateCollection', collection)
|
||||||
},
|
},
|
||||||
collectionRemoved(collection) {
|
collectionRemoved(collection) {
|
||||||
if (this.$route.name.startsWith('collection')) {
|
if (this.$route.name.startsWith('collection')) {
|
||||||
@ -309,7 +309,7 @@ export default {
|
|||||||
this.$router.replace(`/library/${this.$store.state.libraries.currentLibraryId}/bookshelf/collections`)
|
this.$router.replace(`/library/${this.$store.state.libraries.currentLibraryId}/bookshelf/collections`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.$store.commit('user/removeCollection', collection)
|
this.$store.commit('libraries/removeCollection', collection)
|
||||||
},
|
},
|
||||||
rssFeedOpen(data) {
|
rssFeedOpen(data) {
|
||||||
this.$store.commit('feeds/addFeed', data)
|
this.$store.commit('feeds/addFeed', data)
|
||||||
|
@ -52,7 +52,7 @@ export default {
|
|||||||
return redirect('/')
|
return redirect('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
store.commit('user/addUpdateCollection', collection)
|
store.commit('libraries/addUpdateCollection', collection)
|
||||||
return {
|
return {
|
||||||
collectionId: collection.id
|
collectionId: collection.id
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ export default {
|
|||||||
return this.collection.description || ''
|
return this.collection.description || ''
|
||||||
},
|
},
|
||||||
collection() {
|
collection() {
|
||||||
return this.$store.getters['user/getCollection'](this.collectionId)
|
return this.$store.getters['libraries/getCollection'](this.collectionId) || {}
|
||||||
},
|
},
|
||||||
playableBooks() {
|
playableBooks() {
|
||||||
return this.bookItems.filter((book) => {
|
return this.bookItems.filter((book) => {
|
||||||
|
@ -11,7 +11,8 @@ export const state = () => ({
|
|||||||
filterData: null,
|
filterData: null,
|
||||||
seriesSortBy: 'name',
|
seriesSortBy: 'name',
|
||||||
seriesSortDesc: false,
|
seriesSortDesc: false,
|
||||||
seriesFilterBy: 'all'
|
seriesFilterBy: 'all',
|
||||||
|
collections: []
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
@ -55,6 +56,9 @@ export const getters = {
|
|||||||
getBookCoverAspectRatio: (state, getters) => {
|
getBookCoverAspectRatio: (state, getters) => {
|
||||||
if (!getters.getCurrentLibrarySettings || isNaN(getters.getCurrentLibrarySettings.coverAspectRatio)) return 1
|
if (!getters.getCurrentLibrarySettings || isNaN(getters.getCurrentLibrarySettings.coverAspectRatio)) return 1
|
||||||
return getters.getCurrentLibrarySettings.coverAspectRatio === Constants.BookCoverAspectRatio.STANDARD ? 1.6 : 1
|
return getters.getCurrentLibrarySettings.coverAspectRatio === Constants.BookCoverAspectRatio.STANDARD ? 1.6 : 1
|
||||||
|
},
|
||||||
|
getCollection: state => id => {
|
||||||
|
return state.collections.find(c => c.id === id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +115,7 @@ export const actions = {
|
|||||||
commit('setLibraryIssues', issues)
|
commit('setLibraryIssues', issues)
|
||||||
commit('setLibraryFilterData', filterData)
|
commit('setLibraryFilterData', filterData)
|
||||||
commit('setCurrentLibrary', libraryId)
|
commit('setCurrentLibrary', libraryId)
|
||||||
|
commit('setCollections', [])
|
||||||
return data
|
return data
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -301,5 +306,19 @@ export const mutations = {
|
|||||||
},
|
},
|
||||||
setSeriesFilterBy(state, filterBy) {
|
setSeriesFilterBy(state, filterBy) {
|
||||||
state.seriesFilterBy = filterBy
|
state.seriesFilterBy = filterBy
|
||||||
|
},
|
||||||
|
setCollections(state, collections) {
|
||||||
|
state.collections = collections
|
||||||
|
},
|
||||||
|
addUpdateCollection(state, collection) {
|
||||||
|
var index = state.collections.findIndex(c => c.id === collection.id)
|
||||||
|
if (index >= 0) {
|
||||||
|
state.collections.splice(index, 1, collection)
|
||||||
|
} else {
|
||||||
|
state.collections.push(collection)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeCollection(state, collection) {
|
||||||
|
state.collections = state.collections.filter(c => c.id !== collection.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,8 +9,7 @@ export const state = () => ({
|
|||||||
collapseSeries: false,
|
collapseSeries: false,
|
||||||
collapseBookSeries: false
|
collapseBookSeries: false
|
||||||
},
|
},
|
||||||
settingsListeners: [],
|
settingsListeners: []
|
||||||
collections: []
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
@ -57,9 +56,6 @@ export const getters = {
|
|||||||
if (!state.user) return false
|
if (!state.user) return false
|
||||||
if (getters.getUserCanAccessAllLibraries) return true
|
if (getters.getUserCanAccessAllLibraries) return true
|
||||||
return getters.getLibrariesAccessible.includes(libraryId)
|
return getters.getLibrariesAccessible.includes(libraryId)
|
||||||
},
|
|
||||||
getCollection: state => id => {
|
|
||||||
return state.collections.find(c => c.id === id)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,16 +159,5 @@ export const mutations = {
|
|||||||
},
|
},
|
||||||
removeSettingsListener(state, listenerId) {
|
removeSettingsListener(state, listenerId) {
|
||||||
state.settingsListeners = state.settingsListeners.filter(l => l.id !== listenerId)
|
state.settingsListeners = state.settingsListeners.filter(l => l.id !== listenerId)
|
||||||
},
|
|
||||||
addUpdateCollection(state, collection) {
|
|
||||||
var index = state.collections.findIndex(c => c.id === collection.id)
|
|
||||||
if (index >= 0) {
|
|
||||||
state.collections.splice(index, 1, collection)
|
|
||||||
} else {
|
|
||||||
state.collections.push(collection)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
removeCollection(state, collection) {
|
|
||||||
state.collections = state.collections.filter(c => c.id !== collection.id)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -131,6 +131,13 @@ class LibraryController {
|
|||||||
// Remove library watcher
|
// Remove library watcher
|
||||||
this.watcher.removeLibrary(library)
|
this.watcher.removeLibrary(library)
|
||||||
|
|
||||||
|
// Remove collections for library
|
||||||
|
var collections = this.db.collections.filter(c => c.libraryId === library.id)
|
||||||
|
for (const collection of collections) {
|
||||||
|
Logger.info(`[Server] deleting collection "${collection.name}" for library "${library.name}"`)
|
||||||
|
await this.db.removeEntity('collection', collection.id)
|
||||||
|
}
|
||||||
|
|
||||||
// Remove items in this library
|
// Remove items in this library
|
||||||
var libraryItems = this.db.libraryItems.filter(li => li.libraryId === library.id)
|
var libraryItems = this.db.libraryItems.filter(li => li.libraryId === library.id)
|
||||||
Logger.info(`[Server] deleting library "${library.name}" with ${libraryItems.length} items"`)
|
Logger.info(`[Server] deleting library "${library.name}" with ${libraryItems.length} items"`)
|
||||||
|
Loading…
Reference in New Issue
Block a user