definition:
|
showView :: ViewGenerator
showView erdname (Entity entityName attrlist) relationships allEntities =
let manyToManyEntities = manyToMany allEntities (Entity entityName attrlist)
manyToOneEntities = manyToOne (Entity entityName attrlist) relationships
infovar = (0, "_")
evar = (1, lowerFirst entityName)
mmRelatedVars vart =
map (\ ((ename,erel), i) -> vart (i, lowerFirst $ erel ++ ename ++ "s"))
(zip manyToManyEntities [(length manyToOneEntities + 3) ..])
in viewFunction
("Supplies a view to show the details of a "++entityName++".\n")
entityName "show" 2
-- function type
(userSessionInfoType ~>
foldr CFuncType viewBlockType (
[baseType (model erdname,entityName)] ++
(map ctvar manyToOneEntities) ++ -- defaults for n:1
(map (\ (name,_) -> listType (ctvar name)) manyToManyEntities))
)
[simpleRule
( -- parameters
[CPVar infovar, CPVar evar] ++
(map (\ (name, varId) -> CPVar (varId,"related"++name))
(zip manyToOneEntities [3..])) ++
(mmRelatedVars CPVar)
)
(applyF (pre "++")
[applyF (entitiesToHtmlModule erdname,
lowerFirst entityName++"ToDetailsView")
([CVar evar] ++
map (\ (name, varId) -> CVar (varId,"related"++name))
(zip manyToOneEntities [3..]) ++
mmRelatedVars CVar
),
list2ac [applyF hrefButtonName
[applyF (spiceyModule,"listRoute") [CVar evar],
list2ac [applyF (html "htxt")
[string2ac ("To " ++ entityName ++ " list")]]]]
]
)]
|