Skip to content

Build your personal knowledge base with Trilium Notes

saving saved search, #73

azivnerce754cbd9142
diff --git a/src/public/javascripts/note_editor.js b/src/public/javascripts/note_editor.js
index f55962f58f..39b9a52e36 100644
--- a/src/public/javascripts/note_editor.js
+++ b/src/public/javascripts/note_editor.js
@@ -5,6 +5,7 @@ const noteEditor = (function() {
const $noteDetail = $('#note-detail');
const $noteDetailCode = $('#note-detail-code');
+ const $noteDetailSearch = $('#note-detail-search');
const $noteDetailRender = $('#note-detail-render');
const $noteDetailAttachment = $('#note-detail-attachment');
@@ -19,6 +20,7 @@ const noteEditor = (function() {
const $attachmentFileSize = $("#attachment-filesize");
const $attachmentDownload = $("#attachment-download");
const $attachmentOpen = $("#attachment-open");
+ const $searchString = $("#search-string");
let editor = null;
let codeEditor = null;
@@ -90,6 +92,11 @@ const noteEditor = (function() {
else if (note.detail.type === 'code') {
note.detail.content = codeEditor.getValue();
}
+ else if (note.detail.type === 'search') {
+ note.detail.content = JSON.stringify({
+ searchString: $searchString.val()
+ });
+ }
else if (note.detail.type === 'render' || note.detail.type === 'file') {
// nothing
}
@@ -179,6 +186,21 @@ const noteEditor = (function() {
codeEditor.refresh();
}
+ else if (currentNote.detail.type === 'search') {
+ $noteDetailSearch.show();
+
+ try {
+ const json = JSON.parse(content);
+
+ $searchString.val(json.searchString);
+ }
+ catch (e) {
+ console.log(e);
+ $searchString.val('');
+ }
+
+ $searchString.on('input', noteChanged);
+ }
}
async function loadNoteToEditor(noteId) {
@@ -212,6 +234,7 @@ const noteEditor = (function() {
noteType.setNoteMime(currentNote.detail.mime);
$noteDetail.hide();
+ $noteDetailSearch.hide();
$noteDetailCode.hide();
$noteDetailRender.html('').hide();
$noteDetailAttachment.hide();
@@ -283,7 +306,7 @@ const noteEditor = (function() {
else if (note.detail.type === 'code') {
codeEditor.focus();
}
- else if (note.detail.type === 'render' || note.detail.type === 'file') {
+ else if (note.detail.type === 'render' || note.detail.type === 'file' || note.detail.type === 'search') {
// do nothing
}
else {
diff --git a/src/public/javascripts/note_tree.js b/src/public/javascripts/note_tree.js
index 3fc3a14e9b..acf00551e8 100644
--- a/src/public/javascripts/note_tree.js
+++ b/src/public/javascripts/note_tree.js
@@ -154,15 +154,7 @@ const noteTree = (function() {
extraClasses.push("multiple-parents");
}
- if (note.type === 'code') {
- extraClasses.push("code");
- }
- else if (note.type === 'render') {
- extraClasses.push('render');
- }
- else if (note.type === 'file') {
- extraClasses.push('attachment');
- }
+ extraClasses.push(note.type);
return extraClasses.join(" ");
}
diff --git a/src/public/javascripts/note_type.js b/src/public/javascripts/note_type.js
index 8a0e9aa120..d29afbf02d 100644
--- a/src/public/javascripts/note_type.js
+++ b/src/public/javascripts/note_type.js
@@ -63,6 +63,9 @@ const noteType = (function() {
return found ? found.title : mime;
}
}
+ else if (type === 'search') {
+ return 'Saved search';
+ }
else if (type === 'render') {
return 'Render HTML note';
}
@@ -100,6 +103,13 @@ const noteType = (function() {
save();
};
+ this.selectSavedSearch = function() {
+ self.type('search');
+ self.mime('');
+
+ save();
+ };
+
this.selectRender = function() {
self.type('render');
self.mime('');
diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css
index 01380f06d1..81abe378cc 100644
--- a/src/public/stylesheets/style.css
+++ b/src/public/stylesheets/style.css
@@ -72,7 +72,7 @@ span.fancytree-node.fancytree-folder.code > span.fancytree-icon {
background-image: url("../images/icons/code-folder.png");
}
-span.fancytree-node.attachment > span.fancytree-icon {
+span.fancytree-node.file > span.fancytree-icon {
background-position: 0 0;
background-image: url("../images/icons/paperclip.png");
}
diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js
index fdb3dd122d..1db06755ac 100644
--- a/src/services/consistency_checks.js
+++ b/src/services/consistency_checks.js
@@ -214,7 +214,7 @@ async function runAllChecks() {
FROM
notes
WHERE
- type != 'text' AND type != 'code' AND type != 'render' AND type != 'file'`,
+ type != 'text' AND type != 'code' AND type != 'render' AND type != 'file' AND type != 'search'`,
"Note has invalid type", errorList);
await runSyncRowChecks("notes", "noteId", errorList);
diff --git a/src/views/index.ejs b/src/views/index.ejs
index b4a2ecda08..be19acc146 100644
--- a/src/views/index.ejs
+++ b/src/views/index.ejs
@@ -106,6 +106,8 @@
<ul id="note-type-dropdown" class="dropdown-menu dropdown-menu-right" aria-labelledby="dLabel">
<li data-bind="click: selectText, css: { selected: type() == 'text' }"><span class="check">&check;</span> <strong>Text</strong></li>
<li role="separator" class="divider"></li>
+ <li data-bind="click: selectSavedSearch, css: { selected: type() == 'search' }"><span class="check">&check;</span> <strong>Saved search</strong></li>
+ <li role="separator" class="divider"></li>
<li data-bind="click: selectRender, css: { selected: type() == 'render' && mime() == '' }"><span class="check">&check;</span> <strong>Render HTML note</strong></li>
<li role="separator" class="divider"></li>
<li data-bind="click: selectCode, css: { selected: type() == 'code' && mime() == '' }"><span class="check">&check;</span> <strong>Code</strong></li>
@@ -131,13 +133,51 @@
</div>
<div style="position: relative; overflow: auto; grid-area: note-content; padding-left: 10px; padding-top: 10px;" id="note-detail-wrapper">
- <div id="note-detail"></div>
+ <div id="note-detail" style="display: none;"></div>
+
+ <div id="note-detail-search" style="display: none;">
+ <div style="display: flex; align-items: center;">
+ <strong>Search string: &nbsp; &nbsp;</strong>
+ <textarea rows="4" cols="50" id="search-string"></textarea>
+ </div>
+
+ <br />
+
+ <h4>Help</h4>
+ <p>
+ <ul>
+ <li>
+ <code>@abc</code> - matches notes with attribute abc</li>
+ <li>
+ <code>@!abc</code> - matches notes without abc attribute (maybe not the best syntax)</li>
+ <li>
+ <code>@abc=true</code> - matches notes with attribute abc having value true</li>
+ <li><code>@abc!=true</code></li>
+ <li>
+ <code>@"weird attribute"="weird value"</code> - works also with whitespace inside names values</li>
+ <li>
+ <code>@abc and @def</code> - matches notes with both abc and def</li>
+ <li>
+ <code>@abc @def</code> - AND relation is implicit when specifying multiple attributes</li>
+ <li>
+ <code>@abc or @def</code> - OR relation</li>
+ <li>
+ <code>@abc&lt;=5</code> - numerical comparison (also &gt;, &gt;=, &lt;).</li>
+ <li>
+ <code>some search string @abc @def</code> - combination of fulltext and attribute search - both of them need to match (OR not supported)</li>
+ <li>
+ <code>@abc @def some search string</code> - same combination</li>
+ </ul>
+
+ <a href="https://github.com/zadam/trilium/wiki/Attributes">Complete help on search syntax</a>
+ </p>
+ </div>
- <div id="note-detail-code"></div>
+ <div id="note-detail-code" style="display: none;"></div>
- <div id="note-detail-render"></div>
+ <div id="note-detail-render" style="display: none;"></div>
- <div id="note-detail-attachment">
+ <div id="note-detail-attachment" style="display: none;">
<table id="attachment-table">
<tr>
<th>File name:</th>