Merge pull request #3878 from evazion/fix-fetch-source-rendering

Render "Fetch source data" box server-side
This commit is contained in:
Albert Yi
2018-09-11 12:08:48 -07:00
committed by GitHub
6 changed files with 86 additions and 92 deletions

View File

@@ -1,11 +1,50 @@
<div id="source-info">
<p><%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %></p>
<p><%= content_tag "span", "Loading source data...", :id => "loading-data", :style => "display: none;" %></p>
<p id="remote-size" style="display: none;"></p>
<p id="gallery-warning" style="display: none;"><%= content_tag "span", "Gallery. Tags may not apply to all images." %></p>
<%# source %>
<ul>
<li><strong>Artist</strong>: <a id="source-artist-profile"></a> (<span id="source-danbooru-artists"></span>)</li>
<li class="source-tags"><strong>Tags</strong>: <span id="source-tags"></span></li>
</ul>
<div id="source-info">
<%= link_to "Fetch source data", source_path, id: "fetch-data-manual" %>
<i id="source-info-loading" class="fas fa-spinner fa-spin"></i>
<% if @source.present? %>
<dl id="source-info-content">
<div id="source-info-artist">
<dt>Artist</dt>
<dd>
<% if @source.artist_name.blank? %>
<em>None</em>
<% else %>
<%= link_to @source.artist_name, @source.profile_url, id: "source-info-artist-profile" %>
<% if @source.artists.empty? %>
(<%= link_to "Create new artist", new_artist_path(artist: { name: @source.unique_id, other_names: @source.artist_name, url_string: [@source.profile_url, @source.normalize_for_artist_finder].uniq.sort.join("\n") }), id: "source-info-create-new-artist" %>)
<% else %>
(<ul id="source-info-translated-artists">
<% @source.artists.each do |artist| %>
<li><%= link_to artist.name, artist_path(artist), class: "tag-type-#{artist.category_name}" %></li>
<% end %>
</ul>)
<% end %>
<% end %>
</dd>
</div>
<div id="source-info-tags">
<dt>Tags</dt>
<dd>
<% if @source.tags.empty? %>
<em>None</em>
<% else %>
<ul>
<% @source.tags.each do |tag, href| %>
<li><%= link_to tag, href, rel: :nofollow %></li>
<% end %>
</ul>
<% if @source.image_urls.length > 1 %>
<p id="source-info-gallery-warning">Gallery. Tags may not apply to all images.</p>
<% end %>
<% end %>
</dd>
</li>
</dl>
<% end %>
</div>

View File

@@ -0,0 +1,11 @@
$("#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();
if ($("#c-uploads #a-new").length) {
$("#upload_artist_commentary_title").val(<%= raw @source.dtext_artist_commentary_title.to_json %>);
$("#upload_artist_commentary_desc").val(<%= raw @source.dtext_artist_commentary_desc.to_json %>);
Danbooru.Upload.toggle_commentary();
}