diff --git a/src/public/javascripts/services/note_context.js b/src/public/javascripts/services/note_context.js index a7bad322d..76ecb3dfc 100644 --- a/src/public/javascripts/services/note_context.js +++ b/src/public/javascripts/services/note_context.js @@ -1,17 +1,19 @@ -import treeService from "./tree"; -import protectedSessionHolder from "./protected_session_holder"; -import server from "./server"; -import bundleService from "./bundle"; -import attributeService from "./attributes"; -import treeUtils from "./tree_utils"; -import utils from "./utils"; -import noteDetailCode from "./note_detail_code"; -import noteDetailText from "./note_detail_text"; -import noteDetailFile from "./note_detail_file"; -import noteDetailImage from "./note_detail_image"; -import noteDetailSearch from "./note_detail_search"; -import noteDetailRender from "./note_detail_render"; -import noteDetailRelationMap from "./note_detail_relation_map"; +import treeService from "./tree.js"; +import protectedSessionHolder from "./protected_session_holder.js"; +import server from "./server.js"; +import bundleService from "./bundle.js"; +import attributeService from "./attributes.js"; +import treeUtils from "./tree_utils.js"; +import utils from "./utils.js"; +import noteDetailCode from "./note_detail_code.js"; +import noteDetailText from "./note_detail_text.js"; +import noteDetailFile from "./note_detail_file.js"; +import noteDetailImage from "./note_detail_image.js"; +import noteDetailSearch from "./note_detail_search.js"; +import noteDetailRender from "./note_detail_render.js"; +import noteDetailRelationMap from "./note_detail_relation_map.js"; + +const $noteTabsContainer = $("#note-tab-container"); const componentClasses = { 'code': noteDetailCode, diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 592df4271..1d737690f 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -44,11 +44,22 @@ async function reload() { } async function switchToNote(noteId) { - if (getActiveNoteId() !== noteId) { + if (Object.keys(noteContexts).length === 0) { + const tabContent = $("#note-tab-content-template").clone(); + + tabContent.removeAttr('id'); + tabContent.attr('data-note-id', noteId); + + $noteTabsContainer.append(tabContent); + + noteContexts[noteId] = new NoteContext(noteId); + } + + //if (getActiveNoteId() !== noteId) { await saveNotesIfChanged(); await loadNoteDetail(noteId); - } + //} } function getActiveNoteContent() { @@ -60,7 +71,7 @@ function onNoteChange(func) { } async function saveNotesIfChanged() { - for (const ctx of noteContexts) { + for (const ctx of Object.values(noteContexts)) { await ctx.saveNoteIfChanged(); } @@ -103,7 +114,7 @@ function getActiveContext() { } function showTab(noteId) { - for (const ctx of noteContexts) { + for (const ctx of Object.values(noteContexts)) { ctx.$noteTab.toggle(ctx.noteId === noteId); } } diff --git a/src/public/javascripts/services/note_detail_text.js b/src/public/javascripts/services/note_detail_text.js index 1cb9b49f3..7a351038a 100644 --- a/src/public/javascripts/services/note_detail_text.js +++ b/src/public/javascripts/services/note_detail_text.js @@ -8,6 +8,7 @@ class NoteDetailText { * @param {NoteContext} ctx */ constructor(ctx) { + this.ctx = ctx; this.$component = ctx.$noteTab.find('.note-detail-text'); this.textEditor = null; @@ -48,11 +49,11 @@ class NoteDetailText { } } - this.textEditor.isReadOnly = await isReadOnly(); + this.textEditor.isReadOnly = await this.isReadOnly(); this.$component.show(); - this.textEditor.setData(noteDetailService.getActiveNote().content); + this.textEditor.setData(this.ctx.note.content); } getContent() { diff --git a/src/views/details/file.ejs b/src/views/details/file.ejs index bb983ddd4..bfb801cd6 100644 --- a/src/views/details/file.ejs +++ b/src/views/details/file.ejs @@ -1,32 +1,32 @@ -
| Note ID: | -+ | |
|---|---|---|
| Original file name: | -+ | |
| File type: | -+ | |
| File size: | -+ | |
| Preview: | - + | |
| - + - + | ||