From aebaa046522df80e20fd411f1b0172eafeb2282e Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 22 Jan 2021 16:53:33 +0100 Subject: [PATCH] Uniformly rename firstWeekday to firstDayOfWeek --- rslib/backend.proto | 7 ------- rslib/src/config.rs | 12 ++++++++---- rslib/src/stats/graphs.rs | 12 ++++++++---- ts/graphs/calendar.ts | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/rslib/backend.proto b/rslib/backend.proto index 2e6a9a0a3..4f31670b2 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -1084,12 +1084,6 @@ message GraphsIn { } message GraphsOut { - enum Weekday { - SUNDAY = 0; - MONDAY = 1; - FRIDAY = 5; - SATURDAY = 6; - } repeated Card cards = 1; repeated RevlogEntry revlog = 2; uint32 days_elapsed = 3; @@ -1098,7 +1092,6 @@ message GraphsOut { uint32 scheduler_version = 5; /// Seconds to add to UTC timestamps to get local time. int32 local_offset_secs = 7; - Weekday first_weekday = 8; } message GraphsPreferencesOut { diff --git a/rslib/src/config.rs b/rslib/src/config.rs index 0495015dd..eb2b88b1a 100644 --- a/rslib/src/config.rs +++ b/rslib/src/config.rs @@ -47,7 +47,7 @@ pub(crate) enum ConfigKey { ShowRemainingDueCountsInStudy, ShowIntervalsAboveAnswerButtons, NewReviewMix, - FirstWeekday, + FirstDayOfWeek, AnswerTimeLimitSecs, ShowDayLearningCardsFirst, LastUnburiedDay, @@ -76,7 +76,7 @@ impl From for &'static str { ConfigKey::ShowRemainingDueCountsInStudy => "dueCounts", ConfigKey::ShowIntervalsAboveAnswerButtons => "estTimes", ConfigKey::NewReviewMix => "newSpread", - ConfigKey::FirstWeekday => "firstWeekday", + ConfigKey::FirstDayOfWeek => "firstDayOfWeek", ConfigKey::AnswerTimeLimitSecs => "timeLim", ConfigKey::ShowDayLearningCardsFirst => "dayLearnFirst", ConfigKey::LastUnburiedDay => "lastUnburied", @@ -229,11 +229,15 @@ impl Collection { self.set_config(ConfigKey::NewReviewMix, &(mix as u8)) } - pub(crate) fn get_first_weekday(&self) -> Weekday { - self.get_config_optional(ConfigKey::FirstWeekday) + pub(crate) fn get_first_day_of_week(&self) -> Weekday { + self.get_config_optional(ConfigKey::FirstDayOfWeek) .unwrap_or(Weekday::Sunday) } + pub(crate) fn set_first_day_of_week(&self, weekday: Weekday) -> Result<()> { + self.set_config(ConfigKey::FirstDayOfWeek, &weekday) + } + pub(crate) fn get_show_due_counts(&self) -> bool { self.get_config_optional(ConfigKey::ShowRemainingDueCountsInStudy) .unwrap_or(true) diff --git a/rslib/src/stats/graphs.rs b/rslib/src/stats/graphs.rs index eeddf68fd..dcfe4a2a3 100644 --- a/rslib/src/stats/graphs.rs +++ b/rslib/src/stats/graphs.rs @@ -1,7 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::{backend_proto as pb, prelude::*, revlog::RevlogEntry, search::SortMode}; +use crate::{backend_proto as pb, prelude::*, revlog::RevlogEntry, search::SortMode, config::Weekday}; impl Collection { pub(crate) fn graph_data_for_search( @@ -42,19 +42,23 @@ impl Collection { next_day_at_secs: timing.next_day_at as u32, scheduler_version: self.sched_ver() as u32, local_offset_secs: local_offset_secs as i32, - 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, + calendar_first_day_of_week: self.get_first_day_of_week() as i32, 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); + self.set_first_day_of_week(match prefs.calendar_first_day_of_week { + 1 => Weekday::Monday, + 5 => Weekday::Friday, + 6 => Weekday::Saturday, + _ => Weekday::Sunday, + })?; Ok(()) } } diff --git a/ts/graphs/calendar.ts b/ts/graphs/calendar.ts index b01ede2d1..7fa24bdce 100644 --- a/ts/graphs/calendar.ts +++ b/ts/graphs/calendar.ts @@ -64,9 +64,9 @@ export function gatherData( const timeFunction = firstDayOfWeek === Weekday.MONDAY ? timeMonday - : data.firstWeekday === Weekday.FRIDAY + : firstDayOfWeek === Weekday.FRIDAY ? timeFriday - : data.firstWeekday === Weekday.SATURDAY + : firstDayOfWeek === Weekday.SATURDAY ? timeSaturday : timeSunday;