Skip to content

Commit 34d5775

Browse files
committed
Merge branch 'develop' of hub.georepublic.net:gtt/redmine_gtt
2 parents f260914 + 54021ec commit 34d5775

File tree

16 files changed

+100
-71
lines changed

16 files changed

+100
-71
lines changed

Gemfile

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@ gem 'immutable-struct'
55
gem "rgeo"
66
gem "rgeo-geojson"
77
gem "rgeo-activerecord"
8+
gem 'pg', '~> 0.18.1'
9+
gem 'activerecord-postgis-adapter'
810

9-
# TODO: the following path variable requires to run bundler from application
10-
# Eventually there is a way to do this directory independent, so bundler can
11-
# be also run from the plugin directory.
12-
# Otherwise variable `database_file` is already determined on the Gemfile of
13-
# Redmine.`
14-
database_file = File.join(File.dirname(__FILE__), "../../config/database.yml")
15-
16-
if File.exist?(database_file)
17-
database_config = YAML::load(ERB.new(IO.read(database_file)).result)
18-
adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
19-
if adapters.any?
20-
adapters.each do |adapter|
21-
case adapter
22-
when /postgresql/
23-
gem 'activerecord-postgis-adapter'
24-
else
25-
warn("GTT doesn't support `#{adapter}` found in config/database.yml,
26-
use Gemfile.local to load your own database gems")
27-
end
28-
end
29-
else
30-
warn("No adapter found in config/database.yml, please configure it first")
31-
end
32-
else
33-
warn("Please configure your config/database.yml first")
34-
end

README.rdoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Creating a PostGIS-enabled database
99

1010
createdb -U postgres -O redmine redmine
1111
psql -U postgres -d redmine -c "CREATE EXTENSION postgis;"
12-
psql -U redmine -d redmine -c "CREATE SCHEMA app;"
13-
psql -U redmine -d redmine -c "CREATE SCHEMA dev;"
1412

1513
= Installation
1614

app/helpers/gtt_map_helper.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,20 @@ def map_tag(map: nil, layers: map&.layers,
2828
data[:edit] = edit if edit
2929
data[:popup] = popup if popup
3030

31-
content_tag(:div, "", data: data, id: "ol-#{rand(36**8).to_s(36)}", class: 'ol-map')
31+
uid = "ol-" + rand(36**8).to_s(36)
32+
33+
safe_join [
34+
content_tag(:div, "", data: data, id: uid, class: 'ol-map'),
35+
javascript_tag("
36+
$(document).ready(function(){
37+
$('div.ol-map').each(function(idx) {
38+
App.init({
39+
target: this
40+
});
41+
});
42+
});
43+
")
44+
]
3245
end
3346

3447
end

app/models/gtt_map.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ class GttMap
22

33
attr_reader :layers, :json, :bounds
44

5-
def initialize(wkb: nil, json: nil, layers:, bounds: nil)
5+
def initialize(geom: nil, json: nil, layers:, bounds: nil)
66
unless @json = json
7-
@json = RedmineGtt::Conversions.wkb_to_json wkb if wkb
7+
@json = RedmineGtt::Conversions.geom_to_json geom if geom
88
end
99

1010
@bounds = bounds || @json

assets/javascripts/app.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ var App = (function ($, publ) {
1414
});
1515

1616
// Hack to disable geometry changes in history
17-
$("#history ul.details li:contains('ジオメトリ')").hide();
18-
$("#history ul.details li:contains('Geometry')").hide();
19-
$("#history ul.details li:contains('Geometrie')").hide();
17+
// $("#history ul.details li:contains('ジオメトリ')").hide();
18+
// $("#history ul.details li:contains('Geometry')").hide();
19+
// $("#history ul.details li:contains('Geometrie')").hide();
2020

2121
return;
2222
};
@@ -27,15 +27,3 @@ var App = (function ($, publ) {
2727
return publ;
2828

2929
})(jQuery, App || {});
30-
31-
/**
32-
* When DOM is ready, initialize map plugin
33-
*/
34-
$(document).ready(function(){
35-
// A page may contain more than one map
36-
$("div.ol-map").each(function(idx) {
37-
App.init({
38-
target: this
39-
});
40-
});
41-
});

assets/javascripts/app.map.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ App.map = (function ($, publ) {
88

99
var map, vector, bounds, contents, toolbar, geolocation = null;
1010
var features = [];
11-
var layerArr = []
11+
var layerArr = [];
1212

1313
// Quick hack
1414
var quick_hack = {
@@ -23,6 +23,15 @@ App.map = (function ($, publ) {
2323
*/
2424
publ.init = function (options) {
2525

26+
map = null;
27+
vector = null;
28+
bounds = null;
29+
toolbar = null;
30+
geolocation = null;
31+
32+
features = [];
33+
layerArr = [];
34+
2635
contents = $(options.target).data();
2736
defaults = $("#ol-defaults").data();
2837
defaults.geocoderUrl = "https://***REMOVED***/geojson";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class EnsureProperSrid < ActiveRecord::Migration
2+
def up
3+
execute "SELECT UpdateGeometrySRID('issues','geom',4326)"
4+
execute "SELECT UpdateGeometrySRID('projects','geom',4326)"
5+
execute "SELECT UpdateGeometrySRID('users','geom',4326)"
6+
end
7+
end

init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
author 'Georepublic'
66
author_url 'https://hub.georepublic.net/gtt/redmine_gtt'
77
description 'Adds location-based task management and maps'
8-
version '0.6.0'
8+
version '0.7.0'
99

1010
requires_redmine :version_or_higher => '3.4.0'
1111

lib/redmine_gtt.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
# Register MIME Types
1919
Mime::Type.register_alias "application/json", :geojson
2020

21+
RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
22+
# By default, use the GEOS implementation for spatial columns.
23+
# config.default = RGeo::Geos.factory_generator
24+
25+
config.register RGeo::Cartesian.preferred_factory(srid: 4326), geo_type: 'geometry', sql_type: "geometry", srid: 4326
26+
27+
# But use a geographic implementation for point columns.
28+
# config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
29+
end
2130

2231
module RedmineGtt
2332

lib/redmine_gtt/conversions.rb

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,67 @@ module RedmineGtt
99
# between.
1010
module Conversions
1111

12-
class WkbToJson
12+
class GeomToJson
1313
def initialize()
1414
@factory = RGeo::GeoJSON::EntityFactory.instance
15-
@parser = RGeo::WKRep::WKBParser.new(
16-
support_ewkb: true,
17-
default_srid: 4326
18-
)
1915
end
2016

21-
def to_json(wkb, id: nil, properties: nil)
22-
RGeo::GeoJSON.encode feature(wkb, id, properties)
17+
def to_json(object, id: nil, properties: nil)
18+
RGeo::GeoJSON.encode feature(object, id, properties)
2319
end
2420

2521
def collection_to_json(data)
2622
RGeo::GeoJSON.encode @factory.feature_collection(
27-
data.map{|wkb, id, props| feature wkb, id, props}
23+
data.map{|object, id, props| feature object, id, props}
2824
)
2925
end
3026

3127
private
3228

33-
def feature(wkb, id, properties = nil)
34-
@factory.feature @parser.parse(wkb), id, (properties || {})
29+
def feature(object, id, properties = nil)
30+
@factory.feature object, id, (properties || {})
3531
end
32+
end
3633

34+
class WkbToGeom
35+
def initialize()
36+
@parser = RGeo::WKRep::WKBParser.new(
37+
support_ewkb: true,
38+
default_srid: 4326
39+
)
40+
end
41+
42+
def self.call(wkb)
43+
new.call wkb
44+
end
45+
46+
def call(wkb)
47+
@parser.parse(wkb)
48+
end
3749
end
3850

51+
3952
# Turns database WKB into geometry attribute string
4053
def self.wkb_to_json(wkb, id: nil, properties: nil)
41-
WkbToJson.new.to_json(wkb, id: id, properties: properties)
54+
geom_to_json WkbToGeom.(wkb), id: id, properties: properties
4255
end
4356

57+
# turns Rgeo object into GeoJSON
58+
def self.geom_to_json(object, id: nil, properties: nil)
59+
GeomToJson.new.to_json(object, id: id, properties: properties)
60+
end
61+
62+
# Turn geometry attribute string (GeoJSON) into Rgeo object for database
63+
# use
64+
def self.to_geom(geometry)
65+
geojson = JSON.parse(geometry)
66+
RGeo::GeoJSON.decode(
67+
geojson,
68+
json_parser: :json,
69+
geo_factory: RGeo::Cartesian.preferred_factory(srid: 4326)
70+
).geometry
71+
end
72+
4473
# Turn geometry attribute string into WKB for database use
4574
def self.to_wkb(geometry)
4675
geojson = JSON.parse(geometry)

0 commit comments

Comments
 (0)