diff --git a/app/assets/javascripts/artist_commentaries.js b/app/assets/javascripts/artist_commentaries.js new file mode 100644 index 000000000..e36919706 --- /dev/null +++ b/app/assets/javascripts/artist_commentaries.js @@ -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(); +}); diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index 893a336fa..70324be53 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -450,3 +450,14 @@ div#unapprove-dialog { font-size: 0.9em; } } + +#add-commentary-dialog { + input { + width: 70%; + } + + textarea { + font-size: 1em; + width: 100%; + } +} diff --git a/app/controllers/artist_commentaries_controller.rb b/app/controllers/artist_commentaries_controller.rb new file mode 100644 index 000000000..59fb1feff --- /dev/null +++ b/app/controllers/artist_commentaries_controller.rb @@ -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 diff --git a/app/controllers/artist_commentary_versions_controller.rb b/app/controllers/artist_commentary_versions_controller.rb new file mode 100644 index 000000000..305c6f224 --- /dev/null +++ b/app/controllers/artist_commentary_versions_controller.rb @@ -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 diff --git a/app/models/artist_commentary.rb b/app/models/artist_commentary.rb new file mode 100644 index 000000000..8a769e626 --- /dev/null +++ b/app/models/artist_commentary.rb @@ -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 diff --git a/app/models/artist_commentary_version.rb b/app/models/artist_commentary_version.rb new file mode 100644 index 000000000..a6c2e23be --- /dev/null +++ b/app/models/artist_commentary_version.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index 1649d5af2..8c83d6517 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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" diff --git a/app/views/artist_commentaries/_form.html.erb b/app/views/artist_commentaries/_form.html.erb new file mode 100644 index 000000000..dc3ee1f47 --- /dev/null +++ b/app/views/artist_commentaries/_form.html.erb @@ -0,0 +1,19 @@ +

If the artist of this image posted some interesting additional information about this work, you can copy it here.

+ +<%= form_tag(create_or_update_artist_commentaries_path, :class => "simple_form", :method => :put) do %> +
+ <%= hidden_field :artist_commentary, :post_id, :value => @post.id %> + + + <%= text_field :artist_commentary, :original_title, :value => artist_commentary.try(:original_title) %> + + + <%= text_area :artist_commentary, :original_description, :size => "40x6", :value => artist_commentary.try(:original_description) %> + + + <%= text_field :artist_commentary, :translated_title, :value => artist_commentary.try(:translated_title) %> + + + <%= text_area :artist_commentary, :translated_description, :size => "40x6", :value => artist_commentary.try(:translated_description) %> +
+<% end %> diff --git a/app/views/artist_commentaries/_show.html.erb b/app/views/artist_commentaries/_show.html.erb new file mode 100644 index 000000000..bea17e45a --- /dev/null +++ b/app/views/artist_commentaries/_show.html.erb @@ -0,0 +1,26 @@ +

Artist's commentary

+ + + <% if artist_commentary.original_present? && artist_commentary.translated_present? %> +
  • Original
  • | +
  • Translated
  • + <% elsif artist_commentary.original_present? %> +
  • Original
  • + <% elsif artist_commentary.translated_present? %> +
  • Translated
  • + <% end %> +
    + +<% if artist_commentary.original_present? %> +
    +

    <%= artist_commentary.original_title %>

    +

    <%= format_text artist_commentary.original_description %>

    +
    +<% end %> + +<% if artist_commentary.translated_present? %> +
    +

    <%= artist_commentary.translated_title %>

    +

    <%= format_text artist_commentary.translated_description %>

    +
    +<% end %> diff --git a/app/views/artist_commentaries/revert.js.erb b/app/views/artist_commentaries/revert.js.erb new file mode 100644 index 000000000..345366b9b --- /dev/null +++ b/app/views/artist_commentaries/revert.js.erb @@ -0,0 +1 @@ +location.reload(); diff --git a/app/views/artist_commentary_versions/index.html.erb b/app/views/artist_commentary_versions/index.html.erb new file mode 100644 index 000000000..f0ef4e223 --- /dev/null +++ b/app/views/artist_commentary_versions/index.html.erb @@ -0,0 +1,58 @@ +
    +
    +

    Artist Commentary Changes

    + + + + + + + + <% if CurrentUser.is_janitor? %> + + <% end %> + + + <% if CurrentUser.is_member? %> + + <% end %> + + + + <% @commentary_versions.each do |commentary_version| %> + + + + + <% if CurrentUser.is_janitor? %> + + <% end %> + + + <% if CurrentUser.is_member? %> + + <% end %> + + <% end %> + +
    PostOriginalTranslatedIP AddressEdited ByDate
    <%= link_to commentary_version.post_id, post_path(commentary_version.post_id) %> +

    <%= h(commentary_version.original_title) %>

    + <%= h(commentary_version.original_description) %> +
    +

    <%= h(commentary_version.translated_title) %>

    + <%= h(commentary_version.translated_description) %> +
    + <%= commentary_version.updater_ip_addr %> + <%= link_to_user commentary_version.updater %><%= compact_time commentary_version.updated_at %> + <%= 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?" %> +
    + + <%= sequential_paginator(@commentary_versions) %> + + <%= render "posts/partials/common/secondary_links" %> +
    +
    + +<% content_for(:page_title) do %> + Artist Commentary Versions - <%= Danbooru.config.app_name %> +<% end %> diff --git a/app/views/posts/partials/show/_options.html.erb b/app/views/posts/partials/show/_options.html.erb index 622847249..66e5f9479 100644 --- a/app/views/posts/partials/show/_options.html.erb +++ b/app/views/posts/partials/show/_options.html.erb @@ -10,6 +10,7 @@ <% else %>
  • <%= link_to "Add notes", "#", :id => "translate", :title => "Shortcut is N" %>
  • <% end %> + <%= link_to "Add artist commentary", "#", :id => "add-commentary" %> <% if CurrentUser.is_builder? && post.has_notes? %>
  • <%= link_to "Copy all notes", "#", :id => "copy-notes" %>
  • <% end %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index edaeb6cbe..d1702e534 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -28,6 +28,7 @@
  • <%= fast_link_to "Notes", note_versions_path(:search => {:post_id => @post.id}) %>
  • <%= fast_link_to "Flags", post_flags_path(:search => {:post_id => @post.id}) %>
  • <%= fast_link_to "Appeals", post_appeals_path(:search => {:post_id => @post.id}) %>
  • +
  • <%= fast_link_to "Commentary", artist_commentary_versions_path(:search => {:post_id => @post.id}) %>
  • @@ -46,6 +47,12 @@ <%= @post.presenter.image_html(self) %> + <% if @post.artist_commentary && @post.artist_commentary.any_field_present? %> +
    + <%= render "artist_commentaries/show", :artist_commentary => @post.artist_commentary %> +
    + <% end %> + <% if @post.presenter.has_nav_links?(self) %> <%= render "posts/partials/show/nav_links", :post => @post, :position => "bottom" %> <% end %> @@ -92,6 +99,10 @@ + + <% content_for(:page_title) do %> diff --git a/config/routes.rb b/config/routes.rb index a6d732ed8..2cc61b2be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20131117150705_create_artist_commentaries.rb b/db/migrate/20131117150705_create_artist_commentaries.rb new file mode 100644 index 000000000..be865730c --- /dev/null +++ b/db/migrate/20131117150705_create_artist_commentaries.rb @@ -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 diff --git a/db/migrate/20131118153503_create_artist_commentary_versions.rb b/db/migrate/20131118153503_create_artist_commentary_versions.rb new file mode 100644 index 000000000..f0f89e4b4 --- /dev/null +++ b/db/migrate/20131118153503_create_artist_commentary_versions.rb @@ -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