-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
87 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-} | ||
module Handler.Display where | ||
|
||
import Yesod.Json (jsonList, Json(..)) | ||
import Yesod.Content | ||
|
||
import Tap | ||
import Tap.Redis | ||
import Control.Concurrent.MonadIO (liftIO, MonadIO) | ||
import Database.Redis.Redis (Message(..)) | ||
import qualified Data.ByteString as B | ||
import qualified Data.Foldable as F | ||
import qualified Data.Sequence as S | ||
import qualified Data.List as L | ||
|
||
-- do Tap _ messages <- getYesod | ||
-- queue <- liftIO $ clearChannel messages | ||
|
||
--getDisplayTap :: Handler (ContentType, Content) | ||
getDisplayTap :: Handler RepJson | ||
getDisplayTap = do | ||
Tap _ mstore <- getYesod | ||
queue <- liftIO $ clearChannel mstore | ||
--return (typeJson, toContent $ jsonArrayify queue) | ||
return $ RepJson $ (toContent . jsonArrayify) queue | ||
|
||
|
||
jsonArrayify :: MessageStore -> B.ByteString | ||
jsonArrayify queue = | ||
let msgList = (buildList $ getMessage `fmap` queue) | ||
csml = L.intersperse "," msgList in | ||
B.concat $ ["["] ++ csml ++ ["]"] | ||
where getMessage (MMessage _ s) = s | ||
getMessage _ = "" | ||
buildList = F.foldr (:) [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
/robots.txt RobotsR GET | ||
|
||
/ RootR GET | ||
|
||
/tap DisplayTap GET |