Skip to content

Commit edb5f3f

Browse files
committed
fixes Support geoquery as condition #12
Signed-off-by: Daniel Kastl <[email protected]>
1 parent d8a532e commit edb5f3f

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

app/views/subscription_templates/_form.html.erb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,43 @@
3333

3434
<p><%= f.text_field :attrs, size: 75, placeholder: l(:field_subscription_template_attrs_placeholder) %>
3535
<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>
3638
<p><%= f.text_field :expression_georel, size: 75, placeholder: l(:field_subscription_template_expression_georel_placeholder) %>
3739
<p class="min-width"><%= f.select :expression_geometry, SubscriptionTemplate::GEOMETRIES, include_blank: true %></p>
3840
<p><%= f.text_field :expression_coords, size: 75, placeholder: l(:field_subscription_template_expression_coords_placeholder) %>
3941

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+
4073
<p>
4174
<%= content_tag :label, l(:field_subscription_template_alteration_types) %>
4275
<% SubscriptionTemplate::ALTERATION_TYPES.each do |type| %>

config/locales/en.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ en:
4343
field_subscription_template_attrs_placeholder: "[\"temperature\"]"
4444
field_subscription_template_expression_query: "Query"
4545
field_subscription_template_expression_query_placeholder: "temperature > 30"
46+
47+
gtt_fiware_subscription_template_geoquery: "Geospatial Query"
4648
field_subscription_template_expression_georel: "Georel"
4749
field_subscription_template_expression_georel_placeholder: "near;maxDistance:1000"
4850
field_subscription_template_expression_geometry: "Geometry"
@@ -62,6 +64,11 @@ en:
6264
field_subscription_template_attachments_placeholder: "[{\"filename\": \"image.jpg\", \"url\": \"https://example.com/image.jpg\"}]"
6365
field_subscription_template_notification_user: "Sent from user"
6466

67+
link_to_insert_project_geometry: "Insert project boundary"
68+
link_to_insert_project_geometry_hint: "This will use the project boundary as the geospatial query for the subscription"
69+
project_geometry_not_defined: "Project boundary is not defined"
70+
project_geometry_not_supported_multipolygon: "Project boundary is a multipolygon, which is not supported for geospatial queries"
71+
6572
link_to_copy: "Clipboard"
6673
link_to_copy_hint: "Copy command to clipboard"
6774
command_copied: "Command copied to clipboard"

config/locales/ja.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ en:
4343
field_subscription_template_attrs_placeholder: "[\"temperature\"]"
4444
field_subscription_template_expression_query: "Query"
4545
field_subscription_template_expression_query_placeholder: "temperature > 30"
46+
47+
gtt_fiware_subscription_template_geoquery: "Geospatial Query"
4648
field_subscription_template_expression_georel: "Georel"
4749
field_subscription_template_expression_georel_placeholder: "near;maxDistance:1000"
4850
field_subscription_template_expression_geometry: "Geometry"
@@ -62,6 +64,11 @@ en:
6264
field_subscription_template_attachments_placeholder: "[{\"filename\": \"image.jpg\", \"url\": \"https://example.com/image.jpg\"}]"
6365
field_subscription_template_notification_user: "Sent from user"
6466

67+
link_to_insert_project_geometry: "Insert project boundary"
68+
link_to_insert_project_geometry_hint: "This will use the project boundary as the geospatial query for the subscription"
69+
project_geometry_not_defined: "Project boundary is not defined"
70+
project_geometry_not_supported_multipolygon: "Project boundary is a multipolygon, which is not supported for geospatial queries"
71+
6572
link_to_copy: "Clipboard"
6673
link_to_copy_hint: "Copy command to clipboard"
6774
command_copied: "Command copied to clipboard"

0 commit comments

Comments
 (0)