Skip to content

Commit

Permalink
enhancement(admin_manage_fields): manage config_form_fields when modi…
Browse files Browse the repository at this point in the history
…fying parent tables
  • Loading branch information
mguzman14 committed Aug 9, 2024
1 parent 51e139f commit 27a5865
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions utils/fct/gw_fct_admin_manage_fields.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ v_tableversion text = 'sys_version';
v_columntype text = 'project_type';
v_type text;
v_error_context text;
v_layers record;
v_max_layoutorder numeric;
v_widgettype text;


BEGIN
Expand Down Expand Up @@ -72,23 +75,135 @@ BEGIN
END IF;

EXECUTE v_querytext;


-- manage config_form_fields only if column has been added to parent tables
if v_table in ('node', 'arc', 'connec', 'gully') then


execute 'select id from config_typevalue where typevalue = ''datatype_typevalue'' and id ilike ''%'||v_datatype||'%'' limit 1'
into v_datatype;

if v_datatype ilike '%boolean%' then
v_widgettype = 'check';

else
v_widgettype = 'text';

end if;

for v_layers in select parent_layer, child_layer from cat_feature where feature_type = upper(v_table)
loop

-- v_edit_feature
SELECT max(layoutorder)+1 into v_max_layoutorder from config_form_fields
where formname = v_layers.parent_layer
and formtype = 'form_feature' and tabname = 'tab_data' and layoutname = 'lyt_data_1' and layoutorder < 900;

INSERT INTO config_form_fields (formname, formtype, tabname, columnname, layoutname, layoutorder, "datatype", widgettype, "label", tooltip, placeholder, ismandatory, iseditable, hidden)
VALUES(v_layers.parent_layer, 'form_feature', 'tab_data', v_column, 'lyt_data_1', v_max_layoutorder, v_datatype, v_widgettype, v_column, v_column, NULL, false, true, false)
ON CONFLICT (formname, formtype, tabname, columnname) DO NOTHING;

-- ve_feature_type
SELECT max(layoutorder)+1 into v_max_layoutorder from config_form_fields
where formname = v_layers.child_layer
and formtype = 'form_feature' and tabname = 'tab_data' and layoutname = 'lyt_data_1' and layoutorder < 900;

INSERT INTO config_form_fields (formname, formtype, tabname, columnname, layoutname, layoutorder, "datatype", widgettype, "label", tooltip, placeholder, ismandatory, iseditable, hidden)
VALUES(v_layers.child_layer, 'form_feature', 'tab_data', v_column, 'lyt_data_1', v_max_layoutorder, v_datatype, v_widgettype, concat(upper(left(v_column, 1)), substring(v_column, 2)), v_column, NULL, false, true, false)
ON CONFLICT (formname, formtype, tabname, columnname) DO NOTHING;

end loop;

end if;


ELSIF v_action='RENAME' AND (SELECT column_name FROM information_schema.columns WHERE table_schema=v_schemaname and table_name = v_table AND column_name = v_column) IS NOT NULL
AND (SELECT column_name FROM information_schema.columns WHERE table_schema=v_schemaname and table_name = v_table AND column_name = v_newname) IS NULL THEN

v_querytext = 'ALTER TABLE '|| quote_ident(v_table) ||' RENAME COLUMN '||quote_ident(v_column)||' TO '||quote_ident(v_newname);
EXECUTE v_querytext;

-- manage config_form_fields
if v_table in ('node', 'arc', 'connec', 'gully') then

for v_layers in select distinct parent_layer, child_layer from cat_feature where feature_type = upper(v_table)
loop

execute '
update config_form_fields
set columnname = '||quote_literal(v_newname)||', tooltip = '||quote_literal(v_newname)||', label = '||quote_literal(concat(upper(left(v_newname, 1)), substring(v_newname, 2)))||'
where formname = '||quote_literal(v_layers.child_layer)||'
and columnname = '||quote_literal(v_column)||'';

execute '
update config_form_fields
set columnname = '||quote_literal(v_newname)||', tooltip = '||quote_literal(v_newname)||', label = '||quote_literal(concat(upper(left(v_newname, 1)), substring(v_newname, 2)))||'
where formname = '||quote_literal(v_layers.parent_layer)||'
and columnname = '||quote_literal(v_column)||'';

end loop;

end if;

ELSIF v_action='DROP' AND (SELECT column_name FROM information_schema.columns WHERE table_schema=v_schemaname and table_name = v_table AND column_name = v_column) IS NOT NULL THEN

v_querytext = 'ALTER TABLE '|| quote_ident(v_table) ||' DROP COLUMN '||quote_ident(v_column);
EXECUTE v_querytext;

if v_table in ('node', 'arc', 'connec', 'gully') then

for v_layers in select parent_layer, child_layer from cat_feature where feature_type = upper(v_table)
loop
execute '
DELETE FROM config_form_fields
WHERE formname = '||quote_literal(v_layers.parent_layer)||' AND columnname = '||quote_literal(v_column)||'';

EXECUTE '
DELETE FROM config_form_fields
WHERE formname = '||quote_literal(v_layers.child_layer)||' AND columnname = '||quote_literal(v_column)||'';

end loop;

end if;

ELSIF v_action='CHANGETYPE' AND (SELECT column_name FROM information_schema.columns
WHERE table_schema=v_schemaname and table_name = v_table AND column_name = v_column AND data_type!=v_datatype) IS NOT NULL THEN

v_querytext = 'ALTER TABLE '|| quote_ident(v_table) ||' ALTER COLUMN '||quote_ident(v_column)||' TYPE '||v_datatype||' USING '||quote_ident(v_column)||'::'||v_datatype;
EXECUTE v_querytext;

-- manage config_form_fields
if v_table in ('node', 'arc', 'connec', 'gully') then

execute 'select id from config_typevalue where typevalue = ''datatype_typevalue'' and id ilike ''%'||v_datatype||'%'' limit 1'
into v_datatype;

if v_datatype ilike '%boolean%' then
v_widgettype = 'check';

else
v_widgettype = 'text';

end if;


for v_layers in select parent_layer, child_layer from cat_feature where feature_type = upper(v_table)
loop
execute '
UPDATE config_form_fields
SET datatype = '||quote_literal(v_datatype)||'
WHERE formname = '||quote_literal(v_layers.parent_layer)||' AND columnname = '||quote_literal(v_column)||'';

EXECUTE '
UPDATE config_form_fields
SET datatype = '||quote_literal(v_datatype)||'
WHERE formname = '||quote_literal(v_layers.child_layer)||' AND columnname = '||quote_literal(v_column)||'';

end loop;

end if;

ELSE
v_querytext = 'Process not executed. Table has already been modified.';
END IF;
Expand Down

0 comments on commit 27a5865

Please sign in to comment.