Fix backend page bug.

This commit is contained in:
BoHung Chiu 2022-01-28 12:51:21 +08:00
parent cac17bef8c
commit a2ffbf9230
1 changed files with 77 additions and 80 deletions

View File

@ -31,104 +31,95 @@ class Admin::CancerpredictsController < OrbitAdminController
other_in_use_locales = Site.first.in_use_locales.map{|l| l.to_s} other_in_use_locales = Site.first.in_use_locales.map{|l| l.to_s}
other_in_use_locales.delete(params[:locale]) other_in_use_locales.delete(params[:locale])
if !(params["cancerpredictfields"].nil?) if !(params["cancerpredictfields"].nil?)
org_nums = @form_to_show.form_show_was.keys if !(params["cancerpredictfields"]["form_show"].nil?)
remain_org_nums = params["cancerpredictfields"]["form_show"].values.map{|property| property["old_num"]}.select{|n| n.present?} params["cancerpredictfields"]["form_show"].each do |num,property|
delete_nums = org_nums - remain_org_nums property.each do |key,value|
if !delete_nums.blank? if key.include?("_file") && (!value[:temp_file].blank? rescue false)
delete_nums.each do |delete_num| if value[:id].nil?
@form_to_show.form_show.delete(delete_num) mapping_file = CancerPredictMappingFile.create(value)
end
end
params["cancerpredictfields"]["form_show"].each do |num,property|
property.each do |key,value|
if key.include?("_file") && (!value[:temp_file].blank? rescue false)
if value[:id].nil?
mapping_file = CancerPredictMappingFile.create(value)
else
mapping_file = CancerPredictMappingFile.find(value[:id])
mapping_file.temp_file = value[:temp_file]
mapping_file.save
end
@form_to_show.form_show[num.to_s][key.to_s] = mapping_file.id
elsif key.include?("_file")
if value[:_destroy] == "1"
mapping_file = CancerPredictMappingFile.find(value[:id])
mapping_file.destroy
@form_to_show.form_show[num.to_s][key.to_s] = ""
end
end
next if key.include?("_file")
if (key != "old_num")
if key != params[:locale]
@form_to_show.form_show[num.to_s] = {} if @form_to_show.form_show[num.to_s].nil?
type = Cancerpredictfields::FIELDINFO[key.to_s]
if type && Cancerpredictfields::Field_relations[type]
type = Cancerpredictfields::Field_relations[type]
end
type = type.constantize rescue String
if @form_to_show.form_show[num.to_s][key.to_s].class != Array && type != Array
if type == Fixnum
@form_to_show.form_show[num.to_s][key.to_s] = value.to_i rescue 0
elsif type == Float
@form_to_show.form_show[num.to_s][key.to_s] = value.to_f rescue 0.0
else
@form_to_show.form_show[num.to_s][key.to_s] = value
end
else else
if value.length > 2 mapping_file = CancerPredictMappingFile.find(value[:id])
@form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value) mapping_file.temp_file = value[:temp_file]
else mapping_file.save
@form_to_show.form_show[num.to_s][key.to_s] = []
end
end end
else @form_to_show.form_show[num.to_s][key.to_s] = mapping_file.id
value.each do |sub_property,sub_value| elsif key.include?("_file")
type = Cancerpredictfields::FIELDINFO[sub_property.to_s] if value[:_destroy] == "1"
mapping_file = CancerPredictMappingFile.find(value[:id])
mapping_file.destroy
@form_to_show.form_show[num.to_s][key.to_s] = ""
end
end
next if key.include?("_file")
if (key != "old_num")
if key != params[:locale]
@form_to_show.form_show[num.to_s] = {} if @form_to_show.form_show[num.to_s].nil?
type = Cancerpredictfields::FIELDINFO[key.to_s]
if type && Cancerpredictfields::Field_relations[type] if type && Cancerpredictfields::Field_relations[type]
type = Cancerpredictfields::Field_relations[type] type = Cancerpredictfields::Field_relations[type]
end end
type = type.constantize rescue String type = type.constantize rescue String
@form_to_show.form_show[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil? if type != Array
if @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array
if type == Fixnum if type == Fixnum
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0 @form_to_show.form_show[num.to_s][key.to_s] = value.to_i rescue 0
elsif type == Float elsif type == Float
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_f rescue 0.0 @form_to_show.form_show[num.to_s][key.to_s] = value.to_f rescue 0.0
else else
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value @form_to_show.form_show[num.to_s][key.to_s] = value
end end
else else
if sub_value.length > 2 if 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][key.to_s] = YAML.load(value)
else else
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = [] @form_to_show.form_show[num.to_s][key.to_s] = []
end end
end end
if(property["old_num"] != nil && property["old_num"] != num.to_s) else
other_in_use_locales.each do |locale| value.each do |sub_property,sub_value|
@form_to_show.form_show[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale] type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
if type && Cancerpredictfields::Field_relations[type]
type = Cancerpredictfields::Field_relations[type]
end
type = type.constantize rescue String
@form_to_show.form_show[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil?
if type != Array
if type == Fixnum
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0
elsif type == Float
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_f rescue 0.0
else
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value
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)
else
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end
end
if(property["old_num"] != nil && property["old_num"] != num.to_s)
other_in_use_locales.each do |locale|
@form_to_show.form_show[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale]
end
end end
end end
end end
end end
end end
end end
end org_nums = @form_to_show.form_show_was.keys
largest_num = org_nums.map{|n| n.to_i}.sort.last remain_org_nums = params["cancerpredictfields"]["form_show"].values.map{|property| property["old_num"]}.select{|n| n.present?}
if (params["cancerpredictfields"]["form_show"].keys.last.to_i + 1 ) <= largest_num
( (params["cancerpredictfields"]["form_show"].keys.last.to_i + 1 ) .. (largest_num)).each do |i|
@form_to_show.form_show.delete i.to_s
end
end
if !params["cancerpredictfields"]["form_show_in_result"].nil?
org_nums = @form_to_show.form_show_in_result_was.keys
remain_org_nums = params["cancerpredictfields"]["form_show_in_result"].values.map{|property| property["old_num"]}.select{|n| n.present?}
delete_nums = org_nums - remain_org_nums delete_nums = org_nums - remain_org_nums
if !delete_nums.blank? if !delete_nums.blank?
delete_nums.each do |delete_num| delete_nums.each do |delete_num|
@form_to_show.form_show_in_result.delete(delete_num) @form_to_show.form_show.delete(delete_num)
end end
end end
@form_to_show.form_show = @form_to_show.form_show.values.map.with_index{|v,i| [i.to_s, v]}.to_h
else
@form_to_show.form_show = {}
end
if !params["cancerpredictfields"]["form_show_in_result"].nil?
params["cancerpredictfields"]["form_show_in_result"].each do |num,property| params["cancerpredictfields"]["form_show_in_result"].each do |num,property|
property.each do |key,value| property.each do |key,value|
if key.include?("_file") && (!value[:temp_file].blank? rescue false) if key.include?("_file") && (!value[:temp_file].blank? rescue false)
@ -156,7 +147,7 @@ class Admin::CancerpredictsController < OrbitAdminController
type = Cancerpredictfields::Field_relations[type] type = Cancerpredictfields::Field_relations[type]
end end
type = type.constantize rescue String type = type.constantize rescue String
if @form_to_show.form_show_in_result[num.to_s][key.to_s].class != Array && type != Array if type != Array
if type == Fixnum if type == Fixnum
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i rescue 0 @form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i rescue 0
elsif type == Float elsif type == Float
@ -178,8 +169,8 @@ class Admin::CancerpredictsController < OrbitAdminController
type = Cancerpredictfields::Field_relations[type] type = Cancerpredictfields::Field_relations[type]
end end
type = type.constantize rescue String type = type.constantize rescue String
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil? @form_to_show.form_show_in_result[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show_in_result[num.to_s][ sub_property ].nil?
if @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array if type != Array
if type == Fixnum if type == Fixnum
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0 @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_i rescue 0
elsif type == Float elsif type == Float
@ -204,12 +195,17 @@ class Admin::CancerpredictsController < OrbitAdminController
end end
end end
end end
largest_num = org_nums.map{|n| n.to_i}.sort.last org_nums = @form_to_show.form_show_in_result_was.keys
if (params["cancerpredictfields"]["form_show_in_result"].keys.last.to_i + 1 ) <= largest_num remain_org_nums = params["cancerpredictfields"]["form_show_in_result"].values.map{|property| property["old_num"]}.select{|n| n.present?}
( (params["cancerpredictfields"]["form_show_in_result"].keys.last.to_i + 1 ) .. (largest_num)).each do |i| delete_nums = org_nums - remain_org_nums
@form_to_show.form_show_in_result.delete i.to_s if !delete_nums.blank?
delete_nums.each do |delete_num|
@form_to_show.form_show_in_result.delete(delete_num)
end end
end end
@form_to_show.form_show_in_result = @form_to_show.form_show_in_result.values.map.with_index{|v,i| [i.to_s, v]}.to_h
else
@form_to_show.form_show_in_result = {}
end end
@create_items = ['title_texts','form_result_is_right','text_descibe','years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block','prediction_formula','hidden_variables','advance_mode'] @create_items = ['title_texts','form_result_is_right','text_descibe','years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block','prediction_formula','hidden_variables','advance_mode']
params_cancer = params.require("cancerpredictfields").permit! params_cancer = params.require("cancerpredictfields").permit!
@ -521,6 +517,7 @@ class Admin::CancerpredictsController < OrbitAdminController
else else
@disp_value = @value @disp_value = @value
end end
@disp_value = "" if @disp_value.nil?
@field_property[key] = @disp_value @field_property[key] = @disp_value
end end
@table_result_choice_fileds += '<div data-key='+num.to_s+'>' @table_result_choice_fileds += '<div data-key='+num.to_s+'>'