diff --git a/app/assets/stylesheets/common/simple_form.scss b/app/assets/stylesheets/common/simple_form.scss index d2926f181..7e3b606a7 100644 --- a/app/assets/stylesheets/common/simple_form.scss +++ b/app/assets/stylesheets/common/simple_form.scss @@ -66,3 +66,12 @@ form.inline-form { } } } + +div.ui-dialog { + div.input { + input[type="text"] { + width: 100%; + max-width: 100%; + } + } +} diff --git a/app/controllers/post_replacements_controller.rb b/app/controllers/post_replacements_controller.rb index b9bd22984..8250329d1 100644 --- a/app/controllers/post_replacements_controller.rb +++ b/app/controllers/post_replacements_controller.rb @@ -23,6 +23,6 @@ class PostReplacementsController < ApplicationController private def create_params - params.require(:post_replacement).permit(:replacement_url) + params.require(:post_replacement).permit(:replacement_url, :replacement_file, :final_source) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 21ec75472..1723d70ab 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -101,6 +101,14 @@ module ApplicationHelper time_tag(time.strftime("%Y-%m-%d %H:%M"), time) end + def external_link_to(url) + if url =~ %r!\Ahttps?://!i + link_to url, {}, {rel: :nofollow} + else + url + end + end + def link_to_ip(ip) link_to ip, moderator_ip_addrs_path(:search => {:ip_addr => ip}) end diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index 6eea498e5..b41c314de 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -4,7 +4,7 @@ class PostReplacement < ApplicationRecord belongs_to :post belongs_to :creator, class_name: "User" before_validation :initialize_fields - attr_accessible :replacement_url + attr_accessor :replacement_file, :final_source def initialize_fields self.creator = CurrentUser.user @@ -23,7 +23,7 @@ class PostReplacement < ApplicationRecord end transaction do - upload = Upload.create!(source: replacement_url, rating: post.rating, tag_string: post.tag_string) + upload = Upload.create!(file: replacement_file, source: replacement_url, rating: post.rating, tag_string: post.tag_string) upload.process_upload upload.update(status: "completed", post_id: post.id) @@ -37,7 +37,7 @@ class PostReplacement < ApplicationRecord post.image_width = upload.image_width post.image_height = upload.image_height post.file_size = upload.file_size - post.source = upload.source + post.source = final_source.presence || upload.source post.tag_string = upload.tag_string rescale_notes update_ugoira_frame_data(upload) @@ -69,6 +69,10 @@ class PostReplacement < ApplicationRecord end module SearchMethods + def post_tags_match(query) + PostQueryBuilder.new(query).build(self.joins(:post)) + end + def search(params = {}) q = all @@ -77,7 +81,7 @@ class PostReplacement < ApplicationRecord end if params[:creator_name].present? - q = q.where(creator_name: User.name_to_id(params[:creator_name])) + q = q.where(creator_id: User.name_to_id(params[:creator_name])) end if params[:id].present? @@ -88,6 +92,10 @@ class PostReplacement < ApplicationRecord q = q.where(post_id: params[:post_id].split(",").map(&:to_i)) end + if params[:post_tags_match].present? + q = q.post_tags_match(params[:post_tags_match]) + end + q = q.order("created_at DESC") q diff --git a/app/views/post_replacements/_new.html.erb b/app/views/post_replacements/_new.html.erb index d226ca26d..f1fbed06b 100644 --- a/app/views/post_replacements/_new.html.erb +++ b/app/views/post_replacements/_new.html.erb @@ -1,5 +1,7 @@ <%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page).first.try(&:body), ragel: true) %> <%= simple_form_for(post_replacement, url: post_replacements_path(post_id: post_replacement.post_id), method: :post) do |f| %> - <%= f.input :replacement_url, label: "New Source", input_html: { value: "" } %> + <%= f.input :replacement_file, label: "File", as: :file %> + <%= f.input :replacement_url, label: "Replacement URL", hint: "The source URL to download the replacement from.", as: :string, input_html: { value: post_replacement.post.normalized_source } %> + <%= f.input :final_source, label: "Final Source", hint: "If present, the source field will be changed to this after replacement.", as: :string, input_html: { value: post_replacement.post.source } %> <% end %> diff --git a/app/views/post_replacements/index.html.erb b/app/views/post_replacements/index.html.erb new file mode 100644 index 000000000..b1cfaa87f --- /dev/null +++ b/app/views/post_replacements/index.html.erb @@ -0,0 +1,55 @@ +
| Post | +Source | +Replacer | +
|---|---|---|
| <%= PostPresenter.preview(post_replacement.post) %> | +
+
|
+
+ <%= compact_time post_replacement.created_at %>
+ by <%= link_to_user post_replacement.creator %> + <%= link_to "ยป", post_replacements_path(search: params[:search].merge(creator_name: post_replacement.creator.name)) %> + |
+