From 68e7a351b885a00caad5efcbfba45200c0116338 Mon Sep 17 00:00:00 2001 From: Jack Lee <43303581+jacklee1792@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:55:26 -0500 Subject: [PATCH] Improve ranking links in user profile (#8403) Links to the rankings page are put on the NR/CR/WR numbers instead, and redirect to their respective region-based rankings (national, continental, world). When one of these links is clicked, the "focus" parameter highlights the user's row in the rankings if applicable and scrolls it to the center of the viewport. --- .../app/assets/stylesheets/results.scss | 4 +++ .../app/controllers/persons_controller.rb | 2 ++ WcaOnRails/app/helpers/persons_helper.rb | 14 ++++++-- WcaOnRails/app/helpers/results_helper.rb | 5 +++ .../views/persons/_personal_records.html.erb | 20 +++++------ .../views/results/_rankings_table.html.erb | 2 +- .../views/results/_results_selector.html.erb | 35 +++++++++---------- 7 files changed, 48 insertions(+), 34 deletions(-) diff --git a/WcaOnRails/app/assets/stylesheets/results.scss b/WcaOnRails/app/assets/stylesheets/results.scss index 58a081aae0..fae4173f67 100644 --- a/WcaOnRails/app/assets/stylesheets/results.scss +++ b/WcaOnRails/app/assets/stylesheets/results.scss @@ -49,4 +49,8 @@ .cubing-icon { vertical-align: baseline; } + + .highlight-focus { + background-color: $highlight-row-color; + } } diff --git a/WcaOnRails/app/controllers/persons_controller.rb b/WcaOnRails/app/controllers/persons_controller.rb index 32dd865a8f..cd19b1b506 100644 --- a/WcaOnRails/app/controllers/persons_controller.rb +++ b/WcaOnRails/app/controllers/persons_controller.rb @@ -28,6 +28,8 @@ def index def show @person = Person.current.includes(:user, :ranksSingle, :ranksAverage, :competitions).find_by_wca_id!(params[:id]) + @country = @person.country + @continent = @country.continent @previous_persons = Person.where(wca_id: params[:id]).where.not(subId: 1).order(:subId) @ranks_single = @person.ranksSingle.select { |r| r.event.official? } @ranks_average = @person.ranksAverage.select { |r| r.event.official? } diff --git a/WcaOnRails/app/helpers/persons_helper.rb b/WcaOnRails/app/helpers/persons_helper.rb index 4e0f84f8a6..f88a7e1e8e 100644 --- a/WcaOnRails/app/helpers/persons_helper.rb +++ b/WcaOnRails/app/helpers/persons_helper.rb @@ -1,10 +1,18 @@ # frozen_string_literal: true module PersonsHelper - def rank_td(rank_object, type) - rank = rank_object&.public_send("#{type}_rank") + def rank_td(rank_object, type, wca_id, region_id = nil) + region_type = "world" + if region_id&.starts_with?("_") + region_type = "continent" + elsif region_id + region_type = "country" + end + rank = rank_object&.public_send("#{region_type}_rank") rank = "-" if rank == 0 - content_tag :td, rank, class: "#{type}-rank #{'record' if rank == 1}" + content_tag(:td, class: "#{region_type}-rank #{'record' if rank == 1}") do + rank ? link_to(rank, rankings_path(rank_object.event_id, type, region: region_id, focus: wca_id), class: :plain) : nil + end end def odd_rank_reason diff --git a/WcaOnRails/app/helpers/results_helper.rb b/WcaOnRails/app/helpers/results_helper.rb index 9fa9883d20..5fd8487ddb 100644 --- a/WcaOnRails/app/helpers/results_helper.rb +++ b/WcaOnRails/app/helpers/results_helper.rb @@ -106,6 +106,11 @@ def pb_type_class_for_result(regional_record, pb_marker) record_class end + def result_params_merge(**params) + # We should unset the focus every time we change the selectors + request.params.merge(**params, focus: nil) + end + def execute_cached_query(cache_key, sql_query) # As we are using the native Rails cache we set the expiry date to 7 days # as CAD is ran usually before that diff --git a/WcaOnRails/app/views/persons/_personal_records.html.erb b/WcaOnRails/app/views/persons/_personal_records.html.erb index d37ec3a02f..1a5e29f1cf 100644 --- a/WcaOnRails/app/views/persons/_personal_records.html.erb +++ b/WcaOnRails/app/views/persons/_personal_records.html.erb @@ -24,22 +24,18 @@ <%= cubing_icon rank_single.event.id %> <%= t "events.#{rank_single.event.id}" %> - <%= rank_td rank_single, "country" %> - <%= rank_td rank_single, "continent" %> - <%= rank_td rank_single, "world" %> + <%= rank_td rank_single, "single", @person.wca_id, @country.id %> + <%= rank_td rank_single, "single", @person.wca_id, @continent.id %> + <%= rank_td rank_single, "single", @person.wca_id%>