diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index 9523b7b84..a5b63d11f 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -6,7 +6,7 @@ import server from "../services/server.js"; import libraryLoader from "../services/library_loader.js"; import EmptyTypeWidget from "./type_widgets/empty.js"; import EditableTextTypeWidget from "./type_widgets/editable_text.js"; -import CodeTypeWidget from "./type_widgets/code.js"; +import EditableCodeTypeWidget from "./type_widgets/editable_code.js"; import FileTypeWidget from "./type_widgets/file.js"; import ImageTypeWidget from "./type_widgets/image.js"; import SearchTypeWidget from "./type_widgets/search.js"; @@ -19,6 +19,7 @@ import keyboardActionsService from "../services/keyboard_actions.js"; import noteCreateService from "../services/note_create.js"; import DeletedTypeWidget from "./type_widgets/deleted.js"; import ReadOnlyTextTypeWidget from "./type_widgets/read_only_text.js"; +import ReadOnlyCodeTypeWidget from "./type_widgets/read_only_code.js"; const TPL = `
@@ -38,7 +39,8 @@ const typeWidgetClasses = { 'deleted': DeletedTypeWidget, 'editable-text': EditableTextTypeWidget, 'read-only-text': ReadOnlyTextTypeWidget, - 'code': CodeTypeWidget, + 'editable-code': EditableCodeTypeWidget, + 'read-only-code': ReadOnlyCodeTypeWidget, 'file': FileTypeWidget, 'image': ImageTypeWidget, 'search': SearchTypeWidget, @@ -189,10 +191,23 @@ export default class NoteDetailWidget extends TabAwareWidget { } } + if (type === 'code' && !this.tabContext.codePreviewDisabled) { + const noteComplement = await this.tabContext.getNoteComplement(); + + if (note.hasLabel('readOnly') || + (noteComplement.content && noteComplement.content.length > 10000)) { + type = 'read-only-code'; + } + } + if (type === 'text') { type = 'editable-text'; } + if (type === 'code') { + type = 'editable-code'; + } + if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) { type = 'protected-session'; } @@ -276,6 +291,12 @@ export default class NoteDetailWidget extends TabAwareWidget { } } + codePreviewDisabledEvent({tabContext}) { + if (this.isTab(tabContext.tabId)) { + this.refresh(); + } + } + async cutIntoNoteCommand() { const note = appContext.tabManager.getActiveTabNote(); diff --git a/src/public/app/widgets/type_widgets/code.js b/src/public/app/widgets/type_widgets/editable_code.js similarity index 97% rename from src/public/app/widgets/type_widgets/code.js rename to src/public/app/widgets/type_widgets/editable_code.js index 5a027b6d0..20198ece9 100644 --- a/src/public/app/widgets/type_widgets/code.js +++ b/src/public/app/widgets/type_widgets/editable_code.js @@ -21,8 +21,8 @@ const TPL = `
`; -export default class CodeTypeWidget extends TypeWidget { - static getType() { return "code"; } +export default class EditableCodeTypeWidget extends TypeWidget { + static getType() { return "editable-code"; } doRender() { this.$widget = $(TPL); diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js index 41e73f587..635ea7b31 100644 --- a/src/public/app/widgets/type_widgets/editable_text.js +++ b/src/public/app/widgets/type_widgets/editable_text.js @@ -1,13 +1,9 @@ import libraryLoader from "../../services/library_loader.js"; import noteAutocompleteService from '../../services/note_autocomplete.js'; import mimeTypesService from '../../services/mime_types.js'; -import TypeWidget from "./type_widget.js"; import utils from "../../services/utils.js"; -import appContext from "../../services/app_context.js"; import keyboardActionService from "../../services/keyboard_actions.js"; import treeCache from "../../services/tree_cache.js"; -import linkService from "../../services/link.js"; -import noteContentRenderer from "../../services/note_content_renderer.js"; import AbstractTextTypeWidget from "./abstract_text_type_widget.js"; const ENABLE_INSPECTOR = false; diff --git a/src/public/app/widgets/type_widgets/read_only_code.js b/src/public/app/widgets/type_widgets/read_only_code.js new file mode 100644 index 000000000..1a50ca675 --- /dev/null +++ b/src/public/app/widgets/type_widgets/read_only_code.js @@ -0,0 +1,44 @@ +import TypeWidget from "./type_widget.js"; + +const TPL = ` +
+ + +
+ Read only code view is shown. Click here to edit the note. +
+ +

+
`; + +export default class ReadOnlyCodeTypeWidget extends TypeWidget { + static getType() { return "read-only-code"; } + + doRender() { + this.$widget = $(TPL); + this.$content = this.$widget.find('.note-detail-read-only-code-content'); + + this.$widget.find('a.edit-note').on('click', () => { + this.tabContext.codePreviewDisabled = true; + + this.triggerEvent('codePreviewDisabled', {tabContext: this.tabContext}); + }); + + return this.$widget; + } + + async doRefresh(note) { + const noteComplement = await this.tabContext.getNoteComplement(); + + this.$content.text(noteComplement.content); + } +} \ No newline at end of file diff --git a/src/public/app/widgets/type_widgets/type_widget.js b/src/public/app/widgets/type_widgets/type_widget.js index 60755df36..4b0cdb9f2 100644 --- a/src/public/app/widgets/type_widgets/type_widget.js +++ b/src/public/app/widgets/type_widgets/type_widget.js @@ -48,4 +48,10 @@ export default class TypeWidget extends TabAwareWidget { this.refresh(); } } + + codePreviewDisabledEvent({tabContext}) { + if (this.isTab(tabContext.tabId)) { + this.refresh(); + } + } } \ No newline at end of file