Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove taskDone, replace with taskDoneAt

  • Loading branch information...
commit d0ea93225e77c6fdf7f7471ea70f258f372ea6c7 1 parent f82bc63
@samstokes authored
Showing with 12 additions and 6 deletions.
  1. +6 −3 Handler/Root.hs
  2. +6 −2 Model.hs
  3. +0 −1  config/models
View
9 Handler/Root.hs
@@ -9,6 +9,7 @@ import Data.Map (Map)
import qualified Data.Map as M
import Data.Text (Text, pack)
import Data.Text.Read
+import Data.Time
import Database.Persist.GenericSql.Raw (SqlPersist)
import Yesod.Auth (maybeAuthId)
import Yesod.Handler
@@ -51,7 +52,7 @@ getTasksR = maybeAuth >>= getTasksR' where
setTitle "tasks"
addWidget $(widgetFile "tasks")
- userTasks userId = selectList [TaskUser ==. userId] [Asc TaskDone, Asc TaskOrder]
+ userTasks userId = selectList [TaskUser ==. userId] [Asc TaskDoneAt, Asc TaskOrder]
taskEstimates taskId = selectList [EstimateTask ==. taskId] []
taskTr (taskId, task) estimates = $(widgetFile "tasks/task-tr")
@@ -79,10 +80,12 @@ postTasksR = maybeAuthId >>= postTasksR' where
postCompleteTaskR :: TaskId -> Handler RepHtml
-postCompleteTaskR = updateAndRedirectR TasksR [TaskDone =. True]
+postCompleteTaskR taskId = do
+ now <- liftIO getCurrentTime
+ updateAndRedirectR TasksR [TaskDoneAt =. Just now] taskId
postRestartTaskR :: TaskId -> Handler RepHtml
-postRestartTaskR = updateAndRedirectR TasksR [TaskDone =. False]
+postRestartTaskR = updateAndRedirectR TasksR [TaskDoneAt =. Nothing]
updateAndRedirectR :: HasReps a => YesodoroRoute -> [Update Task] -> TaskId -> Handler a
updateAndRedirectR route updates taskId = maybeAuthId >>= updateAndRedirectR' route updates taskId where
View
8 Model.hs
@@ -2,6 +2,7 @@
module Model where
import Yesod
+import Data.Maybe (isJust)
import Data.String (IsString)
import Data.Text (Text)
import Data.Time
@@ -23,7 +24,7 @@ newtype TaskState = TaskState Text
data NewTask = NewTask { newTaskTitle :: Text } deriving (Show)
newTask :: UserId -> Int -> NewTask -> Task
-newTask uid order (NewTask title) = Task uid title 0 False Nothing order
+newTask uid order (NewTask title) = Task uid title 0 Nothing order
createTaskAtBottom :: PersistBackend SqlPersist m => UserId -> NewTask -> SqlPersist m TaskId
createTaskAtBottom userId task = do
@@ -38,7 +39,7 @@ nextTask :: PersistBackend SqlPersist m => Direction -> Task -> SqlPersist m (Ma
nextTask direction task = selectFirst
[ TaskUser ==. (taskUser task)
, (orderConstraint direction) TaskOrder (taskOrder task)
- , TaskDone ==. False
+ , TaskDoneAt ==. Nothing
] [(order direction) TaskOrder]
where
orderConstraint Up = (<.)
@@ -61,6 +62,9 @@ reorderTask direction filters = do
update taskId [TaskOrder =. (taskOrder next)]
+taskDone :: Task -> Bool
+taskDone = isJust . taskDoneAt
+
taskState :: Task -> TaskState
taskState task = if taskDone task then "done" else "pending"
View
1  config/models
@@ -11,7 +11,6 @@ Task
user UserId
title Text
pomos Int default=0
- done Bool default=false
doneAt UTCTime Maybe
order Int
Please sign in to comment.
Something went wrong with that request. Please try again.