Browse files

Don't use retrieval order for presentation sorting

  • Loading branch information...
1 parent 183777a commit 63fb0101527c471d70fdfdb132d9d59748201297 @samstokes committed Sep 22, 2011
Showing with 9 additions and 3 deletions.
  1. +5 −3 Handler/Root.hs
  2. +4 −0 Model.hs
View
8 Handler/Root.hs
@@ -3,7 +3,7 @@ module Handler.Root where
import Control.Applicative
import Control.Monad
-import Data.List (groupBy, partition)
+import Data.List (groupBy, partition, sortBy)
import Data.Monoid
import Data.Maybe (fromJust)
import Data.Text (Text, pack)
@@ -47,7 +47,9 @@ getTasksR = authed (\userId -> do
let tasksEstimates :: [(TaskId, (Task, [(EstimateId, Estimate)]))]
tasksEstimates = (map fst tasks) `zip` ((map snd tasks) `zip` estimates)
- let (done, pending) = partition (taskDone . fst . snd) tasksEstimates
+ let (unsortedDone, unsortedPending) = partition (taskDone . fst . snd) tasksEstimates
+ let done = reverse $ sortBy (compareBy $ taskDoneAt . fst . snd) unsortedDone
+ let pending = sortBy (compareBy $ taskOrder . fst . snd) unsortedPending
timeZone <- liftIO getCurrentTimeZone
let doneByDay = groupByEq (fromJust . taskDoneDay timeZone . fst . snd) done
@@ -56,7 +58,7 @@ getTasksR = authed (\userId -> do
setTitle "tasks"
addWidget $(widgetFile "tasks")) where
- userTasks userId = selectList [TaskUser ==. userId] [Asc TaskOrder, Desc TaskDoneAt] -- must specify sorts backwards...
+ userTasks userId = selectList [TaskUser ==. userId] [Desc TaskDoneAt]
taskEstimates taskId = selectList [EstimateTask ==. taskId] []
taskTr (taskId, (task, estimates)) = $(widgetFile "tasks/task-tr")
estimatedRemaining :: (Task, [(EstimateId, Estimate)]) -> Int
View
4 Model.hs
@@ -17,6 +17,10 @@ import Text.Blaze (ToHtml)
share [mkPersist sqlSettings, mkMigrate "migrateAll"] $(persistFile "config/models")
+compareBy :: Ord a => (b -> a) -> b -> b -> Ordering
+compareBy f x y = compare (f x) (f y)
+
+
newtype TaskState = TaskState Text
deriving (ToHtml, IsString)

0 comments on commit 63fb010

Please sign in to comment.