projects_controller.rb 1.7 KB
Newer Older
D
Douwe Maan 已提交
1
class Dashboard::ProjectsController < Dashboard::ApplicationController
2
  before_action :event_filter
3

4 5
  def index
    @projects = current_user.authorized_projects.sorted_by_activity.non_archived
6
    @projects = @projects.sort(@sort = params[:sort])
7
    @projects = @projects.includes(:namespace)
8 9 10 11 12 13 14

    terms = params['filter_projects']

    if terms.present?
      @projects = @projects.search(terms)
    end

J
Josh Frye 已提交
15
    @projects = @projects.page(params[:page]).per(PER_PAGE) if terms.blank?
16 17 18 19 20 21 22 23 24
    @last_push = current_user.recent_push

    respond_to do |format|
      format.html
      format.atom do
        event_filter
        load_events
        render layout: false
      end
25 26
      format.json do
        render json: {
J
Josh Frye 已提交
27
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
28 29
        }
      end
30 31 32
    end
  end

33 34 35 36
  def starred
    @projects = current_user.starred_projects
    @projects = @projects.includes(:namespace, :forked_from_project, :tags)
    @projects = @projects.sort(@sort = params[:sort])
J
Josh Frye 已提交
37 38 39 40 41 42 43

    terms = params['filter_projects']

    if terms.present?
      @projects = @projects.search(terms)
    end

J
Josh Frye 已提交
44
    @projects = @projects.page(params[:page]).per(PER_PAGE) if terms.blank?
45
    @last_push = current_user.recent_push
46 47 48 49 50 51
    @groups = []

    respond_to do |format|
      format.html

      format.json do
J
Josh Frye 已提交
52
        render json: {
J
Josh Frye 已提交
53
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
J
Josh Frye 已提交
54
        }
55 56 57 58 59 60 61
      end
    end
  end

  private

  def load_events
62
    @events = Event.in_projects(@projects)
63 64 65 66
    @events = @event_filter.apply_filter(@events).with_associations
    @events = @events.limit(20).offset(params[:offset] || 0)
  end
end