diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 7a8e6495..4d249508 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -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(//, "【图片评论】").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 diff --git a/app/views/managements/shixun_feedback_message.html.erb b/app/views/managements/shixun_feedback_message.html.erb index 52d15e10..4d4914c3 100644 --- a/app/views/managements/shixun_feedback_message.html.erb +++ b/app/views/managements/shixun_feedback_message.html.erb @@ -1,13 +1,14 @@
- <%#= form_tag(url_for(shixuns_managements_path), :id => "managements_shixuns_search", :method => "post", :remote => true ) do %> - - - - - - - - <%# end %> + <%= form_tag(url_for(shixun_feedback_message_managements_path), :id => "managements_shixuns_search", :method => "post", :remote => true ) do %> + + <% end %>
<%= render :partial => "shixun_feedback_list" %>
diff --git a/app/views/managements/shixun_feedback_message.js.erb b/app/views/managements/shixun_feedback_message.js.erb index b25de121..135f4107 100644 --- a/app/views/managements/shixun_feedback_message.js.erb +++ b/app/views/managements/shixun_feedback_message.js.erb @@ -1 +1,2 @@ -$("#management_shixun_feedback_list").html("<%= j(render :partial => 'shixun_feedback_list') %>"); \ No newline at end of file +$("#management_shixun_feedback_list").html("<%= j(render :partial => 'shixun_feedback_list') %>"); +$("#shixun_search").attr("href", "<%= shixun_feedback_message_managements_path(:search => @search, :format => "xls") %>") \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 79c46a54..0078eb48 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/migrate/20190321064051_migrate_poll_question_type.rb b/db/migrate/20190321064051_migrate_poll_question_type.rb new file mode 100644 index 00000000..79125894 --- /dev/null +++ b/db/migrate/20190321064051_migrate_poll_question_type.rb @@ -0,0 +1,8 @@ +class MigratePollQuestionType < ActiveRecord::Migration + def up + change_column :poll_questions, :question_title, :text + end + + def down + end +end