Reload only changeset element subpages

This commit is contained in:
Anton Khorev 2024-03-06 15:55:37 +03:00
parent fee3a08368
commit 5add2d7e1d
6 changed files with 71 additions and 21 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -1,6 +1,6 @@
<div>
<%= turbo_frame_tag "changeset_#{type.pluralize}" do %>
<%= render :partial => "paging_nav", :locals => { :type => type, :pages => pages } %>
<ul class="list-unstyled">
<ul class="list-unstyled" data-turbo="false">
<% elements.each do |element| %>
<%= element_list_item type, element do
t "printable_name.current_and_old_links_html",
@ -9,4 +9,4 @@
end %>
<% end %>
</ul>
</div>
<% end %>

View file

@ -1,6 +1,11 @@
<div class="d-flex flex-wrap gap-2">
<h4 class="fs-5 mb-0"><%= type_and_paginated_count(type, pages) %></h4>
<% 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 %>
</div>

View file

@ -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