From 190752a275ad5bc16f138cdf049d897a4a646428 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Sun, 15 Dec 2019 21:08:41 +0800 Subject: [PATCH] finish the first version of predict tool.and finish the backend control panel of this tool. --- app/assets/javascripts/cancer_predict.js | 5 + app/assets/stylesheets/cancer_predict.css | 10 + .../admin/cancerpredicts_controller.rb | 221 +++++++++++------- app/controllers/cancerpredicts_controller.rb | 197 +++++++++------- app/models/cancerpredictfields.rb | 7 +- app/models/head_images_uploader.rb | 33 +++ app/models/headimages.rb | 13 ++ .../admin/cancerpredicts/_image_form.html.erb | 30 +++ app/views/admin/cancerpredicts/index.html.erb | 134 ++++++++++- config/locales/en.yml | 6 + config/locales/zh_tw.yml | 6 + 11 files changed, 491 insertions(+), 171 deletions(-) create mode 100644 app/models/head_images_uploader.rb create mode 100644 app/models/headimages.rb create mode 100644 app/views/admin/cancerpredicts/_image_form.html.erb diff --git a/app/assets/javascripts/cancer_predict.js b/app/assets/javascripts/cancer_predict.js index 30553c5..f188926 100644 --- a/app/assets/javascripts/cancer_predict.js +++ b/app/assets/javascripts/cancer_predict.js @@ -1,4 +1,9 @@ $(document).ready(function(){ + var head_images = $.post("/cancerpredictResult",{"header":1}) + head_images.done(function(){ + $('.header-nav').html(head_images.responseJSON['head_images']); + $('.navbar-brand').html(head_images.responseJSON['title']) + }); Array.prototype.remove_item_from_array = function(){ var result_array = this; for(var i=0;iimage_id.to_s)} rescue nil + @title_images_id.each{|image_id| @title_images.push Headimages.find_by(:id=>image_id.to_s)} rescue nil + @head_new_image = Headimages.new(:cancerpredictfields_id => @form_to_show.id) end def edit - params["cancerpredictfields"]["form_show"].each do |num,property| - property.each do |key,value| - if value != "0" && value != "1" - if key != params[:locale] - if @form_to_show.form_show[num.to_s][key.to_s].class != Array - @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] = YAML.load(value) + if !(params["cancerpredictfields"].nil?) + params["cancerpredictfields"]["form_show"].each do |num,property| + property.each do |key,value| + if value != "0" && value != "1" + if key != params[:locale] + if @form_to_show.form_show[num.to_s][key.to_s].class != Array + @form_to_show.form_show[num.to_s][key.to_s] = value else - @form_to_show.form_show[num.to_s][key.to_s] = [] - end - end - else - value.each do |sub_property,sub_value| - if @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array - @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value - 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 + else + value.each do |sub_property,sub_value| + if @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array + @form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value + 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 end end + else + @form_to_show.form_show[num.to_s][key.to_s] = value.to_i end - else - @form_to_show.form_show[num.to_s][key.to_s] = value.to_i 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) + 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 - @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) + 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 ][ sub_property ][params[:locale].to_s] = [] + @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 - else - @form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i 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 + @images = params["cancerpredictfields"]['head_images'] + @head_images_id = @form_to_show.head_images_id + @delete_index = [] + if !@images.nil? + @images.each do |num,image| + if num.to_i < @head_images_id.length && @head_images_id.length != 0 + if image['remove_image'] == "1" + @delete_index.push num.to_i + else + @image_id = @head_images_id[num.to_i] + @image = Headimages.find_by(:id=>@image_id.to_s) + if !image['sort_number'].nil? + @image.sort_number = image['sort_number'].to_i + @image.save + end + next if image['temp_file'] == nil + @file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next + @image.sort_number = image['sort_number'].to_i + @image.temp_file = image['temp_file'] + @image.save + end + else + @file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next + @headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id,:title => @app_title) + @headimages.temp_file = image['temp_file'] + @headimages.sort_number = image['sort_number'].to_i if !image['sort_number'].nil? + @headimages.save + @form_to_show.head_images_id.push @headimages.id + end + end + end + @delete_index.reverse! + @delete_index.each do |i| + @image_id = @head_images_id[i.to_i] + Headimages.find_by(:id => @image_id ).destroy rescue next + @form_to_show.head_images_id.delete(@image_id) + end + @images = params["cancerpredictfields"]['title_images'] + @title_images_id = @form_to_show.title_images_id + @delete_index = [] + if !@images.nil? + @images.each do |num,image| + if num.to_i < @title_images_id.length && @title_images_id.length != 0 + if image['remove_image'] == "1" + @delete_index.push num.to_i + else + @image_id = @title_images_id[num.to_i] + @image = Headimages.find_by(:id=>@image_id.to_s) + if !image['sort_number'].nil? + @image.sort_number = image['sort_number'].to_i + @image.save + end + next if image['temp_file'] == nil + @file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next + @image.sort_number = image['sort_number'].to_i + @image.temp_file = image['temp_file'] + @image.save + end + else + @file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next + @headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id,:title => @app_title) + @headimages.temp_file = image['temp_file'] + @headimages.sort_number = image['sort_number'].to_i if !image['sort_number'].nil? + @headimages.save + @form_to_show.title_images_id.push @headimages.id + end + end + end + @delete_index.reverse! + @delete_index.each do |i| + @image_id = @title_images_id[i.to_i] + Headimages.find_by(:id => @image_id ).destroy rescue next + @form_to_show.title_images_id.delete(@image_id) + end + @form_to_show.title_texts = params['cancerpredictfields']['title_texts'] + @form_to_show.save 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 - #params.cancerpredictfields - #render :html => params["cancerpredictfields"]["form_result_is_right"].to_s - render :html => params["cancerpredictfields"].to_s - #redirect_to admin_cancerpredicts_path + redirect_to admin_cancerpredicts_path end def showSubmit @results = Cancerpredictrecord.where("title"=>@app_title).take_while{true} @@ -146,7 +204,6 @@ class Admin::CancerpredictsController < OrbitAdminController @choicenames.push @form_to_show.form_show[index.to_s]["choice_fields"][I18n.locale.to_s] end end - #render :html => @result_names.to_s end def create_first_field if Cancerpredictfields.where("title"=>(@app_title + "_back")).take_while{true}.count == 0 diff --git a/app/controllers/cancerpredicts_controller.rb b/app/controllers/cancerpredicts_controller.rb index 3ee4656..a86059f 100644 --- a/app/controllers/cancerpredicts_controller.rb +++ b/app/controllers/cancerpredicts_controller.rb @@ -10,96 +10,121 @@ class CancerpredictsController < ApplicationController tags = OrbitHelper.widget_tags categories = OrbitHelper.widget_categories || [] create_first_field - @record = Cancerpredictrecord.new - @record.title = @app_title - params['data'].each do |rec_key,rec_value| - @record.result[rec_key] = rec_value - end - @record.submit_time = Time.now.to_s - @record.save - 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['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 - result['grade_2'] = 1 - else - result['grade_2'] = 0 - end - if params['data']['grade'].to_i == 3 - result['grade_3'] = 1 - else - result['grade_3'] = 0 - end - if params['data']['subtype'].to_i == 2 - result['subtype_HER2'] = 1 - else - result['subtype_HER2'] = 0 - end - if params['data']['subtype'].to_i == 3 - result['subtype_triple'] = 1 - else - result['subtype_triple'] = 0 - end - if params['data']['pstage'].to_i == 2 - result['pstage_2'] = 1 - else - result['pstage_2'] = 0 - end - if params['data']['pstage'].to_i == 3 - result['pstage_3'] = 1 - else - result['pstage_3'] = 0 - end - if params['data']['pstage'].to_i == 4 - result['pstage_4'] = 1 - else - result['pstage_4'] = 0 - end - if params['data']['lvi'].to_i == 1 - result['lvi_yes'] = 1 - else - result['lvi_yes'] = 0 - end - result['lpv'] = ((result['age1']-0.7276655)*(10.87)+(result['age2']+0.4540707)*8.968+(result['size1']-0.643632)*0.7678+(result['nposit']-1.346932)*0.5339+ - result['grade_2']*0.4795+result['grade_3']*0.818+result['subtype_HER2']*0.1806+result['subtype_triple']*0.6457+result['pstage_2']*0.5311+ - result['pstage_3']*1.134+result['pstage_4']*2.172+result['lvi_yes']*0.3321-0.04 rescue 'error') - @years = ['1','3','5'] - result['table'] = '

此分析微針對已接受手術後病人,下表為此病人分別在第1年、3及5年下,根據選定的術後治療所估計的存活率

' - result['table'] += '' - result['years'] = @years - @years.each{|year| result['table'] += ('')} - result['table'] += '' - @table_head = (locale == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)'] - @head_name = ['Treatment','Additional_Benefit','Overall_Survival'] - @therapy_choices = (locale == "zh_tw") ? ['純手術'] :['Surgery only'] - @form_to_show.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale]} - @therapy_names = ['Surgery_only'] - @form_to_show.form_show_in_result.values.each{|choice| @therapy_names.push choice["variable"]} - result['treatmeny_method'] = @therapy_names - result['table'] += '' - @table_head.each_with_index{|head,index| result['table'] += ('')} - result['table'] += '' - @therapy_choices.each_with_index do |choice,i| - result['table'] += '' - @table_head.each_with_index do |head,index| - result['table'] += ('') + #begin + if params['header'].to_i == 1 + result = {} + @head_images = {} + @form_to_show.head_images_id.each do |image_id| + next if image_id.to_s == "" + @image = Headimages.find_by(:id=>image_id.to_s) + @url = @image.temp_file.to_s + @head_images[@image.sort_number.to_i] = ('') end - result['table'] += '' + result['head_images'] = Hash[@head_images.sort].values.join('') + @head_images = {} + @form_to_show.title_images_id.each do |image_id| + next if image_id.to_s == "" + @image = Headimages.find_by(:id=>image_id.to_s) + @url = @image.temp_file.to_s + @head_images[@image.sort_number.to_i] = ('') + end + + result['title'] = ((@form_to_show.title_texts == "") ? "" : ''+@form_to_show.title_texts+'')+Hash[@head_images.sort].values.join('') + else + @record = Cancerpredictrecord.new + @record.title = @app_title + params['data'].each do |rec_key,rec_value| + @record.result[rec_key] = rec_value + end + @record.submit_time = Time.now.to_s + @record.save + 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['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 + result['grade_2'] = 1 + else + result['grade_2'] = 0 + end + if params['data']['grade'].to_i == 3 + result['grade_3'] = 1 + else + result['grade_3'] = 0 + end + if params['data']['subtype'].to_i == 2 + result['subtype_HER2'] = 1 + else + result['subtype_HER2'] = 0 + end + if params['data']['subtype'].to_i == 3 + result['subtype_triple'] = 1 + else + result['subtype_triple'] = 0 + end + if params['data']['pstage'].to_i == 2 + result['pstage_2'] = 1 + else + result['pstage_2'] = 0 + end + if params['data']['pstage'].to_i == 3 + result['pstage_3'] = 1 + else + result['pstage_3'] = 0 + end + if params['data']['pstage'].to_i == 4 + result['pstage_4'] = 1 + else + result['pstage_4'] = 0 + end + if params['data']['lvi'].to_i == 1 + result['lvi_yes'] = 1 + else + result['lvi_yes'] = 0 + end + result['lpv'] = ((result['age1']-0.7276655)*(10.87)+(result['age2']+0.4540707)*8.968+(result['size1']-0.643632)*0.7678+(result['nposit']-1.346932)*0.5339+ + result['grade_2']*0.4795+result['grade_3']*0.818+result['subtype_HER2']*0.1806+result['subtype_triple']*0.6457+result['pstage_2']*0.5311+ + result['pstage_3']*1.134+result['pstage_4']*2.172+result['lvi_yes']*0.3321-0.04 rescue 'error') + @years = ['1','3','5'] + result['table'] = '

此分析微針對已接受手術後病人,下表為此病人分別在第1年、3及5年下,根據選定的術後治療所估計的存活率

' + result['table'] += '' + result['years'] = @years + @years.each{|year| result['table'] += ('')} + result['table'] += '' + @table_head = (locale == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)'] + @head_name = ['Treatment','Additional_Benefit','Overall_Survival'] + @therapy_choices = (locale == "zh_tw") ? ['純手術'] :['Surgery only'] + @form_to_show.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale]} + @therapy_names = ['Surgery_only'] + @form_to_show.form_show_in_result.values.each{|choice| @therapy_names.push choice["variable"]} + result['treatmeny_method'] = @therapy_names + result['table'] += '
' + head + '
' + ((index == 0) ? (((i==0)? '' : '+') + choice) : '-') + '
' + @table_head.each_with_index{|head,index| result['table'] += ('')} + result['table'] += '' + @therapy_choices.each_with_index do |choice,i| + result['table'] += '' + @table_head.each_with_index do |head,index| + result['table'] += ('') + end + result['table'] += '' + end + result['texts'] = '此研究分析來自已接受根除性手術後之婦女所得之結果,根據您所輸入的資訊以及治療方式,'+'
'+'在術後第' + @years.each{|year| result['texts'] += ('')} + result['texts'] += ',' + @servive_ratio = ((Math.exp(-0.001476145)**(Math.exp(result['lpv'])))*100).round + result['texts'] += ('

100 位只接受根除性手術的婦女中,有 '+ ''+@servive_ratio.round.to_s+''+' 位婦女,術後 '+''+@years[0].to_s+''+'年仍為存活

') + result['texts'] += ''+',此外' + result['servive_ratio'] = @servive_ratio end - result['texts'] = '此研究分析來自已接受根除性手術後之婦女所得之結果,根據您所輸入的資訊以及治療方式,'+'
'+'在術後第' - @years.each{|year| result['texts'] += ('')} - result['texts'] += ',' - @servive_ratio = ((Math.exp(-0.001476145)**(Math.exp(result['lpv'])))*100).round - result['texts'] += ('

100 位只接受根除性手術的婦女中,有 '+ ''+@servive_ratio.round.to_s+''+' 位婦女,術後 '+''+@years[0].to_s+''+'年仍為存活

') - result['texts'] += ''+',此外' - result['servive_ratio'] = @servive_ratio result = result.merge(params) render :json=> result +# rescue + # render :json=> params + #end end def index uid = OrbitHelper.params[:uid] rescue "" diff --git a/app/models/cancerpredictfields.rb b/app/models/cancerpredictfields.rb index 9b1b5b3..a2712a1 100644 --- a/app/models/cancerpredictfields.rb +++ b/app/models/cancerpredictfields.rb @@ -6,7 +6,6 @@ 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}, @@ -29,7 +28,11 @@ class Cancerpredictfields 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: [] + field :image_path ,type:String ,default:"1.25em" + field :head_images_id ,type:Array , default: [] + field :title_images_id ,type:Array , default: [] + field :title_texts ,type:String ,default:"" + #field :image_uploader ,type:Object 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/models/head_images_uploader.rb b/app/models/head_images_uploader.rb new file mode 100644 index 0000000..c79e018 --- /dev/null +++ b/app/models/head_images_uploader.rb @@ -0,0 +1,33 @@ +# encoding: utf-8 +require 'carrierwave/processing/mime_types' + +class HeadImagesUploader < CarrierWave::Uploader::Base + + include CarrierWave::MimeTypes + + process :set_content_type + + # Include RMagick or ImageScience support: + # include CarrierWave::RMagick + # include CarrierWave::ImageScience + + # Choose what kind of storage to use for this uploader: + # storage :file + # storage :s3 + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + return "uploads/#{model.class.to_s.underscore}/predict_tool" + end + + # override + def filename + @original_filename + end + + def cache_dir + "#{Rails.root}/tmp/uploads" + end + +end diff --git a/app/models/headimages.rb b/app/models/headimages.rb new file mode 100644 index 0000000..c84c073 --- /dev/null +++ b/app/models/headimages.rb @@ -0,0 +1,13 @@ +class Headimages + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include OrbitModel::Impression + # encoding: utf-8 + include OrbitTag::Taggable + include OrbitCategory::Categorizable + mount_uploader :temp_file, HeadImagesUploader + field :cancerpredictfields_id ,type:String ,default:"" + field :title ,type:String ,default:"" + field :sort_number ,type:Integer ,default: 0 +end \ No newline at end of file diff --git a/app/views/admin/cancerpredicts/_image_form.html.erb b/app/views/admin/cancerpredicts/_image_form.html.erb new file mode 100644 index 0000000..b2e379a --- /dev/null +++ b/app/views/admin/cancerpredicts/_image_form.html.erb @@ -0,0 +1,30 @@ +
+
+ +
+ <%= t('cancerpredict.sort_num')+': ' %> + <%= f.text_field 'sort_number',{:class=>'sort_num',:value=>((image_form['sort_number'] == nil) ? i+1 : image_form['sort_number'] ),:style=>'float: left;width: 3em;'} %> + <%= t('cancerpredict.logo')+': ' %> +
+ <% if image_form.temp_file.file.present? %> + <%= image_tag( image_form.temp_file, :size=>"120x120") rescue ''%> + <% else %> + <%= image_tag "/assets/site-logo.png", :class => "pull-left upload-picture"%> + <% end %> +
+
+ <% if image_form.temp_file.file.present?%> + + <%= f.file_field :temp_file, {:id => "input-upload", :class => 'fileupload-new', :accept=> 'image/png,image/gif,image/jpeg'} %><%= t('preferences.change') %> + + <%= f.check_box :remove_image,{:checked=>false} %> + <%= t(:remove) %> <%= (I18n.locale.to_s == 'en') ? ' this logo' : '該logo' %> + <%else%> + + <%= f.file_field :temp_file,{ :id => "input-upload", :class => 'fileupload-new', :accept=> 'image/png,image/gif,image/jpeg'} %><%= t('preferences.select_image') %> + + <%end%> + <%= t(:cancel) %> +
+
+
\ No newline at end of file diff --git a/app/views/admin/cancerpredicts/index.html.erb b/app/views/admin/cancerpredicts/index.html.erb index 12565f6..e78cb1a 100644 --- a/app/views/admin/cancerpredicts/index.html.erb +++ b/app/views/admin/cancerpredicts/index.html.erb @@ -1,6 +1,138 @@ +<%= stylesheet_link_tag "lib/fileupload"%> +<%= javascript_include_tag 'lib/bootstrap-fileupload' %>
<%=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.title') %> +
+ <%=form.text_field :title_texts ,{:value => @form_to_show.title_texts,:id=>"title_text"} %> + <% if @title_images.length != 0%> + <% @title_images.each_with_index do |temp_image,i| %> + <%= form.fields_for "title_images" do |image_fields| %> +
+ <%= image_fields.fields_for i.to_s do |image_field| %> + <%= render :partial => 'image_form', :object => temp_image, :locals => {:f => image_field, :i => i} %> + <% if i.to_i == @title_images.length - 1%> + + <% end %> + <% end %> + <% end %> + <% end %> + <% else %> + <%= form.fields_for "title_images" do |image_fields| %> + <%= image_fields.fields_for "0" do |image_field| %> + + <% end %> + <% end %> + <% end %> +
+

+ <%= hidden_field_tag 'title_images_count', @title_images.count %> + <%= t('cancerpredict.add_image') %> +

+ <%= t('cancerpredict.tool_head_pictures') %> +
+ <% if @head_images.length != 0%> + <% @head_images.each_with_index do |temp_image,i| %> + <%= form.fields_for "head_images" do |image_fields| %> +
+ <%= image_fields.fields_for i.to_s do |image_field| %> + <%= render :partial => 'image_form', :object => temp_image, :locals => {:f => image_field, :i => i} %> + <% if i.to_i == @head_images.length - 1%> + + <% end %> + <% end %> + <% end %> + <% end %> + <% else %> + <%= form.fields_for "head_images" do |image_fields| %> + <%= image_fields.fields_for "0" do |image_field| %> + + <% end %> + <% end %> + <% end %> +
+

+ <%= hidden_field_tag 'head_images_count', @head_images.count %> + <%= t('cancerpredict.add_image') %> +

<%= t('cancerpredict.text_descibe') %>
<%= form.text_field 'text_descibe',{:value=> @form_to_show.text_descibe[I18n.locale.to_s],:style=>'width:100%;'} %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a2c0d83..77ba77f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,6 +9,12 @@ en: medium: medium large: large Input_fields: User input fields' contents + tool_head_pictures: All the logos in the page of predict tool + sort_num: sort num + logo: logo image + title: title of the page of predict tool + title_text: title texts + add_image: add image 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 549ce86..aef0b06 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -9,6 +9,12 @@ zh_tw: medium: 中 large: 大 Input_fields: 使用者輸入欄位內容 + tool_head_pictures: 預測工具頁面最上方的所有logo + sort_num: 順序號碼 + logo: logo圖片 + title: 預測工具頁面標題 + title_text: 標題文字 + add_image: 新增圖片 table: welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊 Reset: 重置
' + head + '
' + ((index == 0) ? (((i==0)? '' : '+') + choice) : '-') + '