Class: ProjectsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ProjectsController
- Defined in:
- app/controllers/projects_controller.rb
Instance Method Summary (collapse)
-
- (Object) index
returns projects in json based upon certain paramters.
Methods inherited from ApplicationController
Instance Method Details
- (Object) index
returns projects in json based upon certain paramters
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/projects_controller.rb', line 22 def index conditions(Project) if params[:organization] org = Org.where(:name => params[:organization]).first end if params[:project_name] @conditions << "projects.name = #{params[:project_name]}" unless org.nil? end @conditions << "orgs.org_id = #{org.id}" unless org.nil? @projects = Project.includes(:commits, :coders).where(@conditions.join(" and ")).order("created_at DESC") @coders = Coder.all @projects_by_coder_size = @projects.collect { |x| [x, x.coders.uniq.size]}.sort_by {|x| x[1]}.reverse @projects_by_commit_month_size = @projects.collect { |x| [x, x.commits.where("committed_date > '#{1.month.ago}'").size]}.sort_by {|x| x[1]}.reverse @projects_by_commit_week_size = @projects.collect { |x| [x, x.commits.where("committed_date > '#{1.week.ago}'").size]}.sort_by {|x| x[1]}.reverse @items = [:results => @projects.size, :page => (params[:page].nil? ? 1 : params[:page]), :total_items => @projects.size] respond_to do |format| format.json { render :json => [@items, @projects].to_json} format.html end end |