Theme is now read from Database
This commit is contained in:
parent
f936453204
commit
f4dcd00669
@ -25,6 +25,7 @@ main = db $ do
|
|||||||
, userEmail = "G.Kleen@campus.lmu.de"
|
, userEmail = "G.Kleen@campus.lmu.de"
|
||||||
, userDisplayName = "Gregor Kleen"
|
, userDisplayName = "Gregor Kleen"
|
||||||
, userMaxFavourites = 6
|
, userMaxFavourites = 6
|
||||||
|
, userTheme = AberdeenReds
|
||||||
}
|
}
|
||||||
fhamann <- insert User
|
fhamann <- insert User
|
||||||
{ userPlugin = "LDAP"
|
{ userPlugin = "LDAP"
|
||||||
@ -33,6 +34,7 @@ main = db $ do
|
|||||||
, userEmail = "felix.hamann@campus.lmu.de"
|
, userEmail = "felix.hamann@campus.lmu.de"
|
||||||
, userDisplayName = "Felix Hamann"
|
, userDisplayName = "Felix Hamann"
|
||||||
, userMaxFavourites = defaultFavourites
|
, userMaxFavourites = defaultFavourites
|
||||||
|
, userTheme = Default
|
||||||
}
|
}
|
||||||
jost <- insert User
|
jost <- insert User
|
||||||
{ userPlugin = "LDAP"
|
{ userPlugin = "LDAP"
|
||||||
@ -41,6 +43,7 @@ main = db $ do
|
|||||||
, userEmail = "jost@tcs.ifi.lmu.de"
|
, userEmail = "jost@tcs.ifi.lmu.de"
|
||||||
, userDisplayName = "Steffen Jost"
|
, userDisplayName = "Steffen Jost"
|
||||||
, userMaxFavourites = 14
|
, userMaxFavourites = 14
|
||||||
|
, userTheme = MintGreen
|
||||||
}
|
}
|
||||||
void . insert $ Term
|
void . insert $ Term
|
||||||
{ termName = summer2017
|
{ termName = summer2017
|
||||||
|
|||||||
@ -425,16 +425,19 @@ instance Yesod UniWorX where
|
|||||||
|
|
||||||
menuTypes <- filterM (menuItemAccessCallback . menuItem) menu
|
menuTypes <- filterM (menuItemAccessCallback . menuItem) menu
|
||||||
|
|
||||||
-- Lookup Favourites & Theme if possible
|
-- Lookup Favourites & Theme if possible -- TODO: cache this info in a cookie?!
|
||||||
favourites' <- do
|
(favourites',show -> currentTheme) <- do
|
||||||
muid <- maybeAuthId
|
muid <- maybeAuthId
|
||||||
case muid of
|
case muid of
|
||||||
Nothing -> return []
|
Nothing -> return ([],Default)
|
||||||
(Just uid) -> runDB . E.select . E.from $ \(course `E.InnerJoin` courseFavourite) -> do
|
(Just uid) -> runDB $ do
|
||||||
E.on (course E.^. CourseId E.==. courseFavourite E.^. CourseFavouriteCourse)
|
cs <- E.select . E.from $ \(course `E.InnerJoin` courseFavourite) -> do
|
||||||
E.where_ (courseFavourite E.^. CourseFavouriteUser E.==. E.val uid)
|
E.on (course E.^. CourseId E.==. courseFavourite E.^. CourseFavouriteCourse)
|
||||||
E.orderBy [ E.asc $ course E.^. CourseShorthand ]
|
E.where_ (courseFavourite E.^. CourseFavouriteUser E.==. E.val uid)
|
||||||
return course
|
E.orderBy [ E.asc $ course E.^. CourseShorthand ]
|
||||||
|
return course
|
||||||
|
mt <- get uid
|
||||||
|
return (cs, fromMaybe Default (userTheme <$> mt))
|
||||||
|
|
||||||
favourites <- forM favourites' $ \(Entity _ c@Course{..})
|
favourites <- forM favourites' $ \(Entity _ c@Course{..})
|
||||||
-> let
|
-> let
|
||||||
@ -447,10 +450,6 @@ instance Yesod UniWorX where
|
|||||||
highRs = if null actFav then crumbs else actFav
|
highRs = if null actFav then crumbs else actFav
|
||||||
in \r -> r `elem` highRs
|
in \r -> r `elem` highRs
|
||||||
|
|
||||||
-- TODO: Lookup theme in Cookie/DB and set variable accordingly
|
|
||||||
-- let currentTheme = "theme--default"
|
|
||||||
let currentTheme = "theme--aberdeen-reds" :: Text
|
|
||||||
|
|
||||||
-- We break up the default layout into two components:
|
-- We break up the default layout into two components:
|
||||||
-- default-layout is the contents of the body tag, and
|
-- default-layout is the contents of the body tag, and
|
||||||
-- default-layout-wrapper is the entire page. Since the final
|
-- default-layout-wrapper is the entire page. Since the final
|
||||||
|
|||||||
@ -203,10 +203,9 @@ readTheme :: Map String Theme
|
|||||||
readTheme = Map.fromList [ (show t,t) | t <- allThemes ]
|
readTheme = Map.fromList [ (show t,t) | t <- allThemes ]
|
||||||
|
|
||||||
instance Read Theme where -- generic Read-Instance for Show/Bounded
|
instance Read Theme where -- generic Read-Instance for Show/Bounded
|
||||||
-- readPrec = undefined
|
|
||||||
readsPrec _ s
|
readsPrec _ s
|
||||||
| (Just t) <- (Map.lookup s readTheme) = [(t,"")]
|
| (Just t) <- (Map.lookup s readTheme) = [(t,"")]
|
||||||
| otherwise = [(Default,"")] -- read will always succeed
|
| otherwise = [(Default,"")] -- read shall always succeed
|
||||||
|
|
||||||
derivePersistField "Theme"
|
derivePersistField "Theme"
|
||||||
|
|
||||||
|
|||||||
@ -67,8 +67,9 @@ withFragment :: ( Monad m
|
|||||||
) => MForm m (a, WidgetT site IO ()) -> Markup -> MForm m (a, WidgetT site IO ())
|
) => MForm m (a, WidgetT site IO ()) -> Markup -> MForm m (a, WidgetT site IO ())
|
||||||
withFragment form html = (flip fmap) form $ \(x, widget) -> (x, toWidget html >> widget)
|
withFragment form html = (flip fmap) form $ \(x, widget) -> (x, toWidget html >> widget)
|
||||||
|
|
||||||
|
|
||||||
uncamel :: String -> String -- "Model.Theme.CamelCaseThing" -> "cmael-case-thing"
|
uncamel :: String -> String -- "Model.Theme.CamelCaseThing" -> "cmael-case-thing"
|
||||||
uncamel = drop 1 . reverse . foldl helper []
|
uncamel = ("theme-" ++) . reverse . foldl helper []
|
||||||
where
|
where
|
||||||
helper _ '.' = []
|
helper _ '.' = []
|
||||||
helper acc c
|
helper acc c
|
||||||
@ -76,6 +77,8 @@ uncamel = drop 1 . reverse . foldl helper []
|
|||||||
| Char.isUpper c = Char.toLower c : '-' : acc
|
| Char.isUpper c = Char.toLower c : '-' : acc
|
||||||
| otherwise = c : acc
|
| otherwise = c : acc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
------------
|
------------
|
||||||
-- Tuples --
|
-- Tuples --
|
||||||
------------
|
------------
|
||||||
@ -86,6 +89,9 @@ snd3 :: (a,b,c) -> b
|
|||||||
snd3 (_,y,_) = y
|
snd3 (_,y,_) = y
|
||||||
trd3 :: (a,b,c) -> c
|
trd3 :: (a,b,c) -> c
|
||||||
trd3 (_,_,z) = z
|
trd3 (_,_,z) = z
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
----------
|
----------
|
||||||
-- Maps --
|
-- Maps --
|
||||||
----------
|
----------
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
module Utils.Common where
|
module Utils.Common where
|
||||||
-- Common Utility Functions that require TemplateHaskell
|
-- Common Utility Functions that require TemplateHaskell
|
||||||
|
|
||||||
import Data.Char
|
-- import Data.Char
|
||||||
|
|
||||||
import Language.Haskell.TH
|
import Language.Haskell.TH
|
||||||
-- import Control.Monad
|
-- import Control.Monad
|
||||||
|
|||||||
Reference in New Issue
Block a user