Read about our upcoming Code of Conduct on this issue

projects_controller.rb 1.52 KB
Newer Older
Douwe Maan's avatar
Douwe Maan committed
1
class Explore::ProjectsController < Explore::ApplicationController
2
3
  include FilterProjects

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
5
  def index
    @projects = ProjectsFinder.new.execute(current_user)
6
7
8
    @tags = @projects.tags_on(:tags)
    @projects = @projects.tagged_with(params[:tag]) if params[:tag].present?
    @projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present?
9
    @projects = filter_projects(@projects)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
10
    @projects = @projects.sort(@sort = params[:sort])
11
    @projects = @projects.includes(:namespace).page(params[:page])
12
13
14
15
16
17
18
19
20

    respond_to do |format|
      format.html
      format.json do
        render json: {
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
        }
      end
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
21
22
23
  end

  def trending
24
    @projects = filter_projects(Project.trending)
25
    @projects = @projects.page(params[:page])
26
27
28
29
30
31
32
33
34

    respond_to do |format|
      format.html
      format.json do
        render json: {
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
        }
      end
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
35
  end
36
37

  def starred
Josh Frye's avatar
Josh Frye committed
38
    @projects = ProjectsFinder.new.execute(current_user)
39
    @projects = filter_projects(@projects)
Josh Frye's avatar
Josh Frye committed
40
    @projects = @projects.reorder('star_count DESC')
41
    @projects = @projects.page(params[:page])
42
43
44
45
46
47
48
49
50

    respond_to do |format|
      format.html
      format.json do
        render json: {
          html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
        }
      end
    end
51
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
52
end