diff --git a/db/migrations/0139__show_sidebar_in_new_tab.sql b/db/migrations/0139__show_sidebar_in_new_tab.sql new file mode 100644 index 000000000..83a878384 --- /dev/null +++ b/db/migrations/0139__show_sidebar_in_new_tab.sql @@ -0,0 +1,2 @@ +INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) +VALUES ('showSidebarInNewTab', '1', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); \ No newline at end of file diff --git a/src/public/javascripts/dialogs/options.js b/src/public/javascripts/dialogs/options.js index d50c0746e..323ebfb0f 100644 --- a/src/public/javascripts/dialogs/options.js +++ b/src/public/javascripts/dialogs/options.js @@ -354,10 +354,18 @@ addTabHandler((async function () { addTabHandler((function() { const $sidebarMinWidth = $("#sidebar-min-width"); const $sidebarWidthPercent = $("#sidebar-width-percent"); + const $showSidebarInNewTab = $("#show-sidebar-in-new-tab"); async function optionsLoaded(options) { $sidebarMinWidth.val(options.sidebarMinWidth); $sidebarWidthPercent.val(options.sidebarWidthPercent); + + if (parseInt(options.showSidebarInNewTab)) { + $showSidebarInNewTab.attr("checked", "checked"); + } + else { + $showSidebarInNewTab.removeAttr("checked"); + } } function resizeSidebar() { @@ -385,6 +393,14 @@ addTabHandler((function() { resizeSidebar(); }); + $showSidebarInNewTab.change(async function() { + const flag = $(this).is(":checked") ? 1 : 0; + + await server.put('options/showSidebarInNewTab/' + flag); + + optionsInit.loadOptions(); + }); + return { optionsLoaded }; diff --git a/src/public/javascripts/services/options_init.js b/src/public/javascripts/services/options_init.js index a3010e449..cea79f6f6 100644 --- a/src/public/javascripts/services/options_init.js +++ b/src/public/javascripts/services/options_init.js @@ -26,9 +26,16 @@ function addLoadListener(listener) { optionsReady.then(listener); } +async function getOption(name) { + const options = await optionsReady; + + return options[name]; +} + export default { // use addLoadListener() which will be called also on refreshes optionsReady, addLoadListener, - loadOptions + loadOptions, + getOption } \ No newline at end of file diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index 1afeb1361..ae431dee3 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -17,6 +17,7 @@ import noteDetailRender from "./note_detail_render.js"; import noteDetailRelationMap from "./note_detail_relation_map.js"; import noteDetailProtectedSession from "./note_detail_protected_session.js"; import protectedSessionService from "./protected_session.js"; +import optionsInitService from "./options_init.js"; import linkService from "./link.js"; import Sidebar from "./sidebar.js"; @@ -34,6 +35,12 @@ const componentClasses = { 'protected-session': noteDetailProtectedSession }; +let showSidebarInNewTab = true; + +optionsInitService.addLoadListener(options => { + showSidebarInNewTab = options.showSidebarInNewTab === '1'; +}); + class TabContext { /** * @param {TabRow} tabRow @@ -64,7 +71,11 @@ class TabContext { this.attributes = new Attributes(this); if (utils.isDesktop()) { - this.sidebar = new Sidebar(this, state.sidebar); + const sidebarState = state.sidebar || { + visible: showSidebarInNewTab + }; + + this.sidebar = new Sidebar(this, sidebarState); this.noteType = new NoteTypeContext(this); } diff --git a/src/routes/api/options.js b/src/routes/api/options.js index 32dc59cab..e2e000ceb 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -17,6 +17,7 @@ const ALLOWED_OPTIONS = [ 'leftPaneWidthPercent', 'sidebarMinWidth', 'sidebarWidthPercent', + 'showSidebarInNewTab', 'hoistedNoteId', 'mainFontSize', 'treeFontSize', diff --git a/src/services/app_info.js b/src/services/app_info.js index 7c6bd436c..8b2e45058 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -4,7 +4,7 @@ const build = require('./build'); const packageJson = require('../../package'); const {TRILIUM_DATA_DIR} = require('./data_dir'); -const APP_DB_VERSION = 138; +const APP_DB_VERSION = 139; const SYNC_VERSION = 10; const CLIPPER_PROTOCOL_VERSION = "1.0"; diff --git a/src/views/dialogs/options/sidebar.ejs b/src/views/dialogs/options/sidebar.ejs index e2f727507..4fcd15dd0 100644 --- a/src/views/dialogs/options/sidebar.ejs +++ b/src/views/dialogs/options/sidebar.ejs @@ -1,4 +1,13 @@
+

Show sidebar in new tab

+ +
+ + +
+ +
+

Sidebar sizing