Skip to content

Commit 47de3de

Browse files
committed
Merge branch 'main' into develop
2 parents d1ad3a5 + 3953592 commit 47de3de

File tree

10 files changed

+75
-10
lines changed

10 files changed

+75
-10
lines changed

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gem 'deface'
44
gem 'immutable-struct'
55
gem "rgeo"
66
gem "rgeo-geojson"
7-
gem "rgeo-activerecord"
87
gem "pg", (ENV['GEM_PG_VERSION'] ? "~> #{ENV['GEM_PG_VERSION']}" : "~> 1.1.4") # make sure we use a version compatible with AR
9-
gem 'activerecord-postgis-adapter'
8+
gem "rgeo-activerecord", (ENV['GEM_RGEO_ACTIVERECORD_VERSION'] ? "~> #{ENV['GEM_RGEO_ACTIVERECORD_VERSION']}" : "~> 6.2.2") # same as above
9+
gem 'activerecord-postgis-adapter', (ENV['GEM_ACTIVERECORD_POSTGIS_ADAPTER_VERSION'] ? "~> #{ENV['GEM_ACTIVERECORD_POSTGIS_ADAPTER_VERSION']}" : "~> 5.2.3") # same as above
1010
gem 'rails-controller-testing' # This gem brings back assigns to your controller tests as well as assert_template to both controller and integration tests.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Then run
4545

4646
```
4747
export GEM_PG_VERSION=your-pg-version # skip this line if redmine use pg 1.1.4.
48+
export GEM_RGEO_ACTIVERECORD_VERSION=your-rgeo-activerecord-version # skip this line if using rgeo-activerecord 6.2.2.
49+
export GEM_ACTIVERECORD_POSTGIS_ADAPTER_VERSION=your-activerecord-postgis-adapter-version # skip this line if using activerecord-postgis-adapter 5.2.3.
4850
bundle install
4951
bundle exec rake redmine:plugins:migrate
5052
```
@@ -55,6 +57,14 @@ After restarting Redmine, you should be able to see the Redmine GTT plugin in th
5557

5658
More information on installing (and uninstalling) Redmine plugins can be found here: http://www.redmine.org/wiki/redmine/Plugins
5759

60+
## How to run test
61+
62+
After the installation, you can run the plugin test by the following command:
63+
64+
```
65+
RAILS_ENV=test NAME=redmine_gtt bundle exec rake redmine:plugins:test
66+
```
67+
5868
## How to use
5969

6070
1. Go to plugin configuration for global settings

app/views/issues/index/_map.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<% if @project and @project.module_enabled?(:gtt) %>
22

3-
<fieldset id="location" class="collapsible collapsed">
4-
<legend class="icon icon-collapsed"><%= l(:field_location) %></legend>
3+
<fieldset id="location" class="collapsible">
4+
<legend class="icon icon-expended"><%= l(:field_location) %></legend>
55

66
<%= map_tag map: @project.map, geom: (Issue.array_to_geojson(@issues, include_properties: { only: %i(id subject tracker_id status_id) }) if @issues), popup: { href: '/issues/[id]' } %>
77
</fieldset>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# English strings go here for Rails i18n
22
en:
33
error_invalid_json: must be valid JSON
4+
error_unable_to_update_project_gtt_settings: "Unable to update project GTT settings (%{value})"
45

56
field_default: Default for new projects
67
field_geometry: "Geometry"

config/locales/ja.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Japanese strings go here for Rails i18n
22
ja:
33
error_invalid_json: "正しいJSONにしてください"
4+
error_unable_to_update_project_gtt_settings: "プロジェクトのGTTの設定を更新できません (%{value})"
45

56
field_default: "新規プロジェクトのデフォルト"
67
field_geometry: "所在地"

lib/redmine_gtt/actions/update_project_settings.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ def update_project
2626
if tile_source_ids = @form.gtt_tile_source_ids
2727
@project.gtt_tile_source_ids = tile_source_ids
2828
end
29-
@project.geojson = @form.geojson
29+
30+
begin
31+
@project.geojson = @form.geojson
32+
rescue RGeo::Error::InvalidGeometry => e
33+
@project.errors.add(:geom, :invalid)
34+
return false
35+
end
3036

3137
@project.save
3238
end

lib/redmine_gtt/patches/projects_controller_patch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def update_gtt_configuration
4747
if r.settings_saved?
4848
flash.now[:notice] = l(:notice_successful_update)
4949
else
50-
flash.now[:error] = r.error
50+
flash.now[:error] = l(:error_unable_to_update_project_gtt_settings, "#{r.error}")
5151
end
5252

5353
end

src/stylesheets/app.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ div.usermap h3 {
3434
}
3535

3636
/* hide Map on issues list by default */
37-
fieldset#location > div.ol-map{
38-
display: none;
39-
}
37+
//fieldset#location > div.ol-map{
38+
// display: none;
39+
//}

test/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def point_geojson(coordinates)
1414
{'type'=>'Feature','geometry'=>{ 'type'=>'Point','coordinates'=> coordinates}}.to_json
1515
end
1616

17+
def multipolygon_geojson(coordinates)
18+
{'type'=>'Feature','geometry'=>{ 'type'=>'MultiPolygon','coordinates'=> coordinates}}.to_json
19+
end
20+
1721
def test_geom
1822
RedmineGtt::Conversions::WkbToGeom.("01030000000100000006000000C84B374110E76040381DD011545A4140C84B3739ACE96040F07E6DCC7A594140C84B37F199E960403CBC2D58E2554140C84B373917E8604098CBC3E188564140C84B37FD36E66040F24C2E959D564140C84B374110E76040381DD011545A4140")
1923
end

test/unit/update_project_settings_test.rb

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require_relative '../test_helper'
22

3-
class UpdateProjectSettingsTest < ActiveSupport::TestCase
3+
class UpdateProjectSettingsTest < GttTest
44
fixtures :projects
55

66
test 'should save tile sources' do
@@ -15,6 +15,49 @@ class UpdateProjectSettingsTest < ActiveSupport::TestCase
1515
p.reload
1616
assert_equal [ts], p.gtt_tile_sources.to_a
1717
end
18+
19+
test 'should validate invalid multipolygon geometry' do
20+
p = Project.find 'ecookbook'
21+
coordinates = [
22+
[
23+
[[135.0, 35.0], [136.0, 35.0], [136.0, 36.0], [135.0, 36.0], [135.0, 35.0]]
24+
],
25+
[
26+
[[136.0, 35.0], [137.0, 35.0], [137.0, 36.0], [136.0, 36.0], [136.0, 35.0]]
27+
]
28+
]
29+
30+
form = GttConfiguration.from_params geojson: multipolygon_geojson(coordinates)
31+
form.project = p
32+
r = RedmineGtt::Actions::UpdateProjectSettings.( form )
33+
34+
assert_not r.settings_saved?
35+
36+
p.reload
37+
assert_include 'Geometry is invalid', p.errors.full_messages
38+
end
39+
40+
test 'should save valid multipolygon geometry' do
41+
p = Project.find 'ecookbook'
42+
coordinates = [
43+
[
44+
[[135.0, 35.0], [136.0, 35.0], [136.0, 36.0], [135.0, 36.0], [135.0, 35.0]]
45+
],
46+
[
47+
[[137.0, 35.0], [138.0, 35.0], [138.0, 36.0], [137.0, 36.0], [137.0, 35.0]]
48+
]
49+
]
50+
51+
form = GttConfiguration.from_params geojson: multipolygon_geojson(coordinates)
52+
form.project = p
53+
r = RedmineGtt::Actions::UpdateProjectSettings.( form )
54+
55+
assert r.settings_saved?
56+
57+
p.reload
58+
assert_equal coordinates, JSON.parse(p.geojson)['geometry']['coordinates']
59+
end
60+
1861
end
1962

2063

0 commit comments

Comments
 (0)