This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2021-10-14 20:44:59 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Dimension::SourcesDimension < Admin::Metrics::Dimension::BaseDimension
|
2023-06-05 16:52:33 +02:00
|
|
|
include Admin::Metrics::Dimension::QueryHelper
|
|
|
|
|
2021-10-14 20:44:59 +02:00
|
|
|
def key
|
|
|
|
'sources'
|
|
|
|
end
|
|
|
|
|
2022-02-22 15:27:08 +01:00
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_query
|
2023-06-05 16:52:33 +02:00
|
|
|
dimension_data_rows.map { |row| { key: row['name'] || 'web', human_key: row['name'] || I18n.t('admin.dashboard.website'), value: row['value'].to_s } }
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_array
|
|
|
|
[sql_query_string, { start_at: @start_at, end_at: @end_at, limit: @limit }]
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_query_string
|
|
|
|
<<~SQL.squish
|
2021-10-14 20:44:59 +02:00
|
|
|
SELECT oauth_applications.name, count(*) AS value
|
|
|
|
FROM users
|
|
|
|
LEFT JOIN oauth_applications ON oauth_applications.id = users.created_by_application_id
|
2023-06-05 16:52:33 +02:00
|
|
|
WHERE users.created_at BETWEEN :start_at AND :end_at
|
2021-10-14 20:44:59 +02:00
|
|
|
GROUP BY oauth_applications.name
|
|
|
|
ORDER BY count(*) DESC
|
2023-06-05 16:52:33 +02:00
|
|
|
LIMIT :limit
|
2021-10-14 20:44:59 +02:00
|
|
|
SQL
|
|
|
|
end
|
|
|
|
end
|