From 3b347f262ce81732bacf3a51b2ecb98464a83130 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Sat, 21 Dec 2019 16:41:03 -0500 Subject: [PATCH] feat: save rendering configuration --- client/components/admin/admin-rendering.vue | 32 ++++++-- server/graph/resolvers/rendering.js | 4 +- server/graph/schemas/rendering.graphql | 1 - server/models/renderers.js | 8 ++ .../rendering/html-mathjax/definition.yml | 9 -- .../modules/rendering/html-mathjax/mathjax.js | 82 ------------------- .../rendering/markdown-mathjax/definition.yml | 8 -- .../rendering/markdown-mathjax/renderer.js | 11 --- 8 files changed, 34 insertions(+), 121 deletions(-) delete mode 100644 server/modules/rendering/html-mathjax/definition.yml delete mode 100644 server/modules/rendering/html-mathjax/mathjax.js delete mode 100644 server/modules/rendering/markdown-mathjax/definition.yml delete mode 100644 server/modules/rendering/markdown-mathjax/renderer.js diff --git a/client/components/admin/admin-rendering.vue b/client/components/admin/admin-rendering.vue index e3de4d94..131577df 100644 --- a/client/components/admin/admin-rendering.vue +++ b/client/components/admin/admin-rendering.vue @@ -20,7 +20,6 @@ flat dark ) - v-icon.mr-2 mdi-creation .subtitle-1 Pipeline v-expansion-panels.adm-rendering-pipeline( v-model='selectedCore' @@ -132,6 +131,7 @@ import { get } from 'vuex-pathify' import { StatusIndicator } from 'vue-status-indicator' import renderersQuery from 'gql/admin/rendering/rendering-query-renderers.gql' +import renderersSaveMutation from 'gql/admin/rendering/rendering-mutation-save-renderers.gql' export default { components: { @@ -164,18 +164,34 @@ export default { }) }, async refresh () { + await this.$apollo.queries.renderers.refetch() this.$store.commit('showNotification', { - style: 'indigo', - message: `Coming soon...`, - icon: 'directions_boat' + message: 'Rendering active configuration has been reloaded.', + style: 'success', + icon: 'cached' }) }, async save () { - this.$store.commit('showNotification', { - style: 'indigo', - message: `Coming soon...`, - icon: 'directions_boat' + this.$store.commit(`loadingStart`, 'admin-rendering-saverenderers') + await this.$apollo.mutate({ + mutation: renderersSaveMutation, + variables: { + renderers: _.reduce(this.renderers, (result, core) => { + result = _.concat(result, core.children.map(rd => ({ + key: rd.key, + isEnabled: rd.isEnabled, + config: rd.config.map(cfg => ({ key: cfg.key, value: JSON.stringify({ v: cfg.value.value }) })) + }))) + return result + }, []) + } }) + this.$store.commit('showNotification', { + message: 'Rendering configuration saved successfully.', + style: 'success', + icon: 'check' + }) + this.$store.commit(`loadingStop`, 'admin-rendering-saverenderers') } }, apollo: { diff --git a/server/graph/resolvers/rendering.js b/server/graph/resolvers/rendering.js index 4df266b1..b9331032 100644 --- a/server/graph/resolvers/rendering.js +++ b/server/graph/resolvers/rendering.js @@ -41,10 +41,10 @@ module.exports = { async updateRenderers(obj, args, context) { try { for (let rdr of args.renderers) { - await WIKI.models.storage.query().patch({ + await WIKI.models.renderers.query().patch({ isEnabled: rdr.isEnabled, config: _.reduce(rdr.config, (result, value, key) => { - _.set(result, `${value.key}`, value.value) + _.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null)) return result }, {}) }).where('key', rdr.key) diff --git a/server/graph/schemas/rendering.graphql b/server/graph/schemas/rendering.graphql index 0a918929..9b4d0ae9 100644 --- a/server/graph/schemas/rendering.graphql +++ b/server/graph/schemas/rendering.graphql @@ -50,6 +50,5 @@ type Renderer { input RendererInput { isEnabled: Boolean! key: String! - mode: String! config: [KeyValuePairInput] } diff --git a/server/models/renderers.js b/server/models/renderers.js index 0bb33d13..379bc76a 100644 --- a/server/models/renderers.js +++ b/server/models/renderers.js @@ -90,6 +90,14 @@ module.exports = class Renderer extends Model { } else { WIKI.logger.info(`No new renderers found: [ SKIPPED ]`) } + + // -> Delete removed Renderers + for (const renderer of dbRenderers) { + if (!_.some(WIKI.data.renderers, ['key', renderer.key])) { + await WIKI.models.renderers.query().where('key', renderer.key).del() + WIKI.logger.info(`Removed renderer ${renderer.key} because it is no longer present in the modules folder: [ OK ]`) + } + } } catch (err) { WIKI.logger.error(`Failed to scan or load new renderers: [ FAILED ]`) WIKI.logger.error(err) diff --git a/server/modules/rendering/html-mathjax/definition.yml b/server/modules/rendering/html-mathjax/definition.yml deleted file mode 100644 index 9584c26c..00000000 --- a/server/modules/rendering/html-mathjax/definition.yml +++ /dev/null @@ -1,9 +0,0 @@ -key: htmlMathjax -title: Mathjax Processor -description: TeX/MathML Math Equations Parser -author: requarks.io -icon: mdi-function-variant -enabledDefault: false -dependsOn: htmlCore -step: pre -props: {} diff --git a/server/modules/rendering/html-mathjax/mathjax.js b/server/modules/rendering/html-mathjax/mathjax.js deleted file mode 100644 index 5c9083c3..00000000 --- a/server/modules/rendering/html-mathjax/mathjax.js +++ /dev/null @@ -1,82 +0,0 @@ -const mathjax = require('mathjax-node') -const _ = require('lodash') - -// ------------------------------------ -// Mathjax -// ------------------------------------ - -/* global WIKI */ - -const mathRegex = [ - { - format: 'TeX', - regex: /\\\[([\s\S]*?)\\\]/g - }, - { - format: 'inline-TeX', - regex: /\\\((.*?)\\\)/g - }, - { - format: 'MathML', - regex: //g - } -] - -module.exports = { - init ($, config) { - mathjax.config({ - MathJax: { - jax: ['input/TeX', 'input/MathML', 'output/SVG'], - extensions: ['tex2jax.js', 'mml2jax.js'], - TeX: { - extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js'] - }, - SVG: { - scale: 120, - font: 'STIX-Web' - } - } - }) - }, - async render (content) { - let matchStack = [] - let replaceStack = [] - let currentMatch - let mathjaxState = {} - - _.forEach(mathRegex, mode => { - do { - currentMatch = mode.regex.exec(content) - if (currentMatch) { - matchStack.push(currentMatch[0]) - replaceStack.push( - new Promise((resolve, reject) => { - mathjax.typeset({ - math: (mode.format === 'MathML') ? currentMatch[0] : currentMatch[1], - format: mode.format, - speakText: false, - svg: true, - state: mathjaxState, - timeout: 30 * 1000 - }, result => { - if (!result.errors) { - resolve(result.svg) - } else { - resolve(currentMatch[0]) - WIKI.logger.warn(result.errors.join(', ')) - } - }) - }) - ) - } - } while (currentMatch) - }) - - return (matchStack.length > 0) ? Promise.all(replaceStack).then(results => { - _.forEach(matchStack, (repMatch, idx) => { - content = content.replace(repMatch, results[idx]) - }) - return content - }) : Promise.resolve(content) - } -} diff --git a/server/modules/rendering/markdown-mathjax/definition.yml b/server/modules/rendering/markdown-mathjax/definition.yml deleted file mode 100644 index 48e8e927..00000000 --- a/server/modules/rendering/markdown-mathjax/definition.yml +++ /dev/null @@ -1,8 +0,0 @@ -key: markdownMathjax -title: Mathjax Preprocessor -description: Prepare TeX blocks for Mathjax -author: requarks.io -icon: mdi-function-variant -enabledDefault: false -dependsOn: markdownCore -props: {} diff --git a/server/modules/rendering/markdown-mathjax/renderer.js b/server/modules/rendering/markdown-mathjax/renderer.js deleted file mode 100644 index 9b67a51f..00000000 --- a/server/modules/rendering/markdown-mathjax/renderer.js +++ /dev/null @@ -1,11 +0,0 @@ -const mdMathjax = require('markdown-it-mathjax')() - -// ------------------------------------ -// Markdown - Mathjax Preprocessor -// ------------------------------------ - -module.exports = { - init (md, conf) { - md.use(mdMathjax) - } -}