related tags: build html server-side instead of client-side.

This commit is contained in:
evazion
2018-10-12 21:18:15 -05:00
parent 5a05961bde
commit 4e2944ee06
13 changed files with 134 additions and 271 deletions

View File

@@ -0,0 +1 @@
Danbooru.Upload.fetch_data_manual();

View File

@@ -1,5 +1,5 @@
<%= button_tag "Related tags", :id => "related-tags-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
<%= button_tag "Related tags", type: :button, id: "related-tags-button", class: "related-tags-button ui-button ui-widget ui-corner-all sub gradient" %>
<% TagCategory.related_button_list.each do |category| %>
<%= button_tag "#{TagCategory.related_button_mapping[category]}", :id => "related-#{category}-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
<%= button_tag TagCategory.related_button_mapping[category], type: :button, "data-category": category, class: "related-tags-button ui-button ui-widget ui-corner-all sub gradient" %>
<% end %>

View File

@@ -1,5 +1,9 @@
<div id="related-tags-container">
<h1>Related Tags <a href="#" id="toggle-related-tags-link" style="display: none;">&laquo;</a></h1>
<div id="related-tags" class="related-tags">
</div>
<div id="related-tags-container" class="visible">
<h3>
Related Tags
<a href="#" id="show-related-tags-link">»</a>
<a href="#" id="hide-related-tags-link">«</a>
</h3>
<%= render "related_tags/related_tags" %>
</div>

View File

@@ -0,0 +1,40 @@
<%# related_tags %>
<div id="related-tags" class="related-tags">
<% if local_assigns[:related_tags] %>
<%= render "tag_column", tags: cookies[:recent_tags].to_s.split, title: "Recent" %>
<%= render "tag_column", tags: cookies[:favorite_tags].to_s.split, title: "Frequent" %>
<%= render "tag_column", tags: related_tags.tags, class: "general-related-tags-column", title: related_tags.pretty_name %>
<%= render "tag_column", tags: related_tags.translated_tags, title: "Translated Tags" %>
<%= render "tag_column", tags: related_tags.wiki_page_tags, class: "wiki-related-tags-column", title: link_to("wiki:#{related_tags.pretty_name}", show_or_new_wiki_pages_path(title: related_tags.query)) %>
<% related_tags.other_wiki_category_tags.each do |wiki| %>
<%= render "tag_column", tags: wiki.tags, class: "other-wiki-related-tags-column", title: link_to("wiki:#{wiki.pretty_title}", show_or_new_wiki_pages_path(title: wiki.title)) %>
<% end %>
<div class="tag-column wide-column artist-related-tags-column">
<h6>Artist</h6>
<% if related_tags.artists.size == 0 %>
none
<% else %>
<% related_tags.artists.each do |artist| %>
<%= TagSetPresenter.new([artist.name]).tag_list_html(name_only: true) %>
<ul>
<% artist.sorted_urls.each do |url| %>
<li>
<% if url.is_active %>
<%= external_link_to url.url, truncate: 30 %>
<%= link_to tag.i(class: "fas fa-minus-circle"), artist_url_path(id: url.id, artist_url: { is_active: false }), remote: true, method: :put, "data-confirm": "This will mark the URL as inactive. Continue?" %>
<% else %>
<del><%= truncate(url.url, length: 30) %></del>
<% end %>
</li>
<% end %>
</ul>
<% end %>
<% end %>
</div>
<% end %>
</div>

View File

@@ -0,0 +1,8 @@
<%# tags, title, class (optional) %>
<% if tags.present? %>
<div class="tag-column <%= local_assigns[:class] || "#{title.parameterize}-related-tags-column" %>">
<h6><%= title %></h6>
<%= TagSetPresenter.new(tags).tag_list_html(name_only: true) %>
</div>
<% end %>

View File

@@ -0,0 +1,2 @@
$("div#related-tags").replaceWith("<%= j render "related_tags", related_tags: @query %>");
Danbooru.RelatedTag.update_selected();

View File

@@ -1,8 +1,6 @@
$("#source-info").replaceWith("<%= j render "info", source: @source %>");
Danbooru.RelatedTag.recent_artists = <%= raw @source.artists.to_json(include: :sorted_urls) %>;
Danbooru.RelatedTag.translated_tags = <%= raw @source.translated_tags.to_json %>;
Danbooru.RelatedTag.build_all();
$(document).trigger("danbooru:update-source-data", <%= raw @source.to_json %>);
if ($("#c-uploads #a-new").length) {
$("#upload_artist_commentary_title").val(<%= raw @source.dtext_artist_commentary_title.to_json %>);