diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-15 21:39:15 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-03-15 21:39:15 +0100 |
commit | 3d828feba67f21ae62d1e6eb598a22ffaebf1174 (patch) | |
tree | f81437dab5090906362404b5df61aa5ab1f5203a | |
parent | 299731a0cef7462dd8c17bde7ba1a4aeb6f211cd (diff) | |
download | bar-3d828feba67f21ae62d1e6eb598a22ffaebf1174.tar bar-3d828feba67f21ae62d1e6eb598a22ffaebf1174.tar.gz bar-3d828feba67f21ae62d1e6eb598a22ffaebf1174.tar.bz2 bar-3d828feba67f21ae62d1e6eb598a22ffaebf1174.tar.xz bar-3d828feba67f21ae62d1e6eb598a22ffaebf1174.zip |
Better ids & warnings
-rw-r--r-- | Handler/Common.hs | 12 | ||||
-rw-r--r-- | Handler/InventoryListing.hs | 15 | ||||
-rw-r--r-- | Handler/List.hs | 2 | ||||
-rw-r--r-- | bar.cabal | 2 | ||||
-rw-r--r-- | bar.nix | 16 | ||||
-rw-r--r-- | templates/default-layout.cassius | 19 |
6 files changed, 50 insertions, 16 deletions
diff --git a/Handler/Common.hs b/Handler/Common.hs index aacab92..c2788e8 100644 --- a/Handler/Common.hs +++ b/Handler/Common.hs | |||
@@ -14,11 +14,12 @@ module Handler.Common | |||
14 | , humanId | 14 | , humanId |
15 | ) where | 15 | ) where |
16 | 16 | ||
17 | import Import | 17 | import Import hiding ((\\)) |
18 | 18 | ||
19 | import Data.Unique | 19 | import Data.Unique |
20 | 20 | ||
21 | import qualified Data.Text as Text | 21 | import qualified Data.Text as Text |
22 | import qualified Data.ByteString.Char8 as CBS | ||
22 | 23 | ||
23 | import Data.Set (Set) | 24 | import Data.Set (Set) |
24 | import qualified Data.Set as Set | 25 | import qualified Data.Set as Set |
@@ -29,11 +30,14 @@ import Handler.Common.Types | |||
29 | 30 | ||
30 | import Text.Julius (RawJS(..)) | 31 | import Text.Julius (RawJS(..)) |
31 | 32 | ||
32 | import qualified Codec.Crockford as Crockford (encode) | ||
33 | import Database.Persist.Sql (fromSqlKey) | 33 | import Database.Persist.Sql (fromSqlKey) |
34 | import qualified Web.Hashids as HID | ||
35 | import Data.List ((\\)) | ||
34 | 36 | ||
35 | humanId :: ItemId -> String | 37 | humanId :: ItemId -> Text |
36 | humanId = Crockford.encode . fromSqlKey | 38 | humanId = Text.pack . CBS.unpack . HID.encode ctx . fromIntegral . fromSqlKey |
39 | where | ||
40 | ctx = HID.createHashidsContext "ItemId" 3 $ (['0'..'9'] ++ ['a'..'z']) \\ ['0', 'l', 'v', '2'] | ||
37 | 41 | ||
38 | dayFormat :: Day -> String | 42 | dayFormat :: Day -> String |
39 | dayFormat = formatTime defaultTimeLocale "%e. %b %y" | 43 | dayFormat = formatTime defaultTimeLocale "%e. %b %y" |
diff --git a/Handler/InventoryListing.hs b/Handler/InventoryListing.hs index d5252a1..d87512a 100644 --- a/Handler/InventoryListing.hs +++ b/Handler/InventoryListing.hs | |||
@@ -12,7 +12,20 @@ postInventoryListingR = do | |||
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 | newItem <- insert Item{..} | 14 | newItem <- insert Item{..} |
15 | addMessage "insertSuccess" [hamlet|Inserted new item as #{humanId newItem}|] | 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 70f323a..21b735b 100644 --- a/Handler/List.hs +++ b/Handler/List.hs | |||
@@ -50,7 +50,7 @@ postListR = do | |||
50 | case printResult of | 50 | case printResult of |
51 | FormSuccess pId -> do | 51 | FormSuccess pId -> do |
52 | (JobId jId) <- jobCreate (Just pId) $ mkPrintout list | 52 | (JobId jId) <- jobCreate (Just pId) $ mkPrintout list |
53 | addMessage "printSuccess" . toHtml $ "List is printing as job #" <> tshow jId | 53 | addMessage "printSuccess" [shamlet|List is printing as job ##{jId}|] |
54 | FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors | 54 | FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors |
55 | _ -> return () | 55 | _ -> return () |
56 | 56 | ||
@@ -105,7 +105,7 @@ library | |||
105 | , mtl | 105 | , mtl |
106 | , lens | 106 | , lens |
107 | , thermoprint-client | 107 | , thermoprint-client |
108 | , crockford | 108 | , hashids |
109 | 109 | ||
110 | executable bar | 110 | executable bar |
111 | if flag(library-only) | 111 | if flag(library-only) |
@@ -1,12 +1,12 @@ | |||
1 | { mkDerivation, aeson, base, bytestring, case-insensitive | 1 | { mkDerivation, aeson, base, bytestring, case-insensitive |
2 | , classy-prelude, classy-prelude-conduit, classy-prelude-yesod | 2 | , classy-prelude, classy-prelude-conduit, classy-prelude-yesod |
3 | , conduit, containers, crockford, data-default, directory | 3 | , conduit, containers, data-default, directory, fast-logger |
4 | , fast-logger, file-embed, hjsmin, http-conduit, lens | 4 | , file-embed, hashids, hjsmin, http-conduit, lens, monad-control |
5 | , monad-control, monad-logger, mtl, persistent | 5 | , monad-logger, mtl, persistent, persistent-postgresql |
6 | , persistent-postgresql, persistent-template, safe, shakespeare | 6 | , persistent-template, safe, shakespeare, stdenv, template-haskell |
7 | , stdenv, template-haskell, text, thermoprint-client, time | 7 | , text, thermoprint-client, time, unordered-containers, vector, wai |
8 | , unordered-containers, vector, wai, wai-extra, wai-logger, warp | 8 | , wai-extra, wai-logger, warp, yaml, yesod, yesod-auth, yesod-core |
9 | , yaml, yesod, yesod-auth, yesod-core, yesod-form, yesod-static | 9 | , yesod-form, yesod-static |
10 | }: | 10 | }: |
11 | mkDerivation { | 11 | mkDerivation { |
12 | pname = "bar"; | 12 | pname = "bar"; |
@@ -17,7 +17,7 @@ mkDerivation { | |||
17 | libraryHaskellDepends = [ | 17 | libraryHaskellDepends = [ |
18 | aeson base bytestring case-insensitive classy-prelude | 18 | aeson base bytestring case-insensitive classy-prelude |
19 | classy-prelude-conduit classy-prelude-yesod conduit containers | 19 | classy-prelude-conduit classy-prelude-yesod conduit containers |
20 | crockford data-default directory fast-logger file-embed hjsmin | 20 | data-default directory fast-logger file-embed hashids hjsmin |
21 | http-conduit lens monad-control monad-logger mtl persistent | 21 | http-conduit lens monad-control monad-logger mtl persistent |
22 | persistent-postgresql persistent-template safe shakespeare | 22 | persistent-postgresql persistent-template safe shakespeare |
23 | template-haskell text thermoprint-client time unordered-containers | 23 | template-haskell text thermoprint-client time unordered-containers |
diff --git a/templates/default-layout.cassius b/templates/default-layout.cassius index 61a4046..da76e28 100644 --- a/templates/default-layout.cassius +++ b/templates/default-layout.cassius | |||
@@ -32,11 +32,12 @@ | |||
32 | padding: 0.25em | 32 | padding: 0.25em |
33 | color: #aaa | 33 | color: #aaa |
34 | .itemId | 34 | .itemId |
35 | font-family: monospace | ||
36 | div.itemId | ||
35 | display: table-cell | 37 | display: table-cell |
36 | text-align: left | 38 | text-align: left |
37 | padding: 0.25em | 39 | padding: 0.25em |
38 | color: #aaa | 40 | color: #aaa |
39 | font-family: monospace | ||
40 | .table .table .td, .table .table .tc, .table .table .th, .table .table .kind | 41 | .table .table .td, .table .table .tc, .table .table .th, .table .table .kind |
41 | padding: 0 | 42 | padding: 0 |
42 | table table td, table table th | 43 | table table td, table table th |
@@ -47,10 +48,26 @@ table table td, table table th | |||
47 | padding: 0 | 48 | padding: 0 |
48 | text-align: center | 49 | text-align: center |
49 | font-weight: bold | 50 | font-weight: bold |
51 | li | ||
52 | margin: 0 0 0.5em 0 | ||
53 | li:last-child | ||
54 | margin: 0 | ||
50 | .formError | 55 | .formError |
51 | color: #800 | 56 | color: #800 |
52 | .printSuccess, .insertSuccess | 57 | .printSuccess, .insertSuccess |
53 | color: #080 | 58 | color: #080 |
59 | .insertAmbiguous | ||
60 | color: inherit | ||
61 | ul | ||
62 | list-style-type: none | ||
63 | li | ||
64 | display: inline | ||
65 | margin: 0 0 0 0 | ||
66 | padding: 0 0 0 0 | ||
67 | li::before | ||
68 | content: ", " | ||
69 | li:first-child::before | ||
70 | content: "" | ||
54 | button | 71 | button |
55 | width: 6em | 72 | width: 6em |
56 | display: inline-block | 73 | display: inline-block |