diff --git a/pylib/tools/genbackend.py b/pylib/tools/genbackend.py index 5ed89f86b..e2ad3ced2 100755 --- a/pylib/tools/genbackend.py +++ b/pylib/tools/genbackend.py @@ -34,7 +34,7 @@ LABEL_REPEATED = 3 # messages we don't want to unroll in codegen SKIP_UNROLL_INPUT = {"TranslateString"} -SKIP_DECODE = {"Graphs"} +SKIP_DECODE = {"Graphs", "GraphsPreferences"} def python_type(field): diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index aecfc79d8..c58c19747 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -255,6 +255,10 @@ def graph_data() -> bytes: return aqt.mw.col.backend.graphs(search=args["search"], days=args["days"]) +def graph_preferences() -> bytes: + return aqt.mw.col.backend.graphs_preferences() + + def congrats_info() -> bytes: info = aqt.mw.col.backend.congrats_info() return info.SerializeToString() @@ -262,6 +266,7 @@ def congrats_info() -> bytes: post_handlers = dict( graphData=graph_data, + graphPreferences=graph_preferences, # pylint: disable=unnecessary-lambda i18nResources=lambda: aqt.mw.col.backend.i18n_resources(), congratsInfo=congrats_info, diff --git a/rslib/backend.proto b/rslib/backend.proto index 848a201b9..60a81eec9 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -116,6 +116,7 @@ service BackendService { rpc CardStats(CardID) returns (String); rpc Graphs(GraphsIn) returns (GraphsOut); + rpc GraphsPreferences(Empty) returns (GraphsPreferencesOut); // media @@ -1099,6 +1100,18 @@ message GraphsOut { Weekday first_weekday = 8; } +message GraphsPreferencesOut { + enum Weekday { + SUNDAY = 0; + MONDAY = 1; + FRIDAY = 5; + SATURDAY = 6; + } + Weekday calendar_first_day_of_week = 1; + bool card_counts_separate_inactive = 2; + +} + message RevlogEntry { enum ReviewKind { LEARNING = 0; diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 92080e62c..17ef064d3 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -676,6 +676,10 @@ impl BackendService for Backend { self.with_col(|col| col.graph_data_for_search(&input.search, input.days)) } + fn graphs_preferences(&self, _input: pb::Empty) -> BackendResult { + self.with_col(|col| col.graphs_preferences()) + } + // decks //----------------------------------------------- diff --git a/rslib/src/stats/graphs.rs b/rslib/src/stats/graphs.rs index 59243e13f..3e0fbff64 100644 --- a/rslib/src/stats/graphs.rs +++ b/rslib/src/stats/graphs.rs @@ -45,6 +45,13 @@ impl Collection { first_weekday: self.get_first_weekday() as i32, }) } + + pub(crate) fn graphs_preferences(&self) -> Result { + Ok(pb::GraphsPreferencesOut { + calendar_first_day_of_week: self.get_first_weekday() as i32, + card_counts_separate_inactive: true, + }) + } } impl From for pb::RevlogEntry { diff --git a/ts/graphs/GraphsPage.svelte b/ts/graphs/GraphsPage.svelte index 47b566175..6a461f6a8 100644 --- a/ts/graphs/GraphsPage.svelte +++ b/ts/graphs/GraphsPage.svelte @@ -5,7 +5,7 @@ import type { SvelteComponent } from "svelte/internal"; import type { I18n } from "anki/i18n"; import type pb from "anki/backend_proto"; - import { getGraphData, RevlogRange } from "./graph-helpers"; + import { getGraphData, getGraphPreferences, RevlogRange } from "./graph-helpers"; export let i18n: I18n; export let nightMode: boolean; diff --git a/ts/graphs/graph-helpers.ts b/ts/graphs/graph-helpers.ts index bed36f6d1..9e94fdbf8 100644 --- a/ts/graphs/graph-helpers.ts +++ b/ts/graphs/graph-helpers.ts @@ -19,6 +19,12 @@ export async function getGraphData( ); } +export async function getGraphPreferences(): Promise { + return pb.BackendProto.GraphsPreferencesOut.decode( + await postRequest("/_anki/graphPreferences", JSON.stringify({})) + ); +} + // amount of data to fetch from backend export enum RevlogRange { Year = 1,