diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.js index 3a2dbe76d..f0de1fa52 100644 --- a/src/public/app/layouts/desktop_layout.js +++ b/src/public/app/layouts/desktop_layout.js @@ -39,6 +39,7 @@ import LinkMapWidget from "../widgets/ribbon_widgets/link_map.js"; import NotePathsWidget from "../widgets/ribbon_widgets/note_paths.js"; import SimilarNotesWidget from "../widgets/ribbon_widgets/similar_notes.js"; import RightPaneContainer from "../widgets/containers/right_pane_container.js"; +import EditButton from "../widgets/buttons/edit_button.js"; export default class DesktopLayout { constructor(customWidgets) { @@ -128,6 +129,7 @@ export default class DesktopLayout { .ribbon(new LinkMapWidget()) .ribbon(new SimilarNotesWidget()) .ribbon(new NoteInfoWidget()) + .button(new EditButton()) .button(new ButtonWidget() .icon('bx bx-history') .title("Note Revisions") diff --git a/src/public/app/services/note_context.js b/src/public/app/services/note_context.js index 5e1354e9e..9836c7687 100644 --- a/src/public/app/services/note_context.js +++ b/src/public/app/services/note_context.js @@ -40,8 +40,8 @@ class NoteContext extends Component { this.notePath = resolvedNotePath; this.noteId = treeService.getNoteIdFromNotePath(resolvedNotePath); - this.textPreviewDisabled = false; - this.codePreviewDisabled = false; + this.readOnlyTemporarilyDisabled = false; + this.readOnlyTemporarilyDisabled = false; this.saveToRecentNotes(resolvedNotePath); @@ -177,6 +177,28 @@ class NoteContext extends Component { }); } + async isReadOnly() { + if (this.readOnlyTemporarilyDisabled) { + return false; + } + + if (this.note.type !== 'text' && this.note.type !== 'code') { + return false; + } + + if (this.note.hasLabel('readOnly')) { + return true; + } + + const noteComplement = await this.getNoteComplement(); + + const SIZE_LIMIT = this.note.type === 'text' ? 10000 : 30000; + + return noteComplement.content + && noteComplement.content.length > SIZE_LIMIT + && !this.note.hasLabel('autoReadOnlyDisabled'); + } + async entitiesReloadedEvent({loadResults}) { if (loadResults.isNoteReloaded(this.noteId)) { const note = await froca.getNote(this.noteId); diff --git a/src/public/app/widgets/buttons/edit_button.js b/src/public/app/widgets/buttons/edit_button.js new file mode 100644 index 000000000..b0c173785 --- /dev/null +++ b/src/public/app/widgets/buttons/edit_button.js @@ -0,0 +1,31 @@ +import ButtonWidget from "./button_widget.js"; + +export default class EditButton extends ButtonWidget { + isEnabled() { + return super.isEnabled() && this.noteContext; + } + + constructor() { + super(); + + this.icon("bx-edit-alt") + .title("Edit this note") + .titlePlacement("bottom") + .onClick(widget => { + this.noteContext.readOnlyTemporarilyDisabled = true; + + this.triggerEvent('readOnlyTemporarilyDisabled', {noteContext: this.noteContext}); + + this.refresh(); + }); + } + + async refreshWithNote(note) { + // can't do this in isEnabled() since isReadOnly is async + this.toggleInt(await this.noteContext.isReadOnly()); + + console.log("await this.noteContext.isReadOnly()", await this.noteContext.isReadOnly()); + + await super.refreshWithNote(note); + } +} diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index afec2a95a..e2beff6fb 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -150,26 +150,12 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { let type = note.type; - if (type === 'text' && !this.noteContext.textPreviewDisabled) { - const noteComplement = await this.noteContext.getNoteComplement(); - - if (note.hasLabel('readOnly') || - (noteComplement.content - && noteComplement.content.length > 10000) - && !note.hasLabel('autoReadOnlyDisabled')) { - type = 'read-only-text'; - } + if (type === 'text' && await this.noteContext.isReadOnly()) { + type = 'read-only-text'; } - if (type === 'code' && !this.noteContext.codePreviewDisabled) { - const noteComplement = await this.noteContext.getNoteComplement(); - - if (note.hasLabel('readOnly') || - (noteComplement.content - && noteComplement.content.length > 30000) - && !note.hasLabel('autoReadOnlyDisabled')) { - type = 'read-only-code'; - } + if (type === 'code' && await this.noteContext.isReadOnly()) { + type = 'read-only-code'; } if (type === 'text') { @@ -279,13 +265,13 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { return this.spacedUpdate.isAllSavedAndTriggerUpdate(); } - textPreviewDisabledEvent({noteContext}) { + readOnlyTemporarilyDisabledEvent({noteContext}) { if (this.isNoteContext(noteContext.ntxId)) { this.refresh(); } } - codePreviewDisabledEvent({noteContext}) { + readOnlyTemporarilyDisabledEvent({noteContext}) { if (this.isNoteContext(noteContext.ntxId)) { this.refresh(); } diff --git a/src/public/app/widgets/type_widgets/read_only_code.js b/src/public/app/widgets/type_widgets/read_only_code.js index 8ee0e6792..ad4243fec 100644 --- a/src/public/app/widgets/type_widgets/read_only_code.js +++ b/src/public/app/widgets/type_widgets/read_only_code.js @@ -21,9 +21,6 @@ const TPL = ` } -
-

 `;
 
@@ -33,12 +30,6 @@ export default class ReadOnlyCodeTypeWidget extends TypeWidget {
     doRender() {
         this.$widget = $(TPL);
         this.$content = this.$widget.find('.note-detail-read-only-code-content');
-
-        this.$widget.find('.edit-code-note-button').on('click', () => {
-            this.noteContext.codePreviewDisabled = true;
-
-            this.triggerEvent('codePreviewDisabled', {noteContext: this.noteContext});
-        });
     }
 
     async doRefresh(note) {
diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js
index fb99ac0f6..59777b756 100644
--- a/src/public/app/widgets/type_widgets/read_only_text.js
+++ b/src/public/app/widgets/type_widgets/read_only_text.js
@@ -24,7 +24,6 @@ const TPL = `
         padding-left: 24px;
         padding-top: 10px;
         font-family: var(--detail-text-font-family);
-        position: relative;
         min-height: 50px;
     }
         
@@ -53,9 +52,6 @@ const TPL = `
     }
     
 
-    
-
`; @@ -68,12 +64,6 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget { this.$content = this.$widget.find('.note-detail-readonly-text-content'); - this.$widget.find('.edit-text-note-button').on('click', () => { - this.noteContext.textPreviewDisabled = true; - - this.triggerEvent('textPreviewDisabled', {noteContext: this.noteContext}); - }); - this.setupImageOpening(true); super.doRender(); diff --git a/src/public/app/widgets/type_widgets/type_widget.js b/src/public/app/widgets/type_widgets/type_widget.js index 88d838a5d..af2f0b821 100644 --- a/src/public/app/widgets/type_widgets/type_widget.js +++ b/src/public/app/widgets/type_widgets/type_widget.js @@ -41,13 +41,13 @@ export default class TypeWidget extends NoteContextAwareWidget { focus() {} - textPreviewDisabledEvent({noteContext}) { + readOnlyTemporarilyDisabledEvent({noteContext}) { if (this.isNoteContext(noteContext.ntxId)) { this.refresh(); } } - codePreviewDisabledEvent({noteContext}) { + readOnlyTemporarilyDisabledEvent({noteContext}) { if (this.isNoteContext(noteContext.ntxId)) { this.refresh(); }