mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
feat(search): add create into inbox to search
This commit is contained in:
parent
09aa22c74b
commit
f8090d9217
@ -349,6 +349,27 @@ function renderSuggestion(suggestion: Suggestion): string {
|
||||
: renderNoteSuggestion(suggestion);
|
||||
}
|
||||
|
||||
function mapSuggestionToCreateNoteAction(
|
||||
action: SuggestionAction
|
||||
): CreateNoteAction | null {
|
||||
switch (action) {
|
||||
case SuggestionAction.CreateNote:
|
||||
return CreateNoteAction.CreateNote;
|
||||
|
||||
case SuggestionAction.CreateAndLinkNote:
|
||||
return CreateNoteAction.CreateAndLinkNote;
|
||||
|
||||
case SuggestionAction.CreateChildNote:
|
||||
return CreateNoteAction.CreateChildNote;
|
||||
|
||||
case SuggestionAction.CreateAndLinkChildNote:
|
||||
return CreateNoteAction.CreateAndLinkChildNote;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
||||
if ($el.hasClass("note-autocomplete-input")) {
|
||||
// clear any event listener added in previous invocation of this function
|
||||
@ -507,77 +528,18 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
||||
await doExternalLink();
|
||||
break;
|
||||
|
||||
case SuggestionAction.CreateNote: {
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: "inbox",
|
||||
title: suggestion.noteTitle,
|
||||
activate: true,
|
||||
promptForType: true,
|
||||
}
|
||||
);
|
||||
|
||||
if (!note) break;
|
||||
|
||||
await resolveSuggestionNotePathUnderCurrentHoist(note);
|
||||
await selectNoteFromAutocomplete(suggestion);
|
||||
break;
|
||||
}
|
||||
|
||||
case SuggestionAction.CreateAndLinkNote: {
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: "inbox",
|
||||
title: suggestion.noteTitle,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
}
|
||||
);
|
||||
|
||||
if (!note) break;
|
||||
|
||||
await resolveSuggestionNotePathUnderCurrentHoist(note);
|
||||
await selectNoteFromAutocomplete(suggestion);
|
||||
break;
|
||||
}
|
||||
|
||||
case SuggestionAction.CreateChildNote: {
|
||||
if (!suggestion.parentNoteId) {
|
||||
console.warn("Missing parentNoteId for CreateNoteIntoPath");
|
||||
return;
|
||||
}
|
||||
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: "into",
|
||||
parentNoteUrl: suggestion.parentNoteId,
|
||||
title: suggestion.noteTitle,
|
||||
activate: true,
|
||||
promptForType: true,
|
||||
},
|
||||
);
|
||||
|
||||
if (!note) break;
|
||||
|
||||
await resolveSuggestionNotePathUnderCurrentHoist(note);
|
||||
await selectNoteFromAutocomplete(suggestion);
|
||||
break;
|
||||
}
|
||||
|
||||
case SuggestionAction.CreateNote:
|
||||
case SuggestionAction.CreateAndLinkNote:
|
||||
case SuggestionAction.CreateChildNote:
|
||||
case SuggestionAction.CreateAndLinkChildNote: {
|
||||
if (!suggestion.parentNoteId) {
|
||||
console.warn("Missing parentNoteId for CreateNoteIntoPath");
|
||||
return;
|
||||
}
|
||||
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: "into",
|
||||
parentNoteUrl: suggestion.parentNoteId,
|
||||
title: suggestion.noteTitle,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
}
|
||||
const createNoteAction = mapSuggestionToCreateNoteAction(
|
||||
suggestion.action
|
||||
)!;
|
||||
const { note } = await noteCreateService.createNoteFromAction(
|
||||
createNoteAction,
|
||||
true,
|
||||
suggestion.noteTitle,
|
||||
suggestion.parentNoteId,
|
||||
);
|
||||
|
||||
if (!note) break;
|
||||
|
||||
@ -11,6 +11,7 @@ import type FBranch from "../entities/fbranch.js";
|
||||
import type { ChooseNoteTypeResponse } from "../widgets/dialogs/note_type_chooser.js";
|
||||
import type { CKTextEditor } from "@triliumnext/ckeditor5";
|
||||
import dateNoteService from "../services/date_notes.js";
|
||||
import { CreateNoteAction } from "@triliumnext/commons";
|
||||
|
||||
/**
|
||||
* Defines the type hierarchy and rules for valid argument combinations
|
||||
@ -114,6 +115,7 @@ interface DuplicateResponse {
|
||||
note: FNote;
|
||||
}
|
||||
|
||||
// The low level note creation
|
||||
async function createNote(
|
||||
options: CreateNoteOpts
|
||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
|
||||
@ -141,6 +143,76 @@ async function createNote(
|
||||
}
|
||||
}
|
||||
|
||||
// A wrapper to standardize note creation
|
||||
async function createNoteFromAction(
|
||||
action: CreateNoteAction,
|
||||
promptForType: boolean,
|
||||
title: string | undefined,
|
||||
parentNoteUrl: string | undefined,
|
||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
|
||||
switch (action) {
|
||||
case CreateNoteAction.CreateNote: {
|
||||
const resp = await createNote(
|
||||
{
|
||||
target: "inbox",
|
||||
title: title,
|
||||
activate: true,
|
||||
promptForType: promptForType,
|
||||
}
|
||||
);
|
||||
return resp;
|
||||
}
|
||||
case CreateNoteAction.CreateAndLinkNote: {
|
||||
const resp = await createNote(
|
||||
{
|
||||
target: "inbox",
|
||||
title,
|
||||
activate: false,
|
||||
promptForType: promptForType,
|
||||
}
|
||||
);
|
||||
return resp;
|
||||
}
|
||||
case CreateNoteAction.CreateChildNote: {
|
||||
if (!parentNoteUrl) {
|
||||
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
|
||||
return { note: null, branch: undefined };
|
||||
}
|
||||
|
||||
const resp = await createNote(
|
||||
{
|
||||
target: "into",
|
||||
parentNoteUrl,
|
||||
title,
|
||||
activate: true,
|
||||
promptForType: true,
|
||||
},
|
||||
);
|
||||
return resp
|
||||
}
|
||||
case CreateNoteAction.CreateAndLinkChildNote: {
|
||||
if (!parentNoteUrl) {
|
||||
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
|
||||
return { note: null, branch: undefined };
|
||||
}
|
||||
const resp = await createNote(
|
||||
{
|
||||
target: "into",
|
||||
parentNoteUrl: parentNoteUrl,
|
||||
title,
|
||||
activate: false,
|
||||
promptForType: promptForType,
|
||||
},
|
||||
)
|
||||
return resp;
|
||||
}
|
||||
|
||||
default:
|
||||
console.warn("Unknown CreateNoteAction:", action);
|
||||
return { note: null, branch: undefined };
|
||||
}
|
||||
}
|
||||
|
||||
async function promptForType(
|
||||
options: CreateNoteOpts
|
||||
) : Promise<CreateNoteOpts | null> {
|
||||
@ -326,5 +398,6 @@ async function duplicateSubtree(noteId: string, parentNotePath: string) {
|
||||
|
||||
export default {
|
||||
createNote,
|
||||
createNoteFromAction,
|
||||
duplicateSubtree,
|
||||
};
|
||||
|
||||
@ -253,43 +253,14 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
||||
parentNotePath: string | undefined,
|
||||
action: CreateNoteAction
|
||||
): Promise<string> => {
|
||||
switch (action) {
|
||||
case CreateNoteAction.CreateNote:
|
||||
case CreateNoteAction.CreateAndLinkNote: {
|
||||
const { note } = await note_create.createNote(
|
||||
{
|
||||
target: "inbox",
|
||||
title,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
}
|
||||
);
|
||||
return note?.getBestNotePathString() ?? "";
|
||||
}
|
||||
|
||||
case CreateNoteAction.CreateChildNote:
|
||||
case CreateNoteAction.CreateAndLinkChildNote: {
|
||||
if (!parentNotePath) {
|
||||
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
|
||||
return "";
|
||||
}
|
||||
const resp = await note_create.createNote(
|
||||
{
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
title,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
},
|
||||
)
|
||||
return resp?.note?.getBestNotePathString() ?? "";
|
||||
}
|
||||
|
||||
default:
|
||||
console.warn("Unknown CreateNoteAction:", action);
|
||||
return "";
|
||||
const { note } = await note_create.createNoteFromAction(
|
||||
action,
|
||||
true,
|
||||
parentNotePath,
|
||||
title,
|
||||
);
|
||||
return note?.getBestNotePathString() ?? "";
|
||||
}
|
||||
}
|
||||
}), [ notePath ]));
|
||||
|
||||
// Keyboard shortcuts
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user