Permalink
Browse files

Zip up estimates along with tasks, get rid of map

  • Loading branch information...
1 parent 100b146 commit 63bd4abbbbe8b8847890db3e0dc8f4ba190849af @samstokes committed Sep 16, 2011
Showing with 16 additions and 16 deletions.
  1. +9 −7 Handler/Root.hs
  2. +7 −9 hamlet/tasks.hamlet
View
16 Handler/Root.hs
@@ -5,9 +5,7 @@ import Control.Applicative
import Control.Monad
import Data.List (groupBy, partition)
import Data.Monoid
-import Data.Map (Map)
import Data.Maybe (fromJust)
-import qualified Data.Map as M
import Data.Text (Text, pack)
import Data.Text.Read
import Data.Time
@@ -45,19 +43,23 @@ getTasksR = maybeAuth >>= getTasksR' where
getTasksR' (Just (userId, user)) = do
tasks <- runDB $ userTasks userId
- let (done, pending) = partition (taskDone . snd) tasks
- timeZone <- liftIO getCurrentTimeZone
- let doneByDay = groupByEq (fromJust . taskDoneDay timeZone . snd) done
+
estimates <- runDB $ mapM (taskEstimates . fst) tasks
- let tasksEstimates = M.fromList $ (map fst tasks) `zip` estimates
+ let tasksEstimates :: [(TaskId, (Task, [(EstimateId, Estimate)]))]
+ tasksEstimates = (map fst tasks) `zip` ((map snd tasks) `zip` estimates)
+
+ let (done, pending) = partition (taskDone . fst . snd) tasksEstimates
+
+ timeZone <- liftIO getCurrentTimeZone
+ let doneByDay = groupByEq (fromJust . taskDoneDay timeZone . fst . snd) done
((_, taskWidget), enctype) <- generateFormPost taskForm
defaultLayout $ do
setTitle "tasks"
addWidget $(widgetFile "tasks")
userTasks userId = selectList [TaskUser ==. userId] [Asc TaskOrder, Desc TaskDoneAt] -- must specify sorts backwards...
taskEstimates taskId = selectList [EstimateTask ==. taskId] []
- taskTr (taskId, task) estimates = $(widgetFile "tasks/task-tr")
+ taskTr (taskId, (task, estimates)) = $(widgetFile "tasks/task-tr")
oneButton :: Text -> YesodoroRoute -> Widget
View
16 hamlet/tasks.hamlet
@@ -6,22 +6,20 @@ $if null pending
<p>Nothing to do. Congratulations! Why not take the day off?
$else
<table><tbody>
- $forall idAndTask <- pending
- $with estimates <- M.findWithDefault mempty (fst idAndTask) tasksEstimates
- ^{taskTr idAndTask estimates}
+ $forall idAndTaskEstimates <- pending
+ ^{taskTr idAndTaskEstimates}
<form method=POST action=@{TasksR} enctype=#{enctype}
^{taskWidget}
<input type=submit value=Add
$if not (null doneByDay)
<h2>Done
- $forall dayAndTasks <- doneByDay
+ $forall dayAndTasksEstimates <- doneByDay
<h3
- #{fst dayAndTasks}
- $with tasks <- map snd $ snd dayAndTasks
+ #{fst dayAndTasksEstimates}
+ $with tasks <- map fst $ map snd $ snd dayAndTasksEstimates
\ (#{sum $ map taskPomos tasks})
<table><tbody>
- $forall idAndTask <- snd dayAndTasks
- $with estimates <- M.findWithDefault mempty (fst idAndTask) tasksEstimates
- ^{taskTr idAndTask estimates}
+ $forall idAndTaskEstimates <- snd dayAndTasksEstimates
+ ^{taskTr idAndTaskEstimates}

0 comments on commit 63bd4ab

Please sign in to comment.