Skip to content

Commit 686c967

Browse files
committed
options: render in frontend
1 parent 732f1ef commit 686c967

File tree

12 files changed

+168
-59
lines changed

12 files changed

+168
-59
lines changed

frontend/css/base.css

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,3 @@ td .status-indicator {
446446
border-bottom: 5px solid var(--text-color-lightest);
447447
border-left: 5px solid transparent;
448448
}
449-
450-
/*
451-
* View-specific and tables
452-
*/
453-
454-
.options td {
455-
text-align: left;
456-
}
457-
458-
.options td:nth-child(1) {
459-
font-weight: 500;
460-
}
461-
462-
.options td:nth-child(2) {
463-
white-space: normal;
464-
}

frontend/src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ interface GetAPIParams {
6969
trial_balance: FiltersConversionInterval;
7070
ledger_data: undefined;
7171
move: { filename: string; account: string; new_name: string };
72+
options: undefined;
7273
payee_accounts: { payee: string };
7374
payee_transaction: { payee: string };
7475
query: Filters & { query_string: string };

frontend/src/api/validators.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export const getAPIValidators = {
191191
income_statement: tree_report,
192192
ledger_data: ledgerDataValidator,
193193
move: string,
194+
options: object({
195+
fava_options: record(string),
196+
beancount_options: record(string),
197+
}),
194198
payee_accounts: array(string),
195199
payee_transaction: Transaction.validator,
196200
query: query_validator,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script lang="ts">
2+
import { urlFor } from "../../helpers";
3+
import { _ } from "../../i18n";
4+
import OptionsTable from "./OptionsTable.svelte";
5+
6+
export let fava_options: Record<string, string>;
7+
export let beancount_options: Record<string, string>;
8+
</script>
9+
10+
<h2>
11+
{_("Fava options")}
12+
<a href={urlFor("help/options")}>({_("help")})</a>
13+
</h2>
14+
<OptionsTable options={fava_options} />
15+
16+
<h2>{_("Beancount options")}</h2>
17+
<OptionsTable options={beancount_options} />
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<script lang="ts">
2+
import { _ } from "../../i18n";
3+
import { Sorter, StringColumn } from "../../sort";
4+
import SortHeader from "../../sort/SortHeader.svelte";
5+
6+
type T = [string, string];
7+
export let options: Record<string, string>;
8+
9+
const columns = [
10+
new StringColumn<T>(_("Key"), (d) => d[0]),
11+
new StringColumn<T>(_("Value"), (d) => d[1]),
12+
] as const;
13+
let sorter = new Sorter(columns[0], "asc");
14+
15+
$: options_array = Object.entries(options);
16+
$: sorted_options = sorter.sort(options_array);
17+
</script>
18+
19+
<table>
20+
<thead>
21+
<tr>
22+
{#each columns as column}
23+
<SortHeader bind:sorter {column} />
24+
{/each}
25+
</tr>
26+
</thead>
27+
<tbody>
28+
{#each sorted_options as [key, value] (key)}
29+
<tr>
30+
<td>{key}</td>
31+
<td><pre>{value}</pre></td>
32+
</tr>
33+
{/each}
34+
</tbody>
35+
</table>
36+
37+
<style>
38+
td:nth-child(1) {
39+
font-weight: 500;
40+
}
41+
</style>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { get } from "../../api";
2+
import { _ } from "../../i18n";
3+
import { Route } from "../route";
4+
import OptionsSvelte from "./Options.svelte";
5+
6+
export const options = new Route(
7+
"options",
8+
OptionsSvelte,
9+
async () => get("options"),
10+
() => _("Options"),
11+
);

frontend/src/reports/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ErrorsSvelte from "./errors/Errors.svelte";
77
import { events } from "./events";
88
import { holdings } from "./holdings";
99
import { import_report } from "./import";
10+
import { options } from "./options";
1011
import QuerySvelte from "./query/Query.svelte";
1112
import { noload, Route } from "./route";
1213
import { balance_sheet, income_statement, trial_balance } from "./tree_reports";
@@ -30,6 +31,7 @@ export const frontend_routes: Route[] = [
3031
holdings,
3132
import_report,
3233
income_statement,
34+
options,
3335
new Route("query", QuerySvelte, noload, () => _("Query")),
3436
trial_balance,
3537
];

src/fava/application.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import logging
1616
import mimetypes
17-
from dataclasses import fields
1817
from datetime import date
1918
from datetime import datetime
2019
from datetime import timezone
@@ -77,7 +76,6 @@
7776

7877
SERVER_SIDE_REPORTS = [
7978
"journal",
80-
"options",
8179
"statistics",
8280
]
8381

@@ -91,6 +89,7 @@
9189
"holdings",
9290
"import",
9391
"income_statement",
92+
"options",
9493
"query",
9594
"trial_balance",
9695
]
@@ -238,7 +237,6 @@ def _setup_template_config(fava_app: Flask, *, incognito: bool) -> None:
238237
fava_app.add_template_filter(template_filters.flag_to_type)
239238
fava_app.add_template_filter(template_filters.format_currency)
240239
fava_app.add_template_filter(template_filters.meta_items)
241-
fava_app.add_template_filter(fields, "dataclass_fields")
242240
fava_app.add_template_filter(
243241
template_filters.replace_numbers
244242
if incognito

src/fava/json_api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import shutil
1111
from abc import abstractmethod
1212
from dataclasses import dataclass
13+
from dataclasses import fields
1314
from functools import wraps
1415
from http import HTTPStatus
1516
from inspect import Parameter
1617
from inspect import signature
1718
from pathlib import Path
19+
from pprint import pformat
1820
from typing import Any
1921
from typing import Callable
2022
from typing import TYPE_CHECKING
@@ -504,6 +506,32 @@ def get_documents() -> Sequence[Document]:
504506
]
505507

506508

509+
@dataclass(frozen=True)
510+
class Options:
511+
"""Fava and Beancount options as strings."""
512+
513+
fava_options: Mapping[str, str]
514+
beancount_options: Mapping[str, str]
515+
516+
517+
@api_endpoint
518+
def get_options() -> Options:
519+
"""Get all options, rendered to strings for displaying in the frontend."""
520+
g.ledger.changed()
521+
522+
fava_options = g.ledger.fava_options
523+
pprinted_fava_options = {
524+
field.name.replace("_", "-"): pformat(
525+
getattr(fava_options, field.name)
526+
)
527+
for field in fields(fava_options)
528+
}
529+
return Options(
530+
pprinted_fava_options,
531+
{key: str(value) for key, value in g.ledger.options.items()},
532+
)
533+
534+
507535
@dataclass(frozen=True)
508536
class CommodityPairWithPrices:
509537
"""A pair of commodities and prices for them."""

src/fava/templates/options.html

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)