From c4521acb54e3a0e2386dd75e4f530d17d3e1ec59 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 16 Feb 2020 19:08:27 -0600 Subject: [PATCH] burs/index: format update scripts as dtext, same as forum. Format scripts on the BUR index page as dtext, the same way they're formatted in forum posts. This means that tags have colors and underlines, but they don't have post counts. Gathering post counts was too slow. --- app/helpers/bulk_update_requests_helper.rb | 95 ------------------- .../bulk_update_requests/_listing.html.erb | 6 +- 2 files changed, 5 insertions(+), 96 deletions(-) diff --git a/app/helpers/bulk_update_requests_helper.rb b/app/helpers/bulk_update_requests_helper.rb index 64d580586..ed90ad6e3 100644 --- a/app/helpers/bulk_update_requests_helper.rb +++ b/app/helpers/bulk_update_requests_helper.rb @@ -11,99 +11,4 @@ module BulkUpdateRequestsHelper category touhou -> copyright EOS end - - def approved?(command, antecedent, consequent) - return false unless CurrentUser.is_moderator? - - case command - when :create_alias - TagAlias.where(antecedent_name: antecedent, consequent_name: consequent, status: %w(active processing queued)).exists? - - when :create_implication - TagImplication.where(antecedent_name: antecedent, consequent_name: consequent, status: %w(active processing queued)).exists? - - when :remove_alias - TagAlias.where(antecedent_name: antecedent, consequent_name: consequent, status: "deleted").exists? || !TagAlias.where(antecedent_name: antecedent, consequent_name: consequent).exists? - - when :remove_implication - TagImplication.where(antecedent_name: antecedent, consequent_name: consequent, status: "deleted").exists? || !TagImplication.where(antecedent_name: antecedent, consequent_name: consequent).exists? - - when :change_category - tag, category = antecedent, consequent - Tag.where(name: tag, category: Tag.categories.value_for(category)).exists? - - else - false - end - end - - def failed?(command, antecedent, consequent) - return false unless CurrentUser.is_moderator? - - case command - when :create_alias - TagAlias.where(antecedent_name: antecedent, consequent_name: consequent).where("status like ?", "error: %").exists? - - when :create_implication - TagImplication.where(antecedent_name: antecedent, consequent_name: consequent).where("status like ?", "error: %").exists? - - else - false - end - end - - def script_with_line_breaks(script) - escaped_script = AliasAndImplicationImporter.tokenize(script).map do |cmd, arg1, arg2| - case cmd - when :create_alias, :create_implication, :remove_alias, :remove_implication, :mass_update, :change_category - if approved?(cmd, arg1, arg2) - btag = '' - etag = '' - elsif failed?(cmd, arg1, arg2) - btag = '' - etag = "" - else - btag = nil - etag = nil - end - end - - case cmd - when :create_alias - arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i - arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i - - "#{btag}create alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}" - - when :create_implication - arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i - arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i - - "#{btag}create implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}" - - when :remove_alias - arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i - arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i - - "#{btag}remove alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}" - - when :remove_implication - arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i - arg2_count = Tag.find_by_name(arg2).try(:post_count).to_i - - "#{btag}remove implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})#{etag}" - - when :mass_update - "#{btag}mass update " + link_to(arg1, posts_path(:tags => arg1)) + " -> " + link_to(arg2, posts_path(:tags => arg2)) + etag.to_s - - when :change_category - arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i - - "#{btag}category " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> (#{arg2})#{etag}" - - end - end.join("\n") - - escaped_script.gsub(/\n/m, "
").html_safe - end end diff --git a/app/views/bulk_update_requests/_listing.html.erb b/app/views/bulk_update_requests/_listing.html.erb index 5297f10eb..773ed4ae5 100644 --- a/app/views/bulk_update_requests/_listing.html.erb +++ b/app/views/bulk_update_requests/_listing.html.erb @@ -1,3 +1,5 @@ +<% dtext_data = DText.preprocess(bulk_update_requests.map(&:script_with_links)) %> + <%= table_for bulk_update_requests, width: "100%" do |t| %> <% t.column "Request" do |request| %> <% if request.forum_post.present? %> @@ -6,7 +8,9 @@

<%= link_to "Topic ##{request.forum_topic_id}: #{request.forum_topic.title}", request.forum_topic %>

<% end %> - <%= script_with_line_breaks(request.script) %> +
+ <%= format_text(request.script_with_links, data: dtext_data) %> +
<% end %> <% t.column "Votes" do |request| %> <% if request.forum_post.present? %>