You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

  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