summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-28 14:56:52 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-28 14:56:52 +0200
commitd28c483bdba02cf4163e99efcb07f2ee525ddda1 (patch)
treef9becdc79bcb6495e462ec2f17762a63182dbc2a
parentde1513a40da72632b500c710c5254c8e3639b7bd (diff)
downloadbar-d28c483bdba02cf4163e99efcb07f2ee525ddda1.tar
bar-d28c483bdba02cf4163e99efcb07f2ee525ddda1.tar.gz
bar-d28c483bdba02cf4163e99efcb07f2ee525ddda1.tar.bz2
bar-d28c483bdba02cf4163e99efcb07f2ee525ddda1.tar.xz
bar-d28c483bdba02cf4163e99efcb07f2ee525ddda1.zip
Implement list view
-rw-r--r--Application.hs1
-rw-r--r--Foundation.hs5
-rw-r--r--Handler/Common.hs2
-rw-r--r--Handler/InventoryList.hs12
-rw-r--r--bar.cabal3
-rw-r--r--bar.nix2
-rw-r--r--config/routes3
-rw-r--r--templates/inventoryList.cassius51
-rw-r--r--templates/inventoryList.hamlet33
9 files changed, 106 insertions, 6 deletions
diff --git a/Application.hs b/Application.hs
index 3a16e88..aa9422f 100644
--- a/Application.hs
+++ b/Application.hs
@@ -43,6 +43,7 @@ import Handler.DeleteRefItem
43import Handler.Kinds 43import Handler.Kinds
44import Handler.Types 44import Handler.Types
45import Handler.List 45import Handler.List
46import Handler.InventoryList
46 47
47-- This line actually creates our YesodDispatch instance. It is the second half 48-- This line actually creates our YesodDispatch instance. It is the second half
48-- of the call to mkYesodData which occurs in Foundation.hs. Please see the 49-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
diff --git a/Foundation.hs b/Foundation.hs
index 27082fc..8f45202 100644
--- a/Foundation.hs
+++ b/Foundation.hs
@@ -80,9 +80,10 @@ instance Yesod App where
80 80
81 -- Define the menu items of the header. 81 -- Define the menu items of the header.
82 let menuItems = 82 let menuItems =
83 [ MenuItem "Inventory" InventoryListingR 83 [ MenuItem "List" InventoryListR
84 , MenuItem "Table" InventoryListingR
84 , MenuItem "Reference" ReferenceListingR 85 , MenuItem "Reference" ReferenceListingR
85 , MenuItem "List" ListR 86 , MenuItem "Shopping List" ListR
86 ] 87 ]
87 currentMenu = listToMaybe 88 currentMenu = listToMaybe
88 [ menuItemLabel 89 [ menuItemLabel
diff --git a/Handler/Common.hs b/Handler/Common.hs
index 4f02e3c..73ce9ba 100644
--- a/Handler/Common.hs
+++ b/Handler/Common.hs
@@ -11,7 +11,7 @@ module Handler.Common
11 , FormState(..) 11 , FormState(..)
12 , HasFormState(..) 12 , HasFormState(..)
13 , stockSort, referenceSort 13 , stockSort, referenceSort
14 , humanId 14 , humanId, dayFormat
15 ) where 15 ) where
16 16
17import Import hiding ((\\)) 17import Import hiding ((\\))
diff --git a/Handler/InventoryList.hs b/Handler/InventoryList.hs
new file mode 100644
index 0000000..518d910
--- /dev/null
+++ b/Handler/InventoryList.hs
@@ -0,0 +1,12 @@
1module Handler.InventoryList where
2
3import Import
4import Handler.Common
5
6import Data.Time.Calendar
7
8getInventoryListR :: Handler Html
9getInventoryListR = do
10 (stockSort -> stock) <- runDB $ withTypes =<< selectList [] []
11 today <- utctDay <$> liftIO getCurrentTime
12 defaultLayout $(widgetFile "inventoryList")
diff --git a/bar.cabal b/bar.cabal
index 863279a..1cb254f 100644
--- a/bar.cabal
+++ b/bar.cabal
@@ -1,5 +1,5 @@
1name: bar 1name: bar
2version: 0.3.0 2version: 0.4.0
3cabal-version: >= 1.8 3cabal-version: >= 1.8
4build-type: Simple 4build-type: Simple
5 5
@@ -34,6 +34,7 @@ library
34 Handler.Kinds 34 Handler.Kinds
35 Handler.Types 35 Handler.Types
36 Handler.List 36 Handler.List
37 Handler.InventoryList
37 38
38 if flag(dev) || flag(library-only) 39 if flag(dev) || flag(library-only)
39 cpp-options: -DDEVELOPMENT 40 cpp-options: -DDEVELOPMENT
diff --git a/bar.nix b/bar.nix
index 072231b..9cd039c 100644
--- a/bar.nix
+++ b/bar.nix
@@ -10,7 +10,7 @@
10}: 10}:
11mkDerivation { 11mkDerivation {
12 pname = "bar"; 12 pname = "bar";
13 version = "0.3.0"; 13 version = "0.4.0";
14 src = ./.; 14 src = ./.;
15 isLibrary = true; 15 isLibrary = true;
16 isExecutable = true; 16 isExecutable = true;
diff --git a/config/routes b/config/routes
index 5024ab1..1ad940d 100644
--- a/config/routes
+++ b/config/routes
@@ -14,4 +14,5 @@
14/types TypesR GET 14/types TypesR GET
15/type TypeR GET 15/type TypeR GET
16 16
17/list ListR GET POST 17/shop ListR GET POST
18/list InventoryListR GET
diff --git a/templates/inventoryList.cassius b/templates/inventoryList.cassius
new file mode 100644
index 0000000..edb9feb
--- /dev/null
+++ b/templates/inventoryList.cassius
@@ -0,0 +1,51 @@
1body > ul
2 list-style-type: none
3 margin: 0
4 padding: 0
5 li
6 padding: 0.25em
7 margin: 0
8 .kindType
9 color: inherit
10 .type
11 color: #aaa
12 .type::before
13 content: "("
14 .type::after
15 content: ")"
16 .info
17 list-style-type: none
18 margin: 0
19 padding: 0
20 li
21 display:inline-table
22 border-collapse: collapse
23 div
24 display: table-row
25 div
26 display: table-cell
27 background-color: #ddd
28 border-right:1px solid #999
29 padding: 0.25em
30 div:first-child
31 border-radius: 0.5em 0 0 0.25em
32 div:last-child
33 border-right-style: none
34 border-radius: 0 0.25em 0.5em 0
35 li.content
36 display:inline-block
37 background-color: #ddd
38 padding: 0.25em
39 border-radius: 0.5em 0.25em
40 li
41 margin-bottom:0.5em
42 li:last-child
43 margin-bottom:0
44
45.expireMonth
46 color: #995e00
47.expireWeek
48 color: #994000
49.expired
50 color: #990000
51 text-decoration: line-through
diff --git a/templates/inventoryList.hamlet b/templates/inventoryList.hamlet
new file mode 100644
index 0000000..9bf48f1
--- /dev/null
+++ b/templates/inventoryList.hamlet
@@ -0,0 +1,33 @@
1<ul>
2 $forall WithType (Entity itemId Item{..}) itemType <- stock
3 <li .color>
4 <div .kindType>
5 <span .kind>#{itemKind}
6 <span .type>#{itemType}
7 <ul .info>
8 $case itemBought
9 $of DateKnown d
10 <li>
11 <div>
12 <div>Bought
13 <div>#{dayFormat d}
14 $of _
15 $case itemExpires
16 $of DateKnown d
17 <li>
18 <div>
19 <div>Expires
20 <div :d < today:.expired :d < addDays 7 today:.expireWeek :d < addGregorianMonthsRollOver 1 today:.expireMonth>
21 #{dayFormat d}
22 $of _
23 $case itemOpened
24 $of DateKnown d
25 <li>
26 <div>
27 <div>Opened
28 <div>#{dayFormat d}
29 $of DateUnknown
30 <li .content>Open
31 $of _
32 $if itemRunningLow
33 <li .content>Running low