summaryrefslogtreecommitdiff
path: root/Handler
diff options
context:
space:
mode:
Diffstat (limited to 'Handler')
-rw-r--r--Handler/Common.hs13
-rw-r--r--Handler/InventoryListing.hs17
-rw-r--r--Handler/List.hs2
3 files changed, 28 insertions, 4 deletions
diff --git a/Handler/Common.hs b/Handler/Common.hs
index 990732d..65e6ce1 100644
--- a/Handler/Common.hs
+++ b/Handler/Common.hs
@@ -11,13 +11,15 @@ module Handler.Common
11 , FormState(..) 11 , FormState(..)
12 , HasFormState(..) 12 , HasFormState(..)
13 , stockSort, referenceSort 13 , stockSort, referenceSort
14 , humanId
14 ) where 15 ) where
15 16
16import Import 17import Import hiding ((\\))
17 18
18import Data.Unique 19import Data.Unique
19 20
20import qualified Data.Text as Text 21import qualified Data.Text as Text
22import qualified Data.ByteString.Char8 as CBS
21 23
22import Data.Set (Set) 24import Data.Set (Set)
23import qualified Data.Set as Set 25import qualified Data.Set as Set
@@ -28,10 +30,19 @@ import Handler.Common.Types
28 30
29import Text.Julius (RawJS(..)) 31import Text.Julius (RawJS(..))
30 32
33import Database.Persist.Sql (fromSqlKey)
34import qualified Web.Hashids as HID
35import Data.List ((\\))
36
31import Data.List.NonEmpty (NonEmpty) 37import Data.List.NonEmpty (NonEmpty)
32import Data.Semigroup hiding (First(..)) 38import Data.Semigroup hiding (First(..))
33import Data.Monoid (First(..)) 39import Data.Monoid (First(..))
34 40
41humanId :: ItemId -> Text
42humanId = Text.pack . CBS.unpack . HID.encode ctx . fromIntegral . fromSqlKey
43 where
44 ctx = HID.createHashidsContext "ItemId" 3 $ (['0'..'9'] ++ ['a'..'z']) \\ ['0', 'l', 'v', '2']
45
35dayFormat :: Day -> String 46dayFormat :: Day -> String
36dayFormat = formatTime defaultTimeLocale "%e. %b %y" 47dayFormat = formatTime defaultTimeLocale "%e. %b %y"
37 48
diff --git a/Handler/InventoryListing.hs b/Handler/InventoryListing.hs
index c2ec5d1..d87512a 100644
--- a/Handler/InventoryListing.hs
+++ b/Handler/InventoryListing.hs
@@ -11,8 +11,21 @@ postInventoryListingR = do
11 case insertResult of 11 case insertResult of
12 FormSuccess (Item{..} `WithType` t) -> runDB $ do 12 FormSuccess (Item{..} `WithType` t) -> runDB $ do
13 upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ] 13 upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ]
14 insert Item{..} 14 newItem <- insert Item{..}
15 return () 15 otherItems <- selectKeysList [ ItemNormKind ==. itemNormKind, ItemId !=. newItem ] []
16 when (not $ null otherItems) . addMessage "insertAmbiguous" $
17 [shamlet|
18 $newline never
19 There are other items of the same kind.
20 <ul>
21 $forall other <- otherItems
22 <li .itemId>#{humanId other}
23 |]
24 addMessage "insertSuccess" [shamlet|
25 $newline never
26 Inserted new item as #
27 <span .itemId>#{humanId newItem}
28 |]
16 FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors 29 FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors
17 _ -> return () 30 _ -> return ()
18 31
diff --git a/Handler/List.hs b/Handler/List.hs
index 4209651..7ab4ebe 100644
--- a/Handler/List.hs
+++ b/Handler/List.hs
@@ -64,7 +64,7 @@ postListR = do
64 case printResult of 64 case printResult of
65 FormSuccess pId -> do 65 FormSuccess pId -> do
66 (JobId jId) <- jobCreate (Just pId) $ mkPrintout list 66 (JobId jId) <- jobCreate (Just pId) $ mkPrintout list
67 addMessage "printSuccess" . toHtml $ "List is printing as job #" <> tshow jId 67 addMessage "printSuccess" [shamlet|List is printing as job ##{jId}|]
68 FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors 68 FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors
69 _ -> return () 69 _ -> return ()
70 70