From 2016feeb2833690d9d5f3ca8c4782f0bc37ce1d8 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 21 Apr 2015 17:50:36 -0700 Subject: [PATCH] show counts and post links for bulk update requests --- app/helpers/bulk_update_requests_helper.rb | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/helpers/bulk_update_requests_helper.rb b/app/helpers/bulk_update_requests_helper.rb index 3c19f847f..9f47ce7b9 100644 --- a/app/helpers/bulk_update_requests_helper.rb +++ b/app/helpers/bulk_update_requests_helper.rb @@ -1,6 +1,37 @@ module BulkUpdateRequestsHelper def script_with_line_breaks(script) - escaped_script = script.gsub(/&/, "&").gsub(//, ">") + escaped_script = AliasAndImplicationImporter.tokenize(script).map do |cmd, arg1, arg2| + 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 + + "create_alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})" + + 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 + + "create_implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})" + + 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 + + "remove_alias " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})" + + 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 + + "remove_implication " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> " + link_to(arg2, posts_path(:tags => arg2)) + " (#{arg2_count})" + + when :mass_update + "mass_update " + link_to(arg1, posts_path(:tags => arg1)) + " -> " + link_to(arg2, posts_path(:tags => arg2)) + + end + end.join("\n") + escaped_script.gsub(/\n/m, "
").html_safe end end