From 8aa935ad5cbceb7ae64848dece87dfaf7e58e5d9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 Apr 2022 16:13:32 +0800 Subject: [PATCH 01/10] add: glcc news management and api data --- .../admins/topic/glcc_news_controller.rb | 57 +++++++++++++++++++ app/models/topic.rb | 2 + app/models/topic/glcc_news.rb | 17 ++++++ app/views/admins/shared/_sidebar.html.erb | 6 +- .../topic/glcc_news/_form_modal.html.erb | 44 ++++++++++++++ .../admins/topic/glcc_news/_list.html.erb | 33 +++++++++++ app/views/admins/topic/glcc_news/edit.js.erb | 2 + .../admins/topic/glcc_news/index.html.erb | 18 ++++++ app/views/admins/topic/glcc_news/index.js.erb | 1 + app/views/admins/topic/glcc_news/new.js.erb | 2 + app/views/topics/_glcc_news.json.jbuilder | 4 ++ app/views/topics/index.json.jbuilder | 4 ++ config/routes.rb | 1 + 13 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admins/topic/glcc_news_controller.rb create mode 100644 app/models/topic/glcc_news.rb create mode 100644 app/views/admins/topic/glcc_news/_form_modal.html.erb create mode 100644 app/views/admins/topic/glcc_news/_list.html.erb create mode 100644 app/views/admins/topic/glcc_news/edit.js.erb create mode 100644 app/views/admins/topic/glcc_news/index.html.erb create mode 100644 app/views/admins/topic/glcc_news/index.js.erb create mode 100644 app/views/admins/topic/glcc_news/new.js.erb create mode 100644 app/views/topics/_glcc_news.json.jbuilder diff --git a/app/controllers/admins/topic/glcc_news_controller.rb b/app/controllers/admins/topic/glcc_news_controller.rb new file mode 100644 index 000000000..3c1769e5f --- /dev/null +++ b/app/controllers/admins/topic/glcc_news_controller.rb @@ -0,0 +1,57 @@ +class Admins::Topic::GlccNewsController < Admins::Topic::BaseController + before_action :find_glcc, only: [:edit, :update, :destroy] + + def index + q = ::Topic::GlccNews.ransack(title_cont: params[:search]) + glcc_news = q.result(distinct: true) + @glcc_news = paginate(glcc_news) + end + + def new + @glcc = ::Topic::GlccNews.new + end + + def create + @glcc = ::Topic::GlccNews.new(glcc_params) + if @glcc.save + redirect_to admins_topic_glcc_news_index_path + flash[:success] = "新增新闻稿成功" + else + redirect_to admins_topic_glcc_news_index_path + flash[:danger] = "新增新闻稿失败" + end + end + + def edit + end + + def update + @glcc.attributes = glcc_params + if @glcc.save + redirect_to admins_topic_glcc_news_index_path + flash[:success] = "更新新闻稿成功" + else + redirect_to admins_topic_glcc_news_index_path + flash[:danger] = "更新新闻稿失败" + end + end + + def destroy + if @glcc.destroy + redirect_to admins_topic_glcc_news_index_path + flash[:success] = "删除新闻稿成功" + else + redirect_to admins_topic_glcc_news_index_path + flash[:danger] = "删除新闻稿失败" + end + end + + private + def find_glcc + @glcc = ::Topic::GlccNews.find_by_id(params[:id]) + end + + def glcc_params + params.require(:topic_glcc_news).permit(:title, :uuid, :url, :order_index) + end +end \ No newline at end of file diff --git a/app/models/topic.rb b/app/models/topic.rb index 13bf7b5bd..e464859ec 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -35,6 +35,8 @@ class Topic < ApplicationRecord 'Topic::ExcellentProject' when 'experience_forum' 'Topic::ExperienceForum' + when "glcc_news" + 'Topic::GlccNews' when 'pinned_forum' 'Topic::PinnedForum' end diff --git a/app/models/topic/glcc_news.rb b/app/models/topic/glcc_news.rb new file mode 100644 index 000000000..6b707bf07 --- /dev/null +++ b/app/models/topic/glcc_news.rb @@ -0,0 +1,17 @@ +# == Schema Information +# +# Table name: topics +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# uuid :integer +# image_url :string(255) +# url :string(255) +# order_index :integer +# + +# GLCC 新闻稿 +class Topic::GlccNews < Topic + +end \ No newline at end of file diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 3e659395a..055988731 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -42,7 +42,11 @@
  • <%= sidebar_item(admins_topic_cooperators_path, '合作伙伴管理', icon: 'user', controller: 'admins-topic-cooperators') %>
  • <% end %> - +
  • + <%= sidebar_item_group('#setting-glcc', 'GLCC配置', icon: 'fire') do %> +
  • <%= sidebar_item(admins_topic_glcc_news_index_path, '新闻稿管理', icon: 'edit', controller: 'admins-topic-glcc_news') %>
  • + <% end %> +
  • <%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %>
  • <%= sidebar_item(admins_faqs_path, 'FAQ', icon: 'question-circle', controller: 'admins-faqs') %>
  • diff --git a/app/views/admins/topic/glcc_news/_form_modal.html.erb b/app/views/admins/topic/glcc_news/_form_modal.html.erb new file mode 100644 index 000000000..15af2f27b --- /dev/null +++ b/app/views/admins/topic/glcc_news/_form_modal.html.erb @@ -0,0 +1,44 @@ + \ No newline at end of file diff --git a/app/views/admins/topic/glcc_news/_list.html.erb b/app/views/admins/topic/glcc_news/_list.html.erb new file mode 100644 index 000000000..783910339 --- /dev/null +++ b/app/views/admins/topic/glcc_news/_list.html.erb @@ -0,0 +1,33 @@ + + + + + + + + + + + + + <% if glcc_news.present? %> + <% glcc_news.each_with_index do |news, index| %> + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
    序号标题跳转地址帖子ID排序等级操作
    <%= list_index_no((params[:page] || 1).to_i, index) %><%= news.title %><%= news.url %><%= news.uuid %><%= news.order_index %> + <%= link_to "编辑", edit_admins_topic_glcc_news_path(news), remote: true, class: "action" %> + <%= link_to "删除", admins_topic_glcc_news_path(news), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %> +
    + +<%= render partial: 'admins/shared/paginate', locals: { objects: glcc_news } %> \ No newline at end of file diff --git a/app/views/admins/topic/glcc_news/edit.js.erb b/app/views/admins/topic/glcc_news/edit.js.erb new file mode 100644 index 000000000..64ef542eb --- /dev/null +++ b/app/views/admins/topic/glcc_news/edit.js.erb @@ -0,0 +1,2 @@ +$("#glcc-news-modals").html("<%= j render(partial: 'admins/topic/glcc_news/form_modal', locals: {type: 'update'}) %>") +$(".glcc-news-change-modal").modal('show'); \ No newline at end of file diff --git a/app/views/admins/topic/glcc_news/index.html.erb b/app/views/admins/topic/glcc_news/index.html.erb new file mode 100644 index 000000000..8749fa104 --- /dev/null +++ b/app/views/admins/topic/glcc_news/index.html.erb @@ -0,0 +1,18 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('新闻稿管理') %> +<% end %> + +
    + <%= form_tag(admins_topic_glcc_news_index_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> + <%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %> + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + + <% end %> + <%= link_to "新增", new_admins_topic_glcc_news_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %> +
    + +
    + <%= render partial: 'admins/topic/glcc_news/list', locals: { glcc_news: @glcc_news } %> +
    +
    +
    diff --git a/app/views/admins/topic/glcc_news/index.js.erb b/app/views/admins/topic/glcc_news/index.js.erb new file mode 100644 index 000000000..f7db13698 --- /dev/null +++ b/app/views/admins/topic/glcc_news/index.js.erb @@ -0,0 +1 @@ +$('.glcc-news-list-container').html("<%= j( render partial: 'admins/topic/glcc_news/list', locals: { glcc_news: @glcc_news } ) %>"); \ No newline at end of file diff --git a/app/views/admins/topic/glcc_news/new.js.erb b/app/views/admins/topic/glcc_news/new.js.erb new file mode 100644 index 000000000..e03e5acd9 --- /dev/null +++ b/app/views/admins/topic/glcc_news/new.js.erb @@ -0,0 +1,2 @@ +$("#glcc-news-modals").html("<%= j render(partial: 'admins/topic/glcc_news/form_modal', locals: {type: 'create'}) %>") +$(".glcc-news-change-modal").modal('show'); \ No newline at end of file diff --git a/app/views/topics/_glcc_news.json.jbuilder b/app/views/topics/_glcc_news.json.jbuilder new file mode 100644 index 000000000..0147aff3f --- /dev/null +++ b/app/views/topics/_glcc_news.json.jbuilder @@ -0,0 +1,4 @@ +json.(glcc_news, :id, :title, :url, :uuid) +request_memo = Forum::Memos::GetService.call(glcc_news&.uuid) +json.visits request_memo.nil? ? 0 : request_memo["memo"]["viewed_count"] +json.created_time request_memo.nil? ? format_time(Time.now) : request_memo["memo"]["published_time"] \ No newline at end of file diff --git a/app/views/topics/index.json.jbuilder b/app/views/topics/index.json.jbuilder index 102da6b11..26a4f27d5 100644 --- a/app/views/topics/index.json.jbuilder +++ b/app/views/topics/index.json.jbuilder @@ -17,6 +17,8 @@ json.topics do json.partial! "excellent_project", locals: {excellent_project: topic} when "Topic::ExperienceForum" json.partial! "experience_forum", locals: {experience_forum: topic} + when "Topic::GlccNews" + json.partial! "glcc_news", locals: {glcc_news: topic} when "Topic::PinnedForum" json.partial! "pinned_forum", locals: {pinned_forum: topic} else @@ -39,6 +41,8 @@ json.topics do json.partial! "excellent_project", locals: {excellent_project: topic} when "Topic::ExperienceForum" json.partial! "experience_forum", locals: {experience_forum: topic} + when "Topic::GlccNews" + json.partial! "glcc_news", locals: {glcc_news: topic} when "Topic::PinnedForum" json.partial! "pinned_forum", locals: {pinned_forum: topic} else diff --git a/config/routes.rb b/config/routes.rb index 21caf682e..eb1c09a8f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -690,6 +690,7 @@ Rails.application.routes.draw do resources :cooperators resources :excellent_projects resources :experience_forums + resources :glcc_news resources :pinned_forums end resources :project_statistics, only: [:index] do From dec264d1693bbb70f572f7e61458570e44251901 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 Apr 2022 16:28:40 +0800 Subject: [PATCH 02/10] fix: sync user pwd --- app/controllers/concerns/login_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/login_helper.rb b/app/controllers/concerns/login_helper.rb index d8f2445fb..e608b7833 100644 --- a/app/controllers/concerns/login_helper.rb +++ b/app/controllers/concerns/login_helper.rb @@ -108,7 +108,11 @@ module LoginHelper def sync_pwd_to_gitea!(user, hash={}) return true if user.is_sync_pwd? - sync_params = { email: user.mail } + sync_params = { + login_name: user.name, + source_id: 0, + email: user.mail + } interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params.merge(hash)) if interactor.success? Rails.logger.info "########_ login is #{user.login} sync_pwd_to_gitea success _########" From 551f333261895546a1e7eeacf0af46bd74a5569d Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 8 Apr 2022 14:52:56 +0800 Subject: [PATCH 03/10] fix --- 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 e1a5be1d6..80edd1e58 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -12,7 +12,7 @@ class SettingsController < ApplicationController def get_navbar @navbar = default_laboratory.navbar if User.current.logged? - pernal_index = {"name"=>"个人主页", "link"=>get_site_url("link", "/current_user"), "hidden"=>false} + pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "/current_user"), "hidden"=>false} @navbar << pernal_index end end From eac7331070371acb0599745d204edbea01b506ba Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 8 Apr 2022 15:03:40 +0800 Subject: [PATCH 04/10] fix: settings need prefix --- 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 80edd1e58..952243531 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -12,7 +12,7 @@ class SettingsController < ApplicationController def get_navbar @navbar = default_laboratory.navbar if User.current.logged? - pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "/current_user"), "hidden"=>false} + pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false} @navbar << pernal_index end end From 75a9a65b9bfce9915efd768798e7248d92a98bc8 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Fri, 8 Apr 2022 17:38:26 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AD=90=E8=B5=9B=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/settings/show.json.jbuilder | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 4c57d573f..4f18eafaf 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -66,4 +66,8 @@ json.setting do else json.system_notification nil end + + json.sub_competitions do + json.array! EduSetting.get("sub_competitions") + end end From 9d46f2743d6a5239e04683d283f3c59c92085e71 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Fri, 8 Apr 2022 17:45:15 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AD=90=E8=B5=9B=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/settings/show.json.jbuilder | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 4f18eafaf..b5f163271 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -67,7 +67,5 @@ json.setting do json.system_notification nil end - json.sub_competitions do - json.array! EduSetting.get("sub_competitions") - end + json.sub_competitions EduSetting.get("sub_competitions") end From f60cd409b6b3c685707db6191e1a91e08b8d2010 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Fri, 8 Apr 2022 18:40:52 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AD=90=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 From 3f85f88c925e58b0a4a18786dfd527b8483a003a Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Fri, 8 Apr 2022 18:46:14 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AD=90=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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index bd44b7fd1..839aef2a7 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -32,9 +32,9 @@ class SettingsController < ApplicationController def get_sub_competitions @sub_competitions = [] - Site.add.pluck(:key).each do |key| + Site.competition.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)) + hash.merge!("#{key.to_s}": Site.competition.where(key: key).select(:id, :name, :url, :key).to_a.map(&:serializable_hash)) @sub_competitions << hash end end From 6d280ed8f256fc9179a9d839d0c026512d4ab766 Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Fri, 8 Apr 2022 18:51:01 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AD=90=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 839aef2a7..ea75c12d1 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -32,7 +32,7 @@ class SettingsController < ApplicationController def get_sub_competitions @sub_competitions = [] - Site.competition.pluck(:key).each do |key| + Site.competition.pluck(:key).uniq.each do |key| hash = {} hash.merge!("#{key.to_s}": Site.competition.where(key: key).select(:id, :name, :url, :key).to_a.map(&:serializable_hash)) @sub_competitions << hash From e97e7aa5500fccc6cf72f81182125bf8e5bb411b Mon Sep 17 00:00:00 2001 From: xiaoxiaoqiong Date: Fri, 8 Apr 2022 21:59:35 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AD=90=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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index ea75c12d1..f3eedd0a1 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -33,8 +33,8 @@ class SettingsController < ApplicationController def get_sub_competitions @sub_competitions = [] Site.competition.pluck(:key).uniq.each do |key| - hash = {} - hash.merge!("#{key.to_s}": Site.competition.where(key: key).select(:id, :name, :url, :key).to_a.map(&:serializable_hash)) + hash = {"identifier": "#{key.to_s}"} + hash.merge!("list": Site.competition.where(key: key).select(:id, :name, :url, :key).to_a.map(&:serializable_hash)) @sub_competitions << hash end end