diff options
author | Joey Hess <joey@kitenet.net> | 2012-07-30 02:07:02 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-07-30 02:39:24 -0400 |
commit | 3dce75fb23fca94ad86c3f0ee816bb0ad2ecb27c (patch) | |
tree | 942c851da412a65a1a569bc94e4fd287cd35f3da /Assistant/Alert.hs | |
parent | ec0493fa4d45a8d8f6617c906727d653afb1c50e (diff) |
make old activiy alerts stay visible
They're updated to show whether the activity succeeded or failed.
This adds several TODOs to the code to fix later.
Diffstat (limited to 'Assistant/Alert.hs')
-rw-r--r-- | Assistant/Alert.hs | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/Assistant/Alert.hs b/Assistant/Alert.hs index 49ad515ad..23a93b1c1 100644 --- a/Assistant/Alert.hs +++ b/Assistant/Alert.hs @@ -20,8 +20,8 @@ type Widget = forall sub master. GWidget sub master () data AlertClass = Success | Message | Activity | Warning | Error deriving (Eq, Ord) -{- An alert can be a simple message, or an arbitrary Yesod Widget -} -data AlertMessage = StringAlert String | WidgetAlert Widget +{- An alert can be a simple message, or an arbitrary Yesod Widget. -} +data AlertMessage = StringAlert String | WidgetAlert (Alert -> Widget) data Alert = Alert { alertClass :: AlertClass @@ -37,7 +37,7 @@ type AlertId = Integer type AlertPair = (AlertId, Alert) -data AlertPriority = Low | Medium | High | Pinned +data AlertPriority = Filler | Low | Medium | High | Pinned deriving (Eq, Ord) {- The desired order is the reverse of: @@ -45,7 +45,8 @@ data AlertPriority = Low | Medium | High | Pinned - - Pinned alerts - - High priority alerts, newest first - - Medium priority Activity, newest first (mostly used for Activity) - - - Low priority alwerts, newest first + - - Low priority alerts, newest first + - - Filler priorty alerts, newest first - - Ties are broken by the AlertClass, with Errors etc coming first. -} compareAlertPairs :: AlertPair -> AlertPair -> Ordering @@ -56,6 +57,31 @@ compareAlertPairs `thenOrd` compare aid bid `thenOrd` compare aclass bclass +makeAlertFiller :: Bool -> Alert -> Alert +makeAlertFiller success alert + | alertPriority alert == Filler = alert + | otherwise = alert + { alertClass = if c == Activity then c' else c + , alertPriority = Filler + , alertHeader = finished <$> h + , alertMessage = massage m + } + where + h = alertHeader alert + m = alertMessage alert + c = alertClass alert + c' + | success = Success + | otherwise = Error + + massage (WidgetAlert w) = WidgetAlert w -- renders old on its own + massage (StringAlert s) = StringAlert $ + maybe (finished s) (const s) h + + finished s + | success = s ++ ": Succeeded" + | otherwise = s ++ ": Failed" + sortAlertPairs :: [AlertPair] -> [AlertPair] sortAlertPairs = reverse . sortBy compareAlertPairs |