Skip to content

Commit a6d9b1a

Browse files
authored
Merge pull request #233 from gtt-project/ftr/next-gtt-layers
Ftr/next gtt layers
2 parents 7fd26b1 + a1f3304 commit a6d9b1a

File tree

122 files changed

+6221
-5442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+6221
-5442
lines changed

.gitignore

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1+
# Ignore commonly generated/ignored files
12
.DS_Store
2-
node_modules
3-
# webpack generate files
4-
assets/javascripts/main.js
5-
assets/javascripts/main.js.*
6-
assets/javascripts/*.png
7-
assets/javascripts/*.svg
8-
assets/javascripts/*.ttf
9-
assets/javascripts/*.eot
10-
assets/javascripts/*.woff2
11-
assets/javascripts/*.woff
12-
3+
node_modules/
134

5+
# Ignore webpack generated files
6+
assets/*
7+
!assets/.keep

Gemfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
source 'https://rubygems.org'
22

3+
# Define gem versions with environment variables or default versions
4+
gem_versions = {
5+
pg: ENV['GEM_PG_VERSION'] || '1.4.6',
6+
rgeo: ENV['GEM_RGEO_VERSION'] || '3.0.0',
7+
rgeo_activerecord: ENV['GEM_RGEO_ACTIVERECORD_VERSION'] || '7.0.1',
8+
activerecord_postgis_adapter: ENV['GEM_ACTIVERECORD_POSTGIS_ADAPTER_VERSION'] || '7.1.1'
9+
}
10+
311
gem 'deface'
412
gem 'immutable-struct'
5-
gem "rgeo", "~> 2.4.0"
13+
gem "rgeo", "~> #{gem_versions[:rgeo]}"
614
gem "rgeo-geojson"
7-
gem "pg", (ENV['GEM_PG_VERSION'] ? "~> #{ENV['GEM_PG_VERSION']}" : "~> 1.2.2") # make sure we use a version compatible with AR
8-
gem "rgeo-activerecord", (ENV['GEM_RGEO_ACTIVERECORD_VERSION'] ? "~> #{ENV['GEM_RGEO_ACTIVERECORD_VERSION']}" : "~> 7.0.1") # same as above
9-
gem 'activerecord-postgis-adapter', (ENV['GEM_ACTIVERECORD_POSTGIS_ADAPTER_VERSION'] ? "~> #{ENV['GEM_ACTIVERECORD_POSTGIS_ADAPTER_VERSION']}" : "~> 7.1.1") # same as above
15+
gem "pg", "~> #{gem_versions[:pg]}"
16+
gem "rgeo-activerecord", "~> #{gem_versions[:rgeo_activerecord]}"
17+
gem 'activerecord-postgis-adapter', "~> #{gem_versions[:activerecord_postgis_adapter]}"
1018
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ The Geo-Task-Tracker (GTT) plugin adds spatial capabilities to Redmine:
1717
Redmine GTT plugins **require PostgreSQL/PostGIS** and will not work with SQLite
1818
or MariaDB/MySQL!!!
1919

20-
- Redmine >= 4.2.0
21-
- PostgreSQL >= 10
20+
- Redmine >= 5.0.0
21+
- PostgreSQL >= 12
2222
- PostGIS >= 2.5
23-
- NodeJS v14
23+
- NodeJS v18
2424
- yarn
2525

2626
## Installation
@@ -91,7 +91,7 @@ Help us to translate GTT Project using [OSGeo Weblate](https://weblate.osgeo.org
9191
You can debug frontend by running the following command on another console:
9292

9393
```sh
94-
npx webpack --watch --mode=development
94+
npx webpack --watch --mode=development --devtool=source-map
9595
```
9696

9797
### How to run test
Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,73 @@
11
class GttConfigurationController < ApplicationController
22

3-
before_action :find_optional_project_and_authorize
3+
before_action :find_optional_project_and_authorize
44

5-
accept_api_auth :default_setting_configuration
5+
accept_api_auth :default_setting_configuration
66

7-
def default_setting_configuration
8-
gtt_map_config = build_default_setting_config
9-
respond_to do |format|
10-
format.api { render json: build_default_setting_config}
11-
end
7+
def default_setting_configuration
8+
gtt_map_config = build_default_setting_config
9+
respond_to do |format|
10+
format.api { render json: build_default_setting_config}
1211
end
12+
end
1313

14-
def build_default_setting_config
15-
default_tracker_icon = []
16-
default_status_color = []
17-
gtt_tile_source = []
14+
def build_default_setting_config
15+
default_tracker_icon = []
16+
default_status_color = []
17+
gtt_map_layer = []
1818

19-
Tracker.all.sort.each {|tracker|
20-
default_tracker_icon.append({
21-
trackerID: tracker.id,
22-
trackerName: tracker.name,
23-
icon: Setting.plugin_redmine_gtt['tracker_'+tracker.id.to_s]
24-
})
25-
}
26-
IssueStatus.all.sort.each {|status|
27-
default_status_color.append({
28-
statusID: status.id,
29-
statusName: status.name,
30-
color: Setting.plugin_redmine_gtt['status_'+status.id.to_s]
31-
})
32-
}
33-
GttTileSource.where(global: true).sort.each {|tileSource|
34-
gtt_tile_source.append({
35-
id: tileSource.id,
36-
name: tileSource.name,
37-
type: tileSource.type,
38-
options: tileSource.options
39-
})
40-
}
19+
Tracker.all.sort.each {|tracker|
20+
default_tracker_icon.append({
21+
trackerID: tracker.id,
22+
trackerName: tracker.name,
23+
icon: Setting.plugin_redmine_gtt['tracker_'+tracker.id.to_s]
24+
})
25+
}
4126

42-
mapConfig = {
43-
gttDefaultSetting: {
44-
defaultTrackerIcon: default_tracker_icon,
45-
defaultStatusColor: default_status_color,
46-
defaultMapSetting: {
47-
centerLng: Setting.plugin_redmine_gtt['default_map_center_longitude'],
48-
centerLat: Setting.plugin_redmine_gtt['default_map_center_latitude']
49-
},
50-
geometrySetting: {
51-
geometryTypes: Setting.plugin_redmine_gtt['editable_geometry_types_on_issue_map'],
52-
GeoJsonUpload: (Setting.plugin_redmine_gtt['enable_geojson_upload_on_issue_map'] == 'true'),
53-
},
54-
geocoderSetting: {
55-
enableGeocodingOnMap: (Setting.plugin_redmine_gtt['enable_geocoding_on_map'] == 'true'),
56-
geocoderOptions: Setting.plugin_redmine_gtt['default_geocoder_options']
57-
},
58-
},
59-
gttLayer: gtt_tile_source,
60-
}
61-
return mapConfig
62-
end
27+
IssueStatus.all.sort.each {|status|
28+
default_status_color.append({
29+
statusID: status.id,
30+
statusName: status.name,
31+
color: Setting.plugin_redmine_gtt['status_'+status.id.to_s]
32+
})
33+
}
34+
35+
GttMapLayer.where(global: true).sort.each {|mapLayer|
36+
gtt_map_layer.append(
37+
mapLayer.as_json.except("created_at", "updated_at","position","global")
38+
)
39+
}
40+
41+
mapConfig = {
42+
gttDefaultSetting: {
43+
defaultTrackerIcon: default_tracker_icon,
44+
defaultStatusColor: default_status_color,
45+
defaultMapSetting: {
46+
centerLng: Setting.plugin_redmine_gtt['default_map_center_longitude'],
47+
centerLat: Setting.plugin_redmine_gtt['default_map_center_latitude']
48+
},
49+
geometrySetting: {
50+
geometryTypes: Setting.plugin_redmine_gtt['editable_geometry_types_on_issue_map'],
51+
GeoJsonUpload: (Setting.plugin_redmine_gtt['enable_geojson_upload_on_issue_map'] == 'true'),
52+
},
53+
geocoderSetting: {
54+
enableGeocodingOnMap: (Setting.plugin_redmine_gtt['enable_geocoding_on_map'] == 'true'),
55+
geocoderOptions: Setting.plugin_redmine_gtt['default_geocoder_options']
56+
},
57+
},
58+
gttLayer: gtt_map_layer,
59+
}
60+
return mapConfig
61+
end
6362

64-
private
63+
private
6564

66-
def find_optional_project_and_authorize
67-
if params[:project_id]
68-
@project = Project.find params[:project_id]
69-
authorize
70-
else
71-
authorize_global
72-
end
65+
def find_optional_project_and_authorize
66+
if params[:project_id]
67+
@project = Project.find(params[:project_id])
68+
authorize
69+
else
70+
authorize_global
7371
end
72+
end
7473
end

app/controllers/gtt_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class GttController < ApplicationController
2+
def map
3+
path = Rails.root.join('public', 'plugin_assets', 'redmine_gtt', 'javascripts', 'main.js.map')
4+
send_file path, type: 'application/json', disposition: 'inline'
5+
end
6+
end
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
class GttMapLayersController < ApplicationController
2+
layout 'admin'
3+
4+
before_action :require_admin
5+
6+
self.main_menu = false
7+
8+
def index
9+
@map_layers = GttMapLayer.sorted
10+
end
11+
12+
def new
13+
@map_layer = GttMapLayer.new
14+
end
15+
16+
def create
17+
r = RedmineGtt::Actions::CreateMapLayer.(map_layer_params)
18+
if r.map_layer_created?
19+
redirect_to(params[:continue] ? new_gtt_map_layer_path : gtt_map_layers_path)
20+
else
21+
@map_layer = r.map_layer
22+
render 'new'
23+
end
24+
end
25+
26+
def edit
27+
@map_layer = GttMapLayer.find(params[:id])
28+
end
29+
30+
def update
31+
ml = GttMapLayer.find(params[:id])
32+
r = RedmineGtt::Actions::UpdateMapLayer.(ml, map_layer_params)
33+
if r.map_layer_updated?
34+
respond_to do |format|
35+
format.html {
36+
flash[:notice] = l(:notice_successful_update)
37+
redirect_to gtt_map_layers_path
38+
}
39+
format.js { head 200 }
40+
end
41+
else
42+
respond_to do |format|
43+
format.html {
44+
@map_layer = r.map_layer
45+
render 'edit'
46+
}
47+
format.js { head 422 }
48+
end
49+
end
50+
end
51+
52+
def destroy
53+
ml = GttMapLayer.find(params[:id])
54+
ml.destroy
55+
redirect_to gtt_map_layers_path
56+
end
57+
58+
private
59+
60+
def map_layer_params
61+
return {} unless params[:map_layer]
62+
63+
params[:map_layer].permit(
64+
:name, :default, :global, :baselayer, :position,
65+
:layer, :layer_options_string,
66+
:source, :source_options_string,
67+
:format, :format_options_string,
68+
:styles
69+
)
70+
end
71+
end

app/controllers/gtt_tile_sources_controller.rb

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module GttMapLayersHelper
2+
def pretty_map_layer_layer_options(map_layer)
3+
JSON.pretty_generate map_layer.layer_options if Hash === map_layer.layer_options
4+
end
5+
6+
def map_layer_layer_options(map_layer)
7+
safe_join map_layer.layer_options.to_a.select{
8+
|k,v| v.present?
9+
}.map{|k,v|
10+
"#{k}: #{v}"
11+
}, "<br />".html_safe
12+
end
13+
end

app/helpers/gtt_tile_sources_helper.rb

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

0 commit comments

Comments
 (0)