diff options
| author | Marc Florisson | 2012-09-18 18:07:40 +0200 |
|---|---|---|
| committer | Marc Florisson | 2012-09-18 18:07:40 +0200 |
| commit | d91e2b97fae4ae391f646ef1444e1b7f06704425 (patch) | |
| tree | 8cd07b00eaa40496bf136f3fd0bc5764f2dcdf82 /app | |
| parent | 295f7876004a9c7c048ce627f98af6755f8470e2 (diff) | |
| download | chouette-core-d91e2b97fae4ae391f646ef1444e1b7f06704425.tar.bz2 | |
refactor polymorphic path patch
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/chouette_controller.rb | 2 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 11 | ||||
| -rw-r--r-- | app/maps/application_map.rb | 11 | ||||
| -rw-r--r-- | app/maps/connection_link_map.rb | 2 | ||||
| -rw-r--r-- | app/maps/journey_pattern_map.rb | 2 | ||||
| -rw-r--r-- | app/maps/line_map.rb | 2 | ||||
| -rw-r--r-- | app/maps/network_map.rb | 2 | ||||
| -rw-r--r-- | app/maps/route_map.rb | 2 | ||||
| -rw-r--r-- | app/maps/stop_area_map.rb | 2 | ||||
| -rw-r--r-- | app/maps/style_map/connection_link_style_map.rb | 5 | ||||
| -rw-r--r-- | app/maps/style_map/edit_stop_area_style_map.rb | 64 | ||||
| -rw-r--r-- | app/maps/style_map/generic_style_map.rb | 6 | ||||
| -rw-r--r-- | app/maps/style_map/journey_pattern_style_map.rb | 7 | ||||
| -rw-r--r-- | app/maps/style_map/line_style_map.rb | 3 | ||||
| -rw-r--r-- | app/maps/style_map/route_style_map.rb | 7 | ||||
| -rw-r--r-- | app/maps/style_map/stop_areas_style_map.rb | 42 | ||||
| -rw-r--r-- | app/views/layouts/application.html.erb | 4 |
17 files changed, 89 insertions, 85 deletions
diff --git a/app/controllers/chouette_controller.rb b/app/controllers/chouette_controller.rb index bc74f72fc..f9f832f37 100644 --- a/app/controllers/chouette_controller.rb +++ b/app/controllers/chouette_controller.rb @@ -1,4 +1,6 @@ class ChouetteController < InheritedResources::Base + + include ApplicationHelper before_filter :switch_referential diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 797aab166..3b5bfdfda 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,6 +4,17 @@ module ApplicationHelper @referential.present? and not @referential.new_record? end + def polymorphic_path_patch( source) + relative_url_root = Rails.application.config.relative_url_root + relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source + end + def assets_path_patch( source) + relative_url_root = Rails.application.config.relative_url_root + return "/assets/#{source}" unless relative_url_root + "#{relative_url_root}/assets/#{source}" + end + + def help_page? controller_name == "help" end diff --git a/app/maps/application_map.rb b/app/maps/application_map.rb index 6aae9c927..9c4eaf643 100644 --- a/app/maps/application_map.rb +++ b/app/maps/application_map.rb @@ -6,7 +6,7 @@ class ApplicationMap attr_accessor :helpers def helpers - @helper ||= Helpers.new + @helpers ||= Helpers.new end # For example, in a controller : @@ -116,11 +116,6 @@ class ApplicationMap "#{relative_url_root}/assets/openlayers/" end - def polymorphic_path_patch( source) - relative_url_root = Rails.application.config.relative_url_root - relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source - end - def kml_layer(url_or_object, options_or_url_options = {}, options = nil) unless options url_options = {} @@ -136,9 +131,9 @@ class ApplicationMap when String url_or_object when Array - polymorphic_path_patch( helpers.polymorphic_path(url_or_object, url_options)) + helpers.polymorphic_path_patch( helpers.polymorphic_path(url_or_object, url_options)) else - polymorphic_path_patch( helpers.polymorphic_path([url_or_object.referential, url_or_object], url_options)) + helpers.polymorphic_path_patch( helpers.polymorphic_path([url_or_object.referential, url_or_object], url_options)) end protocol = OpenLayers::Protocol::HTTP.new :url => url, :format => kml diff --git a/app/maps/connection_link_map.rb b/app/maps/connection_link_map.rb index d26bba33b..5e75f371b 100644 --- a/app/maps/connection_link_map.rb +++ b/app/maps/connection_link_map.rb @@ -18,7 +18,7 @@ class ConnectionLinkMap < ApplicationMap page.assign "stop_areas_layer", kml_layer([connection_link.referential, connection_link, :stop_areas], :styleMap => StyleMap::StopAreasStyleMap.new.style_map) page << map.add_layer(:stop_areas_layer) - page << map.add_layer( kml_layer([connection_link.referential, connection_link], :styleMap => StyleMap::ConnectionLinkStyleMap.new.style_map)) + page << map.add_layer( kml_layer([connection_link.referential, connection_link], :styleMap => StyleMap::ConnectionLinkStyleMap.new(helpers).style_map)) page << map.add_control( hover_control_display_name(:stop_areas_layer) ) #page << map.add_layer(kml_layer(connection_link, :styleMap => StyleMap::ConnectionLinkStyleMap.new( :style => connection_link_style).style_map)) #page << map.add_layer(kml_layer(polymorphic_path([referential, connection_link, :stop_areas], :format => :kml), :styleMap => StyleMap::StopAreasStyleMap.new.style_map)) diff --git a/app/maps/journey_pattern_map.rb b/app/maps/journey_pattern_map.rb index d690b3212..b88c31208 100644 --- a/app/maps/journey_pattern_map.rb +++ b/app/maps/journey_pattern_map.rb @@ -16,7 +16,7 @@ class JourneyPatternMap < ApplicationMap page << map.add_layer(google_satellite) #page << map.add_layer(kml_layer(line, :styleMap => StyleMap::LineStyleMap.new( :style => line_style).style_map)) - layer = kml_layer([journey_pattern.referential, journey_pattern.route.line, journey_pattern.route, journey_pattern], :styleMap => StyleMap::JourneyPatternStyleMap.new.style_map) + layer = kml_layer([journey_pattern.referential, journey_pattern.route.line, journey_pattern.route, journey_pattern], :styleMap => StyleMap::JourneyPatternStyleMap.new(helpers).style_map) page.assign "journeyPatternLayer", layer selectFeature = OpenLayers::Control::SelectFeature.new( :journeyPatternLayer) diff --git a/app/maps/line_map.rb b/app/maps/line_map.rb index ec1f6618f..e7b5611e6 100644 --- a/app/maps/line_map.rb +++ b/app/maps/line_map.rb @@ -17,7 +17,7 @@ class LineMap < ApplicationMap page << map.add_layer(google_satellite) #page << map.add_layer(kml_layer(line, :styleMap => StyleMap::LineStyleMap.new( :style => line_style).style_map)) - page.assign "stop_areas_layer", kml_layer([line.referential, line], :styleMap => StyleMap::StopAreasStyleMap.new.style_map) + page.assign "stop_areas_layer", kml_layer([line.referential, line], :styleMap => StyleMap::StopAreasStyleMap.new(helpers).style_map) page << map.add_layer(:stop_areas_layer) page << map.add_control( hover_control_display_name(:stop_areas_layer) ) diff --git a/app/maps/network_map.rb b/app/maps/network_map.rb index f87f088ad..106c4f055 100644 --- a/app/maps/network_map.rb +++ b/app/maps/network_map.rb @@ -15,7 +15,7 @@ class NetworkMap < ApplicationMap page << map.add_layer(google_hybrid) page << map.add_layer(google_satellite) - page.assign "stop_areas_layer", kml_layer([network.referential, network], :styleMap => StyleMap::StopAreasStyleMap.new.style_map) + page.assign "stop_areas_layer", kml_layer([network.referential, network], :styleMap => StyleMap::StopAreasStyleMap.new(helpers).style_map) page << map.add_layer(:stop_areas_layer) page << map.add_control( hover_control_display_name(:stop_areas_layer) ) diff --git a/app/maps/route_map.rb b/app/maps/route_map.rb index 70e31e2e2..e7b6e63c1 100644 --- a/app/maps/route_map.rb +++ b/app/maps/route_map.rb @@ -16,7 +16,7 @@ class RouteMap < ApplicationMap page << map.add_layer(google_satellite) #page << map.add_layer(kml_layer(line, :styleMap => StyleMap::LineStyleMap.new( :style => line_style).style_map)) - layer = kml_layer([route.referential, route.line, route], :styleMap => StyleMap::RouteStyleMap.new.style_map) + layer = kml_layer([route.referential, route.line, route], :styleMap => StyleMap::RouteStyleMap.new(helpers).style_map) page.assign "routeLayer", layer selectFeature = OpenLayers::Control::SelectFeature.new( :routeLayer) diff --git a/app/maps/stop_area_map.rb b/app/maps/stop_area_map.rb index 65c8b72fd..3e172c523 100644 --- a/app/maps/stop_area_map.rb +++ b/app/maps/stop_area_map.rb @@ -17,7 +17,7 @@ class StopAreaMap < ApplicationMap page << map.add_layer(google_hybrid) page << map.add_layer(google_satellite) - page.assign "edit_stop_area_layer", kml_layer(stop_area, { :default => editable? }, :style_map => StyleMap::EditStopAreaStyleMap.new.style_map) + page.assign "edit_stop_area_layer", kml_layer(stop_area, { :default => editable? }, :style_map => StyleMap::EditStopAreaStyleMap.new(helpers).style_map) page << map.add_layer(:edit_stop_area_layer) diff --git a/app/maps/style_map/connection_link_style_map.rb b/app/maps/style_map/connection_link_style_map.rb index 9a0abfebc..99393fc08 100644 --- a/app/maps/style_map/connection_link_style_map.rb +++ b/app/maps/style_map/connection_link_style_map.rb @@ -1,7 +1,8 @@ class StyleMap::ConnectionLinkStyleMap < StyleMap::GenericStyleMap attr_accessor :style - def initialize(options = {}) + def initialize(helpers,options = {}) + @helpers= helpers @style = options[:style].present? ? default_style.merge(options[:style]) : default_style end @@ -18,7 +19,7 @@ class StyleMap::ConnectionLinkStyleMap < StyleMap::GenericStyleMap :strokeWidth => 3, :strokeLineCap => "round", :strokeDashstyle => "solid", - :externalGraphic => self.class.polymorphic_path_patch( "map/${positionType}.png"), + :externalGraphic => @helpers.assets_path_patch( "map/${positionType}.png"), :graphicWidth => 36, :graphicHeight => 36, :graphicOpacity => 1, diff --git a/app/maps/style_map/edit_stop_area_style_map.rb b/app/maps/style_map/edit_stop_area_style_map.rb index 263950d62..38f18f04a 100644 --- a/app/maps/style_map/edit_stop_area_style_map.rb +++ b/app/maps/style_map/edit_stop_area_style_map.rb @@ -1,37 +1,36 @@ class StyleMap::EditStopAreaStyleMap < StyleMap::GenericStyleMap - attr_accessor :default_style, :select_style, :context + attr_accessor :style - @@default_style_class = { - #:label => "${label}", - :fontColor => "black", - :fontSize => "11px", - :fontWeight => "bold", - :labelAlign => "ct", - :labelXOffset => 0, - :labelYOffset => -15, - :pointRadius => 4, - :fillColor => "white", - :fillOpacity => 1, - :strokeColor => "black", - :strokeOpacity => 1, - :strokeWidth => 2 - } + def default_style + { :fontColor => "black", + :fontSize => "11px", + :fontWeight => "bold", + :labelAlign => "ct", + :labelXOffset => 0, + :labelYOffset => -15, + :pointRadius => 4, + :fillColor => "white", + :fillOpacity => 1, + :strokeColor => "black", + :strokeOpacity => 1, + :strokeWidth => 2 } + end - @@select_style_class = { - :fontColor => "black", - :fontSize => "11px", - :fontWeight => "bold", - :pointRadius => 4, - :fillColor => "#86b41d", - :fillOpacity => 1, - :strokeColor => "black", - :strokeOpacity => 1, - :strokeWidth => 2 - } + def select_style + { :fontColor => "black", + :fontSize => "11px", + :fontWeight => "bold", + :pointRadius => 4, + :fillColor => "#86b41d", + :fillOpacity => 1, + :strokeColor => "black", + :strokeOpacity => 1, + :strokeWidth => 2 } + end - def initialize(options = {}) - @default_style = options[:default_style].present? ? options[:default_style].merge(@@default_style_class) : @@default_style_class - @select_style = options[:select_style].present? ? options[:select_style].merge(@@select_style_class) : @@select_style_class + def initialize(helpers, options = {}) + @helpers= helpers + @style = options[:style].present? ? default_style.merge(options[:style]) : default_style end def context @@ -41,10 +40,7 @@ class StyleMap::EditStopAreaStyleMap < StyleMap::GenericStyleMap end def style_map - OpenLayers::StyleMap.new( - :default => OpenLayers::Style.new(default_style, { :context => context}), - :select => OpenLayers::Style.new(select_style) - ) + OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}), :select => OpenLayers::Style.new(style.merge( select_style), { :context => context})) end end diff --git a/app/maps/style_map/generic_style_map.rb b/app/maps/style_map/generic_style_map.rb index 88819650a..c905cd00d 100644 --- a/app/maps/style_map/generic_style_map.rb +++ b/app/maps/style_map/generic_style_map.rb @@ -2,10 +2,4 @@ class StyleMap::GenericStyleMap include MapLayers include MapLayers::ViewHelpers - def self.polymorphic_path_patch( source) - - relative_url_root = Rails.application.config.relative_url_root - return "/assets/#{source}" unless relative_url_root - "#{relative_url_root}/assets/#{source}" - end end diff --git a/app/maps/style_map/journey_pattern_style_map.rb b/app/maps/style_map/journey_pattern_style_map.rb index 9e2550232..5a06b5c18 100644 --- a/app/maps/style_map/journey_pattern_style_map.rb +++ b/app/maps/style_map/journey_pattern_style_map.rb @@ -1,12 +1,13 @@ class StyleMap::JourneyPatternStyleMap < StyleMap::GenericStyleMap attr_accessor :style - def initialize(options = {}) + def initialize(helpers, options = {}) + @helpers= helpers @style = options[:style].present? ? default_style.merge(options[:style]) : default_style end def select_style - default_style.merge :externalGraphic => self.class.polymorphic_path_patch( "icons/stop_area_hover.png") + default_style.merge :externalGraphic => @helpers.assets_path_patch( "icons/stop_area_hover.png") end def default_style { @@ -22,7 +23,7 @@ class StyleMap::JourneyPatternStyleMap < StyleMap::GenericStyleMap :strokeWidth => 3, :strokeLineCap => "round", :strokeDashstyle => "solid", - :externalGraphic => self.class.polymorphic_path_patch( "icons/${positionType}.png"), + :externalGraphic => @helpers.assets_path_patch( "icons/${positionType}.png"), :graphicWidth => 12, :graphicHeight => 12, :graphicOpacity => 1, diff --git a/app/maps/style_map/line_style_map.rb b/app/maps/style_map/line_style_map.rb index e86e8570f..acc307df4 100644 --- a/app/maps/style_map/line_style_map.rb +++ b/app/maps/style_map/line_style_map.rb @@ -1,7 +1,8 @@ class StyleMap::LineStyleMap < StyleMap::GenericStyleMap attr_accessor :style, :line_priority, :line_color - def initialize(options = {}) + def initialize(helpers,options = {}) + @helpers= helpers @line_color = options[:line_color] @style = options[:style].present? ? default_style.merge(options[:style]) : default_style end diff --git a/app/maps/style_map/route_style_map.rb b/app/maps/style_map/route_style_map.rb index c791441f4..1d9ab12f0 100644 --- a/app/maps/style_map/route_style_map.rb +++ b/app/maps/style_map/route_style_map.rb @@ -1,12 +1,13 @@ class StyleMap::RouteStyleMap < StyleMap::GenericStyleMap attr_accessor :style - def initialize(options = {}) + def initialize(helpers,options = {}) + @helpers= helpers @style = options[:style].present? ? default_style.merge(options[:style]) : default_style end def select_style - default_style.merge :externalGraphic => self.class.polymorphic_path_patch( "icons/stop_area_hover.png") + default_style.merge :externalGraphic => @helpers.assets_path_patch( "icons/stop_area_hover.png") end def default_style { @@ -22,7 +23,7 @@ class StyleMap::RouteStyleMap < StyleMap::GenericStyleMap :strokeWidth => 3, :strokeLineCap => "round", :strokeDashstyle => "solid", - :externalGraphic => self.class.polymorphic_path_patch( "icons/${positionType}.png"), + :externalGraphic => @helpers.assets_path_patch( "icons/${positionType}.png"), :graphicWidth => 12, :graphicHeight => 12, :graphicOpacity => 1, diff --git a/app/maps/style_map/stop_areas_style_map.rb b/app/maps/style_map/stop_areas_style_map.rb index 5bb16af35..398748a22 100644 --- a/app/maps/style_map/stop_areas_style_map.rb +++ b/app/maps/style_map/stop_areas_style_map.rb @@ -1,25 +1,27 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap - attr_accessor :default_style, :context + attr_accessor :style, :context - @@default_style_class = { - :label => "${label}", - :fontColor => "black", - :fontSize => "11px", - :fontWeight => "bold", - :labelAlign => "ct", - :labelXOffset => 0, - :labelYOffset => -40, - :pointRadius => 1, - :externalGraphic => polymorphic_path_patch( "map/${areaType}.png"), - :graphicWidth => 25, - :graphicHeight => 25, - :graphicOpacity => 1, - :graphicXOffset => -12.5, - :graphicYOffset => -12.5 - } + def default_style + raise "Helpers nil" if @helpers.nil? + {:label => "${label}", + :fontColor => "black", + :fontSize => "11px", + :fontWeight => "bold", + :labelAlign => "ct", + :labelXOffset => 0, + :labelYOffset => -40, + :pointRadius => 1, + :externalGraphic => @helpers.assets_path_patch( "map/${areaType}.png"), + :graphicWidth => 25, + :graphicHeight => 25, + :graphicOpacity => 1, + :graphicXOffset => -12.5, + :graphicYOffset => -12.5 } + end - def initialize(options = {}) - @default_style = options[:default_style].present? ? options[:default_style].merge(@@default_style_class) : @@default_style_class + def initialize(helpers,options = {}) + @helpers= helpers + @style = options[:style].present? ? default_style.merge(options[:style]) : default_style end @@ -31,7 +33,7 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap end def style_map - OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(default_style, { :context => context}) ) + OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}) ) end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 0780ac2ea..903e945e8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,9 +6,9 @@ <%= javascript_include_tag :application %> <% if defined?( @map) %> <script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script> - <script src="/assets/specific/OpenLayers.js"></script> + <script src="<%= assets_path_patch("specific/OpenLayers.js") %>"></script> <script type="text/JavaScript"> - OpenLayers.ImgPath = "<%= @map.open_layer_path %>"; + OpenLayers.ImgPath = "<%= polymorphic_path_patch("/assets/openlayers/") %>"; </script> <% end %> <%= csrf_meta_tag %> |
