Code to support EmberJS + Discourse Tutorial feature: Admin Reports

This commit is contained in:
Robin Ward
2013-02-27 22:39:42 -05:00
parent 416f981f92
commit dc8e1196fd
11 changed files with 213 additions and 0 deletions

37
app/models/report.rb Normal file
View File

@ -0,0 +1,37 @@
class Report
attr_accessor :type, :data
def initialize(type)
@type = type
@data = nil
end
def as_json
{
type: self.type,
title: I18n.t("reports.#{self.type}.title"),
xaxis: I18n.t("reports.#{self.type}.xaxis"),
yaxis: I18n.t("reports.#{self.type}.yaxis"),
data: self.data
}
end
def self.find(type)
report_method = :"report_#{type}"
return nil unless respond_to?(report_method)
# Load the report
report = Report.new(type)
send(report_method, report)
report
end
def self.report_visits(report)
report.data = []
UserVisit.by_day.each do |date, count|
report.data << {x: date, y: count}
end
end
end