From: Tom Hughes Date: Wed, 3 Feb 2021 14:48:24 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/3078' X-Git-Tag: live~2227 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/66b5e85845547e6f3c6dba59952217f5882b0271?hp=5912a8011b05f36077f0147cdf7403a8e7626216 Merge remote-tracking branch 'upstream/pull/3078' --- diff --git a/INSTALL.md b/INSTALL.md index 321e00987..49f4a78d0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -240,7 +240,7 @@ After installing this software, you may need to carry out some [configuration st # Installing compiled shared library database functions (optional) -There are special database functions required by a (little-used) API call, the migrations and diff replication. The former two are provided as *either* pure SQL functions or a compiled shared library. The SQL versions are installed as part of the recommended install procedure above and the shared library versions are recommended only if you are running a production server making a lot of `/changes` API calls or need the diff replication functionality. +There are special database functions required by a (little-used) API call, the migrations and diff replication. The former two are provided as *either* pure SQL functions or a compiled shared library. The SQL versions are installed as part of the recommended install procedure above and the shared library versions are recommended only if you are running a production server and need the diff replication functionality. If you aren't sure which you need, stick with the SQL versions. @@ -267,14 +267,12 @@ cd ../.. If you previously installed the SQL versions of these functions, we'll need to delete those before adding the new ones: ``` -psql -d openstreetmap -c "DROP FUNCTION IF EXISTS maptile_for_point" psql -d openstreetmap -c "DROP FUNCTION IF EXISTS tile_for_point" ``` Then we create the functions within each database. We're using `pwd` to substitute in the current working directory, since PostgreSQL needs the full path. ``` -psql -d openstreetmap -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '`pwd`/db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT" psql -d openstreetmap -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '`pwd`/db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT" psql -d openstreetmap -c "CREATE FUNCTION xid_to_int4(xid) RETURNS int4 AS '`pwd`/db/functions/libpgosm', 'xid_to_int4' LANGUAGE C STRICT" ``` diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index e3c8ff202..c010691c6 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -448,26 +448,11 @@ body.compact-nav { .welcome { display: none; - padding-bottom: 5px; p { - padding: $lineheight/2 $lineheight $lineheight; font-size: 110%; font-weight: 300; } - - .button { - width: 50%; - float: left; - margin: 0; - border-radius: 0; - font-weight: normal; - padding: .6em; - - &.learn-more { - border-right: 1px solid #fff; - } - } } #banner { @@ -1005,9 +990,8 @@ tr.turn:hover { .export_area_inputs { margin-bottom: $lineheight/2; input[type="text"] { - width: 80px; + width: 100px; text-align: center; - margin-bottom: 5px; } } @@ -1025,18 +1009,13 @@ tr.turn:hover { float: right; /* no-r2 */ margin-right: -1px; } - #minlat { margin-bottom: 0; } + #minlat { margin-bottom: -1px; } } .export_bound { margin: $lineheight/4; } - .export_button { - margin-top: $lineheight; - margin-bottom: $lineheight; - } - dl { padding-left: $lineheight/2; dd { diff --git a/app/controllers/api/changes_controller.rb b/app/controllers/api/changes_controller.rb deleted file mode 100644 index 7170e1562..000000000 --- a/app/controllers/api/changes_controller.rb +++ /dev/null @@ -1,54 +0,0 @@ -module Api - class ChangesController < ApiController - authorize_resource :class => false - - before_action :check_api_readable - around_action :api_call_handle_error, :api_call_timeout - - # Get a list of the tiles that have changed within a specified time - # period - def index - zoom = (params[:zoom] || "12").to_i - - if params.include?(:start) && params.include?(:end) - starttime = Time.parse(params[:start]) - endtime = Time.parse(params[:end]) - else - hours = (params[:hours] || "1").to_i.hours - endtime = Time.now.getutc - starttime = endtime - hours - end - - if zoom >= 1 && zoom <= 16 && - endtime > starttime && endtime - starttime <= 24.hours - mask = (1 << zoom) - 1 - - tiles = Node.where(:timestamp => starttime..endtime).group("maptile_for_point(latitude, longitude, #{zoom})").count - - doc = OSM::API.new.get_xml_doc - changes = XML::Node.new "changes" - changes["starttime"] = starttime.xmlschema - changes["endtime"] = endtime.xmlschema - - tiles.each do |tile, count| - x = (tile.to_i >> zoom) & mask - y = tile.to_i & mask - - t = XML::Node.new "tile" - t["x"] = x.to_s - t["y"] = y.to_s - t["z"] = zoom.to_s - t["changes"] = count.to_s - - changes << t - end - - doc.root << changes - - render :xml => doc.to_s - else - render :plain => "Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", :status => :bad_request - end - end - end -end diff --git a/app/views/layouts/map.html.erb b/app/views/layouts/map.html.erb index 33737ae23..0403bc889 100644 --- a/app/views/layouts/map.html.erb +++ b/app/views/layouts/map.html.erb @@ -41,15 +41,21 @@ <% unless current_user %>
<%= render "sidebar_header", :title => t("layouts.intro_header") %> -

<%= t "layouts.intro_text" %>

-

<%= t "layouts.hosting_partners_html", - :ucl => link_to(t("layouts.partners_ucl"), "https://www.ucl.ac.uk"), - :bytemark => link_to(t("layouts.partners_bytemark"), "https://www.bytemark.co.uk"), - :partners => link_to(t("layouts.partners_partners"), "https://hardware.openstreetmap.org/thanks/") %> -

-
- <%= t("layouts.learn_more") %> - +
+

<%= t "layouts.intro_text" %>

+

<%= t "layouts.hosting_partners_html", + :ucl => link_to(t("layouts.partners_ucl"), "https://www.ucl.ac.uk"), + :bytemark => link_to(t("layouts.partners_bytemark"), "https://www.bytemark.co.uk"), + :partners => link_to(t("layouts.partners_partners"), "https://hardware.openstreetmap.org/thanks/") %> +

+
<% end %> diff --git a/app/views/messages/_message_summary.html.erb b/app/views/messages/_message_summary.html.erb index 1d9630f71..1a4445eae 100644 --- a/app/views/messages/_message_summary.html.erb +++ b/app/views/messages/_message_summary.html.erb @@ -1,8 +1,8 @@ -"> +"> <%= link_to message_summary.sender.display_name, user_path(message_summary.sender) %> <%= link_to message_summary.title, message_path(message_summary) %> <%= l message_summary.sent_on, :format => :friendly %> - <%= button_to t(".unread_button"), message_mark_path(message_summary, :mark => "unread"), :remote => true %> - <%= button_to t(".read_button"), message_mark_path(message_summary, :mark => "read"), :remote => true %> - <%= button_to t(".destroy_button"), message_path(message_summary, :referer => request.fullpath), :method => :delete, :remote => true %> + <%= button_to t(".unread_button"), message_mark_path(message_summary, :mark => "unread"), :remote => true, :class => "btn btn-sm btn-primary" %> + <%= button_to t(".read_button"), message_mark_path(message_summary, :mark => "read"), :remote => true, :class => "btn btn-sm btn-primary" %> + <%= button_to t(".destroy_button"), message_path(message_summary, :referer => request.fullpath), :method => :delete, :remote => true, :class => "btn btn-sm btn-danger" %> diff --git a/app/views/messages/_sent_message_summary.html.erb b/app/views/messages/_sent_message_summary.html.erb index ba18ca875..4d1b361b1 100644 --- a/app/views/messages/_sent_message_summary.html.erb +++ b/app/views/messages/_sent_message_summary.html.erb @@ -2,5 +2,5 @@ <%= link_to sent_message_summary.recipient.display_name, user_path(sent_message_summary.recipient) %> <%= link_to sent_message_summary.title, message_path(sent_message_summary) %> <%= l sent_message_summary.sent_on, :format => :friendly %> - <%= button_to t(".destroy_button"), message_path(sent_message_summary, :referer => request.fullpath), :method => :delete, :remote => true %> + <%= button_to t(".destroy_button"), message_path(sent_message_summary, :referer => request.fullpath), :method => :delete, :remote => true, :class => "btn btn-sm btn-danger" %> diff --git a/app/views/oauth_clients/index.html.erb b/app/views/oauth_clients/index.html.erb index f35537953..8e940e341 100644 --- a/app/views/oauth_clients/index.html.erb +++ b/app/views/oauth_clients/index.html.erb @@ -18,9 +18,9 @@ <%= link_to token.client_application.name, token.client_application.url %> <%= token.authorized_at %> - <%= form_tag({ :controller => "oauth", :action => "revoke" }, { :class => "standard-form" }) do %> + <%= form_tag({ :controller => "oauth", :action => "revoke" }) do %> <%= hidden_field_tag "token", token.token %> - <%= submit_tag t(".revoke") %> + <%= submit_tag t(".revoke"), :class => "btn btn-sm btn-primary" %> <% end %> diff --git a/app/views/site/export.html.erb b/app/views/site/export.html.erb index 934b56a02..d6db3908b 100644 --- a/app/views/site/export.html.erb +++ b/app/views/site/export.html.erb @@ -2,17 +2,17 @@ <%= render "sidebar_header", :title => t(".title") %> -<%= form_tag({ :controller => "export", :action => "finish" }, { :class => "export_form standard-form" }) do %> +<%= form_tag({ :controller => "export", :action => "finish" }, { :class => "export_form" }) do %> <%= hidden_field_tag "format", "osm" %>
- <%= text_field_tag("maxlat", nil, :size => 10, :class => "export_bound") %> -
- <%= text_field_tag("minlon", nil, :size => 10, :class => "export_bound") %> - <%= text_field_tag("maxlon", nil, :size => 10, :class => "export_bound") %> -

- <%= text_field_tag("minlat", nil, :size => 10, :class => "export_bound") %> + <%= text_field_tag("maxlat", nil, :size => 10, :class => "export_bound form-control mx-auto") %> +
+ <%= text_field_tag("minlon", nil, :size => 10, :class => "export_bound form-control") %> + <%= text_field_tag("maxlon", nil, :size => 10, :class => "export_bound form-control") %> +
+ <%= text_field_tag("minlat", nil, :size => 10, :class => "export_bound form-control mx-auto") %>
<%= t ".manually_select" %>
@@ -27,8 +27,8 @@
-
- <%= submit_tag t(".export_button") %> +
+ <%= submit_tag t(".export_button"), :class => "btn btn-primary mx-auto" %>

<%= t ".too_large.advice" %>

diff --git a/app/views/user_blocks/revoke.html.erb b/app/views/user_blocks/revoke.html.erb index 0b6e21788..1899e5145 100644 --- a/app/views/user_blocks/revoke.html.erb +++ b/app/views/user_blocks/revoke.html.erb @@ -11,23 +11,23 @@ <% end %> <% if @user_block.ends_at > Time.now %> -

- <%= t(".time_future", :time => distance_of_time_in_words_to_now(@user_block.ends_at)) %> -

+

+ <%= t(".time_future", :time => distance_of_time_in_words_to_now(@user_block.ends_at)) %> +

-<%= form_for :revoke, :url => { :action => "revoke" }, :html => { :class => "standard-form" } do |f| %> - <%= f.error_messages %> -

- <%= check_box_tag "confirm", "yes" %> - <%= label_tag "confirm", t(".confirm") %> -

-

- <%= submit_tag t(".revoke") %> -

-<% end %> + <%= bootstrap_form_for :revoke, :url => { :action => "revoke" } do |f| %> +
+
+ <%= check_box_tag "confirm", "yes", false, { :class => "form-check-input" } %> + <%= label_tag "confirm", t(".confirm"), { :class => "form-check-label" } %> +
+
+ + <%= f.primary t(".revoke") %> + <% end %> <% else %> -

- <%= t(".past", :time => time_ago_in_words(@user_block.ends_at, :scope => :'datetime.distance_in_words_ago')) %> -

+

+ <%= t(".past", :time => time_ago_in_words(@user_block.ends_at, :scope => :'datetime.distance_in_words_ago')) %> +

<% end %> diff --git a/app/views/users/account.html.erb b/app/views/users/account.html.erb index 43171d834..bb30581f9 100644 --- a/app/views/users/account.html.erb +++ b/app/views/users/account.html.erb @@ -100,9 +100,9 @@ <%= f.text_field :home_lon, :wrapper_class => "col-sm-4", :id => "home_lon" %>
-
- checked="checked" <% end %> id="updatehome" /> - +
+ checked="checked" <% end %> id="updatehome" /> +
<%= tag.div "", :id => "map", :class => "content_map set_location" %> diff --git a/config/routes.rb b/config/routes.rb index bd6f3034d..97cedd965 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,8 +59,6 @@ OpenStreetMap::Application.routes.draw do get "trackpoints" => "api/tracepoints#index" - get "changes" => "api/changes#index" - get "user/:id" => "api/users#show", :id => /\d+/, :as => :api_user get "user/details" => "api/users#details" get "user/gpx_files" => "api/users#gpx_files" diff --git a/db/functions/Makefile b/db/functions/Makefile index a1259fc55..3fa4ae526 100644 --- a/db/functions/Makefile +++ b/db/functions/Makefile @@ -16,7 +16,7 @@ all: ${DESTDIR}/libpgosm.so clean: $(RM) ${DESTDIR}/*.so ${DESTDIR}/*.o -${DESTDIR}/libpgosm.so: ${DESTDIR}/quadtile.o ${DESTDIR}/maptile.o ${DESTDIR}/xid_to_int4.o +${DESTDIR}/libpgosm.so: ${DESTDIR}/quadtile.o ${DESTDIR}/xid_to_int4.o cc ${LDFLAGS} -o $@ $^ ${DESTDIR}/%.o: %.c diff --git a/db/functions/functions.sql b/db/functions/functions.sql index 4f1f7c716..5e3d4bcb3 100644 --- a/db/functions/functions.sql +++ b/db/functions/functions.sql @@ -42,33 +42,6 @@ END; $$ LANGUAGE plpgsql IMMUTABLE; --- maptile_for_point returns an integer representing the tile at the given zoom --- which contains the point (scaled_lon, scaled_lat). Note that the arguments --- are in the order (lat, lon), and should be scaled by 10^7. --- --- The maptile_for_point function is used only for grouping the results of the --- (deprecated?) /changes API call. Please don't use it for anything else, as --- it might go away in the future. -CREATE OR REPLACE FUNCTION maptile_for_point(scaled_lat int8, scaled_lon int8, zoom int4) - RETURNS int4 - AS $$ -DECLARE - lat CONSTANT DOUBLE PRECISION := scaled_lat / 10000000.0; - lon CONSTANT DOUBLE PRECISION := scaled_lon / 10000000.0; - zscale CONSTANT DOUBLE PRECISION := 2.0 ^ zoom; - pi CONSTANT DOUBLE PRECISION := 3.141592653589793; - r_per_d CONSTANT DOUBLE PRECISION := pi / 180.0; - x int4; - y int4; -BEGIN - -- straight port of the C code. see db/functions/maptile.c - x := floor((lon + 180.0) * zscale / 360.0); - y := floor((1.0 - ln(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / pi) * zscale / 2.0); - - RETURN (x << zoom) | y; -END; -$$ LANGUAGE plpgsql IMMUTABLE; - -- xid_to_int4 converts a PostgreSQL transaction ID (xid) to a 32-bit integer -- which can then be used to efficiently find rows which have changed between -- two given transactions. This is currently used by Osmosis to extract a diff --git a/db/functions/maptile.c b/db/functions/maptile.c deleted file mode 100644 index 358a3ba75..000000000 --- a/db/functions/maptile.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include - -Datum -maptile_for_point(PG_FUNCTION_ARGS) -{ - double lat = PG_GETARG_INT64(0) / 10000000.0; - double lon = PG_GETARG_INT64(1) / 10000000.0; - int zoom = PG_GETARG_INT32(2); - double scale = pow(2, zoom); - double r_per_d = M_PI / 180; - unsigned int x; - unsigned int y; - - x = floor((lon + 180.0) * scale / 360.0); - y = floor((1 - log(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / M_PI) * scale / 2.0); - - PG_RETURN_INT32((x << zoom) | y); -} - -PG_FUNCTION_INFO_V1(maptile_for_point); - -/* - * To bind this into PGSQL, try something like: - * - * CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 - * AS '/path/to/rails-port/db/functions/libpgosm', 'maptile_for_point' - * LANGUAGE C STRICT; - * - * (without all the *s) - */ - -#ifdef PG_MODULE_MAGIC -PG_MODULE_MAGIC; -#endif diff --git a/db/structure.sql b/db/structure.sql index b5c4ec01d..89a62626e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -128,31 +128,6 @@ CREATE TYPE public.user_status_enum AS ENUM ( ); --- --- Name: maptile_for_point(bigint, bigint, integer); Type: FUNCTION; Schema: public; Owner: - --- - -CREATE FUNCTION public.maptile_for_point(scaled_lat bigint, scaled_lon bigint, zoom integer) RETURNS integer - LANGUAGE plpgsql IMMUTABLE - AS $$ -DECLARE - lat CONSTANT DOUBLE PRECISION := scaled_lat / 10000000.0; - lon CONSTANT DOUBLE PRECISION := scaled_lon / 10000000.0; - zscale CONSTANT DOUBLE PRECISION := 2.0 ^ zoom; - pi CONSTANT DOUBLE PRECISION := 3.141592653589793; - r_per_d CONSTANT DOUBLE PRECISION := pi / 180.0; - x int4; - y int4; -BEGIN - -- straight port of the C code. see db/functions/maptile.c - x := floor((lon + 180.0) * zscale / 360.0); - y := floor((1.0 - ln(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / pi) * zscale / 2.0); - - RETURN (x << zoom) | y; -END; -$$; - - -- -- Name: tile_for_point(integer, integer); Type: FUNCTION; Schema: public; Owner: - -- diff --git a/script/vagrant/setup/provision.sh b/script/vagrant/setup/provision.sh index ad743ae36..e2cacfff3 100644 --- a/script/vagrant/setup/provision.sh +++ b/script/vagrant/setup/provision.sh @@ -52,7 +52,6 @@ sudo -u vagrant psql -d openstreetmap -f db/functions/functions.sql ################################################################################ #pushd db/functions #sudo -u vagrant make -#sudo -u vagrant psql openstreetmap -c "CREATE OR REPLACE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'maptile_for_point' LANGUAGE C ST#RICT" #sudo -u vagrant psql openstreetmap -c "CREATE OR REPLACE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'tile_for_point' LANGUAGE C STRICT" #sudo -u vagrant psql openstreetmap -c "CREATE OR REPLACE FUNCTION xid_to_int4(xid) RETURNS int4 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'xid_to_int4' LANGUAGE C STRICT" #popd diff --git a/test/controllers/api/changes_controller_test.rb b/test/controllers/api/changes_controller_test.rb deleted file mode 100644 index 88d3c2e0e..000000000 --- a/test/controllers/api/changes_controller_test.rb +++ /dev/null @@ -1,106 +0,0 @@ -require "test_helper" - -module Api - class ChangesControllerTest < ActionDispatch::IntegrationTest - ## - # test all routes which lead to this controller - def test_routes - assert_routing( - { :path => "/api/0.6/changes", :method => :get }, - { :controller => "api/changes", :action => "index" } - ) - end - - # MySQL and Postgres require that the C based functions are installed for - # this test to work. More information is available from: - # http://wiki.openstreetmap.org/wiki/Rails#Installing_the_quadtile_functions - # or by looking at the readme in db/README - def test_changes_simple - # create a selection of nodes - (1..5).each do |n| - create(:node, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => n, :lon => n) - end - # deleted nodes should also be counted - create(:node, :deleted, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => 6, :lon => 6) - # nodes in the same tile won't change the total - create(:node, :timestamp => Time.utc(2007, 1, 1, 0, 0, 0), :lat => 6, :lon => 6) - # nodes with a different timestamp should be ignored - create(:node, :timestamp => Time.utc(2008, 1, 1, 0, 0, 0), :lat => 7, :lon => 7) - - travel_to Time.utc(2010, 4, 3, 10, 55, 0) do - get changes_path - assert_response :success - now = Time.now.getutc - hourago = now - 1.hour - assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do - assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do - assert_select "tile", :count => 0 - end - end - end - - travel_to Time.utc(2007, 1, 1, 0, 30, 0) do - get changes_path - assert_response :success - # print @response.body - # As we have loaded the fixtures, we can assume that there are some - # changes at the time we have frozen at - now = Time.now.getutc - hourago = now - 1.hour - assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do - assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do - assert_select "tile", :count => 6 - end - end - end - end - - def test_changes_zoom_invalid - zoom_to_test = %w[p -1 0 17 one two] - zoom_to_test.each do |zoom| - get changes_path(:zoom => zoom) - assert_response :bad_request - assert_equal("Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", @response.body) - end - end - - def test_changes_zoom_valid - 1.upto(16) do |zoom| - get changes_path(:zoom => zoom) - assert_response :success - # NOTE: there was a test here for the timing, but it was too sensitive to be a good test - # and it was annoying. - assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do - assert_select "changes", :count => 1 - end - end - end - - def test_changes_hours_invalid - invalid = %w[-21 335 -1 0 25 26 100 one two three ping pong :] - invalid.each do |hour| - get changes_path(:hours => hour) - assert_response :bad_request, "Problem with the hour: #{hour}" - assert_equal("Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", @response.body, "Problem with the hour: #{hour}.") - end - end - - def test_changes_hours_valid - 1.upto(24) do |hour| - get changes_path(:hours => hour) - assert_response :success - end - end - - def test_changes_start_end_invalid - get changes_path(:start => "2010-04-03 10:55:00", :end => "2010-04-03 09:55:00") - assert_response :bad_request - assert_equal("Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", @response.body) - end - - def test_changes_start_end_valid - get changes_path(:start => "2010-04-03 09:55:00", :end => "2010-04-03 10:55:00") - assert_response :success - end - end -end