BigW Consortium Gitlab

projects_controller.rb 1.66 KB
Newer Older
1
class Dashboard::ProjectsController < Dashboard::ApplicationController
2
  include ParamsBackwardCompatibility
3
  include RendersMemberAccess
4 5 6

  before_action :set_non_archived_param
  before_action :default_sorting
7

8
  def index
9
    @projects = load_projects(params.merge(non_public: true)).page(params[:page])
10

11
    respond_to do |format|
12
      format.html
13 14
      format.atom do
        load_events
15
        render layout: 'xml.atom'
16
      end
17 18
      format.json do
        render json: {
Josh Frye committed
19
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
20 21
        }
      end
22 23 24
    end
  end

25
  def starred
26 27
    @projects = load_projects(params.merge(starred: true))
      .includes(:forked_from_project, :tags).page(params[:page])
Josh Frye committed
28

29 30 31 32 33
    @groups = []

    respond_to do |format|
      format.html
      format.json do
Josh Frye committed
34
        render json: {
Josh Frye committed
35
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
Josh Frye committed
36
        }
37 38 39 40 41 42
      end
    end
  end

  private

43 44 45 46
  def default_sorting
    params[:sort] ||= 'latest_activity_desc'
    @sort = params[:sort]
  end
47

48
  def load_projects(finder_params)
49 50 51 52 53 54
    projects = ProjectsFinder
                .new(params: finder_params, current_user: current_user)
                .execute
                .includes(:route, :creator, namespace: [:route, :owner])

    prepare_projects_for_rendering(projects)
55 56
  end

57
  def load_events
58 59 60 61 62
    projects = load_projects(params.merge(non_public: true))

    @events = EventCollection
      .new(projects, offset: params[:offset].to_i, filter: event_filter)
      .to_a
63 64

    Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?)
65 66
  end
end