refactor pool nav html
This commit is contained in:
@@ -136,6 +136,17 @@ module PostsHelper
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
def pool_link(pool)
|
||||
render("posts/partials/show/pool_link", post: @post, pool: pool)
|
||||
end
|
||||
|
||||
def is_pool_selected?(pool)
|
||||
return false if params.has_key?(:q)
|
||||
return false if params.has_key?(:favgroup_id)
|
||||
return false if !params.has_key?(:pool_id)
|
||||
return params[:pool_id].to_i == pool.id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def nav_params_for(page)
|
||||
|
||||
@@ -310,7 +310,7 @@ div#c-posts {
|
||||
}
|
||||
|
||||
div#a-show {
|
||||
.active {
|
||||
.active, .pool-selected-true {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,12 @@ class Pool < ApplicationRecord
|
||||
order(Arel.sql("(case pools.category when 'series' then 0 else 1 end), pools.name"))
|
||||
end
|
||||
|
||||
def selected_first(current_pool_id)
|
||||
return where("true") if current_pool_id.blank?
|
||||
current_pool_id = current_pool_id.to_i
|
||||
reorder(Arel.sql("(case pools.id when #{current_pool_id} then 0 else 1 end), pools.name"))
|
||||
end
|
||||
|
||||
def name_matches(name)
|
||||
name = normalize_name_for_search(name)
|
||||
name = "*#{name}*" unless name =~ /\*/
|
||||
@@ -280,6 +286,14 @@ class Pool < ApplicationRecord
|
||||
save if will_save_change_to_post_ids?
|
||||
end
|
||||
|
||||
def first_post?(post_id)
|
||||
page_number(post_id) == 1
|
||||
end
|
||||
|
||||
def first_post_id
|
||||
post_id_array[0]
|
||||
end
|
||||
|
||||
def post_id_array
|
||||
@post_id_array ||= post_ids.scan(/\d+/).map(&:to_i)
|
||||
end
|
||||
@@ -301,20 +315,26 @@ class Pool < ApplicationRecord
|
||||
self
|
||||
end
|
||||
|
||||
def neighbors(post)
|
||||
@neighbor_posts ||= begin
|
||||
post_ids =~ /\A#{post.id} (\d+)|(\d+) #{post.id} (\d+)|(\d+) #{post.id}\Z/
|
||||
def neighbors(post, relation)
|
||||
post_ids =~ /\A#{post.id} (\d+)|(\d+) #{post.id} (\d+)|(\d+) #{post.id}\Z/
|
||||
|
||||
if $2 && $3
|
||||
OpenStruct.new(:previous => $2.to_i, :next => $3.to_i)
|
||||
elsif $1
|
||||
OpenStruct.new(:next => $1.to_i)
|
||||
elsif $4
|
||||
OpenStruct.new(:previous => $4.to_i)
|
||||
if $2 && $3
|
||||
if relation == :previous
|
||||
return $2.to_i
|
||||
else
|
||||
OpenStruct.new
|
||||
return $3.to_i
|
||||
end
|
||||
elsif $1
|
||||
if relation == :next
|
||||
return $1.to_i
|
||||
end
|
||||
elsif $4
|
||||
if relation == :previous
|
||||
return $4.to_i
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
def cover_post_id
|
||||
|
||||
@@ -155,33 +155,6 @@ class PostPresenter < Presenter
|
||||
"#{humanized_essential_tag_string} - #{@post.md5}.#{@post.file_ext}"
|
||||
end
|
||||
|
||||
def safe_mode_message(template)
|
||||
html = ["This image is unavailable on safe mode (#{Danbooru.config.app_name}). Go to "]
|
||||
html << template.link_to("Danbooru", "https://danbooru.donmai.us") # XXX don't hardcode.
|
||||
html << " or disable safe mode to view ("
|
||||
html << template.link_to("learn more", template.wiki_pages_path(title: "help:user_settings"))
|
||||
html << ")."
|
||||
html.join.html_safe
|
||||
end
|
||||
|
||||
def image_html(template)
|
||||
return template.content_tag("p", "The artist requested removal of this image") if @post.banblocked?
|
||||
return template.content_tag("p", template.link_to("You need a gold account to see this image.", template.new_user_upgrade_path)) if @post.levelblocked?
|
||||
return template.content_tag("p", safe_mode_message(template)) if @post.safeblocked?
|
||||
|
||||
if @post.is_flash?
|
||||
template.render("posts/partials/show/flash", :post => @post)
|
||||
elsif @post.is_video?
|
||||
template.render("posts/partials/show/video", :post => @post)
|
||||
elsif @post.is_ugoira?
|
||||
template.render("posts/partials/show/ugoira", :post => @post)
|
||||
elsif !@post.is_image?
|
||||
template.render("posts/partials/show/download", :post => @post)
|
||||
elsif @post.is_image?
|
||||
template.render("posts/partials/show/image", :post => @post)
|
||||
end
|
||||
end
|
||||
|
||||
def has_nav_links?(template)
|
||||
has_sequential_navigation?(template.params) || @post.pools.undeleted.any? || @post.favorite_groups(active_id=template.params[:favgroup_id]).any?
|
||||
end
|
||||
@@ -191,93 +164,4 @@ class PostPresenter < Presenter
|
||||
return false if params[:pool_id].present? || params[:favgroup_id].present?
|
||||
return CurrentUser.user.enable_sequential_post_navigation
|
||||
end
|
||||
|
||||
def post_footer_for_pool_html(template)
|
||||
if template.params[:pool_id]
|
||||
pool = Pool.where(:id => template.params[:pool_id]).first
|
||||
return if pool.nil?
|
||||
return if pool.neighbors(@post).next.nil?
|
||||
template.link_to("Next in #{pool.pretty_name}", template.post_path(pool.neighbors(@post).next))
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def pool_html(template)
|
||||
html = ["<ul>"]
|
||||
|
||||
if template.params[:pool_id].present? && @post.belongs_to_pool_with_id?(template.params[:pool_id])
|
||||
pool = Pool.where(:id => template.params[:pool_id]).first
|
||||
return if pool.nil?
|
||||
html += pool_link_html(template, pool, :include_rel => true)
|
||||
|
||||
other_pools = @post.pools.undeleted.where("id <> ?", template.params[:pool_id]).series_first
|
||||
other_pools.each do |other_pool|
|
||||
html += pool_link_html(template, other_pool)
|
||||
end
|
||||
else
|
||||
first = true
|
||||
pools = @post.pools.undeleted
|
||||
pools.each do |pool|
|
||||
if first && template.params[:q].blank? && template.params[:favgroup_id].blank?
|
||||
html += pool_link_html(template, pool, :include_rel => true)
|
||||
first = false
|
||||
else
|
||||
html += pool_link_html(template, pool)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
html << "</ul>"
|
||||
html.join("\n").html_safe
|
||||
end
|
||||
|
||||
def pool_link_html(template, pool, options = {})
|
||||
pool_html = [%{<li id="nav-link-for-pool-#{pool.id}" class="pool-category-#{pool.category}">}]
|
||||
match_found = false
|
||||
|
||||
if options[:include_rel]
|
||||
prev_rel = "prev"
|
||||
next_rel = "next"
|
||||
klass = "active"
|
||||
else
|
||||
prev_rel = nil
|
||||
next_rel = nil
|
||||
klass = ""
|
||||
end
|
||||
|
||||
if @post.id != pool.post_id_array.first
|
||||
pool_html << template.link_to("«".html_safe, template.post_path(pool.post_id_array.first, :pool_id => pool.id), :class => "#{klass} first", :title => "to page 1")
|
||||
else
|
||||
pool_html << '<span class="first">«</span>'
|
||||
end
|
||||
|
||||
if pool.neighbors(@post).previous
|
||||
pool_html << template.link_to("‹ prev".html_safe, template.post_path(pool.neighbors(@post).previous, :pool_id => pool.id), :rel => prev_rel, :class => "#{klass} prev", :title => "to page #{pool.page_number(pool.neighbors(@post).previous)}")
|
||||
match_found = true
|
||||
else
|
||||
pool_html << '<span class="prev">‹ prev</span>'
|
||||
end
|
||||
|
||||
pool_html << ' <span class="pool-name ' + klass + '">'
|
||||
pool_html << template.link_to("Pool: #{pool.pretty_name}", template.pool_path(pool), :title => "page #{pool.page_number(@post.id)}/#{pool.post_count}")
|
||||
pool_html << '</span> '
|
||||
|
||||
if pool.neighbors(@post).next
|
||||
@next_post_in_pool = pool.neighbors(@post).next
|
||||
pool_html << template.link_to("next ›".html_safe, template.post_path(@next_post_in_pool, :pool_id => pool.id), :rel => next_rel, :class => "#{klass} next", :title => "to page #{pool.page_number(@next_post_in_pool)}")
|
||||
match_found = true
|
||||
else
|
||||
pool_html << '<span class="next">next ›</span>'
|
||||
end
|
||||
|
||||
if @post.id != pool.post_id_array.last
|
||||
pool_html << template.link_to("»".html_safe, template.post_path(pool.post_id_array.last, :pool_id => pool.id), :class => "#{klass} last", :title => "to page #{pool.post_count}")
|
||||
else
|
||||
pool_html << '<span class="last">»</span>'
|
||||
end
|
||||
|
||||
pool_html << "</li>"
|
||||
pool_html
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,7 +70,12 @@
|
||||
"url" : "<%= root_url %>"
|
||||
}
|
||||
</script>
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
|
||||
<% if request.domain =~ /donmai\.us/ %>
|
||||
<!-- this is only usable on danbooru.donmai.us -->
|
||||
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.4.2/css/all.css" integrity="sha384-zhaLg9HKxTxDljOPXpWHGn91XMDH+sYAWRSgvzHes290/ISyrNicGrd6BInTnx3L" crossorigin="anonymous">
|
||||
<% else %>
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
|
||||
<% end %>
|
||||
<script>
|
||||
if (typeof window.Danbooru !== "object") {
|
||||
window.Danbooru = {};
|
||||
|
||||
17
app/views/posts/partials/show/_embedded.html.erb
Normal file
17
app/views/posts/partials/show/_embedded.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<% if post.banblocked? -%>
|
||||
<p>The artist requested removal of this image.</p>
|
||||
<% elsif post.levelblocked? -%>
|
||||
<p><%= link_to("You need a gold account to see this image", new_user_upgrade_path) %>.</p>
|
||||
<% elsif post.safeblocked? -%>
|
||||
<p>This image is unavailable on safe mode (<%= Danbooru.config.app_name %>). Go to <%= link_to("Danbooru", "https://danbooru.donmai.us") %> or disable safe mode to view (<%= link_to("learn more", template.wiki_pages_path(title: "help:user_settings")) -%>).</p>
|
||||
<% elsif post.is_flash? -%>
|
||||
<%= render("posts/partials/show/flash", post: post) -%>
|
||||
<% elsif post.is_video? -%>
|
||||
<%= render("posts/partials/show/video", post: post) -%>
|
||||
<% elsif post.is_ugoira? -%>
|
||||
<%= render("posts/partials/show/ugoira", post: post) -%>
|
||||
<% elsif !post.is_image? -%>
|
||||
<%= render("posts/partials/show/download", post: post) -%>
|
||||
<% elsif post.is_image? -%>
|
||||
<%= render("posts/partials/show/image", post: post) -%>
|
||||
<% end %>
|
||||
@@ -5,7 +5,7 @@
|
||||
<% end %>
|
||||
|
||||
<% if post.pools.undeleted.any? %>
|
||||
<%= render "posts/partials/show/pools", :post => post %>
|
||||
<%= render "posts/partials/show/pool_list", post: post, pools: post.pools.undeleted.selected_first(params[:pool_id]) %>
|
||||
<% end %>
|
||||
|
||||
<% if post.favorite_groups(active_id=params[:favgroup_id]).any? %>
|
||||
|
||||
7
app/views/posts/partials/show/_pool_list.html.erb
Normal file
7
app/views/posts/partials/show/_pool_list.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<div id="pool-nav">
|
||||
<ul>
|
||||
<% pools.each do |pool| -%>
|
||||
<%= render "posts/partials/show/pool_list_item", pool: pool, post: post, selected: is_pool_selected?(pool) -%>
|
||||
<% end -%>
|
||||
</ul>
|
||||
</div>
|
||||
33
app/views/posts/partials/show/_pool_list_item.html.erb
Normal file
33
app/views/posts/partials/show/_pool_list_item.html.erb
Normal file
@@ -0,0 +1,33 @@
|
||||
<%= content_tag :li, id: "nav-link-for-pool-#{pool.id}", class: "pool-category-#{pool.category} pool-selected-#{selected}" do -%>
|
||||
<% if !pool.first_post?(post.id) -%>
|
||||
<%= link_to("«".html_safe, post_path(pool.first_post_id, pool_id: pool.id), class: "first", title: "to page 1") %>
|
||||
<% else -%>
|
||||
<span class="first">«</span>
|
||||
<% end -%>
|
||||
|
||||
<% pool.neighbors(post, :previous).tap do |previous_post_id| -%>
|
||||
<% if previous_post_id %>
|
||||
<%= link_to "‹ prev".html_safe, post_path(previous_post_id, pool_id: pool.id), rel: selected ? "prev" : nil, class: "prev", title: "to page #{pool.page_number(previous_post_id)}" -%>
|
||||
<% else -%>
|
||||
<span class="prev">‹ prev</span>
|
||||
<% end %>
|
||||
<% end -%>
|
||||
|
||||
<span class="pool-name">
|
||||
<%= link_to("Pool: #{pool.pretty_name}", pool_path(pool), title: "page #{pool.page_number(post.id)}/#{pool.post_count}") -%>
|
||||
</span>
|
||||
|
||||
<% if pool.neighbors(post, :next).tap do |previous_post_id| -%>
|
||||
<% if previous_post_id %>
|
||||
<%= link_to("next ›".html_safe, post_path(next_post_in_pool, pool_id: pool.id), rel: selected ? "next" : nil, class: "next", title: "to page #{pool.page_number(previous_post_id)}") -%>
|
||||
<% else -%>
|
||||
<span class="next">next ›</span>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
|
||||
<% if post.id != pool.post_id_array.last -%>
|
||||
<%= link_to("»".html_safe, post_path(pool.post_id_array.last, pool_id: pool.id), class: "last", title: "to page #{pool.post_count}") -%>
|
||||
<% else -%>
|
||||
<span class="last">»</span>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
@@ -1,3 +0,0 @@
|
||||
<div id="pool-nav">
|
||||
<%= @post.presenter.pool_html(self) %>
|
||||
</div>
|
||||
@@ -50,7 +50,7 @@
|
||||
<%= content_tag(:section, PostPresenter.data_attributes(@post).merge(id: "image-container")) do -%>
|
||||
<div id="note-container"></div>
|
||||
<div id="note-preview"></div>
|
||||
<%= @post.presenter.image_html(self) %>
|
||||
<%= render "posts/partials/show/embedded", post: @post %>
|
||||
<% end -%>
|
||||
|
||||
<% if CurrentUser.is_member? %>
|
||||
|
||||
Reference in New Issue
Block a user