diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index ff81cf653..0095b79c4 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -71,6 +71,7 @@ interface GetAPIParams { move: { filename: string; account: string; new_name: string }; payee_accounts: { payee: string }; payee_transaction: { payee: string }; + narration_transaction: { narration: string }; query: Filters & { query_string: string }; source: { filename: string }; } diff --git a/frontend/src/api/validators.ts b/frontend/src/api/validators.ts index ba74ab348..47de2a046 100644 --- a/frontend/src/api/validators.ts +++ b/frontend/src/api/validators.ts @@ -106,6 +106,7 @@ export const ledgerDataValidator = object({ options, other_ledgers: array(tuple(string, string)), payees: array(string), + narrations: array(string), precisions: record(number), sidebar_links: array(tuple(string, string)), tags: array(string), @@ -193,6 +194,7 @@ export const getAPIValidators = { move: string, payee_accounts: array(string), payee_transaction: Transaction.validator, + narration_transaction: Transaction.validator, query: query_validator, source, trial_balance: tree_report, diff --git a/frontend/src/entry-forms/Transaction.svelte b/frontend/src/entry-forms/Transaction.svelte index 16e37381e..14a883fae 100644 --- a/frontend/src/entry-forms/Transaction.svelte +++ b/frontend/src/entry-forms/Transaction.svelte @@ -10,7 +10,8 @@ import { Posting } from "../entries"; import { _ } from "../i18n"; import { notify_err } from "../notifications"; - import { payees } from "../stores"; + import { valueExtractor, valueSelector } from "../sidebar/FilterForm.svelte"; + import { narrations, payees } from "../stores"; import AddMetadataButton from "./AddMetadataButton.svelte"; import EntryMetadata from "./EntryMetadata.svelte"; import PostingSvelte from "./Posting.svelte"; @@ -40,13 +41,9 @@ } } - /// Extract tags and links that can be provided in the narration . - function onNarrationChange({ - currentTarget, - }: { - currentTarget: HTMLInputElement; - }) { - const { value } = currentTarget; + /// Extract tags and links that can be provided in the narration. + function onNarrationBlur() { + const value = narration; entry.tags = [...value.matchAll(TAGS_RE)].map((a) => a[1] ?? ""); entry.links = [...value.matchAll(LINKS_RE)].map((a) => a[1] ?? ""); entry.narration = value @@ -54,8 +51,7 @@ .replaceAll(LINKS_RE, "") .trim(); } - - /// Output tags and links in the narration + /// Output tags and links in the narration function combineNarrationTagsLinks(e: Transaction): string { let val = e.narration; if (e.tags.length) { @@ -66,7 +62,7 @@ } return val; } - $: narration = combineNarrationTagsLinks(entry); + let narration = ""; // Autofill complete transactions. async function autocompleteSelectPayee() { @@ -77,6 +73,17 @@ data.date = entry.date; entry = data; } + async function autocompleteSelectNarration() { + if (entry.payee || !entry.postings.every((p) => !p.account)) { + return; + } + const data = await get("narration_transaction", { + narration: narration, + }); + data.date = entry.date; + entry = data; + narration = combineNarrationTagsLinks(entry); + } function movePosting({ from, to }: { from: number; to: number }) { const moved = entry.postings[from]; @@ -108,14 +115,18 @@ on:select={autocompleteSelectPayee} /> + @@ -151,11 +162,6 @@ flex-basis: 100px; } - input[name="narration"] { - flex-grow: 1; - flex-basis: 200px; - } - label > span:first-child, .label > span:first-child { display: none; diff --git a/frontend/src/sidebar/FilterForm.svelte b/frontend/src/sidebar/FilterForm.svelte index 3bdb9554a..89eabbe61 100644 --- a/frontend/src/sidebar/FilterForm.svelte +++ b/frontend/src/sidebar/FilterForm.svelte @@ -1,22 +1,17 @@ - + +