diff --git a/IHP/IDE/Data/Controller.hs b/IHP/IDE/Data/Controller.hs index 4285a9690..c39094b97 100644 --- a/IHP/IDE/Data/Controller.hs +++ b/IHP/IDE/Data/Controller.hs @@ -73,7 +73,7 @@ instance Controller DataController where tableNames <- fetchTableNames connection let tableName = param "tableName" tableCols <- fetchTableCols connection tableName - let values :: [Text] = map (\col -> quoteIfLiteral (param @Bool (cs (get #columnName col) <> "_")) (param @Text (cs (get #columnName col)))) tableCols + let values :: [Text] = map (\col -> parseValues (param @Bool (cs (get #columnName col) <> "_")) (param @Bool (cs (get #columnName col) <> "-isBoolean")) (param @Text (cs (get #columnName col)))) tableCols let query = "INSERT INTO " <> tableName <> " VALUES (" <> intercalate "," values <> ")" PG.execute_ connection (PG.Query . cs $! query) PG.close connection @@ -100,7 +100,7 @@ instance Controller DataController where tableCols <- fetchTableCols connection tableName primaryKeyFields <- tablePrimaryKeyFields connection tableName - let values :: [Text] = map (\col -> quoteIfLiteral (param @Bool (cs (get #columnName col) <> "_")) (param @Text (cs (get #columnName col)))) tableCols + let values :: [Text] = map (\col -> parseValues (param @Bool (cs (get #columnName col) <> "_")) (param @Bool (cs (get #columnName col) <> "-isBoolean")) (param @Text (cs (get #columnName col)))) tableCols let columns :: [Text] = map (\col -> cs (get #columnName col)) tableCols let primaryKeyValues = map (\pkey -> "'" <> (param @Text (cs pkey <> "-pk")) <> "'") primaryKeyFields @@ -139,7 +139,7 @@ instance Controller DataController where connection <- connectToAppDb let targetCol = param "targetName" let targetValue = param "targetValue" - let query = "UPDATE " <> tableName <> " SET " <> targetCol <> " = '" <> targetValue <> "' WHERE id = " <> cs id + let query = "UPDATE " <> tableName <> " SET " <> targetCol <> " = '" <> targetValue <> "' WHERE id = '" <> cs id <> "'" PG.execute_ connection (PG.Query . cs $! query) PG.close connection redirectTo ShowTableRowsAction { .. } @@ -185,8 +185,13 @@ fetchRows connection tableName = do PG.query_ connection (PG.Query . cs $! query) -quoteIfLiteral :: Bool -> Text -> Text -quoteIfLiteral False text = "'" <> text <> "'" -quoteIfLiteral True text = text +-- parseValues sqlMode isBoolField input +parseValues :: Bool -> Bool -> Text -> Text +parseValues _ True "on" = "true" +parseValues _ True "off" = "false" +parseValues False False text = "'" <> text <> "'" +parseValues True False text = text +parseValues False True text = text +parseValues True True text = text updateValues list = map (\elem -> fst elem <> " = " <> snd elem) list diff --git a/IHP/IDE/Data/View/EditRow.hs b/IHP/IDE/Data/View/EditRow.hs index 02e52b252..7155059a8 100644 --- a/IHP/IDE/Data/View/EditRow.hs +++ b/IHP/IDE/Data/View/EditRow.hs @@ -72,25 +72,127 @@ instance View EditRowView ViewContext where
+ {renderInputMethod (def, val)} +
+ |] + + onClick tableName fieldName id = "window.location.assign(" <> tshow (pathTo (ToggleBooleanFieldAction tableName (cs fieldName) id)) <> ")" + renderInputMethod :: (ColumnDefinition, DynamicField) -> Html + renderInputMethod (def, val) | (get #columnType def) == "boolean" && isNothing (get #fieldValue val) = [hsx| + {isBooleanParam True def} + "-alt"} + type="text" + name={get #columnName def} + class="form-control text-monospace text-secondary bg-light" + value="NULL" + /> +
"-boxcontainer"}> + "-input"} + type="checkbox" + class="d-none" + name={get #columnName def <> "-inactive"} + checked={(value val) == "t"} + /> +
+ "-hidden"} + type="hidden" + name={get #columnName def} + value={inputValue False} + /> +
+ + +
+ |] + renderInputMethod (def, val) | (get #columnType def) == "boolean" = [hsx| + {isBooleanParam True def} + "-alt"} + type="text" + name={get #columnName def <> "-inactive"} + class="form-control text-monospace text-secondary bg-light d-none" + /> +
"-boxcontainer"}> + "-input"} + type="checkbox" + name={get #columnName def} + checked={(value val) == "t"} + /> +
+ "-hidden"} + type="hidden" + name={get #columnName def} + value={inputValue False} + /> +
+ + +
+ |] + renderInputMethod (def, val) = [hsx| + {isBooleanParam False def} "-input"} type="text" name={get #columnName def} - class={classes ["form-control", ("text-monospace text-secondary bg-light", isSqlFunction_ value)]} - value={value} + class={classes ["form-control", ("text-monospace text-secondary bg-light", isSqlFunction_ (value val))]} + value={value val} oninput={"stopSqlModeOnInput('" <> get #columnName def <> "')"} />
-
- - |] - where - value = fromMaybe BS.empty (get #fieldValue val) + |] - onClick tableName fieldName id = "window.location.assign(" <> tshow (pathTo (ToggleBooleanFieldAction tableName (cs fieldName) id)) <> ")" +value val = fromMaybe BS.empty (get #fieldValue val) \ No newline at end of file diff --git a/IHP/IDE/Data/View/EditValue.hs b/IHP/IDE/Data/View/EditValue.hs index 96863f8ed..74d3791f1 100644 --- a/IHP/IDE/Data/View/EditValue.hs +++ b/IHP/IDE/Data/View/EditValue.hs @@ -37,7 +37,7 @@ instance View EditValueView ViewContext where where tableBody = [hsx|{forEach rows renderRow}|] - renderRow fields = [hsx| contextMenuId <> "');"}>{forEach fields (renderField id fields)} + renderRow fields = [hsx| contextMenuId <> "');"}>{forEach fields (renderField id)}