From: Tom Hughes Date: Mon, 10 Jun 2019 20:29:38 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/2204' X-Git-Tag: live~2586 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/6db326aa1f084a062a3b658876bc01bf650f5702?hp=c17cd3a27994f4a0900ca2f292e9761c7098c684 Merge remote-tracking branch 'upstream/pull/2204' --- diff --git a/.rubocop.yml b/.rubocop.yml index 690d984f7..7d2df0445 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,9 @@ inherit_from: .rubocop_todo.yml +require: + - rubocop-performance + - rubocop-rails + AllCops: TargetRubyVersion: 2.5 @@ -15,6 +19,10 @@ Lint/PercentStringArray: - 'app/controllers/application_controller.rb' - 'app/controllers/site_controller.rb' +Metrics/BlockLength: + Exclude: + - 'config/routes.rb' + Naming/FileName: Exclude: - 'script/deliver-message' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 25a30bf40..26b5aa64b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,79 +1,79 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-09-19 14:24:02 +0100 using RuboCop version 0.58.2. +# on 2019-06-05 09:04:25 +0100 using RuboCop version 0.71.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 32 +# Offense count: 33 # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: Exclude: + - 'app/controllers/api/traces_controller.rb' + - 'app/controllers/api/user_preferences_controller.rb' - 'app/controllers/application_controller.rb' - 'app/controllers/geocoder_controller.rb' - 'app/controllers/notes_controller.rb' - - 'app/controllers/api/traces_controller.rb' - 'app/controllers/traces_controller.rb' - 'app/controllers/users_controller.rb' - - 'app/controllers/api/user_preferences_controller.rb' - 'app/helpers/application_helper.rb' - - 'app/helpers/browse_helper.rb' - 'app/helpers/browse_tags_helper.rb' - - 'app/models/client_application.rb' - 'app/mailers/notifier.rb' + - 'app/models/client_application.rb' - 'lib/nominatim.rb' - 'lib/osm.rb' - 'script/deliver-message' # Offense count: 4 +# Configuration parameters: AllowComments. Lint/HandleExceptions: Exclude: - 'app/controllers/api/amf_controller.rb' - 'app/controllers/users_controller.rb' -# Offense count: 692 +# Offense count: 703 Metrics/AbcSize: - Max: 283 + Max: 279 # Offense count: 40 # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 262 + Max: 71 -# Offense count: 11 +# Offense count: 15 # Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 5 -# Offense count: 63 +# Offense count: 68 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 1627 + Max: 1397 -# Offense count: 72 +# Offense count: 73 Metrics/CyclomaticComplexity: - Max: 23 + Max: 22 -# Offense count: 691 -# Configuration parameters: CountComments. +# Offense count: 714 +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 179 -# Offense count: 2 +# Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 135 + Max: 107 # Offense count: 4 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 9 -# Offense count: 72 +# Offense count: 71 Metrics/PerceivedComplexity: - Max: 23 + Max: 25 # Offense count: 6 Naming/AccessorMethodName: @@ -111,14 +111,6 @@ Rails/BulkChangeTable: - 'db/migrate/20120208194454_add_domain_to_acl.rb' - 'db/migrate/20120404205604_add_user_and_description_to_redaction.rb' -# Offense count: 2 -# Configuration parameters: Include. -# Include: app/**/*.rb, config/**/*.rb, lib/**/*.rb -Rails/Exit: - Exclude: - - 'lib/**/*.rake' - - 'lib/daemons/gpx_import.rb' - # Offense count: 2 # Configuration parameters: Include. # Include: app/models/**/*.rb @@ -127,6 +119,15 @@ Rails/HasAndBelongsToMany: - 'app/models/changeset.rb' - 'app/models/user.rb' +# Offense count: 11 +# Configuration parameters: Include. +# Include: app/helpers/**/*.rb +Rails/HelperInstanceVariable: + Exclude: + - 'app/helpers/application_helper.rb' + - 'app/helpers/title_helper.rb' + - 'app/helpers/trace_helper.rb' + # Offense count: 5 # Configuration parameters: Include. # Include: db/migrate/*.rb @@ -138,7 +139,7 @@ Rails/NotNullColumn: - 'db/migrate/025_add_end_time_to_changesets.rb' - 'db/migrate/20120404205604_add_user_and_description_to_redaction.rb' -# Offense count: 20 +# Offense count: 18 Rails/OutputSafety: Exclude: - 'app/controllers/users_controller.rb' @@ -148,11 +149,11 @@ Rails/OutputSafety: - 'app/helpers/note_helper.rb' - 'app/helpers/open_graph_helper.rb' - 'app/helpers/user_blocks_helper.rb' - - 'app/helpers/user_roles_helper.rb' - 'lib/rich_text.rb' - 'test/helpers/application_helper_test.rb' -# Offense count: 86 +# Offense count: 94 +# Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: strict, flexible Rails/TimeZone: @@ -164,14 +165,14 @@ Style/AsciiComments: Exclude: - 'test/models/message_test.rb' -# Offense count: 230 +# Offense count: 255 Style/Documentation: Enabled: false -# Offense count: 462 +# Offense count: 503 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. -# SupportedStyles: when_needed, always, never +# SupportedStyles: always, never Style/FrozenStringLiteralComment: Enabled: false @@ -181,14 +182,15 @@ Style/IfUnlessModifier: Exclude: - 'app/controllers/api/ways_controller.rb' -# Offense count: 70 +# Offense count: 74 # Cop supports --auto-correct. # Configuration parameters: Strict. Style/NumericLiterals: MinDigits: 11 -# Offense count: 3080 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Offense count: 3320 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 1073 diff --git a/.travis.yml b/.travis.yml index 9b848200f..459c36f4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ -sudo: false +dist: xenial language: ruby rvm: - - 2.5.1 -cache: bundler + - 2.5.3 +cache: + - bundler addons: postgresql: 9.5 apt: @@ -14,6 +15,7 @@ env: global: - OSM_MEMCACHE_SERVERS="127.0.0.1" before_script: + - sed -e "/idle_in_transaction_session_timeout/d" -e 's/ IMMUTABLE / /' -e "s/AS '.*libpgosm.*',/AS 'libpgosm',/" -e "/^--/d" db/structure.sql > db/structure.expected - psql -U postgres -c "CREATE DATABASE openstreetmap" - psql -U postgres -c "CREATE EXTENSION btree_gist" openstreetmap - make -C db/functions libpgosm.so @@ -27,6 +29,9 @@ before_script: - bundle exec rake i18n:js:export script: - bundle exec rubocop -f fuubar - - bundle exec rake jshint + - bundle exec rake eslint:run_all - bundle exec erblint . + - bundle exec rake db:structure:dump + - sed -e "/idle_in_transaction_session_timeout/d" -e 's/ IMMUTABLE / /' -e "s/AS '.*libpgosm.*',/AS 'libpgosm',/" -e "/^--/d" db/structure.sql > db/structure.actual + - diff -uw db/structure.expected db/structure.actual - bundle exec rake test:db diff --git a/Gemfile b/Gemfile index 6c867193c..dc1615ffc 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem "psych", :platforms => :ruby_20 gem "json" # Use postgres as the database -gem "pg", "~> 0.18" +gem "pg" # Use SCSS for stylesheets gem "sassc-rails" @@ -60,7 +60,8 @@ gem "paperclip", "~> 5.2" gem "rack-cors" gem "rails-i18n", "~> 4.0.0" gem "record_tag_helper" -gem "rinku", "= 2.0.4", :require => "rails_rinku" +gem "rinku", ">= 2.0.6", :require => "rails_rinku" +gem "strong_migrations" gem "validates_email_format_of", ">= 1.5.1" # Native OSM extensions @@ -137,6 +138,8 @@ group :test do gem "minitest", "~> 5.1", :platforms => [:ruby_19, :ruby_20] gem "rails-controller-testing" gem "rubocop" + gem "rubocop-performance" + gem "rubocop-rails" gem "webmock" end @@ -145,8 +148,10 @@ group :development, :test do gem "capybara", "~> 2.13" gem "coveralls", :require => false gem "erb_lint", :require => false + gem "eslint-rails-ee" + gem "execjs" gem "factory_bot_rails" - gem "jshint" gem "poltergeist" gem "puma", "~> 3.7" + gem "therubyracer", :platforms => :ruby end diff --git a/Gemfile.lock b/Gemfile.lock index a696aaaa9..479818938 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: https://rubygems.org/ specs: SystemTimer (1.2.3) - aasm (5.0.2) + aasm (5.0.5) concurrent-ruby (~> 1.0) actioncable (5.2.3) actionpack (= 5.2.3) @@ -40,7 +40,7 @@ GEM activemodel (= 5.2.3) activesupport (= 5.2.3) arel (>= 9.0) - activerecord-import (1.0.1) + activerecord-import (1.0.2) activerecord (>= 3.2) activestorage (5.2.3) actionpack (= 5.2.3) @@ -53,8 +53,8 @@ GEM tzinfo (~> 1.1) addressable (2.6.0) public_suffix (>= 2.0.2, < 4.0) - annotate (2.7.4) - activerecord (>= 3.2, < 6.0) + annotate (2.7.5) + activerecord (>= 3.2, < 7.0) rake (>= 10.4, < 13.0) arel (9.0.0) ast (2.4.0) @@ -75,11 +75,11 @@ GEM bigdecimal (1.1.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bootsnap (1.4.2) + bootsnap (1.4.4) msgpack (~> 1.0) browser (2.5.3) builder (3.2.3) - cancancan (2.3.0) + cancancan (3.0.1) canonical-rails (0.2.5) rails (>= 4.1, < 6.1) capybara (2.18.0) @@ -99,6 +99,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) + colorize (0.8.1) composite_primary_keys (11.1.0) activerecord (~> 5.2.1) concurrent-ruby (1.1.5) @@ -106,11 +107,11 @@ GEM activesupport (>= 3.0) deep_merge (~> 1.2.1) dry-validation (>= 0.12.2) - coveralls (0.8.22) + coveralls (0.8.23) json (>= 1.8, < 3) simplecov (~> 0.16.1) term-ansicolor (~> 1.3) - thor (~> 0.19.4) + thor (>= 0.19.4, < 2.0) tins (~> 1.6) crack (0.4.3) safe_yaml (~> 1.0.0) @@ -124,7 +125,7 @@ GEM activerecord (>= 3.0, < 5.3) delayed_job (>= 3.0, < 5) docile (1.3.1) - dry-configurable (0.8.2) + dry-configurable (0.8.3) concurrent-ruby (~> 1.0) dry-core (~> 0.4, >= 0.4.7) dry-container (0.7.0) @@ -134,8 +135,8 @@ GEM concurrent-ruby (~> 1.0) dry-equalizer (0.2.2) dry-inflector (0.1.2) - dry-logic (0.5.0) - dry-container (~> 0.2, >= 0.2.6) + dry-logic (0.6.1) + concurrent-ruby (~> 1.0) dry-core (~> 0.2) dry-equalizer (~> 0.2) dry-types (0.14.1) @@ -145,7 +146,7 @@ GEM dry-equalizer (~> 0.2) dry-inflector (~> 0.1, >= 0.1.2) dry-logic (~> 0.5, >= 0.5) - dry-validation (0.13.1) + dry-validation (0.13.3) concurrent-ruby (~> 1.0) dry-configurable (~> 0.1, >= 0.1.3) dry-core (~> 0.2, >= 0.2.1) @@ -161,60 +162,60 @@ GEM rubocop (~> 0.51) smart_properties erubi (1.8.0) + eslint-rails-ee (1.0.2) + colorize + execjs + railties (>= 3.2) execjs (2.7.0) exifr (1.3.6) factory_bot (5.0.2) activesupport (>= 4.2.0) - factory_bot_rails (5.0.1) - factory_bot (~> 5.0.0) + factory_bot_rails (5.0.2) + factory_bot (~> 5.0.2) railties (>= 4.2.0) - fakefs (0.20.0) + fakefs (0.20.1) faraday (0.15.4) multipart-post (>= 1.2, < 3) - ffi (1.10.0) - fspath (3.1.0) + ffi (1.11.1) + fspath (3.1.1) gd2-ffij (0.4.0) ffi (>= 1.0.0) geoip (1.6.4) globalid (0.4.2) activesupport (>= 4.2.0) - hashdiff (0.3.8) + hashdiff (0.4.0) hashie (3.6.0) html_tokenizer (0.0.7) htmlentities (4.3.4) http_accept_language (2.0.5) i18n (0.9.5) concurrent-ruby (~> 1.0) - i18n-js (3.2.1) + i18n-js (3.2.3) i18n (>= 0.6.6) - image_optim (0.26.3) + image_optim (0.26.4) exifr (~> 1.2, >= 1.2.2) fspath (~> 3.0) image_size (>= 1.5, < 3) in_threads (~> 1.3) progress (~> 3.0, >= 3.0.1) - image_optim_rails (0.4.1) + image_optim_rails (0.4.2) image_optim (~> 0.24) rails sprockets - image_size (2.0.0) - in_threads (1.5.1) + image_size (2.0.1) + in_threads (1.5.2) jaro_winkler (1.5.2) jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jshint (1.5.0) - execjs (>= 1.4.0) - multi_json (~> 1.0) - therubyracer (~> 0.12.1) json (2.2.0) jsonify (0.3.1) multi_json (~> 1.0) jsonify-rails (0.3.2) actionpack jsonify (< 0.4.0) - jwt (2.1.0) + jwt (2.2.1) kgio (2.11.2) kramdown (2.1.0) libv8 (3.16.14.19) @@ -238,17 +239,17 @@ GEM method_source (0.9.2) mime-types (3.2.2) mime-types-data (~> 3.2015) - mime-types-data (3.2018.0812) + mime-types-data (3.2019.0331) mimemagic (0.3.3) mini_mime (1.0.1) mini_portile2 (2.4.0) minitest (5.11.3) - msgpack (1.2.9) + msgpack (1.2.10) multi_json (1.13.1) multi_xml (0.6.0) - multipart-post (2.0.0) + multipart-post (2.1.1) nio4r (2.3.1) - nokogiri (1.10.2) + nokogiri (1.10.3) mini_portile2 (~> 2.4.0) nokogumbo (2.0.1) nokogiri (~> 1.8, >= 1.8.4) @@ -272,7 +273,7 @@ GEM omniauth-github (1.3.0) omniauth (~> 1.5) omniauth-oauth2 (>= 1.4.0, < 2.0) - omniauth-google-oauth2 (0.6.1) + omniauth-google-oauth2 (0.7.0) jwt (>= 2.0) omniauth (>= 1.1.1) omniauth-oauth2 (>= 1.5) @@ -298,21 +299,21 @@ GEM mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) - parallel (1.16.0) - parser (2.6.2.0) + parallel (1.17.0) + parser (2.6.3.0) ast (~> 2.4.0) - pg (0.21.0) + pg (1.1.4) poltergeist (1.18.1) capybara (>= 2.1, < 4) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) - progress (3.5.0) + progress (3.5.1) psych (3.1.0) - public_suffix (3.0.3) + public_suffix (3.1.0) puma (3.12.1) quad_tile (1.0.1) r2 (0.2.7) - rack (2.0.6) + rack (2.0.7) rack-cors (1.0.3) rack-openid (1.3.1) rack (>= 1.1.0) @@ -361,19 +362,23 @@ GEM ref (2.0.0) request_store (1.4.1) rack (>= 1.4) - rinku (2.0.4) - rotp (4.1.0) + rinku (2.0.6) + rotp (5.0.0) addressable (~> 2.5) - rubocop (0.66.0) + rubocop (0.71.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - psych (>= 3.1.0) + parser (>= 2.6) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.6) + unicode-display_width (>= 1.4.0, < 1.7) + rubocop-performance (1.3.0) + rubocop (>= 0.68.0) + rubocop-rails (2.0.0) + rack (>= 2.0) + rubocop (>= 0.70.0) ruby-openid (2.7.0) - ruby-progressbar (1.10.0) + ruby-progressbar (1.10.1) ruby_dep (1.5.0) safe_yaml (1.0.5) sanitize (5.0.0) @@ -383,7 +388,7 @@ GEM sassc (2.0.1) ffi (~> 1.9) rake - sassc-rails (2.1.0) + sassc-rails (2.1.1) railties (>= 4.0.0) sassc (>= 2.0) sprockets (> 3.0) @@ -395,7 +400,7 @@ GEM json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - smart_properties (1.13.1) + smart_properties (1.14.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -403,6 +408,8 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + strong_migrations (0.4.0) + activerecord (>= 5) term-ansicolor (1.7.1) tins (~> 1.0) terrapin (0.6.0) @@ -410,22 +417,22 @@ GEM therubyracer (0.12.3) libv8 (~> 3.16.14.15) ref - thor (0.19.4) + thor (0.20.3) thread_safe (0.3.6) tilt (2.0.9) - tins (1.20.2) + tins (1.20.3) tzinfo (1.2.5) thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) - unicode-display_width (1.5.0) + unicode-display_width (1.6.0) validates_email_format_of (1.6.3) i18n vendorer (0.2.0) - webmock (3.5.1) + webmock (3.6.0) addressable (>= 2.3.6) crack (>= 0.3.2) - hashdiff + hashdiff (>= 0.4.0, < 2.0.0) websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) @@ -459,6 +466,8 @@ DEPENDENCIES delayed_job_active_record dynamic_form erb_lint + eslint-rails-ee + execjs factory_bot_rails fakefs faraday @@ -469,7 +478,6 @@ DEPENDENCIES i18n-js (>= 3.0.0) image_optim_rails jquery-rails - jshint json jsonify-rails kgio @@ -488,7 +496,7 @@ DEPENDENCIES omniauth-windowslive openstreetmap-deadlock_retry (>= 1.3.0) paperclip (~> 5.2) - pg (~> 0.18) + pg poltergeist psych puma (~> 3.7) @@ -500,12 +508,16 @@ DEPENDENCIES rails-controller-testing rails-i18n (~> 4.0.0) record_tag_helper - rinku (= 2.0.4) + rinku (>= 2.0.6) rotp rubocop + rubocop-performance + rubocop-rails sanitize sassc-rails secure_headers + strong_migrations + therubyracer uglifier (>= 1.3.0) validates_email_format_of (>= 1.5.1) vendorer diff --git a/Vendorfile b/Vendorfile index 22a6ae422..ad59f91eb 100644 --- a/Vendorfile +++ b/Vendorfile @@ -11,13 +11,13 @@ folder 'vendor/assets' do end folder 'leaflet' do - file 'leaflet.js', 'https://unpkg.com/leaflet@1.4.0/dist/leaflet-src.js' - file 'leaflet.css', 'https://unpkg.com/leaflet@1.4.0/dist/leaflet.css' + file 'leaflet.js', 'https://unpkg.com/leaflet@1.5.1/dist/leaflet-src.js' + file 'leaflet.css', 'https://unpkg.com/leaflet@1.5.1/dist/leaflet.css' [ 'layers.png', 'layers-2x.png', 'marker-icon.png', 'marker-icon-2x.png', 'marker-shadow.png' ].each do |image| - file "images/#{image}", "https://unpkg.com/leaflet@1.4.0/dist/images/#{image}" + file "images/#{image}", "https://unpkg.com/leaflet@1.5.1/dist/images/#{image}" end from 'git://github.com/aratcliffe/Leaflet.contextmenu.git', :tag => 'v1.5.0' do diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index d2864e452..28380392d 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -36,7 +36,7 @@ class Ability if Settings.status != "database_offline" can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication - can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry + can [:new, :create, :edit, :update, :comment, :subscribe, :unsubscribe], DiaryEntry can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message can [:close, :reopen], Note can [:new, :create], Report @@ -51,7 +51,7 @@ class Ability end if user.administrator? - can [:hide, :hidecomment], [DiaryEntry, DiaryComment] + can [:hide, :unhide, :hidecomment, :unhidecomment], [DiaryEntry, DiaryComment] can [:index, :show, :resolve, :ignore, :reopen], Issue can :create, IssueComment can [:set_status, :delete, :index], User diff --git a/app/abilities/api_ability.rb b/app/abilities/api_ability.rb index 54bc8fb4c..a71d05d75 100644 --- a/app/abilities/api_ability.rb +++ b/app/abilities/api_ability.rb @@ -15,7 +15,7 @@ class ApiAbility can [:show, :download, :query], Changeset can [:index, :create, :comment, :feed, :show, :search], Note can :index, Tracepoint - can [:api_users, :api_read], User + can [:index, :show], User can [:index, :show], Node can [:index, :show, :full, :ways_for_node], Way can [:index, :show, :full, :relations_for_node, :relations_for_way, :relations_for_relation], Relation @@ -33,8 +33,8 @@ class ApiAbility can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message can [:close, :reopen], Note can [:new, :create], Report - can [:api_create, :api_read, :api_update, :api_delete, :api_data], Trace - can [:api_details, :api_gpx_files], User + can [:create, :show, :update, :destroy, :data], Trace + can [:details, :gpx_files], User can [:read, :read_one, :update, :update_one, :delete_one], UserPreference if user.terms_agreed? diff --git a/app/abilities/api_capability.rb b/app/abilities/api_capability.rb index 9f59b1f24..7d8a13364 100644 --- a/app/abilities/api_capability.rb +++ b/app/abilities/api_capability.rb @@ -6,10 +6,10 @@ class ApiCapability def initialize(token) if Settings.status != "database_offline" can [:create, :comment, :close, :reopen], Note if capability?(token, :allow_write_notes) - can [:api_read, :api_data], Trace if capability?(token, :allow_read_gpx) - can [:api_create, :api_update, :api_delete], Trace if capability?(token, :allow_write_gpx) - can [:api_details], User if capability?(token, :allow_read_prefs) - can [:api_gpx_files], User if capability?(token, :allow_read_gpx) + can [:show, :data], Trace if capability?(token, :allow_read_gpx) + can [:create, :update, :destroy], Trace if capability?(token, :allow_write_gpx) + can [:details], User if capability?(token, :allow_read_prefs) + can [:gpx_files], User if capability?(token, :allow_read_gpx) can [:read, :read_one], UserPreference if capability?(token, :allow_read_prefs) can [:update, :update_one, :delete_one], UserPreference if capability?(token, :allow_write_prefs) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index ebb0ff580..4a310f22b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,14 +17,14 @@ //= require richtext //= require querystring -var querystring = require('querystring-component'); +var querystring = require("querystring-component"); /* * Called as the user scrolls/zooms around to maniplate hrefs of the * view tab and various other links */ window.updateLinks = function (loc, zoom, layers, object) { - $(".geolink").each(function(index, link) { + $(".geolink").each(function (index, link) { var href = link.href.split(/[?#]/)[0], args = querystring.parse(link.search.substring(1)), editlink = $(link).hasClass("editlink"); @@ -39,11 +39,11 @@ window.updateLinks = function (loc, zoom, layers, object) { } var query = querystring.stringify(args); - if (query) href += '?' + query; + if (query) href += "?" + query; args = { lat: loc.lat, - lon: 'lon' in loc ? loc.lon : loc.lng, + lon: "lon" in loc ? loc.lon : loc.lng, zoom: zoom }; @@ -57,13 +57,13 @@ window.updateLinks = function (loc, zoom, layers, object) { }); var editDisabled = zoom < 13; - $('#edit_tab') - .tooltip({placement: 'bottom'}) - .off('click.minzoom') - .on('click.minzoom', function() { return !editDisabled; }) - .toggleClass('disabled', editDisabled) - .attr('data-original-title', editDisabled ? - I18n.t('javascripts.site.edit_disabled_tooltip') : ''); + $("#edit_tab") + .tooltip({ placement: "bottom" }) + .off("click.minzoom") + .on("click.minzoom", function () { return !editDisabled; }) + .toggleClass("disabled", editDisabled) + .attr("data-original-title", editDisabled ? + I18n.t("javascripts.site.edit_disabled_tooltip") : ""); }; window.maximiseMap = function () { @@ -97,13 +97,13 @@ $(document).ready(function () { * to defer the measurement slightly as a workaround. */ setTimeout(function () { - $("header").children(":visible").each(function (i,e) { + $("header").children(":visible").each(function (i, e) { headerWidth = headerWidth + $(e).outerWidth(); }); $("body").addClass("compact"); - $("header").children(":visible").each(function (i,e) { + $("header").children(":visible").each(function (i, e) { compactWidth = compactWidth + $(e).outerWidth(); }); @@ -114,12 +114,12 @@ $(document).ready(function () { $(window).resize(updateHeader); }, 0); - $("#menu-icon").on("click", function(e) { + $("#menu-icon").on("click", function (e) { e.preventDefault(); $("header").toggleClass("closed"); }); - $("nav.primary li a").on("click", function() { + $("nav.primary li a").on("click", function () { $("header").toggleClass("closed"); }); diff --git a/app/assets/javascripts/diary_entry.js b/app/assets/javascripts/diary_entry.js index f13706971..625d43a52 100644 --- a/app/assets/javascripts/diary_entry.js +++ b/app/assets/javascripts/diary_entry.js @@ -9,8 +9,8 @@ $(document).ready(function () { map.removeLayer(marker); } - marker = L.marker(e.latlng, {icon: OSM.getUserIcon()}).addTo(map) - .bindPopup(I18n.t('diary_entries.edit.marker_text')); + marker = L.marker(e.latlng, { icon: OSM.getUserIcon() }).addTo(map) + .bindPopup(I18n.t("diary_entries.edit.marker_text")); } $("#usemap").click(function (e) { @@ -21,21 +21,21 @@ $(document).ready(function () { var params = $("#map").data(); var centre = [params.lat, params.lon]; - var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright'; + var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright"; map = L.map("map", { attributionControl: false, zoomControl: false }).addLayer(new L.OSM.Mapnik()); - L.OSM.zoom({position: position}) + L.OSM.zoom({ position: position }) .addTo(map); map.setView(centre, params.zoom); if ($("#latitude").val() && $("#longitude").val()) { - marker = L.marker(centre, {icon: OSM.getUserIcon()}).addTo(map) - .bindPopup(I18n.t('diary_entries.edit.marker_text')); + marker = L.marker(centre, { icon: OSM.getUserIcon() }).addTo(map) + .bindPopup(I18n.t("diary_entries.edit.marker_text")); } map.on("click", setLocation); diff --git a/app/assets/javascripts/fixthemap.js b/app/assets/javascripts/fixthemap.js index e2a503ad3..47ba9baf4 100644 --- a/app/assets/javascripts/fixthemap.js +++ b/app/assets/javascripts/fixthemap.js @@ -1,12 +1,12 @@ -$(document).ready(function() { +$(document).ready(function () { var params = OSM.params(); - var url = '/note/new'; + var url = "/note/new"; if (params.lat && params.lon) { params.lat = parseFloat(params.lat); params.lon = parseFloat(params.lon); params.zoom = params.zoom || 17; url += OSM.formatHash(params); } - $('.icon.note').attr('href', url); + $(".icon.note").attr("href", url); }); diff --git a/app/assets/javascripts/id.js b/app/assets/javascripts/id.js index dd7cd3325..0aae749f7 100644 --- a/app/assets/javascripts/id.js +++ b/app/assets/javascripts/id.js @@ -2,14 +2,14 @@ /* globals iD */ -document.addEventListener("DOMContentLoaded", function() { +document.addEventListener("DOMContentLoaded", function () { var container = document.getElementById("id-container"); - if (typeof iD === 'undefined' || !iD.Detect().support) { - container.innerHTML = 'This editor is supported ' + - 'in Firefox, Chrome, Safari, Opera, Edge, and Internet Explorer 11. ' + - 'Please upgrade your browser or use Potlatch 2 to edit the map.'; - container.className = 'unsupported'; + if (typeof iD === "undefined" || !iD.Detect().support) { + container.innerHTML = "This editor is supported " + + "in Firefox, Chrome, Safari, Opera, Edge, and Internet Explorer 11. " + + "Please upgrade your browser or use Potlatch 2 to edit the map."; + container.className = "unsupported"; } else { var id = iD.Context() .embed(true) @@ -24,7 +24,7 @@ document.addEventListener("DOMContentLoaded", function() { oauth_token_secret: container.dataset.tokenSecret }); - id.map().on('move.embed', parent.$.throttle(250, function() { + id.map().on("move.embed", parent.$.throttle(250, function () { if (id.inIntro()) return; var zoom = ~~id.map().zoom(), center = id.map().center(), @@ -46,7 +46,7 @@ document.addEventListener("DOMContentLoaded", function() { // 0ms timeout to avoid iframe JS context weirdness. // http://bl.ocks.org/jfirebaugh/5439412 - setTimeout(function() { + setTimeout(function () { id.map().centerZoom( [data.lon, data.lat], Math.max(data.zoom || 15, 13)); diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index e8e566f53..6228b2376 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -25,49 +25,55 @@ $(document).ready(function () { var loaderTimeout; - OSM.loadSidebarContent = function(path, callback) { + var map = new L.OSM.Map("map", { + zoomControl: false, + layerControl: false, + contextmenu: true + }); + + OSM.loadSidebarContent = function (path, callback) { map.setSidebarOverlaid(false); clearTimeout(loaderTimeout); - loaderTimeout = setTimeout(function() { - $('#sidebar_loader').show(); + loaderTimeout = setTimeout(function () { + $("#sidebar_loader").show(); }, 200); // IE<10 doesn't respect Vary: X-Requested-With header, so // prevent caching the XHR response as a full-page URL. - if (path.indexOf('?') >= 0) { - path += '&xhr=1'; + if (path.indexOf("?") >= 0) { + path += "&xhr=1"; } else { - path += '?xhr=1'; + path += "?xhr=1"; } - $('#sidebar_content') + $("#sidebar_content") .empty(); $.ajax({ url: path, dataType: "html", - complete: function(xhr) { + complete: function (xhr) { clearTimeout(loaderTimeout); - $('#flash').empty(); - $('#sidebar_loader').hide(); + $("#flash").empty(); + $("#sidebar_loader").hide(); var content = $(xhr.responseText); - if (xhr.getResponseHeader('X-Page-Title')) { - var title = xhr.getResponseHeader('X-Page-Title'); + if (xhr.getResponseHeader("X-Page-Title")) { + var title = xhr.getResponseHeader("X-Page-Title"); document.title = decodeURIComponent(title); } - $('head') - .find('link[type="application/atom+xml"]') + $("head") + .find("link[type=\"application/atom+xml\"]") .remove(); - $('head') - .append(content.filter('link[type="application/atom+xml"]')); + $("head") + .append(content.filter("link[type=\"application/atom+xml\"]")); - $('#sidebar_content').html(content.not('link[type="application/atom+xml"]')); + $("#sidebar_content").html(content.not("link[type=\"application/atom+xml\"]")); if (callback) { callback(); @@ -78,13 +84,7 @@ $(document).ready(function () { var params = OSM.mapParams(); - var map = new L.OSM.Map("map", { - zoomControl: false, - layerControl: false, - contextmenu: true - }); - - map.attributionControl.setPrefix(''); + map.attributionControl.setPrefix(""); map.updateLayers(params.layers); @@ -94,32 +94,32 @@ $(document).ready(function () { } }); - var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright'; + var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright"; - L.OSM.zoom({position: position}) + L.OSM.zoom({ position: position }) .addTo(map); var locate = L.control.locate({ position: position, - icon: 'icon geolocate', - iconLoading: 'icon geolocate', + icon: "icon geolocate", + iconLoading: "icon geolocate", strings: { - title: I18n.t('javascripts.map.locate.title'), - popup: I18n.t('javascripts.map.locate.popup') + title: I18n.t("javascripts.map.locate.title"), + popup: I18n.t("javascripts.map.locate.popup") } }).addTo(map); var locateContainer = locate.getContainer(); $(locateContainer) - .removeClass('leaflet-control-locate leaflet-bar') - .addClass('control-locate') + .removeClass("leaflet-control-locate leaflet-bar") + .addClass("control-locate") .children("a") - .attr('href', '#') - .removeClass('leaflet-bar-part leaflet-bar-part-single') - .addClass('control-button'); + .attr("href", "#") + .removeClass("leaflet-bar-part leaflet-bar-part-single") + .addClass("control-button"); - var sidebar = L.OSM.sidebar('#map-ui') + var sidebar = L.OSM.sidebar("#map-ui") .addTo(map); L.OSM.layers({ @@ -134,9 +134,9 @@ $(document).ready(function () { }).addTo(map); L.OSM.share({ - position: position, - sidebar: sidebar, - short: true + "position": position, + "sidebar": sidebar, + "short": true }).addTo(map); L.OSM.note({ @@ -154,7 +154,7 @@ $(document).ready(function () { OSM.initializeContextMenu(map); - if (OSM.STATUS !== 'api_offline' && OSM.STATUS !== 'database_offline') { + if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") { OSM.initializeNotes(map); if (params.layers.indexOf(map.noteLayer.options.code) >= 0) { map.addLayer(map.noteLayer); @@ -170,51 +170,51 @@ $(document).ready(function () { } } - var placement = $('html').attr('dir') === 'rtl' ? 'right' : 'left'; - $('.leaflet-control .control-button').tooltip({placement: placement, container: 'body'}); + var placement = $("html").attr("dir") === "rtl" ? "right" : "left"; + $(".leaflet-control .control-button").tooltip({ placement: placement, container: "body" }); var expiry = new Date(); expiry.setYear(expiry.getFullYear() + 10); - map.on('moveend layeradd layerremove', function() { + map.on("moveend layeradd layerremove", function () { updateLinks( map.getCenter().wrap(), map.getZoom(), map.getLayersCode(), map._object); - $.removeCookie('_osm_location'); - $.cookie('_osm_location', OSM.locationCookie(map), { expires: expiry, path: '/' }); + $.removeCookie("_osm_location"); + $.cookie("_osm_location", OSM.locationCookie(map), { expires: expiry, path: "/" }); }); - if ($.cookie('_osm_welcome') !== 'hide') { - $('.welcome').addClass('visible'); + if ($.cookie("_osm_welcome") !== "hide") { + $(".welcome").addClass("visible"); } - $('.welcome .close-wrap').on('click', function() { - $('.welcome').removeClass('visible'); - $.cookie('_osm_welcome', 'hide', { expires: expiry, path: '/' }); + $(".welcome .close-wrap").on("click", function () { + $(".welcome").removeClass("visible"); + $.cookie("_osm_welcome", "hide", { expires: expiry, path: "/" }); }); var bannerExpiry = new Date(); bannerExpiry.setYear(bannerExpiry.getFullYear() + 1); - $('#banner .close-wrap').on('click', function(e) { + $("#banner .close-wrap").on("click", function (e) { var cookieId = e.target.id; - $('#banner').hide(); + $("#banner").hide(); e.preventDefault(); if (cookieId) { - $.cookie(cookieId, 'hide', { expires: bannerExpiry, path: '/' }); + $.cookie(cookieId, "hide", { expires: bannerExpiry, path: "/" }); } }); if (OSM.PIWIK) { - map.on('layeradd', function (e) { + map.on("layeradd", function (e) { if (e.layer.options) { var goal = OSM.PIWIK.goals[e.layer.options.keyid]; if (goal) { - $('body').trigger('piwikgoal', goal); + $("body").trigger("piwikgoal", goal); } } }); @@ -230,14 +230,14 @@ $(document).ready(function () { L.marker([params.mlat, params.mlon]).addTo(map); } - $("#homeanchor").on("click", function(e) { + $("#homeanchor").on("click", function (e) { e.preventDefault(); var data = $(this).data(), center = L.latLng(data.lat, data.lon); map.setView(center, data.zoom); - L.marker(center, {icon: OSM.getUserIcon()}).addTo(map); + L.marker(center, { icon: OSM.getUserIcon() }).addTo(map); }); function remoteEditHandler(bbox, object) { @@ -250,8 +250,8 @@ $(document).ready(function () { bottom: bbox.getSouth() - 0.0001 }; - if (location.protocol === 'http' || - bowser.check({chrome: "53", firefox: "55"})) { + if (location.protocol === "http" || + bowser.check({ chrome: "53", firefox: "55" })) { url = "http://127.0.0.1:8111/load_and_zoom?"; } else { url = "https://127.0.0.1:8112/load_and_zoom?"; @@ -259,18 +259,18 @@ $(document).ready(function () { if (object) query.select = object.type + object.id; - var iframe = $('') + var iframe = $("") .hide() - .appendTo('body') + .appendTo("body") .attr("src", url + querystring.stringify(query)) - .on('load', function() { + .on("load", function () { $(this).remove(); loaded = true; }); setTimeout(function () { if (!loaded) { - alert(I18n.t('site.index.remote_failed')); + alert(I18n.t("site.index.remote_failed")); iframe.remove(); } }, 1000); @@ -278,35 +278,35 @@ $(document).ready(function () { return false; } - $("a[data-editor=remote]").click(function(e) { + $("a[data-editor=remote]").click(function (e) { var params = OSM.mapParams(this.search); remoteEditHandler(map.getBounds(), params.object); e.preventDefault(); }); if (OSM.params().edit_help) { - $('#editanchor') - .removeAttr('title') + $("#editanchor") + .removeAttr("title") .tooltip({ - placement: 'bottom', - title: I18n.t('javascripts.edit_help') + placement: "bottom", + title: I18n.t("javascripts.edit_help") }) - .tooltip('show'); + .tooltip("show"); - $('body').one('click', function() { - $('#editanchor').tooltip('hide'); + $("body").one("click", function () { + $("#editanchor").tooltip("hide"); }); } - OSM.Index = function(map) { + OSM.Index = function (map) { var page = {}; - page.pushstate = page.popstate = function() { + page.pushstate = page.popstate = function () { map.setSidebarOverlaid(true); - document.title = I18n.t('layouts.project_name.title'); + document.title = I18n.t("layouts.project_name.title"); }; - page.load = function() { + page.load = function () { var params = querystring.parse(location.search.substring(1)); if (params.query) { $("#sidebar .search_form input[name=query]").value(params.query); @@ -320,21 +320,21 @@ $(document).ready(function () { return page; }; - OSM.Browse = function(map, type) { + OSM.Browse = function (map, type) { var page = {}; - page.pushstate = page.popstate = function(path, id) { - OSM.loadSidebarContent(path, function() { + page.pushstate = page.popstate = function (path, id) { + OSM.loadSidebarContent(path, function () { addObject(type, id); }); }; - page.load = function(path, id) { + page.load = function (path, id) { addObject(type, id, true); }; function addObject(type, id, center) { - map.addObject({type: type, id: parseInt(id)}, function(bounds) { + map.addObject({ type: type, id: parseInt(id, 10) }, function (bounds) { if (!window.location.hash && bounds.isValid() && (center || !map.getBounds().contains(bounds))) { OSM.router.withoutMoveListener(function () { @@ -344,7 +344,7 @@ $(document).ready(function () { }); } - page.unload = function() { + page.unload = function () { map.removeObject(); }; @@ -354,21 +354,21 @@ $(document).ready(function () { var history = OSM.History(map); OSM.router = OSM.Router(map, { - "/": OSM.Index(map), - "/search": OSM.Search(map), - "/directions": OSM.Directions(map), - "/export": OSM.Export(map), - "/note/new": OSM.NewNote(map), - "/history/friends": history, - "/history/nearby": history, - "/history": history, + "/": OSM.Index(map), + "/search": OSM.Search(map), + "/directions": OSM.Directions(map), + "/export": OSM.Export(map), + "/note/new": OSM.NewNote(map), + "/history/friends": history, + "/history/nearby": history, + "/history": history, "/user/:display_name/history": history, - "/note/:id": OSM.Note(map), - "/node/:id(/history)": OSM.Browse(map, 'node'), - "/way/:id(/history)": OSM.Browse(map, 'way'), - "/relation/:id(/history)": OSM.Browse(map, 'relation'), - "/changeset/:id": OSM.Changeset(map), - "/query": OSM.Query(map) + "/note/:id": OSM.Note(map), + "/node/:id(/history)": OSM.Browse(map, "node"), + "/way/:id(/history)": OSM.Browse(map, "way"), + "/relation/:id(/history)": OSM.Browse(map, "relation"), + "/changeset/:id": OSM.Changeset(map), + "/query": OSM.Query(map) }); if (OSM.preferred_editor === "remote" && document.location.pathname === "/edit") { @@ -378,19 +378,23 @@ $(document).ready(function () { OSM.router.load(); - $(document).on("click", "a", function(e) { - if (e.isDefaultPrevented() || e.isPropagationStopped()) + $(document).on("click", "a", function (e) { + if (e.isDefaultPrevented() || e.isPropagationStopped()) { return; + } // Open links in a new tab as normal. - if (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) + if (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) { return; + } // Ignore cross-protocol and cross-origin links. - if (location.protocol !== this.protocol || location.host !== this.host) + if (location.protocol !== this.protocol || location.host !== this.host) { return; + } - if (OSM.router.route(this.pathname + this.search + this.hash)) + if (OSM.router.route(this.pathname + this.search + this.hash)) { e.preventDefault(); + } }); }); diff --git a/app/assets/javascripts/index/browse.js b/app/assets/javascripts/index/browse.js index 28a830858..630944411 100644 --- a/app/assets/javascripts/index/browse.js +++ b/app/assets/javascripts/index/browse.js @@ -26,17 +26,17 @@ OSM.initializeBrowse = function (map) { onSelect(e.layer); }); - map.on('layeradd', function (e) { + map.on("layeradd", function (e) { if (e.layer === dataLayer) { map.on("moveend", updateData); updateData(); } }); - map.on('layerremove', function (e) { + map.on("layerremove", function (e) { if (e.layer === dataLayer) { map.off("moveend", updateData); - $('#browse_status').empty(); + $("#browse_status").empty(); } }); @@ -48,7 +48,7 @@ OSM.initializeBrowse = function (map) { } function displayFeatureWarning(count, limit, add, cancel) { - $('#browse_status').html( + $("#browse_status").html( $("") .text(I18n.t("browse.start_rjs.feature_warning", { num_features: count, max_features: limit })) .prepend( @@ -56,7 +56,7 @@ OSM.initializeBrowse = function (map) { .click(cancel)) .append( $("") - .val(I18n.t('browse.start_rjs.load_data')) + .val(I18n.t("browse.start_rjs.load_data")) .click(add))); } @@ -92,13 +92,13 @@ OSM.initializeBrowse = function (map) { var features = dataLayer.buildFeatures(xml); function addFeatures() { - $('#browse_status').empty(); + $("#browse_status").empty(); dataLayer.addData(features); browseBounds = bounds; } function cancelAddFeatures() { - $('#browse_status').empty(); + $("#browse_status").empty(); } if (features.length < maxFeatures) { @@ -120,9 +120,9 @@ OSM.initializeBrowse = function (map) { // Redraw in selected style layer.originalStyle = layer.options; - layer.setStyle({color: '#0000ff', weight: 8}); + layer.setStyle({ color: "#0000ff", weight: 8 }); - OSM.router.route('/' + layer.feature.type + '/' + layer.feature.id); + OSM.router.route("/" + layer.feature.type + "/" + layer.feature.id); // Stash the currently drawn feature selectedLayer = layer; diff --git a/app/assets/javascripts/index/changeset.js b/app/assets/javascripts/index/changeset.js index fa9e1874d..5ff8edc71 100644 --- a/app/assets/javascripts/index/changeset.js +++ b/app/assets/javascripts/index/changeset.js @@ -1,23 +1,22 @@ OSM.Changeset = function (map) { var page = {}, - content = $('#sidebar_content'), + content = $("#sidebar_content"), currentChangesetId; - page.pushstate = page.popstate = function(path, id) { - OSM.loadSidebarContent(path, function() { + page.pushstate = page.popstate = function (path, id) { + OSM.loadSidebarContent(path, function () { page.load(path, id); }); }; - page.load = function(path, id) { - if(id) - currentChangesetId = id; + page.load = function (path, id) { + if (id) currentChangesetId = id; initialize(); addChangeset(currentChangesetId, true); }; function addChangeset(id, center) { - map.addObject({type: 'changeset', id: parseInt(id)}, function(bounds) { + map.addObject({ type: "changeset", id: parseInt(id, 10) }, function (bounds) { if (!window.location.hash && bounds.isValid() && (center || !map.getBounds().contains(bounds))) { OSM.router.withoutMoveListener(function () { @@ -32,8 +31,8 @@ OSM.Changeset = function (map) { $(form).find("input[type=submit]").prop("disabled", true); - if(include_data) { - data = {text: $(form.text).val()}; + if (include_data) { + data = { text: $(form.text).val() }; } else { data = {}; } @@ -72,10 +71,10 @@ OSM.Changeset = function (map) { } }); - content.find("textarea").val('').trigger("input"); + content.find("textarea").val("").trigger("input"); } - page.unload = function() { + page.unload = function () { map.removeObject(); }; diff --git a/app/assets/javascripts/index/contextmenu.js b/app/assets/javascripts/index/contextmenu.js index 080a4de72..e3e30ce6b 100644 --- a/app/assets/javascripts/index/contextmenu.js +++ b/app/assets/javascripts/index/contextmenu.js @@ -77,7 +77,7 @@ OSM.initializeContextMenu = function (map) { else map.contextmenu.enable(); }); - var updateMenu = function updateMenu () { + var updateMenu = function updateMenu() { map.contextmenu.setDisabled(2, map.getZoom() < 12); map.contextmenu.setDisabled(4, map.getZoom() < 14); }; diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index bdba41ec2..4283ef5aa 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -6,16 +6,16 @@ OSM.Directions = function (map) { var awaitingRoute; // true if we've asked the engine for a route and are waiting to hear back var chosenEngine; - var popup = L.popup({autoPanPadding: [100, 100]}); + var popup = L.popup({ autoPanPadding: [100, 100] }); var polyline = L.polyline([], { - color: '#03f', + color: "#03f", opacity: 0.3, weight: 10 }); var highlight = L.polyline([], { - color: '#ff0', + color: "#ff0", opacity: 0.5, weight: 12 }); @@ -28,6 +28,20 @@ OSM.Directions = function (map) { var expiry = new Date(); expiry.setYear(expiry.getFullYear() + 10); + var engines = OSM.Directions.engines; + + engines.sort(function (a, b) { + a = I18n.t("javascripts.directions.engines." + a.id); + b = I18n.t("javascripts.directions.engines." + b.id); + return a.localeCompare(b); + }); + + var select = $("select.routing_engines"); + + engines.forEach(function (engine, i) { + select.append("" + I18n.t("javascripts.directions.engines." + engine.id) + ""); + }); + function Endpoint(input, iconUrl) { var endpoint = {}; @@ -44,8 +58,8 @@ OSM.Directions = function (map) { autoPan: true }); - endpoint.marker.on('drag dragend', function (e) { - var dragging = (e.type === 'drag'); + endpoint.marker.on("drag dragend", function (e) { + var dragging = (e.type === "drag"); if (dragging && !chosenEngine.draggable) return; if (dragging && awaitingRoute) return; endpoint.setLatLng(e.target.getLatLng()); @@ -54,19 +68,19 @@ OSM.Directions = function (map) { } }); - input.on("keydown", function() { + input.on("keydown", function () { input.removeClass("error"); }); input.on("change", function (e) { awaitingGeocode = true; - + // make text the same in both text boxes var value = e.target.value; endpoint.setValue(value); }); - endpoint.setValue = function(value, latlng) { + endpoint.setValue = function (value, latlng) { endpoint.value = value; delete endpoint.latlng; input.removeClass("error"); @@ -79,7 +93,7 @@ OSM.Directions = function (map) { } }; - endpoint.getGeocode = function() { + endpoint.getGeocode = function () { // if no one has entered a value yet, then we can't geocode, so don't // even try. if (!endpoint.value) { @@ -88,12 +102,12 @@ OSM.Directions = function (map) { endpoint.awaitingGeocode = true; - $.getJSON(OSM.NOMINATIM_URL + 'search?q=' + encodeURIComponent(endpoint.value) + '&format=json', function (json) { + $.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json", function (json) { endpoint.awaitingGeocode = false; endpoint.hasGeocode = true; if (json.length === 0) { input.addClass("error"); - alert(I18n.t('javascripts.directions.errors.no_place', {place: endpoint.value})); + alert(I18n.t("javascripts.directions.errors.no_place", { place: endpoint.value })); return; } @@ -121,7 +135,7 @@ OSM.Directions = function (map) { return endpoint; } - $(".directions_form .reverse_directions").on("click", function() { + $(".directions_form .reverse_directions").on("click", function () { var from = endpoints[0].latlng, to = endpoints[1].latlng; @@ -132,7 +146,7 @@ OSM.Directions = function (map) { })); }); - $(".directions_form .close").on("click", function(e) { + $(".directions_form .close").on("click", function (e) { e.preventDefault(); var route_from = endpoints[0].value; if (route_from) { @@ -156,11 +170,11 @@ OSM.Directions = function (map) { var m = Math.round(s / 60); var h = Math.floor(m / 60); m -= h * 60; - return h + ":" + (m < 10 ? '0' : '') + m; + return h + ":" + (m < 10 ? "0" : "") + m; } function findEngine(id) { - return engines.findIndex(function(engine) { + return engines.findIndex(function (engine) { return engine.id === id; }); } @@ -198,14 +212,14 @@ OSM.Directions = function (map) { OSM.router.replace("/directions?" + querystring.stringify({ engine: chosenEngine.id, - route: o.lat.toFixed(precision) + ',' + o.lng.toFixed(precision) + ';' + - d.lat.toFixed(precision) + ',' + d.lng.toFixed(precision) + route: o.lat.toFixed(precision) + "," + o.lng.toFixed(precision) + ";" + + d.lat.toFixed(precision) + "," + d.lng.toFixed(precision) })); // copy loading item to sidebar and display it. we copy it, rather than // just using it in-place and replacing it in case it has to be used // again. - $('#sidebar_content').html($('.directions_form .loader_copy').html()); + $("#sidebar_content").html($(".directions_form .loader_copy").html()); map.setSidebarOverlaid(false); awaitingRoute = chosenEngine.getRoute([o, d], function (err, route) { @@ -215,7 +229,7 @@ OSM.Directions = function (map) { map.removeLayer(polyline); if (reportErrors) { - $('#sidebar_content').html('' + I18n.t('javascripts.directions.errors.no_route') + ''); + $("#sidebar_content").html("" + I18n.t("javascripts.directions.errors.no_route") + ""); } return; @@ -229,23 +243,22 @@ OSM.Directions = function (map) { map.fitBounds(polyline.getBounds().pad(0.05)); } - var html = '' + - '' + I18n.t('javascripts.directions.directions') + - '' + - I18n.t('javascripts.directions.distance') + ': ' + formatDistance(route.distance) + '. ' + - I18n.t('javascripts.directions.time') + ': ' + formatTime(route.time) + '.'; - if (typeof route.ascend !== 'undefined' && typeof route.descend !== 'undefined') { - html += '' + - I18n.t('javascripts.directions.ascend') + ': ' + Math.round(route.ascend) + 'm. ' + - I18n.t('javascripts.directions.descend') + ': ' + Math.round(route.descend) +'m.'; + var html = "" + + "" + I18n.t("javascripts.directions.directions") + + "" + + I18n.t("javascripts.directions.distance") + ": " + formatDistance(route.distance) + ". " + + I18n.t("javascripts.directions.time") + ": " + formatTime(route.time) + "."; + if (typeof route.ascend !== "undefined" && typeof route.descend !== "undefined") { + html += "" + + I18n.t("javascripts.directions.ascend") + ": " + Math.round(route.ascend) + "m. " + + I18n.t("javascripts.directions.descend") + ": " + Math.round(route.descend) + "m."; } - html += ''; + html += "
' + I18n.t('javascripts.directions.errors.no_route') + '
" + I18n.t("javascripts.directions.errors.no_route") + "
' + - I18n.t('javascripts.directions.distance') + ': ' + formatDistance(route.distance) + '. ' + - I18n.t('javascripts.directions.time') + ': ' + formatTime(route.time) + '.'; - if (typeof route.ascend !== 'undefined' && typeof route.descend !== 'undefined') { - html += '' + - I18n.t('javascripts.directions.ascend') + ': ' + Math.round(route.ascend) + 'm. ' + - I18n.t('javascripts.directions.descend') + ': ' + Math.round(route.descend) +'m.'; + var html = "
" + + I18n.t("javascripts.directions.distance") + ": " + formatDistance(route.distance) + ". " + + I18n.t("javascripts.directions.time") + ": " + formatTime(route.time) + "."; + if (typeof route.ascend !== "undefined" && typeof route.descend !== "undefined") { + html += "" + + I18n.t("javascripts.directions.ascend") + ": " + Math.round(route.ascend) + "m. " + + I18n.t("javascripts.directions.descend") + ": " + Math.round(route.descend) + "m."; } - html += '
" + instruction + "
' + - I18n.t('javascripts.directions.instructions.courtesy', {link: chosenEngine.creditline}) + - '
" + + I18n.t("javascripts.directions.instructions.courtesy", { link: chosenEngine.creditline }) + + "
') - .text(I18n.t('javascripts.map.layers.overlays')) + $("
") + .text(I18n.t("javascripts.map.layers.overlays")) .attr("class", "deemphasize") .appendTo(overlaySection); - var overlays = $('
') - .attr('class', 'deemphasize') - .text(I18n.t('javascripts.share.paste_html')) + $("
") + .attr("class", "deemphasize") + .text(I18n.t("javascripts.share.paste_html")) .appendTo($linkSection)); // Geo URI - var $geoUriSection = $('
') - .attr('class', 'deemphasize') - .html(I18n.t('javascripts.share.image_size') + ' x ') + $("
") + .attr("class", "deemphasize") + .html(I18n.t("javascripts.share.image_size") + " x ") .appendTo($form); - $('') - .attr('type', 'submit') - .attr('value', I18n.t('javascripts.share.download')) + $("") + .attr("type", "submit") + .attr("value", I18n.t("javascripts.share.download")) .appendTo($form); locationFilter - .on('change', update) + .on("change", update) .addTo(map); - marker.on('dragend', movedMarker); - map.on('move', movedMap); - map.on('moveend layeradd layerremove', update); + marker.on("dragend", movedMarker); + map.on("move", movedMap); + map.on("moveend layeradd layerremove", update); options.sidebar.addPane($ui); $ui - .on('hide', hidden); + .on("hide", hidden); function hidden() { map.removeLayer(marker); @@ -256,19 +256,19 @@ L.OSM.share = function (options) { e.stopPropagation(); e.preventDefault(); - $('#mapnik_scale').val(getScale()); + $("#mapnik_scale").val(getScale()); marker.setLatLng(map.getCenter()); update(); options.sidebar.togglePane($ui, button); - $('.leaflet-control .control-button').tooltip('hide'); + $(".leaflet-control .control-button").tooltip("hide"); } function toggleMarker() { - if ($(this).is(':checked')) { + if ($(this).is(":checked")) { marker.setLatLng(map.getCenter()); map.addLayer(marker); - map.options.scrollWheelZoom = map.options.doubleClickZoom = 'center'; + map.options.scrollWheelZoom = map.options.doubleClickZoom = "center"; } else { map.removeLayer(marker); map.options.scrollWheelZoom = map.options.doubleClickZoom = true; @@ -277,7 +277,7 @@ L.OSM.share = function (options) { } function toggleFilter() { - if ($(this).is(':checked')) { + if ($(this).is(":checked")) { locationFilter.setBounds(map.getBounds().pad(-0.2)); locationFilter.enable(); } else { @@ -293,27 +293,27 @@ L.OSM.share = function (options) { function movedMarker() { if (map.hasLayer(marker)) { - map.off('move', movedMap); - map.on('moveend', updateOnce); + map.off("move", movedMap); + map.on("moveend", updateOnce); map.panTo(marker.getLatLng()); } } function updateOnce() { - map.off('moveend', updateOnce); - map.on('move', movedMap); + map.off("moveend", updateOnce); + map.on("move", movedMap); update(); } function escapeHTML(string) { var htmlEscapes = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' + "&": "&", + "<": "<", + ">": ">", + "\"": """, + "'": "'" }; - return string === null ? '' : (string + '').replace(/[&<>"']/g, function(match) { + return string === null ? "" : String(string).replace(/[&<>"']/g, function (match) { return htmlEscapes[match]; }); } @@ -321,18 +321,18 @@ L.OSM.share = function (options) { function update() { var bounds = map.getBounds(); - $('#link_marker') - .prop('checked', map.hasLayer(marker)); + $("#link_marker") + .prop("checked", map.hasLayer(marker)); - $('#image_filter') - .prop('checked', locationFilter.isEnabled()); + $("#image_filter") + .prop("checked", locationFilter.isEnabled()); // Link / Embed - $('#short_input').val(map.getShortUrl(marker)); - $('#long_input').val(map.getUrl(marker)); - $('#short_link').attr('href', map.getShortUrl(marker)); - $('#long_link').attr('href', map.getUrl(marker)); + $("#short_input").val(map.getShortUrl(marker)); + $("#long_input").val(map.getUrl(marker)); + $("#short_link").attr("href", map.getShortUrl(marker)); + $("#long_link").attr("href", map.getUrl(marker)); var params = { bbox: bounds.toBBoxString(), @@ -341,20 +341,20 @@ L.OSM.share = function (options) { if (map.hasLayer(marker)) { var latLng = marker.getLatLng().wrap(); - params.marker = latLng.lat + ',' + latLng.lng; + params.marker = latLng.lat + "," + latLng.lng; } - $('#embed_html').val( - '' + - '' + - escapeHTML(I18n.t('javascripts.share.view_larger_map')) + ''); + $("#embed_html").val( + "" + + "" + + escapeHTML(I18n.t("javascripts.share.view_larger_map")) + ""); // Geo URI - $('#geo_uri') - .attr('href', map.getGeoUri(marker)) + $("#geo_uri") + .attr("href", map.getGeoUri(marker)) .html(map.getGeoUri(marker)); // Image @@ -368,10 +368,10 @@ L.OSM.share = function (options) { L.CRS.EPSG3857.project(bounds.getNorthEast())).getSize(), maxScale = Math.floor(Math.sqrt(size.x * size.y / 0.3136)); - $('#mapnik_minlon').val(bounds.getWest()); - $('#mapnik_minlat').val(bounds.getSouth()); - $('#mapnik_maxlon').val(bounds.getEast()); - $('#mapnik_maxlat').val(bounds.getNorth()); + $("#mapnik_minlon").val(bounds.getWest()); + $("#mapnik_minlat").val(bounds.getSouth()); + $("#mapnik_maxlon").val(bounds.getEast()); + $("#mapnik_maxlat").val(bounds.getNorth()); if (scale < maxScale) { scale = roundScale(maxScale); @@ -381,12 +381,12 @@ L.OSM.share = function (options) { $("#mapnik_image_width").text(Math.round(size.x / scale / 0.00028)); $("#mapnik_image_height").text(Math.round(size.y / scale / 0.00028)); - if (map.getMapBaseLayerId() === 'mapnik') { - $('#export-image').show(); - $('#export-warning').hide(); + if (map.getMapBaseLayerId() === "mapnik") { + $("#export-image").show(); + $("#export-warning").hide(); } else { - $('#export-image').hide(); - $('#export-warning').show(); + $("#export-image").hide(); + $("#export-warning").show(); } } diff --git a/app/assets/javascripts/leaflet.sidebar.js b/app/assets/javascripts/leaflet.sidebar.js index db9e7aef2..bb046f99a 100644 --- a/app/assets/javascripts/leaflet.sidebar.js +++ b/app/assets/javascripts/leaflet.sidebar.js @@ -1,8 +1,8 @@ -L.OSM.sidebar = function(selector) { +L.OSM.sidebar = function (selector) { var control = {}, sidebar = $(selector), current = $(), - currentButton = $(), + currentButton = $(), map; control.addTo = function (_) { @@ -10,19 +10,19 @@ L.OSM.sidebar = function(selector) { return control; }; - control.addPane = function(pane) { + control.addPane = function (pane) { pane .hide() .appendTo(sidebar); }; - control.togglePane = function(pane, button) { + control.togglePane = function (pane, button) { current .hide() - .trigger('hide'); + .trigger("hide"); currentButton - .removeClass('active'); + .removeClass("active"); if (current === pane) { $(sidebar).hide(); @@ -33,14 +33,14 @@ L.OSM.sidebar = function(selector) { currentButton = button || $(); } - map.invalidateSize({pan: false, animate: false}); + map.invalidateSize({ pan: false, animate: false }); current .show() - .trigger('show'); + .trigger("show"); currentButton - .addClass('active'); + .addClass("active"); }; return control; diff --git a/app/assets/javascripts/leaflet.zoom.js b/app/assets/javascripts/leaflet.zoom.js index 0ef0f64de..e7c048b2d 100644 --- a/app/assets/javascripts/leaflet.zoom.js +++ b/app/assets/javascripts/leaflet.zoom.js @@ -1,26 +1,26 @@ L.OSM.Zoom = L.Control.extend({ options: { - position: 'topright' + position: "topright" }, onAdd: function (map) { - var zoomName = 'zoom', - container = L.DomUtil.create('div', zoomName); + var zoomName = "zoom", + container = L.DomUtil.create("div", zoomName); this._map = map; - this._zoomInButton = this._createButton( - '', I18n.t('javascripts.map.zoom.in'), zoomName + 'in', container, this._zoomIn, this); + this._zoomInButton = this._createButton( + "", I18n.t("javascripts.map.zoom.in"), zoomName + "in", container, this._zoomIn, this); this._zoomOutButton = this._createButton( - '', I18n.t('javascripts.map.zoom.out'), zoomName + 'out', container, this._zoomOut, this); + "", I18n.t("javascripts.map.zoom.out"), zoomName + "out", container, this._zoomOut, this); - map.on('zoomend zoomlevelschange', this._updateDisabled, this); + map.on("zoomend zoomlevelschange", this._updateDisabled, this); return container; }, onRemove: function (map) { - map.off('zoomend zoomlevelschange', this._updateDisabled, this); + map.off("zoomend zoomlevelschange", this._updateDisabled, this); }, _zoomIn: function (e) { @@ -32,28 +32,28 @@ L.OSM.Zoom = L.Control.extend({ }, _createButton: function (html, title, className, container, fn, context) { - var link = L.DomUtil.create('a', 'control-button ' + className, container); + var link = L.DomUtil.create("a", "control-button " + className, container); link.innerHTML = html; - link.href = '#'; + link.href = "#"; link.title = title; - L.DomUtil.create('span', 'icon ' + className, link); + L.DomUtil.create("span", "icon " + className, link); var stop = L.DomEvent.stopPropagation; L.DomEvent - .on(link, 'click', stop) - .on(link, 'mousedown', stop) - .on(link, 'dblclick', stop) - .on(link, 'click', L.DomEvent.preventDefault) - .on(link, 'click', fn, context); + .on(link, "click", stop) + .on(link, "mousedown", stop) + .on(link, "dblclick", stop) + .on(link, "click", L.DomEvent.preventDefault) + .on(link, "click", fn, context); return link; }, _updateDisabled: function () { var map = this._map, - className = 'disabled'; + className = "disabled"; L.DomUtil.removeClass(this._zoomInButton, className); L.DomUtil.removeClass(this._zoomOutButton, className); diff --git a/app/assets/javascripts/login.js b/app/assets/javascripts/login.js index 3496587b4..853db34a9 100644 --- a/app/assets/javascripts/login.js +++ b/app/assets/javascripts/login.js @@ -1,4 +1,4 @@ -$(document).ready(function() { +$(document).ready(function () { // Preserve location hash in referer if (window.location.hash) { $("#referer").val($("#referer").val() + window.location.hash); @@ -12,7 +12,7 @@ $(document).ready(function() { }); // Add click handler to show OpenID field - $("#openid_open_url").click(function() { + $("#openid_open_url").click(function () { $("#openid_url").val("http://"); $("#login_auth_buttons").hide(); $("#login_openid_url").show(); @@ -24,7 +24,7 @@ $(document).ready(function() { $("#login_openid_submit").hide(); // Handle OpenID submission by redirecting to omniauth - $("#openid_login_form").submit(function() { + $("#openid_login_form").submit(function () { var action = $(this).prop("action"), openid_url = $(this).find("#openid_url").val(), referer = $(this).find("#openid_referer").val(), diff --git a/app/assets/javascripts/oauth.js b/app/assets/javascripts/oauth.js index 037e1d730..411f7fc34 100644 --- a/app/assets/javascripts/oauth.js +++ b/app/assets/javascripts/oauth.js @@ -4,7 +4,7 @@ $(document).ready(function () { var application_data = $("head").data(); function makeAbsolute(url) { - var a = document.createElement('a'); + var a = document.createElement("a"); a.href = url; return a.href; } @@ -17,7 +17,7 @@ $(document).ready(function () { token_secret: application_data.tokenSecret }); - $.ajaxPrefilter(function(options, jqxhr) { + $.ajaxPrefilter(function (options, jqxhr) { if (options.oauth) { options.headers = options.headers || {}; options.headers.Authorization = headerGenerator(options.type, makeAbsolute(options.url), jqxhr.data); diff --git a/app/assets/javascripts/piwik.js b/app/assets/javascripts/piwik.js index 19b5619a2..5353a99ac 100644 --- a/app/assets/javascripts/piwik.js +++ b/app/assets/javascripts/piwik.js @@ -9,14 +9,14 @@ if (OSM.PIWIK) { cache: true, success: function () { piwikTracker = Piwik.getTracker(base + "piwik.php", OSM.PIWIK.site); - + if (OSM.user) { piwikTracker.setUserId(OSM.user.toString()); } piwikTracker.trackPageView(); piwikTracker.enableLinkTracking(); - + $("meta[name=piwik-goal]").each(function () { piwikTracker.trackGoal($(this).attr("content")); }); diff --git a/app/assets/javascripts/richtext.js b/app/assets/javascripts/richtext.js index a5323bc07..ea2efcfad 100644 --- a/app/assets/javascripts/richtext.js +++ b/app/assets/javascripts/richtext.js @@ -2,12 +2,12 @@ $(document).ready(function () { /* Hide the preview panes */ $(".richtext_preview").hide(); - /* + /* * When the text in an edit pane is changed, clear the contents of * the associated preview pne so that it will be regenerated when * the user next switches to it. */ - $(".richtext_content textarea").change(function () { + $(".richtext_content textarea").change(function () { $(this).parents(".richtext_container").find(".richtext_preview").empty(); }); diff --git a/app/assets/javascripts/router.js b/app/assets/javascripts/router.js index 0f37e32f1..08a6c7268 100644 --- a/app/assets/javascripts/router.js +++ b/app/assets/javascripts/router.js @@ -46,32 +46,32 @@ `OSM.router.withoutMoveListener` to run a block of code that may update move the map without the hash changing. */ -OSM.Router = function(map, rts) { +OSM.Router = function (map, rts) { var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g; var optionalParam = /\((.*?)\)/g; var namedParam = /(\(\?)?:\w+/g; var splatParam = /\*\w+/g; function Route(path, controller) { - var regexp = new RegExp('^' + - path.replace(escapeRegExp, '\\$&') - .replace(optionalParam, '(?:$1)?') - .replace(namedParam, function(match, optional){ - return optional ? match : '([^\/]+)'; + var regexp = new RegExp("^" + + path.replace(escapeRegExp, "\\$&") + .replace(optionalParam, "(?:$1)?") + .replace(namedParam, function (match, optional) { + return optional ? match : "([^\/]+)"; }) - .replace(splatParam, '(.*?)') + '(?:\\?.*)?$'); + .replace(splatParam, "(.*?)") + "(?:\\?.*)?$"); var route = {}; - route.match = function(path) { + route.match = function (path) { return regexp.test(path); }; - route.run = function(action, path) { + route.run = function (action, path) { var params = []; if (path) { - params = regexp.exec(path).map(function(param, i) { + params = regexp.exec(path).map(function (param, i) { return (i > 0 && param) ? decodeURIComponent(param) : param; }); } @@ -85,45 +85,46 @@ OSM.Router = function(map, rts) { } var routes = []; - for (var r in rts) + for (var r in rts) { routes.push(new Route(r, rts[r])); + } - routes.recognize = function(path) { + routes.recognize = function (path) { for (var i = 0; i < this.length; i++) { if (this[i].match(path)) return this[i]; } }; - var currentPath = window.location.pathname.replace(/(.)\/$/, '$1') + window.location.search, + var currentPath = window.location.pathname.replace(/(.)\/$/, "$1") + window.location.search, currentRoute = routes.recognize(currentPath), currentHash = location.hash || OSM.formatHash(map); var router = {}; if (window.history && window.history.pushState) { - $(window).on('popstate', function(e) { + $(window).on("popstate", function (e) { if (!e.originalEvent.state) return; // Is it a real popstate event or just a hash change? var path = window.location.pathname + window.location.search, route = routes.recognize(path); if (path === currentPath) return; - currentRoute.run('unload', null, route === currentRoute); + currentRoute.run("unload", null, route === currentRoute); currentPath = path; currentRoute = route; - currentRoute.run('popstate', currentPath); - map.setState(e.originalEvent.state, {animate: false}); + currentRoute.run("popstate", currentPath); + map.setState(e.originalEvent.state, { animate: false }); }); router.route = function (url) { - var path = url.replace(/#.*/, ''), + var path = url.replace(/#.*/, ""), route = routes.recognize(path); if (!route) return false; - currentRoute.run('unload', null, route === currentRoute); + currentRoute.run("unload", null, route === currentRoute); var state = OSM.parseHash(url); map.setState(state); window.history.pushState(state, document.title, url); currentPath = path; currentRoute = route; - currentRoute.run('pushstate', currentPath); + currentRoute.run("pushstate", currentPath); return true; }; @@ -131,7 +132,7 @@ OSM.Router = function(map, rts) { window.history.replaceState(OSM.parseHash(url), document.title, url); }; - router.stateChange = function(state) { + router.stateChange = function (state) { if (state.center) { window.history.replaceState(state, document.title, OSM.formatHash(state)); } else { @@ -143,19 +144,19 @@ OSM.Router = function(map, rts) { window.location.assign(url); }; - router.stateChange = function(state) { + router.stateChange = function (state) { if (state.center) window.location.replace(OSM.formatHash(state)); }; } - router.updateHash = function() { + router.updateHash = function () { var hash = OSM.formatHash(map); if (hash === currentHash) return; currentHash = hash; router.stateChange(OSM.parseHash(hash)); }; - router.hashUpdated = function() { + router.hashUpdated = function () { var hash = location.hash; if (hash === currentHash) return; currentHash = hash; @@ -166,19 +167,19 @@ OSM.Router = function(map, rts) { router.withoutMoveListener = function (callback) { function disableMoveListener() { - map.off('moveend', router.updateHash); - map.once('moveend', function () { - map.on('moveend', router.updateHash); + map.off("moveend", router.updateHash); + map.once("moveend", function () { + map.on("moveend", router.updateHash); }); } - map.once('movestart', disableMoveListener); + map.once("movestart", disableMoveListener); callback(); - map.off('movestart', disableMoveListener); + map.off("movestart", disableMoveListener); }; - router.load = function() { - var loadState = currentRoute.run('load', currentPath); + router.load = function () { + var loadState = currentRoute.run("load", currentPath); router.stateChange(loadState || {}); }; @@ -187,8 +188,8 @@ OSM.Router = function(map, rts) { currentRoute = routes.recognize(currentPath); }; - map.on('moveend baselayerchange overlaylayerchange', router.updateHash); - $(window).on('hashchange', router.hashUpdated); + map.on("moveend baselayerchange overlaylayerchange", router.updateHash); + $(window).on("hashchange", router.hashUpdated); return router; }; diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index bdf044305..69cc259f0 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -7,30 +7,30 @@ $(document).ready(function () { zoomControl: false }).addLayer(new L.OSM.Mapnik()); - var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright'; + var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright"; - L.OSM.zoom({position: position}) + L.OSM.zoom({ position: position }) .addTo(map); var locate = L.control.locate({ position: position, - icon: 'icon geolocate', - iconLoading: 'icon geolocate', + icon: "icon geolocate", + iconLoading: "icon geolocate", strings: { - title: I18n.t('javascripts.map.locate.title'), - popup: I18n.t('javascripts.map.locate.popup') + title: I18n.t("javascripts.map.locate.title"), + popup: I18n.t("javascripts.map.locate.popup") } }).addTo(map); var locateContainer = locate.getContainer(); $(locateContainer) - .removeClass('leaflet-control-locate leaflet-bar') - .addClass('control-locate') + .removeClass("leaflet-control-locate leaflet-bar") + .addClass("control-locate") .children("a") - .attr('href', '#') - .removeClass('leaflet-bar-part leaflet-bar-part-single') - .addClass('control-button'); + .attr("href", "#") + .removeClass("leaflet-bar-part leaflet-bar-part-single") + .addClass("control-button"); if (OSM.home) { map.setView([OSM.home.lat, OSM.home.lon], 12); @@ -39,7 +39,7 @@ $(document).ready(function () { } if ($("#map").hasClass("set_location")) { - var marker = L.marker([0, 0], {icon: OSM.getUserIcon()}); + var marker = L.marker([0, 0], { icon: OSM.getUserIcon() }); if (OSM.home) { marker.setLatLng([OSM.home.lat, OSM.home.lon]); @@ -47,14 +47,14 @@ $(document).ready(function () { } map.on("click", function (e) { - if ($('#updatehome').is(':checked')) { + if ($("#updatehome").is(":checked")) { var zoom = map.getZoom(), precision = OSM.zoomPrecision(zoom), location = e.latlng.wrap(); - $('#homerow').removeClass(); - $('#home_lat').val(location.lat.toFixed(precision)); - $('#home_lon').val(location.lng.toFixed(precision)); + $("#homerow").removeClass(); + $("#home_lat").val(location.lat.toFixed(precision)); + $("#home_lon").val(location.lng.toFixed(precision)); marker.setLatLng(e.latlng); marker.addTo(map); @@ -62,9 +62,9 @@ $(document).ready(function () { }); } else { $("[data-user]").each(function () { - var user = $(this).data('user'); + var user = $(this).data("user"); if (user.lon && user.lat) { - L.marker([user.lat, user.lon], {icon: OSM.getUserIcon(user.icon)}).addTo(map) + L.marker([user.lat, user.lon], { icon: OSM.getUserIcon(user.icon) }).addTo(map) .bindPopup(user.description); } }); @@ -124,4 +124,12 @@ $(document).ready(function () { $("#contributorTerms").html(""); $("#contributorTerms").load(url); }); + + $("#read_ct").on("click", function () { + $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_tou").prop("checked"))); + }); + + $("#read_tou").on("click", function () { + $("#continue").prop("disabled", !($(this).prop("checked") && $("#read_ct").prop("checked"))); + }); }); diff --git a/app/assets/javascripts/welcome.js b/app/assets/javascripts/welcome.js index 5ba0d7cd2..35a1fdc4b 100644 --- a/app/assets/javascripts/welcome.js +++ b/app/assets/javascripts/welcome.js @@ -1,4 +1,4 @@ -$(document).ready(function() { +$(document).ready(function () { var params = OSM.params(); if (params.lat && params.lon) { @@ -6,28 +6,27 @@ $(document).ready(function() { params.lon = parseFloat(params.lon); params.zoom = params.zoom || 17; - var url = '/edit'; + var url = "/edit"; if (params.editor) { - url += '?editor=' + params.editor; + url += "?editor=" + params.editor; } url += OSM.formatHash(params); - $('.start-mapping').attr('href', url); - + $(".start-mapping").attr("href", url); } else { var geoSuccess = function (position) { - window.location = '/edit' + OSM.formatHash({ + window.location = "/edit" + OSM.formatHash({ zoom: 17, lat: position.coords.latitude, lon: position.coords.longitude }); }; - $('.start-mapping').on('click', function(e) { + $(".start-mapping").on("click", function (e) { e.preventDefault(); - $('.start-mapping').addClass('loading'); + $(".start-mapping").addClass("loading"); if (navigator.geolocation) { // handle firefox's weird implementation @@ -42,6 +41,6 @@ $(document).ready(function() { } function manualEdit() { - window.location = '/?edit_help=1'; + window.location = "/?edit_help=1"; } }); diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 71df217b3..d3488fe73 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -1664,10 +1664,18 @@ tr.turn:hover { .diary_post { position: relative; - margin-top: $lineheight/2; padding-top: $lineheight; + padding-bottom: $lineheight/2; border-top: 1px solid #ccc; + &:first-of-type { + margin-top: $lineheight/2; + } + + &.deemphasize { + background-color: #fee; + } + .post_heading { margin-bottom: $lineheight; @@ -1712,14 +1720,17 @@ tr.turn:hover { max-width: 740px; } .diary-comment { - margin-top: $lineheight/2; border-top: 1px dashed #ccc; padding-top: $lineheight/2; + padding-bottom: $lineheight/2; &:first-child { - margin-top: $lineheight; + margin-top: $lineheight/2; padding-top: $lineheight; border-top: 1px solid #ccc; } + &.deemphasize { + background-color: #fee; + } p { margin-bottom: $lineheight/2; } diff --git a/app/controllers/api/amf_controller.rb b/app/controllers/api/amf_controller.rb index 0cf511d76..0f368c3dc 100644 --- a/app/controllers/api/amf_controller.rb +++ b/app/controllers/api/amf_controller.rb @@ -114,18 +114,18 @@ module Api def amf_handle_error(call, rootobj, rootid) yield - rescue OSM::APIAlreadyDeletedError => ex - [-4, ex.object, ex.object_id] - rescue OSM::APIVersionMismatchError => ex - [-3, [rootobj, rootid], [ex.type.downcase, ex.id, ex.latest]] - rescue OSM::APIUserChangesetMismatchError => ex - [-2, ex.to_s] - rescue OSM::APIBadBoundingBox => ex - [-2, "Sorry - I can't get the map for that area. The server said: #{ex}"] - rescue OSM::APIError => ex - [-1, ex.to_s] - rescue StandardError => ex - [-2, "An unusual error happened (in #{call}). The server said: #{ex}"] + rescue OSM::APIAlreadyDeletedError => e + [-4, e.object, e.object_id] + rescue OSM::APIVersionMismatchError => e + [-3, [rootobj, rootid], [e.type.downcase, e.id, e.latest]] + rescue OSM::APIUserChangesetMismatchError => e + [-2, e.to_s] + rescue OSM::APIBadBoundingBox => e + [-2, "Sorry - I can't get the map for that area. The server said: #{e}"] + rescue OSM::APIError => e + [-1, e.to_s] + rescue StandardError => e + [-2, "An unusual error happened (in #{call}). The server said: #{e}"] end def amf_handle_error_with_timeout(call, rootobj, rootid) diff --git a/app/controllers/api/changesets_controller.rb b/app/controllers/api/changesets_controller.rb index fb6523f4e..ffd9a112b 100644 --- a/app/controllers/api/changesets_controller.rb +++ b/app/controllers/api/changesets_controller.rb @@ -364,10 +364,10 @@ module Api end # stupid Time seems to throw both of these for bad parsing, so # we have to catch both and ensure the correct code path is taken. - rescue ArgumentError => ex - raise OSM::APIBadUserInput, ex.message.to_s - rescue RuntimeError => ex - raise OSM::APIBadUserInput, ex.message.to_s + rescue ArgumentError => e + raise OSM::APIBadUserInput, e.message.to_s + rescue RuntimeError => e + raise OSM::APIBadUserInput, e.message.to_s end ## diff --git a/app/controllers/api/map_controller.rb b/app/controllers/api/map_controller.rb index 27d6f3667..e1d1a3b37 100644 --- a/app/controllers/api/map_controller.rb +++ b/app/controllers/api/map_controller.rb @@ -22,8 +22,8 @@ module Api bbox = BoundingBox.from_bbox_params(params) bbox.check_boundaries bbox.check_size - rescue StandardError => err - report_error(err.message) + rescue StandardError => e + report_error(e.message) return end diff --git a/app/controllers/api/tracepoints_controller.rb b/app/controllers/api/tracepoints_controller.rb index b22bcfaea..5fbece05b 100644 --- a/app/controllers/api/tracepoints_controller.rb +++ b/app/controllers/api/tracepoints_controller.rb @@ -25,8 +25,8 @@ module Api bbox = BoundingBox.from_bbox_params(params) bbox.check_boundaries bbox.check_size - rescue StandardError => err - report_error(err.message) + rescue StandardError => e + report_error(e.message) return end diff --git a/app/controllers/api/traces_controller.rb b/app/controllers/api/traces_controller.rb index 5e95892e1..86f1370f6 100644 --- a/app/controllers/api/traces_controller.rb +++ b/app/controllers/api/traces_controller.rb @@ -8,14 +8,14 @@ module Api authorize_resource - before_action :check_database_readable, :except => [:api_read, :api_data] - before_action :check_database_writable, :only => [:api_create, :api_update, :api_delete] - before_action :check_api_readable, :only => [:api_read, :api_data] - before_action :check_api_writable, :only => [:api_create, :api_update, :api_delete] - before_action :offline_redirect, :only => [:api_create, :api_delete, :api_data] + before_action :check_database_readable, :except => [:show, :data] + before_action :check_database_writable, :only => [:create, :update, :destroy] + before_action :check_api_readable, :only => [:show, :data] + before_action :check_api_writable, :only => [:create, :update, :destroy] + before_action :offline_redirect, :only => [:create, :destroy, :data] around_action :api_call_handle_error - def api_read + def show trace = Trace.visible.find(params[:id]) if trace.public? || trace.user == current_user @@ -25,7 +25,7 @@ module Api end end - def api_update + def update trace = Trace.visible.find(params[:id]) if trace.user == current_user @@ -38,7 +38,7 @@ module Api end end - def api_delete + def destroy trace = Trace.visible.find(params[:id]) if trace.user == current_user @@ -52,7 +52,7 @@ module Api end end - def api_data + def data trace = Trace.visible.find(params[:id]) if trace.public? || trace.user == current_user @@ -68,7 +68,7 @@ module Api end end - def api_create + def create tags = params[:tags] || "" description = params[:description] || "" visibility = params[:visibility] @@ -85,7 +85,7 @@ module Api trace = do_create(params[:file], tags, description, visibility) if trace.id - TraceImporterJob.perform_later(@trace) if Settings.trace_use_job_queue + TraceImporterJob.perform_later(trace) if Settings.trace_use_job_queue render :plain => trace.id.to_s elsif trace.valid? head :internal_server_error diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index f24d50cf1..3180cabcc 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -2,29 +2,29 @@ module Api class UsersController < ApiController layout "site", :except => [:api_details] - before_action :disable_terms_redirect, :only => [:api_details] - before_action :authorize, :only => [:api_details, :api_gpx_files] + before_action :disable_terms_redirect, :only => [:details] + before_action :authorize, :only => [:details, :gpx_files] authorize_resource before_action :check_api_readable around_action :api_call_handle_error - before_action :lookup_user_by_id, :only => [:api_read] + before_action :lookup_user_by_id, :only => [:show] - def api_read + def show if @user.visible? - render :action => :api_read, :content_type => "text/xml" + render :action => :show, :content_type => "text/xml" else head :gone end end - def api_details + def details @user = current_user - render :action => :api_read, :content_type => "text/xml" + render :action => :show, :content_type => "text/xml" end - def api_users + def index raise OSM::APIBadUserInput, "The parameter users is required, and must be of the form users=id[,id[,id...]]" unless params["users"] ids = params["users"].split(",").collect(&:to_i) @@ -33,10 +33,10 @@ module Api @users = User.visible.find(ids) - render :action => :api_users, :content_type => "text/xml" + render :action => :index, :content_type => "text/xml" end - def api_gpx_files + def gpx_files doc = OSM::API.new.get_xml_doc current_user.traces.reload.each do |trace| doc.root << trace.to_xml_node diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c880e6add..bee5e8169 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,8 +37,8 @@ class ApplicationController < ActionController::Base elsif session[:token] session[:user] = current_user.id if self.current_user = User.authenticate(:token => session[:token]) end - rescue StandardError => ex - logger.info("Exception authorizing user: #{ex}") + rescue StandardError => e + logger.info("Exception authorizing user: #{e}") reset_session self.current_user = nil end @@ -185,22 +185,22 @@ class ApplicationController < ActionController::Base def api_call_handle_error yield - rescue ActiveRecord::RecordNotFound => ex + rescue ActiveRecord::RecordNotFound => e head :not_found - rescue LibXML::XML::Error, ArgumentError => ex - report_error ex.message, :bad_request - rescue ActiveRecord::RecordInvalid => ex - message = "#{ex.record.class} #{ex.record.id}: " - ex.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{ex.record[attr].inspect})" } + rescue LibXML::XML::Error, ArgumentError => e + report_error e.message, :bad_request + rescue ActiveRecord::RecordInvalid => e + message = "#{e.record.class} #{e.record.id}: " + e.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{e.record[attr].inspect})" } report_error message, :bad_request - rescue OSM::APIError => ex - report_error ex.message, ex.status - rescue AbstractController::ActionNotFound => ex + rescue OSM::APIError => e + report_error e.message, e.status + rescue AbstractController::ActionNotFound => e raise - rescue StandardError => ex - logger.info("API threw unexpected #{ex.class} exception: #{ex.message}") - ex.backtrace.each { |l| logger.info(l) } - report_error "#{ex.class}: #{ex.message}", :internal_server_error + rescue StandardError => e + logger.info("API threw unexpected #{e.class} exception: #{e.message}") + e.backtrace.each { |l| logger.info(l) } + report_error "#{e.class}: #{e.message}", :internal_server_error end ## @@ -227,11 +227,11 @@ class ApplicationController < ActionController::Base OSM::Timer.timeout(Settings.web_timeout, Timeout::Error) do yield end - rescue ActionView::Template::Error => ex - ex = ex.cause + rescue ActionView::Template::Error => e + e = e.cause - if ex.is_a?(Timeout::Error) || - (ex.is_a?(ActiveRecord::StatementInvalid) && ex.message =~ /execution expired/) + if e.is_a?(Timeout::Error) || + (e.is_a?(ActiveRecord::StatementInvalid) && e.message =~ /execution expired/) render :action => "timeout" else raise diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index fb1e7b702..f827bac3f 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -8,38 +8,40 @@ class DiaryEntriesController < ApplicationController authorize_resource before_action :lookup_user, :only => [:show, :comments] - before_action :check_database_writable, :only => [:new, :edit, :comment, :hide, :hidecomment, :subscribe, :unsubscribe] - before_action :allow_thirdparty_images, :only => [:new, :edit, :index, :show, :comments] + before_action :check_database_writable, :only => [:new, :create, :edit, :update, :comment, :hide, :hidecomment, :subscribe, :unsubscribe] + before_action :allow_thirdparty_images, :only => [:new, :create, :edit, :update, :index, :show, :comments] def new @title = t "diary_entries.new.title" - if request.post? - @diary_entry = DiaryEntry.new(entry_params) - @diary_entry.user = current_user + default_lang = current_user.preferences.where(:k => "diary.default_language").first + lang_code = default_lang ? default_lang.v : current_user.preferred_language + @diary_entry = DiaryEntry.new(entry_params.merge(:language_code => lang_code)) + set_map_location + render :action => "new" + end - if @diary_entry.save - default_lang = current_user.preferences.where(:k => "diary.default_language").first - if default_lang - default_lang.v = @diary_entry.language_code - default_lang.save! - else - current_user.preferences.create(:k => "diary.default_language", :v => @diary_entry.language_code) - end + def create + @title = t "diary_entries.new.title" - # Subscribe user to diary comments - @diary_entry.subscriptions.create(:user => current_user) + @diary_entry = DiaryEntry.new(entry_params) + @diary_entry.user = current_user - redirect_to :action => "index", :display_name => current_user.display_name + if @diary_entry.save + default_lang = current_user.preferences.where(:k => "diary.default_language").first + if default_lang + default_lang.v = @diary_entry.language_code + default_lang.save! else - render :action => "edit" + current_user.preferences.create(:k => "diary.default_language", :v => @diary_entry.language_code) end + + # Subscribe user to diary comments + @diary_entry.subscriptions.create(:user => current_user) + + redirect_to :action => "index", :display_name => current_user.display_name else - default_lang = current_user.preferences.where(:k => "diary.default_language").first - lang_code = default_lang ? default_lang.v : current_user.preferred_language - @diary_entry = DiaryEntry.new(entry_params.merge(:language_code => lang_code)) - set_map_location - render :action => "edit" + render :action => "new" end end @@ -47,19 +49,32 @@ class DiaryEntriesController < ApplicationController @title = t "diary_entries.edit.title" @diary_entry = DiaryEntry.find(params[:id]) + redirect_to diary_entry_path(@diary_entry.user, @diary_entry) if current_user != @diary_entry.user + + set_map_location + rescue ActiveRecord::RecordNotFound + render :action => "no_such_entry", :status => :not_found + end + + def update + @title = t "diary_entries.edit.title" + @diary_entry = DiaryEntry.find(params[:id]) + if current_user != @diary_entry.user redirect_to diary_entry_path(@diary_entry.user, @diary_entry) elsif params[:diary_entry] && @diary_entry.update(entry_params) redirect_to diary_entry_path(@diary_entry.user, @diary_entry) + else + set_map_location + render :action => "edit" end - - set_map_location rescue ActiveRecord::RecordNotFound render :action => "no_such_entry", :status => :not_found end def comment @entry = DiaryEntry.find(params[:id]) + @comments = @entry.visible_comments @diary_comment = @entry.comments.build(comment_params) @diary_comment.user = current_user if @diary_comment.save @@ -143,7 +158,7 @@ class DiaryEntriesController < ApplicationController @page = (params[:page] || 1).to_i @page_size = 20 - @entries = @entries.visible + @entries = @entries.visible unless current_user&.administrator? @entries = @entries.order("created_at DESC") @entries = @entries.offset((@page - 1) * @page_size) @entries = @entries.limit(@page_size) @@ -166,6 +181,10 @@ class DiaryEntriesController < ApplicationController else @entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] }) + # Items can't be flagged as deleted in the RSS format. + # For the general feeds, allow a delay before publishing, to help spam fighting + @entries = @entries.where("created_at < :time", :time => Settings.diary_feed_delay.hours.ago) + if params[:language] @entries = @entries.where(:language_code => params[:language]) @title = t("diary_entries.feed.language.title", :language_name => Language.find(params[:language]).english_name) @@ -177,7 +196,6 @@ class DiaryEntriesController < ApplicationController @link = url_for :action => "index", :host => Settings.server_url, :protocol => Settings.server_protocol end end - @entries = @entries.visible.includes(:user).order("created_at DESC").limit(20) end @@ -185,6 +203,7 @@ class DiaryEntriesController < ApplicationController @entry = @user.diary_entries.visible.where(:id => params[:id]).first if @entry @title = t "diary_entries.show.title", :user => params[:display_name], :title => @entry.title + @comments = current_user&.administrator? ? @entry.comments : @entry.visible_comments else @title = t "diary_entries.no_such_entry.title", :id => params[:id] render :action => "no_such_entry", :status => :not_found @@ -197,12 +216,24 @@ class DiaryEntriesController < ApplicationController redirect_to :action => "index", :display_name => entry.user.display_name end + def unhide + entry = DiaryEntry.find(params[:id]) + entry.update(:visible => true) + redirect_to :action => "index", :display_name => entry.user.display_name + end + def hidecomment comment = DiaryComment.find(params[:comment]) comment.update(:visible => false) redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry) end + def unhidecomment + comment = DiaryComment.find(params[:comment]) + comment.update(:visible => true) + redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry) + end + def comments @comment_pages, @comments = paginate(:diary_comments, :conditions => { diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 4a8f77650..d1af43a72 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -98,8 +98,8 @@ class GeocoderController < ApplicationController end render :action => "results" - rescue StandardError => ex - @error = "Error contacting geocoder.ca: #{ex}" + rescue StandardError => e + @error = "Error contacting geocoder.ca: #{e}" render :action => "error" end @@ -166,8 +166,8 @@ class GeocoderController < ApplicationController end render :action => "results" - rescue StandardError => ex - @error = "Error contacting nominatim.openstreetmap.org: #{ex}" + rescue StandardError => e + @error = "Error contacting nominatim.openstreetmap.org: #{e}" render :action => "error" end @@ -198,8 +198,8 @@ class GeocoderController < ApplicationController end render :action => "results" - rescue StandardError => ex - @error = "Error contacting api.geonames.org: #{ex}" + rescue StandardError => e + @error = "Error contacting api.geonames.org: #{e}" render :action => "error" end @@ -230,8 +230,8 @@ class GeocoderController < ApplicationController end render :action => "results" - rescue StandardError => ex - @error = "Error contacting nominatim.openstreetmap.org: #{ex}" + rescue StandardError => e + @error = "Error contacting nominatim.openstreetmap.org: #{e}" render :action => "error" end @@ -261,8 +261,8 @@ class GeocoderController < ApplicationController end render :action => "results" - rescue StandardError => ex - @error = "Error contacting api.geonames.org: #{ex}" + rescue StandardError => e + @error = "Error contacting api.geonames.org: #{e}" render :action => "error" end diff --git a/app/controllers/traces_controller.rb b/app/controllers/traces_controller.rb index 334aa2aa6..3497e92d5 100644 --- a/app/controllers/traces_controller.rb +++ b/app/controllers/traces_controller.rb @@ -113,8 +113,8 @@ class TracesController < ApplicationController begin @trace = do_create(params[:trace][:gpx_file], params[:trace][:tagstring], params[:trace][:description], params[:trace][:visibility]) - rescue StandardError => ex - logger.debug ex + rescue StandardError => e + logger.debug e end if @trace.id diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9b97fa0a1..e41330c4b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -36,7 +36,7 @@ class UsersController < ApplicationController def save @title = t "users.new.title" - if params[:decline] + if params[:decline] || !(params[:read_tou] && params[:read_ct]) if current_user current_user.terms_seen = true @@ -47,12 +47,15 @@ class UsersController < ApplicationController else redirect_to :action => :account, :display_name => current_user.display_name end - else + elsif params[:decline] redirect_to t("users.terms.declined") + else + redirect_to :action => :terms end elsif current_user unless current_user.terms_agreed? current_user.consider_pd = params[:user][:consider_pd] + current_user.tou_agreed = Time.now.getutc current_user.terms_agreed = Time.now.getutc current_user.terms_seen = true @@ -73,6 +76,7 @@ class UsersController < ApplicationController current_user.creation_ip = request.remote_ip current_user.languages = http_accept_language.user_preferred_languages current_user.terms_agreed = Time.now.getutc + current_user.tou_agreed = Time.now.getutc current_user.terms_seen = true if current_user.auth_uid.blank? diff --git a/app/helpers/user_blocks_helper.rb b/app/helpers/user_blocks_helper.rb index 668eeb0e5..ed9997f6d 100644 --- a/app/helpers/user_blocks_helper.rb +++ b/app/helpers/user_blocks_helper.rb @@ -22,4 +22,19 @@ module UserBlocksHelper I18n.t("user_blocks.helper.time_past", :time => friendly_date(last_time)).html_safe end end + + def block_duration_in_words(duration) + parts = ActiveSupport::Duration.build(duration).parts + if duration < 1.day + I18n.t("user_blocks.helper.block_duration.hours", :count => parts[:hours]) + elsif duration < 1.week + I18n.t("user_blocks.helper.block_duration.days", :count => parts[:days]) + elsif duration < 1.month + I18n.t("user_blocks.helper.block_duration.weeks", :count => parts[:weeks]) + elsif duration < 1.year + I18n.t("user_blocks.helper.block_duration.months", :count => parts[:months]) + else + I18n.t("user_blocks.helper.block_duration.years", :count => parts[:years]) + end + end end diff --git a/app/jobs/trace_importer_job.rb b/app/jobs/trace_importer_job.rb index 6b8943aa2..e4395bf3d 100644 --- a/app/jobs/trace_importer_job.rb +++ b/app/jobs/trace_importer_job.rb @@ -10,10 +10,10 @@ class TraceImporterJob < ApplicationJob Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver_later trace.destroy end - rescue StandardError => ex - logger.info ex.to_s - ex.backtrace.each { |l| logger.info l } - Notifier.gpx_failure(trace, ex.to_s + "\n" + ex.backtrace.join("\n")).deliver_later + rescue StandardError => e + logger.info e.to_s + e.backtrace.each { |l| logger.info l } + Notifier.gpx_failure(trace, e.to_s + "\n" + e.backtrace.join("\n")).deliver_later trace.destroy end end diff --git a/app/models/acl.rb b/app/models/acl.rb index 095bad89b..cf83e673c 100644 --- a/app/models/acl.rb +++ b/app/models/acl.rb @@ -2,7 +2,7 @@ # # Table name: acls # -# id :integer not null, primary key +# id :bigint(8) not null, primary key # address :inet # k :string not null # v :string @@ -10,7 +10,9 @@ # # Indexes # -# acls_k_idx (k) +# acls_k_idx (k) +# index_acls_on_address (address) USING gist +# index_acls_on_domain (domain) # class Acl < ActiveRecord::Base diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 3ca719f6c..d57086a8e 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -2,8 +2,8 @@ # # Table name: changesets # -# id :integer not null, primary key -# user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null # created_at :datetime not null # min_lat :integer # max_lat :integer @@ -14,7 +14,7 @@ # # Indexes # -# changesets_bbox_idx (min_lat,max_lat,min_lon,max_lon) +# changesets_bbox_idx (min_lat,max_lat,min_lon,max_lon) USING gist # changesets_closed_at_idx (closed_at) # changesets_created_at_idx (created_at) # changesets_user_id_created_at_idx (user_id,created_at) @@ -88,8 +88,8 @@ class Changeset < ActiveRecord::Base return Changeset.from_xml_node(pt, create) end raise OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.") - rescue LibXML::XML::Error, ArgumentError => ex - raise OSM::APIBadXMLError.new("changeset", xml, ex.message) + rescue LibXML::XML::Error, ArgumentError => e + raise OSM::APIBadXMLError.new("changeset", xml, e.message) end def self.from_xml_node(pt, create = false) diff --git a/app/models/changeset_comment.rb b/app/models/changeset_comment.rb index a0ad6f2ea..529641c7e 100644 --- a/app/models/changeset_comment.rb +++ b/app/models/changeset_comment.rb @@ -3,8 +3,8 @@ # Table name: changeset_comments # # id :integer not null, primary key -# changeset_id :integer not null -# author_id :integer not null +# changeset_id :bigint(8) not null +# author_id :bigint(8) not null # body :text not null # created_at :datetime not null # visible :boolean not null diff --git a/app/models/changeset_tag.rb b/app/models/changeset_tag.rb index 942fafb2a..751029e03 100644 --- a/app/models/changeset_tag.rb +++ b/app/models/changeset_tag.rb @@ -2,7 +2,7 @@ # # Table name: changeset_tags # -# changeset_id :integer not null, primary key +# changeset_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/models/diary_comment.rb b/app/models/diary_comment.rb index ade7a64ea..4ae21be88 100644 --- a/app/models/diary_comment.rb +++ b/app/models/diary_comment.rb @@ -2,9 +2,9 @@ # # Table name: diary_comments # -# id :integer not null, primary key -# diary_entry_id :integer not null -# user_id :integer not null +# id :bigint(8) not null, primary key +# diary_entry_id :bigint(8) not null +# user_id :bigint(8) not null # body :text not null # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/diary_entry.rb b/app/models/diary_entry.rb index d61241993..4affe8b59 100644 --- a/app/models/diary_entry.rb +++ b/app/models/diary_entry.rb @@ -2,8 +2,8 @@ # # Table name: diary_entries # -# id :integer not null, primary key -# user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null # title :string not null # body :text not null # created_at :datetime not null diff --git a/app/models/diary_entry_subscription.rb b/app/models/diary_entry_subscription.rb index 6d24c4598..6e9a103ad 100644 --- a/app/models/diary_entry_subscription.rb +++ b/app/models/diary_entry_subscription.rb @@ -2,8 +2,8 @@ # # Table name: diary_entry_subscriptions # -# user_id :integer not null, primary key -# diary_entry_id :integer not null, primary key +# user_id :bigint(8) not null, primary key +# diary_entry_id :bigint(8) not null, primary key # # Indexes # diff --git a/app/models/friend.rb b/app/models/friend.rb index 86da87b93..615da1076 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -2,9 +2,9 @@ # # Table name: friends # -# id :integer not null, primary key -# user_id :integer not null -# friend_user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null +# friend_user_id :bigint(8) not null # # Indexes # diff --git a/app/models/message.rb b/app/models/message.rb index e3a3ec921..4ab129e91 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -2,13 +2,13 @@ # # Table name: messages # -# id :integer not null, primary key -# from_user_id :integer not null +# id :bigint(8) not null, primary key +# from_user_id :bigint(8) not null # title :string not null # body :text not null # sent_on :datetime not null # message_read :boolean default(FALSE), not null -# to_user_id :integer not null +# to_user_id :bigint(8) not null # to_user_visible :boolean default(TRUE), not null # from_user_visible :boolean default(TRUE), not null # body_format :enum default("markdown"), not null diff --git a/app/models/node.rb b/app/models/node.rb index 989cdee5c..91a1dbc41 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -2,14 +2,14 @@ # # Table name: current_nodes # -# id :integer not null, primary key +# id :bigint(8) not null, primary key # latitude :integer not null # longitude :integer not null -# changeset_id :integer not null +# changeset_id :bigint(8) not null # visible :boolean not null # timestamp :datetime not null -# tile :integer not null -# version :integer not null +# tile :bigint(8) not null +# version :bigint(8) not null # # Indexes # @@ -79,8 +79,8 @@ class Node < ActiveRecord::Base return Node.from_xml_node(pt, create) end raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.") - rescue LibXML::XML::Error, ArgumentError => ex - raise OSM::APIBadXMLError.new("node", xml, ex.message) + rescue LibXML::XML::Error, ArgumentError => e + raise OSM::APIBadXMLError.new("node", xml, e.message) end def self.from_xml_node(pt, create = false) diff --git a/app/models/node_tag.rb b/app/models/node_tag.rb index 43915bc12..86404599b 100644 --- a/app/models/node_tag.rb +++ b/app/models/node_tag.rb @@ -2,7 +2,7 @@ # # Table name: current_node_tags # -# node_id :integer not null, primary key +# node_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/models/note.rb b/app/models/note.rb index d96addbe7..d4f9a801f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -2,10 +2,10 @@ # # Table name: notes # -# id :integer not null, primary key +# id :bigint(8) not null, primary key # latitude :integer not null # longitude :integer not null -# tile :integer not null +# tile :bigint(8) not null # updated_at :datetime not null # created_at :datetime not null # status :enum not null diff --git a/app/models/note_comment.rb b/app/models/note_comment.rb index f94032e1e..388f890a6 100644 --- a/app/models/note_comment.rb +++ b/app/models/note_comment.rb @@ -2,18 +2,18 @@ # # Table name: note_comments # -# id :integer not null, primary key -# note_id :integer not null +# id :bigint(8) not null, primary key +# note_id :bigint(8) not null # visible :boolean not null # created_at :datetime not null # author_ip :inet -# author_id :integer +# author_id :bigint(8) # body :text # event :enum # # Indexes # -# index_note_comments_on_body (to_tsvector('english'::regconfig, body)) +# index_note_comments_on_body (to_tsvector('english'::regconfig, body)) USING gin # index_note_comments_on_created_at (created_at) # note_comments_note_id_idx (note_id) # diff --git a/app/models/old_node.rb b/app/models/old_node.rb index 9690dc46c..cc2327d08 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -2,14 +2,14 @@ # # Table name: nodes # -# node_id :integer not null, primary key +# node_id :bigint(8) not null, primary key # latitude :integer not null # longitude :integer not null -# changeset_id :integer not null +# changeset_id :bigint(8) not null # visible :boolean not null # timestamp :datetime not null -# tile :integer not null -# version :integer not null, primary key +# tile :bigint(8) not null +# version :bigint(8) not null, primary key # redaction_id :integer # # Indexes diff --git a/app/models/old_node_tag.rb b/app/models/old_node_tag.rb index 77b78751b..a3e1c3aaf 100644 --- a/app/models/old_node_tag.rb +++ b/app/models/old_node_tag.rb @@ -2,8 +2,8 @@ # # Table name: node_tags # -# node_id :integer not null, primary key -# version :integer not null, primary key +# node_id :bigint(8) not null, primary key +# version :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 3470561ce..109f7d968 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -2,10 +2,10 @@ # # Table name: relations # -# relation_id :integer default(0), not null, primary key -# changeset_id :integer not null +# relation_id :bigint(8) default(0), not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null -# version :integer not null, primary key +# version :bigint(8) not null, primary key # visible :boolean default(TRUE), not null # redaction_id :integer # diff --git a/app/models/old_relation_member.rb b/app/models/old_relation_member.rb index a74637435..f8d4a359f 100644 --- a/app/models/old_relation_member.rb +++ b/app/models/old_relation_member.rb @@ -2,11 +2,11 @@ # # Table name: relation_members # -# relation_id :integer default(0), not null, primary key +# relation_id :bigint(8) default(0), not null, primary key # member_type :enum not null -# member_id :integer not null +# member_id :bigint(8) not null # member_role :string not null -# version :integer default(0), not null, primary key +# version :bigint(8) default(0), not null, primary key # sequence_id :integer default(0), not null, primary key # # Indexes diff --git a/app/models/old_relation_tag.rb b/app/models/old_relation_tag.rb index 4a247949c..c674f708b 100644 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@ -2,10 +2,10 @@ # # Table name: relation_tags # -# relation_id :integer default(0), not null, primary key +# relation_id :bigint(8) default(0), not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null -# version :integer not null, primary key +# version :bigint(8) not null, primary key # # Foreign Keys # diff --git a/app/models/old_way.rb b/app/models/old_way.rb index baca05d33..31e230c38 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -2,10 +2,10 @@ # # Table name: ways # -# way_id :integer default(0), not null, primary key -# changeset_id :integer not null +# way_id :bigint(8) default(0), not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null -# version :integer not null, primary key +# version :bigint(8) not null, primary key # visible :boolean default(TRUE), not null # redaction_id :integer # diff --git a/app/models/old_way_node.rb b/app/models/old_way_node.rb index e1627d3fa..836e76e47 100644 --- a/app/models/old_way_node.rb +++ b/app/models/old_way_node.rb @@ -2,10 +2,10 @@ # # Table name: way_nodes # -# way_id :integer not null, primary key -# node_id :integer not null -# version :integer not null, primary key -# sequence_id :integer not null, primary key +# way_id :bigint(8) not null, primary key +# node_id :bigint(8) not null +# version :bigint(8) not null, primary key +# sequence_id :bigint(8) not null, primary key # # Indexes # diff --git a/app/models/old_way_tag.rb b/app/models/old_way_tag.rb index 5832f6d4f..ae4ad605e 100644 --- a/app/models/old_way_tag.rb +++ b/app/models/old_way_tag.rb @@ -2,10 +2,10 @@ # # Table name: way_tags # -# way_id :integer default(0), not null, primary key +# way_id :bigint(8) default(0), not null, primary key # k :string not null, primary key # v :string not null -# version :integer not null, primary key +# version :bigint(8) not null, primary key # # Foreign Keys # diff --git a/app/models/redaction.rb b/app/models/redaction.rb index e6d748706..d9b2a5579 100644 --- a/app/models/redaction.rb +++ b/app/models/redaction.rb @@ -7,7 +7,7 @@ # description :text # created_at :datetime # updated_at :datetime -# user_id :integer not null +# user_id :bigint(8) not null # description_format :enum default("markdown"), not null # # Foreign Keys diff --git a/app/models/relation.rb b/app/models/relation.rb index f55711a69..bcac9d04b 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -2,11 +2,11 @@ # # Table name: current_relations # -# id :integer not null, primary key -# changeset_id :integer not null +# id :bigint(8) not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null # visible :boolean not null -# version :integer not null +# version :bigint(8) not null # # Indexes # @@ -62,8 +62,8 @@ class Relation < ActiveRecord::Base return Relation.from_xml_node(pt, create) end raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.") - rescue LibXML::XML::Error, ArgumentError => ex - raise OSM::APIBadXMLError.new("relation", xml, ex.message) + rescue LibXML::XML::Error, ArgumentError => e + raise OSM::APIBadXMLError.new("relation", xml, e.message) end def self.from_xml_node(pt, create = false) diff --git a/app/models/relation_member.rb b/app/models/relation_member.rb index 3e5cdfca2..7c399c3a8 100644 --- a/app/models/relation_member.rb +++ b/app/models/relation_member.rb @@ -2,9 +2,9 @@ # # Table name: current_relation_members # -# relation_id :integer not null, primary key +# relation_id :bigint(8) not null, primary key # member_type :enum not null -# member_id :integer not null +# member_id :bigint(8) not null # member_role :string not null # sequence_id :integer default(0), not null, primary key # diff --git a/app/models/relation_tag.rb b/app/models/relation_tag.rb index 151615f72..b186f505d 100644 --- a/app/models/relation_tag.rb +++ b/app/models/relation_tag.rb @@ -2,7 +2,7 @@ # # Table name: current_relation_tags # -# relation_id :integer not null, primary key +# relation_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/models/trace.rb b/app/models/trace.rb index 0e8763328..7c97b4e96 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -2,11 +2,11 @@ # # Table name: gpx_files # -# id :integer not null, primary key -# user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null # visible :boolean default(TRUE), not null # name :string default(""), not null -# size :integer +# size :bigint(8) # latitude :float # longitude :float # timestamp :datetime not null @@ -43,12 +43,7 @@ class Trace < ActiveRecord::Base validates :timestamp, :presence => true validates :visibility, :inclusion => %w[private public trackable identifiable] - def destroy - super - FileUtils.rm_f(trace_name) - FileUtils.rm_f(icon_picture_name) - FileUtils.rm_f(large_picture_name) - end + after_destroy :remove_files def tagstring tags.collect(&:tag).join(", ") @@ -208,8 +203,8 @@ class Trace < ActiveRecord::Base end raise OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.") - rescue LibXML::XML::Error, ArgumentError => ex - raise OSM::APIBadXMLError.new("trace", xml, ex.message) + rescue LibXML::XML::Error, ArgumentError => e + raise OSM::APIBadXMLError.new("trace", xml, e.message) end def update_from_xml_node(pt, create = false) @@ -343,4 +338,12 @@ class Trace < ActiveRecord::Base gpx end + + private + + def remove_files + FileUtils.rm_f(trace_name) + FileUtils.rm_f(icon_picture_name) + FileUtils.rm_f(large_picture_name) + end end diff --git a/app/models/tracepoint.rb b/app/models/tracepoint.rb index 445688c55..6473c9430 100644 --- a/app/models/tracepoint.rb +++ b/app/models/tracepoint.rb @@ -6,9 +6,9 @@ # trackid :integer not null # latitude :integer not null # longitude :integer not null -# gpx_id :integer not null +# gpx_id :bigint(8) not null # timestamp :datetime -# tile :integer +# tile :bigint(8) # # Indexes # diff --git a/app/models/tracetag.rb b/app/models/tracetag.rb index 84b6c6dfa..8d2f4fffa 100644 --- a/app/models/tracetag.rb +++ b/app/models/tracetag.rb @@ -2,9 +2,9 @@ # # Table name: gpx_file_tags # -# gpx_id :integer default(0), not null +# gpx_id :bigint(8) default(0), not null # tag :string not null -# id :integer not null, primary key +# id :bigint(8) not null, primary key # # Indexes # diff --git a/app/models/user.rb b/app/models/user.rb index 9f1310843..2979b13d7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,7 @@ # Table name: users # # email :string not null -# id :integer not null, primary key +# id :bigint(8) not null, primary key # pass_crypt :string not null # creation_time :datetime not null # display_name :string default(""), not null @@ -33,7 +33,8 @@ # image_use_gravatar :boolean default(FALSE), not null # image_content_type :string # auth_provider :string -# home_tile :integer +# home_tile :bigint(8) +# tou_agreed :datetime # # Indexes # diff --git a/app/models/user_block.rb b/app/models/user_block.rb index 27bc40498..92cee16cd 100644 --- a/app/models/user_block.rb +++ b/app/models/user_block.rb @@ -3,12 +3,12 @@ # Table name: user_blocks # # id :integer not null, primary key -# user_id :integer not null -# creator_id :integer not null +# user_id :bigint(8) not null +# creator_id :bigint(8) not null # reason :text not null # ends_at :datetime not null # needs_view :boolean default(FALSE), not null -# revoker_id :integer +# revoker_id :bigint(8) # created_at :datetime # updated_at :datetime # reason_format :enum default("markdown"), not null diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 3963bd02a..583ced3c5 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -2,7 +2,7 @@ # # Table name: user_preferences # -# user_id :integer not null, primary key +# user_id :bigint(8) not null, primary key # k :string not null, primary key # v :string not null # diff --git a/app/models/user_role.rb b/app/models/user_role.rb index adf569a03..f3d48cade 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -3,11 +3,11 @@ # Table name: user_roles # # id :integer not null, primary key -# user_id :integer not null +# user_id :bigint(8) not null # role :enum not null # created_at :datetime # updated_at :datetime -# granter_id :integer not null +# granter_id :bigint(8) not null # # Indexes # diff --git a/app/models/user_token.rb b/app/models/user_token.rb index 0d1e16e8a..844357d8d 100644 --- a/app/models/user_token.rb +++ b/app/models/user_token.rb @@ -2,8 +2,8 @@ # # Table name: user_tokens # -# id :integer not null, primary key -# user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null # token :string not null # expiry :datetime not null # referer :text diff --git a/app/models/way.rb b/app/models/way.rb index 6573b9805..6fcaf39cc 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -2,11 +2,11 @@ # # Table name: current_ways # -# id :integer not null, primary key -# changeset_id :integer not null +# id :bigint(8) not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null # visible :boolean not null -# version :integer not null +# version :bigint(8) not null # # Indexes # @@ -60,8 +60,8 @@ class Way < ActiveRecord::Base return Way.from_xml_node(pt, create) end raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.") - rescue LibXML::XML::Error, ArgumentError => ex - raise OSM::APIBadXMLError.new("way", xml, ex.message) + rescue LibXML::XML::Error, ArgumentError => e + raise OSM::APIBadXMLError.new("way", xml, e.message) end def self.from_xml_node(pt, create = false) diff --git a/app/models/way_node.rb b/app/models/way_node.rb index 5c09cd740..0788a631c 100644 --- a/app/models/way_node.rb +++ b/app/models/way_node.rb @@ -2,9 +2,9 @@ # # Table name: current_way_nodes # -# way_id :integer not null, primary key -# node_id :integer not null -# sequence_id :integer not null, primary key +# way_id :bigint(8) not null, primary key +# node_id :bigint(8) not null +# sequence_id :bigint(8) not null, primary key # # Indexes # diff --git a/app/models/way_tag.rb b/app/models/way_tag.rb index c4df0abb5..6637c1585 100644 --- a/app/models/way_tag.rb +++ b/app/models/way_tag.rb @@ -2,7 +2,7 @@ # # Table name: current_way_tags # -# way_id :integer not null, primary key +# way_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/views/api/users/_api_user.builder b/app/views/api/users/_api_user.builder deleted file mode 100644 index 91cd562e9..000000000 --- a/app/views/api/users/_api_user.builder +++ /dev/null @@ -1,44 +0,0 @@ -xml.tag! "user", :id => api_user.id, - :display_name => api_user.display_name, - :account_created => api_user.creation_time.xmlschema do - xml.tag! "description", api_user.description if api_user.description - if current_user && current_user == api_user - xml.tag! "contributor-terms", :agreed => api_user.terms_agreed.present?, - :pd => api_user.consider_pd - else - xml.tag! "contributor-terms", :agreed => api_user.terms_agreed.present? - end - xml.tag! "img", :href => user_image_url(api_user) if api_user.image.file? || api_user.image_use_gravatar - xml.tag! "roles" do - api_user.roles.each do |role| - xml.tag! role.role - end - end - xml.tag! "changesets", :count => api_user.changesets.size - xml.tag! "traces", :count => api_user.traces.size - xml.tag! "blocks" do - xml.tag! "received", :count => api_user.blocks.size, - :active => api_user.blocks.active.size - if api_user.moderator? - xml.tag! "issued", :count => api_user.blocks_created.size, - :active => api_user.blocks_created.active.size - end - end - if current_user && current_user == api_user - if api_user.home_lat && api_user.home_lon - xml.tag! "home", :lat => api_user.home_lat, - :lon => api_user.home_lon, - :zoom => api_user.home_zoom - end - if api_user.languages - xml.tag! "languages" do - api_user.languages.split(",") { |lang| xml.tag! "lang", lang } - end - end - xml.tag! "messages" do - xml.tag! "received", :count => api_user.messages.size, - :unread => api_user.new_messages.size - xml.tag! "sent", :count => api_user.sent_messages.size - end - end -end diff --git a/app/views/api/users/_user.builder b/app/views/api/users/_user.builder new file mode 100644 index 000000000..7bf8e18a5 --- /dev/null +++ b/app/views/api/users/_user.builder @@ -0,0 +1,44 @@ +xml.tag! "user", :id => user.id, + :display_name => user.display_name, + :account_created => user.creation_time.xmlschema do + xml.tag! "description", user.description if user.description + if current_user && current_user == user + xml.tag! "contributor-terms", :agreed => user.terms_agreed.present?, + :pd => user.consider_pd + else + xml.tag! "contributor-terms", :agreed => user.terms_agreed.present? + end + xml.tag! "img", :href => user_image_url(user) if user.image.file? || user.image_use_gravatar + xml.tag! "roles" do + user.roles.each do |role| + xml.tag! role.role + end + end + xml.tag! "changesets", :count => user.changesets.size + xml.tag! "traces", :count => user.traces.size + xml.tag! "blocks" do + xml.tag! "received", :count => user.blocks.size, + :active => user.blocks.active.size + if user.moderator? + xml.tag! "issued", :count => user.blocks_created.size, + :active => user.blocks_created.active.size + end + end + if current_user && current_user == user + if user.home_lat && user.home_lon + xml.tag! "home", :lat => user.home_lat, + :lon => user.home_lon, + :zoom => user.home_zoom + end + if user.languages + xml.tag! "languages" do + user.languages.split(",") { |lang| xml.tag! "lang", lang } + end + end + xml.tag! "messages" do + xml.tag! "received", :count => user.messages.size, + :unread => user.new_messages.size + xml.tag! "sent", :count => user.sent_messages.size + end + end +end diff --git a/app/views/api/users/api_users.builder b/app/views/api/users/index.builder similarity index 59% rename from app/views/api/users/api_users.builder rename to app/views/api/users/index.builder index a3c0f4d9a..68d629099 100644 --- a/app/views/api/users/api_users.builder +++ b/app/views/api/users/index.builder @@ -1,4 +1,4 @@ xml.instruct! :xml, :version => "1.0" xml.osm(OSM::API.new.xml_root_attributes) do |osm| - osm << render(:partial => "api_user", :collection => @users) + osm << render(:partial => "user", :collection => @users) end diff --git a/app/views/api/users/api_read.builder b/app/views/api/users/show.builder similarity index 61% rename from app/views/api/users/api_read.builder rename to app/views/api/users/show.builder index 78533279c..dd5e93689 100644 --- a/app/views/api/users/api_read.builder +++ b/app/views/api/users/show.builder @@ -1,4 +1,4 @@ xml.instruct! :xml, :version => "1.0" xml.osm(OSM::API.new.xml_root_attributes) do |osm| - osm << render(:partial => "api_user", :object => @user) + osm << render(:partial => "user", :object => @user) end diff --git a/app/views/diary_entries/_diary_comment.html.erb b/app/views/diary_entries/_diary_comment.html.erb index 9ee675343..301739eef 100644 --- a/app/views/diary_entries/_diary_comment.html.erb +++ b/app/views/diary_entries/_diary_comment.html.erb @@ -1,4 +1,4 @@ -
<%= raw(t(".comment_from", :link_user => (link_to h(diary_comment.user.display_name), user_path(diary_comment.user)), :comment_created_at => link_to(l(diary_comment.created_at, :format => :friendly), :anchor => "comment#{diary_comment.id}"))) %> <% if current_user and diary_comment.user.id != current_user.id %> @@ -9,7 +9,11 @@
<%= t ".community_driven_html", :diary_path => diary_path %>
<%= t ".community_driven_html", :diary_path => diary_entries_path %>
<%= label_tag "user_block_period", t(".period") %> - <%= select_tag("user_block_period", options_for_select(UserBlock::PERIODS.collect { |h| [t("user_blocks.period", :count => h), h.to_s] }, params[:user_block_period])) %> + <%= select_tag("user_block_period", options_for_select(UserBlock::PERIODS.collect { |h| [block_duration_in_words(h.hours), h.to_s] }, params[:user_block_period])) %>
<%= f.check_box :needs_view %> diff --git a/app/views/user_blocks/new.html.erb b/app/views/user_blocks/new.html.erb index c92fe74ec..aa4bf7132 100644 --- a/app/views/user_blocks/new.html.erb +++ b/app/views/user_blocks/new.html.erb @@ -13,7 +13,7 @@
<%= f.check_box :needs_view %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 5090cbee0..87eb9b45f 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -205,7 +205,7 @@ <% else %>
<%= t ".read and accept with tou" %>
<%= t ".contributor_terms_explain" %>
+ <%= raw t ".guidance", + :summary => "https://www.osmfoundation.org/wiki/License/Contributor_Terms_Summary", + :translations => "https://www.osmfoundation.org/wiki/License/Contributor_Terms/Informal_Translations" %> +
<%= t ".tou_explain_html", :tou_link => link_to(t("layouts.tou"), "https://wiki.osmfoundation.org/wiki/Terms_of_Use", :target => :new) %>
<%= t ".read and accept" %>
- <%= raw t ".guidance", - :summary => "https://www.osmfoundation.org/wiki/License/Contributor_Terms_Summary", - :translations => "https://www.osmfoundation.org/wiki/License/Contributor_Terms/Informal_Translations" %> -
DiÄer haritaların aksine, OpenStreetMap tamamıyla sizin gibi insanlar tarafından oluÅturulur ve düzeltme, güncelleme, indirme ve kullanma herkes için ücretsizdir.
Katkıda bulunmaya baÅlamak için kayıt olun. Hesabınızın onaylanması için size bir e-posta göndereceÄiz.
Katkıda bulunmaya baÅlamak için kaydolun. Hesabınızın onaylanması için size bir e-posta göndereceÄiz.