sources_dimension.rb 875 B

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::SourcesDimension < Admin::Metrics::Dimension::BaseDimension
  3. include Admin::Metrics::Dimension::QueryHelper
  4. def key
  5. 'sources'
  6. end
  7. protected
  8. def perform_query
  9. dimension_data_rows.map { |row| { key: row['name'] || 'web', human_key: row['name'] || I18n.t('admin.dashboard.website'), value: row['value'].to_s } }
  10. end
  11. def sql_array
  12. [sql_query_string, { start_at: @start_at, end_at: @end_at, limit: @limit }]
  13. end
  14. def sql_query_string
  15. <<~SQL.squish
  16. SELECT oauth_applications.name, count(*) AS value
  17. FROM users
  18. LEFT JOIN oauth_applications ON oauth_applications.id = users.created_by_application_id
  19. WHERE users.created_at BETWEEN :start_at AND :end_at
  20. GROUP BY oauth_applications.name
  21. ORDER BY count(*) DESC
  22. LIMIT :limit
  23. SQL
  24. end
  25. end