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.delete(params[:locale])
if !(params["cancerpredictfields"].nil?)
org_nums = @form_to_show.form_show_was.keys
remain_org_nums = params["cancerpredictfields"]["form_show"].values.map{|property| property["old_num"]}.select{|n| n.present?}
delete_nums = org_nums - remain_org_nums
if !delete_nums.blank?
delete_nums.each do |delete_num|
@form_to_show.form_show.delete(delete_num)
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
if !(params["cancerpredictfields"]["form_show"].nil?)
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
if value.length > 2
@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
mapping_file = CancerPredictMappingFile.find(value[:id])
mapping_file.temp_file = value[:temp_file]
mapping_file.save
end
else
value.each do |sub_property,sub_value|
type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
@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
@form_to_show.form_show[ num.to_s ][ sub_property ] = {} if @form_to_show.form_show[num.to_s][ sub_property ].nil?
if @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array
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
@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 ][ 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
@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
else
if sub_value.length > 2
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
if value.length > 2
@form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value)
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
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]
else
value.each do |sub_property,sub_value|
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
largest_num = org_nums.map{|n| n.to_i}.sort.last
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?}
org_nums = @form_to_show.form_show_was.keys
remain_org_nums = params["cancerpredictfields"]["form_show"].values.map{|property| property["old_num"]}.select{|n| n.present?}
delete_nums = org_nums - remain_org_nums
if !delete_nums.blank?
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
@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|
property.each do |key,value|
if key.include?("_file") && (!value[:temp_file].blank? rescue false)
@ -156,7 +147,7 @@ class Admin::CancerpredictsController < OrbitAdminController
type = Cancerpredictfields::Field_relations[type]
end
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
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i rescue 0
elsif type == Float
@ -178,8 +169,8 @@ class Admin::CancerpredictsController < OrbitAdminController
type = Cancerpredictfields::Field_relations[type]
end
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?
if @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array && type != Array
@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 type != Array
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
elsif type == Float
@ -204,12 +195,17 @@ class Admin::CancerpredictsController < OrbitAdminController
end
end
end
largest_num = org_nums.map{|n| n.to_i}.sort.last
if (params["cancerpredictfields"]["form_show_in_result"].keys.last.to_i + 1 ) <= largest_num
( (params["cancerpredictfields"]["form_show_in_result"].keys.last.to_i + 1 ) .. (largest_num)).each do |i|
@form_to_show.form_show_in_result.delete i.to_s
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
if !delete_nums.blank?
delete_nums.each do |delete_num|
@form_to_show.form_show_in_result.delete(delete_num)
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
@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!
@ -521,6 +517,7 @@ class Admin::CancerpredictsController < OrbitAdminController
else
@disp_value = @value
end
@disp_value = "" if @disp_value.nil?
@field_property[key] = @disp_value
end
@table_result_choice_fileds += '<div data-key='+num.to_s+'>'