ui: --watch: track date only when a standard period is in effect

This commit is contained in:
Simon Michael 2016-12-07 15:07:59 -08:00
parent 6aeaee17f5
commit 3c4cb4eeeb
4 changed files with 22 additions and 5 deletions

View File

@ -118,6 +118,17 @@ isLastDayOfMonth y m d =
12 -> d==31
_ -> False
-- | Is this period a "standard" period, referencing a particular day, week, month, quarter, or year ?
-- Periods of other durations, or infinite duration, or not starting on a standard period boundary, are not.
isStandardPeriod = isStandardPeriod' . simplifyPeriod
where
isStandardPeriod' (DayPeriod _) = True
isStandardPeriod' (WeekPeriod _) = True
isStandardPeriod' (MonthPeriod _ _) = True
isStandardPeriod' (QuarterPeriod _ _) = True
isStandardPeriod' (YearPeriod _) = True
isStandardPeriod' _ = False
-- | Render a period as a compact display string suitable for user output.
--
-- >>> showPeriod (WeekPeriod (fromGregorian 2016 7 25))
@ -143,7 +154,7 @@ periodEnd p = me
where
DateSpan _ me = periodAsDateSpan p
-- | Move a standard period (day, week, month etc.) to the following period of same duration.
-- | Move a standard period to the following period of same duration.
-- Non-standard periods are unaffected.
periodNext :: Period -> Period
periodNext (DayPeriod b) = DayPeriod (addDays 1 b)
@ -155,7 +166,7 @@ periodNext (QuarterPeriod y q) = QuarterPeriod y (q+1)
periodNext (YearPeriod y) = YearPeriod (y+1)
periodNext p = p
-- | Move a standard period (day, week, month etc.) to the preceding period of same duration.
-- | Move a standard period to the preceding period of same duration.
-- Non-standard periods are unaffected.
periodPrevious :: Period -> Period
periodPrevious (DayPeriod b) = DayPeriod (addDays (-1) b)

View File

@ -291,8 +291,10 @@ asHandle ui0@UIState{
VtyEvent (EvKey (KChar c) []) | c `elem` ['?'] -> continue $ setMode Help ui
-- XXX AppEvents currently handled only in Normal mode
-- XXX be sure we don't leave unconsumed events piling up
AppEvent (DateChange old _) | periodContainsDate (reportPeriod ui) old ->
AppEvent (DateChange old _) | isStandardPeriod p && p `periodContainsDate` old ->
continue $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
where
p = reportPeriod ui
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
liftIO (uiReloadJournal copts d ui) >>= continue
VtyEvent (EvKey (KChar 'I') []) -> continue $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)

View File

@ -267,8 +267,10 @@ rsHandle ui@UIState{
VtyEvent (EvKey (KChar 'q') []) -> halt ui
VtyEvent (EvKey KEsc []) -> continue $ resetScreens d ui
VtyEvent (EvKey (KChar c) []) | c `elem` ['?'] -> continue $ setMode Help ui
AppEvent (DateChange old _) | periodContainsDate (reportPeriod ui) old ->
AppEvent (DateChange old _) | isStandardPeriod p && p `periodContainsDate` old ->
continue $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
where
p = reportPeriod ui
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
liftIO (uiReloadJournal copts d ui) >>= continue
VtyEvent (EvKey (KChar 'I') []) -> continue $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)

View File

@ -129,8 +129,10 @@ tsHandle ui@UIState{aScreen=s@TransactionScreen{tsTransaction=(i,t)
VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor pos f) >> uiReloadJournalIfChanged copts d j ui
where
(pos,f) = let GenericSourcePos f l c = tsourcepos t in (Just (l, Just c),f)
AppEvent (DateChange old _) | periodContainsDate (reportPeriod ui) old ->
AppEvent (DateChange old _) | isStandardPeriod p && p `periodContainsDate` old ->
continue $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
where
p = reportPeriod ui
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> do
d <- liftIO getCurrentDay
ej <- liftIO $ journalReload copts