From d087389fef7b1667ab4d22f794f25a8e85eea5d2 Mon Sep 17 00:00:00 2001 From: Finn Espen Gundersen Date: Thu, 22 Oct 2020 15:51:51 +0200 Subject: [PATCH] IDE support for array types - and duplicate null/NULL bugfix --- IHP/IDE/SchemaDesigner/Controller/Columns.hs | 10 ++++++++-- IHP/IDE/SchemaDesigner/View/Columns/Edit.hs | 17 ++++++++++++++--- IHP/IDE/SchemaDesigner/View/Columns/New.hs | 4 ++++ lib/IHP/static/ihp-schemadesigner.js | 3 ++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/IHP/IDE/SchemaDesigner/Controller/Columns.hs b/IHP/IDE/SchemaDesigner/Controller/Columns.hs index 959401a4f..bf2fedc57 100644 --- a/IHP/IDE/SchemaDesigner/Controller/Columns.hs +++ b/IHP/IDE/SchemaDesigner/Controller/Columns.hs @@ -41,7 +41,7 @@ instance Controller ColumnsController where redirectTo ShowTableAction { .. } let column = Column { name = columnName - , columnType = param "columnType" + , columnType = arrayifytype (param "isArray") (param "columnType") , defaultValue = defaultValue , notNull = (not (param "allowNull")) , isUnique = param "isUnique" @@ -82,7 +82,7 @@ instance Controller ColumnsController where let columnId = param "columnId" let column = Column { name = columnName - , columnType = param "columnType" + , columnType = arrayifytype (param "isArray") (param "columnType") , defaultValue = defaultValue , notNull = (not (param "allowNull")) , isUnique = param "isUnique" @@ -228,3 +228,9 @@ isCreateEnumType CreateEnumType {} = True isCreateEnumType _ = False nameList statements = map (get #name) statements + +arrayifytype :: Bool -> PostgresType -> PostgresType +arrayifytype False (PArray coltype) = coltype +arrayifytype True a@(PArray coltype) = a +arrayifytype False coltype = coltype +arrayifytype True coltype = PArray coltype diff --git a/IHP/IDE/SchemaDesigner/View/Columns/Edit.hs b/IHP/IDE/SchemaDesigner/View/Columns/Edit.hs index b621a578a..3734061b2 100644 --- a/IHP/IDE/SchemaDesigner/View/Columns/Edit.hs +++ b/IHP/IDE/SchemaDesigner/View/Columns/Edit.hs @@ -52,7 +52,14 @@ instance View EditColumnView ViewContext where isUniqueCheckbox = if get #isUnique column then preEscapedToHtml [plain||] else preEscapedToHtml [plain||] - + + isArrayTypeCheckbox = if (isArrayType (get #columnType column)) + then preEscapedToHtml [plain||] + else preEscapedToHtml [plain||] + + isArrayType (PArray _) = True + isArrayType _ = False + modalContent = [hsx|
@@ -80,6 +87,9 @@ instance View EditColumnView ViewContext where {isUniqueCheckbox} Unique {primaryKeyCheckbox} + @@ -93,6 +103,7 @@ instance View EditColumnView ViewContext where +
|] modalFooter = mempty @@ -128,7 +139,7 @@ typeSelector postgresType enumNames = [hsx| option selected value text = case selected of Nothing -> [hsx||] Just selection -> - if selection == value + if selection == value || selection == value <> "[]" then [hsx||] else [hsx||] @@ -141,7 +152,7 @@ defaultSelector defValue = [hsx| |] where - suggestedValues = [Nothing, Just (TextExpression ""), Just (VarExpression "null"), Just (CallExpression "NOW" [])] + suggestedValues = [Nothing, Just (TextExpression ""), Just (VarExpression "NULL"), Just (CallExpression "NOW" [])] values = if defValue `elem` suggestedValues then suggestedValues else defValue:suggestedValues renderValue :: Maybe Expression -> Html diff --git a/IHP/IDE/SchemaDesigner/View/Columns/New.hs b/IHP/IDE/SchemaDesigner/View/Columns/New.hs index 1ab096e9a..b87e690f7 100644 --- a/IHP/IDE/SchemaDesigner/View/Columns/New.hs +++ b/IHP/IDE/SchemaDesigner/View/Columns/New.hs @@ -59,6 +59,9 @@ instance View NewColumnView ViewContext where + @@ -73,6 +76,7 @@ instance View NewColumnView ViewContext where + diff --git a/lib/IHP/static/ihp-schemadesigner.js b/lib/IHP/static/ihp-schemadesigner.js index 8309fa9b8..a90752390 100644 --- a/lib/IHP/static/ihp-schemadesigner.js +++ b/lib/IHP/static/ihp-schemadesigner.js @@ -95,7 +95,8 @@ function initSchemaDesigner() { }); $('#allowNull').change(function() { if ($('#allowNull').is(":checked")) { - $('#defaultSelector').append(new Option("null", "NULL", true, true)); + if(0 == $("#defaultSelector option:contains('NULL')").length) + $('#defaultSelector').append(new Option("NULL", "NULL", true, true)); } else { $("#defaultSelector option[value='NULL']").remove(); }