module DatabaseDesign.Ampersand.Output.ToPandoc.ChapterInterfaces
( chpInterfacesPics
, chpInterfacesBlocks
)
where
import DatabaseDesign.Ampersand.Output.ToPandoc.SharedAmongChapters
import DatabaseDesign.Ampersand.ADL1
import Data.List
import DatabaseDesign.Ampersand.Fspec.Fspec
import DatabaseDesign.Ampersand.Fspec.Switchboard (switchboardAct)
import DatabaseDesign.Ampersand.Output.PandocAux
chpInterfacesPics :: Fspc -> Options -> [Picture]
chpInterfacesPics fSpec flags =
concat [picKnowledgeGraph flags fSpec act : [picSwitchboard flags fSpec act | graphic flags] | act <- fActivities fSpec ]
chpInterfacesBlocks :: Int -> Fspc -> Options -> Blocks
chpInterfacesBlocks lev fSpec flags =
foldr (<>) mempty (map interfaceChap (fActivities fSpec))
where
interfaceChap :: Activity -> Blocks
interfaceChap act
= ( fromList $
header act ++ ifcIntro act
++ (if genGraphics flags then txtKnowledgeGraph act else [])
++ (if graphic flags then txtSwitchboard act else [])
)
header :: Activity ->[Block]
header act = toList (labeledThing flags lev ("chpIfc"++name act) (name act))
ifcIntro :: Activity -> [Block]
ifcIntro act
= purposes2Blocks flags purps
++ifcAutoRules act++
(if genEcaDoc flags then ifcEcaRules act else [])
where purps = purposesDefinedIn fSpec (language flags) fSpec
ifcAutoRules :: Activity -> [Block]
ifcAutoRules act
= case language flags of
Dutch -> [Plain ([Str "Activiteit",Space, Quoted SingleQuote [(Str . name . actRule) act], Space,Str "moet door een gebruiker met rol "]++commaNLPandoc (Str "of") rols++[Str" worden uitgevoerd."] ++
case length auts of
0 -> []
1 -> [Space,Str "Daarbij wordt regel",Space]++auts++[Space,Str "gehandhaafd zonder interventie van de gebruiker."]
_ -> [Space,Str "Daarbij worden regels",Space]++commaNLPandoc (Str "en") auts++[Space,Str "gehandhaafd zonder interventie van de gebruiker."]
)]
English -> [Plain ([Str "Activity",Space, Quoted SingleQuote [(Str . name . actRule) act], Space,Str "must be performed by a user with role "]++commaEngPandoc (Str "or") rols++[Str"."] ++
case length auts of
0 -> []
1 -> [Space,Str "During that activity, rule",Space]++auts++[Space,Str "will be maintained without intervention of a user."]
_ -> [Space,Str "During that activity, rules",Space]++commaEngPandoc (Str "and") auts++[Space,Str "will be maintained without intervention of a user."]
)]
where
auts = nub [ Quoted SingleQuote [Str (name r)] | q<-actQuads act, let r=(cl_rule.qClauses) q, r_usr r == UserDefined]
rols = nub [Str r | (r,rul)<-fRoleRuls fSpec, rul==actRule act]
ifcEcaRules :: Activity -> [Block]
ifcEcaRules act
= ( case (language flags, actEcas act) of
(Dutch,[]) -> [Plain [Str "Alle veranderingen die een gebruiker uitvoert zijn handmatig. Er is geen geautomatiseerde functionaliteit in deze activiteit."]]
(English,[]) -> [Plain [Str "All changes a user makes are done by hand. There is no automated functionality in this activity."]]
(Dutch,_) -> [Plain [Str "De volgende tabel laat zien welke edit-acties welke functie aanroepen."]]
(English,_) -> [Plain [Str "The following table shows which edit actions invoke which function."]]
)++
if length (actEcas act)<1 then [] else
[ Table [] [AlignLeft,AlignLeft,AlignLeft] [0.0,0.0,0.0]
( case language flags of
Dutch ->
[[Plain [Str "actie"]]
,[Plain [Str "relatie"]]
,[Plain [Str "regel"]]]
English ->
[[Plain [Str "action"]]
,[Plain [Str "relation"]]
,[Plain [Str "rule"]]] )
[ [ [Plain [ (Str . show . eSrt.ecaTriggr) eca]]
, [Plain [ (Str . show . eDcl.ecaTriggr) eca]]
, [Plain (shwEca eca)]
]
| eca<-actEcas act
]]
where
shwEca :: ECArule -> [Inline]
shwEca eca
| isBlk (ecaAction eca)
= Str "error: rule ":
commaEngPandoc (Str "and")
[ Quoted SingleQuote [Str (let nrRules = length rs
s | nrRules == 0 = ""
| nrRules == 1 = name (head rs)
| otherwise = name (head rs)++" (and "++show(nrRules 1)++" other rules)."
in s
)]
| (_,rs)<-paMotiv (ecaAction eca)
]
| isNop (ecaAction eca)
= [ Str "no op"]
| otherwise = [ Str "ECA rule ", Str ((show . ecaNum ) eca) ]
txtKnowledgeGraph :: Activity -> [Block]
txtKnowledgeGraph act
= (case language flags of
Dutch -> [Para [ Str "Figuur ", xrefReference (picKnowledgeGraph flags fSpec act)
, Str " geeft de kennisgraaf weer voor deze interface."]]
English -> [Para [ Str "Figure ", xrefReference (picKnowledgeGraph flags fSpec act)
, Str " shows the knowledge graph of this interface."]]
)
++ [Plain (xrefFigure1 (picKnowledgeGraph flags fSpec act))]
txtSwitchboard :: Activity ->[Block]
txtSwitchboard act
= (if name act==name (head (fActivities fSpec)) then switchboardIntro else [])++
(case language flags of
Dutch -> [Para [ Str "Figuur ", xrefReference (picSwitchboard flags fSpec act)
, Str " geeft het schakelpaneel (switchboard diagram) weer voor deze interface."]]
English -> [Para [ Str "Figure ", xrefReference (picSwitchboard flags fSpec act)
, Str " shows the switchboard diagram of this interface."]]
)
++ [Plain (xrefFigure1 (picSwitchboard flags fSpec act))]
switchboardIntro :: [Block]
switchboardIntro
= if not (graphic flags) then [] else
[ Para $ case language flags of
Dutch -> [ Str "Iedere sectie in dit hoofdstuk beschrijft één activiteit. "
, Str "Tijdens het uitvoeren van een activiteit zal een gebruiker populatie invoegen of verwijderen in verschillende relaties. "
, Str "Hierdoor kunnen invarianten potentieel worden overtreden. "
, Str "(Een invariant is een bedrijfsregel die op ieder moment waar moet blijven.) "
, Str "De software die nodig is om invarianten waar te maken wordt automatisch gegenereerd. "
, Str "De structuur van deze software wordt geïllustreerd door een zogenaamd schakelpaneel (switchboard-diagram), "
, Str "waarvan u de eerste in figuur X aantreft. "
, Str "Elk switchboard diagram bestaat uit drie kolommen: "
, Str "Invariante regels staan in het midden en relaties staan aan de (linker en rechter) zijkanten. "
, Str "Een pijl ter linkerzijde wijst van een relatie die ge-edit wordt naar een regel die daardoor mogelijk overtreden wordt. "
, Str "Elke pijl ter rechterzijde van een regel representeert een edit-actie die nodig is om het waar-zijn ervan te herstellen. "
, Str "Deze pijl wijst naar de relatie waarin deze herstel-actie moet worden uitgevoerd. "
, Str "Een pijl gelabeled met '+' duidt op een insert event; een pijl met '-' op "
, Str "Hierdoor onstaat een accuraat beeld op welke manier de activiteit alle invarianten handhaaft. "
]
English -> [ Str "Every section in this chapter describes one activity. "
, Str "While performing an activity, users will insert or delete population in various relations. "
, Str "This may potentially violate invariants. "
, Str "(An invariant is a business rule rules that must remain true at all times.) "
, Str "The software to maintain the truth of invariant rules is generated automatically. "
, Str "The structure of that software is illustrated by a so called switchboard diagram, "
, Str "the first of which you will find in figure X. "
, Str "Each switchboard diagram consists of three columns: "
, Str "Invariant rules are drawn in the middle, and relations occur on the (right and left hand) sides. "
, Str "An arrow on the left hand side points from a relation that may be edited to a rule that may be violated as a consequence thereof. "
, Str "Each arrow on the right hand side of a rule represents an edit action that is required to restore its truth. "
, Str "It points to the relation that is edited for that purpose. "
, Str "If that arrow is labeled '+', it involves an insert event; if labeled '-' it refers to a delete event. "
, Str "This yields an accurate perspective on the way in which invariants are maintained. "
]
]
picKnowledgeGraph :: Options -> Fspc -> Activity ->Picture
picKnowledgeGraph flags fSpec act
= (makePicture flags fSpec Plain_CG act)
{caption = case language flags of
Dutch ->"Taaldiagram van "++name act
English ->"Language diagram of "++name act}
picSwitchboard :: Options -> Fspc -> Activity -> Picture
picSwitchboard flags fSpec act
= (makePicture flags fSpec Plain_CG (switchboardAct fSpec act))
{caption = case language flags of
Dutch ->"Schakelpaneel van "++name act
English ->"Switchboard of "++name act}
graphic :: Options -> Bool
graphic flags = genGraphics flags && theme flags /= StudentTheme