mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-21 20:25:45 +08:00
Merge branch 'develop' of https://git.trustie.net/Gitlink/forgeplus into develop
This commit is contained in:
@@ -5,7 +5,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||
def index
|
||||
sort_by = ProjectCategory.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
q = ProjectCategory.ransack(name_cont: params[:name])
|
||||
q = ProjectCategory.includes(:projects).ransack(name_cont: params[:name])
|
||||
project_categories = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@project_categories = paginate(project_categories)
|
||||
|
||||
@@ -22,7 +22,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||
max_position_items = ProjectCategory.select(:id, :position).pluck(:position).reject!(&:blank?)
|
||||
max_position = max_position_items.present? ? max_position_items.max.to_i : 0
|
||||
|
||||
@project_category = ProjectCategory.new(name: @name,position: max_position)
|
||||
@project_category = ProjectCategory.new(name: @name,position: max_position, pinned_index: params[:project_category][:pinned_index].to_i)
|
||||
if @project_category.save
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '创建成功'
|
||||
@@ -33,7 +33,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||
end
|
||||
|
||||
def update
|
||||
if @project_category.update_attribute(:name, @name)
|
||||
if @project_category.update_attributes({name: @name, pinned_index: params[:project_category][:pinned_index].to_i}) && save_image_file(params[:logo], 'logo')
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '更新成功'
|
||||
else
|
||||
@@ -43,7 +43,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @project_language.destroy
|
||||
if @project_category.destroy
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = "删除成功"
|
||||
else
|
||||
@@ -80,4 +80,12 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||
flash[:danger] = '分类已存在'
|
||||
end
|
||||
end
|
||||
|
||||
def save_image_file(file, type)
|
||||
return unless file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
|
||||
|
||||
file_path = Util::FileManage.source_disk_filename(@project_category, type)
|
||||
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||
Util.write_file(file, file_path)
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,5 @@
|
||||
class Admins::ProjectsController < Admins::BaseController
|
||||
before_action :find_project, only: [:edit, :update]
|
||||
|
||||
def index
|
||||
sort_by = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_on'
|
||||
@@ -8,6 +9,26 @@ class Admins::ProjectsController < Admins::BaseController
|
||||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||
end
|
||||
|
||||
def edit ;end
|
||||
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @project.update_attributes(project_update_params)
|
||||
format.html do
|
||||
redirect_to admins_projects_path
|
||||
flash[:sucess] = "更新成功"
|
||||
end
|
||||
format.js {render_ok}
|
||||
else
|
||||
format.html do
|
||||
redirect_to admins_projects_path
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
format.js {render_js_error}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
project = Project.find_by!(id: params[:id])
|
||||
ActiveRecord::Base.transaction do
|
||||
@@ -21,4 +42,13 @@ class Admins::ProjectsController < Admins::BaseController
|
||||
redirect_to admins_projects_path
|
||||
flash[:danger] = "删除失败"
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def project_update_params
|
||||
params.require(:project).permit(:is_pinned, :recommend, :recommend_index)
|
||||
end
|
||||
end
|
||||
@@ -22,6 +22,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||
@can_create_project = @organization.can_create_project?(current_user.id)
|
||||
@is_admin = can_edit_org?
|
||||
@is_member = @organization.is_member?(current_user.id)
|
||||
Cache::V2::OwnerCommonService.new(@organization.login, @organization.mail).read
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -68,8 +69,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||
def recommend
|
||||
recommend = %W(xuos Huawei_Technology openatom_foundation pkecosystem TensorLayer)
|
||||
|
||||
@organizations = Organization.with_visibility(%w(common))
|
||||
.where(login: recommend).select(:id, :login, :firstname, :lastname, :nickname)
|
||||
@organizations = Organization.includes(:organization_extension).where(organization_extensions: {recommend: true}).to_a.each_slice(group_size).to_a
|
||||
end
|
||||
|
||||
private
|
||||
@@ -80,6 +80,10 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||
:max_repo_creation, :nickname)
|
||||
end
|
||||
|
||||
def group_size
|
||||
params.fetch(:group_size, 4).to_i
|
||||
end
|
||||
|
||||
def password
|
||||
params.fetch(:password, "")
|
||||
end
|
||||
|
||||
@@ -5,6 +5,10 @@ class ProjectCategoriesController < ApplicationController
|
||||
@project_categories = q.result(distinct: true)
|
||||
end
|
||||
|
||||
def pinned_index
|
||||
@project_categories = ProjectCategory.where.not(pinned_index: 0).order(pinned_index: :desc)
|
||||
end
|
||||
|
||||
def group_list
|
||||
@project_categories = ProjectCategory.where('projects_count > 0').order(projects_count: :desc)
|
||||
# projects = Project.no_anomory_projects.visible
|
||||
|
||||
24
app/controllers/project_rank_controller.rb
Normal file
24
app/controllers/project_rank_controller.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class ProjectRankController < ApplicationController
|
||||
# 根据时间获取热门项目
|
||||
def index
|
||||
$redis_cache.zunionstore("recent-days-project-rank", get_timeable_key_names)
|
||||
@project_rank = $redis_cache.zrevrange("recent-days-project-rank", 0, 4, withscores: true)
|
||||
rescue Exception => e
|
||||
@project_rack = []
|
||||
end
|
||||
|
||||
private
|
||||
# 默认显示7天的
|
||||
def time
|
||||
params.fetch(:time, 7).to_i
|
||||
end
|
||||
|
||||
def get_timeable_key_names
|
||||
names_array = []
|
||||
(0...time).to_a.each do |i|
|
||||
date_time_string = (Date.today - i.days).to_s
|
||||
names_array << "v2-project-rank-#{date_time_string}"
|
||||
end
|
||||
names_array
|
||||
end
|
||||
end
|
||||
@@ -4,9 +4,9 @@ class ProjectsController < ApplicationController
|
||||
include ProjectsHelper
|
||||
include Acceleratorable
|
||||
|
||||
before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend about menu_list]
|
||||
before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend banner_recommend about menu_list]
|
||||
before_action :require_profile_completed, only: [:create, :migrate]
|
||||
before_action :load_repository, except: %i[index group_type_list migrate create recommend]
|
||||
before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend]
|
||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||
|
||||
@@ -30,8 +30,8 @@ class ProjectsController < ApplicationController
|
||||
def index
|
||||
scope = current_user.logged? ? Projects::ListQuery.call(params, current_user.id) : Projects::ListQuery.call(params)
|
||||
|
||||
# @projects = kaminari_paginate(scope)
|
||||
@projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
||||
@projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units))
|
||||
# @projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
||||
|
||||
category_id = params[:category_id]
|
||||
@total_count =
|
||||
@@ -190,6 +190,8 @@ class ProjectsController < ApplicationController
|
||||
end
|
||||
|
||||
def simple
|
||||
# 为了缓存活跃项目的基本信息,后续删除
|
||||
Cache::V2::ProjectCommonService.new(@project.id).reset
|
||||
json_response(@project, current_user)
|
||||
end
|
||||
|
||||
@@ -197,6 +199,10 @@ class ProjectsController < ApplicationController
|
||||
@projects = Project.recommend.includes(:repository, :project_category, :owner).order(visits: :desc)
|
||||
end
|
||||
|
||||
def banner_recommend
|
||||
@projects = Project.recommend.where.not(recommend_index: 0).includes(:project_category, :owner, :project_language).order(recommend_index: :desc)
|
||||
end
|
||||
|
||||
def about
|
||||
@project_detail = @project.project_detail
|
||||
@attachments = Array(@project_detail&.attachments) if request.get?
|
||||
|
||||
@@ -48,7 +48,7 @@ class RepositoriesController < ApplicationController
|
||||
|
||||
def entries
|
||||
@project.increment!(:visits)
|
||||
|
||||
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
|
||||
if @project.educoder?
|
||||
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
|
||||
else
|
||||
|
||||
24
app/controllers/user_rank_controller.rb
Normal file
24
app/controllers/user_rank_controller.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class UserRankController < ApplicationController
|
||||
# 根据时间获取热门开发者
|
||||
def index
|
||||
$redis_cache.zunionstore("recent-days-user-rank", get_timeable_key_names)
|
||||
@user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, 3, withscores: true)
|
||||
rescue Exception => e
|
||||
@user_rank = []
|
||||
end
|
||||
|
||||
private
|
||||
# 默认显示7天的
|
||||
def time
|
||||
params.fetch(:time, 7).to_i
|
||||
end
|
||||
|
||||
def get_timeable_key_names
|
||||
names_array = []
|
||||
(0...time).to_a.each do |i|
|
||||
date_time_string = (Date.today - i.days).to_s
|
||||
names_array << "v2-user-rank-#{date_time_string}"
|
||||
end
|
||||
names_array
|
||||
end
|
||||
end
|
||||
@@ -188,30 +188,32 @@ class Users::StatisticsController < Users::BaseController
|
||||
@project_languages_count = time_filter(Project.where(user_id: observed_user.id), 'created_on').joins(:project_language).group("project_languages.name").count
|
||||
@platform_project_languages_count = time_filter(Project, 'created_on').joins(:project_language).group("project_languages.name").count
|
||||
else
|
||||
@platform_result = Cache::V2::PlatformStatisticService.new.read
|
||||
@user_result = Cache::V2::UserStatisticService.new(observed_user.id).read
|
||||
# 用户被follow数量
|
||||
@follow_count = Cache::UserFollowCountService.call(observed_user)
|
||||
@platform_follow_count = Cache::PlatformFollowCountService.call
|
||||
@follow_count = @user_result["follow-count"].to_i
|
||||
@platform_follow_count = @platform_result["follow-count"].to_i
|
||||
# 用户pr数量
|
||||
@pullrequest_count = Cache::UserPullrequestCountService.call(observed_user)
|
||||
@platform_pullrequest_count = Cache::PlatformPullrequestCountService.call
|
||||
@pullrequest_count = @user_result["pullrequest-count"].to_i
|
||||
@platform_pullrequest_count = @platform_result["pullrequest-count"].to_i
|
||||
# 用户issue数量
|
||||
@issues_count = Cache::UserIssueCountService.call(observed_user)
|
||||
@platform_issues_count = Cache::PlatformIssueCountService.call
|
||||
@issues_count = @user_result["issue-count"].to_i
|
||||
@platform_issues_count = @platform_result["issue-count"].to_i
|
||||
# 用户总项目数
|
||||
@project_count = Cache::UserProjectCountService.call(observed_user)
|
||||
@platform_project_count = Cache::PlatformProjectCountService.call
|
||||
@project_count = @user_result["project-count"].to_i
|
||||
@platform_project_count = @platform_result["project-count"].to_i
|
||||
# 用户项目被fork数量
|
||||
@fork_count = Cache::UserProjectForkCountService.call(observed_user)
|
||||
@platform_fork_count = Cache::PlatformProjectForkCountService.call
|
||||
@fork_count = @user_result["fork-count"].to_i
|
||||
@platform_fork_count = @platform_result["fork-count"].to_i
|
||||
# 用户项目关注数
|
||||
@project_watchers_count = Cache::UserProjectWatchersCountService.call(observed_user)
|
||||
@platform_project_watchers_count = Cache::PlatformProjectWatchersCountService.call
|
||||
@project_watchers_count = @user_result["project-watcher-count"].to_i
|
||||
@platform_project_watchers_count = @platform_result["project-watcher-count"].to_i
|
||||
# 用户项目点赞数
|
||||
@project_praises_count = Cache::UserProjectPraisesCountService.call(observed_user)
|
||||
@platform_project_praises_count = Cache::PlatformProjectPraisesCountService.call
|
||||
@project_praises_count = @user_result["project-praise-count"].to_i
|
||||
@platform_project_praises_count = @platform_result["project-praise-count"].to_i
|
||||
# 用户不同语言项目数量
|
||||
@project_languages_count = Cache::UserProjectLanguagesCountService.call(observed_user)
|
||||
@platform_project_languages_count = Cache::PlatformProjectLanguagesCountService.call
|
||||
@project_languages_count = JSON.parse(@user_result["project-language"])
|
||||
@platform_project_languages_count = JSON.parse(@platform_result["project-language"])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -51,6 +51,8 @@ class UsersController < ApplicationController
|
||||
@projects_common_count = user_projects.common.size
|
||||
@projects_mirrior_count = user_projects.mirror.size
|
||||
@projects_sync_mirrior_count = user_projects.sync_mirror.size
|
||||
# 为了缓存活跃用户的基本信息,后续删除
|
||||
Cache::V2::OwnerCommonService.new(@user.login, @user.mail).read
|
||||
end
|
||||
|
||||
def watch_users
|
||||
|
||||
Reference in New Issue
Block a user