|
33 | 33 |
|
34 | 34 | <p><%= f.text_field :attrs, size: 75, placeholder: l(:field_subscription_template_attrs_placeholder) %>
|
35 | 35 | <p><%= f.text_field :expression_query, size: 75, placeholder: l(:field_subscription_template_expression_query_placeholder) %>
|
| 36 | + |
| 37 | + <h4><%= l(:gtt_fiware_subscription_template_geoquery) %></h4> |
36 | 38 | <p><%= f.text_field :expression_georel, size: 75, placeholder: l(:field_subscription_template_expression_georel_placeholder) %>
|
37 | 39 | <p class="min-width"><%= f.select :expression_geometry, SubscriptionTemplate::GEOMETRIES, include_blank: true %></p>
|
38 | 40 | <p><%= f.text_field :expression_coords, size: 75, placeholder: l(:field_subscription_template_expression_coords_placeholder) %>
|
39 | 41 |
|
| 42 | + <% if @project.module_enabled?('gtt') %> |
| 43 | + <p> |
| 44 | + <% if @project.geom.present? && @project.geojson.present? %> |
| 45 | + <% if JSON.parse(@project.geojson.to_json)['geometry']['type'] == 'Polygon' %> |
| 46 | + <%= link_to l(:link_to_insert_project_geometry), '#', class: 'insert-project-geometry-link icon icon-gtt-map', title: l(:link_to_insert_project_geometry_hint), data: { geom: @project.geojson.to_json } %> |
| 47 | + <% elsif JSON.parse(@project.geojson.to_json)['geometry']['type'] == 'MultiPolygon' %> |
| 48 | + <%= l(:project_geometry_not_supported_multipolygon) %> |
| 49 | + <% else %> |
| 50 | + <%= l(:project_geometry_not_defined) %> |
| 51 | + <% end %> |
| 52 | + <% else %> |
| 53 | + <%= l(:project_geometry_not_defined) %> |
| 54 | + <% end %> |
| 55 | + </p> |
| 56 | + <% end %> |
| 57 | + |
| 58 | + <script> |
| 59 | + document.addEventListener('DOMContentLoaded', function() { |
| 60 | + var link = document.querySelector('.insert-project-geometry-link'); |
| 61 | + if (link) { |
| 62 | + link.addEventListener('click', function(e) { |
| 63 | + e.preventDefault(); |
| 64 | + var geom = JSON.parse(e.target.dataset.geom).geometry.coordinates[0].map(coord => [Number(coord[0].toFixed(5)), Number(coord[1].toFixed(5))]).join(';'); |
| 65 | + document.querySelector('input[name="subscription_template[expression_coords]"]').value = geom; |
| 66 | + document.querySelector('select[name="subscription_template[expression_geometry]"]').value = 'polygon'; |
| 67 | + document.querySelector('input[name="subscription_template[expression_georel]"]').value = 'coveredBy'; |
| 68 | + }); |
| 69 | + } |
| 70 | + }); |
| 71 | +</script> |
| 72 | + |
40 | 73 | <p>
|
41 | 74 | <%= content_tag :label, l(:field_subscription_template_alteration_types) %>
|
42 | 75 | <% SubscriptionTemplate::ALTERATION_TYPES.each do |type| %>
|
|
0 commit comments