OSM.router.load();
$(document).on("click", "a", function (e) {
- if (e.isDefaultPrevented() || e.isPropagationStopped()) {
+ if (e.isDefaultPrevented() || e.isPropagationStopped() || $(e.target).data("turbo")) {
return;
}
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
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
-<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",
end %>
<% end %>
</ul>
-</div>
+<% end %>
<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>
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
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