Compare commits

...

3 Commits

Author SHA1 Message Date
邱博亞 d6de5dd99e Fix title. 2024-08-22 23:53:02 +08:00
邱博亞 bd077054bb Fix js not reload bug. 2024-08-22 23:53:02 +08:00
邱博亞 c049ad8050 Fix bug in backend setting. 2024-08-22 23:53:01 +08:00
8 changed files with 117 additions and 24 deletions

View File

@ -14,6 +14,9 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
super
@app_title = "coloncancerpredict2"
end
def yaml_load(v)
YAML.load(v)
end
def index
@tags = @module_app.tags
@categories = @module_app.categories.enabled
@ -69,7 +72,7 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
end
else
if value.length > 2
@form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value)
@form_to_show.form_show[num.to_s][key.to_s] = yaml_load(value)
else
@form_to_show.form_show[num.to_s][key.to_s] = []
end
@ -92,7 +95,7 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
end
else
if sub_value.length > 2
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = yaml_load(sub_value)
else
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end
@ -157,7 +160,7 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
end
else
if value.length > 2
@form_to_show.form_show_in_result[num.to_s][key.to_s] = YAML.load(value)
@form_to_show.form_show_in_result[num.to_s][key.to_s] = yaml_load(value)
else
@form_to_show.form_show_in_result[num.to_s][key.to_s] = []
end
@ -180,7 +183,7 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
end
else
if sub_value.length > 2
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = yaml_load(sub_value)
else
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end
@ -216,7 +219,7 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
@form_to_show[item] = item_hash
elsif @form_to_show[item].class == Array
if params_cancer[item].class != Array
@form_to_show[item] = YAML.load(params_cancer[item]) rescue []
@form_to_show[item] = yaml_load(params_cancer[item]) rescue []
else
@form_to_show[item] = params_cancer[item]
end
@ -226,7 +229,7 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
end
end
@size = ['small','medium','large']
@size.each{|size| @form_to_show[size] = params["coloncancerpredictfields2s"][size]}
@size.each{|size| @form_to_show[size] = params["coloncancerpredictfields2s"][size].to_h}
@file_path = Rails.root.to_s + '/app/assets/images/predict_tool'
if !Dir.exist? @file_path
FileUtils.mkdir_p @file_path
@ -422,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
@ -481,8 +484,8 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
else
@table_str_right += '<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_right += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.titleize+'</button>'
@table_str_right += '<input type="hidden" value="0" name="'+create_choice+'"/>'
@table_str_right += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.to_s.titleize+'</button>'
@table_str_right += '<input type="hidden" value="0" name="'+create_choice.to_s+'"/>'
end
@table_str_right += '</div>'
end
@ -573,8 +576,8 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
else
@table_result_choice_fileds += '<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_result_choice_fileds += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.titleize+'</button>'
@table_result_choice_fileds += '<input type="hidden" value="0" name="'+create_choice+'"></input>'
@table_result_choice_fileds += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.to_s.titleize+'</button>'
@table_result_choice_fileds += '<input type="hidden" value="0" name="'+create_choice.to_s+'"></input>'
end
@table_result_choice_fileds += '</div>'
end

View File

@ -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

View File

@ -1,4 +1,13 @@
module Admin::Coloncancerpredict2sHelper
def cc2_yaml_dump(arr)
if arr.blank?
'[]'
elsif arr.class != String
'[' + arr.map{|s| (s.is_a?(String) && !(s.is_i?) && s.include?(' ')) ? "\"#{s}\"" : s}.join(', ') + ']'
else
arr
end
end
def create_pagination(page=1,fields=Coloncancerpredictrecord2.all,extra_params="")
page = 1 if page == 0
per_page_num = 10.0

View File

@ -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: {
@ -18,7 +19,7 @@ class Coloncancerpredictfields2s
"3"=>{"variable"=>"lymph_nodes_positive", "name"=>{"zh_tw"=>"區域淋巴結侵犯數目<br/>(Regional lymph nodes positive)", "en"=>"Regional lymph nodes positive"}, "is_num"=>1, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"此變項為預測重要變數,若無此資訊預測容易失真。", "en"=>"Regional lymph nodes positive is a key predictive variable. If this information is omitted, the prediction result would be biased."}, "choice_fields"=>{"zh_tw"=>["未知"], "en"=>["unknown"]}, "range"=>[0, 90], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]},
"4"=>{"variable"=>"crm", "name"=>{"zh_tw"=>"病理環切緣<br/>(Circumferential resection margin(per 0.1 mm))", "en"=>"Circumferential resection margin (per 0.1 mm)"}, "is_num"=>1, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"", "en"=>""}, "choice_fields"=>{"zh_tw"=>[], "en"=>[]}, "range"=>[0, 980], "right"=>0, "is_float"=>1, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]},
"5"=>{"variable"=>"grade", "name"=>{"zh_tw"=>"腫瘤級數<br/>(Tumor grade)", "en"=>"Tumor grade"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"腫瘤級數代表腫瘤組織與正常組織間的分化程度,若無分化級數資訊,請選擇“未知”選項,將以級數 1 進行預測。", "en"=>"The grade refers to how different the cancer cells are from normal cells. Please select “unknown” if there is no information about grade. The prediction model would use “grade 2” as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["1", "2", "3", "未知"], "en"=>["1", "2", "3", "unknown"]}, "range"=>[], "right"=>1, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]},
"6"=>{"variable"=>"pstage", "name"=>{"zh_tw"=>"病理分期<br/>(pathologic stage)", "en"=>"Pathologic stage"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無分期資訊,請選擇“未知”選項,將以病理分期第 1 期進行預測。", "en"=>"ER status describes the status of estrogen receptor. Please select “unknown” if there is no information about ER status. The prediction model would use “Positive” (the majority class) as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["1", "2", "3", "4", " 未知"], "en"=>["positive", "negative", "unknown"]}, "is_num"=>0, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>[], "need_map_values"=>0},
"6"=>{"variable"=>"pstage", "name"=>{"zh_tw"=>"病理分期<br/>(Pathological stage)", "en"=>"Pathological stage"}, "is_num"=>0, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無分期資訊,請選擇“未知”選項,將以病理分期第 1 期進行預測。", "en"=>"Please select “unknown” if there is no information about “Pathological stage”. The prediction model would use “1th stage” as the alternative variable."}, "choice_fields"=>{"zh_tw"=>["1", "2", "3", "4", "未知"], "en"=>["1", "2", "3", "4", "unknown"]}, "range"=>[], "right"=>0, "is_float"=>0, "need_map_values"=>0, "revert_value"=>0, "map_values"=>[]},
"7"=>{"variable"=>"pi", "name"=>{"zh_tw"=>"神經侵襲<br/>(Perineural Invasion)", "en"=>"Perineural Invasion"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無神經侵襲資訊,請選擇“未知”選項,將以未神經侵襲進行預測。", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "", "未知"], "en"=>["Yes", "No", "unknown"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>0, "map_values"=>[], "need_map_values"=>0},
"8"=>{"variable"=>"obstruction", "name"=>{"zh_tw"=>"腸阻塞<br/>(Obstruction)", "en"=>"Obstruction"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無腸阻塞資訊,請 選擇“未知”選項,將以無腸阻塞進行預測。", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "", "未知"], "en"=>["Yes", "No", "unknown"]}, "is_num"=>0, "range"=>[], "right"=>0, "is_float"=>0, "revert_value"=>0, "map_values"=>[], "need_map_values"=>0},
"9"=>{"variable"=>"perforation", "name"=>{"zh_tw"=>"腸穿孔<br/>(Perforation)", "en"=>"Perforation"}, "hint"=>{"zh_tw"=>"", "en"=>""}, "comment_text"=>{"zh_tw"=>"若無腸阻塞資訊,請選擇“未知”選項,將以無腸穿孔進行預測。", "en"=>""}, "choice_fields"=>{"zh_tw"=>["", "", " 未知"], "en"=>["Yes", "No", "unknown"]}, "is_num"=>0, "range"=>[], "right"=>1, "is_float"=>0, "revert_value"=>0, "map_values"=>[], "need_map_values"=>0}
@ -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

View File

@ -16,6 +16,7 @@
<%else%>
<% @disp_value = @value %>
<%end%>
<% @disp_value = cc2_yaml_dump(@disp_value) if value_type == 'Array' %>
<% field_type = ((value_type == 'String' || value_type == 'Array' || value_type == 'Float') ? "text_field" : value_type) %>
<% if value_type == 'Fixnum' %>
<% if @value == 1%>

View File

@ -277,15 +277,27 @@
<div><%= form.check_box "form_result_is_right",{:checked=>false,:class=>"checkbox",:style=>"float: left;position: relative;left: 0;transform: none!important;margin-left: 1em;",:id=>"form_result_is_right"}%></div>
<%end%>
<div style="clear:both;"></div>
<% @create_items = ['years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block'] %>
<% @create_items.each do |item|%>
<% @create_items = ['years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block']
array_indices = [0]
%>
<% @create_items.each_with_index do |item, i|%>
<label for="<%=item%>" style="float: left;margin-right:1em;width:11em;"><%= t('coloncancerpredict2.'+item)+':' %></label>
<% if @form_to_show[item].class == BSON::Document || @form_to_show[item].class == Hash %>
<%= form.fields_for item do |locale_fields|%>
<%= locale_fields.text_field I18n.locale.to_s,{:value=>@form_to_show[item][I18n.locale.to_s] ,:id=> item,:style=>'width:calc(100% - 16em)'} %>
<% value = @form_to_show[item][I18n.locale.to_s]
if array_indices.include?(i)
value = cc2_yaml_dump(value)
end
%>
<%= locale_fields.text_field I18n.locale.to_s,{:value=> value,:id=> item,:style=>'width:calc(100% - 16em)'} %>
<% end %>
<% else %>
<%= form.text_field item,{:value=>@form_to_show[item],:id=> item,:style=>'width:calc(100% - 16em)'} %>
<% value = @form_to_show[item]
if array_indices.include?(i)
value = cc2_yaml_dump(value)
end
%>
<%= form.text_field item,{:value=> value,:id=> item,:style=>'width:calc(100% - 16em)'} %>
<% end %>
<div style="clear:both;"></div>
<% end %>

View File

@ -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" %>

View File

@ -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" %>