feat(Description): Use text as editor if available

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2023-01-27 12:24:40 +01:00
parent 0e52215f30
commit c9f539bf31
2 changed files with 51 additions and 17 deletions

View File

@@ -27,6 +27,7 @@ use OCA\Deck\AppInfo\Application;
use OCA\Deck\Service\ConfigService; use OCA\Deck\Service\ConfigService;
use OCA\Deck\Service\PermissionService; use OCA\Deck\Service\PermissionService;
use OCA\Files\Event\LoadSidebar; use OCA\Files\Event\LoadSidebar;
use OCA\Text\Event\LoadEditor;
use OCA\Viewer\Event\LoadViewer; use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as CollaborationResourcesEvent; use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as CollaborationResourcesEvent;
@@ -90,6 +91,9 @@ class PageController extends Controller {
$this->eventDispatcher->dispatchTyped(new LoadSidebar()); $this->eventDispatcher->dispatchTyped(new LoadSidebar());
$this->eventDispatcher->dispatchTyped(new CollaborationResourcesEvent()); $this->eventDispatcher->dispatchTyped(new CollaborationResourcesEvent());
if (class_exists(LoadEditor::class)) {
$this->eventDispatcher->dispatchTyped(new LoadEditor());
}
if (class_exists(LoadViewer::class)) { if (class_exists(LoadViewer::class)) {
$this->eventDispatcher->dispatchTyped(new LoadViewer()); $this->eventDispatcher->dispatchTyped(new LoadViewer());
} }

View File

@@ -26,11 +26,12 @@
{{ t('deck', 'Description') }} {{ t('deck', 'Description') }}
<span v-if="descriptionLastEdit && !descriptionSaving">{{ t('deck', '(Unsaved)') }}</span> <span v-if="descriptionLastEdit && !descriptionSaving">{{ t('deck', '(Unsaved)') }}</span>
<span v-if="descriptionSaving">{{ t('deck', '(Saving)') }}</span> <span v-if="descriptionSaving">{{ t('deck', '(Saving)') }}</span>
<a v-tooltip="t('deck', 'Formatting help')" <a v-if="!textAppAvailable"
v-tooltip="t('deck', 'Formatting help')"
href="https://deck.readthedocs.io/en/latest/Markdown/" href="https://deck.readthedocs.io/en/latest/Markdown/"
target="_blank" target="_blank"
class="icon icon-info" /> class="icon icon-info" />
<NcActions v-if="canEdit"> <NcActions v-if="!textAppAvailable && canEdit">
<NcActionButton v-if="!descriptionEditing" icon="icon-rename" @click="showEditor()"> <NcActionButton v-if="!descriptionEditing" icon="icon-rename" @click="showEditor()">
{{ t('deck', 'Edit description') }} {{ t('deck', 'Edit description') }}
</NcActionButton> </NcActionButton>
@@ -48,6 +49,10 @@
</NcActions> </NcActions>
</h5> </h5>
<template v-if="textAppAvailable">
<div ref="editor" />
</template>
<template v-else>
<div v-if="!descriptionEditing && hasDescription" <div v-if="!descriptionEditing && hasDescription"
id="description-preview" id="description-preview"
@click="clickedPreview" @click="clickedPreview"
@@ -63,6 +68,7 @@
@initialized="addKeyListeners" @initialized="addKeyListeners"
@update:modelValue="updateDescription" @update:modelValue="updateDescription"
@blur="saveDescription" /> @blur="saveDescription" />
</template>
<NcModal v-if="modalShow" :title="t('deck', 'Choose attachment')" @close="modalShow=false"> <NcModal v-if="modalShow" :title="t('deck', 'Choose attachment')" @close="modalShow=false">
<div class="modal__content"> <div class="modal__content">
@@ -116,6 +122,8 @@ export default {
}, },
data() { data() {
return { return {
textAppAvailable: !!window.OCA?.Text?.createEditor,
editor: null,
keyExitState: 0, keyExitState: 0,
description: '', description: '',
markdownIt: null, markdownIt: null,
@@ -175,7 +183,29 @@ export default {
return this.card?.description?.trim?.() !== '' return this.card?.description?.trim?.() !== ''
}, },
}, },
mounted() {
this.setupEditor()
},
beforeDestroy() {
this?.editor?.destroy()
},
methods: { methods: {
setupEditor() {
this?.editor?.vm?.$destroy()
this.$refs.editor.innerHTML = ''
const element = document.createElement('div')
this.$refs.editor.appendChild(element)
this.editor = window.OCA.Text.createEditor({
el: element,
content: this.card.description,
readOnly: !this.canEdit,
onUpdate: ({ markdown }) => {
this.description = markdown
this.updateDescription()
},
})
},
addKeyListeners() { addKeyListeners() {
this.$refs.markdownEditor.easymde.codemirror.on('keydown', (a, b) => { this.$refs.markdownEditor.easymde.codemirror.on('keydown', (a, b) => {