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
|
2020-03-13 15:44:24 +05:30
|
|
|
include PageLimiter
|
2017-08-17 22:00:37 +05:30
|
|
|
include ParamsBackwardCompatibility
|
2018-03-17 18:26:18 +05:30
|
|
|
include RendersMemberAccess
|
2020-07-28 23:09:34 +05:30
|
|
|
include RendersProjectsList
|
2019-12-04 20:38:33 +05:30
|
|
|
include SortingHelper
|
|
|
|
include SortingPreference
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
MIN_SEARCH_LENGTH = 3
|
2021-03-08 18:12:59 +05:30
|
|
|
PAGE_LIMIT = 50
|
2020-12-08 15:28:05 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
before_action :set_non_archived_param
|
2019-12-04 20:38:33 +05:30
|
|
|
before_action :set_sorting
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
# For background information on the limit, see:
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/38357
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/262682
|
2020-03-13 15:44:24 +05:30
|
|
|
before_action only: [:index, :trending, :starred] do
|
2021-03-08 18:12:59 +05:30
|
|
|
limit_pages(PAGE_LIMIT)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
rescue_from PageOutOfBoundsError, with: :page_out_of_bounds
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :projects
|
2022-06-21 17:19:12 +05:30
|
|
|
# TODO: Set higher urgency after addressing https://gitlab.com/gitlab-org/gitlab/-/issues/357913
|
2022-07-16 23:28:13 +05:30
|
|
|
# and https://gitlab.com/gitlab-org/gitlab/-/issues/358945
|
|
|
|
urgency :low, [:index, :topics, :trending, :starred, :topic]
|
2022-06-21 17:19:12 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def index
|
2021-11-11 11:23:49 +05:30
|
|
|
show_alert_if_search_is_disabled
|
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
|
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
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
def topics
|
|
|
|
load_project_counts
|
|
|
|
load_topics
|
|
|
|
end
|
|
|
|
|
|
|
|
def topic
|
|
|
|
load_topic
|
|
|
|
|
|
|
|
return render_404 unless @topic
|
|
|
|
|
|
|
|
params[:topic] = @topic.name
|
|
|
|
@projects = load_projects
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def load_project_counts
|
2023-06-20 00:43:36 +05:30
|
|
|
@all_user_projects = ProjectsFinder.new(params: { non_public: true }, current_user: current_user).execute
|
|
|
|
@all_starred_projects = ProjectsFinder.new(params: { starred: true }, current_user: current_user).execute
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def load_projects
|
|
|
|
load_project_counts
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
finder_params = {
|
|
|
|
minimum_search_length: MIN_SEARCH_LENGTH,
|
|
|
|
not_aimed_for_deletion: true
|
|
|
|
}
|
|
|
|
|
|
|
|
projects = ProjectsFinder.new(current_user: current_user, params: params.merge(finder_params)).execute
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
projects = preload_associations(projects)
|
|
|
|
projects = projects.page(params[:page]).without_count
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
prepare_projects_for_rendering(projects)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
def load_topics
|
|
|
|
@topics = Projects::TopicsFinder.new(params: params.permit(:search)).execute.page(params[:page]).without_count
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_topic
|
2022-06-21 17:19:12 +05:30
|
|
|
@topic = Projects::Topic.find_by_name_case_insensitive(params[:topic_name])
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def preload_associations(projects)
|
2021-10-27 15:23:28 +05:30
|
|
|
projects.includes(:route, :creator, :group, :project_feature, :topics, namespace: [:route, :owner])
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
def set_sorting
|
|
|
|
params[:sort] = set_sort_order
|
|
|
|
@sort = params[:sort]
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_sort_order
|
2021-04-17 20:07:23 +05:30
|
|
|
sort_value_latest_activity
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def sorting_field
|
|
|
|
Project::SORTING_PREFERENCE_FIELD
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
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
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
def show_alert_if_search_is_disabled
|
|
|
|
return if current_user || params[:name].blank? && params[:search].blank? || !html_request? || Feature.disabled?(:disable_anonymous_project_search, type: :ops)
|
|
|
|
|
|
|
|
flash.now[:notice] = _('You must sign in to search for specific projects.')
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Explore::ProjectsController.prepend_mod_with('Explore::ProjectsController')
|