Change Index Category

This commit is contained in:
sylor_huang@126.com 2020-09-11 18:32:42 +08:00
parent f9bcc7e02b
commit 5bef80ee58
7 changed files with 43 additions and 12 deletions

View File

@ -385,7 +385,7 @@ class ApplicationController < ActionController::Base
def current_user
if Rails.env.development?
User.current = User.find 36480
User.current = User.find 1
else
User.current
end

View File

@ -7,7 +7,7 @@ class Oauth::EducoderController < Oauth::BaseController
token = params[:token]
::OauthEducoderForm.new({login: login, token: token, callback_url: callback_url}).validate!
open_user= OpenUsers::Educoder.find_by(uid: login)
if open_user.present? && open_user.user.present? && open_user.user.email_binded?

View File

@ -11,7 +11,11 @@ class ProjectCategoriesController < ApplicationController
# else
# projects = Project.visible
# end
@project_children_categories = ProjectCategory.descendants
projects = Project.no_anomory_projects.visible
@category_group_list = projects.joins(:project_category).group("project_categories.id", "project_categories.name").size
categories = projects.joins(:project_category).where(project_categories: {ancestry: nil}).group("project_categories.name", "project_categories.id").size.keys.to_h
extra_category_id = categories.delete("其他")
categories = categories.merge({"其他": extra_category_id}) if extra_category_id.present? #其他的放在最后面
@category_group_list = categories
end
end

View File

@ -44,7 +44,8 @@ class ProjectsController < ApplicationController
# projects = Project.visible
# end
projects = Project.no_anomory_projects.visible
@project_group_list = projects.group(:project_type).size
language_lists = projects.joins(:project_language).group("project_languages.name", "project_languages.id").size.keys.sort.to_h
@project_group_list = language_lists.delete_if { |k, v| k.blank? }
end
def update

View File

@ -2,4 +2,12 @@ class ProjectCategory < ApplicationRecord
include Projectable
has_ancestry
def self.descendants
where.not(ancestry: [nil, ""])
end
def self.get_children(target_id)
where(ancestry: target_id).pluck(:id,:name)
end
end

View File

@ -1,5 +1,18 @@
json.array! @category_group_list do |category,v|
json.id category[0]
json.name category[1]
json.projects_count v
# json.array! @category_group_list do |category,v|
# json.id category[0]
# json.name category[1]
# json.projects_count v
# end
json.array! @category_group_list do |k,v|
children_category = @project_children_categories.get_children(v)
json.children do
json.array! children_category do |cate|
json.id cate[0]
json.name cate[1]
json.parent_id v
end
end
json.id v
json.name k.to_s
end

View File

@ -1,5 +1,10 @@
json.array! @project_group_list do |type,v|
json.project_type type
json.name render_zh_project_type(type)
json.projects_count v
# json.array! @project_group_list do |type,v|
# json.project_type type
# json.name render_zh_project_type(type)
# json.projects_count v
# end
json.array! @project_group_list do |k,v|
json.name k
json.id v
end