diff --git a/app/controllers/upload_tags_report_controller.rb b/app/controllers/upload_tags_report_controller.rb new file mode 100644 index 000000000..a4235fb50 --- /dev/null +++ b/app/controllers/upload_tags_report_controller.rb @@ -0,0 +1,9 @@ +class UploadTagsReportController < ApplicationController + respond_to :html, :xml, :json + + def show + @user = User.find(params[:id]) + @upload_reports = UploadTagsReport.for_user(params[:id]).order("id desc").paginate(params[:page], :limit => params[:limit]) + respond_with(@upload_reports) + end +end diff --git a/app/helpers/upload_tags_report_helper.rb b/app/helpers/upload_tags_report_helper.rb new file mode 100644 index 000000000..f7a997853 --- /dev/null +++ b/app/helpers/upload_tags_report_helper.rb @@ -0,0 +1,12 @@ +module UploadTagsReportHelper + def diff_to_current(report) + html = [] + report.added_tags_array.each do |tag| + html << '+' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + '' + end + report.removed_tags_array.each do |tag| + html << '-' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + '' + end + return html.join(" ").html_safe + end +end diff --git a/app/models/upload_tags_report.rb b/app/models/upload_tags_report.rb new file mode 100644 index 000000000..ffbc89bbc --- /dev/null +++ b/app/models/upload_tags_report.rb @@ -0,0 +1,67 @@ +class UploadTagsReport < Post + + def readonly? + true + end + + module ApiMethods + + def as_json(options = {}) + options ||= {} + options[:only] ||= [:id] + super(options) + end + + def to_xml(options = {}, &block) + options ||= {} + options[:only] ||= [:id, :uploader_id] + super(options, &block) + end + + def method_attributes + [:uploader_tags, :added_tags, :removed_tags] + end + + end + + include ApiMethods + + def uploader_tags_array + @uploader_tags ||= begin + added_tags = [] + PostVersion.where(post_id: id, updater_id: uploader_id).each do |version| + added_tags += version.changes[:added_tags] + end + added_tags.uniq.sort + end + end + + def current_tags_array + latest_tags = tag_array + latest_tags << "rating:#{rating}" if rating.present? + latest_tags << "parent:#{parent_id}" if parent_id.present? + latest_tags << "source:#{source}" if source.present? + latest_tags + end + + def added_tags_array + current_tags_array - uploader_tags_array + end + + def removed_tags_array + uploader_tags_array - current_tags_array + end + + def uploader_tags + uploader_tags_array.join(' ') + end + + def added_tags + added_tags_array.join(' ') + end + + def removed_tags + removed_tags_array.join(' ') + end + +end \ No newline at end of file diff --git a/app/views/upload_tags_report/show.html.erb b/app/views/upload_tags_report/show.html.erb new file mode 100644 index 000000000..367067d59 --- /dev/null +++ b/app/views/upload_tags_report/show.html.erb @@ -0,0 +1,35 @@ +
+
+

Upload tag changes report for <%= @user.pretty_name %>

+ + + + + + + + + + <% @upload_reports.each do |upload_report| %> + + + + + <% end %> + +
Post IDTags added by uploaderTags changed by other users
<%= link_to(upload_report.id, post_path(:id => upload_report.id ))%> + <% upload_report.uploader_tags_array.each do |tag_name| %> + + <%= link_to(tag_name.tr("_", " "), posts_path(:tags => tag_name)) %> + + <% end %> + <%= diff_to_current(upload_report) %> +
+ <%= numbered_paginator(@upload_reports) %> +
+
+ + +<% content_for(:page_title) do %> + Upload tag changes for <%= @user.pretty_name %> - <%= Danbooru.config.app_name %> +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1deeef348..4c25fd8de 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + namespace :admin do resources :users, :only => [:edit, :update] resource :alias_and_implication_import, :only => [:new, :create] @@ -322,6 +323,8 @@ Rails.application.routes.draw do end end + resources :upload_tags_report, :only => [:show] + # aliases resources :wpages, :controller => "wiki_pages" resources :ftopics, :controller => "forum_topics"