From c3453cf57df864b008dca6479f84504f81c0b131 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 14 Nov 2010 17:35:08 +0000 Subject: [PATCH] Make JOSM remote control based editing work --- app/controllers/site_controller.rb | 60 ++++++++++++++++-------------- app/helpers/application_helper.rb | 8 ++++ app/views/site/_josm.html.erb | 6 --- app/views/site/edit.html.erb | 2 +- app/views/site/index.html.erb | 25 +++++++++++++ 5 files changed, 66 insertions(+), 35 deletions(-) delete mode 100644 app/views/site/_josm.html.erb diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 0a1a55301a..d08f34a0a2 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -32,36 +32,40 @@ def key end def edit - session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token]) - - @preferred_editor = @user.preferred_editor || DEFAULT_EDITOR + editor = @user.preferred_editor || DEFAULT_EDITOR - # Decide on a lat lon to initialise potlatch with. Various ways of doing this - if params['lon'] and params['lat'] - @lon = params['lon'].to_f - @lat = params['lat'].to_f - @zoom = params['zoom'].to_i - - elsif params['mlon'] and params['mlat'] - @lon = params['mlon'].to_f - @lat = params['mlat'].to_f - @zoom = params['zoom'].to_i - - elsif params['gpx'] - #use gpx id to locate (dealt with below) - - elsif cookies.key?("_osm_location") - @lon, @lat, @zoom, layers = cookies["_osm_location"].split("|") - - elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? - @lon = @user.home_lon - @lat = @user.home_lat - + if editor == "josm" + render :action => :index else - #catch all. Do nothing. lat=nil, lon=nil - #Currently this results in potlatch starting up at 0,0 (Atlantic ocean). - end + session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token]) + + # Decide on a lat lon to initialise potlatch with. Various ways of doing this + if params['lon'] and params['lat'] + @lon = params['lon'].to_f + @lat = params['lat'].to_f + @zoom = params['zoom'].to_i + + elsif params['mlon'] and params['mlat'] + @lon = params['mlon'].to_f + @lat = params['mlat'].to_f + @zoom = params['zoom'].to_i + + elsif params['gpx'] + #use gpx id to locate (dealt with below) - @zoom = '14' if @zoom.nil? + elsif cookies.key?("_osm_location") + @lon, @lat, @zoom, layers = cookies["_osm_location"].split("|") + + elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? + @lon = @user.home_lon + @lat = @user.home_lat + + else + #catch all. Do nothing. lat=nil, lon=nil + #Currently this results in potlatch starting up at 0,0 (Atlantic ocean). + end + + @zoom = '14' if @zoom.nil? + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2ccfcca2b0..ca26cfd484 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -119,6 +119,14 @@ def user_thumbnail(user, options = {}) end end + def preferred_editor + if @user and @user.preferred_editor + @user.preferred_editor + else + DEFAULT_EDITOR + end + end + private def javascript_strings_for_key(key) diff --git a/app/views/site/_josm.html.erb b/app/views/site/_josm.html.erb deleted file mode 100644 index 16f33bde0b..0000000000 --- a/app/views/site/_josm.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -
- <% query = "lat=#{@lat || 0}&lon=#{@lon || 0}&zoom=#{@zoom}" %> - -
diff --git a/app/views/site/edit.html.erb b/app/views/site/edit.html.erb index b89184404c..a9b915faf8 100644 --- a/app/views/site/edit.html.erb +++ b/app/views/site/edit.html.erb @@ -19,7 +19,7 @@ <%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %> <%= render :partial => 'search' %> -<%= render :partial => @preferred_editor %> +<%= render :partial => preferred_editor %>