From: Tom Hughes Date: Sat, 15 Feb 2025 14:44:58 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/5521' X-Git-Tag: live~149 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/8ecbe9b07d60828c4d20fbf329696c12bd23b917?hp=8e1e1e47134b652bd1a5facba44280f05cc802fa Merge remote-tracking branch 'upstream/pull/5521' --- diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 3116bc5cd..adedce543 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -29,7 +29,7 @@ class Ability if user&.active? can :welcome, :site - can :read, [:deletion, :account_terms] + can :read, [:deletion, :account_terms, :account_pd_declaration] if Settings.status != "database_offline" can [:read, :create, :destroy], :changeset_subscription @@ -38,6 +38,7 @@ class Ability can [:read, :create, :destroy], :oauth2_authorization can [:update, :destroy], :account can :update, :account_terms + can :create, :account_pd_declaration can :read, :dashboard can [:create, :subscribe, :unsubscribe], DiaryEntry can :update, DiaryEntry, :user => user diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 2e13f6967..464bbecee 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -90,21 +90,76 @@ $(document).ready(function () { // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive Turbo.session.drive = false; - var headerWidth = 0, - compactWidth = 0; + const $expandedSecondaryMenu = $("header nav.secondary > ul"), + $collapsedSecondaryMenu = $("#compact-secondary-nav > ul"), + secondaryMenuItems = [], + breakpointWidth = 768; + let moreItemWidth = 0; function updateHeader() { var windowWidth = $(window).width(); - if (windowWidth < compactWidth) { - $("body").removeClass("compact-nav").addClass("small-nav"); - } else if (windowWidth < headerWidth) { - $("body").addClass("compact-nav").removeClass("small-nav"); + if (windowWidth < breakpointWidth) { + $("body").addClass("small-nav"); + expandAllSecondaryMenuItems(); } else { - $("body").removeClass("compact-nav").removeClass("small-nav"); + $("body").removeClass("small-nav"); + const availableWidth = $expandedSecondaryMenu.width(); + secondaryMenuItems.forEach(function (item) { + $(item[0]).remove(); + }); + let runningWidth = 0, + i = 0, + requiredWidth; + for (; i < secondaryMenuItems.length; i++) { + runningWidth += secondaryMenuItems[i][1]; + if (i < secondaryMenuItems.length - 1) { + requiredWidth = runningWidth + moreItemWidth; + } else { + requiredWidth = runningWidth; + } + if (requiredWidth > availableWidth) { + break; + } + expandSecondaryMenuItem($(secondaryMenuItems[i][0])); + } + for (; i < secondaryMenuItems.length; i++) { + collapseSecondaryMenuItem($(secondaryMenuItems[i][0])); + } } } + function expandAllSecondaryMenuItems() { + secondaryMenuItems.forEach(function (item) { + expandSecondaryMenuItem($(item[0])); + }); + } + + function expandSecondaryMenuItem($item) { + $item.children("a") + .removeClass("dropdown-item") + .addClass("nav-link") + .addClass(function () { + return $(this).hasClass("active") ? "text-secondary-emphasis" : "text-secondary"; + }); + $item.addClass("nav-item").insertBefore("#compact-secondary-nav"); + toggleCompactSecondaryNav(); + } + + function collapseSecondaryMenuItem($item) { + $item.children("a") + .addClass("dropdown-item") + .removeClass("nav-link text-secondary text-secondary-emphasis"); + $item.removeClass("nav-item").appendTo($collapsedSecondaryMenu); + toggleCompactSecondaryNav(); + } + + function toggleCompactSecondaryNav() { + $("#compact-secondary-nav").toggle( + $collapsedSecondaryMenu.find("li").length > 0 + ); + } + /* * Chrome 60 and later seem to fire the "ready" callback * before the DOM is fully ready causing us to measure the @@ -112,20 +167,10 @@ $(document).ready(function () { * to defer the measurement slightly as a workaround. */ setTimeout(function () { - $("header").children(":visible").each(function (i, e) { - headerWidth += $(e).outerWidth(); + $expandedSecondaryMenu.find("li:not(#compact-secondary-nav)").each(function () { + secondaryMenuItems.push([this, $(this).width()]); }); - - $("body").addClass("compact-nav"); - - $("header").children(":visible").each(function (i, e) { - compactWidth += $(e).outerWidth(); - }); - - $("body").removeClass("compact-nav"); - - $("header").removeClass("text-nowrap"); - $("header nav.secondary > ul").removeClass("flex-nowrap"); + moreItemWidth = $("#compact-secondary-nav").width(); updateHeader(); diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index fc9af9803..a27976854 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -131,10 +131,6 @@ header { font-size: 14px; } - nav.primary { - margin-right: auto; - } - .username { max-width: 12em; } @@ -174,7 +170,11 @@ nav.primary { nav.secondary { .nav-link { - padding: 0.3rem; + padding: 0 0.3rem; + } + + > ul { + height: 1.5em; } } @@ -191,15 +191,6 @@ nav.primary, nav.secondary { display: none; } -body.compact-nav { - #compact-secondary-nav { - display: inline-block; - } - .compact-hide { - display: none; - } -} - body.small-nav { #menu-icon { display: block; @@ -240,6 +231,10 @@ body.small-nav { nav.secondary { flex-direction: column; + > ul { + height: auto; + } + .user-menu, .login-menu { width: 100%; } diff --git a/app/controllers/accounts/pd_declarations_controller.rb b/app/controllers/accounts/pd_declarations_controller.rb new file mode 100644 index 000000000..2d2569d62 --- /dev/null +++ b/app/controllers/accounts/pd_declarations_controller.rb @@ -0,0 +1,28 @@ +module Accounts + class PdDeclarationsController < ApplicationController + layout "site" + + before_action :authorize_web + before_action :set_locale + + authorize_resource :class => :account_pd_declaration + + def show; end + + def create + if current_user.consider_pd + flash[:warning] = t(".already_declared") + else + current_user.consider_pd = params[:consider_pd] + + if current_user.consider_pd + flash[:notice] = t(".successfully_declared") if current_user.save + else + flash[:warning] = t(".did_not_confirm") + end + end + + redirect_to edit_account_path + end + end +end diff --git a/app/controllers/accounts/terms_controller.rb b/app/controllers/accounts/terms_controller.rb index 13e9de890..03007a532 100644 --- a/app/controllers/accounts/terms_controller.rb +++ b/app/controllers/accounts/terms_controller.rb @@ -33,7 +33,6 @@ module Accounts flash[:notice] = { :partial => "accounts/terms/terms_declined_flash" } if current_user.save else unless current_user.terms_agreed? - current_user.consider_pd = params[:user][:consider_pd] current_user.tou_agreed = Time.now.utc current_user.terms_agreed = Time.now.utc current_user.terms_seen = true diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a0be87bdc..0df971bd4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -222,8 +222,7 @@ class UsersController < ApplicationController def user_params params.require(:user).permit(:email, :display_name, :auth_provider, :auth_uid, - :pass_crypt, :pass_crypt_confirmation, - :consider_pd) + :pass_crypt, :pass_crypt_confirmation) end ## diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ff6dcd2ff..86a3d56cd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -43,7 +43,7 @@ module ApplicationHelper end def header_nav_link_class(path) - ["nav-link", current_page?(path) ? "text-secondary-emphasis" : "text-secondary"] + ["nav-link", current_page?(path) ? "active text-secondary-emphasis" : "text-secondary"] end def application_data diff --git a/app/views/accounts/edit.html.erb b/app/views/accounts/edit.html.erb index 7a10b12e3..ce7dd97a8 100644 --- a/app/views/accounts/edit.html.erb +++ b/app/views/accounts/edit.html.erb @@ -29,14 +29,18 @@ (" target="_new"><%= t ".openid.link text" %>) -
- +
+ <% if current_user.terms_agreed? %> <%= t ".contributor terms.agreed" %> (" target="_new"><%= t ".contributor terms.link text" %>) +
<% if current_user.consider_pd? %> <%= t ".contributor terms.agreed_with_pd" %> + <% else %> + <%= t ".contributor terms.not_agreed_with_pd" %> + (<%= link_to t(".contributor terms.pd_link_text"), account_pd_declaration_path %>) <% end %> <% else %> <%= t ".contributor terms.not yet agreed" %> diff --git a/app/views/accounts/pd_declarations/show.html.erb b/app/views/accounts/pd_declarations/show.html.erb new file mode 100644 index 000000000..ad314feaa --- /dev/null +++ b/app/views/accounts/pd_declarations/show.html.erb @@ -0,0 +1,14 @@ +<% content_for :heading do %> +

<%= t ".title" %>

+<% end %> + +<%= bootstrap_form_tag do |f| %> + <%= f.form_group :help => link_to(t(".consider_pd_why"), t(".consider_pd_why_url"), :target => :new) do %> + <%= f.check_box :consider_pd, + :label => t(".consider_pd"), + :autocomplete => :off, + :checked => current_user.consider_pd, + :disabled => current_user.consider_pd %> + <% end %> + <%= f.primary t(".confirm"), :disabled => current_user.consider_pd %> +<% end %> diff --git a/app/views/accounts/terms/show.html.erb b/app/views/accounts/terms/show.html.erb index 3cc52302f..c1c0e0a89 100644 --- a/app/views/accounts/terms/show.html.erb +++ b/app/views/accounts/terms/show.html.erb @@ -72,13 +72,4 @@ <%= submit_tag(t(".continue"), :name => "continue", :id => "continue", :disabled => true, :class => "btn btn-primary") %> <%= submit_tag(t(".cancel"), :name => "decline", :id => "decline", :class => "btn btn-outline-secondary") %>
- -
-
- <%= check_box("user", "consider_pd", :class => "form-check-input") %> - - (<%= link_to(t(".consider_pd_why"), t(".consider_pd_why_url"), :target => :new) %>) -
<% end %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 45e23fc2b..aa5249381 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -27,59 +27,43 @@
-