forgeplus/app/controllers/settings_controller.rb

90 lines
2.5 KiB
Ruby
Raw Permalink Normal View History

2020-03-09 00:40:16 +08:00
class SettingsController < ApplicationController
def show
2021-03-22 17:58:15 +08:00
@old_projects_url = nil
2022-03-31 16:04:48 +08:00
get_navbar
2021-03-31 09:49:05 +08:00
get_add_menu
get_common_menu
2022-04-08 18:40:52 +08:00
get_sub_competitions
2021-03-31 09:49:05 +08:00
get_personal_menu
2021-04-01 18:01:51 +08:00
get_third_party
2021-10-12 16:34:00 +08:00
get_top_system_notification
2021-03-31 09:49:05 +08:00
end
private
2022-03-31 16:04:48 +08:00
def get_navbar
2022-03-31 16:18:16 +08:00
@navbar = default_laboratory.navbar
if User.current.logged?
2022-04-08 15:03:40 +08:00
pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false}
2022-03-31 16:18:16 +08:00
@navbar << pernal_index
2022-03-31 16:04:48 +08:00
end
end
2021-03-31 09:49:05 +08:00
def get_add_menu
@add = []
Site.add.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
hash = {}
site.each {|k, v|
2021-03-31 12:44:40 +08:00
hash.merge!("#{k}": get_site_url(k, v))
2021-03-31 09:49:05 +08:00
}
@add << hash
end
end
2022-04-08 18:40:52 +08:00
def get_sub_competitions
@sub_competitions = []
2022-04-08 18:51:01 +08:00
Site.competition.pluck(:key).uniq.each do |key|
2022-04-08 21:59:35 +08:00
hash = {"identifier": "#{key.to_s}"}
hash.merge!("list": Site.competition.where(key: key).select(:id, :name, :url, :key).to_a.map(&:serializable_hash))
2022-04-08 18:40:52 +08:00
@sub_competitions << hash
end
end
2021-03-31 09:49:05 +08:00
def get_common_menu
2021-03-31 12:44:40 +08:00
@common = {}
2021-03-31 13:35:40 +08:00
Site.common.select(:url, :key).each do |site|
2021-03-31 09:49:05 +08:00
next if site["url"].to_s.include?("current_user") && !User.current.logged?
2021-03-31 13:35:40 +08:00
@common.merge!("#{site["key"]}": append_http(reset_site_url(site["url"])))
2021-03-31 09:49:05 +08:00
end
end
2021-03-22 17:58:15 +08:00
2021-03-31 09:49:05 +08:00
def get_personal_menu
@personal = []
2021-03-23 11:42:22 +08:00
if User.current.logged?
Site.personal.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
hash = {}
site.each {|k, v|
2021-03-31 12:44:40 +08:00
hash.merge!("#{k}": get_site_url(k, v))
2021-03-23 11:42:22 +08:00
}
2021-03-31 09:49:05 +08:00
@personal << hash
2021-03-23 11:42:22 +08:00
end
end
2021-03-23 15:42:56 +08:00
end
2021-03-31 09:49:05 +08:00
2021-04-01 18:01:51 +08:00
def get_third_party
@third_party = []
@third_party << {
name: 'educoder',
2021-04-02 09:43:18 +08:00
url: EducoderOauth.oauth_url
2021-04-01 18:01:51 +08:00
}
end
2021-10-12 16:34:00 +08:00
def get_top_system_notification
@top_system_notification = SystemNotification.is_top.first
end
2021-04-01 18:01:51 +08:00
2021-03-31 12:44:40 +08:00
def get_site_url(key, value)
2021-04-01 15:04:17 +08:00
key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value)
end
2021-03-31 12:44:40 +08:00
2021-04-01 15:04:17 +08:00
def reset_site_url(url)
return url unless url.to_s.include?("current_user")
2021-03-31 09:49:05 +08:00
2021-04-01 15:04:17 +08:00
split_arr = url.split('current_user')
split_arr.length > 1 ? split_arr.join(current_user&.login) : (split_arr << current_user&.login).join('')
end
2021-03-31 13:35:40 +08:00
2021-04-01 15:04:17 +08:00
def append_http(url)
url.to_s.start_with?("http") ? url : [request.protocol, request.host_with_port, url].join('')
end
2020-03-09 00:40:16 +08:00
end