Skip to content

Commit

Permalink
feat: manage fields dma_type, presszone_type, dqa_type (mapzones), ca…
Browse files Browse the repository at this point in the history
…t_dint, custom_dint, to_arc, status (epa valve and shortpipe), demand, demand_pattern_id, emitter_coeff (epa inlet) on config_form_fields and triggers
  • Loading branch information
albertbofill committed Aug 21, 2024
1 parent 7dc1bc8 commit 403ce15
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 50 deletions.
4 changes: 3 additions & 1 deletion updates/36/36012/ws/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,6 @@ SELECT gw_fct_admin_manage_fields($${"data":{"action":"DROP","table":"inp_dscena
DROP VIEW IF EXISTS vi_parent_arc;
DROP VIEW IF EXISTS vi_parent_node;
DROP VIEW IF EXISTS vi_parent_hydrometer;
DROP VIEW IF EXISTS v_edit_field_valve;
DROP VIEW IF EXISTS v_edit_field_valve;

SELECT gw_fct_admin_manage_fields($${"data":{"action":"ADD","table":"inp_shortpipe", "column":"custom_dint", "dataType":"integer"}}$$);
26 changes: 9 additions & 17 deletions updates/36/36012/ws/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ AS SELECT d.dma_id,
d.name,
d.macrodma_id,
d.sector_id,
s.name as sector_name,
d.expl_id,
e.name as expl_name,
et.idval,
et.idval as dma_type,
d.descript,
d.pattern_id,
d.graphconfig::text AS graphconfig,
Expand All @@ -58,19 +56,15 @@ AS SELECT d.dma_id,
d.lastupdate_user,
d.the_geom
FROM dma d
LEFT JOIN sector s USING (sector_id)
LEFT JOIN exploitation e USING (expl_id)
LEFT JOIN edit_typevalue et on et.id = dma_type AND typevalue = 'dma_type'
ORDER BY d.dma_id;

CREATE OR REPLACE VIEW vu_presszone
AS SELECT p.presszone_id,
p.name,
p.sector_id,
s.name as sector_name,
p.expl_id,
e.name as expl_name,
et.idval,
et.idval as presszone_type,
p.descript,
p.head,
p.graphconfig::text AS graphconfig,
Expand All @@ -84,8 +78,6 @@ AS SELECT p.presszone_id,
p.lastupdate_user,
p.the_geom
FROM presszone p
LEFT JOIN sector s USING (sector_id)
LEFT JOIN exploitation e USING (expl_id)
LEFT JOIN edit_typevalue et on et.id = presszone_type AND typevalue = 'presszone_type'
ORDER BY p.presszone_id;

Expand All @@ -95,24 +87,20 @@ AS SELECT d.dqa_id,
d.macrodqa_id,
d.descript,
d.sector_id,
s.name as sector_name,
d.expl_id,
e.name as expl_name,
et.idval,
et.idval as dqa_type,
d.pattern_id,
d.graphconfig::text AS graphconfig,
d.stylesheet::text AS stylesheet,
d.link,
d.active,
d.undelete,
d.undelete,
d.tstamp,
d.insert_user,
d.lastupdate,
d.lastupdate_user,
d.the_geom
FROM dqa d
LEFT JOIN sector s USING (sector_id)
LEFT JOIN exploitation e USING (expl_id)
LEFT JOIN edit_typevalue et on et.id = dqa_type AND typevalue = 'dqa_type'
ORDER BY d.dqa_id;

Expand Down Expand Up @@ -3720,9 +3708,12 @@ CREATE OR REPLACE VIEW ve_epa_inlet AS
LEFT JOIN v_rpt_node USING (node_id);


drop view ve_epa_shortpipe;
CREATE OR REPLACE VIEW ve_epa_shortpipe AS
SELECT inp_shortpipe.node_id,
inp_shortpipe.minorloss,
cat_dint,
inp_shortpipe.custom_dint,
v.to_arc,
CASE
WHEN v.active is true and v.to_arc IS NOT NULL THEN 'CV'::character varying(12)
Expand All @@ -3748,7 +3739,8 @@ CREATE OR REPLACE VIEW ve_epa_shortpipe AS
v_rpt_arc.reaction_min,
v_rpt_arc.ffactor_max,
v_rpt_arc.ffactor_min
FROM inp_shortpipe
FROM vu_node
JOIN inp_shortpipe USING (node_id)
LEFT JOIN v_rpt_arc ON concat(inp_shortpipe.node_id, '_n2a') = v_rpt_arc.arc_id::text
LEFT JOIN man_valve v ON v.node_id::text = inp_shortpipe.node_id::text;

Expand Down
75 changes: 71 additions & 4 deletions updates/36/36012/ws/dml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ VALUES('edit_typevalue', 'presszone_type', 'presszone', 'presszone_type', true);
INSERT INTO sys_foreignkey (typevalue_table, typevalue_name, target_table, target_field, active)
VALUES('edit_typevalue', 'dma_type', 'dma', 'dma_type', true);

INSERT INTO edit_typevalue VALUES ('edit_typevalue', 'dqa_type','UDEFINED', 'UDEFINED');

INSERT INTO edit_typevalue VALUES ('edit_typevalue', 'dma_type','UDEFINED', 'UDEFINED');
INSERT INTO edit_typevalue VALUES ('dma_type','UNDEFINED', 'UNDEFINED');

ALTER TABLE edit_typevalue DISABLE TRIGGER gw_trg_typevalue_config_fk;
UPDATE edit_typevalue SET id = upper(id), idval=upper(idval) WHERE typevalue IN ('sector_type');
Expand Down Expand Up @@ -192,4 +190,73 @@ delete from config_form_fields where columnname = 'cat_arctype_id' and formname
delete from sys_table where id = 'vi_parent_arc';
delete from sys_table where id = 'vi_parent_connec';
delete from sys_table where id = 'vi_parent_hydrometer';
delete from sys_table where id = 'v_edit_field_valve';
delete from sys_table where id = 'v_edit_field_valve';

INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('v_edit_dma', 'form_feature', 'tab_none', 'dma_type', 'lyt_data_1', 18, 'string', 'combo', 'dma_type', 'dma_type', false, false, true, false, 'SELECT id, idval FROM edit_typevalue WHERE typevalue=''dma_type''', false);

INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, dv_orderby_id, widgetcontrols, hidden)
VALUES ('v_edit_dma', 'form_feature', 'tab_none', 'sector_id', 'lyt_data_1', 19, 'string', 'combo', 'sector_id', 'sector_id', false, false, true, false, 'SELECT sector_id as id, name as idval FROM sector WHERE sector_id IS NOT NULL', true, '{"setMultiline": false, "valueRelation":{"nullValue":false, "layer": "v_edit_sector", "activated": true, "keyColumn": "sector_id", "valueColumn": "name", "filterExpression": null}}', false);

INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, dv_orderby_id, widgetcontrols, hidden)
VALUES ('v_edit_dqa', 'form_feature', 'tab_none', 'sector_id', 'lyt_data_1', 15, 'string', 'combo', 'sector_id', 'sector_id', false, false, true, false, 'SELECT sector_id as id, name as idval FROM sector WHERE sector_id IS NOT NULL', true, '{"setMultiline": false, "valueRelation":{"nullValue":false, "layer": "v_edit_sector", "activated": true, "keyColumn": "sector_id", "valueColumn": "name", "filterExpression": null}}', false);

INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, dv_orderby_id, widgetcontrols, hidden)
VALUES ('v_edit_presszone', 'form_feature', 'tab_none', 'sector_id', 'lyt_data_1', 11, 'string', 'combo', 'sector_id', 'sector_id', false, false, true, false, 'SELECT sector_id as id, name as idval FROM sector WHERE sector_id IS NOT NULL', true, '{"setMultiline": false, "valueRelation":{"nullValue":false, "layer": "v_edit_sector", "activated": true, "keyColumn": "sector_id", "valueColumn": "name", "filterExpression": null}}', false);


INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('ve_epa_inlet', 'form_feature', 'tab_epa', 'demand', 'lyt_epa_data_1', 17, 'string', 'text', 'Demand:', 'Demand', false, false, true, false, NULL, false);

INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, dv_isnullvalue, hidden)
VALUES ('ve_epa_inlet', 'form_feature', 'tab_epa', 'demand_pattern_id', 'lyt_epa_data_1', 18, 'string', 'combo', 'Demand pattern:', 'Demand pattern', false, false, true, false,
'SELECT pattern_id as id, pattern_id as idval FROM inp_pattern', true, false);

INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('ve_epa_inlet', 'form_feature', 'tab_epa', 'emitter_coeff', 'lyt_epa_data_1', 19, 'string', 'text', 'Emitter coef:', 'Emitter coef', false, false, true, false, NULL, false);


INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('v_edit_inp_inlet', 'form_feature', 'tab_epa', 'demand', 'lyt_epa_data_1', 14, 'string', 'text', 'Demand:', 'Demand', false, false, true, false, NULL, false);

INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, dv_isnullvalue, hidden)
VALUES ('v_edit_inp_inlet', 'form_feature', 'tab_epa', 'demand_pattern_id', 'lyt_epa_data_1', 15, 'string', 'combo', 'Demand pattern:', 'Demand pattern', false, false, true, false,
'SELECT pattern_id as id, pattern_id as idval FROM inp_pattern', true, false);

INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('v_edit_inp_inlet', 'form_feature', 'tab_epa', 'emitter_coeff', 'lyt_epa_data_1', 16, 'string', 'text', 'Emitter coef:', 'Emitter coef', false, false, true, false, NULL, false);


UPDATE config_form_fields SET iseditable=false, dv_querytext=null, dv_parent_id=null where formname='v_edit_inp_shortpipe' and columnname='to_arc';
UPDATE config_form_fields SET iseditable=false, dv_orderby_id=null, dv_isnullvalue=null where formname='v_edit_inp_shortpipe' and columnname='status';
INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('v_edit_inp_shortpipe', 'form_feature', 'tab_epa', 'cat_dint', 'lyt_data_1', 15, 'string', 'text', 'Cat dint:', 'Cat dint', false, false, false, false, NULL, false);
INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('v_edit_inp_shortpipe', 'form_feature', 'tab_epa', 'custom_dint', 'lyt_data_1', 16, 'string', 'text', 'Custom dint:', 'Custom dint', false, false, true, false, NULL, false);


UPDATE config_form_fields SET iseditable=false where formname='ve_epa_shortpipe' and columnname='to_arc';
UPDATE config_form_fields SET dv_orderby_id=null, dv_isnullvalue=null where formname='ve_epa_shortpipe' and columnname='status';
INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('ve_epa_shortpipe', 'form_feature', 'tab_epa', 'cat_dint', 'lyt_epa_data_1', 7, 'string', 'text', 'Cat dint:', 'Cat dint', false, false, false, false, NULL, false);
INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('ve_epa_shortpipe', 'form_feature', 'tab_epa', 'custom_dint', 'lyt_epa_data_1', 8, 'string', 'text', 'Custom dint:', 'Custom dint', false, false, true, false, NULL, false);


UPDATE config_form_fields SET iseditable=false where formname='ve_epa_valve' and columnname='to_arc';
UPDATE config_form_fields SET widgettype='text', iseditable=false, dv_querytext=null, dv_orderby_id=null, dv_isnullvalue=null where formname='ve_epa_valve' and columnname='status';
INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('ve_epa_valve', 'form_feature', 'tab_epa', 'cat_dint', 'lyt_epa_data_1', 13, 'string', 'text', 'Cat dint:', 'Cat dint', false, false, false, false, NULL, false);
UPDATE config_form_fields SET layoutorder=14 where formname='ve_epa_valve' and columnname='custom_dint';


UPDATE config_form_fields SET iseditable=false, dv_querytext=null where formname='v_edit_inp_valve' and columnname='to_arc';
UPDATE config_form_fields SET iseditable=false, dv_querytext=null, dv_orderby_id=null, dv_isnullvalue=null where formname='v_edit_inp_valve' and columnname='status';
INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('v_edit_inp_valve', 'form_feature', 'tab_epa', 'cat_dint', 'lyt_data_1', 20, 'string', 'text', 'Cat dint:', 'Cat dint', false, false, false, false, NULL, false);
INSERT INTO config_form_fields(formname, formtype, tabname, columnname, layoutname, layoutorder, datatype, widgettype, label, tooltip, ismandatory, isparent, iseditable, isautoupdate, dv_querytext, hidden)
VALUES ('v_edit_inp_valve', 'form_feature', 'tab_epa', 'custom_dint', 'lyt_data_1', 21, 'string', 'text', 'Custom dint:', 'Custom dint', false, false, true, false, NULL, false);

UPDATE config_form_fields SET iseditable=false where columnname='macrominsector_id';
UPDATE config_form_fields SET iseditable=false where columnname='to_arc' and formname like 've_node%';

28 changes: 19 additions & 9 deletions updates/36/36012/ws/trg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_arc('inp_virtualpump');
CREATE TRIGGER gw_trg_edit_inp_arc_virtualvalve INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_virtualvalve
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_arc('inp_virtualvalve');

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_pipe
CREATE TRIGGER gw_trg_edit_inp_dscenario_pipe INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_pipe
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('PIPE');

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_virtualvalve
CREATE TRIGGER gw_trg_edit_inp_dscenario_virtualvalve INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_virtualvalve
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('VIRTUALVALVE');

CREATE TRIGGER gw_trg_edit_inp_dscenario_virtualpump INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_virtualpump
Expand All @@ -89,34 +89,34 @@ FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_man_connec_pol('man_fountain_pol');
CREATE TRIGGER gw_trg_edit_man_tank_pol INSTEAD OF INSERT OR DELETE OR UPDATE ON ve_pol_tank
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_man_node_pol('man_tank_pol');

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_pump
CREATE TRIGGER gw_trg_edit_inp_dscenario_pump INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_pump
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('PUMP');

CREATE TRIGGER gw_trg_edit_inp_node_pump INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_pump_additional
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_node('inp_pump_additional');

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_pump_additional
CREATE TRIGGER gw_trg_edit_inp_dscenario_pump_additional INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_pump_additional
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('PUMP_ADDITIONAL');

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_shortpipe
CREATE TRIGGER gw_trg_edit_inp_dscenario_shortpipe INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_shortpipe
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('SHORTPIPE');

CREATE TRIGGER gw_trg_edit_inp_node_shortpipe INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_shortpipe
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_node('inp_shortpipe');

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_connec
CREATE TRIGGER gw_trg_edit_inp_dscenario_connec INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_connec
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('CONNEC');

CREATE TRIGGER gw_trg_edit_inp_connec INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_connec
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_connec();

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_tank
CREATE TRIGGER gw_trg_edit_inp_dscenario_tank INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_tank
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('TANK');

CREATE TRIGGER gw_trg_edit_inp_node_tank INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_tank
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_node('inp_tank');

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_reservoir
CREATE TRIGGER gw_trg_edit_inp_dscenario_reservoir INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_reservoir
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('RESERVOIR');

CREATE TRIGGER gw_trg_edit_inp_node_reservoir INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_reservoir
Expand All @@ -128,7 +128,7 @@ FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('VALVE');
CREATE TRIGGER gw_trg_edit_inp_node_valve INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_valve
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_node('inp_valve');

CREATE TRIGGER gw_trg_edit_inp_dscenario_junction INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_inlet
CREATE TRIGGER gw_trg_edit_inp_dscenario_inlet INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_dscenario_inlet
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_inp_dscenario('INLET');

CREATE TRIGGER gw_trg_edit_inp_node_inlet INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_inp_inlet
Expand All @@ -148,3 +148,13 @@ FOR EACH ROW EXECUTE PROCEDURE gw_trg_edit_ve_epa('inlet');

CREATE TRIGGER gw_trg_edit_link INSTEAD OF INSERT OR UPDATE OR DELETE ON v_edit_link
FOR EACH ROW EXECUTE PROCEDURE gw_trg_edit_link();

CREATE TRIGGER gw_trg_edit_dma INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_dma
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_dma('dma');

CREATE TRIGGER gw_trg_edit_presszone INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_presszone
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_presszone();

CREATE TRIGGER gw_trg_edit_dqa INSTEAD OF INSERT OR DELETE OR UPDATE ON v_edit_dqa
FOR EACH ROW EXECUTE FUNCTION gw_trg_edit_dqa();

12 changes: 6 additions & 6 deletions ws/ftrg/ws_gw_trg_edit_dma.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BEGIN

-- expl_id
IF ((SELECT COUNT(*) FROM exploitation WHERE active IS TRUE) = 0) THEN
RETURN NULL;
RETURN NULL;
END IF;

IF NEW.the_geom IS NOT NULL THEN
Expand All @@ -53,25 +53,25 @@ BEGIN
ON CONFLICT (pattern_id) DO NOTHING;
END IF;

INSERT INTO dma (dma_id, name, descript, macrodma_id, the_geom, undelete, expl_id, pattern_id, link, minc, maxc, effc, graphconfig, stylesheet, active, avg_press)
VALUES (NEW.dma_id, NEW.name, NEW.descript, NEW.macrodma_id, NEW.the_geom, NEW.undelete, NEW.expl_id, NEW.pattern_id, NEW.link, NEW.minc,
NEW.maxc, NEW.effc, NEW.graphconfig::json, NEW.stylesheet::json, NEW.active, NEW.avg_press;
INSERT INTO dma (dma_id, name, descript, macrodma_id, the_geom, undelete, expl_id, pattern_id, link, effc, graphconfig, stylesheet, active, avg_press, dma_type)
VALUES (NEW.dma_id, NEW.name, NEW.descript, NEW.macrodma_id, NEW.the_geom, NEW.undelete, NEW.expl_id, NEW.pattern_id, NEW.link,
NEW.effc, NEW.graphconfig::json, NEW.stylesheet::json, NEW.active, NEW.avg_press, NEW.dma_type);

RETURN NEW;

ELSIF TG_OP = 'UPDATE' THEN

UPDATE dma
SET dma_id=NEW.dma_id, name=NEW.name, descript=NEW.descript, the_geom=NEW.the_geom, undelete=NEW.undelete, expl_id=NEW.expl_id,
pattern_id=NEW.pattern_id, link=NEW.link, minc=NEW.minc, maxc=NEW.maxc, effc=NEW.effc, graphconfig=NEW.graphconfig::json,
pattern_id=NEW.pattern_id, link=NEW.link, effc=NEW.effc, graphconfig=NEW.graphconfig::json, dma_type=NEW.dma_type,
stylesheet = NEW.stylesheet::json, active=NEW.active, avg_press=NEW.avg_press, macrodma_id = NEW.macrodma_id, lastupdate=now(), lastupdate_user = current_user
WHERE dma_id=OLD.dma_id;

RETURN NEW;

ELSIF TG_OP = 'DELETE' THEN

DELETE FROM dma WHERE dma_id = OLD.dma_id;
DELETE FROM dma WHERE dma_id = OLD.dma_id;
RETURN NULL;

END IF;
Expand Down
Loading

0 comments on commit 403ce15

Please sign in to comment.