2022-03-15 00:53:49 +01:00
|
|
|
<template>
|
|
|
|
<modals-modal v-model="show" name="edit-author" :width="800" :height="'unset'" :processing="processing">
|
|
|
|
<template #outer>
|
|
|
|
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden">
|
2023-02-11 22:02:56 +01:00
|
|
|
<p class="text-3xl text-white truncate">{{ title }}</p>
|
2022-03-15 00:53:49 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
2023-10-14 00:37:37 +02:00
|
|
|
<div v-if="author" class="p-4 w-full text-sm py-6 rounded-lg bg-bg shadow-lg border border-black-300 relative overflow-hidden" style="min-height: 400px; max-height: 80vh">
|
|
|
|
<div class="flex">
|
|
|
|
<div class="w-40 p-2">
|
|
|
|
<div class="w-full h-45 relative">
|
2024-05-27 23:04:36 +02:00
|
|
|
<covers-author-image :author="authorCopy" />
|
2023-10-14 00:37:37 +02:00
|
|
|
<div v-if="userCanDelete && !processing && author.imagePath" class="absolute top-0 left-0 w-full h-full opacity-0 hover:opacity-100">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="absolute top-2 right-2 material-symbols text-error transform hover:scale-125 transition-transform cursor-pointer text-lg" @click="removeCover">delete</span>
|
2022-03-15 00:53:49 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-10-14 00:37:37 +02:00
|
|
|
</div>
|
|
|
|
<div class="flex-grow">
|
|
|
|
<form @submit.prevent="submitUploadCover" class="flex flex-grow mb-2 p-2">
|
|
|
|
<ui-text-input v-model="imageUrl" :placeholder="$strings.LabelImageURLFromTheWeb" class="h-9 w-full" />
|
|
|
|
<ui-btn color="success" type="submit" :padding-x="4" :disabled="!imageUrl" class="ml-2 sm:ml-3 w-24 h-9">{{ $strings.ButtonSubmit }}</ui-btn>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<form v-if="author" @submit.prevent="submitForm">
|
2022-03-15 00:53:49 +01:00
|
|
|
<div class="flex">
|
|
|
|
<div class="w-3/4 p-2">
|
2022-11-09 00:10:08 +01:00
|
|
|
<ui-text-input-with-label v-model="authorCopy.name" :disabled="processing" :label="$strings.LabelName" />
|
2022-03-15 00:53:49 +01:00
|
|
|
</div>
|
|
|
|
<div class="flex-grow p-2">
|
|
|
|
<ui-text-input-with-label v-model="authorCopy.asin" :disabled="processing" label="ASIN" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="p-2">
|
2022-11-09 00:10:08 +01:00
|
|
|
<ui-textarea-with-label v-model="authorCopy.description" :disabled="processing" :label="$strings.LabelDescription" :rows="8" />
|
2022-03-15 00:53:49 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex pt-2 px-2">
|
2023-09-25 00:06:32 +02:00
|
|
|
<ui-btn v-if="userCanDelete" small color="error" type="button" @click.stop="removeClick">{{ $strings.ButtonRemove }}</ui-btn>
|
2022-03-15 00:53:49 +01:00
|
|
|
<div class="flex-grow" />
|
2023-09-25 00:06:32 +02:00
|
|
|
<ui-btn type="button" class="mx-2" @click="searchAuthor">{{ $strings.ButtonQuickMatch }}</ui-btn>
|
|
|
|
|
2022-12-17 00:54:00 +01:00
|
|
|
<ui-btn type="submit">{{ $strings.ButtonSave }}</ui-btn>
|
2022-03-15 00:53:49 +01:00
|
|
|
</div>
|
2023-10-14 00:37:37 +02:00
|
|
|
</form>
|
2022-03-15 00:53:49 +01:00
|
|
|
</div>
|
2023-10-14 00:37:37 +02:00
|
|
|
</div>
|
2022-03-15 00:53:49 +01:00
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
authorCopy: {
|
|
|
|
name: '',
|
|
|
|
asin: '',
|
2023-10-14 00:37:37 +02:00
|
|
|
description: ''
|
2022-03-15 00:53:49 +01:00
|
|
|
},
|
2023-10-14 00:37:37 +02:00
|
|
|
imageUrl: '',
|
2022-03-15 00:53:49 +01:00
|
|
|
processing: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
author: {
|
|
|
|
immediate: true,
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
2022-05-09 01:21:46 +02:00
|
|
|
return this.$store.state.globals.showEditAuthorModal
|
2022-03-15 00:53:49 +01:00
|
|
|
},
|
|
|
|
set(val) {
|
2022-05-09 01:21:46 +02:00
|
|
|
this.$store.commit('globals/setShowEditAuthorModal', val)
|
2022-03-15 00:53:49 +01:00
|
|
|
}
|
|
|
|
},
|
2022-05-09 01:21:46 +02:00
|
|
|
author() {
|
|
|
|
return this.$store.state.globals.selectedAuthor
|
|
|
|
},
|
2022-03-15 00:53:49 +01:00
|
|
|
authorId() {
|
|
|
|
if (!this.author) return ''
|
|
|
|
return this.author.id
|
|
|
|
},
|
|
|
|
title() {
|
2022-11-09 00:10:08 +01:00
|
|
|
return this.$strings.HeaderUpdateAuthor
|
2023-04-16 22:53:46 +02:00
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
|
|
|
},
|
|
|
|
libraryProvider() {
|
|
|
|
return this.$store.getters['libraries/getLibraryProvider'](this.currentLibraryId) || 'google'
|
2023-09-25 00:06:32 +02:00
|
|
|
},
|
|
|
|
userCanDelete() {
|
|
|
|
return this.$store.getters['user/getUserCanDelete']
|
2022-03-15 00:53:49 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
init() {
|
2023-10-14 00:37:37 +02:00
|
|
|
this.imageUrl = ''
|
2024-05-27 23:04:36 +02:00
|
|
|
this.authorCopy = {
|
|
|
|
...this.author
|
|
|
|
}
|
2022-03-15 00:53:49 +01:00
|
|
|
},
|
2023-09-25 00:06:32 +02:00
|
|
|
removeClick() {
|
|
|
|
const payload = {
|
|
|
|
message: this.$getString('MessageConfirmRemoveAuthor', [this.author.name]),
|
|
|
|
callback: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.processing = true
|
|
|
|
this.$axios
|
|
|
|
.$delete(`/api/authors/${this.authorId}`)
|
|
|
|
.then(() => {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.ToastAuthorRemoveSuccess)
|
2023-09-25 00:06:32 +02:00
|
|
|
this.show = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to remove author', error)
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastRemoveFailed)
|
2023-09-25 00:06:32 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.processing = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'yesNo'
|
|
|
|
}
|
|
|
|
this.$store.commit('globals/setConfirmPrompt', payload)
|
|
|
|
},
|
2022-03-15 00:53:49 +01:00
|
|
|
async submitForm() {
|
2023-10-14 00:37:37 +02:00
|
|
|
var keysToCheck = ['name', 'asin', 'description']
|
2022-03-15 00:53:49 +01:00
|
|
|
var updatePayload = {}
|
|
|
|
keysToCheck.forEach((key) => {
|
|
|
|
if (this.authorCopy[key] !== this.author[key]) {
|
|
|
|
updatePayload[key] = this.authorCopy[key]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (!Object.keys(updatePayload).length) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.info(this.$strings.ToastNoUpdatesNecessary)
|
2022-03-15 00:53:49 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
this.processing = true
|
|
|
|
var result = await this.$axios.$patch(`/api/authors/${this.authorId}`, updatePayload).catch((error) => {
|
|
|
|
console.error('Failed', error)
|
2022-12-26 22:45:42 +01:00
|
|
|
const errorMsg = error.response ? error.response.data : null
|
|
|
|
this.$toast.error(errorMsg || this.$strings.ToastAuthorUpdateFailed)
|
2022-03-15 00:53:49 +01:00
|
|
|
return null
|
|
|
|
})
|
|
|
|
if (result) {
|
2022-05-04 02:33:00 +02:00
|
|
|
if (result.updated) {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.success(this.$strings.ToastAuthorUpdateSuccess)
|
2022-05-04 02:33:00 +02:00
|
|
|
this.show = false
|
2022-07-24 19:00:36 +02:00
|
|
|
} else if (result.merged) {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.success(this.$strings.ToastAuthorUpdateMerged)
|
2022-07-24 19:00:36 +02:00
|
|
|
this.show = false
|
2024-08-31 00:47:49 +02:00
|
|
|
} else this.$toast.info(this.$strings.ToastNoUpdatesNecessary)
|
2022-03-15 00:53:49 +01:00
|
|
|
}
|
|
|
|
this.processing = false
|
|
|
|
},
|
2023-10-14 00:37:37 +02:00
|
|
|
removeCover() {
|
|
|
|
this.processing = true
|
|
|
|
this.$axios
|
|
|
|
.$delete(`/api/authors/${this.authorId}/image`)
|
|
|
|
.then((data) => {
|
|
|
|
this.$toast.success(this.$strings.ToastAuthorImageRemoveSuccess)
|
2024-05-27 23:04:36 +02:00
|
|
|
|
|
|
|
this.authorCopy.updatedAt = data.author.updatedAt
|
|
|
|
this.authorCopy.imagePath = data.author.imagePath
|
2023-10-14 00:37:37 +02:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastRemoveFailed)
|
2023-10-14 00:37:37 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.processing = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
submitUploadCover() {
|
|
|
|
if (!this.imageUrl?.startsWith('http:') && !this.imageUrl?.startsWith('https:')) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastInvalidImageUrl)
|
2023-10-14 00:37:37 +02:00
|
|
|
return
|
2022-03-15 00:53:49 +01:00
|
|
|
}
|
2023-10-14 00:37:37 +02:00
|
|
|
|
2022-03-15 00:53:49 +01:00
|
|
|
this.processing = true
|
2023-10-14 00:37:37 +02:00
|
|
|
const updatePayload = {
|
|
|
|
url: this.imageUrl
|
2022-03-15 00:53:49 +01:00
|
|
|
}
|
2023-10-14 00:37:37 +02:00
|
|
|
this.$axios
|
|
|
|
.$post(`/api/authors/${this.authorId}/image`, updatePayload)
|
|
|
|
.then((data) => {
|
|
|
|
this.imageUrl = ''
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.ToastAuthorUpdateSuccess)
|
2024-05-27 23:04:36 +02:00
|
|
|
|
|
|
|
this.authorCopy.updatedAt = data.author.updatedAt
|
|
|
|
this.authorCopy.imagePath = data.author.imagePath
|
2023-10-14 00:37:37 +02:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(error.response.data || this.$strings.ToastRemoveFailed)
|
2023-10-14 00:37:37 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.processing = false
|
|
|
|
})
|
2022-03-15 00:53:49 +01:00
|
|
|
},
|
|
|
|
async searchAuthor() {
|
2022-05-14 01:11:54 +02:00
|
|
|
if (!this.authorCopy.name && !this.authorCopy.asin) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastNameRequired)
|
2022-03-15 00:53:49 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
this.processing = true
|
2022-05-14 01:11:54 +02:00
|
|
|
|
|
|
|
const payload = {}
|
|
|
|
if (this.authorCopy.asin) payload.asin = this.authorCopy.asin
|
|
|
|
else payload.q = this.authorCopy.name
|
|
|
|
|
2023-04-16 22:53:46 +02:00
|
|
|
payload.region = 'us'
|
|
|
|
if (this.libraryProvider.startsWith('audible.')) {
|
|
|
|
payload.region = this.libraryProvider.split('.').pop() || 'us'
|
|
|
|
}
|
|
|
|
|
2022-05-14 01:11:54 +02:00
|
|
|
var response = await this.$axios.$post(`/api/authors/${this.authorId}/match`, payload).catch((error) => {
|
2022-03-15 00:53:49 +01:00
|
|
|
console.error('Failed', error)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
if (!response) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastAuthorSearchNotFound)
|
2022-03-15 00:53:49 +01:00
|
|
|
} else if (response.updated) {
|
2022-11-21 01:48:19 +01:00
|
|
|
if (response.author.imagePath) {
|
|
|
|
this.$toast.success(this.$strings.ToastAuthorUpdateSuccess)
|
2024-08-31 00:47:49 +02:00
|
|
|
} else {
|
|
|
|
this.$toast.success(this.$strings.ToastAuthorUpdateSuccessNoImageFound)
|
|
|
|
}
|
2024-05-27 23:04:36 +02:00
|
|
|
|
|
|
|
this.authorCopy = {
|
|
|
|
...response.author
|
|
|
|
}
|
2022-03-15 00:53:49 +01:00
|
|
|
} else {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.info(this.$strings.ToastNoUpdatesNecessary)
|
2022-03-15 00:53:49 +01:00
|
|
|
}
|
|
|
|
this.processing = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {},
|
|
|
|
beforeDestroy() {}
|
|
|
|
}
|
2024-05-07 00:17:35 +02:00
|
|
|
</script>
|