definition:
|
showController :: ControllerGenerator
showController erdname (Entity entityName attrs) relationships allEntities =
let manyToManyEntities = manyToMany allEntities (Entity entityName attrs)
manyToOneEntities = manyToOne (Entity entityName attrs) relationships
pvar = (0, lowerFirst entityName)
infovar = (1, "sinfo")
in
controllerFunction
("Shows a " ++ entityName ++ " entity.")
entityName "show" 1
(baseType (model erdname,entityName) ~> controllerType)
[simpleRule
[CPVar pvar] -- parameterlist for controller
(applyF (pre "$")
[applyF checkAuthorizationFunc
[applyF (enauthModName,lowerFirst entityName ++ "OperationAllowed")
[applyF (authorizationModule,"ShowEntity") [CVar pvar]]],
CLambda [CPVar infovar] $ doExpr (
map (\ (ename, num) ->
CSPat (CPVar (num,lowerFirst
(fst $ relationshipName entityName
ename relationships) ++ ename))
(applyF (model erdname,"runJustT")
[applyF (controllerModuleName entityName,
"get"++ fst (relationshipName
entityName ename relationships)
++ ename)
[CVar pvar]
])
)
(zip (manyToOneEntities) [1..]) ++
map (\ ((ename,erel), num) ->
CSPat (CPVar (num,lowerFirst erel ++ ename ++ "s"))
(applyF (model erdname,"runJustT")
[applyF (controllerModuleName entityName,
"get" ++ erel ++ entityName ++ ename ++ "s")
[CVar pvar]])
)
(zip manyToManyEntities [1..]) ++
[CSExpr (
applyF (pre "return")
[applyF (viewFunctionName entityName "show")
([CVar infovar, CVar pvar] ++
(map (\ (ename, num) ->
CVar (num,lowerFirst (fst $ relationshipName
entityName ename relationships)
++ ename))
(zip (manyToOneEntities) [1..])) ++
(map (\ ((ename,erel), num) ->
CVar (num,lowerFirst erel ++ ename ++ "s"))
(zip manyToManyEntities [1..])))
])
])
]
)
]
|