summaryrefslogtreecommitdiff
path: root/Model.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-15 16:56:58 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-15 16:56:58 +0100
commit37f0dac79707a0de81ec6364d2704007eefd9289 (patch)
tree21c2fd38be8202f5700477360a59a3173057105a /Model.hs
parentfe5cd6ad6c61eb13ca99acd1b69cd09b84051404 (diff)
downloadbar-37f0dac79707a0de81ec6364d2704007eefd9289.tar
bar-37f0dac79707a0de81ec6364d2704007eefd9289.tar.gz
bar-37f0dac79707a0de81ec6364d2704007eefd9289.tar.bz2
bar-37f0dac79707a0de81ec6364d2704007eefd9289.tar.xz
bar-37f0dac79707a0de81ec6364d2704007eefd9289.zip
Fix sorting
Diffstat (limited to 'Model.hs')
-rw-r--r--Model.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/Model.hs b/Model.hs
index a345f2f..13f18b8 100644
--- a/Model.hs
+++ b/Model.hs
@@ -45,14 +45,18 @@ withType :: ( BaseBackend backend ~ SqlBackend
45withType val = (val `WithType`) . kindType <$> getType val 45withType val = (val `WithType`) . kindType <$> getType val
46 46
47instance Ord Item where 47instance Ord Item where
48 x `compare` y = mconcat 48 x `compare` y = mconcat cmprs
49 [ (isNothing $ itemOpened x) `compare` (isNothing $ itemOpened y) 49 where
50 , itemOpened x `compare` itemOpened y 50 cmprs = [ itemOpened x `compareM` itemOpened y
51 , (isNothing $ itemExpires x) `compare` (isNothing $ itemExpires y) 51 , itemExpires x `compareM` itemExpires y
52 , itemExpires x `compare` itemExpires x 52 , itemKind x `compare` itemKind y
53 , itemKind x `compare` itemKind x 53 , itemBought x `compare` itemBought y
54 , itemBought x `compare` itemBought x 54 ]
55 ] 55
56 compareM (Just _) Nothing = LT
57 compareM Nothing (Just _) = GT
58 compareM (Just a) (Just b) = compare a b
59 compareM _ _ = EQ
56 60
57instance ToJSON Item where 61instance ToJSON Item where
58 toJSON Item{..} = object $ 62 toJSON Item{..} = object $
@@ -124,7 +128,7 @@ toUpdate (ItemDiffs ds) = mconcat $ do
124 DiffOpened d -> (, []) [ ItemOpened =. d ] 128 DiffOpened d -> (, []) [ ItemOpened =. d ]
125 129
126data WithType a = WithType { typedVal :: a, valType :: Text } 130data WithType a = WithType { typedVal :: a, valType :: Text }
127 deriving (Eq, Ord) 131 deriving (Eq, Ord, Show)
128 132
129typeToJSON :: ToJSON a 133typeToJSON :: ToJSON a
130 => Text -- ^ Key for value, if needed 134 => Text -- ^ Key for value, if needed