From 6e69cafe5419e8efcc6f652647f9227dbcfa1e18 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 8 Jun 2023 22:45:44 +0200 Subject: [PATCH 1/7] fix showing deleted notes in the recent changes dialog, closes #4013 --- src/routes/api/recent_changes.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/routes/api/recent_changes.js b/src/routes/api/recent_changes.js index 646898e9c..ca0a23c71 100644 --- a/src/routes/api/recent_changes.js +++ b/src/routes/api/recent_changes.js @@ -27,7 +27,8 @@ function getRecentChanges(req) { for (const noteRevisionRow of noteRevisionRows) { const note = becca.getNote(noteRevisionRow.noteId); - if (note?.hasAncestor(ancestorNoteId)) { + // for deleted notes, the becca note is null, and it's not possible to (easily) determine if it belongs to a subtree + if (ancestorNoteId === 'root' || note?.hasAncestor(ancestorNoteId)) { recentChanges.push(noteRevisionRow); } } @@ -43,8 +44,8 @@ function getRecentChanges(req) { notes.title AS current_title, notes.isProtected AS current_isProtected, notes.title, - notes.utcDateCreated AS utcDate, - notes.dateCreated AS date + notes.utcDateCreated AS utcDate, -- different from the second SELECT + notes.dateCreated AS date -- different from the second SELECT FROM notes UNION ALL SELECT @@ -54,15 +55,16 @@ function getRecentChanges(req) { notes.title AS current_title, notes.isProtected AS current_isProtected, notes.title, - notes.utcDateModified AS utcDate, - notes.dateModified AS date + notes.utcDateModified AS utcDate, -- different from the first SELECT + notes.dateModified AS date -- different from the first SELECT FROM notes WHERE notes.isDeleted = 1`); for (const noteRow of noteRows) { const note = becca.getNote(noteRow.noteId); - if (note?.hasAncestor(ancestorNoteId)) { + // for deleted notes, the becca note is null, and it's not possible to (easily) determine if it belongs to a subtree + if (ancestorNoteId === 'root' || note?.hasAncestor(ancestorNoteId)) { recentChanges.push(noteRow); } } From 2bdd538d7d624b5e8870cced3b70816e4953efde Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 8 Jun 2023 22:46:52 +0200 Subject: [PATCH 2/7] release 0.60.2-beta --- package.json | 2 +- src/services/build.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3353f12b9..43b1241f2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "trilium", "productName": "Trilium Notes", "description": "Trilium Notes", - "version": "0.60.1-beta", + "version": "0.60.2-beta", "license": "AGPL-3.0-only", "main": "electron.js", "bin": { diff --git a/src/services/build.js b/src/services/build.js index 88c7d6157..c539d9bd7 100644 --- a/src/services/build.js +++ b/src/services/build.js @@ -1 +1 @@ -module.exports = { buildDate:"2023-05-26T23:11:53+02:00", buildRevision: "82efc924136c5b215e39f2108f00dd2bf075271c" }; +module.exports = { buildDate:"2023-06-08T22:46:52+02:00", buildRevision: "6e69cafe5419e8efcc6f652647f9227dbcfa1e18" }; From 004cfe19658954627b7ac6e3118cffe8648a14e3 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 12 Jun 2023 23:09:29 +0200 Subject: [PATCH 3/7] allow creating backups via ETAPI, #4014 --- src/etapi/backup.js | 14 ++++++++++++++ src/etapi/etapi.openapi.yaml | 25 ++++++++++++++++++++++++- src/routes/routes.js | 2 ++ test-etapi/create-backup.http | 4 ++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/etapi/backup.js create mode 100644 test-etapi/create-backup.http diff --git a/src/etapi/backup.js b/src/etapi/backup.js new file mode 100644 index 000000000..8dc7f8ed1 --- /dev/null +++ b/src/etapi/backup.js @@ -0,0 +1,14 @@ +const eu = require("./etapi_utils"); +const backupService = require("../services/backup"); + +function register(router) { + eu.route(router, 'put', '/etapi/backup/:backupName', async (req, res, next) => { + await backupService.backupNow(req.params.backupName); + + res.sendStatus(204); + }); +} + +module.exports = { + register +}; diff --git a/src/etapi/etapi.openapi.yaml b/src/etapi/etapi.openapi.yaml index 7c41693d1..754fb05b3 100644 --- a/src/etapi/etapi.openapi.yaml +++ b/src/etapi/etapi.openapi.yaml @@ -700,7 +700,26 @@ paths: application/json; charset=utf-8: schema: $ref: '#/components/schemas/Error' - + /backup/{backupName}: + parameters: + - name: backupName + in: path + required: true + description: If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file + schema: + $ref: '#/components/schemas/StringId' + put: + description: Create a database backup under a given name + operationId: createBackup + responses: + '204': + description: backup has been created + default: + description: unexpected error + content: + application/json; charset=utf-8: + schema: + $ref: '#/components/schemas/Error' components: securitySchemes: EtapiTokenAuth: @@ -880,6 +899,10 @@ components: type: string pattern: '[a-zA-Z0-9_]{4,32}' example: evnnmvHTCgIn + StringId: + type: string + pattern: '[a-zA-Z0-9_]{1,32}' + example: my_ID EntityIdList: type: array items: diff --git a/src/routes/routes.js b/src/routes/routes.js index a52a067f5..2989208b5 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -65,6 +65,7 @@ const etapiBranchRoutes = require('../etapi/branches'); const etapiNoteRoutes = require('../etapi/notes'); const etapiSpecialNoteRoutes = require('../etapi/special_notes'); const etapiSpecRoute = require('../etapi/spec'); +const etapiBackupRoute = require('../etapi/backup'); const csrfMiddleware = csurf({ cookie: true, @@ -315,6 +316,7 @@ function register(app) { etapiNoteRoutes.register(router); etapiSpecialNoteRoutes.register(router); etapiSpecRoute.register(router); + etapiBackupRoute.register(router); app.use('', router); } diff --git a/test-etapi/create-backup.http b/test-etapi/create-backup.http new file mode 100644 index 000000000..59ffbebc4 --- /dev/null +++ b/test-etapi/create-backup.http @@ -0,0 +1,4 @@ +PUT {{triliumHost}}/etapi/backup/etapi_test +Authorization: {{authToken}} + +> {% client.assert(response.status === 201); %} From 4a1ecd906bb6491edf663007050269e1543e8ae4 Mon Sep 17 00:00:00 2001 From: mechanarchy <1166756+mechanarchy@users.noreply.github.com> Date: Sat, 10 Jun 2023 07:44:23 +1000 Subject: [PATCH 4/7] Update entrypoints.js (cherry picked from commit 08ec866dd269eca54b37db32284ede1402d560c3) --- src/public/app/components/entrypoints.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/public/app/components/entrypoints.js b/src/public/app/components/entrypoints.js index 68117280e..b2c4d306c 100644 --- a/src/public/app/components/entrypoints.js +++ b/src/public/app/components/entrypoints.js @@ -173,7 +173,7 @@ export default class Entrypoints extends Component { const resp = await server.post(`sql/execute/${note.noteId}`); if (!resp.success) { - toastService.showError(`Error occurred while executing SQL query: ${resp.message}`); + toastService.showError(`Error occurred while executing SQL query: ${resp.error}`); } await appContext.triggerEvent('sqlQueryResults', {ntxId: ntxId, results: resp.results}); From 6015a067ecd7627e52d1b4d1add96c058c26848e Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 12 Jun 2023 23:18:57 +0200 Subject: [PATCH 5/7] sql console outputs results of CTEs, fixes #2800 --- src/routes/api/sql.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/api/sql.js b/src/routes/api/sql.js index 09e14cc86..1c853f365 100644 --- a/src/routes/api/sql.js +++ b/src/routes/api/sql.js @@ -37,7 +37,7 @@ function execute(req) { continue; } - if (query.toLowerCase().startsWith('select')) { + if (query.toLowerCase().startsWith('select') || query.toLowerCase().startsWith('with')) { results.push(sql.getRows(query)); } else { From 6548149107443e66aa0282a7e00a19b722189379 Mon Sep 17 00:00:00 2001 From: mechanarchy <1166756+mechanarchy@users.noreply.github.com> Date: Sat, 10 Jun 2023 17:36:23 +1000 Subject: [PATCH 6/7] Update etapi.js (cherry picked from commit b97ebe9f03e84d01402f26b97fd0418a14a8d946) --- src/public/app/widgets/type_widgets/options/etapi.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/public/app/widgets/type_widgets/options/etapi.js b/src/public/app/widgets/type_widgets/options/etapi.js index d6356dff5..2fa773f8f 100644 --- a/src/public/app/widgets/type_widgets/options/etapi.js +++ b/src/public/app/widgets/type_widgets/options/etapi.js @@ -109,6 +109,10 @@ export default class EtapiOptions extends OptionsWidget { message: "Please enter new token's name", defaultValue: oldName }); + + if(tokenName === null) { + return; + } await server.patch(`etapi-tokens/${etapiTokenId}`, {name: tokenName}); From bea39f37ee2332e753055d77aa4c1b3a9c69cdea Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 13 Jun 2023 00:12:55 +0200 Subject: [PATCH 7/7] stop click propagation in tree item actions --- package-lock.json | 4 ++-- src/public/app/widgets/note_tree.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 14cc4892b..8d9b63fc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "trilium", - "version": "0.60.1-beta", + "version": "0.60.2-beta", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "trilium", - "version": "0.60.1-beta", + "version": "0.60.2-beta", "hasInstallScript": true, "license": "AGPL-3.0-only", "dependencies": { diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 60f7b34a3..1d8f426f2 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -148,6 +148,9 @@ const TPL = ` const MAX_SEARCH_RESULTS_IN_TREE = 100; +// this has to be hanged on the actual elements to effectively intercept and stop click event +const cancelClickPropagation = e => e.stopPropagation(); + export default class NoteTreeWidget extends NoteContextAwareWidget { constructor() { super(); @@ -559,7 +562,8 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { const isHoistedNote = activeNoteContext && activeNoteContext.hoistedNoteId === note.noteId && note.noteId !== 'root'; if (isHoistedNote) { - const $unhoistButton = $(''); + const $unhoistButton = $('') + .on("click", cancelClickPropagation); // unhoist button is prepended since compared to other buttons this is not just convenience // on the mobile interface - it's the only way to unhoist @@ -567,19 +571,22 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { } if (note.hasLabel('workspace') && !isHoistedNote) { - const $enterWorkspaceButton = $(''); + const $enterWorkspaceButton = $('') + .on("click", cancelClickPropagation); $span.append($enterWorkspaceButton); } if (note.type === 'search') { - const $refreshSearchButton = $(''); + const $refreshSearchButton = $('') + .on("click", cancelClickPropagation); $span.append($refreshSearchButton); } if (!['search', 'launcher'].includes(note.type) && !note.isOptions() && !note.isLaunchBarConfig()) { - const $createChildNoteButton = $(''); + const $createChildNoteButton = $('') + .on("click", cancelClickPropagation); $span.append($createChildNoteButton); }