add: glcc news management and api data
This commit is contained in:
parent
fde01e62ef
commit
8aa935ad5c
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -42,7 +42,11 @@
|
|||
<li><%= sidebar_item(admins_topic_cooperators_path, '合作伙伴管理', icon: 'user', controller: 'admins-topic-cooperators') %></li>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<%= sidebar_item_group('#setting-glcc', 'GLCC配置', icon: 'fire') do %>
|
||||
<li><%= sidebar_item(admins_topic_glcc_news_index_path, '新闻稿管理', icon: 'edit', controller: 'admins-topic-glcc_news') %></li>
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %>
|
||||
<li><%= sidebar_item(admins_faqs_path, 'FAQ', icon: 'question-circle', controller: 'admins-faqs') %></li>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<div class="modal fade glcc-news-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @glcc, url: {controller: "topic/glcc_news", action: "#{type}"} do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :title,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
跳转地址 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :url,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
帖子ID <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :uuid,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
排序等级
|
||||
</label>
|
||||
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,33 @@
|
|||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="5%">序号</th>
|
||||
<th width="20%">标题</th>
|
||||
<th width="20%">跳转地址</th>
|
||||
<th width="10%">帖子ID</th>
|
||||
<th width="20%">排序等级</th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if glcc_news.present? %>
|
||||
<% glcc_news.each_with_index do |news, index| %>
|
||||
<tr class="glcc-news-item-<%= news.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= news.title %></td>
|
||||
<td><%= news.url %></td>
|
||||
<td><%= news.uuid %></td>
|
||||
<td><%= news.order_index %></td>
|
||||
<td class="action-container">
|
||||
<%= 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" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: glcc_news } %>
|
|
@ -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');
|
|
@ -0,0 +1,18 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('新闻稿管理') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= 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': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
<%= link_to "新增", new_admins_topic_glcc_news_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container glcc-news-list-container">
|
||||
<%= render partial: 'admins/topic/glcc_news/list', locals: { glcc_news: @glcc_news } %>
|
||||
</div>
|
||||
<div id="glcc-news-modals">
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
$('.glcc-news-list-container').html("<%= j( render partial: 'admins/topic/glcc_news/list', locals: { glcc_news: @glcc_news } ) %>");
|
|
@ -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');
|
|
@ -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"]
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue