Skip to content

Commit fb7f25d

Browse files
authored
Merge pull request #156 from gtt-project/ftr/api-map-config
Ftr/api map config
2 parents 3ebb497 + 6989ae4 commit fb7f25d

File tree

6 files changed

+211
-1
lines changed

6 files changed

+211
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ Before restarting Redmine, you need to set `postgis` adapter instead of `postgre
5656
After restarting Redmine, you should be able to see the Redmine GTT plugin in the Plugins page.
5757

5858
More information on installing (and uninstalling) Redmine plugins can be found here: http://www.redmine.org/wiki/redmine/Plugins
59-
59+
## API
60+
[Redmine GTT API](doc/api.md)
6061
## How to use
6162

6263
1. Go to plugin configuration for global settings
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
class GttConfigurationController < ApplicationController
2+
3+
before_action :find_optional_project_and_authorize
4+
5+
accept_api_auth :default_setting_configuration
6+
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
12+
end
13+
14+
def build_default_setting_config
15+
default_tracker_icon = []
16+
default_status_color = []
17+
gtt_tile_source = []
18+
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+
}
41+
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
63+
64+
private
65+
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
73+
end
74+
end

app/views/projects/show.api.rsb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ api.project do
1414
api.geojson ""
1515
end
1616

17+
if @project.gtt_tile_sources.present?
18+
api.gttLayer @project.gtt_tile_sources
19+
end
20+
1721
render_api_custom_values @project.visible_custom_field_values, api
1822
render_api_includes(@project, api)
1923

config/routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
put 'projects/:id/settings/gtt',
66
to: 'projects#update_gtt_configuration',
77
as: :update_gtt_configuration
8+
9+
scope 'gtt' do
10+
get 'settings', to: 'gtt_configuration#default_setting_configuration', as: :default_setting_configuration
11+
end

doc/api.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# GTT API
2+
3+
## Global Level API Endpoint
4+
### API Endpoint
5+
```
6+
GET /gtt/settings.json
7+
```
8+
Get all the GTT default settings and also all the global GTT layers data.
9+
10+
***Request***
11+
```
12+
http://localhost:3000/gtt/settings.json
13+
```
14+
15+
***Response***
16+
```json
17+
{
18+
"gttDefaultSetting": {
19+
"defaultTrackerIcon": [
20+
{
21+
"trackerID": "1",
22+
"trackerName": "Task",
23+
"icon": "maki-square"
24+
},
25+
],
26+
"defaultStatusColor": [
27+
{
28+
"statusID": "1",
29+
"statusName": "New",
30+
"color": "#00ff00"
31+
},
32+
],
33+
"defaultMapSetting": {
34+
"centerLng": "135.35740",
35+
"centerLat": "34.74701"
36+
},
37+
"geometrySetting": {
38+
"geometryTypes": [
39+
"Point",
40+
"LineString",
41+
"Polygon"
42+
],
43+
"GeoJsonUpload": null
44+
},
45+
"geocoderSetting": {
46+
"enableGeocodingOnMap": "true",
47+
"geocoderOptions": "{}"
48+
}
49+
},
50+
"gttLayer": [
51+
{
52+
"id": 1,
53+
"name": "OSM",
54+
"type": "ol.source.OSM",
55+
"options": {
56+
"url": "https://tile.openstreetmap.jp/{z}/{x}/{y}.png",
57+
"custom": "17/34.74701/135.35740",
58+
"crossOrigin": null,
59+
"attributions": "<a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a>"
60+
},
61+
},
62+
{
63+
"id": 2,
64+
"name": "GIS Satellite Map",
65+
"type": "ol.source.XYZ",
66+
"options": {
67+
"url": "https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/{z}/{x}/{y}.jpg",
68+
"maxZoom": 18,
69+
"minZoom": 0,
70+
"attributions": "<a href=\"https://portal.cyberjapan.jp/help/termsofuse.html\" target=\"_blank\">GISSateliteMap</a>"
71+
},
72+
}
73+
]
74+
}
75+
```
76+
77+
## Project Level API Endpoint
78+
### API Endpoint
79+
```
80+
GET /projects/{project_identifier}.json
81+
```
82+
Get project and selected GTT layer data of a specific project.
83+
84+
***Request***
85+
```
86+
http://localhost:3000/projects/1.json
87+
```
88+
***Response***
89+
```json
90+
{
91+
"project": {
92+
"id": 1,
93+
"name": "first testing project ",
94+
"identifier": "first-testing-project",
95+
"description": "",
96+
"homepage": "",
97+
"status": 1,
98+
"is_public": false,
99+
"geojson": "",
100+
"gttLayer": [
101+
{
102+
"id": 1,
103+
"name": "OSM",
104+
"type": "ol.source.OSM",
105+
"options": {
106+
"url": "https://tile.openstreetmap.jp/{z}/{x}/{y}.png",
107+
"custom": "17/34.74701/135.35740",
108+
"crossOrigin": null,
109+
"attributions": "<a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a>"
110+
},
111+
"created_at": "2022-06-29T09:07:12.574Z",
112+
"updated_at": "2022-07-05T07:33:09.237Z",
113+
"global": true,
114+
"default": true,
115+
"position": 0,
116+
"baselayer": true
117+
}
118+
],
119+
"created_on": "2022-06-29T09:08:38Z",
120+
"updated_on": "2022-06-29T09:08:38Z"
121+
}
122+
}
123+
```
124+

init.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
permission :manage_gtt_settings, {
1717
projects: [ :update_gtt_configuration ]
1818
}, require: :member
19+
permission :view_gtt_settings, {
20+
gtt_configuration: %i( default_setting_configuration )
21+
}, require: :member, read: true
1922
end
2023

2124
settings(

0 commit comments

Comments
 (0)