mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12: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
|
from waitress.server import create_server
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
|
import anki.backend_pb2 as pb
|
||||||
from anki import hooks
|
from anki import hooks
|
||||||
from anki.rsbackend import from_json_bytes
|
from anki.rsbackend import from_json_bytes
|
||||||
from anki.utils import devMode
|
from anki.utils import devMode
|
||||||
|
@ -259,6 +260,18 @@ def graph_preferences() -> bytes:
|
||||||
return aqt.mw.col.backend.graphs_preferences()
|
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:
|
def congrats_info() -> bytes:
|
||||||
info = aqt.mw.col.backend.congrats_info()
|
info = aqt.mw.col.backend.congrats_info()
|
||||||
return info.SerializeToString()
|
return info.SerializeToString()
|
||||||
|
@ -267,6 +280,7 @@ def congrats_info() -> bytes:
|
||||||
post_handlers = dict(
|
post_handlers = dict(
|
||||||
graphData=graph_data,
|
graphData=graph_data,
|
||||||
graphPreferences=graph_preferences,
|
graphPreferences=graph_preferences,
|
||||||
|
setGraphPreferences=set_graph_preferences,
|
||||||
# pylint: disable=unnecessary-lambda
|
# pylint: disable=unnecessary-lambda
|
||||||
i18nResources=lambda: aqt.mw.col.backend.i18n_resources(),
|
i18nResources=lambda: aqt.mw.col.backend.i18n_resources(),
|
||||||
congratsInfo=congrats_info,
|
congratsInfo=congrats_info,
|
||||||
|
|
|
@ -117,6 +117,7 @@ service BackendService {
|
||||||
rpc CardStats(CardID) returns (String);
|
rpc CardStats(CardID) returns (String);
|
||||||
rpc Graphs(GraphsIn) returns (GraphsOut);
|
rpc Graphs(GraphsIn) returns (GraphsOut);
|
||||||
rpc GraphsPreferences(Empty) returns (GraphsPreferencesOut);
|
rpc GraphsPreferences(Empty) returns (GraphsPreferencesOut);
|
||||||
|
rpc SetGraphsPreferences(GraphsPreferencesOut) returns (Empty);
|
||||||
|
|
||||||
// media
|
// media
|
||||||
|
|
||||||
|
|
|
@ -680,6 +680,11 @@ impl BackendService for Backend {
|
||||||
self.with_col(|col| col.graphs_preferences())
|
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
|
// decks
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,11 @@ impl Collection {
|
||||||
card_counts_separate_inactive: true,
|
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 {
|
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
|
// amount of data to fetch from backend
|
||||||
export enum RevlogRange {
|
export enum RevlogRange {
|
||||||
Year = 1,
|
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 type pb from "anki/backend_proto";
|
||||||
|
import { getGraphPreferences, setGraphPreferences } from "./graph-helpers";
|
||||||
|
import { writable, get } from "svelte/store";
|
||||||
|
|
||||||
|
|
||||||
export interface CustomStore<T> {
|
export interface CustomStore<T> {
|
||||||
subscribe: (getter: (value: T) => void) => () => void;
|
subscribe: (getter: (value: T) => void) => () => void;
|
||||||
|
@ -28,10 +29,7 @@ function createPreference<T>(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function preparePreferences(
|
function preparePreferences(graphsPreferences: pb.BackendProto.GraphsPreferencesOut): PreferenceStore {
|
||||||
graphsPreferences: pb.BackendProto.GraphsPreferencesOut,
|
|
||||||
save: (prefs: pb.BackendProto.GraphsPreferencesOut) => void
|
|
||||||
): PreferenceStore {
|
|
||||||
const preferences: Partial<PreferenceStore> = {};
|
const preferences: Partial<PreferenceStore> = {};
|
||||||
|
|
||||||
function constructPreferences(): pb.BackendProto.GraphsPreferencesOut {
|
function constructPreferences(): pb.BackendProto.GraphsPreferencesOut {
|
||||||
|
@ -43,8 +41,7 @@ function preparePreferences(
|
||||||
}
|
}
|
||||||
|
|
||||||
function savePreferences(): void {
|
function savePreferences(): void {
|
||||||
const preferences = constructPreferences();
|
setGraphPreferences(constructPreferences());
|
||||||
save(preferences);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(graphsPreferences)) {
|
for (const [key, value] of Object.entries(graphsPreferences)) {
|
||||||
|
@ -56,8 +53,5 @@ function preparePreferences(
|
||||||
|
|
||||||
export async function getPreferences() {
|
export async function getPreferences() {
|
||||||
const initialPreferences = await getGraphPreferences();
|
const initialPreferences = await getGraphPreferences();
|
||||||
|
return preparePreferences(initialPreferences)
|
||||||
return preparePreferences(initialPreferences, (prefs) => {
|
|
||||||
console.log("preferences to save", prefs);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue