blob: c2cfdd533cfff042dcc92328e7d701aa82845c99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.CaseInsensitive as CI
import Data.List (sortBy)
import Data.Maybe
import qualified Data.Map as Map
import Data.Monoid ((<>))
import Data.Ord (comparing) -- , Down(..))
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.Yaml
import System.Environment (getArgs)
data Client = Client {
_assignee :: Text
, _status :: Text
, _clientname :: Text
, _filename :: Text -- should be ByteString?
}
toClient :: Map.Map Text Text -> Client
toClient ymap = Client user status client filename
where
user = fromMaybe "ERROR" (Map.lookup "AssignedTo" ymap)
status = fromMaybe "ERROR" (Map.lookup "Status" ymap)
client = fromMaybe "ERROR" (Map.lookup "ClientName" ymap)
filename = fromMaybe "ERROR" (Map.lookup "filename" ymap)
formatClient :: Client -> Text
formatClient c = T.concat [pad 10 (_assignee c), pad 7 (_status c), _clientname c, " (", _filename c, ")"]
where
pad x = T.justifyLeft x ' '
printIfNonEmpty :: [Client] -> IO ()
printIfNonEmpty = mapM_ (TIO.putStrLn . formatClient)
main :: IO ()
main = do
yamlcache <- decodeFile "/home/report/tmp/yamlcache.yaml"
args <- fmap (map T.pack) getArgs
let ymap = fromJust yamlcache -- fix that
cs = map toClient ymap
statusopen = cs
useropen = if null args then statusopen else filter (\m -> elem (_assignee m) args) statusopen
uoclients = filter (\m -> "Client/" `T.isPrefixOf` (_filename m) && T.find (=='/') (T.drop 7 (_filename m)) == Nothing) useropen
printIfNonEmpty (sortBy (comparing (CI.mk . _clientname) <> comparing _assignee <> flip (comparing (_status))) uoclients) -- Down
|