From c984251c2c6df0206b701b42e4db22566dfd4f60 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 20 Aug 2025 18:08:53 -0500 Subject: [PATCH] report interface refactor --- app/admin.rb | 17 +- .../131_add_site_file_path_to_reports.rb | 5 + models/report.rb | 5 + views/admin/reports.erb | 196 ++++++++++++++---- 4 files changed, 183 insertions(+), 40 deletions(-) create mode 100644 migrations/131_add_site_file_path_to_reports.rb diff --git a/app/admin.rb b/app/admin.rb index a2cf1934..c08b1476 100644 --- a/app/admin.rb +++ b/app/admin.rb @@ -7,12 +7,25 @@ end get '/admin/reports' do require_admin - @reports = Report.order(:created_at.desc).all + @page = params[:page] ? params[:page].to_i : 1 + @page = 1 if @page < 1 + @per_page = 51 + + @reports = Report.join(:sites, id: :site_id).where(sites__is_deleted: false, sites__is_banned: false).order(:reports__created_at.desc).select_all(:reports).paginate(@page, @per_page) + @pagination_dataset = @reports + erb :'admin/reports' end -post '/admin/reports' do +post '/admin/reports/:report_id/dismiss' do require_admin + content_type :json + + report = Report[params[:report_id]] + return {success: false, error: 'Report not found'}.to_json if report.nil? + + report.destroy + {success: true, message: 'Report dismissed'}.to_json end post '/admin/site_files/train' do diff --git a/migrations/131_add_site_file_path_to_reports.rb b/migrations/131_add_site_file_path_to_reports.rb new file mode 100644 index 00000000..6d2a8905 --- /dev/null +++ b/migrations/131_add_site_file_path_to_reports.rb @@ -0,0 +1,5 @@ +Sequel.migration do + change do + add_column :reports, :site_file_path, String + end +end \ No newline at end of file diff --git a/models/report.rb b/models/report.rb index da085532..78d0bbda 100644 --- a/models/report.rb +++ b/models/report.rb @@ -1,4 +1,9 @@ class Report < Sequel::Model many_to_one :site many_to_one :reporting_site, class: :Site + + def site_file + return nil unless site_file_path && site + site.site_files_dataset.where(path: site_file_path).first + end end \ No newline at end of file diff --git a/views/admin/reports.erb b/views/admin/reports.erb index 6d1e2cf0..51f2f86e 100644 --- a/views/admin/reports.erb +++ b/views/admin/reports.erb @@ -4,43 +4,163 @@ -
-
- <%== csrf_token_input_html %> - - - - - - - - <% @reports.each do |report| %> - - - - - - - <% end %> -
SiteTypeCommentsActions
- <%= report.site.title %> -
- Reported site screenshot -
- Reported <%= report.created_at.ago %> - <% if report.reporting_site %> - by <%= report.reporting_site.username %> - <% end %> -
<%= report.type %><%= report.comments[0...100] %> - -
- - -
- +
+
+ <%== flash_display %> + + <% if @reports.empty? %> +
+

No reports found.

+
+ <% else %> +
+ <% @reports.each_with_index do |report, index| %> +
+
+ <% + # Use the specific site_file_path from report, or default to index.html + if report.site_file_path && !report.site_file_path.empty? + screenshot_path = report.site_file_path + else + screenshot_path = 'index.html' + end + %> + +
+ + + + <% if report.type && !report.type.empty? %> + + <%= report.type.upcase %> + + <% end %> +
+ +

<%= report.site.username %>

+ + + <%= report.site.uri + '/' + screenshot_path %> + + + + Site Info • + Site Profile • + Site Root + + +

<%= report.type %> • <%= report.created_at.ago %><% if report.reporting_site %> • reported by <%= report.reporting_site.username %><% end %> +

+ +
+ <% if report.comments && !report.comments.empty? %> + <%= report.comments[0..200] %><%= report.comments.length > 200 ? '...' : '' %> + <% else %> + No comments + <% end %> +
+ + + <%= report.site.views.format_large_number %> views + + +
+ + <% if !report.site.is_nsfw %> + + <% end %> + + +
+ +
+
+ + <% if (index + 1) % 3 == 0 && index != @reports.length - 1 %> +
+ <% end %> + <% end %> + <%== erb :'_pagination', layout: false %> +
+ <% end %> +
+ + \ No newline at end of file