Fix backend page bug.

This commit is contained in:
BoHung Chiu 2022-01-28 12:49:19 +08:00
parent 5bf740d454
commit dd52046c16
1 changed files with 77 additions and 80 deletions

View File

@ -31,14 +31,7 @@ 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
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)
@ -66,7 +59,7 @@ class Admin::CancerpredictsController < OrbitAdminController
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 != Array
if type == Fixnum
@form_to_show.form_show[num.to_s][key.to_s] = value.to_i rescue 0
elsif type == Float
@ -89,7 +82,7 @@ class Admin::CancerpredictsController < OrbitAdminController
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
elsif type == Float
@ -114,21 +107,19 @@ class Admin::CancerpredictsController < OrbitAdminController
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+'>'