mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
options now allow selecting user theme
This commit is contained in:
parent
2c1580ea65
commit
67630b1a22
@ -5,6 +5,7 @@ import server from '../services/server.js';
|
|||||||
import infoService from "../services/info.js";
|
import infoService from "../services/info.js";
|
||||||
import zoomService from "../services/zoom.js";
|
import zoomService from "../services/zoom.js";
|
||||||
import utils from "../services/utils.js";
|
import utils from "../services/utils.js";
|
||||||
|
import cssLoader from "../services/css_loader.js";
|
||||||
|
|
||||||
const $dialog = $("#options-dialog");
|
const $dialog = $("#options-dialog");
|
||||||
|
|
||||||
@ -50,7 +51,22 @@ addTabHandler((function() {
|
|||||||
const $body = $("body");
|
const $body = $("body");
|
||||||
const $container = $("#container");
|
const $container = $("#container");
|
||||||
|
|
||||||
function optionsLoaded(options) {
|
async function optionsLoaded(options) {
|
||||||
|
const themes = [
|
||||||
|
{ val: 'white', title: 'White' },
|
||||||
|
{ val: 'dark', title: 'Dark' },
|
||||||
|
{ val: 'black', title: 'Black' }
|
||||||
|
].concat(await server.get('options/user-themes'));
|
||||||
|
|
||||||
|
$themeSelect.empty();
|
||||||
|
|
||||||
|
for (const theme of themes) {
|
||||||
|
$themeSelect.append($("<option>")
|
||||||
|
.attr("value", theme.val)
|
||||||
|
.attr("data-note-id", theme.noteId)
|
||||||
|
.html(theme.title));
|
||||||
|
}
|
||||||
|
|
||||||
$themeSelect.val(options.theme);
|
$themeSelect.val(options.theme);
|
||||||
|
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
@ -77,6 +93,14 @@ addTabHandler((function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const noteId = $(this).find(":selected").attr("data-note-id");
|
||||||
|
|
||||||
|
if (noteId) {
|
||||||
|
// make sure the CSS is loaded
|
||||||
|
// if the CSS has been loaded and then updated then the changes won't take effect though
|
||||||
|
cssLoader.requireCss(`/api/notes/${noteId}/download`);
|
||||||
|
}
|
||||||
|
|
||||||
$body.addClass("theme-" + newTheme);
|
$body.addClass("theme-" + newTheme);
|
||||||
|
|
||||||
server.put('options/theme/' + newTheme);
|
server.put('options/theme/' + newTheme);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const sql = require('../../services/sql');
|
|
||||||
const optionService = require('../../services/options');
|
const optionService = require('../../services/options');
|
||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
|
const attributes = require('../../services/attributes');
|
||||||
|
|
||||||
// options allowed to be updated directly in options dialog
|
// options allowed to be updated directly in options dialog
|
||||||
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval',
|
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval',
|
||||||
@ -42,8 +42,20 @@ async function update(name, value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getUserThemes() {
|
||||||
|
return (await attributes.getNotesWithLabel('appTheme'))
|
||||||
|
.map(note => {
|
||||||
|
return {
|
||||||
|
val: note.title,
|
||||||
|
title: note.title,
|
||||||
|
noteId: note.noteId
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getOptions,
|
getOptions,
|
||||||
updateOption,
|
updateOption,
|
||||||
updateOptions
|
updateOptions,
|
||||||
|
getUserThemes
|
||||||
};
|
};
|
@ -153,6 +153,7 @@ function register(app) {
|
|||||||
apiRoute(GET, '/api/options', optionsApiRoute.getOptions);
|
apiRoute(GET, '/api/options', optionsApiRoute.getOptions);
|
||||||
apiRoute(PUT, '/api/options/:name/:value*', optionsApiRoute.updateOption);
|
apiRoute(PUT, '/api/options/:name/:value*', optionsApiRoute.updateOption);
|
||||||
apiRoute(PUT, '/api/options', optionsApiRoute.updateOptions);
|
apiRoute(PUT, '/api/options', optionsApiRoute.updateOptions);
|
||||||
|
apiRoute(GET, '/api/options/user-themes', optionsApiRoute.getUserThemes);
|
||||||
|
|
||||||
apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword);
|
apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword);
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ const BUILTIN_ATTRIBUTES = [
|
|||||||
{ type: 'label', name: 'manualTransactionHandling' },
|
{ type: 'label', name: 'manualTransactionHandling' },
|
||||||
{ type: 'label', name: 'disableInclusion' },
|
{ type: 'label', name: 'disableInclusion' },
|
||||||
{ type: 'label', name: 'appCss' },
|
{ type: 'label', name: 'appCss' },
|
||||||
|
{ type: 'label', name: 'appTheme' },
|
||||||
{ type: 'label', name: 'hideChildrenOverview' },
|
{ type: 'label', name: 'hideChildrenOverview' },
|
||||||
{ type: 'label', name: 'hidePromotedAttributes' },
|
{ type: 'label', name: 'hidePromotedAttributes' },
|
||||||
{ type: 'label', name: 'readOnly' },
|
{ type: 'label', name: 'readOnly' },
|
||||||
|
@ -40,11 +40,7 @@
|
|||||||
<form>
|
<form>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="theme-select">Theme</label>
|
<label for="theme-select">Theme</label>
|
||||||
<select class="form-control" id="theme-select">
|
<select class="form-control" id="theme-select"></select>
|
||||||
<option value="white">White</option>
|
|
||||||
<option value="dark">Dark</option>
|
|
||||||
<option value="black">Black</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user