Skip to content

Commit 195c6a4

Browse files
committed
backend log improvements
1 parent 8c01a77 commit 195c6a4

11 files changed

+168
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// the history was previously not exposed and the fact they were not cleaned up is rather a side-effect than an intention
2+
3+
module.exports = () => {
4+
const cls = require("../../src/services/cls");
5+
const beccaLoader = require("../../src/becca/becca_loader");
6+
const becca = require("../../src/becca/becca");
7+
8+
cls.init(() => {
9+
beccaLoader.load();
10+
11+
// deleting just branches because they might be cloned (and therefore saved) also outside of the hidden subtree
12+
13+
const searchRoot = becca.getNote('search');
14+
15+
for (const searchBranch of searchRoot.getChildBranches()) {
16+
const searchNote = searchBranch.getNote();
17+
18+
if (searchNote.type === 'search') {
19+
searchBranch.deleteBranch('0206__delete_search_and_sql_console_history');
20+
}
21+
}
22+
23+
const sqlConsoleRoot = becca.getNote('sqlConsole');
24+
25+
for (const sqlConsoleBranch of sqlConsoleRoot.getChildBranches()) {
26+
const sqlConsoleNote = sqlConsoleBranch.getNote();
27+
28+
if (sqlConsoleNote.type === 'code' && sqlConsoleNote.mime === 'text/x-sqlite;schema=trilium') {
29+
sqlConsoleBranch.deleteBranch('0206__delete_search_and_sql_console_history');
30+
}
31+
}
32+
});
33+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UPDATE notes SET title = 'SQL Console History' WHERE noteId = 'sqlConsole';
2+
UPDATE notes SET title = 'Search History' WHERE noteId = 'search';

package-lock.json

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/components/root_command_executor.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,35 @@ export default class RootCommandExecutor extends Component {
7272
options.toggle('leftPaneVisible');
7373
}
7474

75+
async showBackendLogCommand() {
76+
await appContext.tabManager.openContextWithNote('backendLog', true);
77+
}
78+
7579
async showLaunchBarSubtreeCommand() {
76-
await appContext.tabManager.openContextWithNote('lbRoot', true, null, 'lbRoot');
80+
await this.showAndHoistSubtree('lbRoot');
7781
}
7882

7983
async showShareSubtreeCommand() {
80-
await appContext.tabManager.openContextWithNote('share', true, null, 'share');
84+
await this.showAndHoistSubtree('share');
8185
}
8286

8387
async showHiddenSubtreeCommand() {
84-
await appContext.tabManager.openContextWithNote('hidden', true, null, 'hidden');
88+
await this.showAndHoistSubtree('hidden');
8589
}
8690

8791
async showOptionsCommand() {
88-
await appContext.tabManager.openContextWithNote('options', true, null, 'options')
92+
await this.showAndHoistSubtree('options');
93+
}
94+
95+
async showSQLConsoleHistoryCommand() {
96+
await this.showAndHoistSubtree('sqlConsole');
97+
}
98+
99+
async showSearchHistoryCommand() {
100+
await this.showAndHoistSubtree('search');
101+
}
102+
103+
async showAndHoistSubtree(subtreeNoteId) {
104+
await appContext.tabManager.openContextWithNote(subtreeNoteId, true, null, subtreeNoteId);
89105
}
90106
}

src/public/app/widgets/buttons/global_menu.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ const TPL = `
102102
103103
<li class="dropdown-item" data-trigger-command="openNewWindow">
104104
<span class="bx bx-window-open"></span>
105-
Open new window
105+
Open New Window
106106
<kbd data-command="openNewWindow"></kbd>
107107
</li>
108108
109109
<li class="dropdown-item switch-to-mobile-version-button" data-trigger-command="switchToMobileVersion">
110110
<span class="bx bx-mobile"></span>
111-
Switch to mobile version
111+
Switch to Mobile Version
112112
</li>
113113
114114
<li class="dropdown-item switch-to-desktop-version-button" data-trigger-command="switchToDesktopVersion">
115115
<span class="bx bx-desktop"></span>
116-
Switch to desktop version
116+
Switch to Desktop Version
117117
</li>
118118
119119
<span class="zoom-container dropdown-item">
@@ -123,26 +123,26 @@ const TPL = `
123123
</div>
124124
125125
<div class="zoom-buttons">
126-
<a data-trigger-command="toggleFullscreen" title="Toggle fullscreen" class="bx bx-expand-alt"></a>
126+
<a data-trigger-command="toggleFullscreen" title="Toggle Fullscreen" class="bx bx-expand-alt"></a>
127127
128128
&nbsp;
129129
130-
<a data-trigger-command="zoomOut" title="Zoom out" class="bx bx-minus"></a>
130+
<a data-trigger-command="zoomOut" title="Zoom Out" class="bx bx-minus"></a>
131131
132132
<span class="zoom-state"></span>
133133
134-
<a data-trigger-command="zoomIn" title="Zoom in" class="bx bx-plus"></a>
134+
<a data-trigger-command="zoomIn" title="Zoom In" class="bx bx-plus"></a>
135135
</div>
136136
</span>
137137
138138
<li class="dropdown-item" data-trigger-command="showLaunchBarSubtree">
139139
<span class="bx bx-sidebar"></span>
140-
Configure launchbar
140+
Configure Launchbar
141141
</li>
142142
143143
<li class="dropdown-item" data-trigger-command="showShareSubtree">
144144
<span class="bx bx-share-alt"></span>
145-
Show share subtree
145+
Show Shared Notes Subtree
146146
</li>
147147
148148
<li class="dropdown-item dropdown-submenu">
@@ -153,7 +153,7 @@ const TPL = `
153153
154154
<ul class="dropdown-menu">
155155
<li class="dropdown-item open-dev-tools-button" data-trigger-command="openDevTools">
156-
<span class="bx bx-terminal"></span>
156+
<span class="bx bx-bug-alt"></span>
157157
Open Dev Tools
158158
<kbd data-command="openDevTools"></kbd>
159159
</li>
@@ -163,23 +163,33 @@ const TPL = `
163163
Open SQL Console
164164
<kbd data-command="showSQLConsole"></kbd>
165165
</li>
166+
167+
<li class="dropdown-item" data-trigger-command="showSQLConsoleHistory">
168+
<span class="bx bx-empty"></span>
169+
Open SQL Console History
170+
</li>
171+
172+
<li class="dropdown-item" data-trigger-command="showSearchHistory">
173+
<span class="bx bx-empty"></span>
174+
Open Search History
175+
</li>
166176
167177
<li class="dropdown-item" data-trigger-command="showBackendLog">
168178
<span class="bx bx-empty"></span>
169-
Show backend log
179+
Show Backend Log
170180
<kbd data-command="showBackendLog"></kbd>
171181
</li>
172182
173183
<li class="dropdown-item" data-trigger-command="reloadFrontendApp"
174184
title="Reload can help with some visual glitches without restarting the whole app.">
175185
<span class="bx bx-empty"></span>
176-
Reload frontend
186+
Reload Frontend
177187
<kbd data-command="reloadFrontendApp"></kbd>
178188
</li>
179189
180190
<li class="dropdown-item" data-trigger-command="showHiddenSubtree">
181191
<span class="bx bx-empty"></span>
182-
Show hidden subtree
192+
Show Hidden Subtree
183193
</li>
184194
</ul>
185195
</li>

src/public/app/widgets/dialogs/backend_log.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const TPL = `
1212
<span aria-hidden="true">&times;</span>
1313
</button>
1414
</div>
15-
<div class="modal-body">
15+
e<div class="modal-body">
1616
<textarea class="backend-log-textarea" readonly="readonly" style="min-height: 600px; width: 100%;"></textarea>
1717
</div>
1818
<div class="modal-footer">
@@ -44,10 +44,4 @@ export default class BackendLogDialog extends BasicWidget {
4444

4545
this.scrollToBottom();
4646
}
47-
48-
async showBackendLogEvent() {
49-
utils.openDialog(this.$widget);
50-
51-
this.load();
52-
}
5347
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import NoteContextAwareWidget from "../../note_context_aware_widget.js";
2+
import server from "../../../services/server.js";
3+
4+
const TPL = `<div style="height: 100%; display: flex; flex-direction: column;">
5+
<style>
6+
.backend-log-textarea {
7+
flex-grow: 1;
8+
width: 100%;
9+
border: none;
10+
}
11+
</style>
12+
13+
<textarea class="backend-log-textarea" readonly="readonly"></textarea>
14+
15+
<div style="display: flex; justify-content: space-around; margin-top: 10px;">
16+
<button class="refresh-backend-log-button btn btn-primary">Refresh</button>
17+
</div>
18+
</div>`;
19+
20+
export default class ContentLogWidget extends NoteContextAwareWidget {
21+
doRender() {
22+
this.$widget = $(TPL);
23+
this.$backendLogTextArea = this.$widget.find(".backend-log-textarea");
24+
this.$refreshBackendLog = this.$widget.find(".refresh-backend-log-button");
25+
26+
this.$refreshBackendLog.on('click', () => this.load());
27+
}
28+
29+
scrollToBottom() {
30+
this.$backendLogTextArea.scrollTop(this.$backendLogTextArea[0].scrollHeight);
31+
}
32+
33+
async refresh() {
34+
await this.load();
35+
}
36+
37+
async load() {
38+
const backendLog = await server.get('backend-log');
39+
40+
this.$backendLogTextArea.text(backendLog);
41+
42+
this.scrollToBottom();
43+
}
44+
}

src/public/app/widgets/type_widgets/content_widget.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import DatabaseIntegrityCheckOptions from "./options/advanced/database_integrity
2727
import ConsistencyChecksOptions from "./options/advanced/consistency_checks.js";
2828
import VacuumDatabaseOptions from "./options/advanced/vacuum_database.js";
2929
import DatabaseAnonymizationOptions from "./options/advanced/database_anonymization.js";
30+
import ContentLogWidget from "./content/backend_log.js";
3031

3132
const TPL = `<div class="note-detail-content-widget note-detail-printable">
3233
<style>
@@ -85,7 +86,8 @@ const CONTENT_WIDGETS = {
8586
DatabaseAnonymizationOptions,
8687
AdvancedSyncOptions,
8788
VacuumDatabaseOptions
88-
]
89+
],
90+
backendLog: [ ContentLogWidget ]
8991
};
9092

9193
export default class ContentWidgetTypeWidget extends TypeWidget {

src/services/app_info.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const build = require('./build');
44
const packageJson = require('../../package');
55
const {TRILIUM_DATA_DIR} = require('./data_dir');
66

7-
const APP_DB_VERSION = 205;
7+
const APP_DB_VERSION = 207;
88
const SYNC_VERSION = 28;
99
const CLIPPER_PROTOCOL_VERSION = "1.0";
1010

src/services/hidden_subtree.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const HIDDEN_SUBTREE_DEFINITION = {
2828
children: [
2929
{
3030
id: 'search',
31-
title: 'search',
31+
title: 'Search History',
3232
type: 'doc'
3333
},
3434
{
@@ -42,7 +42,7 @@ const HIDDEN_SUBTREE_DEFINITION = {
4242
},
4343
{
4444
id: 'sqlConsole',
45-
title: 'SQL Console',
45+
title: 'SQL Console History',
4646
type: 'doc',
4747
icon: 'bx-data'
4848
},
@@ -57,6 +57,15 @@ const HIDDEN_SUBTREE_DEFINITION = {
5757
title: 'Bulk action',
5858
type: 'doc',
5959
},
60+
{
61+
id: 'backendLog',
62+
title: 'Backend Log',
63+
type: 'contentWidget',
64+
icon: 'bx-terminal',
65+
attributes: [
66+
{ type: 'label', name: 'keepCurrentHoisting' }
67+
]
68+
},
6069
{
6170
// place for user scripts hidden stuff (scripts should not create notes directly under hidden root)
6271
id: 'userHidden',
@@ -158,8 +167,9 @@ const HIDDEN_SUBTREE_DEFINITION = {
158167
isExpanded: true,
159168
attributes: [ { type: 'label', name: 'docName', value: 'launchbar_intro' } ],
160169
children: [
161-
{ id: 'lbBackInHistory', title: 'Back in history', type: 'launcher', builtinWidget: 'backInHistoryButton', icon: 'bx bxs-left-arrow-square' },
162-
{ id: 'lbForwardInHistory', title: 'Forward in history', type: 'launcher', builtinWidget: 'forwardInHistoryButton', icon: 'bx bxs-right-arrow-square' },
170+
{ id: 'lbBackInHistory', title: 'Back in History', type: 'launcher', builtinWidget: 'backInHistoryButton', icon: 'bx bxs-left-arrow-square' },
171+
{ id: 'lbForwardInHistory', title: 'Forward in History', type: 'launcher', builtinWidget: 'forwardInHistoryButton', icon: 'bx bxs-right-arrow-square' },
172+
{ id: 'lbBackendLog', title: 'Backend Log', type: 'launcher', targetNoteId: 'backendLog', icon: 'bx bx-terminal' },
163173
]
164174
},
165175
{

src/services/special_notes.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const cls = require("./cls");
66
const dateUtils = require("./date_utils");
77
const log = require("./log");
88
const hiddenSubtreeService = require("./hidden_subtree");
9+
const searchService = require("./search/services/search.js");
10+
const SearchContext = require("./search/search_context.js");
911

1012
function getInboxNote(date) {
1113
const hoistedNote = getHoistedNote();
@@ -33,7 +35,7 @@ function getInboxNote(date) {
3335

3436
function createSqlConsole() {
3537
const {note} = noteService.createNewNote({
36-
parentNoteId: 'sqlConsole',
38+
parentNoteId: getMonthlyParentNoteId('sqlConsole'),
3739
title: 'SQL Console',
3840
content: "SELECT title, isDeleted, isProtected FROM notes WHERE noteId = ''\n\n\n\n",
3941
type: 'code',
@@ -68,7 +70,7 @@ function saveSqlConsole(sqlConsoleNoteId) {
6870

6971
function createSearchNote(searchString, ancestorNoteId) {
7072
const {note} = noteService.createNewNote({
71-
parentNoteId: 'search',
73+
parentNoteId: getMonthlyParentNoteId('search'),
7274
title: 'Search: ' + searchString,
7375
content: "",
7476
type: 'search',
@@ -115,6 +117,28 @@ function saveSearchNote(searchNoteId) {
115117
return result;
116118
}
117119

120+
function getMonthlyParentNoteId(rootNoteId) {
121+
const month = dateUtils.localNowDate().substring(0, 7);
122+
const labelName = `${rootNoteId}MonthNote`;
123+
124+
let monthNote = searchService.findFirstNoteWithQuery(`#${labelName}="${month}"`,
125+
new SearchContext({ancestorNoteId: rootNoteId}));
126+
127+
if (!monthNote) {
128+
monthNote = noteService.createNewNote({
129+
parentNoteId: rootNoteId,
130+
title: month,
131+
content: '',
132+
isProtected: false,
133+
type: 'book'
134+
}).note
135+
136+
monthNote.addLabel(labelName, month);
137+
}
138+
139+
return monthNote.noteId;
140+
}
141+
118142
function getHoistedNote() {
119143
return becca.getNote(cls.getHoistedNoteId());
120144
}

0 commit comments

Comments
 (0)