From 64626817e9e0aeecdc7aac616ba21ab7f730f442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 21 Aug 2024 23:11:17 +0800 Subject: [PATCH] Fix bug in backend setting. --- .../admin/cancerpredicts_controller.rb | 27 ++++++++++--------- app/helpers/admin/cancerpredicts_helper.rb | 9 +++++++ app/views/admin/cancerpredicts/_form.html.erb | 1 + app/views/admin/cancerpredicts/index.html.erb | 20 +++++++++++--- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/cancerpredicts_controller.rb b/app/controllers/admin/cancerpredicts_controller.rb index dba1238..a04684e 100644 --- a/app/controllers/admin/cancerpredicts_controller.rb +++ b/app/controllers/admin/cancerpredicts_controller.rb @@ -14,6 +14,9 @@ class Admin::CancerpredictsController < OrbitAdminController super @app_title = "cancerpredict" 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::CancerpredictsController < 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::CancerpredictsController < 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::CancerpredictsController < 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::CancerpredictsController < 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::CancerpredictsController < 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::CancerpredictsController < OrbitAdminController end end @size = ['small','medium','large'] - @size.each{|size| @form_to_show[size] = params["cancerpredictfields"][size]} + @size.each{|size| @form_to_show[size] = params["cancerpredictfields"][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::CancerpredictsController < OrbitAdminController else @table_str_left += '
' @field_property["choice_fields"].each do |create_choice| - @table_str_left += '' - @table_str_left += '' + @table_str_left += '' + @table_str_left += '' end @table_str_left += '
' end @@ -481,8 +484,8 @@ class Admin::CancerpredictsController < OrbitAdminController else @table_str_right += '
' @field_property["choice_fields"].each do |create_choice| - @table_str_right += '' - @table_str_right += '' + @table_str_right += '' + @table_str_right += '' end @table_str_right += '
' end @@ -573,8 +576,8 @@ class Admin::CancerpredictsController < OrbitAdminController else @table_result_choice_fileds += '
' @field_property["choice_fields"].each do |create_choice| - @table_result_choice_fileds += '' - @table_result_choice_fileds += '' + @table_result_choice_fileds += '' + @table_result_choice_fileds += '' end @table_result_choice_fileds += '
' end diff --git a/app/helpers/admin/cancerpredicts_helper.rb b/app/helpers/admin/cancerpredicts_helper.rb index 57c1789..d89cdd4 100644 --- a/app/helpers/admin/cancerpredicts_helper.rb +++ b/app/helpers/admin/cancerpredicts_helper.rb @@ -1,4 +1,13 @@ module Admin::CancerpredictsHelper + def bc_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=Cancerpredictrecord.all,extra_params="") page = 1 if page == 0 per_page_num = 10.0 diff --git a/app/views/admin/cancerpredicts/_form.html.erb b/app/views/admin/cancerpredicts/_form.html.erb index 9a45a21..23914dd 100644 --- a/app/views/admin/cancerpredicts/_form.html.erb +++ b/app/views/admin/cancerpredicts/_form.html.erb @@ -16,6 +16,7 @@ <%else%> <% @disp_value = @value %> <%end%> + <% @disp_value = bc_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%> diff --git a/app/views/admin/cancerpredicts/index.html.erb b/app/views/admin/cancerpredicts/index.html.erb index 2726e8a..2f8690e 100644 --- a/app/views/admin/cancerpredicts/index.html.erb +++ b/app/views/admin/cancerpredicts/index.html.erb @@ -277,15 +277,27 @@
<%= 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"}%>
<%end%>
- <% @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|%> <% 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 = bc_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 = bc_yaml_dump(value) + end + %> + <%= form.text_field item,{:value=> value,:id=> item,:style=>'width:calc(100% - 16em)'} %> <% end %>
<% end %>