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
|
2017-03-03 05:35:04 -05:00
|
|
|
include ParamsBackwardCompatibility
|
2017-12-07 04:11:41 -05:00
|
|
|
include RendersMemberAccess
|
2017-03-03 05:35:04 -05:00
|
|
|
|
|
|
|
before_action :set_non_archived_param
|
2016-03-04 10:11:33 -05:00
|
|
|
|
2014-07-23 05:03:49 -04:00
|
|
|
def index
|
2017-03-03 05:35:04 -05:00
|
|
|
params[:sort] ||= 'latest_activity_desc'
|
|
|
|
@sort = params[:sort]
|
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: {
|
|
|
|
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2014-07-23 05:03:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def trending
|
2017-03-03 05:35:04 -05:00
|
|
|
params[:trending] = true
|
|
|
|
@sort = params[:sort]
|
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: {
|
|
|
|
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
|
|
|
|
}
|
|
|
|
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: {
|
|
|
|
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-03-03 05:35:04 -05:00
|
|
|
def load_projects
|
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
|
|
|
|
|
2017-12-07 04:11:41 -05:00
|
|
|
projects = ProjectsFinder.new(current_user: current_user, params: params)
|
|
|
|
.execute
|
2018-11-13 22:15:17 -05:00
|
|
|
.includes(:route, :creator, :group, namespace: [:route, :owner])
|
2017-12-07 04:11:41 -05:00
|
|
|
.page(params[:page])
|
|
|
|
.without_count
|
|
|
|
|
|
|
|
prepare_projects_for_rendering(projects)
|
2017-03-15 07:58:41 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2014-07-23 05:03:49 -04:00
|
|
|
end
|