From 8aa935ad5cbceb7ae64848dece87dfaf7e58e5d9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 Apr 2022 16:13:32 +0800 Subject: [PATCH] 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