diff --git a/app/assets/stylesheets/admin/cancerpredict.css b/app/assets/stylesheets/admin/cancerpredict.css
index 68b079f..50070f8 100644
--- a/app/assets/stylesheets/admin/cancerpredict.css
+++ b/app/assets/stylesheets/admin/cancerpredict.css
@@ -52,4 +52,37 @@ table .checkbox{
.label_left{
float: left;
padding-right: 0.5em;
+}
+.PageDetails {
+ padding-top: 0.1875em;
+ padding-bottom: 0.1875em;
+ font-weight: bold;
+ font-size: 0.875em;
+ border-bottom: 0.0625em solid #ddd;
+ overflow: hidden;
+ text-align: right;
+ color: black;
+ font-size: 1.3em;
+}
+.PageList {
+ margin: 0em 0em 0 0.5em;
+ font-weight: bold;
+ font-size: 0.875em;
+ overflow: hidden;
+ list-style: none;
+ display: inline;
+ background: none;
+ color: #999;
+}
+ol {
+ margin: 0 0 0.5em 0;
+ min-height: 0.625em;
+ height: auto !important;
+ height: 0.625em;
+ padding: 0;
+ clear: both;
+ float: right;
+}
+.PageList li {
+ display: inline;
}
\ No newline at end of file
diff --git a/app/controllers/admin/cancerpredicts_controller.rb b/app/controllers/admin/cancerpredicts_controller.rb
index 3d19715..df2b65e 100644
--- a/app/controllers/admin/cancerpredicts_controller.rb
+++ b/app/controllers/admin/cancerpredicts_controller.rb
@@ -4,9 +4,10 @@ class Admin::CancerpredictsController < OrbitAdminController
require 'rubyXL'
require 'fileutils'
require "axlsx"
- helper Admin::CancerpredictsHelper
+ #include Admin::CancerpredictsHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :create_first_field
+ helper Admin::CancerpredictsHelper
#before_action :load_access_levels
def initialize
super
@@ -473,6 +474,21 @@ class Admin::CancerpredictsController < OrbitAdminController
end
end
end
+ @pagination = create_pagination(@page_num.to_i)
+ end
+ def export_cancer_tool_record
+ @cancer_records = Cancerpredictrecord.where("title"=>@app_title).asc(:id)
+ dir_path = 'tmp/cancer_tool/'
+ #FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
+ FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
+ @filename = ("#{Time.now.year}_%02s_%02s_export_cancer_tool_record.xlsx"%[Time.now.month,Time.now.day]).gsub(" ","0")
+ Dir.chdir(dir_path) do
+ File.open(@filename, 'w') do |f|
+ f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'export_cancer_tool_record.xlsx',:locals=> {:@results=>@cancer_records} )
+ end
+ end
+ tmp_filename_data = File.read(dir_path +@filename)
+ send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: @filename)
end
def create_first_field
if Cancerpredictfields.where("title"=>(@app_title + "_back")).take_while{true}.count == 0
@@ -500,4 +516,40 @@ class Admin::CancerpredictsController < OrbitAdminController
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
end
end
+ def create_pagination(page=1,fields=Cancerpredictrecord.all,extra_params="")
+ page = 1 if page == 0
+ per_page_num = 10.0
+ all_page_num = (fields.count / per_page_num).ceil
+ all_page_num = 1 if all_page_num == 0
+ pagination = '
'+((I18n.locale.to_s == 'zh_tw') ? "第 #{page} 頁" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)")+'
'+
+ ((page == 1) ? '- ['+I18n.t('cancerpredict.prev_page')+']
' : '- ['+I18n.t('cancerpredict.prev_page')+']
')
+ if all_page_num > 7
+ if page <= (all_page_num / 2)
+ if page <= 7
+ (1..page).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ else
+ (1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ pagination +='- ...
'
+ (page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ end
+ (page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ pagination +='- ...
'
+ (all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ else
+ (1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ pagination +='- ...
'
+ (page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ if all_page_num - page <= 7
+ (page+1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ else
+ (page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ pagination +='- ...
'
+ (all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ end
+ end
+ else
+ (1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
+ end
+ pagination += (((page==all_page_num) ? '- ['+I18n.t('cancerpredict.next_page')+']
' : '- ['+I18n.t('cancerpredict.next_page')+']
')+'
')
+ end
end
\ No newline at end of file
diff --git a/app/helpers/admin/cancerpredicts_helper.rb b/app/helpers/admin/cancerpredicts_helper.rb
index 659972b..57c1789 100644
--- a/app/helpers/admin/cancerpredicts_helper.rb
+++ b/app/helpers/admin/cancerpredicts_helper.rb
@@ -4,7 +4,7 @@ module Admin::CancerpredictsHelper
per_page_num = 10.0
all_page_num = (fields.count / per_page_num).ceil
pagination = ''+((I18n.locale.to_s == 'zh_tw') ? "第 #{page} 頁" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)")+'
'+
- ((page == 1) ? '- ['+t('cancerpredict.prev_page')+']
' : '- ['+t('cancerpredict.prev_page')+']
')
+ ((page == 1) ? '- ['+I18n.t('cancerpredict.prev_page')+']
' : '- ['+I18n.t('cancerpredict.prev_page')+']
')
if all_page_num > 7
if page <= (all_page_num / 2)
if page <= 7
@@ -32,6 +32,6 @@ module Admin::CancerpredictsHelper
else
(1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
end
- pagination += (((page==all_page_num) ? '- ['+t('cancerpredict.next_page')+']
' : '- ['+t('cancerpredict.next_page')+']
')+'
')
+ pagination += (((page==all_page_num) ? '['+I18n.t('cancerpredict.next_page')+']' : ' ['+I18n.t('cancerpredict.next_page')+'] ')+'')
end
end
diff --git a/app/views/admin/cancerpredicts/_export_cancer_tool_record.xlsx.axlsx b/app/views/admin/cancerpredicts/_export_cancer_tool_record.xlsx.axlsx
new file mode 100644
index 0000000..8fe89b1
--- /dev/null
+++ b/app/views/admin/cancerpredicts/_export_cancer_tool_record.xlsx.axlsx
@@ -0,0 +1,35 @@
+# encoding: utf-8
+
+wb = xlsx_package.workbook
+wb.add_worksheet(name: "school_class") do |sheet|
+ row = []
+ title = sheet.styles.add_style(:bg_color => "FFFF00",:border=>{ :style => :thin, :color => "666666" },:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true})
+ column = sheet.styles.add_style(:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true},:border=>{ :style => :thin, :color => "666666" })
+ row << ((I18n.locale=="en") ? 'submit time' : '提交時間')
+ @fields = @results.first.names.keys
+ @fields.each do |field_name|
+ row << @results.first.names[field_name][I18n.locale.to_s].split('
')[0]
+ end
+ #export data start
+ export_data_rows = []
+ @results.each do |result|
+ temp_row = []
+ temp_row << result.created_at.to_s
+ result.result.each do |key,value|
+ if key != "locale"
+ if result.values[key][I18n.locale.to_s].length == 0
+ temp_row << value
+ else
+ temp_row << (result.values[key][I18n.locale.to_s][value.to_i-1] rescue value)
+ end
+ end
+ end
+ export_data_rows << temp_row
+ end
+
+ #export data end
+ sheet.add_row row , :style=> title,:widths => row.map{|cell| (cell.length* 11/ 2).round}
+ export_data_rows.each do |infos_row|
+ sheet.add_row infos_row , :style=> column
+ end
+end
\ No newline at end of file
diff --git a/app/views/admin/cancerpredicts/showSubmit.html.erb b/app/views/admin/cancerpredicts/showSubmit.html.erb
index 251581a..d15ede6 100644
--- a/app/views/admin/cancerpredicts/showSubmit.html.erb
+++ b/app/views/admin/cancerpredicts/showSubmit.html.erb
@@ -1,3 +1,5 @@
+
+
@@ -42,7 +44,7 @@
<%end%>
-<%=create_pagination(@page_num).html_safe%>
+<%=@pagination.html_safe%>