Files
grecia/app/components/admin/stats/chart_component.rb
Javi Martín 1edf0d937d Move stats graph partial to a component
Note we're naming it "chart" in order to avoid possible conflicts with
the "graph" view when we move it to a component.
2024-05-09 14:28:31 +02:00

28 lines
568 B
Ruby

class Admin::Stats::ChartComponent < ApplicationComponent
attr_reader :name, :event, :count
def initialize(name:, event:, count:)
@name = name
@event = event
@count = count
end
private
def chart_tag(opt = {})
opt[:data] ||= {}
opt[:data][:graph] = admin_api_stats_path(chart_data(opt))
tag.div(**opt)
end
def chart_data(opt = {})
data = nil
if opt[:id].present?
data = { opt[:id] => true }
elsif opt[:event].present?
data = { event: opt[:event] }
end
data
end
end