blob: ef86d5f981ac8fe32db5c7b60e311d732ea29cba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# frozen_string_literal: true
class Explore::ProjectsController < Explore::ApplicationController
include ParamsBackwardCompatibility
include RendersMemberAccess
before_action :set_non_archived_param
def index
params[:sort] ||= 'latest_activity_desc'
@sort = params[:sort]
@projects = load_projects
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("explore/projects/_projects", projects: @projects)
}
end
end
end
def trending
params[:trending] = true
@sort = params[:sort]
@projects = load_projects
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("explore/projects/_projects", projects: @projects)
}
end
end
end
# rubocop: disable CodeReuse/ActiveRecord
def starred
@projects = load_projects.reorder('star_count DESC')
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("explore/projects/_projects", projects: @projects)
}
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def load_projects
@total_user_projects_count = ProjectsFinder.new(params: { non_public: true }, current_user: current_user).execute
@total_starred_projects_count = ProjectsFinder.new(params: { starred: true }, current_user: current_user).execute
projects = ProjectsFinder.new(current_user: current_user, params: params)
.execute
.includes(:route, :creator, :group, namespace: [:route, :owner])
.page(params[:page])
.without_count
prepare_projects_for_rendering(projects)
end
# rubocop: enable CodeReuse/ActiveRecord
end
|