From 299731a0cef7462dd8c17bde7ba1a4aeb6f211cd Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 15 Mar 2017 20:02:53 +0100 Subject: Implement inventory ids --- Handler/Common.hs | 7 +++++++ Handler/InventoryListing.hs | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'Handler') diff --git a/Handler/Common.hs b/Handler/Common.hs index a1ae34b..aacab92 100644 --- a/Handler/Common.hs +++ b/Handler/Common.hs @@ -11,6 +11,7 @@ module Handler.Common , FormState(..) , HasFormState(..) , stockSort, referenceSort + , humanId ) where import Import @@ -28,6 +29,12 @@ import Handler.Common.Types import Text.Julius (RawJS(..)) +import qualified Codec.Crockford as Crockford (encode) +import Database.Persist.Sql (fromSqlKey) + +humanId :: ItemId -> String +humanId = Crockford.encode . fromSqlKey + dayFormat :: Day -> String dayFormat = formatTime defaultTimeLocale "%e. %b %y" diff --git a/Handler/InventoryListing.hs b/Handler/InventoryListing.hs index c2ec5d1..d5252a1 100644 --- a/Handler/InventoryListing.hs +++ b/Handler/InventoryListing.hs @@ -11,8 +11,8 @@ postInventoryListingR = do case insertResult of FormSuccess (Item{..} `WithType` t) -> runDB $ do upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ] - insert Item{..} - return () + newItem <- insert Item{..} + addMessage "insertSuccess" [hamlet|Inserted new item as #{humanId newItem}|] FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors _ -> return () -- cgit v1.2.3