BigW Consortium Gitlab

projects_controller.rb 1.29 KB
Newer Older
1
class Explore::ProjectsController < Explore::ApplicationController
2 3 4
  include ParamsBackwardCompatibility

  before_action :set_non_archived_param
5

6
  def index
7 8
    params[:sort] ||= 'latest_activity_desc'
    @sort = params[:sort]
9
    @projects = load_projects
10 11 12 13 14 15 16 17 18

    respond_to do |format|
      format.html
      format.json do
        render json: {
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
        }
      end
    end
19 20 21
  end

  def trending
22 23
    params[:trending] = true
    @sort = params[:sort]
24
    @projects = load_projects
25 26 27 28 29 30 31 32 33

    respond_to do |format|
      format.html
      format.json do
        render json: {
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
        }
      end
    end
34
  end
35 36

  def starred
37
    @projects = load_projects.reorder('star_count DESC')
38 39 40 41 42 43 44 45 46

    respond_to do |format|
      format.html
      format.json do
        render json: {
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
        }
      end
    end
47
  end
48

49
  private
50

51
  def load_projects
52
    ProjectsFinder.new(current_user: current_user, params: params)
53 54 55 56
      .execute
      .includes(:route, namespace: :route)
      .page(params[:page])
      .without_count
57
  end
58
end