Module: Studio::AdminModels

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/studio/admin_models.rb

Constant Summary collapse

PREVIEW_LIMIT =
10
PER_PAGE =
25
TEAM_SORTS =
{
  "team" => "LOWER(teams.name)",
  "sport" => "LOWER(COALESCE(teams.sport, ''))",
  "league" => "LOWER(COALESCE(teams.league, ''))"
}.freeze
SHARED_TABLE_KEYS =
%w[teams arenas].freeze

Instance Method Summary collapse

Instance Method Details

#indexObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/concerns/studio/admin_models.rb', line 20

def index
  @sections = admin_model_configs.map do |key, config|
    scope = admin_model_scope_for(key)
    {
      key: key,
      label: config.fetch(:label),
      description: config.fetch(:description),
      count: scope.count,
      records: scope.limit(PREVIEW_LIMIT)
    }
  end

  render "studio/admin_models/index"
end

#showObject



35
36
37
38
39
40
41
42
# File 'app/controllers/concerns/studio/admin_models.rb', line 35

def show
  @page = [params[:page].to_i, 1].max
  @total_count = @scope.count
  @total_pages = [(@total_count.to_f / PER_PAGE).ceil, 1].max
  @records = @scope.offset((@page - 1) * PER_PAGE).limit(PER_PAGE)

  render "studio/admin_models/show"
end