This commit is contained in:
邱博亞 2024-08-23 21:42:21 +08:00
parent 0cf4dafdd2
commit 6069591060
3 changed files with 26 additions and 35 deletions

View File

@ -337,29 +337,23 @@ class Admin::HncCancerPredictsController < OrbitAdminController
@form_to_show.auto_write_predict_js
end
end
@index = 0
Dir.chdir("public") do
while File.exist?("cancerfield_back" + @index.to_s + ".txt")
@index += 1
end
end
Dir.chdir("public") do
@site_locales = Site.last.in_use_locales.each do |locale|
I18n.with_locale(locale) do
@file_tmp = File.new(HncCancerPredictfields::ToolTableMap[I18n.locale], "w")
@site_locales = Site.last.in_use_locales.each do |locale|
I18n.with_locale(locale) do
File.open(HncCancerPredictfields::ToolTableMap[I18n.locale], "w") do |f|
tmp_table_texts = create_table(locale)
@file_tmp.write(tmp_table_texts)
@file_tmp.close
f.write(tmp_table_texts)
end
end
end
Dir.chdir("public") do
@file_back = File.open("cancerfield_back" + @index.to_s + ".txt", "w")
@file_back.write(@form_to_show.attributes)
@file_back.close
@file_org = File.open("cancerfield_org" + @index.to_s + ".txt", "w")
@file_org.write(HncCancerPredictfields.where("title" => @app_title + "_back").first.attributes)
@file_org.close
idx = 0
while File.exist?("public/hnc_field_back#{idx}.txt")
idx += 1
end
File.open("public/hnc_field_back#{idx}.txt", "w") do |f|
f.write(@form_to_show.attributes)
end
File.open("public/hnc_field_org#{idx}.txt", "w") do |f|
f.write(HncCancerPredictfields.where("title" => @app_title + "_back").first.attributes)
end
redirect_to admin_hnc_cancer_predicts_path
end
@ -650,10 +644,8 @@ class Admin::HncCancerPredictsController < OrbitAdminController
#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
File.open("#{dir_path}/#{@filename}", "w") do |f|
f.write render_to_string(:handlers => [:axlsx], :formats => [:xlsx], :partial => "export_cancer_tool_record.xlsx", :locals => { :results => cancer_records })
end
tmp_filename_data = File.read(dir_path + @filename)
send_data(tmp_filename_data, type: "application/xlsx", disposition: "attachment", filename: @filename)
@ -671,13 +663,11 @@ class Admin::HncCancerPredictsController < OrbitAdminController
@form_to_show.title = @app_title
@form_to_show.save
@form_to_show = HncCancerPredictfields.where("title" => @app_title).first
Dir.chdir("public") do
@site_locales = Site.last.in_use_locales.each do |locale|
I18n.with_locale(locale) do
@file_tmp = File.new(HncCancerPredictfields::ToolTableMap[I18n.locale], "w")
@site_locales = Site.last.in_use_locales.each do |locale|
I18n.with_locale(locale) do
File.open(HncCancerPredictfields::ToolTableMap[I18n.locale], "w") do |f|
tmp_table_texts = create_table(locale)
@file_tmp.write(tmp_table_texts)
@file_tmp.close
f.write(tmp_table_texts)
end
end
end

View File

@ -156,10 +156,10 @@ class HncCancerPredictsController < ApplicationController
tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || []
@table_str = File.read(HncCancerPredictfields::ToolTableMap[I18n.locale])
preidct_js_url = "/assets/hnc_cancer_predict.js"
preidct_js_url = "/assets/#{HncCancerPredictfields::JS}"
if File.exist?(HncCancerPredictfields::JSFileName)
js_filename = File.read(HncCancerPredictfields::JSFileName)
if js_filename.include?("hnc_cancer_predict.js")
if js_filename.include?(HncCancerPredictfields::JS)
asset = Rails.application.assets[js_filename]
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
else
@ -177,10 +177,10 @@ class HncCancerPredictsController < ApplicationController
tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || []
@table_str = File.read(HncCancerPredictfields::ToolTableMap[I18n.locale])
preidct_js_url = "/assets/hnc_cancer_predict.js"
preidct_js_url = "/assets/#{HncCancerPredictfields::JS}"
if File.exist?("public/cancer_tool_js_filename.txt")
js_filename = File.read("public/cancer_tool_js_filename.txt")
if js_filename.match("hnc_cancer_predict.js")
if js_filename.include?(HncCancerPredictfields::JS)
asset = Rails.application.assets[js_filename]
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
else

View File

@ -9,6 +9,8 @@ class HncCancerPredictfields
AdvanceFields = ["revert_value","map_values","hnc_cancer_predict_mapping_file"]
TherapyFields = ["variable","name","hint","comment_text","choice_fields","lpv_impact","active_choice","disable_condition"]
TherapyOnly = ["lpv_impact","active_choice","disable_condition"]
ModuleAppPath = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s.freeze
JS = "hnc_cancer_predict.js"
JSFileName = "public/hnc_tool_js_filename.txt".freeze
ToolTableMap = I18n.available_locales.map do |locale|
[locale, "public/hnc_tool_table_tmp_#{locale}.txt".freeze]
@ -406,8 +408,7 @@ class HncCancerPredictfields
end
def auto_write_predict_js(force_reload=true)
js_codes = generate_jscode
module_app_path = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s
save_path = module_app_path + '/app/assets/javascripts/hnc_cancer_predict.js'
save_path = "#{ModuleAppPath}/app/assets/javascripts/#{JS}"
file_texts = File.read(save_path)
need_write = false
str1 = "/* auto add start */"