tweak Alert closability and construction

This commit is contained in:
Joey Hess 2012-07-29 19:41:17 -04:00
parent d62b157194
commit 0186f06744
2 changed files with 23 additions and 15 deletions

View file

@ -28,6 +28,7 @@ data Alert = Alert
, alertHeader :: Maybe String , alertHeader :: Maybe String
, alertMessage :: AlertMessage , alertMessage :: AlertMessage
, alertBlockDisplay :: Bool , alertBlockDisplay :: Bool
, alertClosable :: Bool
, alertPriority :: AlertPriority , alertPriority :: AlertPriority
} }
@ -36,11 +37,12 @@ type AlertId = Integer
type AlertPair = (AlertId, Alert) type AlertPair = (AlertId, Alert)
data AlertPriority = Low | Medium | High data AlertPriority = Low | Medium | High | Pinned
deriving (Eq, Ord) deriving (Eq, Ord)
{- The desired order is the reverse of: {- The desired order is the reverse of:
- -
- - Pinned alerts
- - High priority alerts, newest first - - High priority alerts, newest first
- - Medium priority Activity, newest first (mostly used for Activity) - - Medium priority Activity, newest first (mostly used for Activity)
- - Low priority alwerts, newest first - - Low priority alwerts, newest first
@ -57,22 +59,30 @@ compareAlertPairs
sortAlertPairs :: [AlertPair] -> [AlertPair] sortAlertPairs :: [AlertPair] -> [AlertPair]
sortAlertPairs = reverse . sortBy compareAlertPairs sortAlertPairs = reverse . sortBy compareAlertPairs
activityAlert :: Maybe String -> String -> Alert baseActivityAlert :: Alert
activityAlert header message = Alert baseActivityAlert = Alert
{ alertClass = Activity { alertClass = Activity
, alertHeader = header , alertHeader = Nothing
, alertMessage = StringAlert message , alertMessage = StringAlert ""
, alertBlockDisplay = False , alertBlockDisplay = False
, alertClosable = False
, alertPriority = Medium , alertPriority = Medium
} }
activityAlert :: Maybe String -> String -> Alert
activityAlert header message = baseActivityAlert
{ alertHeader = header
, alertMessage = StringAlert message
}
startupScanAlert :: Alert startupScanAlert :: Alert
startupScanAlert = activityAlert Nothing "Performing startup scan" startupScanAlert = activityAlert Nothing "Performing startup scan"
runningAlert :: Alert runningAlert :: Alert
runningAlert = (activityAlert Nothing "Running") runningAlert = baseActivityAlert
{ alertClass = Success { alertClass = Success
, alertPriority = High -- pin above the other activity alerts , alertMessage = StringAlert "Running"
, alertPriority = Pinned
} }
pushAlert :: [Remote] -> Alert pushAlert :: [Remote] -> Alert
@ -84,9 +94,8 @@ pushRetryAlert rs = activityAlert (Just "Retrying sync") $
"with " ++ unwords (map Remote.name rs) ++ ", which failed earlier." "with " ++ unwords (map Remote.name rs) ++ ", which failed earlier."
syncMountAlert :: FilePath -> [Remote] -> Alert syncMountAlert :: FilePath -> [Remote] -> Alert
syncMountAlert dir rs = Alert syncMountAlert dir rs = baseActivityAlert
{ alertClass = Activity { alertHeader = Just $ "Syncing with " ++ unwords (map Remote.name rs)
, alertHeader = Just $ "Syncing with " ++ unwords (map Remote.name rs)
, alertMessage = StringAlert $ unwords , alertMessage = StringAlert $ unwords
["I noticed you plugged in" ["I noticed you plugged in"
, dir , dir
@ -97,9 +106,8 @@ syncMountAlert dir rs = Alert
} }
scanAlert :: Remote -> Alert scanAlert :: Remote -> Alert
scanAlert r = Alert scanAlert r = baseActivityAlert
{ alertClass = Activity { alertHeader = Just $ "Scanning " ++ Remote.name r
, alertHeader = Just $ "Scanning " ++ Remote.name r
, alertMessage = StringAlert $ unwords , alertMessage = StringAlert $ unwords
[ "Ensuring that ", Remote.name r [ "Ensuring that ", Remote.name r
, "is fully in sync." ] , "is fully in sync." ]
@ -122,4 +130,5 @@ sanityCheckFixAlert msg = Alert
] ]
, alertBlockDisplay = True , alertBlockDisplay = True
, alertPriority = High , alertPriority = High
, alertClosable = True
} }

View file

@ -177,8 +177,7 @@ sideBarDisplay noScript = do
renderalert (alertid, alert) = addalert renderalert (alertid, alert) = addalert
(show alertid) (show alertid)
-- Activity alerts auto-close (alertClosable alert)
(alertClass alert /= Activity)
(alertBlockDisplay alert) (alertBlockDisplay alert)
(bootstrapclass $ alertClass alert) (bootstrapclass $ alertClass alert)
(alertHeader alert) (alertHeader alert)