1
0

dashboard_helper.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 relevant_account_timestamp(account)
  18. timestamp, exact = if account.user_current_sign_in_at && account.user_current_sign_in_at < 24.hours.ago
  19. [account.user_current_sign_in_at, true]
  20. elsif account.user_current_sign_in_at
  21. [account.user_current_sign_in_at, false]
  22. elsif account.user_pending?
  23. [account.user_created_at, true]
  24. elsif account.last_status_at.present?
  25. [account.last_status_at, true]
  26. else
  27. [nil, false]
  28. end
  29. return '-' if timestamp.nil?
  30. return t('generic.today') unless exact
  31. content_tag(:time, l(timestamp), class: 'time-ago', datetime: timestamp.iso8601, title: l(timestamp))
  32. end
  33. end