From 62a80ef016cdc014433246758f39d27117048709 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 2 Feb 2020 18:46:50 +0100 Subject: [PATCH] standard widget => collapsible widget --- package-lock.json | 20 +++++----- package.json | 2 +- .../services/frontend_script_api.js | 6 +-- .../javascripts/services/tab_context.js | 14 +++++-- src/public/javascripts/widgets/attributes.js | 4 +- src/public/javascripts/widgets/calendar.js | 4 +- ...andard_widget.js => collapsible_widget.js} | 40 +++---------------- src/public/javascripts/widgets/component.js | 4 +- .../javascripts/widgets/edited_notes.js | 4 +- src/public/javascripts/widgets/link_map.js | 4 +- src/public/javascripts/widgets/note_info.js | 26 ++++++------ .../javascripts/widgets/note_revisions.js | 4 +- .../javascripts/widgets/similar_notes.js | 4 +- .../javascripts/widgets/tab_aware_widget.js | 5 ++- .../javascripts/widgets/what_links_here.js | 4 +- 15 files changed, 60 insertions(+), 85 deletions(-) rename src/public/javascripts/widgets/{standard_widget.js => collapsible_widget.js} (67%) diff --git a/package-lock.json b/package-lock.json index d6b9d0a3d..75ca59422 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.40.1", + "version": "0.40.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -566,8 +566,7 @@ "@types/debug": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz", - "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==", - "dev": true + "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==" }, "@types/events": { "version": "3.0.0", @@ -3848,12 +3847,12 @@ } }, "file-type": { - "version": "13.1.2", - "resolved": "https://registry.npmjs.org/file-type/-/file-type-13.1.2.tgz", - "integrity": "sha512-NiHXbmclwHN38eHZfRklosbm7/W+1yacDzRCyddd0NiyuJUArQDmzJ8GPSFJGl82+I59u7sNGfcAVnJsfXJb8A==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-14.0.0.tgz", + "integrity": "sha512-+gxNvurlwHfTohZC6gqf0ybMl+cXYB9f1x++kw9AgKItdFx20J0fV9wCVR38a5/jphL5EUcusJ9tLYkPRtGHaw==", "requires": { "readable-web-to-node-stream": "^2.0.0", - "strtok3": "^5.0.2", + "strtok3": "^6.0.0", "token-types": "^2.0.0", "typedarray-to-buffer": "^3.1.5" } @@ -9522,11 +9521,12 @@ } }, "strtok3": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-5.0.2.tgz", - "integrity": "sha512-EFeVpFC5qDsqPEJSrIYyS/ueFBknGhgSK9cW+YAJF/cgJG/KSjoK7X6rK5xnpcLe7y1LVkVFCXWbAb+ClNKzKQ==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.0.0.tgz", + "integrity": "sha512-ZXlmE22LZnIBvEU3n/kZGdh770fYFie65u5+2hLK9s74DoFtpkQIdBZVeYEzlolpGa+52G5IkzjUWn+iXynOEQ==", "requires": { "@tokenizer/token": "^0.1.1", + "@types/debug": "^4.1.5", "debug": "^4.1.1", "peek-readable": "^3.1.0" } diff --git a/package.json b/package.json index af0553877..d73596116 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "electron-window-state": "5.0.3", "express": "4.17.1", "express-session": "1.17.0", - "file-type": "13.1.2", + "file-type": "14.0.0", "fs-extra": "8.1.0", "helmet": "3.21.2", "html": "1.0.0", diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.js index a3f6be33e..fc0e561e1 100644 --- a/src/public/javascripts/services/frontend_script_api.js +++ b/src/public/javascripts/services/frontend_script_api.js @@ -7,7 +7,7 @@ import treeCache from './tree_cache.js'; import noteTooltipService from './note_tooltip.js'; import protectedSessionService from './protected_session.js'; import dateNotesService from './date_notes.js'; -import StandardWidget from '../widgets/standard_widget.js'; +import CollapsibleWidget from '../widgets/standard_widget.js'; import ws from "./ws.js"; import hoistedNoteService from "./hoisted_note.js"; import appContext from "./app_context.js"; @@ -37,8 +37,8 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte /** @property {TabContext|null} - experimental! */ this.tabContext = tabContext; - /** @property {StandardWidget} */ - this.StandardWidget = StandardWidget; + /** @property {CollapsibleWidget} */ + this.StandardWidget = CollapsibleWidget; /** * Activates note in the tree and in the note detail. diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index add1f54f8..987cde4ef 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -69,7 +69,10 @@ class TabContext extends Component { protectedSessionHolder.touchProtectedSession(); } - this.trigger('tabNoteSwitched', {tabId: this.tabId}); + this.trigger('tabNoteSwitched', { + tabId: this.tabId, + notePath: this.notePath + }); this.trigger('openTabsChanged'); } @@ -114,11 +117,14 @@ class TabContext extends Component { } noteDeletedListener({noteId}) { - if (this.note && noteId === this.note.noteId) { - this.note = null; + if (this.noteId === noteId) { + this.noteId = null; this.notePath = null; - this.trigger('tabNoteSwitched', {tabId: this.tabId}); + this.trigger('tabNoteSwitched', { + tabId: this.tabId, + notePath: this.notePath + }); } } diff --git a/src/public/javascripts/widgets/attributes.js b/src/public/javascripts/widgets/attributes.js index 9812eedad..62352250b 100644 --- a/src/public/javascripts/widgets/attributes.js +++ b/src/public/javascripts/widgets/attributes.js @@ -1,9 +1,9 @@ import utils from "../services/utils.js"; import linkService from "../services/link.js"; import ws from "../services/ws.js"; -import StandardWidget from "./standard_widget.js"; +import CollapsibleWidget from "./standard_widget.js"; -class AttributesWidget extends StandardWidget { +class AttributesWidget extends CollapsibleWidget { getWidgetTitle() { return "Attributes"; } getHelp() { diff --git a/src/public/javascripts/widgets/calendar.js b/src/public/javascripts/widgets/calendar.js index fcc6bb4c0..d68704714 100644 --- a/src/public/javascripts/widgets/calendar.js +++ b/src/public/javascripts/widgets/calendar.js @@ -1,4 +1,4 @@ -import StandardWidget from "./standard_widget.js"; +import CollapsibleWidget from "./standard_widget.js"; import libraryLoader from "../services/library_loader.js"; import utils from "../services/utils.js"; import dateNoteService from "../services/date_notes.js"; @@ -24,7 +24,7 @@ const TPL = ` `; -class CalendarWidget extends StandardWidget { +class CalendarWidget extends CollapsibleWidget { getWidgetTitle() { return "Calendar"; } async isEnabled() { diff --git a/src/public/javascripts/widgets/standard_widget.js b/src/public/javascripts/widgets/collapsible_widget.js similarity index 67% rename from src/public/javascripts/widgets/standard_widget.js rename to src/public/javascripts/widgets/collapsible_widget.js index d19573243..eec4f3297 100644 --- a/src/public/javascripts/widgets/standard_widget.js +++ b/src/public/javascripts/widgets/collapsible_widget.js @@ -21,7 +21,7 @@ const WIDGET_TPL = ` `; -class StandardWidget extends TabAwareWidget { +class CollapsibleWidget extends TabAwareWidget { getWidgetTitle() { return "Untitled widget"; } getHeaderActions() { return []; } @@ -30,20 +30,14 @@ class StandardWidget extends TabAwareWidget { getMaxHeight() { return null; } - //getPosition() { return this.widgetOptions.position; } - render() { - const widgetInstanceId = this.componentId + "-" + utils.randomString(10); - this.$widget = $(WIDGET_TPL); - this.$widget.find('[data-target]').attr('data-target', "#" + widgetInstanceId); + this.$widget.find('[data-target]').attr('data-target', "#" + this.componentId); this.$bodyWrapper = this.$widget.find('.body-wrapper'); - this.$bodyWrapper.attr('id', widgetInstanceId); + this.$bodyWrapper.attr('id', this.componentId); -// if (this.state.expanded) { - this.$bodyWrapper.collapse("show"); -// } + this.$bodyWrapper.collapse("show"); this.$body = this.$bodyWrapper.find('.card-body'); @@ -54,10 +48,6 @@ class StandardWidget extends TabAwareWidget { this.$body.css("overflow", "auto"); } - // this.$widget.on('shown.bs.collapse', () => this.renderBody()); - // this.$widget.on('shown.bs.collapse', () => this.ctx.stateChanged()); - // this.$widget.on('hidden.bs.collapse', () => this.ctx.stateChanged()); - this.$title = this.$widget.find('.widget-title'); this.$title.text(this.getWidgetTitle()); @@ -91,31 +81,11 @@ class StandardWidget extends TabAwareWidget { /** for overriding */ async doRenderBody() {} - async isEnabled() { - const label = await this.ctx.note.getLabelValue(this.widgetName); - - if (label === 'enabled') { - return true; - } else if (label === 'disabled') { - return false; - } - else { - return this.widgetOptions.enabled; - } - } - isExpanded() { return this.$bodyWrapper.hasClass("show"); } - getWidgetState() { - return { - name: this.widgetName, - expanded: this.isExpanded() - }; - } - cleanup() {} } -export default StandardWidget; \ No newline at end of file +export default CollapsibleWidget; \ No newline at end of file diff --git a/src/public/javascripts/widgets/component.js b/src/public/javascripts/widgets/component.js index 66db2fb55..67931cccb 100644 --- a/src/public/javascripts/widgets/component.js +++ b/src/public/javascripts/widgets/component.js @@ -3,7 +3,7 @@ import utils from '../services/utils.js'; export default class Component { /** @param {AppContext} appContext */ constructor(appContext) { - this.componentId = `comp-${this.constructor.name}-` + utils.randomString(10); + this.componentId = `comp-${this.constructor.name}-` + utils.randomString(6); this.appContext = appContext; /** @type Component[] */ this.children = []; @@ -13,8 +13,6 @@ export default class Component { async eventReceived(name, data, sync = false) { await this.initialized; -// console.log(`Received ${name} to ${this.componentId}`); - const fun = this[name + 'Listener']; let propagateToChildren = true; diff --git a/src/public/javascripts/widgets/edited_notes.js b/src/public/javascripts/widgets/edited_notes.js index 09ec0f5e4..837b50558 100644 --- a/src/public/javascripts/widgets/edited_notes.js +++ b/src/public/javascripts/widgets/edited_notes.js @@ -1,9 +1,9 @@ -import StandardWidget from "./standard_widget.js"; +import CollapsibleWidget from "./standard_widget.js"; import linkService from "../services/link.js"; import server from "../services/server.js"; import treeCache from "../services/tree_cache.js"; -class EditedNotesWidget extends StandardWidget { +class EditedNotesWidget extends CollapsibleWidget { getWidgetTitle() { return "Edited notes on this day"; } getHelp() { diff --git a/src/public/javascripts/widgets/link_map.js b/src/public/javascripts/widgets/link_map.js index a003018c3..debeab82c 100644 --- a/src/public/javascripts/widgets/link_map.js +++ b/src/public/javascripts/widgets/link_map.js @@ -1,4 +1,4 @@ -import StandardWidget from "./standard_widget.js"; +import CollapsibleWidget from "./standard_widget.js"; let linkMapContainerIdCtr = 1; @@ -8,7 +8,7 @@ const TPL = ` `; -class LinkMapWidget extends StandardWidget { +class LinkMapWidget extends CollapsibleWidget { getWidgetTitle() { return "Link map"; } getHelp() { diff --git a/src/public/javascripts/widgets/note_info.js b/src/public/javascripts/widgets/note_info.js index 7edee6064..ce3fd8a91 100644 --- a/src/public/javascripts/widgets/note_info.js +++ b/src/public/javascripts/widgets/note_info.js @@ -1,4 +1,4 @@ -import StandardWidget from "./standard_widget.js"; +import CollapsibleWidget from "./standard_widget.js"; const TPL = ` @@ -35,34 +35,34 @@ const TPL = `
`; -class NoteInfoWidget extends StandardWidget { +class NoteInfoWidget extends CollapsibleWidget { getWidgetTitle() { return "Note info"; } doRenderBody() { this.$body.html(TPL); + + this.$noteId = this.$body.find(".note-info-note-id"); + this.$dateCreated = this.$body.find(".note-info-date-created"); + this.$dateModified = this.$body.find(".note-info-date-modified"); + this.$type = this.$body.find(".note-info-type"); + this.$mime = this.$body.find(".note-info-mime"); } async refreshWithNote(note) { - const $noteId = this.$body.find(".note-info-note-id"); - const $dateCreated = this.$body.find(".note-info-date-created"); - const $dateModified = this.$body.find(".note-info-date-modified"); - const $type = this.$body.find(".note-info-type"); - const $mime = this.$body.find(".note-info-mime"); - const noteComplement = await this.tabContext.getNoteComplement(); - $noteId.text(note.noteId); - $dateCreated + this.$noteId.text(note.noteId); + this.$dateCreated .text(noteComplement.dateCreated) .attr("title", noteComplement.dateCreated); - $dateModified + this.$dateModified .text(noteComplement.dateModified) .attr("title", noteComplement.dateCreated); - $type.text(note.type); + this.$type.text(note.type); - $mime + this.$mime .text(note.mime) .attr("title", note.mime); } diff --git a/src/public/javascripts/widgets/note_revisions.js b/src/public/javascripts/widgets/note_revisions.js index d3159ecfe..a7a5f0c30 100644 --- a/src/public/javascripts/widgets/note_revisions.js +++ b/src/public/javascripts/widgets/note_revisions.js @@ -1,12 +1,12 @@ import server from "../services/server.js"; -import StandardWidget from "./standard_widget.js"; +import CollapsibleWidget from "./standard_widget.js"; const TPL = ` `; -class NoteRevisionsWidget extends StandardWidget { +class NoteRevisionsWidget extends CollapsibleWidget { getWidgetTitle() { return "Note revisions"; } getHelp() { diff --git a/src/public/javascripts/widgets/similar_notes.js b/src/public/javascripts/widgets/similar_notes.js index 73b191049..17334ddfd 100644 --- a/src/public/javascripts/widgets/similar_notes.js +++ b/src/public/javascripts/widgets/similar_notes.js @@ -1,9 +1,9 @@ -import StandardWidget from "./standard_widget.js"; +import CollapsibleWidget from "./standard_widget.js"; import linkService from "../services/link.js"; import server from "../services/server.js"; import treeCache from "../services/tree_cache.js"; -class SimilarNotesWidget extends StandardWidget { +class SimilarNotesWidget extends CollapsibleWidget { getWidgetTitle() { return "Similar notes"; } getHelp() { diff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.js index a064958b8..0dd5f0139 100644 --- a/src/public/javascripts/widgets/tab_aware_widget.js +++ b/src/public/javascripts/widgets/tab_aware_widget.js @@ -28,8 +28,9 @@ export default class TabAwareWidget extends BasicWidget { return this.tabContext && this.tabContext.notePath; } - tabNoteSwitchedListener({tabId}) { - if (this.isTab(tabId)) { + tabNoteSwitchedListener({tabId, notePath}) { + // if notePath does not match then the tabContext has been switched to another note in the mean time + if (this.isTab(tabId) && this.notePath === notePath) { this.noteSwitched(); } } diff --git a/src/public/javascripts/widgets/what_links_here.js b/src/public/javascripts/widgets/what_links_here.js index 8f9a0a73c..169d69cb2 100644 --- a/src/public/javascripts/widgets/what_links_here.js +++ b/src/public/javascripts/widgets/what_links_here.js @@ -1,7 +1,7 @@ -import StandardWidget from "./standard_widget.js"; +import CollapsibleWidget from "./standard_widget.js"; import linkService from "../services/link.js"; -class WhatLinksHereWidget extends StandardWidget { +class WhatLinksHereWidget extends CollapsibleWidget { getWidgetTitle() { return "What links here"; } getMaxHeight() { return "200px"; }