From 9f94013ddc1b6ac7256b9cebcf8685949ce88c34 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 16 Jul 2017 23:31:22 +0200 Subject: Quick Action for running low --- Application.hs | 1 + Handler/LowItem.hs | 11 +++++++++++ bar.cabal | 1 + config/routes | 1 + shell.nix | 2 +- stack.yaml | 2 +- templates/default-layout.cassius | 4 ++-- templates/inventoryListing.cassius | 4 +++- templates/inventoryListing.hamlet | 32 +++++++++++++++++++++++--------- 9 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 Handler/LowItem.hs diff --git a/Application.hs b/Application.hs index 46dc4c1..0f86dd4 100644 --- a/Application.hs +++ b/Application.hs @@ -36,6 +36,7 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, import Handler.InventoryListing import Handler.UpdateItem import Handler.OpenItem +import Handler.LowItem import Handler.DeleteItem import Handler.Item import Handler.ReferenceListing diff --git a/Handler/LowItem.hs b/Handler/LowItem.hs new file mode 100644 index 0000000..969e62a --- /dev/null +++ b/Handler/LowItem.hs @@ -0,0 +1,11 @@ +module Handler.LowItem where + +import Import + +postLowItemR :: ItemId -> Handler TypedContent +postLowItemR itemId = do + result <- fmap (Entity itemId) . runDB $ updateGet itemId [ ItemRunningLow =. True + ] + selectRep $ do + provideJson result + provideRep (redirect $ InventoryListingR :#: itemId :: Handler Html) diff --git a/bar.cabal b/bar.cabal index 0d98dfc..583c277 100644 --- a/bar.cabal +++ b/bar.cabal @@ -26,6 +26,7 @@ library Handler.InventoryListing Handler.UpdateItem Handler.OpenItem + Handler.LowItem Handler.DeleteItem Handler.Item Handler.ReferenceListing diff --git a/config/routes b/config/routes index 1ad940d..57c515f 100644 --- a/config/routes +++ b/config/routes @@ -4,6 +4,7 @@ /inv/#ItemId/edit UpdateItemR GET POST /inv/#ItemId/open OpenItemR POST /inv/#ItemId/delete DeleteItemR POST +/inv/#ItemId/low LowItemR POST /inv/#ItemId ItemR GET PUT PATCH DELETE /ref ReferenceListingR GET POST PUT diff --git a/shell.nix b/shell.nix index c6a13de..b2b6842 100644 --- a/shell.nix +++ b/shell.nix @@ -10,7 +10,7 @@ let drv = haskellPackages.callPackage ./bar.nix {}; in pkgs.stdenv.lib.overrideDerivation drv.env (oldAttrs: { - nativeBuildInputs = oldAttrs.nativeBuildInputs ++ (with pkgs; [ cabal2nix gup ]) ++ (with haskellPackages; [ hlint stack yesod-bin alex ]); + nativeBuildInputs = oldAttrs.nativeBuildInputs ++ (with pkgs; [ cabal2nix gup postgresql ]) ++ (with haskellPackages; [ hlint stack yesod-bin alex ]); shellHook = '' ${oldAttrs.shellHook} export PROMPT_INFO="${oldAttrs.name}" diff --git a/stack.yaml b/stack.yaml index 161b308..eeed1bc 100644 --- a/stack.yaml +++ b/stack.yaml @@ -65,7 +65,7 @@ system-ghc: true # Allow a newer minor version of GHC than the snapshot specifies # compiler-check: newer-minor nix: - #enable: true + enable: false packages: - postgresql - zlib diff --git a/templates/default-layout.cassius b/templates/default-layout.cassius index c622901..31389d8 100644 --- a/templates/default-layout.cassius +++ b/templates/default-layout.cassius @@ -1,4 +1,4 @@ -.main +main min-width: 20em .table, table display: table @@ -62,7 +62,7 @@ table table td, table table th, .table table td, .table table th li:first-child::before content: "" button - width: 6em + width: 8em display: inline-block .sepBelow, .sepAbove border: 2px none #ddd diff --git a/templates/inventoryListing.cassius b/templates/inventoryListing.cassius index 5116667..dc01471 100644 --- a/templates/inventoryListing.cassius +++ b/templates/inventoryListing.cassius @@ -26,4 +26,6 @@ div.itemId padding: 0 margin: 0 input - vertical-align: middle \ No newline at end of file + vertical-align: middle +.actions .td + width: 8em \ No newline at end of file diff --git a/templates/inventoryListing.hamlet b/templates/inventoryListing.hamlet index cc1c9ce..8eee3e7 100644 --- a/templates/inventoryListing.hamlet +++ b/templates/inventoryListing.hamlet @@ -36,12 +36,14 @@
$of DateKnown d #{dayFormat d} + $of DateNever
$case itemExpires $of DateNever
$of DateKnown d #{dayFormat d} + $of DateUnknown
$case itemOpened $of DateKnown d @@ -49,17 +51,29 @@ $of DateUnknown Yes $of DateNever -
-