diff --git a/backend/app/controllers/admin/announcements_controller.rb b/backend/app/controllers/admin/announcements_controller.rb index 3566a52..9e495ca 100644 --- a/backend/app/controllers/admin/announcements_controller.rb +++ b/backend/app/controllers/admin/announcements_controller.rb @@ -11,7 +11,8 @@ module Admin kind: "info", severity: "info", status: "draft", - show_on_app: true, + show_on_android: true, + show_on_ios: true, show_on_web_public: true, show_on_web_private: true, dismissible: true @@ -55,12 +56,18 @@ module Admin params.require(:app_announcement).permit( :kind, :severity, :status, :title, :body, :action_url, :action_label, :dismissible, :starts_at, :ends_at, - :show_on_app, :show_on_web_public, :show_on_web_private + :show_on_android, :show_on_ios, :show_on_web_public, :show_on_web_private, + :android_title, :android_body, :android_action_url, :android_action_label, + :ios_title, :ios_body, :ios_action_url, :ios_action_label ).tap do |permitted| - %i[dismissible show_on_app show_on_web_public show_on_web_private].each do |key| + %i[dismissible show_on_android show_on_ios show_on_web_public show_on_web_private].each do |key| permitted[key] = ActiveModel::Type::Boolean.new.cast(permitted[key]) end - %i[starts_at ends_at action_url action_label].each do |key| + %i[ + starts_at ends_at action_url action_label + android_title android_body android_action_url android_action_label + ios_title ios_body ios_action_url ios_action_label + ].each do |key| permitted[key] = nil if permitted[key].blank? end end diff --git a/backend/app/controllers/admin/dashboard_controller.rb b/backend/app/controllers/admin/dashboard_controller.rb index c71c449..f23f76c 100644 --- a/backend/app/controllers/admin/dashboard_controller.rb +++ b/backend/app/controllers/admin/dashboard_controller.rb @@ -5,7 +5,7 @@ module Admin @host = HostMetrics.new.sample! @active_sessions = StreamSession .where(status: DashboardStats::ACTIVE_STATUSES) - .includes(match: :team) + .includes(:stream_node, match: :team) .order(started_at: :desc) @teams = Team.includes(:matches).order(:name).limit(8) end diff --git a/backend/app/controllers/admin/sessions_controller.rb b/backend/app/controllers/admin/sessions_controller.rb index 16410c6..f01c7ad 100644 --- a/backend/app/controllers/admin/sessions_controller.rb +++ b/backend/app/controllers/admin/sessions_controller.rb @@ -1,11 +1,11 @@ module Admin class SessionsController < Admin::BaseController def index - @sessions = StreamSession.includes(:match, :user).order(created_at: :desc).limit(50) + @sessions = StreamSession.includes(:stream_node, :user, match: :team).order(created_at: :desc).limit(50) end def show - @session = StreamSession.find(params[:id]) + @session = StreamSession.includes(:stream_node, match: :team).find(params[:id]) @events = @session.stream_events.recent.limit(50) end diff --git a/backend/app/controllers/api/v1/announcements_controller.rb b/backend/app/controllers/api/v1/announcements_controller.rb index a5e4335..a9fba73 100644 --- a/backend/app/controllers/api/v1/announcements_controller.rb +++ b/backend/app/controllers/api/v1/announcements_controller.rb @@ -5,7 +5,7 @@ module Api def index platform = params[:platform].to_s.presence - announcements = AppAnnouncement.for_app.newest + announcements = AppAnnouncement.for_platform(platform).newest render json: announcements.map { |item| item.as_api_json(platform: platform) } end end diff --git a/backend/app/helpers/admin_helper.rb b/backend/app/helpers/admin_helper.rb index 6ff7895..3e31adb 100644 --- a/backend/app/helpers/admin_helper.rb +++ b/backend/app/helpers/admin_helper.rb @@ -30,6 +30,19 @@ module AdminHelper 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? diff --git a/backend/app/models/app_announcement.rb b/backend/app/models/app_announcement.rb index e6fa4bd..a64df1a 100644 --- a/backend/app/models/app_announcement.rb +++ b/backend/app/models/app_announcement.rb @@ -3,10 +3,12 @@ class AppAnnouncement < ApplicationRecord SEVERITIES = %w[info warning critical].freeze STATUSES = %w[draft published archived].freeze CHANNELS = { - app: :show_on_app, + android: :show_on_android, + ios: :show_on_ios, web_public: :show_on_web_public, web_private: :show_on_web_private }.freeze + URL_FIELDS = %i[action_url android_action_url ios_action_url].freeze belongs_to :created_by_admin, class_name: "AdminAccount", optional: true @@ -14,10 +16,12 @@ class AppAnnouncement < ApplicationRecord validates :kind, inclusion: { in: KINDS } validates :severity, inclusion: { in: SEVERITIES } validates :status, inclusion: { in: STATUSES } - validates :title, length: { maximum: 120 } - validates :body, length: { maximum: 2000 } - validates :action_label, length: { maximum: 40 }, allow_blank: true - validates :action_url, format: { with: /\Ahttps?:\/\/.+/i, allow_blank: true } + validates :title, :android_title, :ios_title, length: { maximum: 120 }, allow_blank: true + validates :body, :android_body, :ios_body, length: { maximum: 2000 }, allow_blank: true + validates :action_label, :android_action_label, :ios_action_label, length: { maximum: 40 }, allow_blank: true + URL_FIELDS.each do |field| + validates field, format: { with: /\Ahttps?:\/\/.+/i, allow_blank: true } + end validate :ends_at_after_starts_at validate :at_least_one_channel @@ -38,7 +42,15 @@ class AppAnnouncement < ApplicationRecord end def self.for_app - for_channel(:app) + active_now.where("show_on_android = TRUE OR show_on_ios = TRUE") + end + + def self.for_platform(platform) + case platform.to_s + when "android" then for_channel(:android) + when "ios" then for_channel(:ios) + else for_app + end end def published? @@ -56,17 +68,19 @@ class AppAnnouncement < ApplicationRecord id: id, kind: kind, severity: severity, - title: title, - body: body, + title: copy_for(platform, :title), + body: copy_for(platform, :body), dismissible: dismissible, action_url: resolved_action_url(platform), - action_label: action_label.presence, + action_label: copy_for(platform, :action_label).presence, starts_at: starts_at&.iso8601, ends_at: ends_at&.iso8601 } end def resolved_action_url(platform) + override = platform_override(platform, :action_url) + return override if override.present? return action_url if action_url.present? return nil unless kind == "update" @@ -78,8 +92,23 @@ class AppAnnouncement < ApplicationRecord private + def copy_for(platform, field) + override = platform_override(platform, field) + override.presence || public_send(field) + end + + def platform_override(platform, field) + prefix = case platform.to_s + when "android" then :android + when "ios" then :ios + end + return if prefix.blank? + + public_send("#{prefix}_#{field}") + end + def at_least_one_channel - return if show_on_app? || show_on_web_public? || show_on_web_private? + return if show_on_android? || show_on_ios? || show_on_web_public? || show_on_web_private? errors.add(:base, :no_channel) end diff --git a/backend/app/views/admin/announcements/_form.html.erb b/backend/app/views/admin/announcements/_form.html.erb index 8e0c478..1e6a9bb 100644 --- a/backend/app/views/admin/announcements/_form.html.erb +++ b/backend/app/views/admin/announcements/_form.html.erb @@ -19,8 +19,12 @@
<%= t("admin.announcements.form.channels") %> +