admin用户导出缺失文件列表功能
This commit is contained in:
parent
d196b3930d
commit
2344e3d07f
|
@ -72,6 +72,22 @@ class StoresController < ApplicationController
|
||||||
l(:label_borad_project), #l(:label_contest_innovate),
|
l(:label_borad_project), #l(:label_contest_innovate),
|
||||||
l(:label_forum) ]
|
l(:label_forum) ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#缺失文件列表
|
||||||
|
def lost_file
|
||||||
|
attachments = []
|
||||||
|
Attachment.where("container_id is not null and container_type is not null and container_type <> 'Bid' and container_type <> 'HomeworkAttach'").each do |attachment|
|
||||||
|
unless File.exist?(attachment.diskfile)
|
||||||
|
attachments << attachment
|
||||||
|
end
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.xls {
|
||||||
|
send_data(homework_to_xls(attachments), :type => "text/excel;charset=utf-8; header=present",
|
||||||
|
:filename => "#{l(:label_file_lost_list)}.xls")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -117,4 +133,27 @@ class StoresController < ApplicationController
|
||||||
else
|
else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#作品列表转换为excel
|
||||||
|
def homework_to_xls attachments
|
||||||
|
xls_report = StringIO.new
|
||||||
|
book = Spreadsheet::Workbook.new
|
||||||
|
sheet1 = book.create_worksheet :name => "homework"
|
||||||
|
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||||||
|
sheet1.row(0).default_format = blue
|
||||||
|
sheet1.row(0).concat(["文件ID","文件名","硬盘路径","上传时间","是否公开","所属对象","所属对象Id"])
|
||||||
|
count_row = 1
|
||||||
|
attachments.each do |attachment|
|
||||||
|
sheet1[count_row,0] = attachment.id
|
||||||
|
sheet1[count_row,1] = attachment.filename
|
||||||
|
sheet1[count_row,2] = attachment.diskfile
|
||||||
|
sheet1[count_row,3] = format_time(attachment.created_on)
|
||||||
|
sheet1[count_row,4] = (attachment.is_public == 1 || attachment.is_public) ? "是" :"否"
|
||||||
|
sheet1[count_row,5] = attachment.container_type
|
||||||
|
sheet1[count_row,6] = attachment.container_id
|
||||||
|
count_row += 1
|
||||||
|
end
|
||||||
|
book.write xls_report
|
||||||
|
xls_report.string
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<div style="width: 57%;margin: 10px auto;">
|
<div style="width: 67%;margin: 10px auto;">
|
||||||
<%= form_tag( search_stores_path, method: 'post') do %>
|
<%= form_tag( search_stores_path, method: 'post') do %>
|
||||||
<%= text_field_tag 'name', params[:name], placeholder: l('welcome.search.information'), name: "name", :class => 'blueinputbar', :style => 'width:450px;'%>
|
<%= text_field_tag 'name', params[:name], placeholder: l('welcome.search.information'), name: "name", :class => 'blueinputbar', :style => 'width:450px;'%>
|
||||||
|
|
||||||
<%= submit_tag l(:label_search), :class => "enterprise"%>
|
<%= submit_tag l(:label_search), :class => "enterprise "%>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= link_to("导出缺失列表",lost_file_stores_path(:format => 'xls'),:style => "background-color: #15bccf;padding: 4px 5px;color: white;") if User.current.admin?%>
|
||||||
<div class='font_lighter' style="display: inline-block; margin-top:3px;"><%= l(:label_resources_search_all)%></div>
|
<div class='font_lighter' style="display: inline-block; margin-top:3px;"><%= l(:label_resources_search_all)%></div>
|
||||||
</div>
|
</div>
|
|
@ -2023,5 +2023,7 @@ zh:
|
||||||
label_evaluation_common: 匿评评语
|
label_evaluation_common: 匿评评语
|
||||||
label_evaluation_time: 匿评时间
|
label_evaluation_time: 匿评时间
|
||||||
|
|
||||||
|
label_file_lost_list: 缺失文件列表
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -192,6 +192,7 @@ RedmineApp::Application.routes.draw do
|
||||||
resources :stores do
|
resources :stores do
|
||||||
collection do
|
collection do
|
||||||
match 'search', :via => [:get, :post]
|
match 'search', :via => [:get, :post]
|
||||||
|
get 'lost_file'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue