2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/controllers/cohortly/metrics_controller.rb', line 2
def index
@metric_search = Cohortly::Metric.new(params[:cohortly_metric])
scope = Cohortly::Metric.sort(:created_at.desc)
if params[:cohortly_metric] && params[:cohortly_metric][:tags]
scope = scope.where(:tags => { :$in => @metric_search.tags })
end
if params[:cohortly_metric] && params[:cohortly_metric][:groups]
groups = params[:cohortly_metric][:groups]
scope = scope.where(:$where => "function() { return #{ groups.collect {|x| 'this.tags.indexOf("' + x + '") >= 0' }.join(' || ') }; }" )
end
if !@metric_search.user_id.blank?
scope = scope.where(:user_id => @metric_search.user_id)
end
if !@metric_search.username.blank?
scope = scope.where(:username => @metric_search.username)
end
@metrics = scope.paginate(:per_page => 200, :page => params[:page])
end
|