|
86 | 86 | </div>
|
87 | 87 | </div>
|
88 | 88 |
|
89 |
| - <div class="w-full flex items-center justify-end p-4"> |
| 89 | + <div class="w-full flex items-center p-4 space-x-2"> |
| 90 | + <ui-btn small @click.stop="resetMapDetails">{{ $strings.ButtonReset }}</ui-btn> |
| 91 | + <ui-tooltip direction="bottom" :text="$strings.MessageBatchEditPopulateMapDetailsAllHelp"> |
| 92 | + <ui-btn small :disabled="!hasSelectedBatchUsage" @click.stop="populateFromExisting()">{{ $strings.ButtonBatchEditPopulateFromExisting }}</ui-btn> |
| 93 | + </ui-tooltip> |
| 94 | + <div class="flex-grow" /> |
90 | 95 | <ui-btn color="success" :disabled="!hasSelectedBatchUsage" :padding-x="8" small class="text-base" :loading="isProcessing" @click="mapBatchDetails">{{ $strings.ButtonApply }}</ui-btn>
|
91 | 96 | </div>
|
92 | 97 | </div>
|
|
97 | 102 | <div class="flex justify-center flex-wrap">
|
98 | 103 | <template v-for="libraryItem in libraryItemCopies">
|
99 | 104 | <div :key="libraryItem.id" class="w-full max-w-3xl border border-black-300 p-6 -ml-px -mt-px">
|
| 105 | + <div class="flex items-center justify-end"> |
| 106 | + <ui-tooltip direction="bottom" :text="$strings.MessageBatchEditPopulateMapDetailsItemHelp"> |
| 107 | + <ui-btn small :disabled="!hasSelectedBatchUsage" @click="populateFromExisting(libraryItem.id)">{{ $strings.ButtonBatchEditPopulateMapDetails }}</ui-btn> |
| 108 | + </ui-tooltip> |
| 109 | + </div> |
100 | 110 | <widgets-book-details-edit v-if="libraryItem.mediaType === 'book'" :ref="`itemForm-${libraryItem.id}`" :library-item="libraryItem" @change="handleItemChange" />
|
101 | 111 | <widgets-podcast-details-edit v-else :ref="`itemForm-${libraryItem.id}`" :library-item="libraryItem" @change="handleItemChange" />
|
102 | 112 | </div>
|
@@ -228,6 +238,88 @@ export default {
|
228 | 238 | }
|
229 | 239 | },
|
230 | 240 | methods: {
|
| 241 | + resetMapDetails() { |
| 242 | + this.blurBatchForm() |
| 243 | + this.batchDetails = { |
| 244 | + subtitle: null, |
| 245 | + authors: null, |
| 246 | + publishedYear: null, |
| 247 | + series: [], |
| 248 | + genres: [], |
| 249 | + tags: [], |
| 250 | + narrators: [], |
| 251 | + publisher: null, |
| 252 | + language: null, |
| 253 | + explicit: false, |
| 254 | + abridged: false |
| 255 | + } |
| 256 | + this.selectedBatchUsage = { |
| 257 | + subtitle: false, |
| 258 | + authors: false, |
| 259 | + publishedYear: false, |
| 260 | + series: false, |
| 261 | + genres: false, |
| 262 | + tags: false, |
| 263 | + narrators: false, |
| 264 | + publisher: false, |
| 265 | + language: false, |
| 266 | + explicit: false, |
| 267 | + abridged: false |
| 268 | + } |
| 269 | + }, |
| 270 | + populateFromExisting(libraryItemId) { |
| 271 | + this.blurBatchForm() |
| 272 | +
|
| 273 | + let libraryItemsToMap = this.libraryItemCopies |
| 274 | + if (libraryItemId) { |
| 275 | + libraryItemsToMap = this.libraryItemCopies.filter((li) => li.id === libraryItemId) |
| 276 | + } |
| 277 | +
|
| 278 | + for (const key in this.selectedBatchUsage) { |
| 279 | + if (!this.selectedBatchUsage[key]) continue |
| 280 | + if (this.isMapAppend && !this.appendableKeys.includes(key)) continue |
| 281 | +
|
| 282 | + let existingValues = undefined |
| 283 | + libraryItemsToMap.forEach((li) => { |
| 284 | + if (key === 'tags') { |
| 285 | + if (!existingValues) existingValues = [] |
| 286 | + li.media.tags.forEach((tag) => { |
| 287 | + if (!existingValues.includes(tag)) { |
| 288 | + existingValues.push(tag) |
| 289 | + } |
| 290 | + }) |
| 291 | + } else if (key === 'authors') { |
| 292 | + if (!existingValues) existingValues = [] |
| 293 | + li.media.metadata[key].forEach((entity) => { |
| 294 | + if (!existingValues.some((au) => au.id === entity.id)) { |
| 295 | + existingValues.push({ |
| 296 | + id: entity.id, |
| 297 | + name: entity.name |
| 298 | + }) |
| 299 | + } |
| 300 | + }) |
| 301 | + } else if (key === 'series') { |
| 302 | + if (!existingValues) existingValues = [] |
| 303 | + li.media.metadata[key].forEach((entity) => { |
| 304 | + if (!existingValues.includes(entity.name)) { |
| 305 | + existingValues.push(entity.name) |
| 306 | + } |
| 307 | + }) |
| 308 | + } else if (key === 'genres' || key === 'narrators') { |
| 309 | + if (!existingValues) existingValues = [] |
| 310 | + li.media.metadata[key].forEach((item) => { |
| 311 | + if (!existingValues.includes(item)) { |
| 312 | + existingValues.push(item) |
| 313 | + } |
| 314 | + }) |
| 315 | + } else if (existingValues === undefined) { |
| 316 | + existingValues = li.media.metadata[key] |
| 317 | + } |
| 318 | + }) |
| 319 | +
|
| 320 | + this.batchDetails[key] = existingValues |
| 321 | + } |
| 322 | + }, |
231 | 323 | handleItemChange(itemChange) {
|
232 | 324 | if (!itemChange.hasChanges) {
|
233 | 325 | this.itemsWithChanges = this.itemsWithChanges.filter((id) => id !== itemChange.libraryItemId)
|
|
0 commit comments