Rename GraphsPreferencesOut to simply GraphsPreferences

This commit is contained in:
Henrik Giesel 2021-01-22 19:22:36 +01:00
parent 17ebb69151
commit de71123ab4
7 changed files with 22 additions and 22 deletions

View file

@ -256,12 +256,12 @@ def graph_data() -> bytes:
return aqt.mw.col.backend.graphs(search=args["search"], days=args["days"]) return aqt.mw.col.backend.graphs(search=args["search"], days=args["days"])
def graph_preferences() -> bytes: def graph_preferences() -> pb.GraphsPreferences:
return aqt.mw.col.backend.graphs_preferences() return aqt.mw.col.backend.get_graphs_preferences()
def set_graph_preferences() -> None: def set_graph_preferences() -> None:
input = pb.GraphsPreferencesOut() input = pb.GraphsPreferences()
input.ParseFromString(request.data) input.ParseFromString(request.data)
aqt.mw.col.backend.set_graphs_preferences(input=input) aqt.mw.col.backend.set_graphs_preferences(input=input)

View file

@ -116,8 +116,8 @@ 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 GetGraphsPreferences(Empty) returns (GraphsPreferences);
rpc SetGraphsPreferences(GraphsPreferencesOut) returns (Empty); rpc SetGraphsPreferences(GraphsPreferences) returns (Empty);
// media // media
@ -1094,7 +1094,7 @@ message GraphsOut {
int32 local_offset_secs = 7; int32 local_offset_secs = 7;
} }
message GraphsPreferencesOut { message GraphsPreferences {
enum Weekday { enum Weekday {
SUNDAY = 0; SUNDAY = 0;
MONDAY = 1; MONDAY = 1;

View file

@ -676,11 +676,11 @@ impl BackendService for Backend {
self.with_col(|col| col.graph_data_for_search(&input.search, input.days)) self.with_col(|col| col.graph_data_for_search(&input.search, input.days))
} }
fn graphs_preferences(&self, _input: pb::Empty) -> BackendResult<pb::GraphsPreferencesOut> { fn get_graphs_preferences(&self, _input: pb::Empty) -> BackendResult<pb::GraphsPreferences> {
self.with_col(|col| col.graphs_preferences()) self.with_col(|col| col.get_graphs_preferences())
} }
fn set_graphs_preferences(&self, input: pb::GraphsPreferencesOut) -> BackendResult<Empty> { fn set_graphs_preferences(&self, input: pb::GraphsPreferences) -> BackendResult<Empty> {
self.with_col(|col| col.set_graphs_preferences(input)) self.with_col(|col| col.set_graphs_preferences(input))
.map(Into::into) .map(Into::into)
} }

View file

@ -47,14 +47,14 @@ impl Collection {
}) })
} }
pub(crate) fn graphs_preferences(&self) -> Result<pb::GraphsPreferencesOut> { pub(crate) fn get_graphs_preferences(&self) -> Result<pb::GraphsPreferences> {
Ok(pb::GraphsPreferencesOut { Ok(pb::GraphsPreferences {
calendar_first_day_of_week: self.get_first_day_of_week() as i32, calendar_first_day_of_week: self.get_first_day_of_week() as i32,
card_counts_separate_inactive: self.get_card_counts_separate_inactive(), card_counts_separate_inactive: self.get_card_counts_separate_inactive(),
}) })
} }
pub(crate) fn set_graphs_preferences(&self, prefs: pb::GraphsPreferencesOut) -> Result<()> { pub(crate) fn set_graphs_preferences(&self, prefs: pb::GraphsPreferences) -> Result<()> {
self.set_first_day_of_week(match prefs.calendar_first_day_of_week { self.set_first_day_of_week(match prefs.calendar_first_day_of_week {
1 => Weekday::Monday, 1 => Weekday::Monday,
5 => Weekday::Friday, 5 => Weekday::Friday,

View file

@ -41,8 +41,8 @@ interface DayDatum {
date: Date; date: Date;
} }
type WeekdayType = pb.BackendProto.GraphsPreferencesOut.Weekday; type WeekdayType = pb.BackendProto.GraphsPreferences.Weekday;
const Weekday = pb.BackendProto.GraphsPreferencesOut.Weekday; /* enum */ const Weekday = pb.BackendProto.GraphsPreferences.Weekday; /* enum */
export function gatherData( export function gatherData(
data: pb.BackendProto.GraphsOut, data: pb.BackendProto.GraphsOut,

View file

@ -20,8 +20,8 @@ export async function getGraphData(
); );
} }
export async function getGraphPreferences(): Promise<pb.BackendProto.GraphsPreferencesOut> { export async function getGraphPreferences(): Promise<pb.BackendProto.GraphsPreferences> {
return pb.BackendProto.GraphsPreferencesOut.decode( return pb.BackendProto.GraphsPreferences.decode(
await postRequest("/_anki/graphPreferences", JSON.stringify({})) await postRequest("/_anki/graphPreferences", JSON.stringify({}))
); );
} }
@ -30,7 +30,7 @@ export async function setGraphPreferences(prefs: PreferencePayload): Promise<voi
return (async (): Promise<void> => { return (async (): Promise<void> => {
await postRequest( await postRequest(
"/_anki/setGraphPreferences", "/_anki/setGraphPreferences",
pb.BackendProto.GraphsPreferencesOut.encode(prefs).finish() pb.BackendProto.GraphsPreferences.encode(prefs).finish()
); );
})(); })();
} }

View file

@ -8,16 +8,16 @@ export interface CustomStore<T> extends Writable<T> {
} }
export type PreferenceStore = { export type PreferenceStore = {
[K in keyof Omit<pb.BackendProto.GraphsPreferencesOut, "toJSON">]: CustomStore< [K in keyof Omit<pb.BackendProto.GraphsPreferences, "toJSON">]: CustomStore<
pb.BackendProto.GraphsPreferencesOut[K] pb.BackendProto.GraphsPreferences[K]
>; >;
}; };
export type PreferencePayload = { export type PreferencePayload = {
[K in keyof Omit< [K in keyof Omit<
pb.BackendProto.GraphsPreferencesOut, pb.BackendProto.GraphsPreferences,
"toJSON" "toJSON"
>]: pb.BackendProto.GraphsPreferencesOut[K]; >]: pb.BackendProto.GraphsPreferences[K];
}; };
function createPreference<T>( function createPreference<T>(
@ -40,7 +40,7 @@ function createPreference<T>(
} }
function preparePreferences( function preparePreferences(
graphsPreferences: pb.BackendProto.GraphsPreferencesOut graphsPreferences: pb.BackendProto.GraphsPreferences
): PreferenceStore { ): PreferenceStore {
const preferences: Partial<PreferenceStore> = {}; const preferences: Partial<PreferenceStore> = {};