From: John Firebaugh Date: Fri, 21 Sep 2012 22:16:56 +0000 (-0700) Subject: Support the same edit params for Potlatch 1 and 2 X-Git-Tag: live~5323 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/20e5f756be74c8adf31d7ec3a6406a2b4bdb22c1 Support the same edit params for Potlatch 1 and 2 Trac ticket 4587 --- diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 015da9e22..72fe3b241 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -39,6 +39,21 @@ class SiteController < ApplicationController if editor == "remote" render :action => :index + return + end + + if params[:node] + bbox = Node.find(params[:node]).bbox.to_unscaled + @lat = bbox.centre_lat + @lon = bbox.centre_lon + elsif params[:way] + bbox = Way.find(params[:way]).bbox.to_unscaled + @lat = bbox.centre_lat + @lon = bbox.centre_lon + elsif params[:gpx] + trace = Trace.find(params[:gpx]) + @lat = trace.latitude + @lon = trace.longitude end end diff --git a/app/views/site/_potlatch.html.erb b/app/views/site/_potlatch.html.erb index 8180cee02..a1c637b79 100644 --- a/app/views/site/_potlatch.html.erb +++ b/app/views/site/_potlatch.html.erb @@ -42,8 +42,12 @@ // 700,600 for fixed size, 100%,100% for resizable } + <% if @lat && @lon -%> + doSWF(<%= @lat %>,<%= @lon %>,16); + <% else -%> var params = OSM.mapParams(); doSWF(params.lat, params.lon, params.zoom || 17); + <% end -%> $(document).ready(function () { $("body").on("click", "a.set_position", function () { diff --git a/app/views/site/_potlatch2.html.erb b/app/views/site/_potlatch2.html.erb index 31e15f09d..73ef782b5 100644 --- a/app/views/site/_potlatch2.html.erb +++ b/app/views/site/_potlatch2.html.erb @@ -63,15 +63,8 @@ // 700,600 for fixed size, 100%,100% for resizable } - <% if params[:node] -%> - <% bbox = Node.find(params[:node]).bbox.to_unscaled -%> - doSWF(<%= bbox.centre_lat %>,<%= bbox.centre_lon %>,16); - <% elsif params[:way] -%> - <% bbox = Way.find(params[:way]).bbox.to_unscaled -%> - doSWF(<%= bbox.centre_lat %>,<%= bbox.centre_lon %>,16); - <% elsif params[:gpx] -%> - <% trace = Trace.find(params[:gpx]) -%> - doSWF(<%= trace.latitude %>,<%= trace.longitude %>,16); + <% if @lat && @lon -%> + doSWF(<%= @lat %>,<%= @lon %>,16); <% else -%> var params = OSM.mapParams(); doSWF(params.lat, params.lon, params.zoom || 17); diff --git a/test/functional/site_controller_test.rb b/test/functional/site_controller_test.rb index 67d020b74..7495e30e0 100644 --- a/test/functional/site_controller_test.rb +++ b/test/functional/site_controller_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class SiteControllerTest < ActionController::TestCase - fixtures :users + api_fixtures ## # test all routes which lead to this controller @@ -118,5 +118,38 @@ class SiteControllerTest < ActionController::TestCase get(:edit, nil, { 'user' => user.id }) assert_response :success assert_template "index" - end + end + + def test_edit_with_node + @request.cookies["_osm_username"] = users(:public_user).display_name + + user = users(:public_user) + node = current_nodes(:visible_node) + + get :edit, { :node => node.id }, { 'user' => user.id } + assert_equal 1.0, assigns(:lat) + assert_equal 1.0, assigns(:lon) + end + + def test_edit_with_way + @request.cookies["_osm_username"] = users(:public_user).display_name + + user = users(:public_user) + way = current_ways(:visible_way) + + get :edit, { :way => way.id }, { 'user' => user.id } + assert_equal 3.0, assigns(:lat) + assert_equal 3.0, assigns(:lon) + end + + def test_edit_with_gpx + @request.cookies["_osm_username"] = users(:public_user).display_name + + user = users(:public_user) + gpx = gpx_files(:public_trace_file) + + get :edit, { :gpx => gpx.id }, { 'user' => user.id } + assert_equal 1.0, assigns(:lat) + assert_equal 1.0, assigns(:lon) + end end