save plugin settings and toggle enable/disable

This commit is contained in:
lesion
2022-08-29 22:47:09 +02:00
parent 438780a741
commit 982db2b51d
5 changed files with 150 additions and 36 deletions

View File

@@ -1,44 +1,48 @@
<template lang='pug'>
v-container
v-card-title {{$t('common.plugins')}}
v-card-title {{ $t('common.plugins') }}
v-spacer
v-card-subtitle(v-html="$t('admin.plugins_description')")
v-dialog(v-model='dialog' width='600' :fullscreen='$vuetify.breakpoint.xsOnly')
v-card(color='secondary')
v-card-title {{$t('admin.config_plugin')}}
v-card-title {{ $t('admin.config_plugin') }} - {{ selectedPlugin.name }}
v-card-text
v-form(v-model='valid' ref='form' lazy-validation)
div(v-for='(setting, name) in selectedPlugin.settings')
v-text-field(v-model='pluginSettings[name]' type='text' :label='setting.description')
v-card-actions
v-spacer
v-btn(@click='dialog=false' color='warning') {{$t('common.cancel')}}
v-btn(@click='saveSettings' color='primary' :loading='loading'
:disable='!valid || loading') {{$t('common.save')}}
v-spacer
v-btn(@click='dialog = false' outlined color='warning') {{ $t('common.cancel') }}
v-btn(@click='saveSettings' outlined color='primary' :loading='loading'
:disable='!valid || loading') {{ $t('common.save') }}
v-card-text
v-card(v-for='plugin in plugins' :key='plugin.name' max-width="400" elevation='10')
v-card-title {{plugin.name}}
v-card-text
p {{plugin.description}}
blockquote author: {{plugin.author}}
a(:href='plugin.url' v-text='plugin.url')
v-row
v-switch
v-spacer
v-btn(text color='primary') {{$t('common.settings')}}
v-card(v-for='plugin in plugins' :key='plugin.name' max-width="400" elevation='10' color='secondary')
v-card-title.d-block {{ plugin.name }}
v-switch.float-right(:label="$t('common.enable')" @change='toggleEnable(plugin)')
v-card-text
p {{ plugin.description }}
blockquote author: {{ plugin.author }}
a(:href='plugin.url' v-text='plugin.url')
v-row
v-spacer
v-btn(text color='primary' @click='setOptions(plugin)') {{ $t('common.settings') }}
</template>
<script>
import { mdiPencil, mdiChevronLeft, mdiChevronRight, mdiMagnify, mdiEye } from '@mdi/js'
export default {
data () {
data() {
return {
mdiPencil, mdiChevronRight, mdiChevronLeft, mdiMagnify, mdiEye,
loading: false,
dialog: false,
valid: false,
selectedPlugin: {},
pluginSettings: {},
plugins: [],
headers: [
{ value: 'name', text: 'Name' },
@@ -47,23 +51,23 @@ export default {
]
}
},
async fetch () {
async fetch() {
this.plugins = await this.$axios.$get('/plugins')
},
methods: {
editPlugin (item) {
this.place.name = item.name
this.place.address = item.address
this.place.id = item.id
this.dialog = true
saveSettings() {
console.error(this.pluginSettings)
this.setSetting({ key: 'plugin_' + this.selectedPlugin.name, value: this.pluginSettings })
},
async saveSettings () {
if (!this.$refs.form.validate()) return
this.loading = true
await this.$axios.$put('/place', this.place)
await this.$fetch()
this.loading = false
this.dialog = false
toggleEnable(plugin) {
this.pluginSettings.enable = !this.pluginSettings.enable
this.setSetting({ key: 'plugin_' + this.selectedPlugin.name, value: this.pluginSettings })
},
setOptions(plugin) {
console.error(plugin)
this.selectedPlugin = plugin
console.error(plugin)
this.dialog = true
}
}
}

View File

@@ -69,6 +69,7 @@
"sequelize-slugify": "^1.6.1",
"sharp": "^0.27.2",
"sqlite3": "^5.0.11",
"telegraf": "^4.9.0",
"tiptap": "^1.32.0",
"tiptap-extensions": "^1.35.0",
"umzug": "^2.3.0",

View File

@@ -5,10 +5,42 @@ const config = require('../../config')
const pluginController = {
plugins: [],
getAll (req, res, next) {
getAll(req, res, next) {
res.json(pluginController.plugins)
},
_load () {
togglePlugin(req, res, next) {
const plugin = req.params.plugin
if (this.plugins[plugin].enable) {
}
},
unloadPlugin(plugin) {
log.info('Unload plugin ' + plugin)
},
loadPlugin(pluginName) {
const plugin = this.plugins[pluginName]
if (!plugin) {
log.warn(`Plugin ${pluginName} not found`)
return
}
if (typeof plugin.onEventCreate === 'function') {
notifier.emitter.on('Create', plugin.onEventCreate)
}
if (typeof plugin.onEventDelete === 'function') {
notifier.emitter.on('Delete', plugin.onEventDelete)
}
if (typeof plugin.onEventUpdate === 'function') {
notifier.emitter.on('Update', plugin.onEventUpdate)
}
plugin.load({ settings: settingsController.settings }, settingsController.settings.plugins)
},
_load() {
const settingsController = require('./settings')
// load custom plugins
const plugins_path = config.plugins_path || path.resolve(process.env.cwd || '', 'gancio_plugins')
@@ -18,7 +50,7 @@ const pluginController = {
const plugins = fs.readdirSync(plugins_path)
.map(e => path.resolve(plugins_path, e, 'index.js'))
.filter(index => fs.existsSync(index))
plugins.forEach( pluginFile => {
plugins.forEach(pluginFile => {
try {
const plugin = require(pluginFile)
if (typeof plugin.load !== 'function') return

View File

@@ -2298,6 +2298,13 @@ abbrev@1, abbrev@^1.0.0:
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==
abort-controller@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
dependencies:
event-target-shim "^5.0.0"
accept-language@^3.0.18:
version "3.0.18"
resolved "https://registry.yarnpkg.com/accept-language/-/accept-language-3.0.18.tgz#f5025f17bf65a466a845838ccf98cdb877d83384"
@@ -3096,11 +3103,29 @@ bser@2.1.1:
dependencies:
node-int64 "^0.4.0"
buffer-alloc-unsafe@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0"
integrity sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==
buffer-alloc@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/buffer-alloc/-/buffer-alloc-1.2.0.tgz#890dd90d923a873e08e10e5fd51a57e5b7cce0ec"
integrity sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==
dependencies:
buffer-alloc-unsafe "^1.1.0"
buffer-fill "^1.0.0"
buffer-equal-constant-time@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819"
integrity sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==
buffer-fill@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c"
integrity sha512-T7zexNBwiiaCOGDg9xNX9PBmjrubblRkENuptryuI64URkXDFum9il/JGL8Lm8wYfAXpredVXXZz7eMHilimiQ==
buffer-from@^1.0.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
@@ -4821,6 +4846,11 @@ es-array-method-boxes-properly@^1.0.0:
resolved "https://registry.yarnpkg.com/es-array-method-boxes-properly/-/es-array-method-boxes-properly-1.0.0.tgz#873f3e84418de4ee19c5be752990b2e44718d09e"
integrity sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==
es-main@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/es-main/-/es-main-1.2.0.tgz#b85954f1d9d9f542fcb08685ec19515f969bad16"
integrity sha512-A4tCSY43O/mH4rHjG1n0mI4DhK2BmKDr8Lk8PXK/GBB6zxGFGmIW4bbkbTQ2Gi9iNamMZ9vbGrwjZOIeiM7vMw==
es-to-primitive@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a"
@@ -4956,6 +4986,11 @@ event-emitter@^0.3.5:
d "1"
es5-ext "~0.10.14"
event-target-shim@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==
eventemitter3@^4.0.0:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
@@ -8074,6 +8109,11 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
module-alias@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.2.2.tgz#151cdcecc24e25739ff0aa6e51e1c5716974c0e0"
integrity sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==
moment-timezone@^0.5.34:
version "0.5.37"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.37.tgz#adf97f719c4e458fdb12e2b4e87b8bec9f4eef1e"
@@ -8757,6 +8797,11 @@ p-timeout@^3.0.0, p-timeout@^3.1.0:
dependencies:
p-finally "^1.0.0"
p-timeout@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-4.1.0.tgz#788253c0452ab0ffecf18a62dff94ff1bd09ca0a"
integrity sha512-+/wmHtzJuWii1sXn3HCuH/FTwGhrp4tmJTxSKJbfS+vkipci6osxXM5mY0jUiRzWKMTgUT8l7HFbeSwZAynqHw==
p-try@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
@@ -10646,6 +10691,13 @@ safe-buffer@5.2.1, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, s
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
safe-compare@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/safe-compare/-/safe-compare-1.1.4.tgz#5e0128538a82820e2e9250cd78e45da6786ba593"
integrity sha512-b9wZ986HHCo/HbKrRpBJb2kqXMK9CEWIE1egeEvZsYn69ay3kdfl9nG3RyOcR+jInTDf7a86WQ1d4VJX7goSSQ==
dependencies:
buffer-alloc "^1.2.0"
safe-identifier@^0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/safe-identifier/-/safe-identifier-0.4.2.tgz#cf6bfca31c2897c588092d1750d30ef501d59fcb"
@@ -10668,6 +10720,11 @@ safe-stable-stringify@^2.3.1:
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
sandwich-stream@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/sandwich-stream/-/sandwich-stream-2.0.2.tgz#6d1feb6cf7e9fe9fadb41513459a72c2e84000fa"
integrity sha512-jLYV0DORrzY3xaz/S9ydJL6Iz7essZeAfnAavsJ+zsJGZ1MOnsS52yRjU3uF3pJa/lla7+wisp//fxOwOH8SKQ==
sass-loader@^10.2.0:
version "10.3.1"
resolved "https://registry.yarnpkg.com/sass-loader/-/sass-loader-10.3.1.tgz#a45f0d1dd7ea90de7eb099239a18c83dea6e6341"
@@ -11615,6 +11672,22 @@ tar@^6.0.2, tar@^6.1.11, tar@^6.1.2:
mkdirp "^1.0.3"
yallist "^4.0.0"
telegraf@^4.9.0:
version "4.9.0"
resolved "https://registry.yarnpkg.com/telegraf/-/telegraf-4.9.0.tgz#30997bf6cbc941bff0bb698b13154647fc918032"
integrity sha512-fL+KLaYRElo4aNtrqAHmFdVsAMHHOHbmdTsAAzMJafhXJu1oYKTRMNipJ/YUvwNd5DnZY+zmGMgVVe1M/dkN4w==
dependencies:
abort-controller "^3.0.0"
debug "^4.3.3"
es-main "^1.2.0"
minimist "^1.2.6"
module-alias "^2.2.2"
node-fetch "^2.6.7"
p-timeout "^4.1.0"
safe-compare "^1.1.4"
sandwich-stream "^2.0.2"
typegram "github:MKRhere/typegram#e2ba9f01f14b96c6dbb1c617e66692a3cc776cf6"
terminal-link@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/terminal-link/-/terminal-link-2.1.1.tgz#14a64a27ab3c0df933ea546fba55f2d078edc994"
@@ -11996,6 +12069,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==
"typegram@github:MKRhere/typegram#e2ba9f01f14b96c6dbb1c617e66692a3cc776cf6":
version "3.10.0"
resolved "https://codeload.github.com/MKRhere/typegram/tar.gz/e2ba9f01f14b96c6dbb1c617e66692a3cc776cf6"
ua-parser-js@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.2.tgz#e2976c34dbfb30b15d2c300b2a53eac87c57a775"