From 24d14e2b3b556ce515634f13706a402821e34ef4 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Sat, 14 Dec 2019 12:21:09 +0800 Subject: [PATCH] -0.5=>0.5,add image uploader --- app/assets/javascripts/cancer_predict.js | 14 +++- app/assets/stylesheets/cancer_predict.css | 65 ++++++++++++---- .../admin/cancerpredicts_controller.rb | 74 +++++++++++++++++-- app/controllers/cancerpredicts_controller.rb | 17 +++-- app/models/cancerpredictfields.rb | 7 +- app/views/admin/cancerpredicts/index.html.erb | 21 +++++- config/locales/en.yml | 7 ++ config/locales/zh_tw.yml | 7 ++ 8 files changed, 179 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/cancer_predict.js b/app/assets/javascripts/cancer_predict.js index 38a3a3e..30553c5 100644 --- a/app/assets/javascripts/cancer_predict.js +++ b/app/assets/javascripts/cancer_predict.js @@ -479,8 +479,8 @@ $(document).ready(function(){ }; function calculate_first_lpv(result_json){ result = {} - result['age1'] = -Math.pow((Number(result_json['age'])/100),-0.5); - result['age2'] = -Math.pow((Number(result_json['age'])/100),-0.5)*Math.log(result_json['age']/100); + result['age1'] = -Math.pow((Number(result_json['age'])/100),0.5); + result['age2'] = -Math.pow((Number(result_json['age'])/100),0.5)*Math.log(result_json['age']/100); result['size1'] = -Math.log(Number(result_json['size'])/10); result['nposit'] = -Math.pow(((Number(result_json['ratio'])+0.1)/0.1),0.5); if( Number(result_json['grade']) == 2) @@ -589,4 +589,14 @@ $(document).ready(function(){ $('#danger_texts').remove(); }; }); + if($(window).width() < 768) + $('#cancer_predict_result').attr('style',''); +}); +$(window).resize(function(){ + if($(window).width() > 768){ + if($('.cancer_table_right_result').length != 0) + $('#cancer_predict_result').css('float','right'); + }else{ + $('#cancer_predict_result').attr('style',''); + }; }); diff --git a/app/assets/stylesheets/cancer_predict.css b/app/assets/stylesheets/cancer_predict.css index 081bf88..ec7b437 100644 --- a/app/assets/stylesheets/cancer_predict.css +++ b/app/assets/stylesheets/cancer_predict.css @@ -18,6 +18,24 @@ } #cancer_table{ font-size:0.825em; + color:#5d7ca2; +} +#cancer_table_top{ + padding-bottom: 4em; +} +#font_texts{ + padding-right: 0.5em; +} +#text_descibe{ + font-weight: bold; + float: left; + max-width: 50%; +} +#font_size_choices{ + font-weight: bold; + float: right; + max-width: 50%; + padding-left:1em; } form.for_num{ position: relative; @@ -30,6 +48,7 @@ select.select_num{ left:1em; clip: rect(0.25em,3.8em,1.5em,2.875em); border:none; + padding: 0.5em; } input.num_only{ color: black; @@ -48,12 +67,10 @@ input.float_num{ position: relative; } #cancer_table_left{ - float:left; - width:50%; + width:100%; } #cancer_table_right{ - float:right; - width:50%; + width:100%; } #cancer_table_submit{ margin-left: 1em; @@ -63,6 +80,7 @@ input.float_num{ border: 0em; padding: 0.125em 0.5em; border-radius: 0.5em; + font-size: 1.25em; } #cancer_table_reset{ float: right; @@ -71,6 +89,7 @@ input.float_num{ border: 0em; padding: 0.125em 0.5em; border-radius: 0.5em; + font-size: 1.25em; } .btn-sub{ background:url("/assets/cancerpredict/triangle_sub.png") no-repeat top transparent; @@ -120,6 +139,7 @@ input.float_num{ border: 0em; padding: 0.125em 0.5em; border-radius: 0.5em; + font-size: 1.25em; } .result_tab{ background: #023d79; @@ -162,18 +182,6 @@ input.float_num{ margin: 0; float: left; } -#cancer_predict_result{ - width: 50%; - float: left; -} -#cancer_table_left_result{ - width: 50%; - float: left; -} -#cancer_table_right_result{ - width: 50%; - float: right; -} .result_content_group{ width: 80%; margin: 0; @@ -276,4 +284,29 @@ div.texts_show{ transform: translate(-50%, -50%) !important; overflow: auto; overflow-y: auto; +} +#cancer_predict_result{ + width: 80%; +} +@media screen and (min-width: 48em) { + #cancer_table_right{ + float:right; + width:50%; + } + #cancer_table_left{ + float:left; + width:50%; + } + #cancer_table_right_result{ + width: 50%; + float: right; + } + #cancer_table_left_result{ + width: 50%; + float: left; + } + #cancer_predict_result{ + width: 50%; + float: left; + } } \ No newline at end of file diff --git a/app/controllers/admin/cancerpredicts_controller.rb b/app/controllers/admin/cancerpredicts_controller.rb index 0d43159..a034718 100644 --- a/app/controllers/admin/cancerpredicts_controller.rb +++ b/app/controllers/admin/cancerpredicts_controller.rb @@ -25,7 +25,7 @@ class Admin::CancerpredictsController < OrbitAdminController @form_to_show.form_show[num.to_s][key.to_s] = value else if value.length > 2 - @form_to_show.form_show[num.to_s][key.to_s] = value[1..-2].split(',').collect!{|n| n.to_i} + @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 @@ -36,8 +36,7 @@ class Admin::CancerpredictsController < OrbitAdminController @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value else if sub_value.length > 2 - #render :html => sub_value.gsub('"','') and return - @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.gsub('"','')[1..-2].split(',').collect!{|n| n} + @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 @@ -49,8 +48,73 @@ class Admin::CancerpredictsController < OrbitAdminController end end end + params["cancerpredictfields"]["form_show_in_result"].each do |num,property| + property.each do |key,value| + if value != "0" && value != "1" + if key != params[:locale] + if @form_to_show.form_show_in_result[num.to_s][key.to_s].class != Array + @form_to_show.form_show_in_result[num.to_s][key.to_s] = value + else + if value.length > 2 + @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 + end + else + value.each do |sub_property,sub_value| + if @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value + 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) + else + @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = [] + end + end + end + end + else + @form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i + end + end + end + @form_to_show.form_result_is_right = params["cancerpredictfields"]["form_result_is_right"] + @form_to_show.text_descibe[I18n.locale.to_s] = params["cancerpredictfields"]["text_descibe"] + @size = ['small','medium','large'] + @size.each{|size| @form_to_show[size] = params["cancerpredictfields"][size]} + @file_path = Rails.root.to_s + '/app/assets/images/predict_tool' + if !Dir.exist? @file_path + #FileUtils.mkdir_p @file_path + end + # if @file.nil? != true + # @file_name = @file.original_filename + # @file_content = @file.read + # FileUtils.cp(@file , @file_path) + # @file_content.force_encoding('UTF-8') + # Dir.chdir(@file_path) + # @filetowrite + # if !File.file?(@file_name) + # @filetowrite = File.new(@file_name,"w") + # else + # @filetowrite = File.open(@file_name,"w") + # end + # @filetowrite.write(@file_content) + # @filetowrite.close + # Dir.chdir(Rails.root.to_s) + # else + # @file_name = @font_settings.font_file_name + # end + @field_name = {"font_file_name" => @file_name,"font_dir" => @file_path} + @field_name.each do |name,value| + @font_settings["old_" + name.to_s] = @font_settings[name.to_s] + @font_settings[name.to_s] = value.to_s + end @form_to_show.save - redirect_to admin_cancerpredicts_path + #params.cancerpredictfields + #render :html => params["cancerpredictfields"]["form_result_is_right"].to_s + render :html => params["cancerpredictfields"].to_s + #redirect_to admin_cancerpredicts_path end def showSubmit @results = Cancerpredictrecord.where("title"=>@app_title).take_while{true} @@ -68,7 +132,7 @@ class Admin::CancerpredictsController < OrbitAdminController @result_variables = [] @result_names = [] @indexs=[] - @results[0].result.each{|key,value| @result_variables.push key} + @results[0].result.each{|key,value| @result_variables.push key} rescue nil @result_variables.each do |variable| @index = @variables.index(variable.to_s) @result_names.push @names[@index] if !@index.nil? diff --git a/app/controllers/cancerpredicts_controller.rb b/app/controllers/cancerpredicts_controller.rb index 68b6ca6..3ee4656 100644 --- a/app/controllers/cancerpredicts_controller.rb +++ b/app/controllers/cancerpredicts_controller.rb @@ -20,8 +20,8 @@ class CancerpredictsController < ApplicationController locale = params['data']['locale'].to_s rescue 'zh_tw' locale = 'zh_tw' if locale == 'zh_cn' result = {} - result['age1'] = -(params['data']['age'].to_f/100)**(-0.5) - result['age2'] = -((params['data']['age'].to_f/100)**(-0.5))*Math.log(params['data']['age'].to_f/100,Math.exp(1)) + result['age1'] = -(params['data']['age'].to_f/100)**(0.5) + result['age2'] = -((params['data']['age'].to_f/100)**(0.5))*Math.log(params['data']['age'].to_f/100,Math.exp(1)) result['size1'] = -Math.log(params['data']['size'].to_f/10,Math.exp(1)) result['nposit'] = -((params['data']['ratio'].to_f+0.1)/0.1)**0.5 if params['data']['grade'].to_i == 2 @@ -105,10 +105,15 @@ class CancerpredictsController < ApplicationController uid = OrbitHelper.params[:uid] rescue "" tags = OrbitHelper.widget_tags categories = OrbitHelper.widget_categories || [] + create_first_field @table_str = '
' + @table_str += '
'+@form_to_show.text_descibe[I18n.locale.to_s] +'
' + @size = {'small'=>@form_to_show.small,'medium'=>@form_to_show.medium,'large'=>@form_to_show.large} + @table_str += '
'+'' + @size.each{|size_key,size_value| @table_str += ('' )} + @table_str += '
' @table_str_left = '
' @table_str_right = '
' - create_first_field @form_to_show.form_show.each do |num,property| @field_property = {} property.each do |key,value| @@ -200,7 +205,7 @@ class CancerpredictsController < ApplicationController @table_str_right += '
' @table_str += (@table_str_left+@table_str_right) @table_str +='
' - @table_result_str = '
'+t("cancerpredict.table.result").to_s+'
' + @table_result_str = '
'+t("cancerpredict.table.result").to_s+'
' @tab_name = ['table','text'] @table_result_str += '
' @tab_name.each_with_index{|name,index| @table_result_str += ('
')} @@ -263,8 +268,8 @@ class CancerpredictsController < ApplicationController end @table_result_choice_fileds += '
' end - @table_result_choice_fileds += '
' - @table_str += (@table_button+@table_result_str+@table_result_choice_fileds+'
') + @table_result_choice_fileds += '
' + @table_str += (@table_button+'
'+@table_result_str+@table_result_choice_fileds+'
'+'
') { "cancerpredict" => [], "extras"=>{"table"=> @table_str} diff --git a/app/models/cancerpredictfields.rb b/app/models/cancerpredictfields.rb index b0f0854..9b1b5b3 100644 --- a/app/models/cancerpredictfields.rb +++ b/app/models/cancerpredictfields.rb @@ -6,6 +6,7 @@ class Cancerpredictfields # encoding: utf-8 include OrbitTag::Taggable include OrbitCategory::Categorizable + mount_uploader :temp_file, AssetUploader field :title ,type:String ,default:"" field :form_show , :type=> Hash ,default:{0=>{:variable=>"age",:name=>{"zh_tw"=>"年齡
(age)","en"=>"age"},:is_num=>1, :hint=>{'zh_tw'=>'從 18 歲(含)開始至 93 歲','en'=>''} , :comment_text=>{'zh_tw'=>'年齡為該婦女於確診罹患乳癌時之年齡','en'=>''}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[18,93],:right=>0,:is_float=>0}, 1=>{:variable=>"size",:name=>{"zh_tw"=>"腫瘤大小
(tumor size)","en"=>"tumor size"},:is_num=>1,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'若有多個原發腫瘤,請輸入最大尺寸之原發腫瘤','en'=>''}, :choice_fields=> {"zh_tw"=>[],"en"=>[]},:range=>[1,300],:right=>0,:is_float=>0}, @@ -24,7 +25,11 @@ class Cancerpredictfields 3=>{:variable=>"Targeted_therapy",:name=>{"zh_tw"=>"標靶治療","en"=>"Targeted therapy"},:is_num=>0,:hint=>{'zh_tw'=>'','en'=>''}, :comment_text=>{'zh_tw'=>'','en'=>''}, :choice_fields=> {"zh_tw"=>['否','是'],"en"=>['No','Yes']},:range=>[]} } field :form_result_is_right , :type=> Integer ,default: 1 -# before_destroy :destroy_email + field :text_descibe ,type:Hash ,default:{"zh_tw"=>"歡迎使用台灣準備乳癌癒後系統!
若要開始 請在下方輸入相關資訊","en"=>" Welcome to The after breast cancer healing system of Taiwanprepare!\nTo start, please enter the relevant information below."} + field :small ,type:String ,default:"0.825em" + field :medium ,type:String ,default:"1em" + field :large ,type:String ,default:"1.25em" + field :head_images ,type:Array , default: [] scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])} scope :is_approved, ->{where(:approved => true)} #before_create :set_expire diff --git a/app/views/admin/cancerpredicts/index.html.erb b/app/views/admin/cancerpredicts/index.html.erb index 3041b2f..12565f6 100644 --- a/app/views/admin/cancerpredicts/index.html.erb +++ b/app/views/admin/cancerpredicts/index.html.erb @@ -1,6 +1,17 @@
-<% @i = 0 %> <%=form_for @form_to_show ,:url=>{:controller=>"cancerpredicts" ,:action=>"edit"} do |form|%> + <%= form.file_field :temp_file, accept: 'image/png,image/gif,image/jpeg'%> + <%= t('cancerpredict.text_descibe') %> +
+ <%= form.text_field 'text_descibe',{:value=> @form_to_show.text_descibe[I18n.locale.to_s],:style=>'width:100%;'} %> + <%= t('cancerpredict.font_size') %> +
+ <% @size=['small','medium','large'] %> + <% @size.each do |size|%> +
<%= form.text_field size,{:value=> @form_to_show[size],:id=>'font_'+size} %>
+ <%end%> + <%= t('cancerpredict.Input_fields') %> +
@@ -43,7 +54,7 @@
<%=t('cancerpredict.table.Results')%>
- + <% if @form_to_show.form_result_is_right.to_i == 1%>
<%= form.check_box "form_result_is_right",{:checked=>true,:class=>"checkbox",:style=>"float: left;position: relative;left: 0;transform: none!important;margin-left: 1em;",:id=>"form_result_is_right"}%>
<% else%> @@ -123,7 +134,7 @@ #updatebtn{ margin-top: 1em; right: 1em; - background-color: rgb(210, 105, 0); + background-color: #0088cc; color: white; border: 0em; padding: 0.125em 0.5em; @@ -139,4 +150,8 @@ border-radius: 0.5em; width: fit-content; } + .label_left{ + float: left; + padding-right: 0.5em; + } \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 4350afd..a2c0d83 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,13 @@ en: cancerpredict: cancerpredict: adjust the predict breast cancer tool submitResult: see submit results of the users + result_is_right: Is therapy choices in the right hand side of result block? + text_descibe: text descibe + font_size: font size + small: small + medium: medium + large: large + Input_fields: User input fields' contents table: welcome: Welcome to The after breast cancer healing system of Taiwanprepare!\nTo start, please enter the relevant information below. Reset: Reset diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index eae146d..549ce86 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,13 @@ zh_tw: cancerpredict: cancerpredict: 乳癌預測工具調整 submitResult: 查看用戶繳交表單結果 + result_is_right: 治療選項在結果的右邊? + text_descibe: 文字說明 + font_size: 字體 + small: 小 + medium: 中 + large: 大 + Input_fields: 使用者輸入欄位內容 table: welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊 Reset: 重置