forked from e621ng/e621ng
Add artist commentary, fixes #2024
This commit is contained in:
parent
fab4e81669
commit
fd4c8c3cd3
62
app/assets/javascripts/artist_commentaries.js
Normal file
62
app/assets/javascripts/artist_commentaries.js
Normal file
@ -0,0 +1,62 @@
|
||||
(function() {
|
||||
Danbooru.ArtistCommentary = {};
|
||||
|
||||
Danbooru.ArtistCommentary.initialize_all = function() {
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
if ($("#original-artist-commentary").length && $("#translated-artist-commentary").length) {
|
||||
this.initialize_commentary_display_tabs();
|
||||
}
|
||||
|
||||
this.initialize_edit_commentary_dialog();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.ArtistCommentary.initialize_commentary_display_tabs = function() {
|
||||
$("#commentary-sections li a").click(function(e) {
|
||||
if (e.target.hash === "#original") {
|
||||
$("#original-artist-commentary").show();
|
||||
$("#translated-artist-commentary").hide();
|
||||
} else if (e.target.hash === "#translated") {
|
||||
$("#original-artist-commentary").hide();
|
||||
$("#translated-artist-commentary").show();
|
||||
}
|
||||
|
||||
$("#commentary-sections li").removeClass("active");
|
||||
$(e.target).parent("li").addClass("active");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#commentary-sections li:last-child").addClass("active");
|
||||
$("#original-artist-commentary").hide();
|
||||
}
|
||||
|
||||
Danbooru.ArtistCommentary.initialize_edit_commentary_dialog = function() {
|
||||
$("#add-commentary-dialog").dialog({
|
||||
autoOpen: false,
|
||||
width: 500,
|
||||
modal: true,
|
||||
buttons: {
|
||||
"Submit": function() {
|
||||
$("#add-commentary-dialog form").submit();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#add-commentary-dialog form').submit(function() {
|
||||
$('#add-commentary-dialog').dialog('close');
|
||||
});
|
||||
|
||||
$("#add-commentary").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#add-commentary-dialog").dialog("open");
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
Danbooru.ArtistCommentary.initialize_all();
|
||||
});
|
@ -450,3 +450,14 @@ div#unapprove-dialog {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
}
|
||||
|
||||
#add-commentary-dialog {
|
||||
input {
|
||||
width: 70%;
|
||||
}
|
||||
|
||||
textarea {
|
||||
font-size: 1em;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
23
app/controllers/artist_commentaries_controller.rb
Normal file
23
app/controllers/artist_commentaries_controller.rb
Normal file
@ -0,0 +1,23 @@
|
||||
class ArtistCommentariesController < ApplicationController
|
||||
respond_to :html, :xml, :json, :js
|
||||
before_filter :member_only
|
||||
|
||||
def create_or_update
|
||||
@artist_commentary = ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id])
|
||||
|
||||
if @artist_commentary
|
||||
@artist_commentary.update_attributes(params[:artist_commentary])
|
||||
else
|
||||
@artist_commentary = ArtistCommentary.create(params[:artist_commentary])
|
||||
end
|
||||
|
||||
respond_with(@artist_commentary.post)
|
||||
end
|
||||
|
||||
def revert
|
||||
@artist_commentary = ArtistCommentary.find_by_post_id(params[:id])
|
||||
@version = ArtistCommentaryVersion.find(params[:version_id])
|
||||
@artist_commentary.revert_to!(@version)
|
||||
respond_with(@artist_commentary)
|
||||
end
|
||||
end
|
12
app/controllers/artist_commentary_versions_controller.rb
Normal file
12
app/controllers/artist_commentary_versions_controller.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class ArtistCommentaryVersionsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def index
|
||||
@commentary_versions = ArtistCommentaryVersion.search(params[:search]).order("artist_commentary_versions.id desc").paginate(params[:page], :limit => params[:limit])
|
||||
respond_with(@commentary_versions) do |format|
|
||||
format.xml do
|
||||
render :xml => @commentary_versions.to_xml(:root => "artist-commentary-versions")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
41
app/models/artist_commentary.rb
Normal file
41
app/models/artist_commentary.rb
Normal file
@ -0,0 +1,41 @@
|
||||
class ArtistCommentary < ActiveRecord::Base
|
||||
attr_accessible :post_id, :original_description, :original_title, :translated_description, :translated_title
|
||||
validates_uniqueness_of :post_id
|
||||
belongs_to :post
|
||||
has_many :versions, :class_name => "ArtistCommentaryVersion", :foreign_key => :post_id, :primary_key => :post_id, :order => "artist_commentary_versions.id ASC"
|
||||
after_save :create_version
|
||||
|
||||
def original_present?
|
||||
original_title.present? || original_description.present?
|
||||
end
|
||||
|
||||
def translated_present?
|
||||
translated_title.present? || translated_description.present?
|
||||
end
|
||||
|
||||
def any_field_present?
|
||||
original_present? || translated_present?
|
||||
end
|
||||
|
||||
def create_version
|
||||
versions.create(
|
||||
:post_id => post_id,
|
||||
:original_title => original_title,
|
||||
:original_description => original_description,
|
||||
:translated_title => translated_title,
|
||||
:translated_description => translated_description
|
||||
)
|
||||
end
|
||||
|
||||
def revert_to(version)
|
||||
self.original_description = version.original_description
|
||||
self.original_title = version.original_title
|
||||
self.translated_description = version.translated_description
|
||||
self.translated_title = version.translated_title
|
||||
end
|
||||
|
||||
def revert_to!(version)
|
||||
revert_to(version)
|
||||
save!
|
||||
end
|
||||
end
|
29
app/models/artist_commentary_version.rb
Normal file
29
app/models/artist_commentary_version.rb
Normal file
@ -0,0 +1,29 @@
|
||||
class ArtistCommentaryVersion < ActiveRecord::Base
|
||||
before_validation :initialize_updater
|
||||
belongs_to :updater, :class_name => "User"
|
||||
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
|
||||
|
||||
def self.search(params)
|
||||
q = scoped
|
||||
params = {} if params.blank?
|
||||
|
||||
if params[:updater_id]
|
||||
q = q.where("updater_id = ?", params[:updater_id].to_i)
|
||||
end
|
||||
|
||||
if params[:post_id]
|
||||
q = q.where("post_id = ?", params[:post_id].to_i)
|
||||
end
|
||||
|
||||
q
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
end
|
@ -23,6 +23,7 @@ class Post < ActiveRecord::Base
|
||||
belongs_to :uploader, :class_name => "User"
|
||||
belongs_to :parent, :class_name => "Post"
|
||||
has_one :upload, :dependent => :destroy
|
||||
has_one :artist_commentary
|
||||
has_many :flags, :class_name => "PostFlag", :dependent => :destroy
|
||||
has_many :appeals, :class_name => "PostAppeal", :dependent => :destroy
|
||||
has_many :versions, :class_name => "PostVersion", :dependent => :destroy, :order => "post_versions.id ASC"
|
||||
|
19
app/views/artist_commentaries/_form.html.erb
Normal file
19
app/views/artist_commentaries/_form.html.erb
Normal file
@ -0,0 +1,19 @@
|
||||
<p>If the artist of this image posted some interesting additional information about this work, you can copy it here.</p>
|
||||
|
||||
<%= form_tag(create_or_update_artist_commentaries_path, :class => "simple_form", :method => :put) do %>
|
||||
<div class="input">
|
||||
<%= hidden_field :artist_commentary, :post_id, :value => @post.id %>
|
||||
|
||||
<label for="artist_commentary_original_title">Original title</label>
|
||||
<%= text_field :artist_commentary, :original_title, :value => artist_commentary.try(:original_title) %>
|
||||
|
||||
<label for="artist_commentary_original_description">Original description</label>
|
||||
<%= text_area :artist_commentary, :original_description, :size => "40x6", :value => artist_commentary.try(:original_description) %>
|
||||
|
||||
<label for="artist_commentary_translated_title">Translated title</label>
|
||||
<%= text_field :artist_commentary, :translated_title, :value => artist_commentary.try(:translated_title) %>
|
||||
|
||||
<label for="artist_commentary_translated_description">Translated description</label>
|
||||
<%= text_area :artist_commentary, :translated_description, :size => "40x6", :value => artist_commentary.try(:translated_description) %>
|
||||
</div>
|
||||
<% end %>
|
26
app/views/artist_commentaries/_show.html.erb
Normal file
26
app/views/artist_commentaries/_show.html.erb
Normal file
@ -0,0 +1,26 @@
|
||||
<h2>Artist's commentary</h2>
|
||||
|
||||
<menu id="commentary-sections">
|
||||
<% if artist_commentary.original_present? && artist_commentary.translated_present? %>
|
||||
<li><a href="#original">Original</a></li> |
|
||||
<li><a href="#translated">Translated</a></li>
|
||||
<% elsif artist_commentary.original_present? %>
|
||||
<li><b>Original</b></li>
|
||||
<% elsif artist_commentary.translated_present? %>
|
||||
<li><b>Translated</b></li>
|
||||
<% end %>
|
||||
</menu>
|
||||
|
||||
<% if artist_commentary.original_present? %>
|
||||
<section id="original-artist-commentary">
|
||||
<h3><%= artist_commentary.original_title %></h3>
|
||||
<p><%= format_text artist_commentary.original_description %></p>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
<% if artist_commentary.translated_present? %>
|
||||
<section id="translated-artist-commentary">
|
||||
<h3><%= artist_commentary.translated_title %></h3>
|
||||
<p><%= format_text artist_commentary.translated_description %></p>
|
||||
</section>
|
||||
<% end %>
|
1
app/views/artist_commentaries/revert.js.erb
Normal file
1
app/views/artist_commentaries/revert.js.erb
Normal file
@ -0,0 +1 @@
|
||||
location.reload();
|
58
app/views/artist_commentary_versions/index.html.erb
Normal file
58
app/views/artist_commentary_versions/index.html.erb
Normal file
@ -0,0 +1,58 @@
|
||||
<div id="c-artist-commentary-versions">
|
||||
<div id="a-index">
|
||||
<h1>Artist Commentary Changes</h1>
|
||||
|
||||
<table width="100%" class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%">Post</th>
|
||||
<th>Original</th>
|
||||
<th>Translated</th>
|
||||
<% if CurrentUser.is_janitor? %>
|
||||
<th width="10%">IP Address</th>
|
||||
<% end %>
|
||||
<th width="10%">Edited By</th>
|
||||
<th width="10%">Date</th>
|
||||
<% if CurrentUser.is_member? %>
|
||||
<th width="7%"></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @commentary_versions.each do |commentary_version| %>
|
||||
<tr>
|
||||
<td><%= link_to commentary_version.post_id, post_path(commentary_version.post_id) %></td>
|
||||
<td>
|
||||
<h3><%= h(commentary_version.original_title) %></h3>
|
||||
<%= h(commentary_version.original_description) %>
|
||||
</td>
|
||||
<td>
|
||||
<h3><%= h(commentary_version.translated_title) %></h3>
|
||||
<%= h(commentary_version.translated_description) %>
|
||||
</td>
|
||||
<% if CurrentUser.is_janitor? %>
|
||||
<td>
|
||||
<%= commentary_version.updater_ip_addr %>
|
||||
</td>
|
||||
<% end %>
|
||||
<td><%= link_to_user commentary_version.updater %></td>
|
||||
<td><%= compact_time commentary_version.updated_at %></td>
|
||||
<% if CurrentUser.is_member? %>
|
||||
<td>
|
||||
<%= link_to "Revert to", revert_artist_commentary_path(commentary_version.post_id, :version_id => commentary_version.id), :remote => true, :method => :put, :confirm => "Are you sure you want to revert to this version?" %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= sequential_paginator(@commentary_versions) %>
|
||||
|
||||
<%= render "posts/partials/common/secondary_links" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Artist Commentary Versions - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
@ -10,6 +10,7 @@
|
||||
<% else %>
|
||||
<li><%= link_to "Add notes", "#", :id => "translate", :title => "Shortcut is N" %></li>
|
||||
<% end %>
|
||||
<%= link_to "Add artist commentary", "#", :id => "add-commentary" %>
|
||||
<% if CurrentUser.is_builder? && post.has_notes? %>
|
||||
<li><%= link_to "Copy all notes", "#", :id => "copy-notes" %></li>
|
||||
<% end %>
|
||||
|
@ -28,6 +28,7 @@
|
||||
<li><%= fast_link_to "Notes", note_versions_path(:search => {:post_id => @post.id}) %></li>
|
||||
<li><%= fast_link_to "Flags", post_flags_path(:search => {:post_id => @post.id}) %></li>
|
||||
<li><%= fast_link_to "Appeals", post_appeals_path(:search => {:post_id => @post.id}) %></li>
|
||||
<li><%= fast_link_to "Commentary", artist_commentary_versions_path(:search => {:post_id => @post.id}) %></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
@ -46,6 +47,12 @@
|
||||
<%= @post.presenter.image_html(self) %>
|
||||
</section>
|
||||
|
||||
<% if @post.artist_commentary && @post.artist_commentary.any_field_present? %>
|
||||
<div id="artist-commentary">
|
||||
<%= render "artist_commentaries/show", :artist_commentary => @post.artist_commentary %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @post.presenter.has_nav_links?(self) %>
|
||||
<%= render "posts/partials/show/nav_links", :post => @post, :position => "bottom" %>
|
||||
<% end %>
|
||||
@ -92,6 +99,10 @@
|
||||
<div id="add-to-pool-dialog" title="Add to pool" style="display: none;">
|
||||
<%= render "pool_elements/new" %>
|
||||
</div>
|
||||
|
||||
<div id="add-commentary-dialog" title="Add artist commentary" style="display: none;">
|
||||
<%= render "artist_commentaries/form", :artist_commentary => @post.artist_commentary %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
|
@ -173,6 +173,15 @@ Danbooru::Application.routes.draw do
|
||||
get :search
|
||||
end
|
||||
end
|
||||
resources :artist_commentaries do
|
||||
collection do
|
||||
put :create_or_update
|
||||
end
|
||||
member do
|
||||
put :revert
|
||||
end
|
||||
end
|
||||
resources :artist_commentary_versions, :only => [:index]
|
||||
resource :related_tag, :only => [:show]
|
||||
match "reports/user_promotions" => "reports#user_promotions"
|
||||
resource :session do
|
||||
|
19
db/migrate/20131117150705_create_artist_commentaries.rb
Normal file
19
db/migrate/20131117150705_create_artist_commentaries.rb
Normal file
@ -0,0 +1,19 @@
|
||||
class CreateArtistCommentaries < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :artist_commentaries do |t|
|
||||
t.integer :post_id, :null => false
|
||||
t.text :original_title
|
||||
t.text :original_description
|
||||
t.text :translated_title
|
||||
t.text :translated_description
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :artist_commentaries, :post_id, :unique => true
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :artist_commentaries
|
||||
end
|
||||
end
|
@ -0,0 +1,24 @@
|
||||
class CreateArtistCommentaryVersions < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :artist_commentary_versions do |t|
|
||||
t.integer :post_id, :null => false
|
||||
|
||||
t.integer :updater_id, :null => false
|
||||
t.column :updater_ip_addr, "inet", :null => false
|
||||
|
||||
t.text :original_title
|
||||
t.text :original_description
|
||||
t.text :translated_title
|
||||
t.text :translated_description
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :artist_commentary_versions, :post_id
|
||||
add_index :artist_commentary_versions, :updater_id
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :artist_commentary_versions
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user