forked from Trustie/forgeplus
新增:技术探讨模块后台管理
This commit is contained in:
parent
1cb358b193
commit
36965e3a52
|
|
@ -0,0 +1,56 @@
|
|||
class Admins::Topic::TechnicalDiscussionsController < Admins::Topic::BaseController
|
||||
before_action :require_business
|
||||
before_action :find_discussion, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@discussions = paginate(::Topic::TechnicalDiscussion)
|
||||
end
|
||||
|
||||
def new
|
||||
@discussion = ::Topic::TechnicalDiscussion.new
|
||||
end
|
||||
|
||||
def create
|
||||
@discussion = ::Topic::TechnicalDiscussion.new(discussion_params)
|
||||
if @discussion.save
|
||||
redirect_to admins_topic_technical_discussions_path
|
||||
flash[:success] = "新增技术探讨成功"
|
||||
else
|
||||
redirect_to admins_topic_technical_discussions_path
|
||||
flash[:danger] = "新增技术探讨失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@discussion.attributes = discussion_params
|
||||
if @discussion.save
|
||||
redirect_to admins_topic_technical_discussions_path
|
||||
flash[:success] = "更新技术探讨成功"
|
||||
else
|
||||
redirect_to admins_topic_technical_discussions_path
|
||||
flash[:danger] = "更新技术探讨失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @discussion.destroy
|
||||
redirect_to admins_topic_technical_discussions_path
|
||||
flash[:success] = "删除技术探讨成功"
|
||||
else
|
||||
redirect_to admins_topic_technical_discussions_path
|
||||
flash[:danger] = "删除技术探讨失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_discussion
|
||||
@discussion = ::Topic::TechnicalDiscussion.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def discussion_params
|
||||
params.require(:topic_technical_discussion).permit(:title, :description, :date, :order_index)
|
||||
end
|
||||
end
|
||||
|
|
@ -26,7 +26,7 @@ class ProjectUnit < ApplicationRecord
|
|||
unit_types = unit_types.except("dataset")
|
||||
unit_types.each do |_, v|
|
||||
self.create!(project_id: project_id, unit_type: v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_by_unit_types!(project, types)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
# location :integer default("0")
|
||||
#
|
||||
|
||||
# 首页技术讨论
|
||||
class Topic::TechnicalDiscussion < Topic
|
||||
end
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<div class="modal fade discussion-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 @discussion, url: {controller: "topic/technical_discussions", action: "#{type}"}, html: { enctype: 'multipart/form-data' } 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_area :description,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
日期 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :date,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="20%">日期</th>
|
||||
<th width="20%">排序等级</th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if discussions.present? %>
|
||||
<% discussions.each_with_index do |discussion, index| %>
|
||||
<tr class="cooperator-item-<%= discussion.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= discussion.title %></td>
|
||||
<td><%= discussion.description %></td>
|
||||
<td><%= discussion.date %></td>
|
||||
<td><%= discussion.order_index %></td>
|
||||
<td class="action-container">
|
||||
<%= link_to "编辑", edit_admins_topic_technical_discussion_path(discussion), remote: true, class: "action" %>
|
||||
<%= link_to "删除", admins_topic_technical_discussion_path(discussion), 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: discussions } %>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$("#discussion-modals").html("<%= j render(partial: 'admins/topic/technical_discussions/form_modal', locals: {type: 'update'}) %>")
|
||||
$(".discussion-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_technical_discussions_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_technical_discussion_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container discusssions-list-container">
|
||||
<%= render partial: 'admins/topic/technical_discussions/list', locals: { discussions: @discussions } %>
|
||||
</div>
|
||||
<div id="discussion-modals">
|
||||
</div>
|
||||
|
|
@ -0,0 +1 @@
|
|||
$('.discussions-list-container').html("<%= j( render partial: 'admins/topic/technical_discussions/list', locals: { discusssions: @discusssions } ) %>");
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$("#discussion-modals").html("<%= j render(partial: 'admins/topic/technical_discussions/form_modal', locals: {type: 'create'}) %>")
|
||||
$(".discussion-change-modal").modal('show');
|
||||
|
|
@ -867,6 +867,7 @@ Rails.application.routes.draw do
|
|||
get '/baidu_tongji', to: 'dashboards#baidu_tongji'
|
||||
get '/baidu_tongji_auth', to: 'dashboards#baidu_tongji_auth'
|
||||
namespace :topic do
|
||||
resources :technical_discussions
|
||||
resources :ck_js_forums
|
||||
resources :activity_forums
|
||||
resources :banners
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
class AddDescriptionDateToTopics < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :topics, :description, :text
|
||||
add_column :topics, :date, :string
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue