dashboard_helper.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. module Admin::DashboardHelper
  3. def relevant_account_ip(account, ip_query)
  4. ips = account.user.present? ? account.user.ips.to_a : []
  5. matched_ip = begin
  6. ip_query_addr = IPAddr.new(ip_query)
  7. ips.find { |ip| ip_query_addr.include?(ip.ip) } || ips.first
  8. rescue IPAddr::Error
  9. ips.first
  10. end
  11. if matched_ip
  12. link_to matched_ip.ip, admin_accounts_path(ip: matched_ip.ip)
  13. else
  14. '-'
  15. end
  16. end
  17. def date_range(range)
  18. [l(range.first), l(range.last)]
  19. .join(' - ')
  20. end
  21. def relevant_account_timestamp(account)
  22. timestamp, exact = if account.user_current_sign_in_at && account.user_current_sign_in_at < 24.hours.ago
  23. [account.user_current_sign_in_at, true]
  24. elsif account.user_current_sign_in_at
  25. [account.user_current_sign_in_at, false]
  26. elsif account.user_pending?
  27. [account.user_created_at, true]
  28. elsif account.suspended_at.present? && account.local? && account.user.nil?
  29. [account.suspended_at, true]
  30. elsif account.last_status_at.present?
  31. [account.last_status_at, true]
  32. else
  33. [nil, false]
  34. end
  35. return '-' if timestamp.nil?
  36. return t('generic.today') unless exact
  37. content_tag(:time, l(timestamp), class: 'time-ago', datetime: timestamp.iso8601, title: l(timestamp))
  38. end
  39. end