2015-03-10 23:13:42 +00:00
|
|
|
module Import
|
|
|
|
( module Import
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Foundation as Import
|
|
|
|
import Import.NoFoundation as Import
|
2015-07-20 20:10:30 +00:00
|
|
|
import Yesod.Form.Bootstrap3 as Import
|
2015-08-16 22:14:33 +00:00
|
|
|
import Text.Printf
|
|
|
|
import Data.List (unfoldr)
|
2015-08-18 10:28:15 +00:00
|
|
|
import Text.Hamlet
|
2015-07-20 20:10:30 +00:00
|
|
|
|
2015-09-06 13:53:09 +00:00
|
|
|
{- CONVINIENCE FUNCTIONS -}
|
|
|
|
|
2015-07-22 00:01:58 +00:00
|
|
|
loginOrDo :: ((Key User, User) -> Handler Html) -> Handler Html
|
2015-07-20 20:10:30 +00:00
|
|
|
loginOrDo cont = do
|
|
|
|
maid <- maybeAuthId
|
|
|
|
muid <- case maid of
|
2015-08-16 22:14:33 +00:00
|
|
|
Just uid -> fmap ((,) uid) <$> runDB (get uid)
|
2015-07-20 20:10:30 +00:00
|
|
|
Nothing -> return Nothing
|
|
|
|
case muid of
|
|
|
|
Nothing -> redirect (AuthR LoginR)
|
2015-07-22 00:01:58 +00:00
|
|
|
Just (uid,u) -> cont (uid,u)
|
2015-08-16 22:14:33 +00:00
|
|
|
|
|
|
|
prettyISK :: Int64 -> String
|
|
|
|
prettyISK isk = signIsk++pretty++","++ printf "%02u" cents
|
|
|
|
where
|
|
|
|
signIsk = if isk >= 0 then "" else "-"
|
|
|
|
(isk',cents) = divMod (abs isk) 100
|
|
|
|
thousands = unfoldr (\b -> if b == 0 then Nothing else Just (b `mod` 1000, b `div` 1000)) isk'
|
|
|
|
pretty = case reverse thousands of
|
|
|
|
(ht:t) -> intercalate "." $ show ht : (printf "%03u" <$> t)
|
|
|
|
[] -> "0"
|
|
|
|
|
|
|
|
showTime :: Int64 -> String
|
2015-08-18 00:46:13 +00:00
|
|
|
showTime t = printf "%02u" hours ++ ":" ++ printf "%02u" minutes ++ ":" ++ printf "%02u" seconds
|
2015-08-16 22:14:33 +00:00
|
|
|
where
|
|
|
|
(hours, minutes') = divMod t 3600
|
|
|
|
(minutes, seconds) = divMod minutes' 60
|
|
|
|
|
|
|
|
showDateTime :: UTCTime -> String
|
|
|
|
showDateTime t = (show . utctDay $ t) ++ " " ++
|
|
|
|
(showTime . round . utctDayTime $ t)
|
2015-08-18 10:28:15 +00:00
|
|
|
|
|
|
|
loginLayout :: ToWidget App a =>
|
|
|
|
User
|
|
|
|
-> a
|
|
|
|
-> HandlerT
|
|
|
|
App IO Html
|
|
|
|
loginLayout user widget = do
|
|
|
|
master <- getYesod
|
|
|
|
mmsg <- getMessage
|
|
|
|
|
|
|
|
-- We break up the default layout into two components:
|
|
|
|
-- default-layout is the contents of the body tag, and
|
|
|
|
-- default-layout-wrapper is the entire page. Since the final
|
|
|
|
-- value passed to hamletToRepHtml cannot be a widget, this allows
|
|
|
|
-- you to use normal widget features in default-layout.
|
|
|
|
|
|
|
|
pc <- widgetToPageContent $ do
|
|
|
|
addStylesheet $ StaticR css_bootstrap_css
|
|
|
|
addStylesheet $ StaticR css_neat_css
|
|
|
|
addScript $ StaticR js_jquery_js
|
|
|
|
addScript $ StaticR js_bootstrap_js
|
2015-09-17 21:31:25 +00:00
|
|
|
addScript $ StaticR js_neat_js
|
2015-08-18 10:28:15 +00:00
|
|
|
$(widgetFile "default-layout")
|
|
|
|
withUrlRenderer $(hamletFile "templates/login-layout-wrapper.hamlet")
|
2015-08-22 22:22:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
showSecsToSell :: Int64 -> String
|
|
|
|
showSecsToSell t
|
|
|
|
| t > 4*7*86400 = pp (fromIntegral t / (7*86400) :: Double) ++ "w"
|
|
|
|
| t > 86400 = pp (fromIntegral t / 86400 :: Double) ++ "d"
|
|
|
|
| t > 3600 = pp (fromIntegral t / 3600 :: Double) ++ "h"
|
|
|
|
| t > 60 = pp (fromIntegral t / 60 :: Double) ++ "m"
|
|
|
|
| t == 0 = "-"
|
|
|
|
| otherwise = pp (fromIntegral t :: Double) ++ "s"
|
|
|
|
where
|
|
|
|
pp = printf "%.2f"
|