mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 10:25:42 +08:00

This commit converts the `AdminReport` component, which is quite high complexity, to gjs. After this initial round, ideally this component would be broken up into smaller components because it is getting quite big now. Also in this commit: * Add an option to display the report description in a tooltip, which was the main way the description was shown until recently. We want to use this on the dashboard view mostly. * Move admin report "mode" definitions to the server-side Report model, inside a `Report::MODES` constant, collecting the modes defined in various places in the UI into one place * Refactor report code to refer to mode definitions * Add a `REPORT_MODES` constant in JS via javascript.rake and refactor JS to refer to the modes * Delete old admin report components that are no longer used (trust-level-counts, counts, per-day-counts) which were replaced by admin-report-counters a while ago * Add a new `registerReportModeComponent` plugin API, some plugins introduce their own modes (like AI's `emotion`) and components and we need a way to render them
43 lines
1.4 KiB
Ruby
43 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Reports::ConsolidatedPageViews
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
|
# NOTE: This report is superseded by "SiteTraffic". Eventually once
|
|
# use_legacy_pageviews is always false or no longer needed, and users
|
|
# no longer rely on the data in this old report in the transition period,
|
|
# we can delete this.
|
|
def report_consolidated_page_views(report)
|
|
filters = %w[page_view_logged_in page_view_anon page_view_crawler]
|
|
|
|
report.modes = [Report::MODES[:stacked_chart]]
|
|
|
|
requests =
|
|
filters.map do |filter|
|
|
color = report.colors[:turquoise]
|
|
color = report.colors[:lime] if filter == "page_view_anon"
|
|
color = report.colors[:purple] if filter == "page_view_crawler"
|
|
|
|
{
|
|
req: filter,
|
|
label: I18n.t("reports.consolidated_page_views.xaxis.#{filter}"),
|
|
color: color,
|
|
data: ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter]),
|
|
}
|
|
end
|
|
|
|
requests.each do |request|
|
|
request[:data] = request[:data]
|
|
.where("date >= ? AND date <= ?", report.start_date, report.end_date)
|
|
.order(date: :asc)
|
|
.group(:date)
|
|
.sum(:count)
|
|
.map { |date, count| { x: date, y: count } }
|
|
end
|
|
|
|
report.data = requests
|
|
end
|
|
end
|
|
end
|