2018-09-23 15:44:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-30 13:06:18 -04:00
|
|
|
class Explore::ProjectsController < Explore::ApplicationController
|
2020-01-23 07:08:38 -05:00
|
|
|
include PageLimiter
|
2017-03-03 05:35:04 -05:00
|
|
|
include ParamsBackwardCompatibility
|
2017-12-07 04:11:41 -05:00
|
|
|
include RendersMemberAccess
|
2020-07-09 11:08:59 -04:00
|
|
|
include RendersProjectsList
|
2019-08-21 06:13:45 -04:00
|
|
|
include SortingHelper
|
|
|
|
include SortingPreference
|
2017-03-03 05:35:04 -05:00
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
MIN_SEARCH_LENGTH = 3
|
2020-12-17 13:10:14 -05:00
|
|
|
PAGE_LIMIT = 50
|
2020-12-07 16:10:08 -05:00
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
before_action :set_non_archived_param
|
2019-08-21 06:13:45 -04:00
|
|
|
before_action :set_sorting
|
2016-03-04 10:11:33 -05:00
|
|
|
|
2020-12-17 13:10:14 -05:00
|
|
|
# For background information on the limit, see:
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/38357
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/262682
|
2020-01-23 07:08:38 -05:00
|
|
|
before_action only: [:index, :trending, :starred] do
|
2020-12-17 13:10:14 -05:00
|
|
|
limit_pages(PAGE_LIMIT)
|
2020-01-23 07:08:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
rescue_from PageOutOfBoundsError, with: :page_out_of_bounds
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
feature_category :projects
|
|
|
|
|
2014-07-23 05:03:49 -04:00
|
|
|
def index
|
2017-08-10 09:01:38 -04:00
|
|
|
@projects = load_projects
|
2016-02-05 14:33:24 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
render json: {
|
2019-03-18 20:01:49 -04:00
|
|
|
html: view_to_html_string("explore/projects/_projects", projects: @projects)
|
2016-02-05 14:33:24 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2014-07-23 05:03:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def trending
|
2017-03-03 05:35:04 -05:00
|
|
|
params[:trending] = true
|
2017-08-10 09:01:38 -04:00
|
|
|
@projects = load_projects
|
2016-02-05 14:33:24 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
render json: {
|
2019-03-18 20:01:49 -04:00
|
|
|
html: view_to_html_string("explore/projects/_projects", projects: @projects)
|
2016-02-05 14:33:24 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2014-07-23 05:03:49 -04:00
|
|
|
end
|
2014-07-25 15:05:23 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2014-07-25 15:05:23 -04:00
|
|
|
def starred
|
2017-08-10 09:01:38 -04:00
|
|
|
@projects = load_projects.reorder('star_count DESC')
|
2016-02-05 14:33:24 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
render json: {
|
2019-03-18 20:01:49 -04:00
|
|
|
html: view_to_html_string("explore/projects/_projects", projects: @projects)
|
2016-02-05 14:33:24 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2014-07-25 15:05:23 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-15 07:58:41 -04:00
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
private
|
2017-03-15 07:58:41 -04:00
|
|
|
|
2020-01-23 07:08:38 -05:00
|
|
|
def load_project_counts
|
2018-12-07 05:05:17 -05:00
|
|
|
@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
|
2020-01-23 07:08:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_projects
|
|
|
|
load_project_counts
|
2018-12-07 05:05:17 -05:00
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
projects = ProjectsFinder.new(current_user: current_user, params: params.merge(minimum_search_length: MIN_SEARCH_LENGTH)).execute
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
projects = preload_associations(projects)
|
|
|
|
projects = projects.page(params[:page]).without_count
|
2017-12-07 04:11:41 -05:00
|
|
|
|
|
|
|
prepare_projects_for_rendering(projects)
|
2017-03-15 07:58:41 -04:00
|
|
|
end
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def preload_associations(projects)
|
2020-07-17 11:09:13 -04:00
|
|
|
projects.includes(:route, :creator, :group, :project_feature, namespace: [:route, :owner])
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2019-08-21 06:13:45 -04:00
|
|
|
|
|
|
|
def set_sorting
|
|
|
|
params[:sort] = set_sort_order
|
|
|
|
@sort = params[:sort]
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_sort_order
|
2021-02-25 19:11:20 -05:00
|
|
|
sort_value_latest_activity
|
2019-08-21 06:13:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def sorting_field
|
|
|
|
Project::SORTING_PREFERENCE_FIELD
|
|
|
|
end
|
2020-01-23 07:08:38 -05:00
|
|
|
|
|
|
|
def page_out_of_bounds(error)
|
|
|
|
load_project_counts
|
|
|
|
@max_page_number = error.message
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
render "page_out_of_bounds", status: :bad_request
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
html: view_to_html_string("explore/projects/page_out_of_bounds")
|
|
|
|
}, status: :bad_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-23 05:03:49 -04:00
|
|
|
end
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
Explore::ProjectsController.prepend_if_ee('EE::Explore::ProjectsController')
|