From d28c483bdba02cf4163e99efcb07f2ee525ddda1 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 28 Mar 2017 14:56:52 +0200 Subject: Implement list view --- Application.hs | 1 + Foundation.hs | 5 ++-- Handler/Common.hs | 2 +- Handler/InventoryList.hs | 12 ++++++++++ bar.cabal | 3 ++- bar.nix | 2 +- config/routes | 3 ++- templates/inventoryList.cassius | 51 +++++++++++++++++++++++++++++++++++++++++ templates/inventoryList.hamlet | 33 ++++++++++++++++++++++++++ 9 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 Handler/InventoryList.hs create mode 100644 templates/inventoryList.cassius create mode 100644 templates/inventoryList.hamlet 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 import Handler.Kinds import Handler.Types import Handler.List +import Handler.InventoryList -- This line actually creates our YesodDispatch instance. It is the second half -- 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 -- Define the menu items of the header. let menuItems = - [ MenuItem "Inventory" InventoryListingR + [ MenuItem "List" InventoryListR + , MenuItem "Table" InventoryListingR , MenuItem "Reference" ReferenceListingR - , MenuItem "List" ListR + , MenuItem "Shopping List" ListR ] currentMenu = listToMaybe [ 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 , FormState(..) , HasFormState(..) , stockSort, referenceSort - , humanId + , humanId, dayFormat ) where import 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 @@ +module Handler.InventoryList where + +import Import +import Handler.Common + +import Data.Time.Calendar + +getInventoryListR :: Handler Html +getInventoryListR = do + (stockSort -> stock) <- runDB $ withTypes =<< selectList [] [] + today <- utctDay <$> liftIO getCurrentTime + 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 @@ name: bar -version: 0.3.0 +version: 0.4.0 cabal-version: >= 1.8 build-type: Simple @@ -34,6 +34,7 @@ library Handler.Kinds Handler.Types Handler.List + Handler.InventoryList if flag(dev) || flag(library-only) 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 @@ }: mkDerivation { pname = "bar"; - version = "0.3.0"; + version = "0.4.0"; src = ./.; isLibrary = true; isExecutable = true; diff --git a/config/routes b/config/routes index 5024ab1..1ad940d 100644 --- a/config/routes +++ b/config/routes @@ -14,4 +14,5 @@ /types TypesR GET /type TypeR GET -/list ListR GET POST +/shop ListR GET POST +/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 @@ +body > ul + list-style-type: none + margin: 0 + padding: 0 + li + padding: 0.25em + margin: 0 + .kindType + color: inherit + .type + color: #aaa + .type::before + content: "(" + .type::after + content: ")" + .info + list-style-type: none + margin: 0 + padding: 0 + li + display:inline-table + border-collapse: collapse + div + display: table-row + div + display: table-cell + background-color: #ddd + border-right:1px solid #999 + padding: 0.25em + div:first-child + border-radius: 0.5em 0 0 0.25em + div:last-child + border-right-style: none + border-radius: 0 0.25em 0.5em 0 + li.content + display:inline-block + background-color: #ddd + padding: 0.25em + border-radius: 0.5em 0.25em + li + margin-bottom:0.5em + li:last-child + margin-bottom:0 + +.expireMonth + color: #995e00 +.expireWeek + color: #994000 +.expired + color: #990000 + 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 @@ +