debian-mirror-gitlab/app/controllers/explore/projects_controller.rb

71 lines
1.8 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
class Explore::ProjectsController < Explore::ApplicationController
2017-08-17 22:00:37 +05:30
include ParamsBackwardCompatibility
2018-03-17 18:26:18 +05:30
include RendersMemberAccess
2017-08-17 22:00:37 +05:30
before_action :set_non_archived_param
2016-06-02 11:05:42 +05:30
2014-09-02 18:07:02 +05:30
def index
2017-08-17 22:00:37 +05:30
params[:sort] ||= 'latest_activity_desc'
@sort = params[:sort]
2017-09-10 17:25:29 +05:30
@projects = load_projects
2016-04-02 18:10:28 +05:30
respond_to do |format|
format.html
format.json do
render json: {
2019-07-07 11:18:12 +05:30
html: view_to_html_string("explore/projects/_projects", projects: @projects)
2016-04-02 18:10:28 +05:30
}
end
end
2014-09-02 18:07:02 +05:30
end
def trending
2017-08-17 22:00:37 +05:30
params[:trending] = true
@sort = params[:sort]
2017-09-10 17:25:29 +05:30
@projects = load_projects
2016-04-02 18:10:28 +05:30
respond_to do |format|
format.html
format.json do
render json: {
2019-07-07 11:18:12 +05:30
html: view_to_html_string("explore/projects/_projects", projects: @projects)
2016-04-02 18:10:28 +05:30
}
end
end
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
def starred
2017-09-10 17:25:29 +05:30
@projects = load_projects.reorder('star_count DESC')
2016-04-02 18:10:28 +05:30
respond_to do |format|
format.html
format.json do
render json: {
2019-07-07 11:18:12 +05:30
html: view_to_html_string("explore/projects/_projects", projects: @projects)
2016-04-02 18:10:28 +05:30
}
end
end
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
private
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
def load_projects
2019-03-02 22:35:43 +05:30
@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
2018-03-17 18:26:18 +05:30
projects = ProjectsFinder.new(current_user: current_user, params: params)
.execute
2019-02-15 15:39:39 +05:30
.includes(:route, :creator, :group, namespace: [:route, :owner])
2018-03-17 18:26:18 +05:30
.page(params[:page])
.without_count
prepare_projects_for_rendering(projects)
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
end