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-09 13:42:32 +05:30
|
|
|
include PageLimiter
|
2017-08-17 22:00:37 +05:30
|
|
|
include ParamsBackwardCompatibility
|
2018-03-17 18:26:18 +05:30
|
|
|
include RendersMemberAccess
|
2019-12-04 20:38:33 +05:30
|
|
|
include SortingHelper
|
|
|
|
include SortingPreference
|
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
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
# Limit taken from https://gitlab.com/gitlab-org/gitlab/issues/38357
|
|
|
|
before_action only: [:index, :trending, :starred] do
|
|
|
|
limit_pages(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue_from PageOutOfBoundsError, with: :page_out_of_bounds
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def index
|
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
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
def load_project_counts
|
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
|
2020-03-09 13:42:32 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def load_projects
|
|
|
|
load_project_counts
|
2019-03-02 22:35:43 +05:30
|
|
|
|
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
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
def set_sorting
|
|
|
|
params[:sort] = set_sort_order
|
|
|
|
@sort = params[:sort]
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_sort_order
|
|
|
|
sort_value_latest_activity
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorting_field
|
|
|
|
Project::SORTING_PREFERENCE_FIELD
|
|
|
|
end
|
2020-03-09 13:42:32 +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
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|