Merge pull request #2793 from evazion/feat-copy-artist-commentary
Copy artist commentary (#2561, #2238)
This commit is contained in:
@@ -53,6 +53,91 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$("#add-commentary-dialog").dialog("open");
|
$("#add-commentary-dialog").dialog("open");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#fetch-commentary select[name="commentary_source_type"]').change(function() {
|
||||||
|
$("#fetch-commentary input").toggle();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#fetch-commentary button[type="submit"]').click(Danbooru.ArtistCommentary.fetch_commentary);
|
||||||
|
}
|
||||||
|
|
||||||
|
Danbooru.ArtistCommentary.fetch_commentary = function() {
|
||||||
|
Danbooru.notice("Fetching artist commentary...");
|
||||||
|
|
||||||
|
var type = $('#fetch-commentary select[name="commentary_source_type"]').val();
|
||||||
|
if (type === "Source") {
|
||||||
|
var source = $('#fetch-commentary input[name="commentary_source"]').val();
|
||||||
|
var commentary = Danbooru.ArtistCommentary.from_source(source);
|
||||||
|
} else if (type === "Post") {
|
||||||
|
var id = $('#fetch-commentary input[name="commentary_post_id"]').val();
|
||||||
|
var commentary = Danbooru.ArtistCommentary.from_post_id(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
commentary.then(Danbooru.ArtistCommentary.fill_commentary).done(function (success) {
|
||||||
|
var message = success ? "Artist commentary copied." : "Artist commentary copied; conflicting fields ignored.";
|
||||||
|
Danbooru.notice(message);
|
||||||
|
}).fail(function () {
|
||||||
|
Danbooru.notice("Fetching artist commentary failed.");
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
Danbooru.ArtistCommentary.from_source = function(source) {
|
||||||
|
return $.get("/source.json?url=" + encodeURIComponent(source)).then(function(data) {
|
||||||
|
return {
|
||||||
|
original_title: data.artist_commentary.title,
|
||||||
|
original_description: data.artist_commentary.description,
|
||||||
|
source: source,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Danbooru.ArtistCommentary.from_post_id = function(post_id) {
|
||||||
|
return $.get("/posts/" + encodeURIComponent(post_id) + "/artist_commentary.json").then(function(commentary) {
|
||||||
|
commentary.source = "post #" + post_id;
|
||||||
|
return commentary;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Danbooru.ArtistCommentary.fill_commentary = function(commentary) {
|
||||||
|
var description = Danbooru.ArtistCommentary.merge_commentaries($("#artist_commentary_original_description").val().trim(), commentary);
|
||||||
|
$("#artist_commentary_original_description").val(description);
|
||||||
|
|
||||||
|
// Update the other fields if they're blank. Return success if none conflict.
|
||||||
|
return [
|
||||||
|
Danbooru.ArtistCommentary.update_field($("#artist_commentary_original_title"), commentary.original_title),
|
||||||
|
Danbooru.ArtistCommentary.update_field($("#artist_commentary_translated_title"), commentary.translated_title),
|
||||||
|
Danbooru.ArtistCommentary.update_field($("#artist_commentary_translated_description"), commentary.translated_description),
|
||||||
|
].every(function (i) { return i; });
|
||||||
|
};
|
||||||
|
|
||||||
|
// If the new description conflicts with the current description, merge them
|
||||||
|
// by appending the new description onto the old one.
|
||||||
|
Danbooru.ArtistCommentary.merge_commentaries = function(description, commentary) {
|
||||||
|
if ((commentary.original_description && description) &&
|
||||||
|
(commentary.original_description != description)) {
|
||||||
|
return description
|
||||||
|
+ "\n\n[tn]\nSource: " + $("#post_source").val() + "\n[/tn]"
|
||||||
|
+ "\n\nh6. " + (commentary.original_title || "Untitled")
|
||||||
|
+ "\n\n" + commentary.original_description
|
||||||
|
+ "\n\n[tn]\nSource: " + commentary.source + "\n[/tn]";
|
||||||
|
} else {
|
||||||
|
return commentary.original_description || description;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update commentary field if it's blank, signal an error if there's a conflict.
|
||||||
|
Danbooru.ArtistCommentary.update_field = function($field, value) {
|
||||||
|
if ($field.val().trim() === "") {
|
||||||
|
$field.val(value);
|
||||||
|
return true;
|
||||||
|
} else if ($field.val().trim() !== value) {
|
||||||
|
$field.effect("shake", { direction: "up", distance: 5 });
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class ArtistCommentariesController < ApplicationController
|
class ArtistCommentariesController < ApplicationController
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
before_filter :member_only, :except => [:index]
|
before_filter :member_only, :except => [:index, :show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@commentaries = ArtistCommentary.search(params[:search]).order("artist_commentaries.id desc").paginate(params[:page], :limit => params[:limit])
|
@commentaries = ArtistCommentary.search(params[:search]).order("artist_commentaries.id desc").paginate(params[:page], :limit => params[:limit])
|
||||||
@@ -11,6 +11,18 @@ class ArtistCommentariesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
if params[:id]
|
||||||
|
@commentary = ArtistCommentary.find(params[:id])
|
||||||
|
else
|
||||||
|
@commentary = ArtistCommentary.find_by_post_id!(params[:post_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_with(@commentary) do |format|
|
||||||
|
format.html { redirect_to post_path(@commentary.post) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_or_update
|
def create_or_update
|
||||||
@artist_commentary = ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id])
|
@artist_commentary = ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id])
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,11 @@ module Sources
|
|||||||
:danbooru_name => artist_record.try(:first).try(:name),
|
:danbooru_name => artist_record.try(:first).try(:name),
|
||||||
:danbooru_id => artist_record.try(:first).try(:id),
|
:danbooru_id => artist_record.try(:first).try(:id),
|
||||||
:unique_id => unique_id,
|
:unique_id => unique_id,
|
||||||
:page_count => page_count
|
:page_count => page_count,
|
||||||
|
:artist_commentary => {
|
||||||
|
:title => artist_commentary_title,
|
||||||
|
:description => artist_commentary_desc,
|
||||||
|
}
|
||||||
}.to_json
|
}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
<p>If the artist of this image posted some interesting additional information about this work, you can copy it here. <%= link_to "View help.", wiki_pages_path(:search => {:title => "help:artist_commentary"}) %></p>
|
<p>If the artist of this image posted some interesting additional information about this work, you can copy it here. <%= link_to "View help.", wiki_pages_path(:search => {:title => "help:artist_commentary"}) %></p>
|
||||||
|
|
||||||
|
<form id="fetch-commentary" class="simple_form">
|
||||||
|
<div class="input">
|
||||||
|
<label>Copy from</label>
|
||||||
|
<%= select_tag :commentary_source_type, options_for_select(%w[Source Post]) %>
|
||||||
|
<%= text_field_tag :commentary_source, @post.source %>
|
||||||
|
<%= text_field_tag :commentary_post_id, (@post.parent.try(&:id) || @post.children.first.try(&:id)), :style => "display: none;" %>
|
||||||
|
<%= button_tag "Fetch" %>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<%= form_tag(create_or_update_artist_commentaries_path(:format => :js), :remote => true, :class => "simple_form", :method => :put) do %>
|
<%= form_tag(create_or_update_artist_commentaries_path(:format => :js), :remote => true, :class => "simple_form", :method => :put) do %>
|
||||||
<%= hidden_field :artist_commentary, :post_id, :value => @post.id %>
|
<%= hidden_field :artist_commentary, :post_id, :value => @post.id %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
<%= form_tag(artist_commentaries_path, :method => :get) do %>
|
<%= form_tag(artist_commentaries_path, :method => :get) do %>
|
||||||
<%= text_field "search", "name", :id => "quick_search_name", :placeholder => "Search commentary" %>
|
<%= text_field "search", "text_matches", :id => "quick_search_text_matches", :placeholder => "Search commentary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -5,5 +5,6 @@
|
|||||||
<li><%= link_to "Listing", artist_commentaries_path %></li>
|
<li><%= link_to "Listing", artist_commentaries_path %></li>
|
||||||
<li><%= link_to "Recent changes", artist_commentary_versions_path %></li>
|
<li><%= link_to "Recent changes", artist_commentary_versions_path %></li>
|
||||||
<li><%= link_to "Translation requests", artist_commentaries_path(:search => {:post_tags_match => "commentary_request"}) %></li>
|
<li><%= link_to "Translation requests", artist_commentaries_path(:search => {:post_tags_match => "commentary_request"}) %></li>
|
||||||
|
<li><%= link_to "Help", wiki_pages_path(:title => "help:artist_commentary") %></li>
|
||||||
</menu>
|
</menu>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
<h1>Search Artist Commentary</h1>
|
<h1>Search Artist Commentary</h1>
|
||||||
<%= form_tag(artist_commentaries_path, :method => :get, :class => "simple_form") do %>
|
<%= form_tag(artist_commentaries_path, :method => :get, :class => "simple_form") do %>
|
||||||
<%= search_field "text_matches", :label => "Text" %>
|
<%= search_field "text_matches", :label => "Text" %>
|
||||||
|
<%= search_field "post_tags_match", :label => "Tags" %>
|
||||||
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<label for="search_original_present">Original present?</label>
|
<label for="search_original_present">Original present?</label>
|
||||||
@@ -14,7 +15,6 @@
|
|||||||
<%= select "search", "translated_present", ["yes", "no"], :include_blank => true %>
|
<%= select "search", "translated_present", ["yes", "no"], :include_blank => true %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= search_field "post_tags_match", :label => "Tags" %>
|
|
||||||
<%= submit_tag "Search" %>
|
<%= submit_tag "Search" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -193,6 +193,10 @@ Rails.application.routes.draw do
|
|||||||
resources :pool_versions, :only => [:index]
|
resources :pool_versions, :only => [:index]
|
||||||
resources :posts do
|
resources :posts do
|
||||||
resources :events, :only => [:index], :controller => "post_events"
|
resources :events, :only => [:index], :controller => "post_events"
|
||||||
|
resource :artist_commentary, :only => [:index, :show] do
|
||||||
|
collection { put :create_or_update }
|
||||||
|
member { put :revert }
|
||||||
|
end
|
||||||
resources :votes, :controller => "post_votes", :only => [:create, :destroy]
|
resources :votes, :controller => "post_votes", :only => [:create, :destroy]
|
||||||
collection do
|
collection do
|
||||||
get :home
|
get :home
|
||||||
@@ -216,7 +220,7 @@ Rails.application.routes.draw do
|
|||||||
get :search
|
get :search
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :artist_commentaries do
|
resources :artist_commentaries, :only => [:index, :show] do
|
||||||
collection do
|
collection do
|
||||||
put :create_or_update
|
put :create_or_update
|
||||||
get :search
|
get :search
|
||||||
|
|||||||
Reference in New Issue
Block a user