Compare commits
4 Commits
3b5b950eb3
...
a90a842a4c
Author | SHA1 | Date |
---|---|---|
|
a90a842a4c | |
|
894b39913b | |
|
77dd9cc169 | |
|
5fe13fe367 |
|
@ -15,7 +15,7 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
|
|||
@app_title = "coloncancerpredict2"
|
||||
end
|
||||
def yaml_load(v)
|
||||
YAML.load(v).map(&:to_s)
|
||||
YAML.load(v)
|
||||
end
|
||||
def index
|
||||
@tags = @module_app.tags
|
||||
|
@ -425,8 +425,8 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
|
|||
else
|
||||
@table_str_left += '<div class= "cancer-btn-group cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;">'
|
||||
@field_property["choice_fields"].each do |create_choice|
|
||||
@table_str_left += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.titleize+'</button>'
|
||||
@table_str_left += '<input type="hidden" value="0" name="'+create_choice+'"/>'
|
||||
@table_str_left += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.to_s.titleize+'</button>'
|
||||
@table_str_left += '<input type="hidden" value="0" name="'+create_choice.to_s+'"/>'
|
||||
end
|
||||
@table_str_left += '</div>'
|
||||
end
|
||||
|
|
|
@ -148,9 +148,19 @@ class Coloncancerpredict2sController < ApplicationController
|
|||
tags = OrbitHelper.widget_tags
|
||||
categories = OrbitHelper.widget_categories || []
|
||||
@table_str = File.read('public/colon_cancer_tool_table_tmp_'+I18n.locale.to_s+'2.txt')
|
||||
preidct_js_url = '/assets/colon_cancer_predict2.js'
|
||||
if File.exist?("public/#{Coloncancerpredictfields2s::JSFileName}")
|
||||
js_filename = File.read("public/#{Coloncancerpredictfields2s::JSFileName}")
|
||||
if js_filename.include?('colon_cancer_predict2.js')
|
||||
asset = Rails.application.assets[js_filename]
|
||||
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
|
||||
else
|
||||
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{File.basename(js_filename)}"
|
||||
end
|
||||
end
|
||||
{
|
||||
"coloncancerpredict2" => [],
|
||||
"extras"=>{"table"=> @table_str}
|
||||
"extras"=>{"table"=> @table_str,'preidct_js_url'=>preidct_js_url}
|
||||
}
|
||||
end
|
||||
def widget
|
||||
|
@ -158,9 +168,19 @@ class Coloncancerpredict2sController < ApplicationController
|
|||
tags = OrbitHelper.widget_tags
|
||||
categories = OrbitHelper.widget_categories || []
|
||||
@table_str = File.read('public/colon_cancer_tool_table_tmp_'+I18n.locale.to_s+'2.txt')
|
||||
preidct_js_url = '/assets/colon_cancer_predict2.js'
|
||||
if File.exist?("public/#{Coloncancerpredictfields2s::JSFileName}")
|
||||
js_filename = File.read("public/#{Coloncancerpredictfields2s::JSFileName}")
|
||||
if js_filename.include?('colon_cancer_predict2.js')
|
||||
asset = Rails.application.assets[js_filename]
|
||||
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
|
||||
else
|
||||
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{File.basename(js_filename)}"
|
||||
end
|
||||
end
|
||||
{
|
||||
"coloncancerpredict2" => [],
|
||||
"extras"=>{"table"=> @table_str}
|
||||
"extras"=>{"table"=> @table_str,'preidct_js_url'=>preidct_js_url}
|
||||
}
|
||||
end
|
||||
def create_first_field
|
||||
|
|
|
@ -9,6 +9,7 @@ class Coloncancerpredictfields2s
|
|||
AdvanceFields = ["revert_value","map_values","coloncancer_predict_mapping_file2"]
|
||||
TherapyFields = ["variable","name","hint","comment_text","choice_fields","lpv_impact","active_choice","disable_condition"]
|
||||
TherapyOnly = ["lpv_impact","active_choice","disable_condition"]
|
||||
JSFileName = "cc2_tool_js_filename.txt"
|
||||
field :title ,type:String ,default:""
|
||||
field :advance_mode, type: Boolean, default: false
|
||||
field :form_show , :type=> Hash ,default: {
|
||||
|
@ -36,7 +37,7 @@ class Coloncancerpredictfields2s
|
|||
field :large ,type:Hash ,default:{'font_size'=>"1.25em",'active'=>0}
|
||||
field :head_images_id ,type:Array , default: []
|
||||
field :title_images_id ,type:Array , default: []
|
||||
field :title_texts ,type:Hash ,default: {"zh_tw"=>"大腸癌線上預測工具", "en"=>"Asian breast cancer prediction"}
|
||||
field :title_texts ,type:Hash ,default: {"zh_tw"=>"大腸癌線上預測工具(進階版)", "en"=>"Predict Colon Cancer Tool (Advanced)"}
|
||||
field :table_above_texts ,type:Hash ,default: {"zh_tw"=>"下表之分析為針對手術後病人,根據選定的術後治療,分別估計在第1年、3 及5年的存活率。", "en"=>"The analysis is for women who had undergone surgery.The table shows the 1-, 3- and 5-year survival rates,based on the treatment you have selected."}
|
||||
field :text_above_texts ,type:Hash ,default: {"zh_tw"=>"此研究分析來自已接受根除性手術後之婦女所得之結果,根據您所輸入的資訊以及治療方式,在術後<br/>第{{years}}年,", "en"=>"The analysis is for women who had undergone surgery. Base on the information and the treatment you have selected, the predictions of survival status<br/>{{years}}"}
|
||||
field :surgery_only_texts ,type:Hash ,default: {"zh_tw"=>"100 位只接受根除性手術的婦女中,有{{Surgery_only}}位婦女,術後{{surgery_year}}年仍為存活", "en"=>"after surgery are as follows:<br/>{{Surgery_only}} out of 100 women treated with surgery only are alive at {{surgery_year}} years."}
|
||||
|
@ -218,6 +219,50 @@ class Coloncancerpredictfields2s
|
|||
self.lpv_calc = get_years_settings_dict
|
||||
self.generate_eval_formula
|
||||
end
|
||||
def reload_any_asset(path, type=nil, force_reload=false)
|
||||
env = Rails.application.assets
|
||||
new_env = Sprockets::Environment.new(Rails.root.to_s) do |env|
|
||||
env.version = ::Rails.env
|
||||
tmp_path = "#{Rails.application.config.root}/tmp/cache/assets/#{::Rails.env}"
|
||||
env.cache = ::Sprockets::Cache::FileStore.new(tmp_path)
|
||||
env.context_class.class_eval do
|
||||
include ::Sprockets::Rails::Helper
|
||||
end
|
||||
end
|
||||
new_env.config = env.config
|
||||
stats = env.cached.instance_variable_get(:@stats)
|
||||
new_path = path.sub(/\.erb$/,'')
|
||||
if force_reload || (stats && stats[path]) #Need reload asset
|
||||
if type.nil?
|
||||
ext = File.extname(new_path)
|
||||
env.mime_types.each do |t, h|
|
||||
if h[:extensions].include?(ext)
|
||||
type = t
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if type
|
||||
full_path = 'file://'+path+'?type='+type
|
||||
uris = env.cached.instance_variable_get(:@uris)
|
||||
keys = uris.keys.select{|k| k.include?(full_path)}
|
||||
asset = new_env.load(full_path)
|
||||
if keys.count != 0
|
||||
keys.each do |k|
|
||||
uris[k] = asset
|
||||
end
|
||||
end
|
||||
new_path = new_path.sub(/\.[^.]+$/){|ext| '-' + asset.digest + ext}
|
||||
File.binwrite(new_path, asset.to_s)
|
||||
yield new_path if block_given?
|
||||
end
|
||||
end
|
||||
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/#{JSFileName}",'w+'){|f| f.write(new_path)}
|
||||
end
|
||||
end
|
||||
def generate_eval_formula
|
||||
eval_hidden_variables = "def eval_hidden_variables(result); #{self.tmp_hidden_variables_for_ruby}; end"
|
||||
Coloncancerpredict2sController.module_eval(eval_hidden_variables)
|
||||
|
@ -343,7 +388,7 @@ class Coloncancerpredictfields2s
|
|||
org_str.insert(st, replace_str)
|
||||
org_str
|
||||
end
|
||||
def auto_write_predict_js
|
||||
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/colon_cancer_predict2.js'
|
||||
|
@ -409,6 +454,9 @@ class Coloncancerpredictfields2s
|
|||
end
|
||||
if need_write
|
||||
File.write(save_path,file_texts)
|
||||
reload_js_asset(save_path, force_reload)
|
||||
elsif !(File.exist?("#{Rails.root}/public/#{JSFileName}"))
|
||||
File.open("#{Rails.root}/public/#{JSFileName}.txt",'w+'){|f| f.write(save_path)}
|
||||
end
|
||||
end
|
||||
def get_years_settings_dict
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<script type="text/javascript" src="/assets/jquery.smartmenus.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/jquery.smartmenus.bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/colon_cancer_predict2.js"></script>
|
||||
<script type="text/javascript" src="{{preidct_js_url}}"></script>
|
||||
{{table}}
|
||||
<%= stylesheet_link_tag "colon_cancer_predict2", media: "screen" %>
|
||||
<%= stylesheet_link_tag "bootstrap.min.print", media: "print" %>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<script type="text/javascript" src="/assets/jquery.smartmenus.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/jquery.smartmenus.bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/colon_cancer_predict2.js"></script>
|
||||
<script type="text/javascript" src="{{preidct_js_url}}"></script>
|
||||
{{table}}
|
||||
<%= stylesheet_link_tag "colon_cancer_predict2", media: "screen" %>
|
||||
<%= stylesheet_link_tag "bootstrap.min.print", media: "print" %>
|
||||
|
|
Loading…
Reference in New Issue