mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Add non-functioning logic for settings graphs preferences
This commit is contained in:
parent
64352ce0d5
commit
054c30a695
6 changed files with 37 additions and 12 deletions
|
@ -19,6 +19,7 @@ from flask import Response, request
|
|||
from waitress.server import create_server
|
||||
|
||||
import aqt
|
||||
import anki.backend_pb2 as pb
|
||||
from anki import hooks
|
||||
from anki.rsbackend import from_json_bytes
|
||||
from anki.utils import devMode
|
||||
|
@ -259,6 +260,18 @@ def graph_preferences() -> bytes:
|
|||
return aqt.mw.col.backend.graphs_preferences()
|
||||
|
||||
|
||||
def set_graph_preferences() -> bytes:
|
||||
data = from_json_bytes(request.data)
|
||||
|
||||
underscore_data = {
|
||||
"calendar_first_day_of_week": data["calendarFirstDayOfWeek"],
|
||||
"card_counts_separate_inactive": data["cardCountsSeparateInactive"],
|
||||
}
|
||||
|
||||
data = pb.GraphsPreferencesOut(**underscore_data)
|
||||
return aqt.mw.col.backend.set_graphs_preferences(input=data)
|
||||
|
||||
|
||||
def congrats_info() -> bytes:
|
||||
info = aqt.mw.col.backend.congrats_info()
|
||||
return info.SerializeToString()
|
||||
|
@ -267,6 +280,7 @@ def congrats_info() -> bytes:
|
|||
post_handlers = dict(
|
||||
graphData=graph_data,
|
||||
graphPreferences=graph_preferences,
|
||||
setGraphPreferences=set_graph_preferences,
|
||||
# pylint: disable=unnecessary-lambda
|
||||
i18nResources=lambda: aqt.mw.col.backend.i18n_resources(),
|
||||
congratsInfo=congrats_info,
|
||||
|
|
|
@ -117,6 +117,7 @@ service BackendService {
|
|||
rpc CardStats(CardID) returns (String);
|
||||
rpc Graphs(GraphsIn) returns (GraphsOut);
|
||||
rpc GraphsPreferences(Empty) returns (GraphsPreferencesOut);
|
||||
rpc SetGraphsPreferences(GraphsPreferencesOut) returns (Empty);
|
||||
|
||||
// media
|
||||
|
||||
|
|
|
@ -680,6 +680,11 @@ impl BackendService for Backend {
|
|||
self.with_col(|col| col.graphs_preferences())
|
||||
}
|
||||
|
||||
fn set_graphs_preferences(&self, input: pb::GraphsPreferencesOut) -> BackendResult<Empty> {
|
||||
self.with_col(|col| col.set_graphs_preferences(input))
|
||||
.map(Into::into)
|
||||
}
|
||||
|
||||
// decks
|
||||
//-----------------------------------------------
|
||||
|
||||
|
|
|
@ -52,6 +52,11 @@ impl Collection {
|
|||
card_counts_separate_inactive: true,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn set_graphs_preferences(&self, prefs: pb::GraphsPreferencesOut) -> Result<()> {
|
||||
// self.set_first_weekday(prefs.calendar_first_day_of_week);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RevlogEntry> for pb::RevlogEntry {
|
||||
|
|
|
@ -25,6 +25,12 @@ export async function getGraphPreferences(): Promise<pb.BackendProto.GraphsPrefe
|
|||
);
|
||||
}
|
||||
|
||||
export async function setGraphPreferences(prefs: pb.BackendProto.GraphsPreferencesOut): Promise<void> {
|
||||
return (async () => {
|
||||
await postRequest("/_anki/setGraphPreferences", JSON.stringify({ ...prefs }))
|
||||
})()
|
||||
}
|
||||
|
||||
// amount of data to fetch from backend
|
||||
export enum RevlogRange {
|
||||
Year = 1,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { getGraphPreferences } from "./graph-helpers";
|
||||
import { writable, get } from "svelte/store";
|
||||
import type pb from "anki/backend_proto";
|
||||
import { getGraphPreferences, setGraphPreferences } from "./graph-helpers";
|
||||
import { writable, get } from "svelte/store";
|
||||
|
||||
|
||||
export interface CustomStore<T> {
|
||||
subscribe: (getter: (value: T) => void) => () => void;
|
||||
|
@ -28,10 +29,7 @@ function createPreference<T>(
|
|||
};
|
||||
}
|
||||
|
||||
function preparePreferences(
|
||||
graphsPreferences: pb.BackendProto.GraphsPreferencesOut,
|
||||
save: (prefs: pb.BackendProto.GraphsPreferencesOut) => void
|
||||
): PreferenceStore {
|
||||
function preparePreferences(graphsPreferences: pb.BackendProto.GraphsPreferencesOut): PreferenceStore {
|
||||
const preferences: Partial<PreferenceStore> = {};
|
||||
|
||||
function constructPreferences(): pb.BackendProto.GraphsPreferencesOut {
|
||||
|
@ -43,8 +41,7 @@ function preparePreferences(
|
|||
}
|
||||
|
||||
function savePreferences(): void {
|
||||
const preferences = constructPreferences();
|
||||
save(preferences);
|
||||
setGraphPreferences(constructPreferences());
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(graphsPreferences)) {
|
||||
|
@ -56,8 +53,5 @@ function preparePreferences(
|
|||
|
||||
export async function getPreferences() {
|
||||
const initialPreferences = await getGraphPreferences();
|
||||
|
||||
return preparePreferences(initialPreferences, (prefs) => {
|
||||
console.log("preferences to save", prefs);
|
||||
});
|
||||
return preparePreferences(initialPreferences)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue