diff options
Diffstat (limited to 'Handler/Common.hs')
-rw-r--r-- | Handler/Common.hs | 13 |
1 files changed, 12 insertions, 1 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 | ||