Skip to content
Browse files

Add explicit order to tasks to avoid jumping around; new tasks at end

  • Loading branch information...
1 parent ad7c641 commit 2b2da6fad5b79b685d5fe0b7381105d0a0174e72 @samstokes committed Sep 12, 2011
Showing with 13 additions and 5 deletions.
  1. +2 −3 Handler/Root.hs
  2. +8 −2 Model.hs
  3. +3 −0 config/models
View
5 Handler/Root.hs
@@ -51,7 +51,7 @@ getTasksR = maybeAuth >>= getTasksR' where
setTitle "tasks"
addWidget $(widgetFile "tasks")
- userTasks userId = selectList [TaskUser ==. userId] [Asc TaskDone]
+ userTasks userId = selectList [TaskUser ==. userId] [Asc TaskDone, Asc TaskOrder]
taskEstimates taskId = selectList [EstimateTask ==. taskId] []
taskTr (taskId, task) estimates = $(widgetFile "tasks/task-tr")
@@ -73,8 +73,7 @@ postTasksR = maybeAuthId >>= postTasksR' where
((result, taskWidget), _) <- runFormPost taskForm
case result of
FormSuccess task -> do
- let task' = newTask userId task
- runDB $ insert task'
+ createTaskAtBottom userId task
redirectTemporary TasksR
_ -> undefined -- TODO
View
10 Model.hs
@@ -20,8 +20,14 @@ newtype TaskState = TaskState Text
data NewTask = NewTask { newTaskTitle :: Text } deriving (Show)
-newTask :: UserId -> NewTask -> Task
-newTask uid (NewTask title) = Task uid title 0 False
+newTask :: UserId -> Int -> NewTask -> Task
+newTask uid order (NewTask title) = Task uid title 0 False order
+
+
+createTaskAtBottom userId task = do
+ maybeLastTask <- runDB $ selectFirst [TaskUser ==. userId] [Desc TaskOrder]
+ let lastOrder = maybe 0 (taskOrder . snd) maybeLastTask
+ runDB $ insert $ newTask userId (succ lastOrder) task
taskState :: Task -> TaskState
taskState task = if taskDone task then "done" else "pending"
View
3 config/models
@@ -12,6 +12,9 @@ Task
title Text
pomos Int default=0
done Bool default=false
+ order Int
+
+ UniqueTaskOrder user order
Estimate
task TaskId
pomos Int

0 comments on commit 2b2da6f

Please sign in to comment.
Something went wrong with that request. Please try again.