From 369b66eda602c25636aa0543eb6146f998247682 Mon Sep 17 00:00:00 2001 From: Xavier Torret Date: Thu, 2 Jan 2025 18:33:18 +0100 Subject: [PATCH] enhan(mapzones): Enhance mapzones strategy --- example/user/ud/ud_99_sample_other.sql | 6 +- example/user/ud/ud_99_sample_zfinal.sql | 2 - example/user/ws/ws_99_sample_other.sql | 5 -- example/user/ws/ws_99_sample_zfinal.sql | 1 - updates/36/36017/ud/ddlview.sql | 68 +-------------- updates/36/36017/utils/ddlview.sql | 57 +------------ updates/36/36017/utils/dml.sql | 33 ++++---- updates/36/36017/utils/trg.sql | 15 ---- updates/36/36017/ws/ddlview.sql | 106 +++++++++--------------- utils/fct/gw_fct_getselectors.sql | 58 +++++++++++-- utils/fct/gw_fct_setinitproject.sql | 6 -- utils/fct/gw_fct_setselectors.sql | 2 +- utils/ftrg/gw_trg_exploitation.sql | 57 ------------- 13 files changed, 109 insertions(+), 307 deletions(-) delete mode 100644 updates/36/36017/utils/trg.sql delete mode 100644 utils/ftrg/gw_trg_exploitation.sql diff --git a/example/user/ud/ud_99_sample_other.sql b/example/user/ud/ud_99_sample_other.sql index 9b0645bdee..689806a846 100644 --- a/example/user/ud/ud_99_sample_other.sql +++ b/example/user/ud/ud_99_sample_other.sql @@ -806,11 +806,7 @@ UPDATE cat_feature_gully SET double_geom = '{"activated":true,"value":1}' WHERE INSERT INTO config_param_user (parameter, value, cur_user) VALUES ('om_visit_status_vdefault', '4', current_user) ON CONFLICT (parameter, cur_user) DO NOTHING; -SELECT setval('SCHEMA_NAME.urn_id_seq', gw_fct_setvalurn(),true); - -UPDATE config_param_system SET value = gw_fct_json_object_set_key(value::json, 'sectorFromExpl', false) WHERE parameter = 'basic_selector_tab_exploitation'; -UPDATE config_param_system SET value = gw_fct_json_object_set_key(value::json, 'explFromSector', false) WHERE parameter = 'basic_selector_tab_sector'; -UPDATE config_param_system SET value = gw_fct_json_object_set_key(value::json,'explFromMacroexpl', false) WHERE parameter = 'basic_selector_tab_macroexploitation'; +SELECT setval('SCHEMA_NAME.urn_id_seq', gw_fct_setvalurn(),true);; INSERT INTO inp_lid VALUES ('BIO-RETENTION','BC'); INSERT INTO inp_lid VALUES ('VEGE-SWALE','VS'); diff --git a/example/user/ud/ud_99_sample_zfinal.sql b/example/user/ud/ud_99_sample_zfinal.sql index 1718bd531d..41c18ab05c 100644 --- a/example/user/ud/ud_99_sample_zfinal.sql +++ b/example/user/ud/ud_99_sample_zfinal.sql @@ -99,8 +99,6 @@ UPDATE cat_arc SET visitability_vdef = 1 WHERE geom1 <= 1.2; -- NO VISITABLE UPDATE cat_arc SET visitability_vdef = 2 WHERE geom1 > 1.2 AND geom1 < 1.6; -- SEMI VISITABLE UPDATE cat_arc SET visitability_vdef = 3 WHERE geom1 >= 1.6; -- VISITABLE -UPDATE config_param_system SET isenabled = true WHERE parameter = 'basic_selector_tab_municipality'; - UPDATE link SET muni_id = c.muni_id FROM connec c WHERE connec_id = feature_id; UPDATE link SET muni_id = g.muni_id FROM gully g WHERE gully_id = feature_id; diff --git a/example/user/ws/ws_99_sample_other.sql b/example/user/ws/ws_99_sample_other.sql index 4470f94528..bba9022cf6 100644 --- a/example/user/ws/ws_99_sample_other.sql +++ b/example/user/ws/ws_99_sample_other.sql @@ -446,11 +446,6 @@ UPDATE cat_mat_roughness SET roughness = 0.025 WHERE matcat_id IN ('FC'); SELECT setval('SCHEMA_NAME.urn_id_seq', gw_fct_setvalurn(),true); -UPDATE config_param_system SET value = gw_fct_json_object_set_key(value::json, 'sectorFromExpl', false) WHERE parameter = 'basic_selector_tab_exploitation'; -UPDATE config_param_system SET value = gw_fct_json_object_set_key(value::json, 'explFromSector', false) WHERE parameter = 'basic_selector_tab_sector'; -UPDATE config_param_system SET value = gw_fct_json_object_set_key(value::json,'explFromMacroexpl', false) WHERE parameter = 'basic_selector_tab_macroexploitation'; - - INSERT INTO config_param_user VALUES ('edit_pavement_vdefault','Asphalt',current_user); INSERT INTO plan_arc_x_pavement (arc_id, pavcat_id, percent) VALUES ('2001', 'Slab', 0.5); diff --git a/example/user/ws/ws_99_sample_zfinal.sql b/example/user/ws/ws_99_sample_zfinal.sql index 167b1ceba4..9ff7fc61a6 100644 --- a/example/user/ws/ws_99_sample_zfinal.sql +++ b/example/user/ws/ws_99_sample_zfinal.sql @@ -77,7 +77,6 @@ UPDATE config_param_system SET value = gw_fct_json_object_set_key(value::json, ' UPDATE config_param_system SET value = gw_fct_json_object_set_key(value::json, 'sys_geom', 's.the_geom'::text) WHERE parameter ='basic_search_v2_tab_address'; -UPDATE config_param_system SET isenabled = true WHERE parameter = 'basic_selector_tab_municipality'; UPDATE link SET muni_id = c.muni_id FROM connec c WHERE connec_id = feature_id; diff --git a/updates/36/36017/ud/ddlview.sql b/updates/36/36017/ud/ddlview.sql index 437bf3b5ff..58fbaf13fd 100644 --- a/updates/36/36017/ud/ddlview.sql +++ b/updates/36/36017/ud/ddlview.sql @@ -988,70 +988,4 @@ drop view v_edit_link_connec; create or replace view v_edit_link_connec as select * from v_edit_link where feature_type = 'CONNEC'; drop view v_edit_link_gully; -create or replace view v_edit_link_gully as select * from v_edit_link where feature_type = 'GULLY'; - --- 31/12/2024 -CREATE OR REPLACE VIEW vu_sector as -SELECT distinct on (sector_id) s.sector_id, - s.name, - s.macrosector_id, - m.name AS macrosector_name, - et.idval, - s.descript, - s.parent_id, - s.graphconfig::text AS graphconfig, - s.stylesheet::text AS stylesheet, - s.link, - s.active, - s.undelete, - s.tstamp, - s.insert_user, - s.lastupdate, - s.lastupdate_user, - s.the_geom - FROM sector s - JOIN (SELECT DISTINCT sector_id, expl_id FROM node WHERE state > 0) a USING (sector_id) - JOIN config_user_x_expl USING (expl_id) - LEFT JOIN macrosector m USING (macrosector_id) - LEFT JOIN edit_typevalue et ON et.id::text = s.sector_type::text AND et.typevalue::text = 'sector_type'::text - where username = current_user and (s.sector_id > 0 or s.sector_id <-9) - union - SELECT distinct on (sector_id) s.sector_id, - s.name, - s.macrosector_id, - m.name AS macrosector_name, - et.idval, - s.descript, - s.parent_id, - s.graphconfig::text AS graphconfig, - s.stylesheet::text AS stylesheet, - s.link, - s.active, - s.undelete, - s.tstamp, - s.insert_user, - s.lastupdate, - s.lastupdate_user, - s.the_geom - FROM sector s - LEFT JOIN ( SELECT DISTINCT node.sector_id, node.expl_id FROM node WHERE node.state > 0) a USING (sector_id) - LEFT JOIN macrosector m USING (macrosector_id) - LEFT JOIN edit_typevalue et ON et.id::text = s.sector_type::text AND et.typevalue::text = 'sector_type'::text - where (s.sector_id > 0 or s.sector <-9) and a.sector_id is null - ORDER BY 1; - - -CREATE OR REPLACE VIEW v_edit_sector -AS SELECT sector.sector_id, - sector.name, - sector.descript, - sector.macrosector_id, - sector.sector_type, - sector.the_geom, - sector.undelete, - sector.active, - sector.parent_id, - sector.graphconfig::text AS graphconfig, - sector.stylesheet - FROM selector_sector, sector - WHERE sector.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text and active is true; \ No newline at end of file +create or replace view v_edit_link_gully as select * from v_edit_link where feature_type = 'GULLY'; \ No newline at end of file diff --git a/updates/36/36017/utils/ddlview.sql b/updates/36/36017/utils/ddlview.sql index c2824013db..04f8658538 100644 --- a/updates/36/36017/utils/ddlview.sql +++ b/updates/36/36017/utils/ddlview.sql @@ -8,59 +8,4 @@ This version of Giswater is provided by Giswater Association SET search_path = SCHEMA_NAME, public, pg_catalog; --- 31/12/2024 - -CREATE OR REPLACE VIEW vu_exploitation as -select e.* from exploitation e -JOIN config_user_x_expl USING (expl_id) -where username = current_user and (expl_id > 0 or expl_id < -9) -order by 1; - -CREATE OR REPLACE VIEW vu_macroexploitation as -select distinct on (macroexpl_id) m.* from macroexploitation m -join exploitation using (macroexpl_id) -JOIN config_user_x_expl USING (expl_id) -where username = current_user and (macroexpl_id > 0 or macroexpl_id < -9) -UNION -select distinct on (macroexpl_id) m.* from macroexploitation m -LEFT join exploitation using (macroexpl_id) -where expl_id IS NULL and (macroexpl_id > 0 or macroexpl_id < -9) -order by 1; - -CREATE OR REPLACE VIEW vu_macrosector as -select distinct on (macrosector_id) m.* from macrosector m -join sector using (macrosector_id) -JOIN (SELECT DISTINCT sector_id, expl_id FROM node WHERE state > 0) a USING (sector_id) -join exploitation using (expl_id) -JOIN config_user_x_expl USING (expl_id) -where username = current_user and (macrosector_id > 0 or macrosector_id < -9) -UNION -select distinct on (macrosector_id) m.* from macrosector m -LEFT join sector using (macrosector_id) -where sector_id IS NULL and (macrosector_id > 0 or macrosector_id < -9) -order by 1; - -CREATE OR REPLACE VIEW vu_ext_municipality as -select m.* from ext_municipality m -join (SELECT DISTINCT muni_id, expl_id FROM node WHERE state > 0) a USING (muni_id) -JOIN config_user_x_expl USING (expl_id) -where username = current_user and (muni_id > 0 or muni_id < -9) -UNION -select m.* from ext_municipality m -LEFT join (SELECT DISTINCT muni_id, expl_id FROM node WHERE state > 0) a USING (muni_id) -where a.muni_id IS NULL and (muni_id > 0 or muni_id < -9) -order by 1; - -CREATE OR REPLACE VIEW v_edit_exploitation -AS SELECT exploitation.expl_id, - exploitation.name, - exploitation.macroexpl_id, - exploitation.descript, - exploitation.undelete, - exploitation.the_geom, - exploitation.tstamp, - exploitation.active - FROM selector_expl, - exploitation - WHERE exploitation.expl_id = selector_expl.expl_id AND selector_expl.cur_user = "current_user"()::text - and active is true; \ No newline at end of file +-- 31/12/2024 \ No newline at end of file diff --git a/updates/36/36017/utils/dml.sql b/updates/36/36017/utils/dml.sql index 61141a7d68..c790b7fdb7 100644 --- a/updates/36/36017/utils/dml.sql +++ b/updates/36/36017/utils/dml.sql @@ -21,14 +21,6 @@ UPDATE config_form_tabs SET orderby = 2 where formname = 'selector_basic' and ta UPDATE sys_table set sys_role='role_edit' where id = 'sector'; UPDATE sys_table set sys_role='role_basic' where id = 'config_user_x_expl'; -update config_param_system set value = -'{"table":"vu_macrosector","selector":"selector_macrosector","table_id":"macrosector_id","selector_id":"macrosector_id","label":"macrosector_id, '' - '', name","orderBy":"macrosector_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(macrosector_id, '' - '', name))", "selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}'::text -where parameter='basic_selector_tab_macrosector'; - -update config_param_system set value = -'{"table":"vu_macroexploitation","selector":"selector_macroexpl","table_id":"macroexpl_id","selector_id":"macroexpl_id","label":"macroexpl_id, '' - '', name","orderBy":"macroexpl_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(macroexpl_id, '' - '', name))", "selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}'::text -where parameter='basic_selector_tab_macroexploitation'; - INSERT INTO config_form_tabs VALUES ('selector_basic','tab_exploitation_add', 'Expl Add', 'Active exploitation', 'role_basic',null,null,1,'{4,5}'); INSERT into config_param_system (parameter, value, descript, label, isenabled, project_type, datatype, widgettype) @@ -39,8 +31,9 @@ delete from config_param_system where parameter = 'basic_selector_mapzone_relati delete from config_param_system where parameter = 'basic_selector_explfrommuni'; +delete from config_param_system where parameter = 'basic_selector_options'; insert into config_param_system (parameter, value, descript, label, project_type) -values ('basic_selector_options', '{"sectorFromExpl":true, "explFromMacro":true, "sectorFromMacro":true, "muniClientFilter":false, "sectorClientFilter":false}', 'Options variables for selector', 'Selector variables', 'utils'); +values ('basic_selector_options', '{"sectorFromExpl":false, "explFromMacro":false, "sectorFromMacro":false, "muniClientFilter":false, "sectorClientFilter":false}', 'Options variables for selector', 'Selector variables', 'utils'); UPDATE config_param_system set isenabled = false where parameter = 'basic_selector_tab_municipality'; @@ -54,29 +47,33 @@ INSERT INTO sys_table (id, descript, sys_role, source) VALUES ('vu_ext_municipal INSERT INTO sys_table (id, descript, sys_role, source) VALUES ('vu_om_mincut','View of all mincuts related to user', 'role_basic', 'core'); update config_param_system -set value = '{"table":"vu_sector","selector":"selector_sector","table_id":"sector_id","selector_id":"sector_id","label":"sector_id, '' - '', name","orderBy":"sector_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(sector_id, '' - '', name))", "selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}' +set value = '{"table":"temp_sector","selector":"selector_sector","table_id":"sector_id","selector_id":"sector_id","label":"sector_id, '' - '', name","orderBy":"sector_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(sector_id, '' - '', name))", "selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}' where parameter = 'basic_selector_tab_sector'; update config_param_system -set value = '{"table":"vu_exploitation","selector":"selector_expl","table_id":"expl_id","selector_id":"expl_id","label":"expl_id, '' - '', name","orderBy":"expl_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(expl_id, '' - '', name))","selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}' +set value = '{"table":"temp_exploitation","selector":"selector_expl","table_id":"expl_id","selector_id":"expl_id","label":"expl_id, '' - '', name","orderBy":"expl_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(expl_id, '' - '', name))","selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}' where parameter = 'basic_selector_tab_exploitation'; +update config_param_system set value = +'{"table":"temp_macrosector","selector":"selector_macrosector","table_id":"macrosector_id","selector_id":"macrosector_id","label":"macrosector_id, '' - '', name","orderBy":"macrosector_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(macrosector_id, '' - '', name))", "selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}'::text +where parameter='basic_selector_tab_macrosector'; + +update config_param_system set value = +'{"table":"temp_macroexploitation","selector":"selector_macroexpl","table_id":"macroexpl_id","selector_id":"macroexpl_id","label":"macroexpl_id, '' - '', name","orderBy":"macroexpl_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(macroexpl_id, '' - '', name))", "selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}'::text +where parameter='basic_selector_tab_macroexploitation'; + update config_param_system -set value = '{"table":"vu_ext_municipality","selector":"selector_municipality","table_id":"muni_id","selector_id":"muni_id","label":"muni_id, ''- '', name","orderBy":"muni_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(muni_id, '' - '', name))","selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}' +set isenabled = false, value = '{"table":"ext_municipality","selector":"selector_municipality","table_id":"muni_id","selector_id":"muni_id","label":"muni_id, ''- '', name","orderBy":"muni_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(muni_id, '' - '', name))","selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}' where parameter = 'basic_selector_tab_municipality'; update config_param_system -set value = '{"table":"vu_macroexploitation","selector":"selector_expl","table_id":"macroexpl_id","selector_id":"expl_id","label":"macroexpl_id, '' - '', name","orderBy":"macroexpl_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(macroexpl_id, '' - '', name))", "selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}' +set value = '{"table":"macroexploitation","selector":"selector_expl","table_id":"macroexpl_id","selector_id":"expl_id","label":"macroexpl_id, '' - '', name","orderBy":"macroexpl_id","manageAll":true,"query_filter":"","typeaheadFilter":" AND lower(concat(macroexpl_id, '' - '', name))", "selectionMode":"keepPreviousUsingShift", "orderbyCheck":false}' where parameter = 'basic_selector_tab_macroexploitation_add'; update config_param_system -set value = '{"table":"vu_om_mincut","table_id":"id","selector":"selector_mincut_result","selector_id":"result_id","label":"id, ''('', CASE WHEN work_order IS NULL THEN ''N/I'' ELSE work_order END, '') on '', forecast_start::date, '' at '', forecast_start::time, ''H-'', forecast_end::time,''H''","query_filter":"","manageAll":true}' +set value = '{"table":"temp_mincut","table_id":"id","selector":"selector_mincut_result","selector_id":"result_id","label":"id, ''('', CASE WHEN work_order IS NULL THEN ''N/I'' ELSE work_order END, '') on '', forecast_start::date, '' at '', forecast_start::time, ''H-'', forecast_end::time,''H''","query_filter":"","manageAll":true}' where parameter = 'basic_selector_tab_mincut'; -INSERT INTO sys_function (id, function_name, project_type, function_type, input_params, return_type, descript, sys_role, sample_query, "source") -VALUES(3368, 'gw_trg_exploitation', 'utils', 'trigger function', null, null, 'Manage insert into config_user_x_expl table.', 'role_basic', NULL, 'core'); - - diff --git a/updates/36/36017/utils/trg.sql b/updates/36/36017/utils/trg.sql deleted file mode 100644 index 92051c26a0..0000000000 --- a/updates/36/36017/utils/trg.sql +++ /dev/null @@ -1,15 +0,0 @@ -/* -This file is part of Giswater 3 -The program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -This version of Giswater is provided by Giswater Association -*/ - - -SET search_path = SCHEMA_NAME, public, pg_catalog; - - --- 31/12/2024 - CREATE TRIGGER gw_trg_exploitation AFTER INSERT OR UPDATE of active OR DELETE on exploitation - FOR EACH ROW EXECUTE FUNCTION gw_trg_exploitation(); - - diff --git a/updates/36/36017/ws/ddlview.sql b/updates/36/36017/ws/ddlview.sql index 0ea2c4dd8c..21ba3008f6 100644 --- a/updates/36/36017/ws/ddlview.sql +++ b/updates/36/36017/ws/ddlview.sql @@ -859,19 +859,14 @@ WITH ) SELECT l.* FROM link_selected l; - - -CREATE OR REPLACE VIEW vu_om_mincut as -select distinct on (m.id) m.* from om_mincut m -JOIN config_user_x_expl USING (expl_id) -where username = current_user and m.id > 0; -CREATE OR REPLACE VIEW vu_sector as -SELECT DISTINCT ON (s.sector_id) s.sector_id, +DROP VIEW IF EXISTS v_edit_sector; +DROP VIEW IF EXISTS vu_sector; +CREATE OR REPLACE VIEW vu_sector +AS SELECT s.sector_id, s.name, s.macrosector_id, - m.name AS macrosector_name, - et.idval, + et.idval as sector_type, s.descript, s.parent_id, s.pattern_id, @@ -887,61 +882,38 @@ SELECT DISTINCT ON (s.sector_id) s.sector_id, s.lastupdate_user, s.the_geom FROM sector s - JOIN ( SELECT DISTINCT node.sector_id, node.expl_id FROM node WHERE node.state > 0) a USING (sector_id) - JOIN config_user_x_expl USING (expl_id) - LEFT JOIN macrosector m USING (macrosector_id) LEFT JOIN edit_typevalue et ON et.id::text = s.sector_type::text AND et.typevalue::text = 'sector_type'::text - WHERE config_user_x_expl.username::text = CURRENT_USER AND (s.sector_id > 0 or s.sector_id < -9) - UNION - select s.sector_id, - s.name, - s.macrosector_id, - m.name AS macrosector_name, - et.idval, - s.descript, - s.parent_id, - s.pattern_id, - s.graphconfig::text AS graphconfig, - s.stylesheet::text AS stylesheet, - s.link, - s.avg_press, - s.active, - s.undelete, - s.tstamp, - s.insert_user, - s.lastupdate, - s.lastupdate_user, - s.the_geom - FROM sector s - LEFT JOIN ( SELECT DISTINCT node.sector_id, node.expl_id FROM node WHERE node.state > 0) a USING (sector_id) - LEFT JOIN macrosector m USING (macrosector_id) - LEFT JOIN edit_typevalue et ON et.id::text = s.sector_type::text AND et.typevalue::text = 'sector_type'::text - where (s.sector_id > 0 or s.sector_id < -9) and a.sector_id is null - ORDER BY 1; - - - CREATE OR REPLACE VIEW v_edit_sector -AS SELECT vu_sector.sector_id, - vu_sector.name, - vu_sector.macrosector_id, - vu_sector.macrosector_name, - vu_sector.idval, - vu_sector.descript, - vu_sector.parent_id, - vu_sector.pattern_id, - vu_sector.graphconfig, - vu_sector.stylesheet, - vu_sector.link, - vu_sector.avg_press, - vu_sector.active, - vu_sector.undelete, - vu_sector.tstamp, - vu_sector.insert_user, - vu_sector.lastupdate, - vu_sector.lastupdate_user, - vu_sector.the_geom - FROM vu_sector, - selector_sector - WHERE vu_sector.sector_id = selector_sector.sector_id AND selector_sector.cur_user = "current_user"()::text - and active is true; - \ No newline at end of file + ORDER BY s.sector_id; + +DROP VIEW IF EXISTS v_edit_sector; +CREATE OR REPLACE VIEW v_edit_sector +AS SELECT s.* +FROM vu_sector s, selector_sector +WHERE s.sector_id = selector_sector.sector_id and active AND selector_sector.cur_user = "current_user"()::text; + +create trigger gw_trg_edit_sector instead of insert or delete or update on v_edit_sector +for each row execute function gw_trg_edit_sector('sector'); + +create or replace view v_edit_presszone as +select vu.* from vu_presszone vu, selector_expl +WHERE vu.expl_id = selector_expl.expl_id and active AND selector_expl.cur_user = "current_user"()::text OR vu.expl_id IS NULL +ORDER BY vu.presszone_id; + +create or replace view v_edit_dma as +select vu.* from vu_dma vu, selector_expl +WHERE vu.expl_id = selector_expl.expl_id and active AND selector_expl.cur_user = "current_user"()::text OR vu.expl_id IS NULL +ORDER BY vu.dma_id; + +create or replace view v_edit_dma as +select vu.* from vu_dma vu, selector_expl +WHERE vu.expl_id = selector_expl.expl_id and active AND selector_expl.cur_user = "current_user"()::text OR vu.expl_id IS NULL +ORDER BY vu.dma_id; + +create or replace view v_edit_dqa as +select vu.* from vu_dqa vu, selector_expl +WHERE vu.expl_id = selector_expl.expl_id and active AND selector_expl.cur_user = "current_user"()::text OR vu.expl_id IS NULL +ORDER BY vu.dqa_id; + + + + diff --git a/utils/fct/gw_fct_getselectors.sql b/utils/fct/gw_fct_getselectors.sql index 8bf09b7561..ef5842240d 100644 --- a/utils/fct/gw_fct_getselectors.sql +++ b/utils/fct/gw_fct_getselectors.sql @@ -7,7 +7,6 @@ This version of Giswater is provided by Giswater Association --FUNCTION CODE: 2796 --- DROP FUNCTION IF EXISTS SCHEMA_NAME.gw_fct_getselectors(p_data json); CREATE OR REPLACE FUNCTION SCHEMA_NAME.gw_fct_getselectors(p_data json) RETURNS json AS $BODY$ @@ -103,16 +102,19 @@ v_sectorfromexpl boolean; v_orderby_check boolean; v_sectorfrommacro boolean; v_explfrommacro boolean; +v_project_type text; BEGIN -- Set search path to local schema SET search_path = "SCHEMA_NAME", public; - -- get api version + -- get system values EXECUTE 'SELECT row_to_json(row) FROM (SELECT value FROM config_param_system WHERE parameter=''admin_version'') row' INTO v_version; + v_project_type = (SELECT project_type FROM sys_version LIMIT 1); + -- Get input parameters: v_selector_type := (p_data ->> 'data')::json->> 'selectorType'; v_currenttab := (p_data ->> 'form')::json->> 'currentTab'; @@ -170,6 +172,53 @@ BEGIN v_debug := json_build_object('querystring', v_query, 'vars', v_debug_vars, 'funcname', 'gw_fct_getselectors', 'flag', 10); SELECT gw_fct_debugsql(v_debug) INTO v_msgerr; + -- create temp tables related to expl x user variable + DROP TABLE IF EXISTS temp_exploitation; + DROP TABLE IF EXISTS temp_macroexploitation; + DROP TABLE IF EXISTS temp_sector; + DROP TABLE IF EXISTS temp_macrosector; + DROP TABLE IF EXISTS temp_mincut; + + IF v_expl_x_user is false then + CREATE TEMP TABLE temp_exploitation as select e.* from exploitation e WHERE active and expl_id > 0 order by 1; + CREATE TEMP TABLE temp_macroexploitation as select e.* from macroexploitation e WHERE active and macroexpl_id > 0 order by 1; + CREATE TEMP TABLE temp_sector as select e.* from sector e WHERE active and sector_id > 0 order by 1; + CREATE TEMP TABLE temp_macrosector as select e.* from macrosector e WHERE active and macrosector_id > 0 order by 1; + + IF v_project_type = 'WS' THEN + CREATE TEMP TABLE temp_mincut as select e.* from om_mincut e WHERE id > 0 order by 1; + END IF; + ELSE + CREATE TEMP TABLE temp_exploitation as select e.* from exploitation e + JOIN config_user_x_expl USING (expl_id) WHERE e.active and expl_id > 0 and username = current_user order by 1; + + CREATE TEMP TABLE temp_macroexploitation as select distinct on (m.macroexpl_id) m.* from macroexploitation m + JOIN temp_exploitation e USING (macroexpl_id) + WHERE m.active and m.macroexpl_id > 0 order by 1; + + CREATE TEMP TABLE temp_sector as + select distinct on (s.sector_id) s.sector_id, s.name, s.macrosector_id, s.descript, s.active from sector s + JOIN (SELECT DISTINCT node.sector_id, node.expl_id FROM node WHERE node.state > 0)n USING (sector_id) + JOIN exploitation e ON e.expl_id=n.expl_id + JOIN config_user_x_expl c ON c.expl_id=n.expl_id WHERE s.active and s.sector_id > 0 and username = current_user + UNION + select distinct on (s.sector_id) s.sector_id, s.name, s.macrosector_id, s.descript, s.active from sector s + JOIN (SELECT DISTINCT node.sector_id, node.expl_id FROM node WHERE node.state > 0)n USING (sector_id) + WHERE n.sector_id is null AND s.active and s.sector_id > 0 + order by 1; + + CREATE TEMP TABLE temp_macrosector as select distinct on (m.macrosector_id) m.* from macrosector m + JOIN temp_sector e USING (macrosector_id) + WHERE m.active and m.macrosector_id > 0; + + IF v_project_type = 'WS' THEN + CREATE TEMP TABLE temp_mincut AS select distinct on (m.id) m.* from om_mincut m + JOIN config_user_x_expl USING (expl_id) + where username = current_user and m.id > 0; + END IF; + END IF; + + -- starting loop for tabs FOR v_tab IN EXECUTE v_query ​ LOOP @@ -254,11 +303,6 @@ BEGIN END IF; END IF; - -- manage active mapzones - IF v_tab.tabname IN ('tab_sector', 'tab_exploitation', 'tab_macroexploitation', 'tab_macrosector') THEN - v_filterfrominput = CONCAT (v_filterfrominput, ' AND active '); - END IF; - -- built full filter v_fullfilter = concat(v_filterfromids, v_filterfromconfig, v_filterfrominput); diff --git a/utils/fct/gw_fct_setinitproject.sql b/utils/fct/gw_fct_setinitproject.sql index 63cc21a320..8e999a96c6 100644 --- a/utils/fct/gw_fct_setinitproject.sql +++ b/utils/fct/gw_fct_setinitproject.sql @@ -85,12 +85,6 @@ BEGIN -- delete on config_param_user fron updated values on sys_param_user DELETE FROM config_param_user WHERE parameter NOT IN (SELECT id FROM sys_param_user) AND cur_user = current_user; - -- insert expl_x_user - IF v_expl_x_user IS FALSE THEN - INSERT INTO config_user_x_expl SELECT distinct ON (expl_id) expl_id, current_user - from config_user_x_expl ON CONFLICT (expl_id, username) DO NOTHING; - END IF; - -- Force exploitation selector in case of null values IF v_qgis_init_guide_map AND (v_isaudit IS NULL OR v_isaudit = 'false') THEN DELETE FROM selector_expl WHERE cur_user = current_user; diff --git a/utils/fct/gw_fct_setselectors.sql b/utils/fct/gw_fct_setselectors.sql index 7985a8f7ff..94ab6d3a2b 100644 --- a/utils/fct/gw_fct_setselectors.sql +++ b/utils/fct/gw_fct_setselectors.sql @@ -87,7 +87,7 @@ BEGIN INTO v_version; -- get system variables - v_sectorfromexpl = (SELECT value::json->>'sectorfromexpl' FROM config_param_system WHERE parameter = 'basic_selector_options'); + v_sectorfromexpl = (SELECT value::json->>'sectorFromExpl' FROM config_param_system WHERE parameter = 'basic_selector_options'); v_sectorfrommacro = (SELECT value::json->>'sectorFromMacro' FROM config_param_system WHERE parameter = 'basic_selector_options'); v_explfrommacro = (SELECT value::json->>'explFromNacro' FROM config_param_system WHERE parameter = 'basic_selector_options'); diff --git a/utils/ftrg/gw_trg_exploitation.sql b/utils/ftrg/gw_trg_exploitation.sql deleted file mode 100644 index e4ae360161..0000000000 --- a/utils/ftrg/gw_trg_exploitation.sql +++ /dev/null @@ -1,57 +0,0 @@ -/* -This file is part of Giswater 3 -The program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -This version of Giswater is provided by Giswater Association -*/ - - ---FUNCTION CODE: 3368 - -CREATE OR REPLACE FUNCTION SCHEMA_NAME.gw_trg_exploitation() - RETURNS trigger AS -$BODY$ - -DECLARE -v_expl_x_user boolean; - -BEGIN - - EXECUTE 'SET search_path TO '||quote_literal(TG_TABLE_SCHEMA)||', public'; - - -- getting values from system - v_expl_x_user = (SELECT value FROM config_param_system WHERE parameter = 'admin_exploitation_x_user'); - - IF v_expl_x_user IS FALSE THEN - - IF TG_OP = 'INSERT' THEN - - -- for all users - INSERT INTO config_user_x_expl SELECT distinct ON (username) NEW.expl_id, username - from config_user_x_expl ON CONFLICT (expl_id, username) DO NOTHING; - - -- for this user (in case of does not exists) - INSERT INTO config_user_x_expl VALUES (NEW.expl_id, current_user) - ON CONFLICT (expl_id, username) DO NOTHING; - - RETURN NEW; - - ELSIF TG_OP = 'UPDATE' THEN - - RETURN NEW; - - ELSIF TG_OP = 'DELETE' THEN - - -- delete from config_user_x_expl - DELETE FROM config_user_x_expl WHERE expl_id = NEW.expl_id; - - RETURN OLD; - - END IF; - - END IF; - - -END; -$BODY$ - LANGUAGE plpgsql VOLATILE - COST 100; \ No newline at end of file