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.
This commit is contained in:
27
app/components/admin/stats/chart_component.rb
Normal file
27
app/components/admin/stats/chart_component.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
Reference in New Issue
Block a user