From aa23762b2fa362581f074c8b5703cce4b48cee2b Mon Sep 17 00:00:00 2001 From: jasder Date: Mon, 22 Mar 2021 17:58:15 +0800 Subject: [PATCH 1/5] FIX update setting api for nav bar url --- app/controllers/settings_controller.rb | 7 ++++++- app/models/site.rb | 23 +++++++++++++++++++++++ app/views/settings/show.json.jbuilder | 7 +++++++ config/routes.rb | 3 +-- db/migrate/20210322084619_create_sites.rb | 12 ++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 app/models/site.rb create mode 100644 db/migrate/20210322084619_create_sites.rb diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index bb031c7b6..7e5e94d5e 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -1,6 +1,11 @@ class SettingsController < ApplicationController def show - @old_projects_url = nil + @old_projects_url = nil @old_projects_url = "https://www.trustie.net/users/#{current_user.try(:login)}/projects" if User.current.logged? + + @add = Site.add + @personal = User.current.logged? ? Site.personal : [] + + # @sites = Site.group(:site_type).select(:name, :url, :key) end end diff --git a/app/models/site.rb b/app/models/site.rb new file mode 100644 index 000000000..0ed8d8020 --- /dev/null +++ b/app/models/site.rb @@ -0,0 +1,23 @@ +# == Schema Information +# +# Table name: sites +# +# id :integer not null, primary key +# name :string(255) +# url :string(255) +# key :string(255) +# site_type :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +class Site < ApplicationRecord + # add: 添加类链接 + # personal: 个人名下类链接, + # common: 普通链接 + enum site_type: { add: 0, personal: 1, common: 2 } + + def self.set_default + + end +end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 7de12345d..4202283bd 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -47,5 +47,12 @@ json.setting do json.new_course default_course_links json.old_projects_url @old_projects_url + json.add do + json.array! @add, :name, :url, :key + end + + json.personal do + json.array! @personal, :name, :url, :key + end end diff --git a/config/routes.rb b/config/routes.rb index 9e9e3d7a8..daef12bb4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,7 +23,6 @@ Rails.application.routes.draw do resources :edu_settings - resources :edu_settings scope '/api' do namespace :ci do resources :languages, only: [:index, :show] do @@ -379,7 +378,7 @@ Rails.application.routes.draw do end end - resource :repositories, path: '/', only: [:show, :create, :edit] do + resource :repositories, path: '/', only: [:show, :create, :edit] do member do get :files get :detail diff --git a/db/migrate/20210322084619_create_sites.rb b/db/migrate/20210322084619_create_sites.rb new file mode 100644 index 000000000..e05784ec9 --- /dev/null +++ b/db/migrate/20210322084619_create_sites.rb @@ -0,0 +1,12 @@ +class CreateSites < ActiveRecord::Migration[5.2] + def change + create_table :sites do |t| + t.string :name, comment: "中文名称" + t.string :url, comment: "具体链接" + t.string :key, comment: "标识" + t.integer :site_type, comment: "分类,按照分类编排链接" + + t.timestamps + end + end +end From 18ae3853d76fbb36641f84350b570ed7a5e4961a Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 23 Mar 2021 11:42:22 +0800 Subject: [PATCH 2/5] FIX update setting api --- app/controllers/settings_controller.rb | 15 +++++++++++++-- app/views/settings/show.json.jbuilder | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 7e5e94d5e..4f4122c00 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -4,8 +4,19 @@ class SettingsController < ApplicationController @old_projects_url = "https://www.trustie.net/users/#{current_user.try(:login)}/projects" if User.current.logged? @add = Site.add - @personal = User.current.logged? ? Site.personal : [] - + @personal = + if User.current.logged? + arr =[] + Site.personal.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site| + hash = {} + site.each {|k, v| + hash.merge!("#{k}": v.to_s.include?("current_user") ? v.split('current_user').join(current_user&.login) : v) + } + arr << hash + end + else + [] + end # @sites = Site.group(:site_type).select(:name, :url, :key) end end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 4202283bd..fb03c6377 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -50,9 +50,9 @@ json.setting do json.add do json.array! @add, :name, :url, :key end - + json.personal do - json.array! @personal, :name, :url, :key + json.array! @personal end end From 815b3644281081db3238cf201a32938586a6cce3 Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 23 Mar 2021 15:42:56 +0800 Subject: [PATCH 3/5] ADD common url with setting api --- app/controllers/settings_controller.rb | 12 ++++++++++-- app/views/settings/show.json.jbuilder | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 4f4122c00..a4eb551d9 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -3,7 +3,7 @@ class SettingsController < ApplicationController @old_projects_url = nil @old_projects_url = "https://www.trustie.net/users/#{current_user.try(:login)}/projects" if User.current.logged? - @add = Site.add + @add = Site.add.select(:id, :name, :url, :key) @personal = if User.current.logged? arr =[] @@ -17,6 +17,14 @@ class SettingsController < ApplicationController else [] end - # @sites = Site.group(:site_type).select(:name, :url, :key) + + @common = [] + Site.common.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site| + hash = {} + site.each {|k, v| + hash.merge!("#{k}": v.to_s.include?("current_user") ? v.split('current_user').join(current_user&.login) : v) + } + @common << hash + end end end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index fb03c6377..697e1dd5d 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -47,6 +47,7 @@ json.setting do json.new_course default_course_links json.old_projects_url @old_projects_url + json.add do json.array! @add, :name, :url, :key end @@ -55,4 +56,7 @@ json.setting do json.array! @personal end + json.common do + json.array! @common + end end From 8b656fd4093386f12ba42938314c624d5c993762 Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 23 Mar 2021 15:47:01 +0800 Subject: [PATCH 4/5] FIX bug --- app/controllers/settings_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index a4eb551d9..34f951cea 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -22,6 +22,7 @@ class SettingsController < ApplicationController Site.common.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site| hash = {} site.each {|k, v| + next if v.to_s.include?("current_user") && !User.current_user.logged? hash.merge!("#{k}": v.to_s.include?("current_user") ? v.split('current_user').join(current_user&.login) : v) } @common << hash From 0f67944911dc0076d7884cbf7f8f4337e161ebe0 Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 23 Mar 2021 15:58:12 +0800 Subject: [PATCH 5/5] FIX code bug --- app/controllers/settings_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 34f951cea..65a5786d1 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -20,9 +20,9 @@ class SettingsController < ApplicationController @common = [] Site.common.select(:id, :name, :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| - next if v.to_s.include?("current_user") && !User.current_user.logged? hash.merge!("#{k}": v.to_s.include?("current_user") ? v.split('current_user').join(current_user&.login) : v) } @common << hash