mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-03-01 05:29:41 +00:00
Implement interactive consolidation conflict resolution with merge and rename options
This commit is contained in:
parent
ca85e4af43
commit
86b036cb7c
7 changed files with 260 additions and 20 deletions
|
|
@ -273,16 +273,25 @@ export default {
|
|||
batchConsolidate() {
|
||||
const payload = {
|
||||
message: this.$getString('MessageConfirmConsolidate', [this.$getString('MessageItemsSelected', [this.numMediaItemsSelected]), 'Author - Title']),
|
||||
callback: (confirmed) => {
|
||||
checkboxLabel: 'Merge contents on conflict',
|
||||
checkboxType: 'checkbox',
|
||||
callback: (confirmed, merge) => {
|
||||
if (confirmed) {
|
||||
this.$store.commit('setProcessingBatch', true)
|
||||
this.$axios
|
||||
.$post('/api/items/batch/consolidate', {
|
||||
libraryItemIds: this.selectedMediaItems.map((i) => i.id)
|
||||
libraryItemIds: this.selectedMediaItems.map((i) => i.id),
|
||||
merge
|
||||
})
|
||||
.then((data) => {
|
||||
this.$toast.success(this.$strings.ToastBatchConsolidateSuccess)
|
||||
if (this.numMediaItemsSelected === 1) {
|
||||
if (data.success) {
|
||||
this.$toast.success(this.$strings.ToastBatchConsolidateSuccess)
|
||||
} else {
|
||||
const numFailed = data.results.filter((r) => !r.success).length
|
||||
this.$toast.warning(`${numFailed} items failed to consolidate. They may already exist or have other errors.`)
|
||||
}
|
||||
|
||||
if (this.numMediaItemsSelected === 1 && data.success) {
|
||||
this.$router.push(`/item/${this.selectedMediaItems[0].id}`)
|
||||
}
|
||||
this.cancelSelectionMode()
|
||||
|
|
|
|||
|
|
@ -830,7 +830,19 @@ export default {
|
|||
})
|
||||
.catch((error) => {
|
||||
console.error('Failed to consolidate', error)
|
||||
this.$toast.error(error.response?.data || this.$strings.ToastConsolidateFailed || 'Consolidate failed')
|
||||
if (error.response?.status === 409) {
|
||||
const data = error.response.data
|
||||
const author = this.mediaMetadata.authorName?.split(',')[0]?.trim() || 'Unknown Author'
|
||||
const title = this.mediaMetadata.title || 'Unknown Title'
|
||||
this.$eventBus.$emit('show-consolidation-conflict', {
|
||||
item: this._libraryItem,
|
||||
path: data.path,
|
||||
folderName: this.$getConsolidatedFolderName(author, title),
|
||||
existingLibraryItemId: data.existingLibraryItemId
|
||||
})
|
||||
} else {
|
||||
this.$toast.error(error.response?.data?.error || error.response?.data || this.$strings.ToastConsolidateFailed || 'Consolidate failed')
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.processing = false
|
||||
|
|
|
|||
107
client/components/modals/ConsolidationConflictModal.vue
Normal file
107
client/components/modals/ConsolidationConflictModal.vue
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
<template>
|
||||
<modals-modal v-model="show" name="consolidation-conflict" :width="500" :processing="processing">
|
||||
<div class="px-6 py-6 font-sans">
|
||||
<div class="flex items-center mb-4">
|
||||
<span class="material-symbols text-yellow-500 text-3xl mr-3 font-bold">warning</span>
|
||||
<h2 class="text-xl font-semibold text-white">Consolidation Conflict</h2>
|
||||
</div>
|
||||
|
||||
<div class="text-gray-200 mb-6 text-sm">
|
||||
<p class="mb-2">The destination folder already exists:</p>
|
||||
<div class="bg-black/30 p-3 rounded-md font-mono text-xs break-all border border-white/10 mb-4 text-gray-300">
|
||||
{{ folderPath }}
|
||||
</div>
|
||||
<div v-if="existingLibraryItemId" class="flex items-center text-xs text-yellow-400/80 mb-4 bg-yellow-400/5 p-2 rounded-sm border border-yellow-400/10">
|
||||
<span class="material-symbols text-sm mr-2">info</span>
|
||||
Another library item is already at this location.
|
||||
</div>
|
||||
<p class="text-base text-white/90">How would you like to resolve this?</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 mb-8">
|
||||
<div class="bg-white/5 rounded-lg border border-white/5 p-1">
|
||||
<label class="flex items-start p-3 cursor-pointer group hover:bg-white/5 rounded-md transition-colors duration-200" :class="{ 'bg-white/5 border-white/10': resolution === 'merge' }">
|
||||
<input v-model="resolution" type="radio" value="merge" class="mt-1 mr-4 accent-yellow-500" />
|
||||
<div class="flex-1">
|
||||
<span class="text-white font-medium block mb-0.5 group-hover:text-yellow-400 transition-colors">Merge Contents</span>
|
||||
<p class="text-xs text-gray-400 leading-relaxed">Move all files from this book into the existing folder. Files with identical names will be automatically renamed with a timestamp.</p>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="flex items-start p-3 cursor-pointer group hover:bg-white/5 rounded-md transition-colors duration-200" :class="{ 'bg-white/5 border-white/10': resolution === 'rename' }">
|
||||
<input v-model="resolution" type="radio" value="rename" class="mt-1 mr-4 accent-yellow-500" />
|
||||
<div class="flex-1">
|
||||
<span class="text-white font-medium block mb-0.5 group-hover:text-yellow-400 transition-colors">Rename Destination</span>
|
||||
<p class="text-xs text-gray-400 leading-relaxed mb-3">Save this book to a different folder name instead.</p>
|
||||
<div v-if="resolution === 'rename'" class="mt-2 pl-1">
|
||||
<ui-text-input v-model="newName" class="w-full" placeholder="Enter new folder name" @keyup.enter="submit" />
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end space-x-3 pt-4 border-t border-white/10">
|
||||
<ui-btn @click="show = false">Cancel</ui-btn>
|
||||
<ui-btn color="success" class="px-6" :loading="processing" @click="submit">Confirm Resolution</ui-btn>
|
||||
</div>
|
||||
</div>
|
||||
</modals-modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
value: Boolean,
|
||||
item: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
folderPath: String,
|
||||
folderName: String,
|
||||
existingLibraryItemId: String,
|
||||
processing: Boolean
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
resolution: 'merge',
|
||||
newName: ''
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
show: {
|
||||
get() {
|
||||
return this.value
|
||||
},
|
||||
set(val) {
|
||||
this.$emit('input', val)
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
folderName(val) {
|
||||
if (val) this.newName = val
|
||||
},
|
||||
show(val) {
|
||||
if (val) {
|
||||
this.resolution = 'merge'
|
||||
this.newName = this.folderName || ''
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit() {
|
||||
if (this.resolution === 'rename' && !this.newName.trim()) {
|
||||
this.$toast.error('New folder name is required')
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
merge: this.resolution === 'merge',
|
||||
newName: this.resolution === 'rename' ? this.newName.trim() : null
|
||||
}
|
||||
this.$emit('confirm', payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
@ -22,6 +22,15 @@
|
|||
<modals-raw-cover-preview-modal />
|
||||
<modals-share-modal />
|
||||
<modals-item-move-to-library-modal />
|
||||
<modals-consolidation-conflict-modal
|
||||
v-model="showConsolidationConflictModal"
|
||||
:item="consolidationConflictItem"
|
||||
:folder-path="consolidationConflictPath"
|
||||
:folder-name="consolidationConflictFolderName"
|
||||
:existing-library-item-id="consolidationConflictExistingItemId"
|
||||
:processing="processingConsolidationConflict"
|
||||
@confirm="resolveConsolidationConflict"
|
||||
/>
|
||||
<prompt-confirm />
|
||||
<readers-reader />
|
||||
</div>
|
||||
|
|
@ -39,7 +48,13 @@ export default {
|
|||
socketConnectionToastId: null,
|
||||
currentLang: null,
|
||||
multiSessionOtherSessionId: null, // Used for multiple sessions open warning toast
|
||||
multiSessionCurrentSessionId: null // Used for multiple sessions open warning toast
|
||||
multiSessionCurrentSessionId: null, // Used for multiple sessions open warning toast
|
||||
showConsolidationConflictModal: false,
|
||||
consolidationConflictItem: null,
|
||||
consolidationConflictPath: '',
|
||||
consolidationConflictFolderName: '',
|
||||
consolidationConflictExistingItemId: null,
|
||||
processingConsolidationConflict: false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
|
@ -600,6 +615,27 @@ export default {
|
|||
console.log('Changed lang', code)
|
||||
this.currentLang = code
|
||||
document.documentElement.lang = code
|
||||
},
|
||||
openConsolidationConflict(data) {
|
||||
this.consolidationConflictItem = data.item
|
||||
this.consolidationConflictPath = data.path
|
||||
this.consolidationConflictFolderName = data.folderName
|
||||
this.consolidationConflictExistingItemId = data.existingLibraryItemId
|
||||
this.showConsolidationConflictModal = true
|
||||
},
|
||||
async resolveConsolidationConflict(payload) {
|
||||
this.processingConsolidationConflict = true
|
||||
const axios = this.$axios || this.$nuxt.$axios
|
||||
try {
|
||||
await axios.$post(`/api/items/${this.consolidationConflictItem.id}/consolidate`, payload)
|
||||
this.$toast.success(this.$strings.ToastConsolidateSuccess || 'Consolidation successful')
|
||||
this.showConsolidationConflictModal = false
|
||||
} catch (error) {
|
||||
console.error('Failed to resolve consolidation conflict', error)
|
||||
this.$toast.error(error.response?.data?.error || error.response?.data || 'Failed to resolve conflict')
|
||||
} finally {
|
||||
this.processingConsolidationConflict = false
|
||||
}
|
||||
}
|
||||
},
|
||||
beforeMount() {
|
||||
|
|
@ -610,6 +646,7 @@ export default {
|
|||
this.resize()
|
||||
this.$eventBus.$on('change-lang', this.changeLanguage)
|
||||
this.$eventBus.$on('token_refreshed', this.tokenRefreshed)
|
||||
this.$eventBus.$on('show-consolidation-conflict', this.openConsolidationConflict)
|
||||
window.addEventListener('resize', this.resize)
|
||||
window.addEventListener('keydown', this.keyDown)
|
||||
|
||||
|
|
@ -634,6 +671,7 @@ export default {
|
|||
beforeDestroy() {
|
||||
this.$eventBus.$off('change-lang', this.changeLanguage)
|
||||
this.$eventBus.$off('token_refreshed', this.tokenRefreshed)
|
||||
this.$eventBus.$off('show-consolidation-conflict', this.openConsolidationConflict)
|
||||
window.removeEventListener('resize', this.resize)
|
||||
window.removeEventListener('keydown', this.keyDown)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -812,7 +812,19 @@ export default {
|
|||
})
|
||||
.catch((error) => {
|
||||
console.error('Failed to consolidate', error)
|
||||
this.$toast.error(error.response?.data || this.$strings.ToastConsolidateFailed)
|
||||
if (error.response?.status === 409) {
|
||||
const data = error.response.data
|
||||
const author = this.mediaMetadata.authorName?.split(',')[0]?.trim() || 'Unknown Author'
|
||||
const title = this.mediaMetadata.title || 'Unknown Title'
|
||||
this.$eventBus.$emit('show-consolidation-conflict', {
|
||||
item: this.libraryItem,
|
||||
path: data.path,
|
||||
folderName: this.$getConsolidatedFolderName(author, title),
|
||||
existingLibraryItemId: data.existingLibraryItemId
|
||||
})
|
||||
} else {
|
||||
this.$toast.error(error.response?.data?.error || error.response?.data || this.$strings.ToastConsolidateFailed)
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.processing = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue