feat: implement promote file to book and split book functionality

This commit is contained in:
Tiberiu Ichim 2026-02-20 17:42:45 +02:00
parent 8be6f3a3d0
commit f171755d43
6 changed files with 367 additions and 0 deletions

View file

@ -7,6 +7,7 @@
</div>
<div class="grow" />
<ui-btn v-if="userIsAdmin" small :color="showFullPath ? 'bg-gray-600' : 'bg-primary'" class="mr-2 hidden md:block" @click.stop="toggleFullPath">{{ $strings.ButtonFullPath }}</ui-btn>
<ui-btn v-if="userCanDelete" small color="bg-primary" class="mr-2" @click.stop="showSplitBookModal = true">{{ $strings.ButtonSplitBook || 'Split Book' }}</ui-btn>
<div class="cursor-pointer h-10 w-10 rounded-full hover:bg-black-400 flex justify-center items-center duration-500" :class="showFiles ? 'transform rotate-180' : ''">
<span class="material-symbols text-4xl">&#xe313;</span>
</div>
@ -28,6 +29,7 @@
</transition>
<modals-audio-file-data-modal v-model="showAudioFileDataModal" :library-item-id="libraryItemId" :audio-file="selectedAudioFile" />
<modals-item-split-book-modal v-model="showSplitBookModal" :library-item="libraryItem" />
</div>
</template>
@ -46,6 +48,7 @@ export default {
showFiles: false,
showFullPath: false,
showAudioFileDataModal: false,
showSplitBookModal: false,
selectedAudioFile: null
}
},

View file

@ -55,6 +55,12 @@ export default {
action: 'download'
})
}
if (this.userCanDelete && (this.file.audioFile || this.file.isEBookFile)) {
items.push({
text: this.$strings.LabelPromoteToBook || 'Promote to book',
action: 'promote'
})
}
if (this.userCanDelete) {
items.push({
text: this.$strings.ButtonDelete,
@ -77,6 +83,8 @@ export default {
this.deleteLibraryFile()
} else if (action === 'download') {
this.downloadLibraryFile()
} else if (action === 'promote') {
this.promoteLibraryFile()
} else if (action === 'more') {
this.$emit('showMore', this.file.audioFile)
}
@ -103,6 +111,27 @@ export default {
},
downloadLibraryFile() {
this.$downloadFile(this.downloadUrl, this.file.metadata.filename)
},
promoteLibraryFile() {
const payload = {
message: this.$strings.MessageConfirmPromoteFile || 'Are you sure you want to promote this file to a new book?',
callback: (confirmed) => {
if (confirmed) {
this.$axios
.$post(`/api/items/${this.libraryItemId}/file/${this.file.ino}/promote`)
.then(() => {
this.$toast.success(this.$strings.ToastPromoteFileSuccess || 'File successfully promoted to new book')
})
.catch((error) => {
console.error('Failed to promote file', error)
const errorMsg = error.response?.data || 'Unknown error'
this.$toast.error(this.$strings.ToastPromoteFileFailed || `Failed to promote file: ${errorMsg}`)
})
}
},
type: 'yesNo'
}
this.$store.commit('globals/setConfirmPrompt', payload)
}
},
mounted() {}