mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-20 19:55:56 +08:00
组织首页改版,增加精选、新闻
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
class Organizations::OrganizationsController < Organizations::BaseController
|
||||
before_action :require_login, except: [:index, :show, :recommend]
|
||||
before_action :require_profile_completed, only: [:create]
|
||||
before_action :require_login, except: [:index, :show, :recommend, :languages]
|
||||
# before_action :require_profile_completed, only: [:create]
|
||||
before_action :convert_image!, only: [:create, :update]
|
||||
before_action :load_organization, only: [:show, :update, :destroy]
|
||||
before_action :load_organization, only: [:show, :update, :destroy, :update_news, :update_memo, :update_other, :languages]
|
||||
before_action :check_user_can_edit_org, only: [:update, :destroy]
|
||||
|
||||
def index
|
||||
@@ -62,6 +62,45 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def update_news
|
||||
@organization.organization_extension.update_attributes!(news_banner_id: params[:news_banner_id],
|
||||
news_title: params[:news_title],
|
||||
news_url: params[:news_url],
|
||||
news_content: params[:news_content])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def update_memo
|
||||
@organization.organization_extension.update_attributes!(memo: params[:memo])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def update_other
|
||||
@organization.organization_extension.update_attributes!(news_banner_id: params[:news_banner_id],
|
||||
news_content: params[:news_content],
|
||||
news_title: params[:news_title],
|
||||
news_url: params[:news_url],
|
||||
memo: params[:memo])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def languages
|
||||
projects = @organization.projects
|
||||
projects_count = @organization.projects.count
|
||||
|
||||
languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}", :expires_in => 1.days) do
|
||||
total_languages(projects)
|
||||
end
|
||||
|
||||
languages_hash = languages_hash.sort { |x, y| y[1] <=> x[1] }
|
||||
sort_hash = Hash[*languages_hash.flatten]
|
||||
# Rails.logger.info "languages_hash=============#{sort_hash}"
|
||||
sort_hash= sort_hash.transform_values { |v|
|
||||
ActionController::Base.helpers.number_to_percentage((v / projects_count), precision: 1)
|
||||
}.select { |k, v| v != "0.0%" }
|
||||
render json: sort_hash
|
||||
end
|
||||
|
||||
def destroy
|
||||
tip_exception("密码不正确") unless current_user.check_password?(password)
|
||||
ActiveRecord::Base.transaction do
|
||||
@@ -144,5 +183,28 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||
# 更新对应所属分类下的项目数量(私有)
|
||||
project.project_category.decrement!(:private_projects_count, 1) if project.project_category.present?
|
||||
end
|
||||
|
||||
def total_languages(projects)
|
||||
languages_hash ={}
|
||||
projects.each do |p|
|
||||
result = Gitea::Repository::Languages::ListService.call(p.owner.login,
|
||||
p.identifier, current_user&.gitea_token)
|
||||
next unless result[:status] === :success
|
||||
total_byte_size = result[:body].values.sum
|
||||
hash = result[:body].transform_values { |v|
|
||||
(v * 100.0 / total_byte_size).to_f
|
||||
}
|
||||
|
||||
hash.each do |key,value|
|
||||
# Rails.logger.info "key=============#{key}:#{value}"
|
||||
if languages_hash.has_key?(key)
|
||||
languages_hash[key] = languages_hash[key] + value
|
||||
else
|
||||
languages_hash[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
languages_hash
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user