From 876b329b82271ca190af67c92348fd75880e5f39 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 16 Feb 2016 19:00:26 +0100 Subject: [PATCH] format timestamp --- Handler/Tables.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Handler/Tables.hs b/Handler/Tables.hs index 29da906..4838520 100644 --- a/Handler/Tables.hs +++ b/Handler/Tables.hs @@ -14,6 +14,8 @@ import qualified Data.Maybe as DM import qualified Data.List as DL +import Data.Text (pack) + import GEval.Core data LeaderboardEntry = LeaderboardEntry { @@ -26,7 +28,7 @@ data LeaderboardEntry = LeaderboardEntry { submissionsTable :: [Entity Test] -> Table site (Entity Submission, Entity User, Map (Key Test) Evaluation) submissionsTable tests = mempty ++ Table.text "submitter" (formatSubmitter . \(_, Entity _ submitter, _) -> submitter) - ++ Table.string "when" (show . submissionStamp . \(Entity _ s, _, _) -> s) + ++ timestampCell "when" (submissionStamp . \(Entity _ s, _, _) -> s) ++ Table.text "description" (submissionDescription . \(Entity _ s, _, _) -> s) ++ mconcat (map (\(Entity k t) -> Table.string (testName t) (submissionScore k)) tests) @@ -35,12 +37,20 @@ leaderboardTable :: Table site (Int, LeaderboardEntry) leaderboardTable = mempty ++ Table.int "#" fst ++ Table.text "submitter" (formatSubmitter . leaderboardUser . snd) - ++ Table.string "when" (show . submissionStamp . leaderboardBestSubmission . snd) + ++ timestampCell "when" (submissionStamp . leaderboardBestSubmission . snd) ++ Table.text "description" (submissionDescription . leaderboardBestSubmission . snd) ++ Table.string "result" (presentScore . leaderboardEvaluation . snd) ++ Table.int "×" (leaderboardNumberOfSubmissions . snd) +hoverTextCell :: Text -> (a -> Text) -> (a -> Text) -> Table site a +hoverTextCell h mainTextFun hoverTextFun = Table.widget h ( + \v -> [whamlet|#{mainTextFun v}|]) + +timestampCell :: Text -> (a -> UTCTime) -> Table site a +timestampCell h timestampFun = hoverTextCell h (Data.Text.pack . shorterFormat . timestampFun) (Data.Text.pack . show . timestampFun) + where shorterFormat = formatTime defaultTimeLocale "%Y-%m-%d %H:%M" + getMainTest :: [Entity Test] -> Entity Test getMainTest tests = DL.maximumBy (\(Entity _ a) (Entity _ b) -> ((testName a) `compare` (testName b))) tests