| @@ -0,0 +1,59 @@ | |||||
| class Admins::PlatformCommunicatesController < Admins::BaseController | |||||
| before_action :get_communicate, only: [:edit, :update, :destroy] | |||||
| def index | |||||
| sort_by = PlatformCommunicate.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' | |||||
| sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' | |||||
| q = PlatformCommunicate.ransack(title_cont: params[:search]) | |||||
| communicates = q.result(distinct: true).order("#{sort_by} #{sort_direction}") | |||||
| @communicates = kaminari_paginate(communicates) | |||||
| end | |||||
| def new | |||||
| @communicate = PlatformCommunicate.new | |||||
| end | |||||
| def create | |||||
| @communicate = PlatformCommunicate.new(communicate_params) | |||||
| if @communicate.save | |||||
| redirect_to admins_platform_communicates_path | |||||
| flash[:success] = '创建社区动态成功' | |||||
| else | |||||
| redirect_to admins_platform_communicates_path | |||||
| flash[:danger] = "创建社区动态失败" | |||||
| end | |||||
| end | |||||
| def edit | |||||
| end | |||||
| def update | |||||
| @communicate.attributes = communicate_params | |||||
| if @communicate.save | |||||
| redirect_to admins_platform_communicates_path | |||||
| flash[:success] = '更新社区动态成功' | |||||
| else | |||||
| redirect_to admins_platform_communicates_path | |||||
| flash[:danger] = '更新社区动态失败' | |||||
| end | |||||
| end | |||||
| def destroy | |||||
| if @communicate.destroy | |||||
| redirect_to admins_platform_communicates_path | |||||
| flash[:success] = '删除社区动态成功' | |||||
| else | |||||
| redirect_to admins_platform_communicates_path | |||||
| flash[:danger] = '删除社区动态失败' | |||||
| end | |||||
| end | |||||
| private | |||||
| def get_communicate | |||||
| @communicate = PlatformCommunicate.find_by_id(params[:id]) | |||||
| end | |||||
| def communicate_params | |||||
| params.require(:platform_communicate).permit! | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,59 @@ | |||||
| class Admins::PlatformPeopleController < Admins::BaseController | |||||
| before_action :get_person, only: [:edit, :update, :destroy] | |||||
| def index | |||||
| sort_by = PlatformPerson.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' | |||||
| sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' | |||||
| q = PlatformPerson.ransack(title_cont: params[:search]) | |||||
| people = q.result(distinct: true).order("#{sort_by} #{sort_direction}") | |||||
| @people = kaminari_paginate(people) | |||||
| end | |||||
| def new | |||||
| @person = PlatformPerson.new | |||||
| end | |||||
| def create | |||||
| @person = PlatformPerson.new(person_params) | |||||
| if @person.save | |||||
| redirect_to admins_platform_people_path | |||||
| flash[:success] = '创建论坛动态成功' | |||||
| else | |||||
| redirect_to admins_platform_people_path | |||||
| flash[:danger] = "创建论坛动态失败" | |||||
| end | |||||
| end | |||||
| def edit | |||||
| end | |||||
| def update | |||||
| @person.attributes = person_params | |||||
| if @person.save | |||||
| redirect_to admins_platform_people_path | |||||
| flash[:success] = '更新论坛动态成功' | |||||
| else | |||||
| redirect_to admins_platform_people_path | |||||
| flash[:danger] = '更新论坛动态失败' | |||||
| end | |||||
| end | |||||
| def destroy | |||||
| if @person.destroy | |||||
| redirect_to admins_platform_people_path | |||||
| flash[:success] = '删除论坛动态成功' | |||||
| else | |||||
| redirect_to admins_platform_people_path | |||||
| flash[:danger] = '删除论坛动态失败' | |||||
| end | |||||
| end | |||||
| private | |||||
| def get_person | |||||
| @person = PlatformPerson.find_by_id(params[:id]) | |||||
| end | |||||
| def person_params | |||||
| params.require(:platform_person).permit! | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,44 @@ | |||||
| <div class="modal fade platform-communicate-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 @communicate, url: {controller: "platform_communicates", 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_area :content,class: "form-control input-lg",required: true%> | |||||
| </div> | |||||
| <div class="form-group"> | |||||
| <label> | |||||
| 标签(多个请用,隔开) <span class="ml10 color-orange mr20">*</span> | |||||
| </label> | |||||
| <%= p.text_field :tag_field,class: "form-control input-lg",required: true%> | |||||
| </div> | |||||
| <div class="form-group"> | |||||
| <label> | |||||
| 帖子ID <span class="ml10 color-orange mr20">*</span> | |||||
| </label> | |||||
| <%= p.number_field :fake_id,class: "form-control input-lg",required: true%> | |||||
| </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 communicates.present? %> | |||||
| <% communicates.each_with_index do |c, index| %> | |||||
| <tr class="platform-communicate-item-<%= c.id %>"> | |||||
| <td><%= list_index_no((params[:page] || 1).to_i, index) %></td> | |||||
| <td><%= c.title %></td> | |||||
| <td><%= c.content.truncate(50) %></td> | |||||
| <td><%= c.fake_id %></td> | |||||
| <td><%= c.tag_field %></td> | |||||
| <td class="action-container"> | |||||
| <%= link_to "编辑", edit_admins_platform_communicate_path(c), remote: true, class: "action" %> | |||||
| <%= link_to "删除", admins_platform_communicate_path(c), 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: communicates } %> | |||||
| @@ -0,0 +1,2 @@ | |||||
| $("#platform-communicate-modals").html("<%= j render(partial: 'admins/platform_communicates/form_modal', locals: {type: 'update'}) %>") | |||||
| $(".platform-communicate-change-modal").modal('show'); | |||||
| @@ -0,0 +1,18 @@ | |||||
| <% define_admin_breadcrumbs do %> | |||||
| <% add_admin_breadcrumb('社区动态管理') %> | |||||
| <% end %> | |||||
| <div class="box search-form-container platform-communicate-list-form"> | |||||
| <%= form_tag(admins_platform_communicates_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_platform_communicate_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %> | |||||
| </div> | |||||
| <div class="box admin-list-container platform-communicate-list-container"> | |||||
| <%= render partial: 'admins/platform_communicates/list', locals: { communicates: @communicates } %> | |||||
| </div> | |||||
| <div id="platform-communicate-modals"> | |||||
| </div> | |||||
| @@ -0,0 +1 @@ | |||||
| $('.platform-communicate-list-container').html("<%= j( render partial: 'admins/platform_communicates/list', locals: { communicates: @communicates } ) %>"); | |||||
| @@ -0,0 +1,2 @@ | |||||
| $("#platform-communicate-modals").html("<%= j render(partial: 'admins/platform_communicates/form_modal', locals: {type: 'create'}) %>") | |||||
| $(".platform-communicate-change-modal").modal('show'); | |||||
| @@ -31,7 +31,12 @@ | |||||
| <% end %> | <% end %> | ||||
| </li> | </li> | ||||
| <li> | |||||
| <%= sidebar_item_group('#homepage-submenu', '首页配置', icon: 'file') do %> | |||||
| <li><%= sidebar_item(admins_platform_communicates_path, '社区动态', icon: 'edit', controller: 'admins-platform_communicates') %></li> | |||||
| <li><%= sidebar_item(admins_platform_people_path, '论坛交流人物', icon: 'user', controller: 'admins-platform_people') %></li> | |||||
| <% end %> | |||||
| </li> | |||||
| <li><%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %></li> | <li><%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %></li> | ||||
| <!-- | <!-- | ||||
| <li> | <li> | ||||
| @@ -864,6 +864,8 @@ Rails.application.routes.draw do | |||||
| post :batch_add, on: :collection | post :batch_add, on: :collection | ||||
| end | end | ||||
| resources :apply_signatures, only: [:index, :update] | resources :apply_signatures, only: [:index, :update] | ||||
| resources :platform_communicates | |||||
| resources :platform_people | |||||
| end | end | ||||