Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Don't use retrieval order for presentation sorting

  • Loading branch information...
commit 63fb0101527c471d70fdfdb132d9d59748201297 1 parent 183777a
Sam Stokes authored

Showing 2 changed files with 9 additions and 3 deletions. Show diff stats Hide diff stats

  1. +5 3 Handler/Root.hs
  2. +4 0 Model.hs
8 Handler/Root.hs
@@ -3,7 +3,7 @@ module Handler.Root where
3 3
4 4 import Control.Applicative
5 5 import Control.Monad
6   -import Data.List (groupBy, partition)
  6 +import Data.List (groupBy, partition, sortBy)
7 7 import Data.Monoid
8 8 import Data.Maybe (fromJust)
9 9 import Data.Text (Text, pack)
@@ -47,7 +47,9 @@ getTasksR = authed (\userId -> do
47 47 let tasksEstimates :: [(TaskId, (Task, [(EstimateId, Estimate)]))]
48 48 tasksEstimates = (map fst tasks) `zip` ((map snd tasks) `zip` estimates)
49 49
50   - let (done, pending) = partition (taskDone . fst . snd) tasksEstimates
  50 + let (unsortedDone, unsortedPending) = partition (taskDone . fst . snd) tasksEstimates
  51 + let done = reverse $ sortBy (compareBy $ taskDoneAt . fst . snd) unsortedDone
  52 + let pending = sortBy (compareBy $ taskOrder . fst . snd) unsortedPending
51 53
52 54 timeZone <- liftIO getCurrentTimeZone
53 55 let doneByDay = groupByEq (fromJust . taskDoneDay timeZone . fst . snd) done
@@ -56,7 +58,7 @@ getTasksR = authed (\userId -> do
56 58 setTitle "tasks"
57 59 addWidget $(widgetFile "tasks")) where
58 60
59   - userTasks userId = selectList [TaskUser ==. userId] [Asc TaskOrder, Desc TaskDoneAt] -- must specify sorts backwards...
  61 + userTasks userId = selectList [TaskUser ==. userId] [Desc TaskDoneAt]
60 62 taskEstimates taskId = selectList [EstimateTask ==. taskId] []
61 63 taskTr (taskId, (task, estimates)) = $(widgetFile "tasks/task-tr")
62 64 estimatedRemaining :: (Task, [(EstimateId, Estimate)]) -> Int
4 Model.hs
@@ -17,6 +17,10 @@ import Text.Blaze (ToHtml)
17 17 share [mkPersist sqlSettings, mkMigrate "migrateAll"] $(persistFile "config/models")
18 18
19 19
  20 +compareBy :: Ord a => (b -> a) -> b -> b -> Ordering
  21 +compareBy f x y = compare (f x) (f y)
  22 +
  23 +
20 24 newtype TaskState = TaskState Text
21 25 deriving (ToHtml, IsString)
22 26

0 comments on commit 63fb010

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