app/controllers/cohortly/metrics_controller.rb in cohortly-0.0.5 vs app/controllers/cohortly/metrics_controller.rb in cohortly-0.0.6
- old
+ new
@@ -2,13 +2,20 @@
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 => { :$all => @metric_search.tags })
+ scope = scope.where(:tags => { :$in => @metric_search.tags })
end
- if @metric_search.user_id
+ 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
end