redesign of search input. Saved search is now saved under active note and doesn't need page reload
This commit is contained in:
@@ -123,7 +123,10 @@ if (utils.isElectron()) {
|
||||
setTimeout(async () => {
|
||||
const parentNode = treeService.getActiveNode();
|
||||
|
||||
const {note} = await treeService.createNote(parentNode, parentNode.data.noteId, 'into', "text", parentNode.data.isProtected);
|
||||
const {note} = await treeService.createNote(parentNode, parentNode.data.noteId, 'into', {
|
||||
type: "text",
|
||||
isProtected: parentNode.data.isProtected
|
||||
});
|
||||
|
||||
await treeService.activateNote(note.noteId);
|
||||
|
||||
|
||||
@@ -91,10 +91,10 @@ $("#note-menu-button").click(async e => {
|
||||
const parentNoteId = node.data.parentNoteId;
|
||||
const isProtected = treeUtils.getParentProtectedStatus(node);
|
||||
|
||||
treeService.createNote(node, parentNoteId, 'after', null, isProtected);
|
||||
treeService.createNote(node, parentNoteId, 'after', { isProtected: isProtected });
|
||||
}
|
||||
else if (cmd === "insertChildNote") {
|
||||
treeService.createNote(node, node.data.noteId, 'into', null);
|
||||
treeService.createNote(node, node.data.noteId, 'into');
|
||||
}
|
||||
else if (cmd === "delete") {
|
||||
treeChangesService.deleteNodes([node]);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import treeService from './tree.js';
|
||||
import treeCache from "./tree_cache.js";
|
||||
import server from './server.js';
|
||||
import treeUtils from "./tree_utils.js";
|
||||
import infoService from "./info.js";
|
||||
|
||||
const $tree = $("#tree");
|
||||
const $searchInput = $("input[name='search-text']");
|
||||
@@ -64,16 +65,35 @@ async function doSearch(searchText) {
|
||||
|
||||
$searchResultsInner.append($result);
|
||||
}
|
||||
|
||||
// have at least some feedback which is good especially in situations
|
||||
// when the result list does not change with a query
|
||||
infoService.showMessage("Search finished successfully.");
|
||||
}
|
||||
|
||||
async function saveSearch() {
|
||||
const {noteId} = await server.post('search/' + encodeURIComponent($searchInput.val()));
|
||||
const searchString = $searchInput.val().trim();
|
||||
|
||||
if (searchString.length === 0) {
|
||||
alert("Write some search criteria first so there is something to save.");
|
||||
return;
|
||||
}
|
||||
|
||||
let activeNode = treeService.getActiveNode();
|
||||
const parentNote = await treeCache.getNote(activeNode.data.noteId);
|
||||
|
||||
if (parentNote.type === 'search') {
|
||||
activeNode = activeNode.getParent();
|
||||
}
|
||||
|
||||
await treeService.createNote(activeNode, activeNode.data.noteId, 'into', {
|
||||
type: "search",
|
||||
mime: "application/json",
|
||||
title: searchString,
|
||||
content: JSON.stringify({ searchString: searchString })
|
||||
});
|
||||
|
||||
resetSearch();
|
||||
|
||||
await treeService.reload();
|
||||
|
||||
await treeService.activateNote(noteId);
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
@@ -560,49 +560,44 @@ async function createNewTopLevelNote() {
|
||||
|
||||
const rootNode = getNodesByNoteId(hoistedNoteId)[0];
|
||||
|
||||
await createNote(rootNode, hoistedNoteId, "into", null, false);
|
||||
await createNote(rootNode, hoistedNoteId, "into");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type - type can be falsy - in that case it will be chosen automatically based on parent note
|
||||
*/
|
||||
async function createNote(node, parentNoteId, target, type, isProtected, saveSelection = false) {
|
||||
async function createNote(node, parentNoteId, target, extraOptions) {
|
||||
utils.assertArguments(node, parentNoteId, target);
|
||||
|
||||
// if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted
|
||||
// but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often
|
||||
if (!isProtected || !protectedSessionHolder.isProtectedSessionAvailable()) {
|
||||
isProtected = false;
|
||||
if (!extraOptions.isProtected || !protectedSessionHolder.isProtectedSessionAvailable()) {
|
||||
extraOptions.isProtected = false;
|
||||
}
|
||||
|
||||
if (noteDetailService.getActiveNoteType() !== 'text') {
|
||||
saveSelection = false;
|
||||
extraOptions.saveSelection = false;
|
||||
}
|
||||
else {
|
||||
// just disable this feature altogether - there's a problem that note containing image or table at the beginning
|
||||
// of the content will be auto-selected by CKEditor and then CTRL-P with no user interaction will automatically save
|
||||
// the selection - see https://github.com/ckeditor/ckeditor5/issues/1384
|
||||
saveSelection = false;
|
||||
extraOptions.saveSelection = false;
|
||||
}
|
||||
|
||||
let title, content;
|
||||
|
||||
if (saveSelection) {
|
||||
[title, content] = parseSelectedHtml(window.cutToNote.getSelectedHtml());
|
||||
if (extraOptions.saveSelection) {
|
||||
[extraOptions.title, extraOptions.content] = parseSelectedHtml(window.cutToNote.getSelectedHtml());
|
||||
}
|
||||
|
||||
const newNoteName = title || "new note";
|
||||
const newNoteName = extraOptions.title || "new note";
|
||||
|
||||
const {note, branch} = await server.post('notes/' + parentNoteId + '/children', {
|
||||
title: newNoteName,
|
||||
content: content,
|
||||
content: extraOptions.content,
|
||||
target: target,
|
||||
target_branchId: node.data.branchId,
|
||||
isProtected: isProtected,
|
||||
type: type
|
||||
isProtected: extraOptions.isProtected,
|
||||
type: extraOptions.type
|
||||
});
|
||||
|
||||
if (saveSelection) {
|
||||
if (extraOptions.saveSelection) {
|
||||
// we remove the selection only after it was saved to server to make sure we don't lose anything
|
||||
window.cutToNote.removeSelection();
|
||||
}
|
||||
@@ -622,9 +617,11 @@ async function createNote(node, parentNoteId, target, type, isProtected, saveSel
|
||||
parentNoteId: parentNoteId,
|
||||
refKey: branchEntity.noteId,
|
||||
branchId: branchEntity.branchId,
|
||||
isProtected: isProtected,
|
||||
isProtected: extraOptions.isProtected,
|
||||
extraClasses: await treeBuilder.getExtraClasses(noteEntity),
|
||||
icon: await treeBuilder.getIcon(noteEntity)
|
||||
icon: await treeBuilder.getIcon(noteEntity),
|
||||
folder: extraOptions.type === 'search',
|
||||
lazy: true
|
||||
};
|
||||
|
||||
if (target === 'after') {
|
||||
@@ -708,13 +705,19 @@ utils.bindShortcut('ctrl+o', async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
createNote(node, parentNoteId, 'after', null, isProtected, true);
|
||||
await createNote(node, parentNoteId, 'after', {
|
||||
isProtected: isProtected,
|
||||
saveSelection: true
|
||||
});
|
||||
});
|
||||
|
||||
function createNoteInto() {
|
||||
async function createNoteInto() {
|
||||
const node = getActiveNode();
|
||||
|
||||
createNote(node, node.data.noteId, 'into', null, node.data.isProtected, true);
|
||||
await createNote(node, node.data.noteId, 'into', {
|
||||
isProtected: node.data.isProtected,
|
||||
saveSelection: true
|
||||
});
|
||||
}
|
||||
|
||||
async function checkFolderStatus(node) {
|
||||
@@ -768,10 +771,8 @@ $scrollToActiveNoteButton.click(scrollToActiveNote);
|
||||
export default {
|
||||
reload,
|
||||
collapseTree,
|
||||
scrollToActiveNote,
|
||||
setBranchBackgroundBasedOnProtectedStatus,
|
||||
setProtected,
|
||||
expandToNote,
|
||||
activateNote,
|
||||
getFocusedNode,
|
||||
getActiveNode,
|
||||
@@ -779,7 +780,6 @@ export default {
|
||||
setCurrentNotePathToHash,
|
||||
setNoteTitle,
|
||||
setPrefix,
|
||||
createNewTopLevelNote,
|
||||
createNote,
|
||||
createNoteInto,
|
||||
getSelectedNodes,
|
||||
|
||||
@@ -165,12 +165,15 @@ function selectContextMenuItem(event, cmd) {
|
||||
const isProtected = treeUtils.getParentProtectedStatus(node);
|
||||
const type = cmd.split("_")[1];
|
||||
|
||||
treeService.createNote(node, parentNoteId, 'after', type, isProtected);
|
||||
treeService.createNote(node, parentNoteId, 'after', {
|
||||
type: type,
|
||||
isProtected: isProtected
|
||||
});
|
||||
}
|
||||
else if (cmd.startsWith("insertChildNote")) {
|
||||
const type = cmd.split("_")[1];
|
||||
|
||||
treeService.createNote(node, node.data.noteId, 'into', type);
|
||||
treeService.createNote(node, node.data.noteId, 'into', { type: type });
|
||||
}
|
||||
else if (cmd === "editBranchPrefix") {
|
||||
branchPrefixDialog.showDialog(node);
|
||||
|
||||
Reference in New Issue
Block a user