From 493730dff6a5d0b6027449722320ec28d7a12965 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 18 Jan 2020 19:46:30 +0100 Subject: [PATCH] working note type and note paths widgets --- src/public/javascripts/widgets/component.js | 10 +- .../widgets/detail/note_detail_text.js | 2 +- src/public/javascripts/widgets/note_detail.js | 4 +- src/public/javascripts/widgets/note_paths.js | 90 +++++++++ src/public/javascripts/widgets/note_title.js | 174 +++++------------- src/public/javascripts/widgets/note_type.js | 28 ++- .../javascripts/widgets/tab_aware_widget.js | 14 +- .../javascripts/widgets/tab_caching_widget.js | 8 +- src/public/stylesheets/style.css | 4 - 9 files changed, 177 insertions(+), 157 deletions(-) create mode 100644 src/public/javascripts/widgets/note_paths.js diff --git a/src/public/javascripts/widgets/component.js b/src/public/javascripts/widgets/component.js index 83163efc2..45ad72c7e 100644 --- a/src/public/javascripts/widgets/component.js +++ b/src/public/javascripts/widgets/component.js @@ -15,12 +15,16 @@ export default class Component { const fun = this[name + 'Listener']; + let propagateToChildren = true; + if (typeof fun === 'function') { - await fun.call(this, data); + propagateToChildren = await fun.call(this, data) !== false; } - for (const child of this.children) { - child.eventReceived(name, data); + if (propagateToChildren) { + for (const child of this.children) { + child.eventReceived(name, data); + } } } diff --git a/src/public/javascripts/widgets/detail/note_detail_text.js b/src/public/javascripts/widgets/detail/note_detail_text.js index 772bc56a9..c0c9a46af 100644 --- a/src/public/javascripts/widgets/detail/note_detail_text.js +++ b/src/public/javascripts/widgets/detail/note_detail_text.js @@ -130,7 +130,7 @@ class NoteDetailText extends TabAwareWidget { } } - async noteSwitched() { + async refresh() { // lazy loading above can take time and tab might have been already switched to another note if (this.tabContext.note && this.tabContext.note.type === 'text') { this.textEditor.isReadOnly = await this.isReadOnly(); diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js index 6169cabc6..7c2121a0c 100644 --- a/src/public/javascripts/widgets/note_detail.js +++ b/src/public/javascripts/widgets/note_detail.js @@ -101,9 +101,7 @@ export default class NoteDetailWidget extends TabAwareWidget { this.components[this.type].renderTo(this.$widget); - this.components[this.type].setTabContext(this.tabContext); - - this.components[this.type].eventReceived('tabNoteSwitched', {tabId: this.tabContext.tabId}); + this.components[this.type].eventReceived('setTabContext', {tabContext: this.tabContext}); } getComponentType(disableAutoBook) { diff --git a/src/public/javascripts/widgets/note_paths.js b/src/public/javascripts/widgets/note_paths.js new file mode 100644 index 000000000..6ca12b316 --- /dev/null +++ b/src/public/javascripts/widgets/note_paths.js @@ -0,0 +1,90 @@ +import TabAwareWidget from "./tab_aware_widget.js"; +import treeService from "../services/tree.js"; +import treeUtils from "../services/tree_utils.js"; +import linkService from "../services/link.js"; + +const TPL = ` +`; + +export default class NotePathsWidget extends TabAwareWidget { + doRender() { + this.$widget = $(TPL); + + this.$notePathList = this.$widget.find(".note-path-list"); + this.$notePathCount = this.$widget.find(".note-path-count"); + + return this.$widget; + } + + async refresh() { + const {note, notePath} = this.tabContext; + + if (note.noteId === 'root') { + // root doesn't have any parent, but it's still technically 1 path + + this.$notePathCount.html("1 path"); + + this.$notePathList.empty(); + + await this.addPath('root', true); + } + else { + const parents = await note.getParentNotes(); + + this.$notePathCount.html(parents.length + " path" + (parents.length > 1 ? "s" : "")); + this.$notePathList.empty(); + + const pathSegments = notePath.split("/"); + const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent + + for (const parentNote of parents) { + const parentNotePath = await treeService.getSomeNotePath(parentNote); + // this is to avoid having root notes leading '/' + const notePath = parentNotePath ? (parentNotePath + '/' + note.noteId) : note.noteId; + const isCurrent = activeNoteParentNoteId === parentNote.noteId; + + await this.addPath(notePath, isCurrent); + } + + const cloneLink = $("
") + .addClass("dropdown-item") + .append( + $(' + + + +
+ + + -
- +     - - -
- - - - -
- - - -
- -     - -
- - -
@@ -92,19 +81,10 @@ const TPL = `
`; export default class NoteTitleWidget extends TabAwareWidget { - constructor(appContext) { - super(appContext); - - this.tree = null; - } - doRender() { this.$widget = $(TPL); this.$noteTitle = this.$widget.find(".note-title"); - this.$noteTitleRow = this.$widget.find(".note-title-row"); - this.$notePathList = this.$widget.find(".note-path-list"); - this.$notePathCount = this.$widget.find(".note-path-count"); this.$protectButton = this.$widget.find(".protect-button"); this.$protectButton.on('click', protectedSessionService.protectNoteAndSendToServer); @@ -114,7 +94,13 @@ export default class NoteTitleWidget extends TabAwareWidget { this.$savedIndicator = this.$widget.find(".saved-indicator"); - this.noteType = new NoteTypeWidget(this); + this.noteType = new NoteTypeWidget(this.appContext); + this.$widget.find('.note-type-actions').prepend(this.noteType.render()); + + this.notePaths = new NotePathsWidget(this.appContext); + this.$widget.prepend(this.notePaths.render()); + + this.children.push(this.noteType, this.notePaths); this.$noteTitle.on('input', () => { if (!this.note) { @@ -144,7 +130,7 @@ export default class NoteTitleWidget extends TabAwareWidget { return this.$widget; } - async activeTabChanged() { + async refresh() { const note = this.tabContext.note; this.$noteTitle.val(note.title); @@ -153,66 +139,6 @@ export default class NoteTitleWidget extends TabAwareWidget { this.$protectButton.prop("disabled", note.isProtected); this.$unprotectButton.toggleClass("active", !note.isProtected); this.$unprotectButton.prop("disabled", !note.isProtected || !protectedSessionHolder.isProtectedSessionAvailable()); - - await this.showPaths(); - } - - async showPaths() { - const {note, notePath} = this.tabContext; - - if (note.noteId === 'root') { - // root doesn't have any parent, but it's still technically 1 path - - this.$notePathCount.html("1 path"); - - this.$notePathList.empty(); - - await this.addPath('root', true); - } - else { - const parents = await note.getParentNotes(); - - this.$notePathCount.html(parents.length + " path" + (parents.length > 1 ? "s" : "")); - this.$notePathList.empty(); - - const pathSegments = notePath.split("/"); - const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent - - for (const parentNote of parents) { - const parentNotePath = await treeService.getSomeNotePath(parentNote); - // this is to avoid having root notes leading '/' - const notePath = parentNotePath ? (parentNotePath + '/' + note.noteId) : note.noteId; - const isCurrent = activeNoteParentNoteId === parentNote.noteId; - - await this.addPath(notePath, isCurrent); - } - - const cloneLink = $("
") - .addClass("dropdown-item") - .append( - $('