Skip to content

Commit bb0cc1b

Browse files
authored
Merge pull request #3887 from advplyr/batch-edit-populate-map-details
Add populate map details from buttons to batch editor
2 parents 598a93d + abb5bd3 commit bb0cc1b

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

client/pages/batch/index.vue

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@
8686
</div>
8787
</div>
8888

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" />
9095
<ui-btn color="success" :disabled="!hasSelectedBatchUsage" :padding-x="8" small class="text-base" :loading="isProcessing" @click="mapBatchDetails">{{ $strings.ButtonApply }}</ui-btn>
9196
</div>
9297
</div>
@@ -97,6 +102,11 @@
97102
<div class="flex justify-center flex-wrap">
98103
<template v-for="libraryItem in libraryItemCopies">
99104
<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>
100110
<widgets-book-details-edit v-if="libraryItem.mediaType === 'book'" :ref="`itemForm-${libraryItem.id}`" :library-item="libraryItem" @change="handleItemChange" />
101111
<widgets-podcast-details-edit v-else :ref="`itemForm-${libraryItem.id}`" :library-item="libraryItem" @change="handleItemChange" />
102112
</div>
@@ -228,6 +238,88 @@ export default {
228238
}
229239
},
230240
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+
},
231323
handleItemChange(itemChange) {
232324
if (!itemChange.hasChanges) {
233325
this.itemsWithChanges = this.itemsWithChanges.filter((id) => id !== itemChange.libraryItemId)

client/strings/en-us.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"ButtonApplyChapters": "Apply Chapters",
1111
"ButtonAuthors": "Authors",
1212
"ButtonBack": "Back",
13+
"ButtonBatchEditPopulateFromExisting": "Populate from existing",
14+
"ButtonBatchEditPopulateMapDetails": "Populate map details",
1315
"ButtonBrowseForFolder": "Browse for Folder",
1416
"ButtonCancel": "Cancel",
1517
"ButtonCancelEncode": "Cancel Encode",
@@ -704,6 +706,8 @@
704706
"MessageBackupsLocationEditNote": "Note: Updating the backup location will not move or modify existing backups",
705707
"MessageBackupsLocationNoEditNote": "Note: The backup location is set through an environment variable and cannot be changed here.",
706708
"MessageBackupsLocationPathEmpty": "Backup location path cannot be empty",
709+
"MessageBatchEditPopulateMapDetailsAllHelp": "Populate enabled fields with data from all items. Fields with multiple values will be merged",
710+
"MessageBatchEditPopulateMapDetailsItemHelp": "Populate enabled map details fields with data from this item",
707711
"MessageBatchQuickMatchDescription": "Quick Match will attempt to add missing covers and metadata for the selected items. Enable the options below to allow Quick Match to overwrite existing covers and/or metadata.",
708712
"MessageBookshelfNoCollections": "You haven't made any collections yet",
709713
"MessageBookshelfNoRSSFeeds": "No RSS feeds are open",

0 commit comments

Comments
 (0)