From a093508fbe72088554fd58bf394237b08086efdc Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 18 May 2021 20:56:49 +0200 Subject: [PATCH] converting note properties to methods --- spec/search/note_cache_mocking.js | 4 ++-- src/becca/becca_service.js | 4 ++-- src/becca/entities/note.js | 2 +- src/public/app/entities/note_short.js | 4 ++-- src/public/app/services/zoom.js | 4 +++- src/public/app/widgets/note_paths.js | 2 +- src/routes/api/attributes.js | 9 +++++---- src/services/search/services/search.js | 2 ++ 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/spec/search/note_cache_mocking.js b/spec/search/note_cache_mocking.js index 69b17cc3c..855b0c80a 100644 --- a/spec/search/note_cache_mocking.js +++ b/spec/search/note_cache_mocking.js @@ -17,7 +17,7 @@ class NoteBuilder { } label(name, value = '', isInheritable = false) { - new Attribute(becca, { + new Attribute({ attributeId: id(), noteId: this.note.noteId, type: 'label', @@ -30,7 +30,7 @@ class NoteBuilder { } relation(name, targetNote) { - new Attribute(becca, { + new Attribute({ attributeId: id(), noteId: this.note.noteId, type: 'relation', diff --git a/src/becca/becca_service.js b/src/becca/becca_service.js index 5b559c095..dda9d53ad 100644 --- a/src/becca/becca_service.js +++ b/src/becca/becca_service.js @@ -9,7 +9,7 @@ function isNotePathArchived(notePath) { const noteId = notePath[notePath.length - 1]; const note = becca.notes[noteId]; - if (note.isArchived()) { + if (note.isArchived) { return true; } @@ -123,7 +123,7 @@ function getNoteTitleForPath(notePathArray) { * Returns notePath for noteId from cache. Note hoisting is respected. * Archived notes are also returned, but non-archived paths are preferred if available * - this means that archived paths is returned only if there's no non-archived path - * - you can check whether returned path is archived using isArchived() + * - you can check whether returned path is archived using isArchived */ function getSomePath(note, path = []) { // first try to find note within hoisted note, otherwise take any existing note path diff --git a/src/becca/entities/note.js b/src/becca/entities/note.js index 29bf4bdbb..383ad611e 100644 --- a/src/becca/entities/note.js +++ b/src/becca/entities/note.js @@ -568,7 +568,7 @@ class Note extends AbstractEntity { return attrs.length > 0 ? attrs[0] : null; } - isArchived() { + get isArchived() { return this.hasAttribute('label', 'archived'); } diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index 3a0e6d682..1fa815344 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -308,8 +308,8 @@ class NoteShort { return a.isInHoistedSubTree ? -1 : 1; } else if (a.isSearch !== b.isSearch) { return a.isSearch ? 1 : -1; - } else if (a.isArchived() !== b.isArchived()) { - return a.isArchived() ? 1 : -1; + } else if (a.isArchived !== b.isArchived) { + return a.isArchived ? 1 : -1; } else { return a.notePath.length - b.notePath.length; } diff --git a/src/public/app/services/zoom.js b/src/public/app/services/zoom.js index 1f729db87..e435ac970 100644 --- a/src/public/app/services/zoom.js +++ b/src/public/app/services/zoom.js @@ -15,7 +15,9 @@ class ZoomService extends Component { }); window.addEventListener("wheel", event => { - this.setZoomFactorAndSave(this.getCurrentZoom() + event.deltaY * 0.001); + if (event.ctrlKey) { + this.setZoomFactorAndSave(this.getCurrentZoom() + event.deltaY * 0.001); + } }); } } diff --git a/src/public/app/widgets/note_paths.js b/src/public/app/widgets/note_paths.js index 7bd33f279..d18a664af 100644 --- a/src/public/app/widgets/note_paths.js +++ b/src/public/app/widgets/note_paths.js @@ -100,7 +100,7 @@ export default class NotePathsWidget extends TabAwareWidget { icons.push(``); } - if (notePathRecord.isArchived()) { + if (notePathRecord.isArchived) { $noteLink.addClass("path-archived"); icons.push(``); diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index 132c41c5e..b11131f5a 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -47,10 +47,11 @@ function updateNoteAttribute(req) { return {}; } - attribute = new Attribute(); - attribute.noteId = noteId; - attribute.name = body.name; - attribute.type = body.type; + attribute = new Attribute({ + noteId: noteId, + name: body.name, + type: body.type + }); } if (attribute.type === 'label' || body.value.trim()) { diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index bbf7a924c..2138e7516 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -153,6 +153,8 @@ function findResultsWithQuery(query, searchContext) { const expression = parseQueryToExpression(query, searchContext); + console.log("expression", expression); + if (!expression) { return []; }