Sha256: 0e829fd830137608774539491d6f1775b20cc435bcb3331455a29568396f4a4f

Contents?: true

Size: 928 Bytes

Versions: 7

Compression:

Stored size: 928 Bytes

Contents

class Cohortly::MetricsController < Cohortly::CohortlyController
  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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cohortly-0.0.93 app/controllers/cohortly/metrics_controller.rb
cohortly-0.0.92 app/controllers/cohortly/metrics_controller.rb
cohortly-0.0.9.1 app/controllers/cohortly/metrics_controller.rb
cohortly-0.0.9 app/controllers/cohortly/metrics_controller.rb
cohortly-0.0.8 app/controllers/cohortly/metrics_controller.rb
cohortly-0.0.7 app/controllers/cohortly/metrics_controller.rb
cohortly-0.0.6 app/controllers/cohortly/metrics_controller.rb