From b8821e100e0d8b02cde5392a2bb7d5f71428de87 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 15 Sep 2018 15:20:50 +0200 Subject: Disable thermoprint via flag --- Handler/Common.hs | 3 ++- Handler/Common/Types.hs | 2 -- Handler/List.hs | 29 ++++++++++++++++++++--------- 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'Handler') diff --git a/Handler/Common.hs b/Handler/Common.hs index 88cbd8d..11a9431 100644 --- a/Handler/Common.hs +++ b/Handler/Common.hs @@ -1,4 +1,5 @@ -{-# LANGUAGE ApplicativeDo #-} +{-# LANGUAGE ApplicativeDo + #-} module Handler.Common ( inventoryListing diff --git a/Handler/Common/Types.hs b/Handler/Common/Types.hs index 9150f16..491468c 100644 --- a/Handler/Common/Types.hs +++ b/Handler/Common/Types.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE FunctionalDependencies #-} - module Handler.Common.Types where import Import diff --git a/Handler/List.hs b/Handler/List.hs index 522f6f5..a2194ba 100644 --- a/Handler/List.hs +++ b/Handler/List.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE PatternGuards #-} - module Handler.List where import Import @@ -12,8 +10,18 @@ import qualified Data.Map as Map import qualified Data.Text as Text import qualified Data.Text.Lazy as Lazy.Text +#ifdef THERMOPRINT import Thermoprint.Client +mkPrintout :: Set (WithType Text) -> Printout +mkPrintout list = Printout ps + where + ps = Map.foldMapWithKey (fmap (pure . Paragraph . pure . Cooked) . toLines) $ group list + group = Map.fromListWith (<>) . fmap (\(kind `WithType` t) -> (t, Set.singleton kind)) . Set.toAscList + toLines t (Set.toAscList -> kinds) = either id Line . text . Lazy.Text.fromStrict . Text.unlines $ + pure t ++ map (" - " <>) kinds +#endif + list :: Handler (Set (WithType Text)) list = runDB $ do today <- liftIO $ utctDay <$> getCurrentTime @@ -34,14 +42,8 @@ list = runDB $ do return $ Set.map (fmap referenceKind) references' -mkPrintout :: Set (WithType Text) -> Printout -mkPrintout list = Printout ps - where - ps = Map.foldMapWithKey (fmap (pure . Paragraph . pure . Cooked) . toLines) $ group list - group = Map.fromListWith (<>) . fmap (\(kind `WithType` t) -> (t, Set.singleton kind)) . Set.toAscList - toLines t (Set.toAscList -> kinds) = either id Line . text . Lazy.Text.fromStrict . Text.unlines $ - pure t ++ map (" - " <>) kinds +#ifdef THERMOPRINT getListR, postListR :: Handler TypedContent getListR = postListR postListR = do @@ -99,3 +101,12 @@ postListR = do selectRep $ do provideJson $ typeToJSON "item" <$> Set.toAscList list provideRep $ defaultLayout $(widgetFile "list") +#else +getListR, postListR :: Handler TypedContent +getListR = postListR +postListR = do + list <- list + selectRep $ do + provideJson $ typeToJSON "item" <$> Set.toAscList list + provideRep $ defaultLayout $(widgetFile "list-no-thermoprint") +#endif -- cgit v1.2.3