Refine constant variables.

This commit is contained in:
邱博亞 2024-08-23 21:17:27 +08:00
parent be5b892aee
commit 0fdbf08f9e
3 changed files with 36 additions and 45 deletions

View File

@ -324,29 +324,23 @@ class Admin::CancerpredictsController < OrbitAdminController
@form_to_show.auto_write_predict_js @form_to_show.auto_write_predict_js
end end
end end
@index = 0 @site_locales = Site.last.in_use_locales.each do |locale|
Dir.chdir("public") do I18n.with_locale(locale) do
while File.exist?("cancerfield_back" + @index.to_s + ".txt") File.open(Cancerpredictfields::ToolTableMap[I18n.locale], "w") do |f|
@index += 1 tmp_table_texts = create_table(locale)
end f.write(tmp_table_texts)
end
end
end
idx = 0
while File.exist?("public/cancerfield_back#{idx}.txt")
idx += 1
end end
Dir.chdir("public") do File.open("public/cancerfield_back#{idx}.txt", "w") do |f|
@site_locales = Site.last.in_use_locales.each do |locale| f.write(@form_to_show.attributes)
I18n.with_locale(locale) do
@file_tmp = File.new("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt", "w")
tmp_table_texts = create_table(locale)
@file_tmp.write(tmp_table_texts)
@file_tmp.close
end
end
end end
Dir.chdir("public") do File.open("public/cancerfield_org#{idx}.txt", "w") do |f|
@file_back = File.open("cancerfield_back" + @index.to_s + ".txt", "w") f.write(Cancerpredictfields.where("title" => @app_title + "_back").first.attributes)
@file_back.write(@form_to_show.attributes)
@file_back.close
@file_org = File.open("cancerfield_org" + @index.to_s + ".txt", "w")
@file_org.write(Cancerpredictfields.where("title" => @app_title + "_back").first.attributes)
@file_org.close
end end
redirect_to admin_cancerpredicts_path redirect_to admin_cancerpredicts_path
end end
@ -637,12 +631,10 @@ class Admin::CancerpredictsController < OrbitAdminController
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path) #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 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") @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("#{dir_path}#{@filename}", "w") do |f|
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 })
f.write render_to_string(:handlers => [:axlsx], :formats => [:xlsx], :partial => "export_cancer_tool_record.xlsx", :locals => { :results => cancer_records })
end
end end
tmp_filename_data = File.read(dir_path + @filename) tmp_filename_data = File.read("#{dir_path}#{@filename}")
send_data(tmp_filename_data, type: "application/xlsx", disposition: "attachment", filename: @filename) send_data(tmp_filename_data, type: "application/xlsx", disposition: "attachment", filename: @filename)
end end
@ -658,16 +650,12 @@ class Admin::CancerpredictsController < OrbitAdminController
@form_to_show.title = @app_title @form_to_show.title = @app_title
@form_to_show.save @form_to_show.save
@form_to_show = Cancerpredictfields.where("title" => @app_title).first @form_to_show = Cancerpredictfields.where("title" => @app_title).first
Dir.chdir("public") do @site_locales = Site.last.in_use_locales.each do |locale|
@site_locales = Site.last.in_use_locales.each do |locale| File.open(Cancerpredictfields::ToolTableMap[I18n.locale], "w") do |f|
I18n.with_locale(locale) do tmp_table_texts = create_table(locale)
@file_tmp = File.new("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt", "w") f.write(tmp_table_texts)
tmp_table_texts = create_table(locale) end
@file_tmp.write(tmp_table_texts) end
@file_tmp.close
end
end
end
else else
@form_to_show = Cancerpredictfields.where("title" => @app_title).first @form_to_show = Cancerpredictfields.where("title" => @app_title).first
end end

View File

@ -150,11 +150,11 @@ class CancerpredictsController < ApplicationController
uid = OrbitHelper.params[:uid] rescue "" uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || [] categories = OrbitHelper.widget_categories || []
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt") @table_str = File.read(Cancerpredictfields::ToolTableMap[I18n.locale])
preidct_js_url = "/assets/cancer_predict.js" preidct_js_url = "/assets/#{Cancerpredictfields::JS}"
if File.exist?(Cancerpredictfields::JSFileName) if File.exist?(Cancerpredictfields::JSFileName)
js_filename = File.read(Cancerpredictfields::JSFileName) js_filename = File.read(Cancerpredictfields::JSFileName)
if js_filename.include?("cancer_predict.js") if js_filename.include?(Cancerpredictfields::JS)
asset = Rails.application.assets[js_filename] asset = Rails.application.assets[js_filename]
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}" preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
else else
@ -171,11 +171,11 @@ class CancerpredictsController < ApplicationController
uid = OrbitHelper.params[:uid] rescue "" uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || [] categories = OrbitHelper.widget_categories || []
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt") @table_str = File.read(Cancerpredictfields::ToolTableMap[I18n.locale])
preidct_js_url = "/assets/cancer_predict.js" preidct_js_url = "/assets/#{Cancerpredictfields::JS}"
if File.exist?(Cancerpredictfields::JSFileName) if File.exist?(Cancerpredictfields::JSFileName)
js_filename = File.read(Cancerpredictfields::JSFileName) js_filename = File.read(Cancerpredictfields::JSFileName)
if js_filename.include?("cancer_predict.js") if js_filename.include?(Cancerpredictfields::JS)
asset = Rails.application.assets[js_filename] asset = Rails.application.assets[js_filename]
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}" preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
else else

View File

@ -10,7 +10,11 @@ class Cancerpredictfields
TherapyFields = ["variable","name","hint","comment_text","choice_fields","lpv_impact","active_choice","disable_condition"] TherapyFields = ["variable","name","hint","comment_text","choice_fields","lpv_impact","active_choice","disable_condition"]
TherapyOnly = ["lpv_impact","active_choice","disable_condition"] TherapyOnly = ["lpv_impact","active_choice","disable_condition"]
JSFileName = "public/cancer_tool_js_filename.txt".freeze JSFileName = "public/cancer_tool_js_filename.txt".freeze
ToolTablePrefix = "public/cancer_tool_table_tmp_".freeze ModuleAppPath = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s.freeze
JS = "cancer_predict.js"
ToolTableMap = I18n.available_locales.map do |locale|
[locale, "public/cancer_tool_table_tmp_#{locale}.txt".freeze]
end.to_h
field :title ,type:String ,default:"" field :title ,type:String ,default:""
field :advance_mode, type: Boolean, default: false field :advance_mode, type: Boolean, default: false
field :form_show , :type=> Hash ,default:{ field :form_show , :type=> Hash ,default:{
@ -419,8 +423,7 @@ class Cancerpredictfields
end end
def auto_write_predict_js(force_reload=true) def auto_write_predict_js(force_reload=true)
js_codes = generate_jscode js_codes = generate_jscode
module_app_path = Pathname.new(File.expand_path(__dir__)).dirname.dirname.to_s save_path = "#{ModuleAppPath}/app/assets/javascripts/#{JS}"
save_path = module_app_path + '/app/assets/javascripts/cancer_predict.js'
file_texts = File.read(save_path) file_texts = File.read(save_path)
need_write = false need_write = false
str1 = "/* auto add start */" str1 = "/* auto add start */"