From 41b5fe2199545c56b0f50327ab69d44d7d343fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 13 Aug 2023 23:54:26 +0200 Subject: [PATCH] Fix editing gis data with twig strict types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Krög --- templates/gis_data_editor_form.twig | 266 +++++++++++++--------------- 1 file changed, 125 insertions(+), 141 deletions(-) diff --git a/templates/gis_data_editor_form.twig b/templates/gis_data_editor_form.twig index 75c70e548897..28d3414e5af6 100644 --- a/templates/gis_data_editor_form.twig +++ b/templates/gis_data_editor_form.twig @@ -46,160 +46,144 @@ {% endif %} - {% for a in 0..geom_count - 1 %} - {% if gis_data[a] is not null %} - {% if geom_type == 'GEOMETRYCOLLECTION' %} -

- {{ 'Geometry %d:'|trans|format(a + 1) }} -
- {% if gis_data[a]['gis_type'] is not null %} - {% set type = gis_data[a]['gis_type'] %} - {% else %} - {% set type = gis_types[0] %} - {% endif %} - - {% else %} - {% set type = geom_type %} - {% endif %} - - {% if type == 'POINT' %} -
- {% trans 'Point:' %} - - - - - {% elseif type == 'MULTIPOINT' or type == 'LINESTRING' %} - {% set no_of_points = gis_data[a][type]['no_of_points'] ?? 1 %} - {% if type == 'LINESTRING' and no_of_points < 2 %} - {% set no_of_points = 2 %} - {% endif %} - {% if type == 'MULTIPOINT' and no_of_points < 1 %} - {% set no_of_points = 1 %} - {% endif %} - {% if gis_data[a][type]['add_point'] is not null %} - {% set no_of_points = no_of_points + 1 %} - {% endif %} - - - {% for i in 0..no_of_points - 1 %} -
- {{ 'Point %d:'|trans|format(i + 1) }} - - - - - {% endfor %} - - {% elseif type == 'MULTILINESTRING' or type == 'POLYGON' %} - {% set no_of_lines = gis_data[a][type]['no_of_lines'] ?? 1 %} - {% if no_of_lines < 1 %} - {% set no_of_lines = 1 %} - {% endif %} - {% if gis_data[a][type]['add_line'] is not null %} - {% set no_of_lines = no_of_lines + 1 %} - {% endif %} - - - {% for i in 0..no_of_lines - 1 %} -
- {% if type == 'MULTILINESTRING' %} - {{ 'Linestring %d:'|trans|format(i + 1) }} - {% elseif i == 0 %} - {% trans 'Outer ring:' %} + {% if geom_count > 0 %} + {% for a in 0..geom_count - 1 %} + {% if gis_data[a] is not null %} + {% if geom_type == 'GEOMETRYCOLLECTION' %} +

+ {{ 'Geometry %d:'|trans|format(a + 1) }} +
+ {% if gis_data[a]['gis_type'] is not null %} + {% set type = gis_data[a]['gis_type'] %} + {% else %} + {% set type = gis_types[0] %} + {% endif %} + {% else %} - {{ 'Inner ring %d:'|trans|format(i) }} + {% set type = geom_type %} {% endif %} - {% set no_of_points = gis_data[a][type][i]['no_of_points'] ?? 2 %} - {% if type == 'MULTILINESTRING' and no_of_points < 2 %} - {% set no_of_points = 2 %} - {% endif %} - {% if type == 'POLYGON' and no_of_points < 4 %} - {% set no_of_points = 4 %} - {% endif %} - {% if gis_data[a][type][i]['add_point'] is not null %} - {% set no_of_points = no_of_points + 1 %} - {% endif %} - - - {% for j in 0..no_of_points - 1 %} + {% if type == 'POINT' %}
- {{ 'Point %d:'|trans|format(j + 1) }} + {% trans 'Point:' %} - + - - {% endfor %} - - {% endfor %} -
- - {% elseif type == 'MULTIPOLYGON' %} - {% set no_of_polygons = gis_data[a][type]['no_of_polygons'] ?? 1 %} - {% if no_of_polygons < 1 %} - {% set no_of_polygons = 1 %} - {% endif %} - {% if gis_data[a][type]['add_polygon'] is not null %} - {% set no_of_polygons = no_of_polygons + 1 %} - {% endif %} - - - {% for k in 0..no_of_polygons - 1 %} -
- {{ 'Polygon %d:'|trans|format(k + 1) }} - {% set no_of_lines = gis_data[a][type][k]['no_of_lines'] ?? 1 %} - {% if no_of_lines < 1 %} - {% set no_of_lines = 1 %} - {% endif %} - {% if gis_data[a][type][k]['add_line'] is not null %} - {% set no_of_lines = no_of_lines + 1 %} - {% endif %} - - - {% for i in 0..no_of_lines - 1 %} -

- {% if i == 0 %} - {% trans 'Outer ring:' %} - {% else %} - {{ 'Inner ring %d:'|trans|format(i) }} - {% endif %} - - {% set no_of_points = gis_data[a][type][k][i]['no_of_points'] ?? 4 %} - {% if no_of_points < 4 %} - {% set no_of_points = 4 %} + + {% elseif type == 'MULTIPOINT' or type == 'LINESTRING' %} + {% set no_of_points = gis_data[a][type]['no_of_points'] ?? 1 %} + {% if type == 'LINESTRING' and no_of_points < 2 %} + {% set no_of_points = 2 %} {% endif %} - {% if gis_data[a][type][k][i]['add_point'] is not null %} - {% set no_of_points = no_of_points + 1 %} + {% if type == 'MULTIPOINT' and no_of_points < 1 %} + {% set no_of_points = 1 %} {% endif %} - + - {% for j in 0..no_of_points - 1 %} + {% for i in 0..no_of_points - 1 %}
- {{ 'Point %d:'|trans|format(j + 1) }} + {{ 'Point %d:'|trans|format(i + 1) }} - + - + + {% endfor %} + + {% elseif type == 'MULTILINESTRING' or type == 'POLYGON' %} + {% set no_of_lines = gis_data[a][type]['no_of_lines'] ?? 1 %} + {% if no_of_lines < 1 %} + {% set no_of_lines = 1 %} + {% endif %} + + + {% for i in 0..no_of_lines - 1 %} +
+ {% if type == 'MULTILINESTRING' %} + {{ 'Linestring %d:'|trans|format(i + 1) }} + {% elseif i == 0 %} + {% trans 'Outer ring:' %} + {% else %} + {{ 'Inner ring %d:'|trans|format(i) }} + {% endif %} + + {% set no_of_points = gis_data[a][type][i]['no_of_points'] ?? 2 %} + {% if type == 'MULTILINESTRING' and no_of_points < 2 %} + {% set no_of_points = 2 %} + {% endif %} + {% if type == 'POLYGON' and no_of_points < 4 %} + {% set no_of_points = 4 %} + {% endif %} + + + {% for j in 0..no_of_points - 1 %} +
+ {{ 'Point %d:'|trans|format(j + 1) }} + + + + + {% endfor %} + {% endfor %} - - {% endfor %} -
- -
- {% endfor %} -
- - {% endif %} - {% endif %} - {% endfor %} +
+ + {% elseif type == 'MULTIPOLYGON' %} + {% set no_of_polygons = gis_data[a][type]['no_of_polygons'] ?? 1 %} + {% if no_of_polygons < 1 %} + {% set no_of_polygons = 1 %} + {% endif %} + + + {% for k in 0..no_of_polygons - 1 %} +
+ {{ 'Polygon %d:'|trans|format(k + 1) }} + {% set no_of_lines = gis_data[a][type][k]['no_of_lines'] ?? 1 %} + {% if no_of_lines < 1 %} + {% set no_of_lines = 1 %} + {% endif %} + + + {% for i in 0..no_of_lines - 1 %} +

+ {% if i == 0 %} + {% trans 'Outer ring:' %} + {% else %} + {{ 'Inner ring %d:'|trans|format(i) }} + {% endif %} + + {% set no_of_points = gis_data[a][type][k][i]['no_of_points'] ?? 4 %} + {% if no_of_points < 4 %} + {% set no_of_points = 4 %} + {% endif %} + + + {% for j in 0..no_of_points - 1 %} +
+ {{ 'Point %d:'|trans|format(j + 1) }} + + + + + {% endfor %} + + {% endfor %} +
+ +
+ {% endfor %} +
+ + {% endif %} + {% endif %} + {% endfor %} + {% endif %} {% if geom_type == 'GEOMETRYCOLLECTION' %}