laboratory: shixun filter menu api

issues25489
p31729568 5 years ago
parent e4eb27622c
commit 04b040d3fe

@ -9,7 +9,7 @@ module LaboratoryHelper
end
def current_laboratory
@_current_laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1))
@_current_laboratory ||= (Laboratory.find_by_subdomain('hut' || request.subdomain) || Laboratory.find(1))
end
def default_laboratory

@ -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