mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-12 10:24:22 +01:00
This may be a bit extreme. It's modeled after the ideal "rails way". In the controller, we now know the name of a single resource. It doesn't happen to be backed by a database table, but it does know all about the task of collecting stats, leaving the controller concerned with just munging params and rendering stuff. I called the resource `IndexPage`, to avoid the temptation of trying to reuse it, which can get pretty messy. Later, if a better abstraction appears, it should be fairly painless to alter.
43 lines
835 B
Ruby
43 lines
835 B
Ruby
module Stats
|
|
class IndexPage
|
|
|
|
attr_reader :user
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
def actions
|
|
@actions ||= Stats::Actions.new(user)
|
|
end
|
|
|
|
def totals
|
|
@totals ||= Stats::Totals.new(user)
|
|
end
|
|
|
|
def projects
|
|
@projects ||= Stats::Projects.new(user)
|
|
end
|
|
|
|
def contexts
|
|
@contexts ||= Stats::Contexts.new(user)
|
|
end
|
|
|
|
def tag_cloud
|
|
unless @tag_cloud
|
|
tags = Stats::TagCloudQuery.new(user).result
|
|
@tag_cloud = Stats::TagCloud.new(tags)
|
|
end
|
|
@tag_cloud
|
|
end
|
|
|
|
def tag_cloud_90days
|
|
unless @tag_cloud_90days
|
|
cutoff = 3.months.ago.beginning_of_day
|
|
tags = Stats::TagCloudQuery.new(user, cutoff).result
|
|
@tag_cloud_90days = Stats::TagCloud.new(tags)
|
|
end
|
|
@tag_cloud_90days
|
|
end
|
|
|
|
end
|
|
end
|