Aggiunge filtri/colonne (società, orari) e dettaglio leggibile; evita 422 CSRF su logout e non cancella le cover slate custom in sync prod. Co-authored-by: Cursor <cursoragent@cursor.com>
150 lines
4.1 KiB
Ruby
150 lines
4.1 KiB
Ruby
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_session_status_badge_class(status)
|
|
case status.to_s
|
|
when "live" then "badge--live"
|
|
when "connecting", "reconnecting" then "badge--connecting"
|
|
when "paused", "idle" then "badge--paused"
|
|
when "ended" then "badge--ended"
|
|
when "error" then "badge--error"
|
|
else "badge--paused"
|
|
end
|
|
end
|
|
|
|
def admin_datetime(time, with_seconds: false)
|
|
return I18n.t("admin.common.dash") if time.blank?
|
|
|
|
format = with_seconds ? "%d/%m/%Y %H:%M:%S" : "%d/%m/%Y %H:%M"
|
|
time.in_time_zone.strftime(format)
|
|
end
|
|
|
|
def admin_session_duration_label(session)
|
|
secs = session.total_duration_secs.to_i
|
|
if secs <= 0 && session.started_at
|
|
end_time = session.ended_at || (session.terminal? ? session.updated_at : Time.current)
|
|
secs = (end_time - session.started_at).to_i if end_time
|
|
end
|
|
return I18n.t("admin.common.dash") if secs <= 0
|
|
|
|
hours = secs / 3600
|
|
mins = (secs % 3600) / 60
|
|
rem = secs % 60
|
|
if hours.positive?
|
|
format("%dh %02dm %02ds", hours, mins, rem)
|
|
elsif mins.positive?
|
|
format("%dm %02ds", mins, rem)
|
|
else
|
|
"#{rem}s"
|
|
end
|
|
end
|
|
|
|
def admin_format_event_meta(metadata)
|
|
return content_tag(:span, I18n.t("admin.common.dash"), class: "muted") if metadata.blank?
|
|
|
|
pairs = metadata.to_h
|
|
return content_tag(:span, I18n.t("admin.common.dash"), class: "muted") if pairs.empty?
|
|
|
|
content_tag(:dl, class: "admin-event-meta") do
|
|
safe_join(
|
|
pairs.map do |key, value|
|
|
content_tag(:div, class: "admin-event-meta__row") do
|
|
content_tag(:dt, key.to_s) +
|
|
content_tag(:dd, admin_event_meta_value(value))
|
|
end
|
|
end
|
|
)
|
|
end
|
|
end
|
|
|
|
def admin_event_meta_value(value)
|
|
case value
|
|
when Hash, Array
|
|
content_tag(:code, value.to_json)
|
|
when TrueClass, FalseClass
|
|
value ? "true" : "false"
|
|
when NilClass
|
|
I18n.t("admin.common.dash")
|
|
else
|
|
value.to_s
|
|
end
|
|
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
|