From f849c16d9d3dea8bb74a9d1b88c32a17427241de Mon Sep 17 00:00:00 2001 From: Nicolas Giard Date: Sun, 26 Feb 2023 03:46:09 +0000 Subject: [PATCH] feat: save + load admin editors config --- server/db/migrations/3.0.0.js | 17 +-- server/graph/schemas/site.graphql | 12 +++ server/models/sites.js | 28 +++++ .../EditorMarkdownConfigOverlay.vue | 101 +++++++++++++++++- ux/src/i18n/locales/en.json | 4 +- ux/src/pages/AdminEditors.vue | 50 ++++++++- 6 files changed, 201 insertions(+), 11 deletions(-) diff --git a/server/db/migrations/3.0.0.js b/server/db/migrations/3.0.0.js index 5765d46c..6d0c77b6 100644 --- a/server/db/migrations/3.0.0.js +++ b/server/db/migrations/3.0.0.js @@ -579,15 +579,18 @@ exports.up = async knex => { isActive: true, config: { allowHTML: true, - linkify: true, + kroki: false, + krokiServerUrl: 'https://kroki.io', + latexEngine: 'katex', lineBreaks: true, - typographer: false, - underline: false, + linkify: true, + multimdTable: true, + plantuml: false, + plantumlServerUrl: 'https://www.plantuml.com/plantuml/', + quotes: 'english', tabWidth: 2, - latexEngine: 'katex', - kroki: true, - plantuml: true, - multimdTable: true + typographer: false, + underline: true } }, wysiwyg: { diff --git a/server/graph/schemas/site.graphql b/server/graph/schemas/site.graphql index 4b08963f..8799c663 100644 --- a/server/graph/schemas/site.graphql +++ b/server/graph/schemas/site.graphql @@ -186,6 +186,7 @@ input SiteUpdateInput { features: SiteFeaturesInput defaults: SiteDefaultsInput uploads: SiteUploadsInput + editors: SiteEditorsInput theme: SiteThemeInput } @@ -230,6 +231,17 @@ input SiteThemeInput { contentFont: String } +input SiteEditorsInput { + asciidoc: SiteEditorInput + markdown: SiteEditorInput + wysiwyg: SiteEditorInput +} + +input SiteEditorInput { + isActive: Boolean + config: JSON +} + input SiteUploadsInput { conflictBehavior: SiteUploadConflictBehavior normalizeFilename: Boolean diff --git a/server/models/sites.js b/server/models/sites.js index 78830942..2e51e970 100644 --- a/server/models/sites.js +++ b/server/models/sites.js @@ -107,6 +107,34 @@ module.exports = class Site extends Model { baseFont: 'roboto', contentFont: 'roboto' }, + editors: { + asciidoc: { + isActive: true, + config: {} + }, + markdown: { + isActive: true, + config: { + allowHTML: true, + kroki: false, + krokiServerUrl: 'https://kroki.io', + latexEngine: 'katex', + lineBreaks: true, + linkify: true, + multimdTable: true, + plantuml: false, + plantumlServerUrl: 'https://www.plantuml.com/plantuml/', + quotes: 'english', + tabWidth: 2, + typographer: false, + underline: true + } + }, + wysiwyg: { + isActive: true, + config: {} + } + }, uploads: { conflictBehavior: 'overwrite', normalizeFilename: true diff --git a/ux/src/components/EditorMarkdownConfigOverlay.vue b/ux/src/components/EditorMarkdownConfigOverlay.vue index 50c47d52..53abf79e 100644 --- a/ux/src/components/EditorMarkdownConfigOverlay.vue +++ b/ux/src/components/EditorMarkdownConfigOverlay.vue @@ -15,6 +15,16 @@ q-layout(view='hHh lpR fFf', container) type='a' ) q-btn-group(push) + q-btn( + push + color='grey-6' + text-color='white' + :aria-label='t(`common.actions.refresh`)' + icon='las la-redo-alt' + @click='load' + :loading='state.loading > 0' + ) + q-tooltip(anchor='center left', self='center right') {{t(`common.actions.refresh`)}} q-btn( push color='white' @@ -245,7 +255,9 @@ q-layout(view='hHh lpR fFf', container) diff --git a/ux/src/i18n/locales/en.json b/ux/src/i18n/locales/en.json index b6e60250..d2ae6246 100644 --- a/ux/src/i18n/locales/en.json +++ b/ux/src/i18n/locales/en.json @@ -1705,5 +1705,7 @@ "admin.editors.markdown.plantumlServerUrl": "PlantUML Server URL", "admin.editors.markdown.plantumlServerUrlHint": "URL to the PlantUML server used for image generation.", "admin.editors.markdown.quotes": "Quotes Style", - "admin.editors.markdown.quotesHint": "When typographer is enabled. Double + single quotes replacement pairs. e.g. «»„“ for Russian, „“‚‘ for German, etc." + "admin.editors.markdown.quotesHint": "When typographer is enabled. Double + single quotes replacement pairs. e.g. «»„“ for Russian, „“‚‘ for German, etc.", + "admin.editors.saveSuccess": "Editors state saved successfully.", + "admin.editors.markdown.saveSuccess": "Markdown editor configuration saved successfully." } diff --git a/ux/src/pages/AdminEditors.vue b/ux/src/pages/AdminEditors.vue index e3411962..13205df2 100644 --- a/ux/src/pages/AdminEditors.vue +++ b/ux/src/pages/AdminEditors.vue @@ -209,7 +209,55 @@ async function load () { state.loading-- } -async function save () {} +async function save () { + state.loading++ + try { + const respRaw = await APOLLO_CLIENT.mutate({ + mutation: gql` + mutation saveEditorState ( + $id: UUID! + $patch: SiteUpdateInput! + ) { + updateSite ( + id: $id, + patch: $patch + ) { + operation { + succeeded + slug + message + } + } + } + `, + variables: { + id: adminStore.currentSiteId, + patch: { + editors: { + asciidoc: { isActive: state.config.asciidoc }, + markdown: { isActive: state.config.markdown }, + wysiwyg: { isActive: state.config.wysiwyg } + } + } + } + }) + if (respRaw?.data?.updateSite?.operation?.succeeded) { + $q.notify({ + type: 'positive', + message: t('admin.editors.saveSuccess') + }) + } else { + throw new Error(respRaw?.data?.updateSite?.operation?.message || 'An unexpected error occured.') + } + } catch (err) { + $q.notify({ + type: 'negative', + message: 'Failed to save site editors config', + caption: err.message + }) + } + state.loading-- +} async function refresh () { await load()