Skip to content

Commit

Permalink
Fixes bug generating View when generating Action
Browse files Browse the repository at this point in the history
  • Loading branch information
fegu committed Oct 8, 2020
1 parent ef137c9 commit d959b11
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions IHP/IDE/CodeGen/ActionGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data ActionConfig = ActionConfig
buildPlan :: Text -> Text -> Text -> Bool -> IO (Either Text [GeneratorAction])
buildPlan actionName applicationName controllerName doGenerateView=
if (null actionName || null controllerName)
then pure $ Left "Action name and controller name cannot be empty"
then pure $ Left "Neither action name nor controller name can be empty"
else do
schema <- SchemaDesigner.parseSchemaSql >>= \case
Left parserError -> pure []
Expand All @@ -37,9 +37,9 @@ buildPlan actionName applicationName controllerName doGenerateView=
Left error -> pure $ Left error
else pure $ Right $ actionPlan
where
viewName = if "Action" `isSuffixOf` actionName
then Text.dropEnd 6 actionName
else actionName
viewName = ucfirst $ if "Action" `isSuffixOf` actionName
then Text.dropEnd 6 actionName
else actionName
modelName = tableNameToModelName controllerName

-- E.g. qualifiedViewModuleName config "Edit" == "Web.View.Users.Edit"
Expand Down
2 changes: 1 addition & 1 deletion IHP/IDE/CodeGen/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ instance Controller CodeGenController where
let doGenerateView = paramOrDefault False "doGenerateView"
(Right plan) <- ActionGenerator.buildPlan actionName applicationName controllerName doGenerateView
executePlan plan
setSuccessMessage "Action generated"
setSuccessMessage $ "Action" ++ (if doGenerateView then " and View " else "") ++ " generated"
redirectTo GeneratorsAction

action NewApplicationAction = do
Expand Down
1 change: 1 addition & 0 deletions IHP/IDE/CodeGen/View/NewAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ instance View NewActionView ViewContext where
<input type="hidden" name="name" value={actionName}/>
<input type="hidden" name="controllerName" value={controllerName}/>
<input type="hidden" name="applicationName" value={applicationName}/>
<input type="hidden" name="doGenerateView" value={(if doGenerateView then "on" else "off") :: Text}/>

<button class="btn btn-primary" type="submit">Generate</button>
</form>
Expand Down
9 changes: 5 additions & 4 deletions IHP/IDE/CodeGen/ViewGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data ViewConfig = ViewConfig
buildPlan :: Text -> Text -> Text -> IO (Either Text [GeneratorAction])
buildPlan viewName applicationName controllerName' =
if (null viewName || null controllerName')
then pure $ Left "View name and controller name cannot be empty"
then pure $ Left "Neither view name nor controller name can be empty"
else do
schema <- SchemaDesigner.parseSchemaSql >>= \case
Left parserError -> pure []
Expand Down Expand Up @@ -97,7 +97,8 @@ buildPlan' schema config =
<> " </ol>\n"
<> " </nav>\n"
<> " <h1>Show " <> singularName <> "</h1>\n"
<> " |]\n"
<> " <p>{" <> singularVariableName <> "}</p>\n"
<> " |]\n"

newView =
viewHeader
Expand All @@ -117,7 +118,7 @@ buildPlan' schema config =
<> "\n"
<> "renderForm :: " <> singularName <> " -> Html\n"
<> "renderForm " <> singularVariableName <> " = formFor " <> singularVariableName <> " [hsx|\n"
<> (intercalate "\n" (map (\field -> " {textField #" <> field <> "}") modelFields)) <> "\n"
<> (intercalate "\n" (map (\field -> " {(textField #" <> field <> ")}") modelFields)) <> "\n"
<> " {submitButton}\n"
<> "|]\n"

Expand All @@ -139,7 +140,7 @@ buildPlan' schema config =
<> "\n"
<> "renderForm :: " <> singularName <> " -> Html\n"
<> "renderForm " <> singularVariableName <> " = formFor " <> singularVariableName <> " [hsx|\n"
<> (intercalate "\n" (map (\field -> " {textField #" <> field <> "}") modelFields)) <> "\n"
<> (intercalate "\n" (map (\field -> " {(textField #" <> field <> ")}") modelFields)) <> "\n"
<> " {submitButton}\n"
<> "|]\n"

Expand Down
2 changes: 1 addition & 1 deletion lib/IHP/static/ihp-codegen.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
}

.code-generator .generator-options {
font-size: 11px;
font-size: 13px;
margin-top: 0.5rem;
margin-left: 0.5rem;
}
Expand Down

0 comments on commit d959b11

Please sign in to comment.