Add:Match All Authors button #642

This commit is contained in:
advplyr 2022-05-29 12:15:39 -05:00
parent 514893646a
commit cfcd351570
3 changed files with 53 additions and 4 deletions

View File

@ -61,6 +61,10 @@
<p>Search results for "{{ searchQuery }}"</p> <p>Search results for "{{ searchQuery }}"</p>
<div class="flex-grow" /> <div class="flex-grow" />
</template> </template>
<template v-else-if="page === 'authors'">
<div class="flex-grow" />
<ui-btn v-if="userCanUpdate && authors && authors.length" :loading="processingAuthors" color="primary" small @click="matchAllAuthors">Match All Authors</ui-btn>
</template>
</div> </div>
</div> </div>
</template> </template>
@ -75,7 +79,11 @@ export default {
default: () => null default: () => null
}, },
searchQuery: String, searchQuery: String,
viewMode: String viewMode: String,
authors: {
type: Array,
default: () => []
}
}, },
data() { data() {
return { return {
@ -85,13 +93,17 @@ export default {
keywordFilter: null, keywordFilter: null,
keywordTimeout: null, keywordTimeout: null,
processingSeries: false, processingSeries: false,
processingIssues: false processingIssues: false,
processingAuthors: false
} }
}, },
computed: { computed: {
userCanDelete() { userCanDelete() {
return this.$store.getters['user/getUserCanDelete'] return this.$store.getters['user/getUserCanDelete']
}, },
userCanUpdate() {
return this.$store.getters['user/getUserCanUpdate']
},
isPodcast() { isPodcast() {
return this.$store.getters['libraries/getCurrentLibraryMediaType'] == 'podcast' return this.$store.getters['libraries/getCurrentLibraryMediaType'] == 'podcast'
}, },
@ -147,6 +159,35 @@ export default {
} }
}, },
methods: { methods: {
async matchAllAuthors() {
this.processingAuthors = true
for (const author of this.authors) {
const payload = {}
if (author.asin) payload.asin = author.asin
else payload.q = author.name
console.log('Payload', payload, 'author', author)
this.$eventBus.$emit(`searching-author-${author.id}`, true)
var response = await this.$axios.$post(`/api/authors/${author.id}/match`, payload).catch((error) => {
console.error('Failed', error)
return null
})
if (!response) {
console.error(`Author ${author.name} not found`)
this.$toast.error(`Author ${author.name} not found`)
} else if (response.updated) {
if (response.author.imagePath) console.log(`Author ${response.author.name} was updated`)
else console.log(`Author ${response.author.name} was updated (no image found)`)
} else {
console.log(`No updates were made for Author ${response.author.name}`)
}
this.$eventBus.$emit(`searching-author-${author.id}`, false)
}
this.processingAuthors = false
},
removeAllIssues() { removeAllIssues() {
if (confirm(`Are you sure you want to remove all library items with issues?\n\nNote: This will not delete any files`)) { if (confirm(`Are you sure you want to remove all library items with issues?\n\nNote: This will not delete any files`)) {
this.processingIssues = true this.processingIssues = true

View File

@ -101,8 +101,16 @@ export default {
this.$toast.info('No updates were made for Author') this.$toast.info('No updates were made for Author')
} }
this.searching = false this.searching = false
},
setSearching(isSearching) {
this.searching = isSearching
} }
}, },
mounted() {} mounted() {
this.$eventBus.$on(`searching-author-${this.authorId}`, this.setSearching)
},
beforeDestroy() {
this.$eventBus.$off(`searching-author-${this.authorId}`, this.setSearching)
}
} }
</script> </script>

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="page" :class="streamLibraryItem ? 'streaming' : ''"> <div class="page" :class="streamLibraryItem ? 'streaming' : ''">
<app-book-shelf-toolbar is-home /> <app-book-shelf-toolbar page="authors" is-home :authors="authors" />
<div id="bookshelf" class="w-full h-full p-8 overflow-y-auto"> <div id="bookshelf" class="w-full h-full p-8 overflow-y-auto">
<div class="flex flex-wrap justify-center"> <div class="flex flex-wrap justify-center">
<template v-for="author in authors"> <template v-for="author in authors">