From 113888204ee0eadbb0b3e1601d7b5739e6e35b63 Mon Sep 17 00:00:00 2001 From: Michael Wedl Date: Thu, 14 Dec 2023 15:12:49 +0100 Subject: [PATCH 1/3] Spell check configuration --- .../api_utils/serializers.py | 48 +++++++++++++++++-- api/src/reportcreator_api/conf/settings.py | 2 + docs/docs/setup/configuration.md | 13 ++++- languagetool/Dockerfile | 2 +- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/api/src/reportcreator_api/api_utils/serializers.py b/api/src/reportcreator_api/api_utils/serializers.py index dd7c02e1c..fd7255c4f 100644 --- a/api/src/reportcreator_api/api_utils/serializers.py +++ b/api/src/reportcreator_api/api_utils/serializers.py @@ -72,14 +72,15 @@ def validate_language(self, value): async def spellcheck(self): data = self.validated_data - return await self.languagetool_request('/v2/check', { + return await self.languagetool_request('/v2/check', settings.SPELLCHECK_LANGUAGETOOL_CONFIG | { 'language': data['language'], 'data': json.dumps(data['data'], ensure_ascii=False), + 'level': 'picky' if settings.SPELLCHECK_MODE_PICKY else 'default', **({ 'preferredVariants': ','.join(self.spellcheck_languages), } if data['language'] == 'auto' else {}), }) - + def validate_singe_word(val): if ' ' in val: @@ -127,4 +128,45 @@ def validate_aes_key(self, value): except ValueError: raise serializers.ValidationError('Invalid base64 encoding') - + +# TODO: spellcheck adaptions +# * [x] update languagetool +# * [x] picky mode + advanced config +# * [x] spellcheck API: use picky mode + config +# * [ ] frontend +# * [ ] in community: reset spellcheckEnabled to false on navigation +# * [x] rework spellcheck enabled +# * [x] localSettings.spellcheckEnabled +# * [x] MarkdownFieldContent +# * [x] MarkdownTextFieldContent +# * [x] MarkdownPage +# * [x] MarkdownToolbar +# * [x] pass spellcheckEnabled as props + event update:spellcheckEnabled +# * [x] section +# * [x] finding +# * [x] project note +# * [x] personal notes +# * [x] template +# * [x] preview data +# * [x] layout editor +# * [x] report fields +# * [x] finding fields +# * [ ] rework markdownEditorMode +# * [ ] localSettings.markdownEditorMode +# * [ ] MarkdownFieldContent +# * [ ] MarkdownTextFieldContent +# * [ ] MarkdownPage +# * [ ] MarkdownToolbar +# * [ ] pass markdownEditorMode as props + event update:markdownEditorMode +# * [ ] section +# * [ ] finding +# * [ ] project note +# * [ ] personal notes +# * [ ] template +# * [ ] preview data +# * [ ] layout editor +# * [ ] report fields +# * [ ] finding fields +# * [ ] docs: new languagetool env variables +# * [x] markdown images: add "{width=100%}"" + \ No newline at end of file diff --git a/api/src/reportcreator_api/conf/settings.py b/api/src/reportcreator_api/conf/settings.py index 908b80000..7a6d11e4f 100644 --- a/api/src/reportcreator_api/conf/settings.py +++ b/api/src/reportcreator_api/conf/settings.py @@ -507,6 +507,8 @@ def __bool__(self): SPELLCHECK_URL = config('SPELLCHECK_URL', default=None) SPELLCHECK_DICTIONARY_PER_USER = config('SPELLCHECK_DICTIONARY_PER_USER', cast=bool, default=False) +SPELLCHECK_MODE_PICKY = config('SPELLCHECK_MODE_PICKY', cast=bool, default=False) +SPELLCHECK_LANGUAGETOOL_CONFIG = config('SPELLCHECK_LANGUAGETOOL_CONFIG', cast=json.loads, default='{"disabledRules": "TODO,TO_DO_HYPHEN"}') BACKUP_KEY = config('BACKUP_KEY', default=None) diff --git a/docs/docs/setup/configuration.md b/docs/docs/setup/configuration.md index f69523288..326251265 100644 --- a/docs/docs/setup/configuration.md +++ b/docs/docs/setup/configuration.md @@ -124,10 +124,21 @@ Words are added to a global spell check dictionary by default, which is availabl Using both global and personal dictionaries at the same time is not possible. Words of personal dictionaries are not shared between users. If one user adds an unknown word to their personal dictionary, the spell checker will still detect an error for other users, even when they are working in the same project or finding. -``` title="Example:" +``` title="Spell check dictionary configuration" SPELLCHECK_DICTIONARY_PER_USER=false ``` +The picky mode enables additional spell check rules. + +It is also possible to selectively enable and disable rules or rule-categories by passing a LanguageTool configuration as JSON. +See https://languagetool.org/http-api/ for available options on the `/check` request. +See https://community.languagetool.org/rule/list for available rules (note: rule IDs might differ for languages). + +``` title="Spell check rule configuration" +SPELLCHECK_PICKY_MODE=true +SPELLCHECK_LANGUAGETOOL_CONFIG='{"disabledRules": "TODO,TO_DO_HYPHEN,PASSIVE_VOICE,PASSIVE_SENTENCE_DE"}' +``` + ### Languages Configure which languages are available in the language selection. By default all languages are shown. diff --git a/languagetool/Dockerfile b/languagetool/Dockerfile index 3a0797a19..355da767f 100644 --- a/languagetool/Dockerfile +++ b/languagetool/Dockerfile @@ -1,4 +1,4 @@ -FROM erikvl87/languagetool:6.1 +FROM erikvl87/languagetool:6.3 # Add custom CA certificates ARG CA_CERTIFICATES="" From ba78dfa6787cb64149c686e9aa2ffe91d686b041 Mon Sep 17 00:00:00 2001 From: Michael Wedl Date: Thu, 14 Dec 2023 16:04:41 +0100 Subject: [PATCH 2/3] Scopes for spellcheck and MDE mode settings --- .../api_utils/serializers.py | 38 ++++++++++--------- .../Design/InputFieldDefinition.vue | 4 ++ .../components/Design/LayoutComponentForm.vue | 11 +++++- .../src/components/Design/PreviewDataForm.vue | 30 ++++++++------- frontend/src/components/DynamicInputField.vue | 15 ++++---- .../src/components/Markdown/FieldContent.vue | 12 +++--- frontend/src/components/Markdown/Page.vue | 14 +++---- frontend/src/components/Markdown/Preview.vue | 2 +- frontend/src/components/Markdown/Toolbar.vue | 37 +++++++++--------- frontend/src/components/Template/Editor.vue | 37 +++++++++--------- frontend/src/composables/apisettings.ts | 3 +- frontend/src/composables/lockedit.ts | 21 ++++++++-- frontend/src/composables/markdown.ts | 27 +++++++++++-- .../designs/[projectTypeId]/pdfdesigner.vue | 2 +- .../src/pages/notes/personal/[noteId].vue | 13 +++++-- .../notes/[noteId]/history/[historyDate].vue | 2 + .../[projectId]/notes/[noteId]/index.vue | 3 ++ .../pages/templates/[templateId]/index.vue | 2 +- frontend/src/stores/settings.ts | 29 +++++--------- 19 files changed, 180 insertions(+), 122 deletions(-) diff --git a/api/src/reportcreator_api/api_utils/serializers.py b/api/src/reportcreator_api/api_utils/serializers.py index fd7255c4f..a01a7d23e 100644 --- a/api/src/reportcreator_api/api_utils/serializers.py +++ b/api/src/reportcreator_api/api_utils/serializers.py @@ -151,22 +151,26 @@ def validate_aes_key(self, value): # * [x] layout editor # * [x] report fields # * [x] finding fields -# * [ ] rework markdownEditorMode -# * [ ] localSettings.markdownEditorMode -# * [ ] MarkdownFieldContent -# * [ ] MarkdownTextFieldContent -# * [ ] MarkdownPage -# * [ ] MarkdownToolbar -# * [ ] pass markdownEditorMode as props + event update:markdownEditorMode -# * [ ] section -# * [ ] finding -# * [ ] project note -# * [ ] personal notes -# * [ ] template -# * [ ] preview data -# * [ ] layout editor -# * [ ] report fields -# * [ ] finding fields -# * [ ] docs: new languagetool env variables +# * [x] rework markdownEditorMode +# * [x] localSettings.markdownEditorMode +# * [x] MarkdownFieldContent +# * [x] MarkdownPage +# * [x] MarkdownToolbar +# * [x] pass markdownEditorMode as props + event update:markdownEditorMode +# * [x] section +# * [x] finding +# * [x] project note +# * [x] personal notes +# * [x] template +# * [x] preview data +# * [x] layout editor +# * [x] report fields +# * [x] finding fields +# * [x] template history +# * [x] section history +# * [x] finding history +# * [x] project note history + +# * [x] docs: new languagetool env variables # * [x] markdown images: add "{width=100%}"" \ No newline at end of file diff --git a/frontend/src/components/Design/InputFieldDefinition.vue b/frontend/src/components/Design/InputFieldDefinition.vue index 42c9322e8..8e06b2b19 100644 --- a/frontend/src/components/Design/InputFieldDefinition.vue +++ b/frontend/src/components/Design/InputFieldDefinition.vue @@ -221,6 +221,8 @@ @update:model-value="updateProperty('default', $event)" :definition="{...props.modelValue, label: 'Default Value', required: false, pattern: null} as FieldDefinition" :lang="props.lang" + v-model:spellcheck-enabled="localSettings.designSpellcheckEnabled" + v-model:markdown-editor-mode="localSettings.designMarkdownEditorMode" :disabled="props.disabled" :disable-validation="true" /> @@ -289,6 +291,8 @@ const emit = defineEmits<{ 'update:modelValue': [FieldDefinitionWithId]; }>(); +const localSettings = useLocalSettings(); + const rules = { id: [ (id: string) => ( diff --git a/frontend/src/components/Design/LayoutComponentForm.vue b/frontend/src/components/Design/LayoutComponentForm.vue index fd209cc20..fc35c4295 100644 --- a/frontend/src/components/Design/LayoutComponentForm.vue +++ b/frontend/src/components/Design/LayoutComponentForm.vue @@ -179,6 +179,7 @@