Skip to content

Commit

Permalink
Move task rendering into its own template
Browse files Browse the repository at this point in the history
  • Loading branch information
samstokes committed Sep 8, 2011
1 parent 35c4075 commit 39fea14
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Handler/Root.hs
Expand Up @@ -51,6 +51,7 @@ getTasksR = maybeAuth >>= getTasksR' where

userTasks userId = selectList [TaskUser ==. userId] [Asc TaskDone]
taskEstimates taskId = selectList [EstimateTask ==. taskId] []
taskTr (taskId, task) estimates = $(widgetFile "tasks/task-tr")


oneButton :: Text -> YesodoroRoute -> Widget
Expand Down Expand Up @@ -94,8 +95,8 @@ setTaskDonenessRoute (taskId, task) = route taskId
where route | taskDone task = RestartTaskR
| otherwise = CompleteTaskR

setTaskDonenessButton :: (TaskId, Task) -> Widget
setTaskDonenessButton (taskId, task) = oneButton action (route taskId)
setTaskDonenessButton :: TaskId -> Task -> Widget
setTaskDonenessButton taskId task = oneButton action (route taskId)
where action = taskActionName task
route | taskDone task = RestartTaskR
| otherwise = CompleteTaskR
Expand Down
22 changes: 2 additions & 20 deletions hamlet/tasks.hamlet
Expand Up @@ -5,26 +5,8 @@ $if null tasks
$else
<table><tbody>
$forall idAndTask <- tasks
<tr .task .#{taskState $ snd idAndTask}
<th .title rowspan=2>#{taskTitle $ snd idAndTask}
<td rowspan=2>^{setTaskDonenessButton idAndTask}
<td rowspan=2>^{oneButton "Delete" (DeleteTaskR $ fst idAndTask)}
<td>
$with estimates <- M.findWithDefault mempty (fst idAndTask) tasksEstimates
$if null estimates
<form method=POST action=@{TaskAddEstimateR $ fst idAndTask}
$forall numPomos <- estimateOptions
<button name=pomos value=#{show numPomos}
#{show numPomos}
$else
$with firstEstimate <- estimatePomos $ snd $ head estimates
$forall estimate <- replicate firstEstimate undefined
<td rowspan=2>^{oneButton "Pomo" (TaskAddPomoR $ fst idAndTask)}
<tr .task .#{taskState $ snd idAndTask}
<td
$forall pomo <- replicate (taskPomos $ snd idAndTask) undefined
$with estimates <- M.findWithDefault mempty (fst idAndTask) tasksEstimates
^{taskTr idAndTask estimates}

<form method=POST action=@{TasksR} enctype=#{enctype}
^{taskWidget}
Expand Down
19 changes: 19 additions & 0 deletions hamlet/tasks/task-tr.hamlet
@@ -0,0 +1,19 @@
<tr .task .#{taskState task}
<th .title rowspan=2>#{taskTitle task}
<td rowspan=2>^{setTaskDonenessButton taskId task}
<td rowspan=2>^{oneButton "Delete" (DeleteTaskR taskId)}
<td>
$if null estimates
<form method=POST action=@{TaskAddEstimateR taskId}
$forall numPomos <- estimateOptions
<button name=pomos value=#{show numPomos}
#{show numPomos}
$else
$with firstEstimate <- estimatePomos $ snd $ head estimates
$forall estimate <- replicate firstEstimate undefined
<td rowspan=2>^{oneButton "Pomo" (TaskAddPomoR taskId)}
<tr .task .#{taskState task}
<td
$forall pomo <- replicate (taskPomos task) undefined

0 comments on commit 39fea14

Please sign in to comment.