dashboard_helper.rb 1.1 KB

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