超级管理员的实训反馈页面,增加excel导出功能和实训名称检索功能

dev_local
daiao 6 years ago
parent 3992b7f9ea
commit 7d0d89d4e2

@ -791,7 +791,14 @@ class ManagementsController < ApplicationController
def shixun_feedback_message
@menu_type = 8
@sub_type = 2
@discusses = Discuss.where(:dis_type => "Shixun").reorder("created_at desc")
@search = params[:search]
if @search.present?
shixun_ids = Shixun.where("name like ?", "%#{params[:search]}%").pluck(:id)
@discusses = Discuss.where(:dis_type => "Shixun", :dis_id => shixun_ids).reorder("created_at desc")
else
@discusses = Discuss.where(:dis_type => "Shixun").reorder("created_at desc")
end
@all_discusses = @discusses
@discusses_count = @discusses.count
@limit = 20
@is_remote = true
@ -802,6 +809,11 @@ class ManagementsController < ApplicationController
respond_to do |format|
format.js
format.html
format.xls{
shixun_ids = @all_discusses.pluck(:dis_id).uniq
filename = "#{Time.now.strftime("%Y%m%d")}-实训反馈.xls"
send_data(shixun_feedback_xls(shixun_ids), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
}
end
end
@ -4045,6 +4057,39 @@ end
return sheet.rows
end
def shixun_feedback_xls shixun_ids
xls_report = StringIO.new
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "报名列表"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
sheet1.row(0).default_format = blue
count_row = 1
shixuns = Shixun.where(:id => shixun_ids).includes(discusses: [:user])
sheet1.row(0).concat(["序号", "实训ID", "实训名称","评论数", "评论内容", "关卡", "评论者", "评论者职业",
"评论者单位", "评论时间", "社区导师是否已回复"])
shixuns.each_with_index do |shixun, i|
discusses = shixun.discusses.where("user_id != ?", 1)
sheet1[count_row, 0] = i + 1
sheet1[count_row, 1] = shixun.identifier
sheet1[count_row, 2] = shixun.name
sheet1[count_row, 3] = discusses.count
discusses.each_with_index do |discuss, j|
user = discuss.user
sheet1[count_row, 4] = discuss.content.gsub(/<img.*\/>/, "【图片评论】").gsub(/!\[\].+\)/, "【图片评论】")
sheet1[count_row, 5] = "#{discuss.position}"
sheet1[count_row, 6] = user.show_real_name
sheet1[count_row, 7] = user.identity
sheet1[count_row, 8] = user.school_name
sheet1[count_row, 9] = format_time discuss.created_at
sheet1[count_row, 10] = discuss.children.pluck(:user_id).include?(1) ? "" : ""
count_row += 1
end
#count_row += 1
end
book.write xls_report
xls_report.string
end
def competition_member_xls members, competition
xls_report = StringIO.new
book = Spreadsheet::Workbook.new

@ -1,13 +1,14 @@
<div class="edu-class-container">
<%#= form_tag(url_for(shixuns_managements_path), :id => "managements_shixuns_search", :method => "post", :remote => true ) do %>
<!--<div class="edu-con-top clearfix mb20">-->
<!--<input class="fl task-form-20 task-height-30 ml25" id="shixun_Look_name" name="search" maxlength="" placeholder="输入实训名称关键字进行搜索" type="text" style="height: 21px;">-->
<!--<li class="fl ml10">-->
<!--<a href="javascript:void(0)" class="task-btn task-btn-orange" onclick="$('#managements_shixuns_search').submit();">搜索</a>-->
<!--<a href="javascript:clearSearchCondition();" class="task-btn mr10">清除</a>-->
<!--</li>-->
<!--</div>-->
<%# end %>
<%= form_tag(url_for(shixun_feedback_message_managements_path), :id => "managements_shixuns_search", :method => "post", :remote => true ) do %>
<div class="edu-con-top clearfix mb20">
<input class="fl task-form-20 task-height-30 ml25" id="shixun_Look_name" name="search" maxlength="" placeholder="输入实训名称关键字进行搜索" type="text" style="height: 21px;">
<li class="fl ml10">
<a href="javascript:void(0)" class="task-btn task-btn-orange" onclick="$('#managements_shixuns_search').submit();">搜索</a>
<a href="javascript:clearSearchCondition();" class="task-btn mr10">清除</a>
</li>
<a href="<%= shixun_feedback_message_managements_path(:search => @search, :format => "xls") %>" id="shixun_search" class="task-btn mr10 task-btn-orange fr">导出</a>
</div>
<% end %>
<div class="ex_container" id="management_shixun_feedback_list">
<%= render :partial => "shixun_feedback_list" %>
</div>

@ -1 +1,2 @@
$("#management_shixun_feedback_list").html("<%= j(render :partial => 'shixun_feedback_list') %>");
$("#management_shixun_feedback_list").html("<%= j(render :partial => 'shixun_feedback_list') %>");
$("#shixun_search").attr("href", "<%= shixun_feedback_message_managements_path(:search => @search, :format => "xls") %>")

@ -600,7 +600,7 @@ RedmineApp::Application.routes.draw do ## oauth相关
get 'create_departments'
post 'add_department'
get 'shixun_feedback'
get 'shixun_feedback_message'
match 'shixun_feedback_message', :via => [:get, :post]
get 'leave_message'
get 'messages_list'
get 'course_messages_list'

Loading…
Cancel
Save