module Recognize.Data.Entry where
import Data.List
import Ideas.Common.Id
import Recognize.Data.DiagnoseError
import Recognize.Data.Approach
import Recognize.Data.Solution
import Recognize.Data.DiagnoseResult
import Ideas.Text.HTML
import Ideas.Text.HTML.W3CSS
import Ideas.Text.XML
import qualified Text.PrettyPrint.Leijen as PP
data Entry = Entry
{
diagnoses :: [DiagnoseResult]
}
instance Show Entry where
show = show . PP.pretty
instance PP.Pretty Entry where
pretty e = PP.vcat
[ PP.string ("=== Diagnosis " ++ show i ++ " ===")
PP.<$$> PP.indent 2 (PP.pretty d)
| d <- diagnoses e
, let i = getInputId (originalInput d)
]
where
pp s = maybe PP.empty (\x -> PP.string $ s ++ ": " ++ show x)
instance ToXML Entry where
toXML e = makeXML "entry" $ mconcat
[ element "diagnoses"
(map
(\v-> let k = getInputId (originalInput v)
in element "input" ["id" .=. show k, builderXML v])
(diagnoses e)
)
]
instance ToHTML Entry where
toHTML e = container $ background LightGray $ mconcat
[ if null (diagnoses e)
then string "(no diagnoses)"
else toHTML (diagnoses e)
]
categoryAsString :: Entry -> String
categoryAsString e
| null (diagnoses e) = show Unknown
| otherwise = intercalate ", " (map (show . approach) (diagnoses e))