# frozen_string_literal: true module Admin class StreamConcurrencyViolationsController < Admin::BaseController def index @filters = { q: params[:q].to_s.strip.presence, devices_differ: params[:devices_differ].to_s == "1" } scope = StreamConcurrencyViolation.recent if @filters[:q] term = "%#{ActiveRecord::Base.sanitize_sql_like(@filters[:q])}%" scope = scope.where( "user_email ILIKE :term OR user_name ILIKE :term OR occupying_club_name ILIKE :term OR attempted_club_name ILIKE :term OR occupying_match_label ILIKE :term OR attempted_match_label ILIKE :term", term: term ) end scope = scope.two_devices if @filters[:devices_differ] @total_count = scope.count @violations = scope.limit(200) @lookback_count = StreamConcurrencyViolation.lookback.count @two_devices_count = StreamConcurrencyViolation.lookback.two_devices.count end end end