From 5add2d7e1d1d365e80d1d4ef417ff249ca7f35c0 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 6 Mar 2024 15:55:37 +0300 Subject: [PATCH 1/1] Reload only changeset element subpages --- app/assets/javascripts/index.js | 2 +- app/controllers/changesets_controller.rb | 39 +++++++++++++++-------- app/helpers/browse_helper.rb | 2 +- app/views/changesets/_elements.html.erb | 6 ++-- app/views/changesets/_paging_nav.html.erb | 7 +++- test/system/changeset_elements_test.rb | 36 ++++++++++++++++++++- 6 files changed, 71 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 8ffa05c53..eac3f82cc 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -396,7 +396,7 @@ $(document).ready(function () { OSM.router.load(); $(document).on("click", "a", function (e) { - if (e.isDefaultPrevented() || e.isPropagationStopped()) { + if (e.isDefaultPrevented() || e.isPropagationStopped() || $(e.target).data("turbo")) { return; } diff --git a/app/controllers/changesets_controller.rb b/app/controllers/changesets_controller.rb index a5ddaf364..ba04b9a17 100644 --- a/app/controllers/changesets_controller.rb +++ b/app/controllers/changesets_controller.rb @@ -75,22 +75,33 @@ class ChangesetsController < ApplicationController end def show - @type = "changeset" @changeset = Changeset.find(params[:id]) - @comments = if current_user&.moderator? - @changeset.comments.unscope(:where => :visible).includes(:author) - else - @changeset.comments.includes(:author) - end - @node_pages, @nodes = paginate(:old_nodes, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "node_page") - @way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "way_page") - @relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "relation_page") - if @changeset.user.active? && @changeset.user.data_public? - changesets = conditions_nonempty(@changeset.user.changesets) - @next_by_user = changesets.where("id > ?", @changeset.id).reorder(:id => :asc).first - @prev_by_user = changesets.where(:id => ...@changeset.id).reorder(:id => :desc).first + case turbo_frame_request_id + when "changeset_nodes" + @node_pages, @nodes = paginate(:old_nodes, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "node_page") + render :partial => "elements", :locals => { :type => "node", :elements => @nodes, :pages => @node_pages } + when "changeset_ways" + @way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "way_page") + render :partial => "elements", :locals => { :type => "way", :elements => @ways, :pages => @way_pages } + when "changeset_relations" + @relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "relation_page") + render :partial => "elements", :locals => { :type => "relation", :elements => @relations, :pages => @relation_pages } + else + @comments = if current_user&.moderator? + @changeset.comments.unscope(:where => :visible).includes(:author) + else + @changeset.comments.includes(:author) + end + @node_pages, @nodes = paginate(:old_nodes, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "node_page") + @way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "way_page") + @relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "relation_page") + if @changeset.user.active? && @changeset.user.data_public? + changesets = conditions_nonempty(@changeset.user.changesets) + @next_by_user = changesets.where("id > ?", @changeset.id).reorder(:id => :asc).first + @prev_by_user = changesets.where(:id => ...@changeset.id).reorder(:id => :desc).first + end + render :layout => map_layout end - render :layout => map_layout rescue ActiveRecord::RecordNotFound render :template => "browse/not_found", :status => :not_found, :layout => map_layout end diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index 4cd0384cb..0ea10e219 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -96,7 +96,7 @@ module BrowseHelper pagination_items(pages, {}).each do |body, page_or_class| linked = !(page_or_class.is_a? String) link = if linked - link_to body, url_for(page_param => page_or_class.number), :class => link_classes, :title => yield(page_or_class) + link_to body, url_for(page_param => page_or_class.number), :class => link_classes, **yield(page_or_class) else tag.span body, :class => link_classes end diff --git a/app/views/changesets/_elements.html.erb b/app/views/changesets/_elements.html.erb index 37ef2d122..fd5dd8a26 100644 --- a/app/views/changesets/_elements.html.erb +++ b/app/views/changesets/_elements.html.erb @@ -1,6 +1,6 @@ -
+<%= turbo_frame_tag "changeset_#{type.pluralize}" do %> <%= render :partial => "paging_nav", :locals => { :type => type, :pages => pages } %> -
+<% end %> diff --git a/app/views/changesets/_paging_nav.html.erb b/app/views/changesets/_paging_nav.html.erb index 19ac42f95..fbdf1d507 100644 --- a/app/views/changesets/_paging_nav.html.erb +++ b/app/views/changesets/_paging_nav.html.erb @@ -1,6 +1,11 @@

<%= type_and_paginated_count(type, pages) %>

<% if pages.page_count > 1 %> - <%= sidebar_classic_pagination(pages, "#{type}_page") { |page| type_and_paginated_count(type, pages, page) } %> + <%= sidebar_classic_pagination(pages, "#{type}_page") do |page| + { + :title => type_and_paginated_count(type, pages, page), + :data => { :turbo => "true" } + } + end %> <% end %>
diff --git a/test/system/changeset_elements_test.rb b/test/system/changeset_elements_test.rb index 22c065933..9e65f5be2 100644 --- a/test/system/changeset_elements_test.rb +++ b/test/system/changeset_elements_test.rb @@ -13,11 +13,39 @@ class ChangesetElementsTest < ApplicationSystemTestCase visit changeset_path(changeset) within_sidebar do - assert_one_missing_link way_paths + next_page_way_path = assert_one_missing_link way_paths + assert_no_link "Ways (1-20 of 21)" assert_link "Ways (21-21 of 21)" assert_one_missing_link node_paths + assert_no_link "Nodes (1-20 of 21)" assert_link "Nodes (21-21 of 21)" + + fill_in "text", :with => "Comment text we don't want to lose" + + click_on "Ways (21-21 of 21)" + + assert_one_present_link way_paths, next_page_way_path + assert_link "Ways (1-20 of 21)" + assert_no_link "Ways (21-21 of 21)" + + next_page_node_path = assert_one_missing_link node_paths + assert_no_link "Nodes (1-20 of 21)" + assert_link "Nodes (21-21 of 21)" + + assert_field "text", :with => "Comment text we don't want to lose" + + click_on "Nodes (21-21 of 21)" + + assert_one_present_link way_paths, next_page_way_path + assert_link "Ways (1-20 of 21)" + assert_no_link "Ways (21-21 of 21)" + + assert_one_present_link node_paths, next_page_node_path + assert_link "Nodes (1-20 of 21)" + assert_no_link "Nodes (21-21 of 21)" + + assert_field "text", :with => "Comment text we don't want to lose" end end @@ -38,4 +66,10 @@ class ChangesetElementsTest < ApplicationSystemTestCase assert_not_nil missing_href, "expected one link missing but all are present" missing_href end + + def assert_one_present_link(hrefs, present_href) + hrefs.each do |href| + assert_link :href => href, :count => (href == present_href ? 1 : 0) + end + end end -- 2.39.5