Skip to content

Commit 8ad5b89

Browse files
committed
Merge branch 'develop' into 'master'
Develop See merge request gtt/redmine_gtt!10
2 parents 0b19069 + 4d5652c commit 8ad5b89

26 files changed

+262
-193
lines changed

app/helpers/gtt_map_helper.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module GttMapHelper
4+
5+
def map_form_field(form, map, field: :geojson, edit_mode:)
6+
safe_join [
7+
form.hidden_field(field, id: 'geom'),
8+
map_tag(map: map, bounds: map.bounds, edit: edit_mode)
9+
]
10+
end
11+
12+
def map_tag(map: nil, layers: map&.layers,
13+
geom: map.json, bounds: map.bounds,
14+
edit: nil)
15+
16+
data = {
17+
geom: geom,
18+
layers: layers
19+
}
20+
data[:bounds] = bounds if bounds
21+
data[:edit] = edit if edit
22+
23+
map_id = rand(36**8).to_s(36)
24+
content_tag(:div, "", data: data, id: "ol-#{map_id}", class: 'ol-map')
25+
end
26+
27+
end

app/models/gtt_configuration.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
class GttConfiguration
22
include ActiveModel::Model
33

4-
attr_accessor :project, :gtt_tile_source_ids
4+
attr_accessor :project, :geojson, :gtt_tile_source_ids
55

66
def self.for(project)
7-
new project: project
7+
new(
8+
project: project,
9+
geojson: project.geojson,
10+
gtt_tile_source_ids: project.gtt_tile_source_ids
11+
)
812
end
913

10-
def gtt_tile_source_ids
11-
project.gtt_tile_source_ids
14+
def self.from_params(params)
15+
new geojson: params[:geojson],
16+
gtt_tile_source_ids: params[:gtt_tile_source_ids]
1217
end
1318

14-
def gtt_tile_source_ids=(ids)
15-
project.gtt_tile_source_ids = ids
19+
def map
20+
GttMap.new json: geojson, layers: project.gtt_tile_sources
1621
end
22+
1723
end

app/models/gtt_map.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class GttMap
2+
3+
attr_reader :layers, :json, :bounds
4+
5+
def initialize(wkb: nil, json: nil, layers:, bounds: nil)
6+
unless @json = json
7+
@json = RedmineGtt::Conversions.wkb_to_json wkb if wkb
8+
end
9+
10+
@bounds = bounds || @json
11+
@layers = layers
12+
end
13+
14+
end

app/overrides/projects.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
Deface::Override.new(
2-
:virtual_path => "projects/_form",
3-
:name => "deface_view_projects_form_map",
4-
:insert_after => "div.box",
5-
:partial => "projects/form/map"
6-
)
7-
81
Deface::Override.new(
92
:virtual_path => "projects/show",
103
:name => "deface_view_projects_show_map",

app/overrides/users.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
Deface::Override.new(
2-
:virtual_path => "my/account",
3-
:name => "deface_view_users_account_map",
4-
:insert_after => "div.splitcontentleft fieldset.box",
5-
:partial => "users/form/map"
6-
)
7-
8-
Deface::Override.new(
9-
:virtual_path => "users/_form",
10-
:name => "deface_view_users_form_map",
11-
:insert_bottom => "div.splitcontentleft",
12-
:partial => "users/form/map"
13-
)
14-
15-
Deface::Override.new(
16-
:virtual_path => "users/show",
17-
:name => "deface_view_users_show_map",
18-
:insert_bottom => "div.splitcontentleft",
19-
:partial => "users/show/map"
20-
)
21-
221
Deface::Override.new(
232
:virtual_path => "users/show",
243
:name => "deface_view_users_show_other_formats",
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
1-
<% return '' if @issue.nil? || @issue.project.nil? %>
2-
<% return '' unless User.current.allowed_to?(:view_issues, @issue.project) %>
3-
4-
<%
5-
if @issue.new_record?
6-
return '' unless User.current.allowed_to?(:add_issues, @issue.project)
7-
else
8-
return '' unless User.current.allowed_to?(:edit_issues, @issue.project)
9-
end
1+
<% if (@project.nil? or @project.module_enabled?(:gtt)) &&
2+
((@issue.new_record? && User.current.allowed_to?(:add_issues, @issue.project)) ||
3+
User.current.allowed_to?(:edit_issues, @issue.project))
104
%>
11-
12-
<% if @project.nil? or @project.module_enabled?(:gtt) %>
135
<div class="box">
14-
<%= f.hidden_field(:geom, :value => @issue.geojson, :id => 'geom') %>
15-
16-
<%= content_tag(:div, "", :data => {
17-
:geom => @issue.geojson,
18-
:bounds => @project.geojson,
19-
:layers => @project.gtt_tile_sources,
20-
:edit => 'Point LineString Polygon'
21-
}, :id => 'ol-' + rand(36**8).to_s(36), :class => 'ol-map')
22-
%>
6+
<%= map_form_field f, @issue.map, edit_mode: 'Point LineString Polygon' %>
237
</div>
248
<% end %>

app/views/projects/form/_map.html.erb

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/views/projects/settings/_gtt.html.erb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
<% @gtt_configuration ||= GttConfiguration.for(@project) %>
2-
<%= labelled_form_for @gtt_configuration,
1+
<% @form ||= GttConfiguration.for(@project) %>
2+
<%= labelled_form_for @form,
33
url: update_gtt_configuration_path(@project),
44
html: { method: :put } do |f| %>
55

66
<h3><%= t :label_gtt_settings_headline %></h3>
7+
78
<div class="box tabular">
89
<p>
910
<%= f.select :gtt_tile_source_ids,
10-
options_from_collection_for_select(GttTileSource.all.order(name: :asc), :id, :name, selected: @gtt_configuration.gtt_tile_source_ids),
11+
options_from_collection_for_select(GttTileSource.all.order(name: :asc), :id, :name, selected: @form.gtt_tile_source_ids),
1112
{}, { multiple: true, size: 5 } %>
1213
<br /><em><%= t :gtt_tile_sources_info %></em>
1314
</p>
1415
</div>
1516

17+
<div class="box">
18+
<%= map_form_field f, @form.map, edit_mode: 'Polygon' %>
19+
</div>
20+
21+
1622
<%= submit_tag l(:button_save) %>
1723

1824
<% end %>

app/views/projects/show/_map.html.erb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
<div class="usermap box">
33
<h3><%= l(:label_project_map) %></h3>
44

5-
<%= content_tag(:div, "",:data => {
6-
:geom => @project.geojson,
7-
:bounds => @project.geojson,
8-
:layers => @project.gtt_tile_sources
9-
}, :id => 'ol-' + rand(36**8).to_s(36), :class => 'ol-map')
10-
%>
5+
<%= map_tag map: @project.map %>
116
</div>
127
<% end %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
</fieldset>
2+
<fieldset class="box tabular">
3+
<legend><%= l(:label_user_map) %></legend>
4+
<%= map_form_field form, user.map, edit_mode: 'Point' %>
5+

0 commit comments

Comments
 (0)