mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-04-25 14:18:53 -05:00
refactoring and fixes for saved note
This commit is contained in:
@@ -5,7 +5,6 @@ import ws from './services/ws.js';
|
||||
import noteType from './widgets/note_type.js';
|
||||
import protectedSessionService from './services/protected_session.js';
|
||||
import protectedSessionHolder from './services/protected_session_holder.js';
|
||||
import searchNotesService from './services/search_notes.js';
|
||||
import FrontendScriptApi from './services/frontend_script_api.js';
|
||||
import ScriptContext from './services/script_context.js';
|
||||
import sync from './services/sync.js';
|
||||
@@ -135,9 +134,22 @@ window.glob.importMarkdownInline = async () => {
|
||||
dialog.importMarkdownInline();
|
||||
};
|
||||
|
||||
macInit.init();
|
||||
window.glob.SEARCH_HELP_TEXT = `
|
||||
<strong>Search tips</strong> - also see <button class="btn btn-sm" type="button" data-help-page="Search">complete help on search</button>
|
||||
<p>
|
||||
<ul>
|
||||
<li>Just enter any text for full text search</li>
|
||||
<li><code>@abc</code> - returns notes with label abc</li>
|
||||
<li><code>@year=2019</code> - matches notes with label <code>year</code> having value <code>2019</code></li>
|
||||
<li><code>@rock @pop</code> - matches notes which have both <code>rock</code> and <code>pop</code> labels</li>
|
||||
<li><code>@rock or @pop</code> - only one of the labels must be present</li>
|
||||
<li><code>@year<=2000</code> - numerical comparison (also >, >=, <).</li>
|
||||
<li><code>@dateCreated>=MONTH-1</code> - notes created in the last month</li>
|
||||
<li><code>=handler</code> - will execute script defined in <code>handler</code> relation to get results</li>
|
||||
</ul>
|
||||
</p>`;
|
||||
|
||||
searchNotesService.init(); // should be in front of treeService since that one manipulates address bar hash
|
||||
macInit.init();
|
||||
|
||||
appContext.start();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import searchNotesService from '../services/search_notes.js';
|
||||
import noteAutocompleteService from '../services/note_autocomplete.js';
|
||||
import utils from "../services/utils.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import toastService from "./toast.js";
|
||||
import appContext from "./app_context.js";
|
||||
|
||||
const helpText = `
|
||||
<strong>Search tips</strong> - also see <button class="btn btn-sm" type="button" data-help-page="Search">complete help on search</button>
|
||||
<p>
|
||||
<ul>
|
||||
<li>Just enter any text for full text search</li>
|
||||
<li><code>@abc</code> - returns notes with label abc</li>
|
||||
<li><code>@year=2019</code> - matches notes with label <code>year</code> having value <code>2019</code></li>
|
||||
<li><code>@rock @pop</code> - matches notes which have both <code>rock</code> and <code>pop</code> labels</li>
|
||||
<li><code>@rock or @pop</code> - only one of the labels must be present</li>
|
||||
<li><code>@year<=2000</code> - numerical comparison (also >, >=, <).</li>
|
||||
<li><code>@dateCreated>=MONTH-1</code> - notes created in the last month</li>
|
||||
<li><code>=handler</code> - will execute script defined in <code>handler</code> relation to get results</li>
|
||||
</ul>
|
||||
</p>`;
|
||||
|
||||
async function refreshSearch() {
|
||||
// FIXME
|
||||
const activeNode = appContext.getMainNoteTree().getActiveNode();
|
||||
|
||||
activeNode.load(true);
|
||||
activeNode.setExpanded(true);
|
||||
|
||||
toastService.showMessage("Saved search note refreshed.");
|
||||
}
|
||||
|
||||
function init() {
|
||||
const hashValue = document.location.hash ? document.location.hash.substr(1) : ""; // strip initial #
|
||||
|
||||
if (hashValue.startsWith("search=")) {
|
||||
showSearch();
|
||||
doSearch(hashValue.substr(7));
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
refreshSearch,
|
||||
init,
|
||||
getHelpText: () => helpText
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
import hoistedNoteService from "../services/hoisted_note.js";
|
||||
import searchNotesService from "../services/search_notes.js";
|
||||
import treeService from "../services/tree.js";
|
||||
import utils from "../services/utils.js";
|
||||
import contextMenuWidget from "../services/context_menu.js";
|
||||
@@ -12,6 +11,7 @@ import ws from "../services/ws.js";
|
||||
import TabAwareWidget from "./tab_aware_widget.js";
|
||||
import server from "../services/server.js";
|
||||
import noteCreateService from "../services/note_create.js";
|
||||
import toastService from "../services/toast.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="tree">
|
||||
@@ -41,7 +41,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
this.$widget = $(TPL);
|
||||
|
||||
this.$widget.on("click", ".unhoist-button", hoistedNoteService.unhoist);
|
||||
this.$widget.on("click", ".refresh-search-button", searchNotesService.refreshSearch);
|
||||
this.$widget.on("click", ".refresh-search-button", () => this.refreshSearch());
|
||||
|
||||
// fancytree doesn't support middle click so this is a way to support it
|
||||
this.$widget.on('mousedown', '.fancytree-title', e => {
|
||||
@@ -438,6 +438,15 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
}
|
||||
}
|
||||
|
||||
async refreshSearch() {
|
||||
const activeNode = this.getActiveNode();
|
||||
|
||||
activeNode.load(true);
|
||||
activeNode.setExpanded(true);
|
||||
|
||||
toastService.showMessage("Saved search note refreshed.");
|
||||
}
|
||||
|
||||
async entitiesReloadedListener({loadResults}) {
|
||||
const noteIdsToUpdate = new Set();
|
||||
const noteIdsToReload = new Set();
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import BasicWidget from "./basic_widget.js";
|
||||
import searchService from "../services/search_notes.js";
|
||||
import treeCache from "../services/tree_cache.js";
|
||||
import toastService from "../services/toast.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
import noteCreateService from "../services/note_create.js";
|
||||
@@ -109,14 +107,13 @@ export default class SearchBoxWidget extends BasicWidget {
|
||||
}
|
||||
|
||||
// FIXME
|
||||
let activeNode = appContext.getMainNoteTree().getActiveNode();
|
||||
const parentNote = await treeCache.getNote(activeNode.data.noteId);
|
||||
let activeNote = appContext.tabManager.getActiveTabNote();
|
||||
|
||||
if (parentNote.type === 'search') {
|
||||
activeNode = activeNode.getParent();
|
||||
if (activeNote.type === 'search') {
|
||||
activeNote = (await activeNote.getParentNotes())[0];
|
||||
}
|
||||
|
||||
await noteCreateService.createNote(activeNode.data.noteId, {
|
||||
await noteCreateService.createNote(activeNote.noteId, {
|
||||
type: "search",
|
||||
mime: "application/json",
|
||||
title: searchString,
|
||||
@@ -134,7 +131,7 @@ export default class SearchBoxWidget extends BasicWidget {
|
||||
this.$searchBox.tooltip({
|
||||
trigger: 'focus',
|
||||
html: true,
|
||||
title: searchService.getHelpText(),
|
||||
title: window.glob.SEARCH_HELP_TEXT,
|
||||
placement: 'right',
|
||||
delay: {
|
||||
show: 500, // necessary because sliding out may cause wrong position
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import searchNotesService from "../../services/search_notes.js";
|
||||
import TypeWidget from "./type_widget.js";
|
||||
|
||||
const TPL = `
|
||||
@@ -6,11 +5,6 @@ const TPL = `
|
||||
<div style="display: flex; align-items: center; margin-right: 20px; margin-top: 15px;">
|
||||
<strong>Search string: </strong>
|
||||
<textarea rows="4" style="width: auto !important; flex-grow: 4" class="search-string form-control"></textarea>
|
||||
|
||||
<span>
|
||||
|
||||
<button type="button" class="btn btn-primary note-detail-search-refresh-results-button">Refresh search results</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
@@ -26,19 +20,12 @@ export default class SearchTypeWidget extends TypeWidget {
|
||||
this.$searchString = this.$widget.find(".search-string");
|
||||
this.$component = this.$widget.find('.note-detail-search');
|
||||
this.$help = this.$widget.find(".note-detail-search-help");
|
||||
this.$refreshButton = this.$widget.find('.note-detail-search-refresh-results-button');
|
||||
|
||||
this.$refreshButton.on('click', async () => {
|
||||
await this.spacedUpdate.updateNowIfNecessary();
|
||||
|
||||
await searchNotesService.refreshSearch();
|
||||
});
|
||||
|
||||
return this.$widget;
|
||||
}
|
||||
|
||||
async doRefresh(note) {
|
||||
this.$help.html(searchNotesService.getHelpText());
|
||||
this.$help.html(window.glob.SEARCH_HELP_TEXT);
|
||||
|
||||
this.$component.show();
|
||||
|
||||
@@ -53,7 +40,7 @@ export default class SearchTypeWidget extends TypeWidget {
|
||||
this.$searchString.val('');
|
||||
}
|
||||
|
||||
this.$searchString.on('input', () => this.noteChanged());
|
||||
this.$searchString.on('input', () => this.spacedUpdate.scheduleUpdate());
|
||||
}
|
||||
|
||||
getContent() {
|
||||
|
||||
Reference in New Issue
Block a user