2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2021-09-06 21:13:01 +02:00
|
|
|
<div class="w-full h-full relative">
|
2022-05-08 21:52:58 +02:00
|
|
|
<div id="formWrapper" class="w-full overflow-y-auto">
|
2022-05-08 22:25:33 +02:00
|
|
|
<widgets-book-details-edit v-if="mediaType == 'book'" ref="itemDetailsEdit" :library-item="libraryItem" @submit="saveAndClose" />
|
|
|
|
<widgets-podcast-details-edit v-else ref="itemDetailsEdit" :library-item="libraryItem" @submit="saveAndClose" />
|
2022-05-08 21:52:58 +02:00
|
|
|
</div>
|
2021-09-05 02:58:39 +02:00
|
|
|
|
2022-06-26 18:15:19 +02:00
|
|
|
<div class="absolute bottom-0 left-0 w-full py-2 md:py-4 bg-bg" :class="isScrollable ? 'box-shadow-md-up' : 'border-t border-white border-opacity-5'">
|
2022-03-13 23:10:48 +01:00
|
|
|
<div class="flex items-center px-4">
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-tooltip :disabled="!!quickMatching" :text="$getString('MessageQuickMatchDescription', [libraryProvider])" direction="bottom" class="mr-2 md:mr-4">
|
|
|
|
<ui-btn v-if="userIsAdminOrUp" :loading="quickMatching" color="bg" type="button" class="h-full" small @click.stop.prevent="quickMatch">{{ $strings.ButtonQuickMatch }}</ui-btn>
|
2022-03-13 23:10:48 +01:00
|
|
|
</ui-tooltip>
|
2021-08-18 00:01:11 +02:00
|
|
|
|
2023-10-21 20:53:00 +02:00
|
|
|
<ui-tooltip :disabled="isLibraryScanning" text="Rescan library item including metadata" direction="bottom" class="mr-2 md:mr-4">
|
|
|
|
<ui-btn v-if="userIsAdminOrUp && !isFile" :loading="rescanning" :disabled="isLibraryScanning" color="bg" type="button" class="h-full" small @click.stop.prevent="rescan">{{ $strings.ButtonReScan }}</ui-btn>
|
2022-03-13 23:10:48 +01:00
|
|
|
</ui-tooltip>
|
2022-01-10 01:37:16 +01:00
|
|
|
|
2023-04-14 23:44:41 +02:00
|
|
|
<div class="flex-grow" />
|
|
|
|
|
2022-11-08 01:27:17 +01:00
|
|
|
<!-- desktop -->
|
|
|
|
<ui-btn @click="save" class="mx-2 hidden md:block">{{ $strings.ButtonSave }}</ui-btn>
|
|
|
|
<ui-btn @click="saveAndClose" class="mx-2 hidden md:block">{{ $strings.ButtonSaveAndClose }}</ui-btn>
|
|
|
|
<!-- mobile -->
|
|
|
|
<ui-btn @click="saveAndClose" class="mx-2 md:hidden">{{ $strings.ButtonSave }}</ui-btn>
|
2021-09-06 23:11:37 +02:00
|
|
|
</div>
|
2022-03-12 02:46:32 +01:00
|
|
|
</div>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
processing: Boolean,
|
2022-03-11 01:45:02 +01:00
|
|
|
libraryItem: {
|
2021-08-18 00:01:11 +02:00
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-09-06 21:13:01 +02:00
|
|
|
resettingProgress: false,
|
2021-09-29 17:16:38 +02:00
|
|
|
isScrollable: false,
|
2022-02-15 23:15:09 +01:00
|
|
|
rescanning: false,
|
|
|
|
quickMatching: false
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isProcessing: {
|
|
|
|
get() {
|
|
|
|
return this.processing
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('update:processing', val)
|
|
|
|
}
|
|
|
|
},
|
2022-04-28 02:42:34 +02:00
|
|
|
isFile() {
|
|
|
|
return !!this.libraryItem && this.libraryItem.isFile
|
|
|
|
},
|
2022-05-04 02:16:16 +02:00
|
|
|
userIsAdminOrUp() {
|
|
|
|
return this.$store.getters['user/getIsAdminOrUp']
|
2021-09-29 17:16:38 +02:00
|
|
|
},
|
2021-10-27 00:55:48 +02:00
|
|
|
isMissing() {
|
2022-03-11 01:45:02 +01:00
|
|
|
return !!this.libraryItem && !!this.libraryItem.isMissing
|
2021-10-27 00:55:48 +02:00
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
libraryItemId() {
|
|
|
|
return this.libraryItem ? this.libraryItem.id : null
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
media() {
|
|
|
|
return this.libraryItem ? this.libraryItem.media || {} : {}
|
|
|
|
},
|
2022-03-26 21:23:25 +01:00
|
|
|
mediaType() {
|
|
|
|
return this.libraryItem ? this.libraryItem.mediaType : null
|
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
mediaMetadata() {
|
|
|
|
return this.media.metadata || {}
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2021-10-06 04:10:49 +02:00
|
|
|
libraryId() {
|
2022-03-11 01:45:02 +01:00
|
|
|
return this.libraryItem ? this.libraryItem.libraryId : null
|
2021-10-06 04:10:49 +02:00
|
|
|
},
|
2022-02-15 23:15:09 +01:00
|
|
|
libraryProvider() {
|
|
|
|
return this.$store.getters['libraries/getLibraryProvider'](this.libraryId) || 'google'
|
|
|
|
},
|
2023-10-21 20:53:00 +02:00
|
|
|
isLibraryScanning() {
|
2021-10-06 04:10:49 +02:00
|
|
|
if (!this.libraryId) return null
|
2023-10-21 20:53:00 +02:00
|
|
|
return !!this.$store.getters['tasks/getRunningLibraryScanTask'](this.libraryId)
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-02-15 23:15:09 +01:00
|
|
|
quickMatch() {
|
2022-03-14 01:34:31 +01:00
|
|
|
if (this.quickMatching) return
|
|
|
|
if (!this.$refs.itemDetailsEdit) return
|
|
|
|
|
|
|
|
var { title, author } = this.$refs.itemDetailsEdit.getTitleAndAuthorName()
|
|
|
|
if (!title) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastTitleRequired)
|
2022-03-14 01:34:31 +01:00
|
|
|
return
|
|
|
|
}
|
2022-02-15 23:15:09 +01:00
|
|
|
this.quickMatching = true
|
|
|
|
var matchOptions = {
|
|
|
|
provider: this.libraryProvider,
|
2022-03-14 01:34:31 +01:00
|
|
|
title: title || null,
|
|
|
|
author: author || null
|
2022-02-15 23:15:09 +01:00
|
|
|
}
|
|
|
|
this.$axios
|
2022-03-14 01:34:31 +01:00
|
|
|
.$post(`/api/items/${this.libraryItemId}/match`, matchOptions)
|
2022-02-15 23:15:09 +01:00
|
|
|
.then((res) => {
|
|
|
|
this.quickMatching = false
|
|
|
|
if (res.warning) {
|
|
|
|
this.$toast.warning(res.warning)
|
|
|
|
} else if (res.updated) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.ToastNoUpdatesNecessary)
|
2022-02-15 23:15:09 +01:00
|
|
|
} else {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.info(this.$strings.ToastItemDetailsUpdateUnneeded)
|
2022-02-15 23:15:09 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
var errMsg = error.response ? error.response.data || '' : ''
|
|
|
|
console.error('Failed to match', error)
|
|
|
|
this.$toast.error(errMsg || 'Failed to match')
|
|
|
|
this.quickMatching = false
|
|
|
|
})
|
|
|
|
},
|
2021-10-01 01:52:32 +02:00
|
|
|
rescan() {
|
|
|
|
this.rescanning = true
|
2022-03-18 17:51:55 +01:00
|
|
|
this.$axios
|
2023-02-04 00:50:42 +01:00
|
|
|
.$post(`/api/items/${this.libraryItemId}/scan`)
|
2022-03-18 17:51:55 +01:00
|
|
|
.then((data) => {
|
|
|
|
this.rescanning = false
|
|
|
|
var result = data.result
|
|
|
|
if (!result) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$getString('ToastRescanFailed', [this.title]))
|
2022-03-18 17:51:55 +01:00
|
|
|
} else if (result === 'UPDATED') {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.ToastRescanUpdated)
|
2022-03-18 17:51:55 +01:00
|
|
|
} else if (result === 'UPTODATE') {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.ToastRescanUpToDate)
|
2022-03-18 17:51:55 +01:00
|
|
|
} else if (result === 'REMOVED') {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastRescanRemoved)
|
2022-03-18 17:51:55 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to scan library item', error)
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastScanFailed)
|
2022-03-18 17:51:55 +01:00
|
|
|
this.rescanning = false
|
|
|
|
})
|
2021-10-01 01:52:32 +02:00
|
|
|
},
|
2022-05-08 22:25:33 +02:00
|
|
|
async saveAndClose() {
|
|
|
|
const wasUpdated = await this.save()
|
|
|
|
if (wasUpdated !== null) this.$emit('close')
|
|
|
|
},
|
|
|
|
async save() {
|
2021-08-25 13:38:32 +02:00
|
|
|
if (this.isProcessing) {
|
2022-05-08 22:25:33 +02:00
|
|
|
return null
|
2021-08-25 13:38:32 +02:00
|
|
|
}
|
2022-03-13 23:10:48 +01:00
|
|
|
if (!this.$refs.itemDetailsEdit) {
|
2022-05-08 22:25:33 +02:00
|
|
|
return null
|
2021-12-02 02:07:03 +01:00
|
|
|
}
|
2022-03-13 23:10:48 +01:00
|
|
|
var updatedDetails = this.$refs.itemDetailsEdit.getDetails()
|
|
|
|
if (!updatedDetails.hasChanges) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.info(this.$strings.MessageNoUpdatesWereNecessary)
|
2022-05-08 22:25:33 +02:00
|
|
|
return false
|
2021-12-02 02:07:03 +01:00
|
|
|
}
|
2022-05-08 22:25:33 +02:00
|
|
|
return this.updateDetails(updatedDetails)
|
2021-12-02 02:07:03 +01:00
|
|
|
},
|
2022-03-13 23:10:48 +01:00
|
|
|
async updateDetails(updatedDetails) {
|
|
|
|
this.isProcessing = true
|
2022-03-14 14:12:28 +01:00
|
|
|
var updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, updatedDetails.updatePayload).catch((error) => {
|
2021-08-18 00:01:11 +02:00
|
|
|
console.error('Failed to update', error)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
this.isProcessing = false
|
2022-03-14 14:12:28 +01:00
|
|
|
if (updateResult) {
|
|
|
|
if (updateResult.updated) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.MessageItemDetailsUpdated)
|
2022-05-08 22:25:33 +02:00
|
|
|
return true
|
2022-03-14 14:12:28 +01:00
|
|
|
} else {
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.info(this.$strings.MessageNoUpdatesWereNecessary)
|
2022-03-14 14:12:28 +01:00
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
2022-05-08 22:25:33 +02:00
|
|
|
return false
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2021-09-06 21:13:01 +02:00
|
|
|
checkIsScrollable() {
|
|
|
|
this.$nextTick(() => {
|
2022-03-13 23:10:48 +01:00
|
|
|
var formWrapper = document.getElementById('formWrapper')
|
|
|
|
if (formWrapper) {
|
|
|
|
if (formWrapper.scrollHeight > formWrapper.clientHeight) {
|
2021-09-06 21:13:01 +02:00
|
|
|
this.isScrollable = true
|
|
|
|
} else {
|
|
|
|
this.isScrollable = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
setResizeObserver() {
|
|
|
|
try {
|
2022-03-13 23:10:48 +01:00
|
|
|
var formWrapper = document.getElementById('formWrapper')
|
|
|
|
if (formWrapper) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
|
|
this.checkIsScrollable()
|
|
|
|
})
|
|
|
|
resizeObserver.observe(formWrapper)
|
2021-09-06 21:13:01 +02:00
|
|
|
})
|
2022-03-13 23:10:48 +01:00
|
|
|
}
|
2021-09-06 21:13:01 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to set resize observer')
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
2021-09-06 21:13:01 +02:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.setResizeObserver()
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-06 21:13:01 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2022-05-08 21:52:58 +02:00
|
|
|
#formWrapper {
|
|
|
|
height: calc(100% - 80px);
|
|
|
|
max-height: calc(100% - 80px);
|
2021-09-06 21:13:01 +02:00
|
|
|
}
|
2024-08-31 00:47:49 +02:00
|
|
|
</style>
|