module AdminHelper def format_bytes(bytes) return "—" if bytes.nil? units = %w[B KB MB GB TB] size = bytes.to_f unit = units.shift while size >= 1024 && units.any? size /= 1024 unit = units.shift end "#{size.round(size >= 10 ? 0 : 1)} #{unit}" end def format_duration_minutes(minutes) return "0 min" if minutes.to_i <= 0 hours = minutes / 60 mins = minutes % 60 hours.positive? ? "#{hours}h #{mins}m" : "#{mins} min" end def admin_session_watch_links(session) links = [] if session.matchlivetv_platform? links << { label: I18n.t("admin.common.live_page"), url: session.watch_page_url } end youtube = session.youtube_watch_url links << { label: "YouTube", url: youtube } if youtube.present? links end def admin_session_ingest_badge_class(node) case node.role when "home" then "badge--ingest-home" when "lab" then "badge--ingest-lab" when "cloud" then "badge--ingest-cloud" else "badge--paused" end end def admin_session_ingest_role_label(node) I18n.t("admin.sessions.ingest.role.#{node.role}", default: node.role.to_s.humanize) end def admin_regia_expires_label(iso_time) return if iso_time.blank? Time.zone.parse(iso_time).strftime("%d/%m/%Y %H:%M") rescue ArgumentError, TypeError nil end def announcement_status_badge(item) case item.status when "published" then item.severity == "critical" ? "live" : "ready" when "archived" then "paused" else "connecting" end end def announcement_window_label(item) start_label = item.starts_at&.in_time_zone&.strftime("%d/%m %H:%M") end_label = item.ends_at&.in_time_zone&.strftime("%d/%m %H:%M") if start_label && end_label "#{start_label} → #{end_label}" elsif start_label I18n.t("admin.announcements.window.from", time: start_label) elsif end_label I18n.t("admin.announcements.window.until", time: end_label) else I18n.t("admin.announcements.window.always") end end def announcement_channels_label(item) labels = item.selected_channels.map { |key| I18n.t("admin.announcements.channels.#{key}") } labels.presence&.join(" · ") || I18n.t("admin.common.dash") end end