From c41bdb951cd882e80c58109b958d9e37473cb44e Mon Sep 17 00:00:00 2001 From: Josh Vincent Date: Sat, 7 Jun 2025 14:48:05 -0600 Subject: [PATCH] Moves the lock button and fixes padding on bulk add feature. Moves the lock button the right of the Title text box. Enhances the bulk chapter add feature by preserving zero-padding in chapter titles and prevents editing of locked chapters. Also allows Enter to be pressed in the Add Multiple Chapters modal. Adds a warning toast when attempting to modify locked chapters. Fixes sizing of boxes on smaller windows --- client/pages/audiobook/_id/chapters.vue | 91 ++++++++++++++----------- client/strings/en-us.json | 1 + 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/client/pages/audiobook/_id/chapters.vue b/client/pages/audiobook/_id/chapters.vue index 26902240..4271b501 100644 --- a/client/pages/audiobook/_id/chapters.vue +++ b/client/pages/audiobook/_id/chapters.vue @@ -53,29 +53,20 @@
-
+
{{ $strings.LabelStart }}
+
{{ $strings.LabelTitle }}
+
-
-
{{ $strings.LabelStart }}
-
{{ $strings.LabelTitle }}
#{{ chapter.id + 1 }}
-
-
- - - -
-
-
+
+
+
+ + + +
+
@@ -136,14 +136,13 @@
-
-
+
- +
-
+
- @@ -266,15 +265,16 @@

{{ $strings.HeaderBulkChapterModal }}

{{ $strings.MessageBulkChapterPattern }}

+
- {{ $strings.LabelDetectedPattern }} "{{ detectedPattern.before }}{{ detectedPattern.startingNumber }}{{ detectedPattern.after }}" + {{ $strings.LabelDetectedPattern }} "{{ detectedPattern.before }}{{ formatNumberWithPadding(detectedPattern.startingNumber, detectedPattern) }}{{ detectedPattern.after }}"
{{ $strings.LabelNextChapters }} - "{{ detectedPattern.before }}{{ detectedPattern.startingNumber + 1 }}{{ detectedPattern.after }}", "{{ detectedPattern.before }}{{ detectedPattern.startingNumber + 2 }}{{ detectedPattern.after }}", etc. + "{{ detectedPattern.before }}{{ formatNumberWithPadding(detectedPattern.startingNumber + 1, detectedPattern) }}{{ detectedPattern.after }}", "{{ detectedPattern.before }}{{ formatNumberWithPadding(detectedPattern.startingNumber + 2, detectedPattern) }}{{ detectedPattern.after }}", etc.
- +
{{ $strings.ButtonAddChapters }} @@ -394,6 +394,12 @@ export default { } }, methods: { + formatNumberWithPadding(number, pattern) { + if (!pattern || !pattern.hasLeadingZeros || !pattern.originalPadding) { + return number.toString() + } + return number.toString().padStart(pattern.originalPadding, '0') + }, setChaptersFromTracks() { let currentStartTime = 0 let index = 0 @@ -460,15 +466,8 @@ export default { return } - // Find the previous chapter to ensure we don't go below it - const previousChapter = this.newChapters[chapter.id - 1] - if (previousChapter && chapter.start + amount <= previousChapter.start) { - return - } - - // Find the next chapter to ensure we don't go above it - const nextChapter = this.newChapters[chapter.id + 1] - if (nextChapter && chapter.start + amount >= nextChapter.start) { + if (this.lockedChapters.has(chapter.id)) { + this.$toast.warning(this.$strings.ToastChapterLocked) return } @@ -553,6 +552,10 @@ export default { this.checkChapters() }, removeChapter(chapter) { + if (this.lockedChapters.has(chapter.id)) { + this.$toast.warning(this.$strings.ToastChapterLocked) + return + } this.newChapters = this.newChapters.filter((ch) => ch.id !== chapter.id) this.checkChapters() }, @@ -874,17 +877,20 @@ export default { const numberMatch = input.match(/(\d+)/) if (numberMatch) { - // Extract the base pattern and number - const foundNumber = parseInt(numberMatch[1]) + // Extract the base pattern and number, preserving zero-padding + const originalNumberString = numberMatch[1] + const foundNumber = parseInt(originalNumberString) const numberIndex = numberMatch.index const beforeNumber = input.substring(0, numberIndex) - const afterNumber = input.substring(numberIndex + numberMatch[1].length) + const afterNumber = input.substring(numberIndex + originalNumberString.length) - // Store pattern info for bulk creation + // Store pattern info for bulk creation, preserving padding this.detectedPattern = { before: beforeNumber, after: afterNumber, - startingNumber: foundNumber + startingNumber: foundNumber, + originalPadding: originalNumberString.length, + hasLeadingZeros: originalNumberString.length > 1 && originalNumberString.startsWith('0') } // Show modal to ask for number of chapters @@ -920,13 +926,20 @@ export default { return } - const { before, after, startingNumber } = this.detectedPattern + const { before, after, startingNumber, originalPadding, hasLeadingZeros } = this.detectedPattern const lastChapter = this.newChapters[this.newChapters.length - 1] const baseStart = lastChapter ? lastChapter.start + 1 : 0 // Add multiple chapters with the detected pattern for (let i = 0; i < count; i++) { const chapterNumber = startingNumber + i + let formattedNumber = chapterNumber.toString() + + // Apply zero-padding if the original had leading zeros + if (hasLeadingZeros && originalPadding > 1) { + formattedNumber = chapterNumber.toString().padStart(originalPadding, '0') + } + const newStart = baseStart + i const newEnd = Math.min(newStart + i + i, this.mediaDuration) @@ -934,7 +947,7 @@ export default { id: this.newChapters.length, start: newStart, end: newEnd, - title: `${before}${chapterNumber}${after}` + title: `${before}${formattedNumber}${after}` } this.newChapters.push(newChapter) diff --git a/client/strings/en-us.json b/client/strings/en-us.json index 64c7d99c..a3923699 100644 --- a/client/strings/en-us.json +++ b/client/strings/en-us.json @@ -982,6 +982,7 @@ "ToastCachePurgeFailed": "Failed to purge cache", "ToastCachePurgeSuccess": "Cache purged successfully", "ToastChapterInvalidShiftAmount": "Invalid shift amount. First chapter would have zero or negative length.", + "ToastChapterLocked": "Chapter is locked.", "ToastChaptersAllLocked": "All chapters are locked. Unlock some chapters to shift their times.", "ToastChaptersHaveErrors": "Chapters have errors", "ToastChaptersInvalidShiftAmountLast": "Invalid shift amount. The last chapter start time would extend beyond the duration of this audiobook.",