From f60cd409b6b3c685707db6191e1a91e08b8d2010 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Fri, 8 Apr 2022 18:40:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=85=8D=E7=BD=AE=E5=AD=90?= =?UTF-8?q?=E8=B5=9B=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/settings_controller.rb | 10 ++++++++++ app/models/site.rb | 2 +- app/views/settings/show.json.jbuilder | 6 ++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 68a5ad541..bd44b7fd1 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -4,6 +4,7 @@ class SettingsController < ApplicationController get_navbar get_add_menu get_common_menu + get_sub_competitions get_personal_menu get_third_party get_top_system_notification @@ -29,6 +30,15 @@ class SettingsController < ApplicationController end end + def get_sub_competitions + @sub_competitions = [] + Site.add.pluck(:key).each do |key| + hash = {} + hash.merge!("#{key.to_s}": Site.add.where(key: key).select(:id, :name, :url, :key).to_a.map(&:serializable_hash)) + @sub_competitions << hash + end + end + def get_common_menu @common = {} Site.common.select(:url, :key).each do |site| diff --git a/app/models/site.rb b/app/models/site.rb index 755fe3866..a8b725ef6 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -15,7 +15,7 @@ class Site < ApplicationRecord # add: 添加类链接 # personal: 个人名下类链接, # common: 普通链接 - enum site_type: { add: 0, personal: 1, common: 2 } + enum site_type: { add: 0, personal: 1, common: 2, competition: 3 } scope :by_search, -> (keyword){ where("name LIKE :keyword OR url LIKE :keyword", keyword: "%#{strip_param(keyword)}%") unless strip_param(keyword).blank? } scope :by_site_type, -> (site_type){ where(site_type: strip_param(site_type)) unless strip_param(site_type).blank? } diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index b5f163271..abe8207eb 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -51,6 +51,10 @@ json.setting do json.array! @add end + json.sub_competitions do + json.array! @sub_competitions + end + json.personal do json.array! @personal end @@ -66,6 +70,4 @@ json.setting do else json.system_notification nil end - - json.sub_competitions EduSetting.get("sub_competitions") end