module Simulation.Aivika.Experiment.Base.ExperimentSpecsView
(ExperimentSpecsView(..),
defaultExperimentSpecsView) where
import Control.Monad
import Control.Monad.Trans
import Data.Monoid
import Simulation.Aivika.Experiment.Types
import Simulation.Aivika.Experiment.Base.WebPageRenderer
import Simulation.Aivika.Experiment.Base.HtmlWriter
import Simulation.Aivika.Experiment.Base.ExperimentWriter
import Simulation.Aivika.Experiment.Base.ExperimentSpecsWriter
data ExperimentSpecsView =
ExperimentSpecsView { experimentSpecsTitle :: String,
experimentSpecsDescription :: String,
experimentSpecsWriter :: ExperimentSpecsWriter
}
defaultExperimentSpecsView :: ExperimentSpecsView
defaultExperimentSpecsView =
ExperimentSpecsView { experimentSpecsTitle = "Experiment Specs",
experimentSpecsDescription = "It shows the experiment specs.",
experimentSpecsWriter = defaultExperimentSpecsWriter }
instance ExperimentView ExperimentSpecsView (WebPageRenderer a) where
outputView v =
let reporter exp renderer dir =
do st <- newExperimentSpecs v exp
let context =
WebPageContext $
WebPageWriter { reporterWriteTOCHtml = experimentSpecsTOCHtml st,
reporterWriteHtml = experimentSpecsHtml st }
return ExperimentReporter { reporterInitialise = return (),
reporterFinalise = return (),
reporterSimulate = const $ return mempty,
reporterContext = context }
in ExperimentGenerator { generateReporter = reporter }
data ExperimentSpecsViewState =
ExperimentSpecsViewState { experimentSpecsView :: ExperimentSpecsView,
experimentSpecsExperiment :: Experiment }
newExperimentSpecs :: ExperimentSpecsView -> Experiment -> ExperimentWriter ExperimentSpecsViewState
newExperimentSpecs view exp =
return ExperimentSpecsViewState { experimentSpecsView = view,
experimentSpecsExperiment = exp }
experimentSpecsHtml :: ExperimentSpecsViewState -> Int -> HtmlWriter ()
experimentSpecsHtml st index =
do header st index
let writer = experimentSpecsWriter (experimentSpecsView st)
write = experimentSpecsWrite writer
exp = experimentSpecsExperiment st
write writer exp
header :: ExperimentSpecsViewState -> Int -> HtmlWriter ()
header st index =
do writeHtmlHeader3WithId ("id" ++ show index) $
writeHtmlText (experimentSpecsTitle $ experimentSpecsView st)
let description = experimentSpecsDescription $ experimentSpecsView st
unless (null description) $
writeHtmlParagraph $
writeHtmlText description
experimentSpecsTOCHtml :: ExperimentSpecsViewState -> Int -> HtmlWriter ()
experimentSpecsTOCHtml st index =
writeHtmlListItem $
writeHtmlLink ("#id" ++ show index) $
writeHtmlText (experimentSpecsTitle $ experimentSpecsView st)