Merge remote-tracking branch 'origin/dev_aliyun' into dev_aliyun

dev_ysm
杨树明 5 years ago
commit 03f5340c9f

@ -154,7 +154,19 @@ class ShixunsController < ApplicationController
## 获取顶部菜单
def menus
@repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).order("updated_at asc")
where_sql = ShixunTagRepertoire.where("shixun_tag_repertoires.tag_repertoire_id = tag_repertoires.id")
# 云上实验室过滤
unless current_laboratory.main_site?
where_sql = where_sql.joins('JOIN laboratory_shixuns ls ON ls.shixun_id = shixun_tag_repertoires.shixun_id')
end
where_sql = where_sql.select('1').to_sql
tags = TagRepertoire.where("EXISTS(#{where_sql})").distinct.includes(sub_repertoire: :repertoire)
@tags_map = tags.group_by(&:sub_repertoire)
@sub_reps_map = @tags_map.keys.group_by(&:repertoire)
# @repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).order("updated_at asc")
# respond_with @repertoires
render_json

@ -13,20 +13,36 @@
# ]
# }]
json.array! @repertoires do |rep|
json.id rep.id
json.name rep.name
json.sub_repertoires do
json.array! rep.sub_repertoires do |sub|
json.id sub.id
json.name sub.name
json.tags do
json.array! sub.tag_repertoires do |tag|
json.id tag.id
json.name tag.name
end
end
end
end
# json.array! @repertoires do |rep|
# json.id rep.id
# json.name rep.name
# json.sub_repertoires do
# json.array! rep.sub_repertoires do |sub|
# json.id sub.id
# json.name sub.name
# json.tags do
# json.array! sub.tag_repertoires do |tag|
# json.id tag.id
# json.name tag.name
# end
# end
# end
# end
# end
json.array! @sub_reps_map.keys do |rep|
json.extract! rep, :id, :name
json.sub_repertoires do
json.array! @sub_reps_map[rep] do |sub_rep|
json.extract! sub_rep, :id, :name
json.tags do
json.array! @tags_map[sub_rep] do |tag|
json.extract! tag, :id, :name
end
end
end
end
end

Loading…
Cancel
Save