mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-02-02 16:29:39 +00:00
Update PluginManager to singleton, update PluginContext, support prompt object in plugin extension
This commit is contained in:
parent
a762e6ca03
commit
50e84fc2d5
14 changed files with 121 additions and 45 deletions
|
|
@ -7,6 +7,14 @@
|
|||
|
||||
<ui-checkbox v-if="checkboxLabel" v-model="checkboxValue" checkbox-bg="bg" :label="checkboxLabel" label-class="pl-2 text-base" class="mb-6 px-1" />
|
||||
|
||||
<div v-if="formFields.length" class="mb-6 space-y-2">
|
||||
<template v-for="field in formFields">
|
||||
<ui-select-input v-if="field.type === 'select'" :key="field.name" v-model="formData[field.name]" :label="field.label" :items="field.options" class="px-1" />
|
||||
<ui-textarea-with-label v-else-if="field.type === 'textarea'" :key="field.name" v-model="formData[field.name]" :label="field.label" class="px-1" />
|
||||
<ui-text-input-with-label v-else-if="field.type === 'text'" :key="field.name" v-model="formData[field.name]" :label="field.label" class="px-1" />
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="flex px-1 items-center">
|
||||
<ui-btn v-if="isYesNo" color="primary" @click="nevermind">{{ $strings.ButtonCancel }}</ui-btn>
|
||||
<div class="flex-grow" />
|
||||
|
|
@ -25,7 +33,8 @@ export default {
|
|||
return {
|
||||
el: null,
|
||||
content: null,
|
||||
checkboxValue: false
|
||||
checkboxValue: false,
|
||||
formData: {}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
|
@ -61,6 +70,9 @@ export default {
|
|||
persistent() {
|
||||
return !!this.confirmPromptOptions.persistent
|
||||
},
|
||||
formFields() {
|
||||
return this.confirmPromptOptions.formFields || []
|
||||
},
|
||||
checkboxLabel() {
|
||||
return this.confirmPromptOptions.checkboxLabel
|
||||
},
|
||||
|
|
@ -100,11 +112,31 @@ export default {
|
|||
this.show = false
|
||||
},
|
||||
confirm() {
|
||||
if (this.callback) this.callback(true, this.checkboxValue)
|
||||
if (this.callback) {
|
||||
if (this.formFields.length) {
|
||||
const formFieldData = {
|
||||
...this.formData
|
||||
}
|
||||
|
||||
this.callback(true, formFieldData)
|
||||
} else {
|
||||
this.callback(true, this.checkboxValue)
|
||||
}
|
||||
}
|
||||
this.show = false
|
||||
},
|
||||
setShow() {
|
||||
this.checkboxValue = this.checkboxDefaultValue
|
||||
|
||||
if (this.formFields.length) {
|
||||
this.formFields.forEach((field) => {
|
||||
let defaultValue = ''
|
||||
if (field.type === 'boolean') defaultValue = false
|
||||
if (field.type === 'select') defaultValue = field.options[0].value
|
||||
this.$set(this.formData, field.name, defaultValue)
|
||||
})
|
||||
}
|
||||
|
||||
this.$eventBus.$emit('showing-prompt', true)
|
||||
document.body.appendChild(this.el)
|
||||
setTimeout(() => {
|
||||
|
|
|
|||
|
|
@ -12,10 +12,14 @@
|
|||
<span class="material-symbols text-xl w-5 text-gray-200">help_outline</span>
|
||||
</a>
|
||||
</ui-tooltip>
|
||||
|
||||
<div class="flex-grow" />
|
||||
|
||||
<a v-if="repositoryUrl" :href="repositoryUrl" target="_blank" class="abs-btn outline-none rounded-md shadow-md relative border border-gray-600 text-center bg-primary text-white px-4 py-1 text-sm inline-flex items-center space-x-2"><span>Source</span><span class="material-symbols text-base">open_in_new</span> </a>
|
||||
</template>
|
||||
|
||||
<div class="py-4">
|
||||
<p class="mb-4">{{ configDescription }}</p>
|
||||
<p v-if="configDescription" class="mb-4">{{ configDescription }}</p>
|
||||
|
||||
<form v-if="configFormFields.length" @submit.prevent="handleFormSubmit">
|
||||
<template v-for="field in configFormFields">
|
||||
|
|
@ -46,7 +50,7 @@ export default {
|
|||
console.error('Failed to get plugin config', error)
|
||||
return null
|
||||
})
|
||||
if (!pluginConfigData?.config) {
|
||||
if (!pluginConfigData) {
|
||||
redirect('/config/plugins')
|
||||
}
|
||||
const pluginManifest = store.state.plugins.find((plugin) => plugin.id === params.id)
|
||||
|
|
@ -84,6 +88,9 @@ export default {
|
|||
},
|
||||
configFormFields() {
|
||||
return this.pluginManifestConfig.formFields || []
|
||||
},
|
||||
repositoryUrl() {
|
||||
return this.pluginManifest.repositoryUrl
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -123,6 +130,7 @@ export default {
|
|||
})
|
||||
},
|
||||
initializeForm() {
|
||||
if (!this.pluginConfig) return
|
||||
this.configFormFields.forEach((field) => {
|
||||
if (this.pluginConfig[field.name] === undefined) {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -12,11 +12,13 @@
|
|||
<p v-if="!plugins.length" class="text-gray-300">No plugins installed</p>
|
||||
|
||||
<template v-for="plugin in plugins">
|
||||
<nuxt-link :key="plugin.id" :to="`/config/plugins/${plugin.id}`" class="flex items-center bg-primary rounded-md shadow-sm p-4 my-4 space-x-4">
|
||||
<p class="text-lg">{{ plugin.name }}</p>
|
||||
<p class="text-sm text-gray-300">{{ plugin.description }}</p>
|
||||
<div class="flex-grow" />
|
||||
<span class="material-symbols text-4xl">chevron_right</span>
|
||||
<nuxt-link :key="plugin.id" :to="`/config/plugins/${plugin.id}`" class="block w-full rounded bg-primary/40 hover:bg-primary/60 text-gray-300 hover:text-white p-4 my-2">
|
||||
<div class="flex items-center space-x-4">
|
||||
<p class="text-lg">{{ plugin.name }}</p>
|
||||
<p class="text-sm text-gray-300">{{ plugin.description }}</p>
|
||||
<div class="flex-grow" />
|
||||
<span class="material-symbols">arrow_forward</span>
|
||||
</div>
|
||||
</nuxt-link>
|
||||
</template>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -786,13 +786,35 @@ export default {
|
|||
}
|
||||
},
|
||||
onPluginAction(pluginId, pluginAction) {
|
||||
const plugin = this.pluginExtensions.find((p) => p.id === pluginId)
|
||||
const extension = plugin.extensions.find((ext) => ext.name === pluginAction)
|
||||
|
||||
if (extension.prompt) {
|
||||
const payload = {
|
||||
message: extension.prompt.message,
|
||||
formFields: extension.prompt.formFields || [],
|
||||
callback: (confirmed, promptData) => {
|
||||
if (confirmed) {
|
||||
this.sendPluginAction(pluginId, pluginAction, promptData)
|
||||
}
|
||||
},
|
||||
type: 'yesNo'
|
||||
}
|
||||
this.$store.commit('globals/setConfirmPrompt', payload)
|
||||
} else {
|
||||
this.sendPluginAction(pluginId, pluginAction)
|
||||
}
|
||||
},
|
||||
sendPluginAction(pluginId, pluginAction, promptData = null) {
|
||||
this.$axios
|
||||
.$post(`/api/plugins/${pluginId}/action`, {
|
||||
pluginAction,
|
||||
target: 'item.detail.actions',
|
||||
data: {
|
||||
entityId: this.libraryItemId,
|
||||
entityType: 'libraryItem'
|
||||
entityType: 'libraryItem',
|
||||
userId: this.$store.state.user.user.id,
|
||||
promptData
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue