state is now applied to sidebar widgets

This commit is contained in:
zadam 2019-08-16 21:29:44 +02:00
parent aa981d3cd4
commit f259c60b54
11 changed files with 38 additions and 38 deletions

34
package-lock.json generated
View File

@ -1960,9 +1960,9 @@
}
},
"cli-spinners": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.1.0.tgz",
"integrity": "sha512-8B00fJOEh1HPrx4fo5eW16XmE1PcL1tGpGrxy63CXGP9nHdPBN63X75hA1zhvQuhVztJWLqV58Roj2qlNM7cAA==",
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.2.0.tgz",
"integrity": "sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==",
"dev": true
},
"cli-table3": {
@ -4017,20 +4017,20 @@
}
},
"electron-rebuild": {
"version": "1.8.5",
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.8.5.tgz",
"integrity": "sha512-gDwRA3utfiPnFwBZ1z8M4SEMwsdsy6Bg4VGO2ohelMOIO0vxiCrDQ/FVdLk3h2g7fLb06QFUsQU+86jiTSmZxw==",
"version": "1.8.6",
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.8.6.tgz",
"integrity": "sha512-4BAPcNG0XP6stByqvFXggrjmf/C47P2L6HFFrWdR2ako1VLiTDIeZAOmU4WEBuWdaXYNqstleszVmcNHdRDojA==",
"dev": true,
"requires": {
"colors": "^1.3.3",
"debug": "^4.1.1",
"detect-libc": "^1.0.3",
"fs-extra": "^7.0.1",
"node-abi": "^2.8.0",
"node-gyp": "^4.0.0",
"node-abi": "^2.9.0",
"node-gyp": "^5.0.1",
"ora": "^3.4.0",
"spawn-rx": "^3.0.0",
"yargs": "^13.2.2"
"yargs": "^13.2.4"
},
"dependencies": {
"colors": {
@ -9135,17 +9135,17 @@
}
},
"node-gyp": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-4.0.0.tgz",
"integrity": "sha512-2XiryJ8sICNo6ej8d0idXDEMKfVfFK7kekGCtJAuelGsYHQxhj13KTf95swTCN2dZ/4lTfZ84Fu31jqJEEgjWA==",
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-5.0.3.tgz",
"integrity": "sha512-z/JdtkFGUm0QaQUusvloyYuGDub3nUbOo5de1Fz57cM++osBTvQatBUSTlF1k/w8vFHPxxXW6zxGvkxXSpaBkQ==",
"dev": true,
"requires": {
"env-paths": "^1.0.0",
"glob": "^7.0.3",
"graceful-fs": "^4.1.2",
"mkdirp": "^0.5.0",
"nopt": "2 || 3",
"npmlog": "0 || 1 || 2 || 3 || 4",
"osenv": "0",
"request": "^2.87.0",
"rimraf": "2",
"semver": "~5.3.0",
@ -9173,7 +9173,7 @@
},
"semver": {
"version": "5.3.0",
"resolved": "http://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
"integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=",
"dev": true
}
@ -13405,9 +13405,9 @@
}
},
"ws": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.1.1.tgz",
"integrity": "sha512-o41D/WmDeca0BqYhsr3nJzQyg9NF5X8l/UdnFNux9cS3lwB+swm8qGWX5rn+aD6xfBU3rGmtHij7g7x6LxFU3A==",
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.1.2.tgz",
"integrity": "sha512-gftXq3XI81cJCgkUiAVixA0raD9IVmXqsylCrjRygw4+UOOGzPoxnQ6r/CnVL9i+mDncJo94tSkyrtuuQVBmrg==",
"requires": {
"async-limiter": "^1.0.0"
}

View File

@ -73,7 +73,7 @@
"tar-stream": "2.1.0",
"turndown": "5.0.3",
"unescape": "1.0.1",
"ws": "7.1.1",
"ws": "7.1.2",
"xml2js": "0.4.19"
},
"devDependencies": {
@ -83,7 +83,7 @@
"electron-compile": "6.4.4",
"electron-installer-debian": "2.0.0",
"electron-packager": "14.0.4",
"electron-rebuild": "1.8.5",
"electron-rebuild": "1.8.6",
"lorem-ipsum": "2.0.3",
"xo": "0.24.0"
},

View File

@ -133,7 +133,6 @@ async function switchToTab(tabId, notePath) {
if (!tabContext) {
await loadNoteDetail(notePath, {
newTab: true,
tabId: tabId,
activate: true
});
} else {
@ -262,7 +261,7 @@ async function loadNoteDetail(origNotePath, options = {}) {
if (!getActiveTabContext() || newTab) {
// if it's a new tab explicitly by user then it's in background
ctx = new TabContext(tabRow, options.tabId);
ctx = new TabContext(tabRow, options.state);
tabContexts.push(ctx);
}
else {

View File

@ -3,14 +3,13 @@ import LinkMapWidget from "../widgets/link_map.js";
import NoteRevisionsWidget from "../widgets/note_revisions.js";
import AttributesWidget from "../widgets/attributes.js";
let widgetIdCtr = 1;
class Sidebar {
/**
* @param {TabContext} ctx
*/
constructor(ctx) {
constructor(ctx, state) {
this.ctx = ctx;
this.state = state;
this.widgets = [];
this.rendered = false;
this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar");
@ -51,7 +50,9 @@ class Sidebar {
const widgetClasses = [AttributesWidget, LinkMapWidget, NoteRevisionsWidget, NoteInfoWidget];
for (const widgetClass of widgetClasses) {
const widget = new widgetClass(this.ctx);
const state = (this.state.widgets || []).find(s => s.name === widgetClass.name);
const widget = new widgetClass(this.ctx, state);
this.widgets.push(widget);
widget.renderBody(); // let it run in parallel

View File

@ -37,10 +37,11 @@ const componentClasses = {
class TabContext {
/**
* @param {TabRow} tabRow
* @param {object} state
*/
constructor(tabRow, tabId = null) {
constructor(tabRow, state = {}) {
this.tabRow = tabRow;
this.tabId = tabId || utils.randomString(4);
this.tabId = state.tabId || utils.randomString(4);
this.$tab = $(this.tabRow.addTab(this.tabId));
this.$tabContent = $(".note-tab-content-template").clone();
@ -62,7 +63,7 @@ class TabContext {
this.attributes = new Attributes(this);
if (utils.isDesktop()) {
this.sidebar = new Sidebar(this);
this.sidebar = new Sidebar(this, state.sidebar);
this.noteType = new NoteTypeContext(this);
}

View File

@ -395,7 +395,7 @@ async function treeInitialized() {
for (const tab of filteredTabs) {
await noteDetailService.loadNoteDetail(tab.notePath, {
tabId: tab.tabId,
state: tab,
newTab: true,
activate: tab.active
});

View File

@ -6,7 +6,7 @@ import StandardWidget from "./standard_widget.js";
class AttributesWidget extends StandardWidget {
constructor(ctx, state) {
super(ctx, state, 'attributes');
super(ctx, state);
this.$title.text("Attributes");

View File

@ -29,7 +29,7 @@ class LinkMapWidget extends StandardWidget {
* @param {object} state
*/
constructor(ctx, state) {
super(ctx, state,'link-map');
super(ctx, state);
this.$title.text("Link map");

View File

@ -31,7 +31,7 @@ class NoteInfoWidget extends StandardWidget {
* @param {object} state
*/
constructor(ctx, state) {
super(ctx, state, 'note-info');
super(ctx, state);
this.$title.text("Note info");
}

View File

@ -12,7 +12,7 @@ class NoteRevisionsWidget extends StandardWidget {
* @param {object} state
*/
constructor(ctx, state) {
super(ctx, state, 'note-revisions');
super(ctx, state);
this.$title.text("Note revisions");
}

View File

@ -18,13 +18,12 @@ class StandardWidget {
/**
* @param {TabContext} ctx
* @param {object} state
* @param {string} widgetName
*/
constructor(ctx, state, widgetName) {
constructor(ctx, state) {
this.ctx = ctx;
this.widgetName = widgetName;
this.widgetName = this.constructor.name;
const widgetId = `tab-${ctx.tabId}-widget-${widgetName}`;
const widgetId = `tab-${ctx.tabId}-widget-${this.widgetName}`;
this.$widget = $(WIDGET_TPL);
this.$widget.find('[data-target]').attr('data-target', "#" + widgetId);
@ -33,7 +32,7 @@ class StandardWidget {
this.$bodyWrapper.attr('id', widgetId);
if (state && state.visible) {
this.$bodyWrapper.addClass("show");
this.$bodyWrapper.collapse("show");
}
this.$body = this.$bodyWrapper.find('.card-body');