{-# LANGUAGE MultiParamTypeClasses #-}
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 { ExperimentSpecsView -> String
experimentSpecsTitle :: String,
ExperimentSpecsView -> String
experimentSpecsDescription :: String,
ExperimentSpecsView -> ExperimentSpecsWriter
experimentSpecsWriter :: ExperimentSpecsWriter
}
defaultExperimentSpecsView :: ExperimentSpecsView
defaultExperimentSpecsView :: ExperimentSpecsView
defaultExperimentSpecsView =
ExperimentSpecsView { experimentSpecsTitle :: String
experimentSpecsTitle = String
"Experiment Specs",
experimentSpecsDescription :: String
experimentSpecsDescription = String
"It shows the experiment specs.",
experimentSpecsWriter :: ExperimentSpecsWriter
experimentSpecsWriter = ExperimentSpecsWriter
defaultExperimentSpecsWriter }
instance ExperimentView ExperimentSpecsView (WebPageRenderer a) where
outputView :: ExperimentSpecsView -> ExperimentGenerator (WebPageRenderer a)
outputView ExperimentSpecsView
v =
let reporter :: Experiment
-> p
-> p
-> ExperimentWriter (ExperimentReporter (WebPageRenderer a))
reporter Experiment
exp p
renderer p
dir =
do ExperimentSpecsViewState
st <- ExperimentSpecsView
-> Experiment -> ExperimentWriter ExperimentSpecsViewState
newExperimentSpecs ExperimentSpecsView
v Experiment
exp
let context :: ExperimentContext (WebPageRenderer a)
context =
forall a. WebPageWriter -> ExperimentContext (WebPageRenderer a)
WebPageContext forall a b. (a -> b) -> a -> b
$
WebPageWriter { reporterWriteTOCHtml :: Int -> HtmlWriter ()
reporterWriteTOCHtml = ExperimentSpecsViewState -> Int -> HtmlWriter ()
experimentSpecsTOCHtml ExperimentSpecsViewState
st,
reporterWriteHtml :: Int -> HtmlWriter ()
reporterWriteHtml = ExperimentSpecsViewState -> Int -> HtmlWriter ()
experimentSpecsHtml ExperimentSpecsViewState
st }
forall (m :: * -> *) a. Monad m => a -> m a
return ExperimentReporter { reporterInitialise :: ExperimentMonad (WebPageRenderer a) ()
reporterInitialise = forall (m :: * -> *) a. Monad m => a -> m a
return (),
reporterFinalise :: ExperimentMonad (WebPageRenderer a) ()
reporterFinalise = forall (m :: * -> *) a. Monad m => a -> m a
return (),
reporterSimulate :: ExperimentData -> Composite ()
reporterSimulate = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty,
reporterContext :: ExperimentContext (WebPageRenderer a)
reporterContext = forall {a}. ExperimentContext (WebPageRenderer a)
context }
in ExperimentGenerator { generateReporter :: Experiment
-> WebPageRenderer a
-> ExperimentEnvironment (WebPageRenderer a)
-> ExperimentMonad
(WebPageRenderer a) (ExperimentReporter (WebPageRenderer a))
generateReporter = forall {p} {p} {a}.
Experiment
-> p
-> p
-> ExperimentWriter (ExperimentReporter (WebPageRenderer a))
reporter }
data ExperimentSpecsViewState =
ExperimentSpecsViewState { ExperimentSpecsViewState -> ExperimentSpecsView
experimentSpecsView :: ExperimentSpecsView,
ExperimentSpecsViewState -> Experiment
experimentSpecsExperiment :: Experiment }
newExperimentSpecs :: ExperimentSpecsView -> Experiment -> ExperimentWriter ExperimentSpecsViewState
newExperimentSpecs :: ExperimentSpecsView
-> Experiment -> ExperimentWriter ExperimentSpecsViewState
newExperimentSpecs ExperimentSpecsView
view Experiment
exp =
forall (m :: * -> *) a. Monad m => a -> m a
return ExperimentSpecsViewState { experimentSpecsView :: ExperimentSpecsView
experimentSpecsView = ExperimentSpecsView
view,
experimentSpecsExperiment :: Experiment
experimentSpecsExperiment = Experiment
exp }
experimentSpecsHtml :: ExperimentSpecsViewState -> Int -> HtmlWriter ()
experimentSpecsHtml :: ExperimentSpecsViewState -> Int -> HtmlWriter ()
experimentSpecsHtml ExperimentSpecsViewState
st Int
index =
do ExperimentSpecsViewState -> Int -> HtmlWriter ()
header ExperimentSpecsViewState
st Int
index
let writer :: ExperimentSpecsWriter
writer = ExperimentSpecsView -> ExperimentSpecsWriter
experimentSpecsWriter (ExperimentSpecsViewState -> ExperimentSpecsView
experimentSpecsView ExperimentSpecsViewState
st)
write :: ExperimentSpecsWriter -> Experiment -> HtmlWriter ()
write = ExperimentSpecsWriter
-> ExperimentSpecsWriter -> Experiment -> HtmlWriter ()
experimentSpecsWrite ExperimentSpecsWriter
writer
exp :: Experiment
exp = ExperimentSpecsViewState -> Experiment
experimentSpecsExperiment ExperimentSpecsViewState
st
ExperimentSpecsWriter -> Experiment -> HtmlWriter ()
write ExperimentSpecsWriter
writer Experiment
exp
header :: ExperimentSpecsViewState -> Int -> HtmlWriter ()
ExperimentSpecsViewState
st Int
index =
do String -> HtmlWriter () -> HtmlWriter ()
writeHtmlHeader3WithId (String
"id" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
index) forall a b. (a -> b) -> a -> b
$
String -> HtmlWriter ()
writeHtmlText (ExperimentSpecsView -> String
experimentSpecsTitle forall a b. (a -> b) -> a -> b
$ ExperimentSpecsViewState -> ExperimentSpecsView
experimentSpecsView ExperimentSpecsViewState
st)
let description :: String
description = ExperimentSpecsView -> String
experimentSpecsDescription forall a b. (a -> b) -> a -> b
$ ExperimentSpecsViewState -> ExperimentSpecsView
experimentSpecsView ExperimentSpecsViewState
st
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
description) forall a b. (a -> b) -> a -> b
$
HtmlWriter () -> HtmlWriter ()
writeHtmlParagraph forall a b. (a -> b) -> a -> b
$
String -> HtmlWriter ()
writeHtmlText String
description
experimentSpecsTOCHtml :: ExperimentSpecsViewState -> Int -> HtmlWriter ()
experimentSpecsTOCHtml :: ExperimentSpecsViewState -> Int -> HtmlWriter ()
experimentSpecsTOCHtml ExperimentSpecsViewState
st Int
index =
HtmlWriter () -> HtmlWriter ()
writeHtmlListItem forall a b. (a -> b) -> a -> b
$
String -> HtmlWriter () -> HtmlWriter ()
writeHtmlLink (String
"#id" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
index) forall a b. (a -> b) -> a -> b
$
String -> HtmlWriter ()
writeHtmlText (ExperimentSpecsView -> String
experimentSpecsTitle forall a b. (a -> b) -> a -> b
$ ExperimentSpecsViewState -> ExperimentSpecsView
experimentSpecsView ExperimentSpecsViewState
st)