option to configure if sidebar should be enabled in new tab

This commit is contained in:
zadam 2019-08-19 23:29:42 +02:00
parent 9888850c22
commit b818f020a7
7 changed files with 49 additions and 3 deletions

View File

@ -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);

View File

@ -354,10 +354,18 @@ addTabHandler((async function () {
addTabHandler((function() { addTabHandler((function() {
const $sidebarMinWidth = $("#sidebar-min-width"); const $sidebarMinWidth = $("#sidebar-min-width");
const $sidebarWidthPercent = $("#sidebar-width-percent"); const $sidebarWidthPercent = $("#sidebar-width-percent");
const $showSidebarInNewTab = $("#show-sidebar-in-new-tab");
async function optionsLoaded(options) { async function optionsLoaded(options) {
$sidebarMinWidth.val(options.sidebarMinWidth); $sidebarMinWidth.val(options.sidebarMinWidth);
$sidebarWidthPercent.val(options.sidebarWidthPercent); $sidebarWidthPercent.val(options.sidebarWidthPercent);
if (parseInt(options.showSidebarInNewTab)) {
$showSidebarInNewTab.attr("checked", "checked");
}
else {
$showSidebarInNewTab.removeAttr("checked");
}
} }
function resizeSidebar() { function resizeSidebar() {
@ -385,6 +393,14 @@ addTabHandler((function() {
resizeSidebar(); resizeSidebar();
}); });
$showSidebarInNewTab.change(async function() {
const flag = $(this).is(":checked") ? 1 : 0;
await server.put('options/showSidebarInNewTab/' + flag);
optionsInit.loadOptions();
});
return { return {
optionsLoaded optionsLoaded
}; };

View File

@ -26,9 +26,16 @@ function addLoadListener(listener) {
optionsReady.then(listener); optionsReady.then(listener);
} }
async function getOption(name) {
const options = await optionsReady;
return options[name];
}
export default { export default {
// use addLoadListener() which will be called also on refreshes // use addLoadListener() which will be called also on refreshes
optionsReady, optionsReady,
addLoadListener, addLoadListener,
loadOptions loadOptions,
getOption
} }

View File

@ -17,6 +17,7 @@ import noteDetailRender from "./note_detail_render.js";
import noteDetailRelationMap from "./note_detail_relation_map.js"; import noteDetailRelationMap from "./note_detail_relation_map.js";
import noteDetailProtectedSession from "./note_detail_protected_session.js"; import noteDetailProtectedSession from "./note_detail_protected_session.js";
import protectedSessionService from "./protected_session.js"; import protectedSessionService from "./protected_session.js";
import optionsInitService from "./options_init.js";
import linkService from "./link.js"; import linkService from "./link.js";
import Sidebar from "./sidebar.js"; import Sidebar from "./sidebar.js";
@ -34,6 +35,12 @@ const componentClasses = {
'protected-session': noteDetailProtectedSession 'protected-session': noteDetailProtectedSession
}; };
let showSidebarInNewTab = true;
optionsInitService.addLoadListener(options => {
showSidebarInNewTab = options.showSidebarInNewTab === '1';
});
class TabContext { class TabContext {
/** /**
* @param {TabRow} tabRow * @param {TabRow} tabRow
@ -64,7 +71,11 @@ class TabContext {
this.attributes = new Attributes(this); this.attributes = new Attributes(this);
if (utils.isDesktop()) { 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); this.noteType = new NoteTypeContext(this);
} }

View File

@ -17,6 +17,7 @@ const ALLOWED_OPTIONS = [
'leftPaneWidthPercent', 'leftPaneWidthPercent',
'sidebarMinWidth', 'sidebarMinWidth',
'sidebarWidthPercent', 'sidebarWidthPercent',
'showSidebarInNewTab',
'hoistedNoteId', 'hoistedNoteId',
'mainFontSize', 'mainFontSize',
'treeFontSize', 'treeFontSize',

View File

@ -4,7 +4,7 @@ const build = require('./build');
const packageJson = require('../../package'); const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir'); const {TRILIUM_DATA_DIR} = require('./data_dir');
const APP_DB_VERSION = 138; const APP_DB_VERSION = 139;
const SYNC_VERSION = 10; const SYNC_VERSION = 10;
const CLIPPER_PROTOCOL_VERSION = "1.0"; const CLIPPER_PROTOCOL_VERSION = "1.0";

View File

@ -1,4 +1,13 @@
<div id="options-sidebar" class="tab-pane"> <div id="options-sidebar" class="tab-pane">
<h3>Show sidebar in new tab</h3>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="show-sidebar-in-new-tab">
<label class="form-check-label" for="show-sidebar-in-new-tab">Show sidebar in new tab</label>
</div>
<br>
<h3>Sidebar sizing</h3> <h3>Sidebar sizing</h3>
<div class="form-group row"> <div class="form-group row">