Refine constant variables.
This commit is contained in:
parent
be5b892aee
commit
0fdbf08f9e
|
@ -324,29 +324,23 @@ class Admin::CancerpredictsController < 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("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt", "w")
|
||||
File.open(Cancerpredictfields::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(Cancerpredictfields.where("title" => @app_title + "_back").first.attributes)
|
||||
@file_org.close
|
||||
idx = 0
|
||||
while File.exist?("public/cancerfield_back#{idx}.txt")
|
||||
idx += 1
|
||||
end
|
||||
File.open("public/cancerfield_back#{idx}.txt", "w") do |f|
|
||||
f.write(@form_to_show.attributes)
|
||||
end
|
||||
File.open("public/cancerfield_org#{idx}.txt", "w") do |f|
|
||||
f.write(Cancerpredictfields.where("title" => @app_title + "_back").first.attributes)
|
||||
end
|
||||
redirect_to admin_cancerpredicts_path
|
||||
end
|
||||
|
@ -637,12 +631,10 @@ class Admin::CancerpredictsController < 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|
|
||||
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
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -658,14 +650,10 @@ class Admin::CancerpredictsController < OrbitAdminController
|
|||
@form_to_show.title = @app_title
|
||||
@form_to_show.save
|
||||
@form_to_show = Cancerpredictfields.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("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt", "w")
|
||||
File.open(Cancerpredictfields::ToolTableMap[I18n.locale], "w") do |f|
|
||||
tmp_table_texts = create_table(locale)
|
||||
@file_tmp.write(tmp_table_texts)
|
||||
@file_tmp.close
|
||||
end
|
||||
f.write(tmp_table_texts)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
@ -150,11 +150,11 @@ class CancerpredictsController < ApplicationController
|
|||
uid = OrbitHelper.params[:uid] rescue ""
|
||||
tags = OrbitHelper.widget_tags
|
||||
categories = OrbitHelper.widget_categories || []
|
||||
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt")
|
||||
preidct_js_url = "/assets/cancer_predict.js"
|
||||
@table_str = File.read(Cancerpredictfields::ToolTableMap[I18n.locale])
|
||||
preidct_js_url = "/assets/#{Cancerpredictfields::JS}"
|
||||
if File.exist?(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]
|
||||
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
|
||||
else
|
||||
|
@ -171,11 +171,11 @@ class CancerpredictsController < ApplicationController
|
|||
uid = OrbitHelper.params[:uid] rescue ""
|
||||
tags = OrbitHelper.widget_tags
|
||||
categories = OrbitHelper.widget_categories || []
|
||||
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt")
|
||||
preidct_js_url = "/assets/cancer_predict.js"
|
||||
@table_str = File.read(Cancerpredictfields::ToolTableMap[I18n.locale])
|
||||
preidct_js_url = "/assets/#{Cancerpredictfields::JS}"
|
||||
if File.exist?(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]
|
||||
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
|
||||
else
|
||||
|
|
|
@ -10,7 +10,11 @@ class Cancerpredictfields
|
|||
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
|
||||
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 :advance_mode, type: Boolean, default: false
|
||||
field :form_show , :type=> Hash ,default:{
|
||||
|
@ -419,8 +423,7 @@ class Cancerpredictfields
|
|||
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/cancer_predict.js'
|
||||
save_path = "#{ModuleAppPath}/app/assets/javascripts/#{JS}"
|
||||
file_texts = File.read(save_path)
|
||||
need_write = false
|
||||
str1 = "/* auto add start */"
|
||||
|
|
Loading…
Reference in New Issue