sources: factor out 'Fetch source data' box into view component.

This commit is contained in:
evazion
2021-02-25 18:54:15 -06:00
parent 0eea654a48
commit e1ef94faf7
13 changed files with 74 additions and 59 deletions

View File

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

View File

@@ -4,7 +4,7 @@
</div>
<% end %>
<%= render "sources/info" %>
<%= render_source_data(nil) %>
<%= edit_form_for(post, html: { id: "form" }) do |f| %>
<%= f.input :tags_query, as: :hidden, input_html: { id: nil, name: "tags_query", value: params[:q] } %>

View File

@@ -1,50 +0,0 @@
<%# source %>
<div id="source-info" class="p-4 mb-4">
<%= link_to "Fetch source data", source_path, id: "fetch-data-manual" %>
<%= spinner_icon(id: "source-info-loading") %>
<% 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 %>
<%= external_link_to @source.profile_url, @source.artist_name, id: "source-info-artist-profile" %>
<% if @source.artists.empty? %>
(<%= link_to "Create new artist", new_artist_path(artist: { source: @source.canonical_url }), 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_class(artist.tag) %></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><%= external_link_to href, tag %></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

@@ -1,4 +1,4 @@
$("#source-info").replaceWith("<%= j render "info", source: @source %>");
$(".source-data").replaceWith("<%= j render_source_data(@source) %>");
$(document).trigger("danbooru:update-source-data", {
source: <%= raw @source.to_json %>,

View File

@@ -15,7 +15,7 @@
<%= render "image" %>
<%= render "related_posts", source: @source %>
<%= render "sources/info" %>
<%= render_source_data(nil) %>
<div id="client-errors" class="error-messages ui-state-error ui-corner-all" style="display:none"></div>