Browse Source

Merge branch 'develop' into standalone

tags/v3.0.2
jasder 5 years ago
parent
commit
049e5a6d5f
3 changed files with 19 additions and 24 deletions
  1. +2
    -2
      README.md
  2. +16
    -18
      app/controllers/settings_controller.rb
  3. +1
    -4
      app/views/settings/show.json.jbuilder

+ 2
- 2
README.md View File

@@ -82,9 +82,9 @@ gitea:


#### 7. 创建数据库
**开发环境为development, 生成环境为production**
```bash
rails db:create
rails db:create RAILS_ENV=development
```

#### 8. 导入数据表结构


+ 16
- 18
app/controllers/settings_controller.rb View File

@@ -4,6 +4,8 @@ class SettingsController < ApplicationController
get_add_menu
get_common_menu
get_personal_menu

puts @com
end

private
@@ -12,21 +14,17 @@ class SettingsController < ApplicationController
Site.add.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
hash = {}
site.each {|k, v|
hash.merge!("#{k}": set_site_url(k, v))
hash.merge!("#{k}": get_site_url(k, v))
}
@add << hash
end
end

def get_common_menu
@common = []
Site.common.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
@common = {}
Site.common.select(:url, :key).to_a.map(&:serializable_hash).each do |site|
next if site["url"].to_s.include?("current_user") && !User.current.logged?
hash = {}
site.each {|k, v|
hash.merge!("#{k}": set_site_url(k, v))
}
@common << hash
@common.merge!("#{site["key"]}": reset_site_url(site['url']))
end
end

@@ -36,22 +34,22 @@ class SettingsController < ApplicationController
Site.personal.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
hash = {}
site.each {|k, v|
hash.merge!("#{k}": set_site_url(k, v))
hash.merge!("#{k}": get_site_url(k, v))
}
@personal << hash
end
end
end

def set_site_url(key, value)
value =
if value.to_s.include?("current_user")
split_arr = value.split('current_user')
split_arr.length > 1 ? split_arr.join(current_user&.login) : (split_arr << current_user&.login).join('')
else
value
end
def get_site_url(key, value)
url = reset_site_url(value)
key.to_s === "url" && !value.to_s.start_with?("http") ? [request.protocol, request.host_with_port, value].join('') : url
end

def reset_site_url(url)
return url unless url.to_s.include?("current_user")

key.to_s === "url" && !value.to_s.start_with?("http") ? [request.protocol, request.host_with_port, value].join('') : value
split_arr = url.split('current_user')
split_arr.length > 1 ? split_arr.join(current_user&.login) : (split_arr << current_user&.login).join('')
end
end

+ 1
- 4
app/views/settings/show.json.jbuilder View File

@@ -48,7 +48,6 @@ json.setting do


json.add do
# json.array! @add, :name, :url, :key
json.array! @add
end

@@ -56,7 +55,5 @@ json.setting do
json.array! @personal
end

json.common do
json.array! @common
end
json.common @common
end

Loading…
Cancel
Save