saving saved search, #73

This commit is contained in:
azivner 2018-03-11 10:49:22 -04:00
parent f6c7f6a0f2
commit ce754cbd91
6 changed files with 81 additions and 16 deletions

View file

@ -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 {

View file

@ -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(" ");
}

View file

@ -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('');

View file

@ -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");
}

View file

@ -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);

View file

@ -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-code"></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>
<div id="note-detail-render"></div>
<br />
<div id="note-detail-attachment">
<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" style="display: none;"></div>
<div id="note-detail-render" style="display: none;"></div>
<div id="note-detail-attachment" style="display: none;">
<table id="attachment-table">
<tr>
<th>File name:</th>