diff --git a/app/controllers/admin/cancerpredicts_controller.rb b/app/controllers/admin/cancerpredicts_controller.rb index a04684e..cf1213b 100644 --- a/app/controllers/admin/cancerpredicts_controller.rb +++ b/app/controllers/admin/cancerpredicts_controller.rb @@ -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 diff --git a/app/controllers/cancerpredicts_controller.rb b/app/controllers/cancerpredicts_controller.rb index 21c4868..f4d1efb 100644 --- a/app/controllers/cancerpredicts_controller.rb +++ b/app/controllers/cancerpredicts_controller.rb @@ -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 diff --git a/app/models/cancerpredictfields.rb b/app/models/cancerpredictfields.rb index 90a7dff..915962c 100644 --- a/app/models/cancerpredictfields.rb +++ b/app/models/cancerpredictfields.rb @@ -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