Refine constant variables.

This commit is contained in:
邱博亞 2024-08-23 21:04:57 +08:00
parent 64626817e9
commit d2b3464359
3 changed files with 15 additions and 13 deletions

View File

@ -330,7 +330,7 @@ class Admin::CancerpredictsController < OrbitAdminController
Dir.chdir("public") do
@site_locales = Site.last.in_use_locales.each do |locale|
I18n.with_locale(locale) do
@file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w')
@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
@ -654,7 +654,7 @@ class Admin::CancerpredictsController < OrbitAdminController
Dir.chdir("public") do
@site_locales = Site.last.in_use_locales.each do |locale|
I18n.with_locale(locale) do
@file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w')
@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

View File

@ -147,11 +147,11 @@ class CancerpredictsController < ApplicationController
uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || []
@table_str = File.read('public/cancer_tool_table_tmp_'+I18n.locale.to_s+'.txt')
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt")
preidct_js_url = '/assets/cancer_predict.js'
if File.exist?('public/cancer_tool_js_filename.txt')
js_filename = File.read('public/cancer_tool_js_filename.txt')
if js_filename.match(/cancer_predict\.js$/)
if File.exist?(Cancerpredictfields::JSFileName)
js_filename = File.read(Cancerpredictfields::JSFileName)
if js_filename.include?('cancer_predict.js')
asset = Rails.application.assets[js_filename]
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
else
@ -167,11 +167,11 @@ class CancerpredictsController < ApplicationController
uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || []
@table_str = File.read('public/cancer_tool_table_tmp_'+I18n.locale.to_s+'.txt')
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt")
preidct_js_url = '/assets/cancer_predict.js'
if File.exist?('public/cancer_tool_js_filename.txt')
js_filename = File.read('public/cancer_tool_js_filename.txt')
if js_filename.match(/cancer_predict\.js$/)
if File.exist?(Cancerpredictfields::JSFileName)
js_filename = File.read(Cancerpredictfields::JSFileName)
if js_filename.include?('cancer_predict.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 Cancerpredictfields
AdvanceFields = ["revert_value","map_values","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"]
JSFileName = "public/cancer_tool_js_filename.txt".freeze
ToolTablePrefix = "public/cancer_tool_table_tmp_".freeze
field :title ,type:String ,default:""
field :advance_mode, type: Boolean, default: false
field :form_show , :type=> Hash ,default:{
@ -287,7 +289,7 @@ class Cancerpredictfields
end
def reload_js_asset(path, force_reload=false)
reload_any_asset(path, 'application/javascript', force_reload) do |new_path|
File.open("#{Rails.root}/public/cancer_tool_js_filename.txt",'w+'){|f| f.write(new_path)}
File.open(JSFileName, 'w+'){|f| f.write(new_path)}
end
end
def generate_eval_formula
@ -482,8 +484,8 @@ class Cancerpredictfields
if need_write
File.write(save_path,file_texts)
reload_js_asset(save_path, force_reload)
elsif !(File.exist?("#{Rails.root}/public/cancer_tool_js_filename.txt"))
File.open("#{Rails.root}/public/cancer_tool_js_filename.txt",'w+'){|f| f.write(save_path)}
elsif !(File.exist?(JSFileName))
File.open(JSFileName, 'w+'){|f| f.write(save_path)}
end
end
def get_years_settings_dict