diff options
Diffstat (limited to 'Handler')
-rw-r--r-- | Handler/Common.hs | 13 | ||||
-rw-r--r-- | Handler/InventoryListing.hs | 17 | ||||
-rw-r--r-- | Handler/List.hs | 2 |
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 | ||
16 | import Import | 17 | import Import hiding ((\\)) |
17 | 18 | ||
18 | import Data.Unique | 19 | import Data.Unique |
19 | 20 | ||
20 | import qualified Data.Text as Text | 21 | import qualified Data.Text as Text |
22 | import qualified Data.ByteString.Char8 as CBS | ||
21 | 23 | ||
22 | import Data.Set (Set) | 24 | import Data.Set (Set) |
23 | import qualified Data.Set as Set | 25 | import qualified Data.Set as Set |
@@ -28,10 +30,19 @@ import Handler.Common.Types | |||
28 | 30 | ||
29 | import Text.Julius (RawJS(..)) | 31 | import Text.Julius (RawJS(..)) |
30 | 32 | ||
33 | import Database.Persist.Sql (fromSqlKey) | ||
34 | import qualified Web.Hashids as HID | ||
35 | import Data.List ((\\)) | ||
36 | |||
31 | import Data.List.NonEmpty (NonEmpty) | 37 | import Data.List.NonEmpty (NonEmpty) |
32 | import Data.Semigroup hiding (First(..)) | 38 | import Data.Semigroup hiding (First(..)) |
33 | import Data.Monoid (First(..)) | 39 | import Data.Monoid (First(..)) |
34 | 40 | ||
41 | humanId :: ItemId -> Text | ||
42 | humanId = 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 | |||
35 | dayFormat :: Day -> String | 46 | dayFormat :: Day -> String |
36 | dayFormat = formatTime defaultTimeLocale "%e. %b %y" | 47 | dayFormat = 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 | ||