Format files. (fix indent)
This commit is contained in:
parent
d2b3464359
commit
be5b892aee
|
@ -1,8 +1,8 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
class Admin::CancerpredictsController < OrbitAdminController
|
class Admin::CancerpredictsController < OrbitAdminController
|
||||||
require 'spreadsheet'
|
require "spreadsheet"
|
||||||
require 'rubyXL'
|
require "rubyXL"
|
||||||
require 'fileutils'
|
require "fileutils"
|
||||||
require "axlsx"
|
require "axlsx"
|
||||||
require "csv"
|
require "csv"
|
||||||
#include Admin::CancerpredictsHelper
|
#include Admin::CancerpredictsHelper
|
||||||
|
@ -14,9 +14,11 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
super
|
super
|
||||||
@app_title = "cancerpredict"
|
@app_title = "cancerpredict"
|
||||||
end
|
end
|
||||||
|
|
||||||
def yaml_load(v)
|
def yaml_load(v)
|
||||||
YAML.load(v)
|
YAML.load(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tags = @module_app.tags
|
@tags = @module_app.tags
|
||||||
@categories = @module_app.categories.enabled
|
@categories = @module_app.categories.enabled
|
||||||
|
@ -26,17 +28,18 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
@title_images_id = @form_to_show.title_images_id
|
@title_images_id = @form_to_show.title_images_id
|
||||||
@head_images = []
|
@head_images = []
|
||||||
@title_images = []
|
@title_images = []
|
||||||
@head_images_id.each{|image_id| @head_images.push Headimages.find_by(:id=>image_id.to_s)} rescue nil
|
@head_images_id.each { |image_id| @head_images.push Headimages.find_by(:id => image_id.to_s) } rescue nil
|
||||||
@title_images_id.each{|image_id| @title_images.push Headimages.find_by(:id=>image_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)
|
@head_new_image = Headimages.new(:cancerpredictfields_id => @form_to_show.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
other_in_use_locales = Site.first.in_use_locales.map{|l| l.to_s}
|
other_in_use_locales = Site.first.in_use_locales.map { |l| l.to_s }
|
||||||
other_in_use_locales.delete(params[:locale])
|
other_in_use_locales.delete(params[:locale])
|
||||||
if !(params["cancerpredictfields"].nil?)
|
if !(params["cancerpredictfields"].nil?)
|
||||||
if !(params["cancerpredictfields"]["form_show"].nil?)
|
if !(params["cancerpredictfields"]["form_show"].nil?)
|
||||||
params["cancerpredictfields"]["form_show"].each do |num,property|
|
params["cancerpredictfields"]["form_show"].each do |num, property|
|
||||||
property.each do |key,value|
|
property.each do |key, value|
|
||||||
if key.include?("_file") && (!value[:temp_file].blank? rescue false)
|
if key.include?("_file") && (!value[:temp_file].blank? rescue false)
|
||||||
if value[:id].nil?
|
if value[:id].nil?
|
||||||
mapping_file = CancerPredictMappingFile.create(value)
|
mapping_file = CancerPredictMappingFile.create(value)
|
||||||
|
@ -78,31 +81,31 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
value.each do |sub_property,sub_value|
|
value.each do |sub_property, sub_value|
|
||||||
type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
|
type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
|
||||||
if type && Cancerpredictfields::Field_relations[type]
|
if type && Cancerpredictfields::Field_relations[type]
|
||||||
type = Cancerpredictfields::Field_relations[type]
|
type = Cancerpredictfields::Field_relations[type]
|
||||||
end
|
end
|
||||||
type = type.constantize rescue String
|
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?
|
@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 != Array
|
||||||
if type == Fixnum
|
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][sub_property][params[:locale].to_s] = sub_value.to_i rescue 0
|
||||||
elsif type == Float
|
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][sub_property][params[:locale].to_s] = sub_value.to_f rescue 0.0
|
||||||
else
|
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][sub_property][params[:locale].to_s] = sub_value
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if sub_value.length > 2
|
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
|
else
|
||||||
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = []
|
@form_to_show.form_show[num.to_s][sub_property][params[:locale].to_s] = []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(property["old_num"].present? && property["old_num"] != num.to_s)
|
if (property["old_num"].present? && property["old_num"] != num.to_s)
|
||||||
other_in_use_locales.each do |locale|
|
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]
|
@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
|
||||||
|
@ -111,20 +114,20 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
org_nums = @form_to_show.form_show_was.keys
|
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?}
|
remain_org_nums = params["cancerpredictfields"]["form_show"].values.map { |property| property["old_num"] }.select { |n| n.present? }
|
||||||
delete_nums = org_nums - remain_org_nums
|
delete_nums = org_nums - remain_org_nums
|
||||||
if !delete_nums.blank?
|
if !delete_nums.blank?
|
||||||
delete_nums.each do |delete_num|
|
delete_nums.each do |delete_num|
|
||||||
@form_to_show.form_show.delete(delete_num)
|
@form_to_show.form_show.delete(delete_num)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@form_to_show.form_show = @form_to_show.form_show.values.map.with_index{|v,i| [i.to_s, v]}.to_h
|
@form_to_show.form_show = @form_to_show.form_show.values.map.with_index { |v, i| [i.to_s, v] }.to_h
|
||||||
else
|
else
|
||||||
@form_to_show.form_show = {}
|
@form_to_show.form_show = {}
|
||||||
end
|
end
|
||||||
if !params["cancerpredictfields"]["form_show_in_result"].nil?
|
if !params["cancerpredictfields"]["form_show_in_result"].nil?
|
||||||
params["cancerpredictfields"]["form_show_in_result"].each do |num,property|
|
params["cancerpredictfields"]["form_show_in_result"].each do |num, property|
|
||||||
property.each do |key,value|
|
property.each do |key, value|
|
||||||
if key.include?("_file") && (!value[:temp_file].blank? rescue false)
|
if key.include?("_file") && (!value[:temp_file].blank? rescue false)
|
||||||
if value[:id].nil?
|
if value[:id].nil?
|
||||||
mapping_file = CancerPredictMappingFile.create(value)
|
mapping_file = CancerPredictMappingFile.create(value)
|
||||||
|
@ -166,31 +169,31 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
value.each do |sub_property,sub_value|
|
value.each do |sub_property, sub_value|
|
||||||
type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
|
type = Cancerpredictfields::FIELDINFO[sub_property.to_s]
|
||||||
if type && Cancerpredictfields::Field_relations[type]
|
if type && Cancerpredictfields::Field_relations[type]
|
||||||
type = Cancerpredictfields::Field_relations[type]
|
type = Cancerpredictfields::Field_relations[type]
|
||||||
end
|
end
|
||||||
type = type.constantize rescue String
|
type = type.constantize rescue String
|
||||||
@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?
|
@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 != Array
|
||||||
if type == Fixnum
|
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
|
@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
|
elsif type == Float
|
||||||
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.to_f rescue 0.0
|
@form_to_show.form_show_in_result[num.to_s][sub_property][params[:locale].to_s] = sub_value.to_f rescue 0.0
|
||||||
else
|
else
|
||||||
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value
|
@form_to_show.form_show_in_result[num.to_s][sub_property][params[:locale].to_s] = sub_value
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if sub_value.length > 2
|
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
|
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][sub_property][params[:locale].to_s] = []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(property["old_num"].present? && property["old_num"] != num.to_s)
|
if (property["old_num"].present? && property["old_num"] != num.to_s)
|
||||||
other_in_use_locales.each do |locale|
|
other_in_use_locales.each do |locale|
|
||||||
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][locale] = @form_to_show.form_show_was[ property["old_num"] ][ sub_property ][locale]
|
@form_to_show.form_show_in_result[num.to_s][sub_property][locale] = @form_to_show.form_show_was[property["old_num"]][sub_property][locale]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -199,18 +202,18 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
org_nums = @form_to_show.form_show_in_result_was.keys
|
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?}
|
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
|
delete_nums = org_nums - remain_org_nums
|
||||||
if !delete_nums.blank?
|
if !delete_nums.blank?
|
||||||
delete_nums.each do |delete_num|
|
delete_nums.each do |delete_num|
|
||||||
@form_to_show.form_show_in_result.delete(delete_num)
|
@form_to_show.form_show_in_result.delete(delete_num)
|
||||||
end
|
end
|
||||||
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
|
@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
|
else
|
||||||
@form_to_show.form_show_in_result = {}
|
@form_to_show.form_show_in_result = {}
|
||||||
end
|
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','years_settings']
|
@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", "years_settings"]
|
||||||
params_cancer = params.require("cancerpredictfields").permit!
|
params_cancer = params.require("cancerpredictfields").permit!
|
||||||
@create_items.each do |item|
|
@create_items.each do |item|
|
||||||
if (@form_to_show[item].class == BSON::Document) || (@form_to_show.send(item).class == Hash)
|
if (@form_to_show[item].class == BSON::Document) || (@form_to_show.send(item).class == Hash)
|
||||||
|
@ -228,38 +231,38 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
@form_to_show[item] = params_cancer[item]
|
@form_to_show[item] = params_cancer[item]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@size = ['small','medium','large']
|
@size = ["small", "medium", "large"]
|
||||||
@size.each{|size| @form_to_show[size] = params["cancerpredictfields"][size].to_h}
|
@size.each { |size| @form_to_show[size] = params["cancerpredictfields"][size].to_h }
|
||||||
@file_path = Rails.root.to_s + '/app/assets/images/predict_tool'
|
@file_path = Rails.root.to_s + "/app/assets/images/predict_tool"
|
||||||
if !Dir.exist? @file_path
|
if !Dir.exist? @file_path
|
||||||
FileUtils.mkdir_p @file_path
|
FileUtils.mkdir_p @file_path
|
||||||
end
|
end
|
||||||
@images = params["cancerpredictfields"]['head_images']
|
@images = params["cancerpredictfields"]["head_images"]
|
||||||
@head_images_id = @form_to_show.head_images_id
|
@head_images_id = @form_to_show.head_images_id
|
||||||
@delete_index = []
|
@delete_index = []
|
||||||
if !@images.nil?
|
if !@images.nil?
|
||||||
@images.each do |num,image|
|
@images.each do |num, image|
|
||||||
if num.to_i < @head_images_id.length && @head_images_id.length != 0
|
if num.to_i < @head_images_id.length && @head_images_id.length != 0
|
||||||
if image['remove_image'] == "1"
|
if image["remove_image"] == "1"
|
||||||
@delete_index.push num.to_i
|
@delete_index.push num.to_i
|
||||||
else
|
else
|
||||||
@image_id = @head_images_id[num.to_i]
|
@image_id = @head_images_id[num.to_i]
|
||||||
@image = Headimages.find_by(:id=>@image_id.to_s)
|
@image = Headimages.find_by(:id => @image_id.to_s)
|
||||||
if !image['sort_number'].nil?
|
if !image["sort_number"].nil?
|
||||||
@image.sort_number = image['sort_number'].to_i
|
@image.sort_number = image["sort_number"].to_i
|
||||||
@image.save
|
@image.save
|
||||||
end
|
end
|
||||||
next if image['temp_file'] == nil
|
next if image["temp_file"] == nil
|
||||||
@file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
|
@file_name = image["temp_file"].original_filename.gsub("(", "_").gsub(")", "_").gsub(" ", "_") rescue next
|
||||||
@image.sort_number = image['sort_number'].to_i
|
@image.sort_number = image["sort_number"].to_i
|
||||||
@image.temp_file = image['temp_file']
|
@image.temp_file = image["temp_file"]
|
||||||
@image.save
|
@image.save
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
|
@file_name = image["temp_file"].original_filename.gsub("(", "_").gsub(")", "_").gsub(" ", "_") rescue next
|
||||||
@headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id,:title => @app_title+'head_images')
|
@headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id, :title => @app_title + "head_images")
|
||||||
@headimages.temp_file = image['temp_file']
|
@headimages.temp_file = image["temp_file"]
|
||||||
@headimages.sort_number = image['sort_number'].to_i if !image['sort_number'].nil?
|
@headimages.sort_number = image["sort_number"].to_i if !image["sort_number"].nil?
|
||||||
@headimages.save
|
@headimages.save
|
||||||
@form_to_show.head_images_id.push @headimages.id
|
@form_to_show.head_images_id.push @headimages.id
|
||||||
end
|
end
|
||||||
|
@ -268,35 +271,35 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
@delete_index.reverse!
|
@delete_index.reverse!
|
||||||
@delete_index.each do |i|
|
@delete_index.each do |i|
|
||||||
@image_id = @head_images_id[i.to_i]
|
@image_id = @head_images_id[i.to_i]
|
||||||
Headimages.find_by(:id => @image_id ).destroy rescue next
|
Headimages.find_by(:id => @image_id).destroy rescue next
|
||||||
@form_to_show.head_images_id.delete(@image_id)
|
@form_to_show.head_images_id.delete(@image_id)
|
||||||
end
|
end
|
||||||
@images = params["cancerpredictfields"]['title_images']
|
@images = params["cancerpredictfields"]["title_images"]
|
||||||
@title_images_id = @form_to_show.title_images_id
|
@title_images_id = @form_to_show.title_images_id
|
||||||
@delete_index = []
|
@delete_index = []
|
||||||
if !@images.nil?
|
if !@images.nil?
|
||||||
@images.each do |num,image|
|
@images.each do |num, image|
|
||||||
if num.to_i < @title_images_id.length && @title_images_id.length != 0
|
if num.to_i < @title_images_id.length && @title_images_id.length != 0
|
||||||
if image['remove_image'] == "1"
|
if image["remove_image"] == "1"
|
||||||
@delete_index.push num.to_i
|
@delete_index.push num.to_i
|
||||||
else
|
else
|
||||||
@image_id = @title_images_id[num.to_i]
|
@image_id = @title_images_id[num.to_i]
|
||||||
@image = Headimages.find_by(:id=>@image_id.to_s)
|
@image = Headimages.find_by(:id => @image_id.to_s)
|
||||||
if !image['sort_number'].nil?
|
if !image["sort_number"].nil?
|
||||||
@image.sort_number = image['sort_number'].to_i
|
@image.sort_number = image["sort_number"].to_i
|
||||||
@image.save
|
@image.save
|
||||||
end
|
end
|
||||||
next if image['temp_file'] == nil
|
next if image["temp_file"] == nil
|
||||||
@file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
|
@file_name = image["temp_file"].original_filename.gsub("(", "_").gsub(")", "_").gsub(" ", "_") rescue next
|
||||||
@image.sort_number = image['sort_number'].to_i
|
@image.sort_number = image["sort_number"].to_i
|
||||||
@image.temp_file = image['temp_file']
|
@image.temp_file = image["temp_file"]
|
||||||
@image.save
|
@image.save
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@file_name = image['temp_file'].original_filename.gsub('(','_').gsub(')','_').gsub(' ','_') rescue next
|
@file_name = image["temp_file"].original_filename.gsub("(", "_").gsub(")", "_").gsub(" ", "_") rescue next
|
||||||
@headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id,:title => @app_title+'title_images' )
|
@headimages = Headimages.new(:cancerpredictfields_id => @form_to_show.id, :title => @app_title + "title_images")
|
||||||
@headimages.temp_file = image['temp_file']
|
@headimages.temp_file = image["temp_file"]
|
||||||
@headimages.sort_number = image['sort_number'].to_i if !image['sort_number'].nil?
|
@headimages.sort_number = image["sort_number"].to_i if !image["sort_number"].nil?
|
||||||
@headimages.save
|
@headimages.save
|
||||||
@form_to_show.title_images_id.push @headimages.id
|
@form_to_show.title_images_id.push @headimages.id
|
||||||
end
|
end
|
||||||
|
@ -305,13 +308,13 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
@delete_index.reverse!
|
@delete_index.reverse!
|
||||||
@delete_index.each do |i|
|
@delete_index.each do |i|
|
||||||
@image_id = @title_images_id[i.to_i]
|
@image_id = @title_images_id[i.to_i]
|
||||||
Headimages.find_by(:id => @image_id ).destroy rescue next
|
Headimages.find_by(:id => @image_id).destroy rescue next
|
||||||
@form_to_show.title_images_id.delete(@image_id)
|
@form_to_show.title_images_id.delete(@image_id)
|
||||||
end
|
end
|
||||||
file_ids = (@form_to_show.form_show.values + @form_to_show.form_show_in_result.values).map{|property| [property[:variable],property[:cancer_predict_mapping_file]]}.select{|k,f| f.present?}.to_h
|
file_ids = (@form_to_show.form_show.values + @form_to_show.form_show_in_result.values).map { |property| [property[:variable], property[:cancer_predict_mapping_file]] }.select { |k, f| f.present? }.to_h
|
||||||
mapping_data_from_csv = {}
|
mapping_data_from_csv = {}
|
||||||
if !file_ids.blank?
|
if !file_ids.blank?
|
||||||
file_ids.each do |k,v|
|
file_ids.each do |k, v|
|
||||||
mapping_data_from_csv[k] = read_mapping_file(v)
|
mapping_data_from_csv[k] = read_mapping_file(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -323,14 +326,14 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
@index = 0
|
@index = 0
|
||||||
Dir.chdir("public") do
|
Dir.chdir("public") do
|
||||||
while File.exist?('cancerfield_back'+@index.to_s+'.txt')
|
while File.exist?("cancerfield_back" + @index.to_s + ".txt")
|
||||||
@index += 1
|
@index += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Dir.chdir("public") do
|
Dir.chdir("public") do
|
||||||
@site_locales = Site.last.in_use_locales.each do |locale|
|
@site_locales = Site.last.in_use_locales.each do |locale|
|
||||||
I18n.with_locale(locale) do
|
I18n.with_locale(locale) do
|
||||||
@file_tmp = File.new("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt", 'w')
|
@file_tmp = File.new("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt", "w")
|
||||||
tmp_table_texts = create_table(locale)
|
tmp_table_texts = create_table(locale)
|
||||||
@file_tmp.write(tmp_table_texts)
|
@file_tmp.write(tmp_table_texts)
|
||||||
@file_tmp.close
|
@file_tmp.close
|
||||||
|
@ -338,34 +341,35 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Dir.chdir("public") do
|
Dir.chdir("public") do
|
||||||
@file_back = File.open('cancerfield_back'+@index.to_s+'.txt', 'w')
|
@file_back = File.open("cancerfield_back" + @index.to_s + ".txt", "w")
|
||||||
@file_back.write(@form_to_show.attributes)
|
@file_back.write(@form_to_show.attributes)
|
||||||
@file_back.close
|
@file_back.close
|
||||||
@file_org = File.open('cancerfield_org'+@index.to_s+'.txt', 'w')
|
@file_org = File.open("cancerfield_org" + @index.to_s + ".txt", "w")
|
||||||
@file_org.write(Cancerpredictfields.where("title"=>@app_title+'_back').first.attributes)
|
@file_org.write(Cancerpredictfields.where("title" => @app_title + "_back").first.attributes)
|
||||||
@file_org.close
|
@file_org.close
|
||||||
end
|
end
|
||||||
redirect_to admin_cancerpredicts_path
|
redirect_to admin_cancerpredicts_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_table(current_locale)
|
def create_table(current_locale)
|
||||||
create_first_field
|
create_first_field
|
||||||
current_site = Site.last
|
current_site = Site.last
|
||||||
@size = {}
|
@size = {}
|
||||||
@size_name = ['small','medium','large']
|
@size_name = ["small", "medium", "large"]
|
||||||
@size_name.each{|name| @size[name] = @form_to_show[name]['font_size']}
|
@size_name.each { |name| @size[name] = @form_to_show[name]["font_size"] }
|
||||||
@size_active_size = ''
|
@size_active_size = ""
|
||||||
@size.each{|size_key,size_value| (@form_to_show[size_key]['active'].to_i == 1) ? ( @size_active_size = size_value ): nil }
|
@size.each { |size_key, size_value| (@form_to_show[size_key]["active"].to_i == 1) ? (@size_active_size = size_value) : nil }
|
||||||
@table_str = '<div id="cancer_table" style="font-size:' + @size_active_size + ';"><div id="show_help_modal" class="modal fade"></div>'
|
@table_str = '<div id="cancer_table" style="font-size:' + @size_active_size + ';"><div id="show_help_modal" class="modal fade"></div>'
|
||||||
@table_str += '<div id="cancer_table_top"><div id="text_describe">'+@form_to_show.text_descibe[current_locale] +'</div>'
|
@table_str += '<div id="cancer_table_top"><div id="text_describe">' + @form_to_show.text_descibe[current_locale] + "</div>"
|
||||||
@table_str += '<div id="font_size_choices">'+'<label id="font_texts">'+t('cancerpredict.font_size').titleize+':</label>'
|
@table_str += '<div id="font_size_choices">' + '<label id="font_texts">' + t("cancerpredict.font_size").titleize + ":</label>"
|
||||||
@size.each{|size_key,size_value| @table_str += ('<button class="cancer_table_btn '+((@form_to_show[size_key]['active'].to_i == 1) ? 'active' :'') + ' btn btn-default btn-sm" onclick="document.getElementById(\'cancer_table\').style[\'font-size\']=\''+size_value+'\';document.getElementById(\'cancer_predict_result_block\').style[\'font-size\']=\''+size_value+'\';">'+t('cancerpredict.'+size_key).titleize+'</button>' )}
|
@size.each { |size_key, size_value| @table_str += ('<button class="cancer_table_btn ' + ((@form_to_show[size_key]["active"].to_i == 1) ? "active" : "") + ' btn btn-default btn-sm" onclick="document.getElementById(\'cancer_table\').style[\'font-size\']=\'' + size_value + '\';document.getElementById(\'cancer_predict_result_block\').style[\'font-size\']=\'' + size_value + '\';">' + t("cancerpredict." + size_key).titleize + "</button>") }
|
||||||
@table_str += '</div></div><div style="clear:both;"></div>'
|
@table_str += '</div></div><div style="clear:both;"></div>'
|
||||||
@table_str_left = '<div id="cancer_table_left">'
|
@table_str_left = '<div id="cancer_table_left">'
|
||||||
@table_str_right = '<div id="cancer_table_right">'
|
@table_str_right = '<div id="cancer_table_right">'
|
||||||
@form_to_show.form_show.each do |num,property|
|
@form_to_show.form_show.each do |num, property|
|
||||||
@field_property = {}
|
@field_property = {}
|
||||||
property.each do |key,value|
|
property.each do |key, value|
|
||||||
@value= value
|
@value = value
|
||||||
@disp_value
|
@disp_value
|
||||||
if @value.class == BSON::Document || @value.class == Hash
|
if @value.class == BSON::Document || @value.class == Hash
|
||||||
@disp_value = @value[current_locale] rescue ""
|
@disp_value = @value[current_locale] rescue ""
|
||||||
|
@ -375,15 +379,15 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
@disp_value = "" if @disp_value.nil?
|
@disp_value = "" if @disp_value.nil?
|
||||||
@field_property[key] = @disp_value
|
@field_property[key] = @disp_value
|
||||||
end
|
end
|
||||||
if @field_property['right'] == 0
|
if @field_property["right"] == 0
|
||||||
next if @field_property["name"].blank?
|
next if @field_property["name"].blank?
|
||||||
@table_str_left += '<div data-key='+num.to_s+'>'
|
@table_str_left += "<div data-key=" + num.to_s + ">"
|
||||||
@table_str_left += '<label for="'+@field_property["variable"]+'" style="float:left;'+(@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "")+'" class="cencer_table_name">'
|
@table_str_left += '<label for="' + @field_property["variable"] + '" style="float:left;' + (@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "") + '" class="cencer_table_name">'
|
||||||
@table_str_left += @field_property["name"]
|
@table_str_left += @field_property["name"]
|
||||||
@table_str_left += '</label>'
|
@table_str_left += "</label>"
|
||||||
if @field_property["comment_text"].present?
|
if @field_property["comment_text"].present?
|
||||||
@table_str_left += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
@table_str_left += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
||||||
@table_str_left += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
|
@table_str_left += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>"
|
||||||
else
|
else
|
||||||
@site_locales = current_site.in_use_locales
|
@site_locales = current_site.in_use_locales
|
||||||
@site_locales.delete(current_locale)
|
@site_locales.delete(current_locale)
|
||||||
|
@ -394,55 +398,55 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
if @field_property["comment_text"].present?
|
if @field_property["comment_text"].present?
|
||||||
@table_str_left += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
@table_str_left += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
||||||
@table_str_left += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
|
@table_str_left += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>"
|
||||||
else
|
else
|
||||||
@table_str_left += '<div style="margin-right: 2.125em;float: left;"></div>'
|
@table_str_left += '<div style="margin-right: 2.125em;float: left;"></div>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @field_property["is_num"] == 1
|
if @field_property["is_num"] == 1
|
||||||
if @field_property["is_float"] == 1
|
if @field_property["is_float"] == 1
|
||||||
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/><input class="num_only_value" type="hidden" /></div>'
|
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/><input class="num_only_value" type="hidden" /></div>'
|
||||||
else
|
else
|
||||||
if @field_property["range"] == []
|
if @field_property["range"] == []
|
||||||
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/></div>'
|
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/></div>'
|
||||||
else
|
else
|
||||||
@table_str_left += '<div class="num_group"><form class="for_num">'
|
@table_str_left += '<div class="num_group"><form class="for_num">'
|
||||||
@table_str_left += '<input class="num_only cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/>'
|
@table_str_left += '<input class="num_only cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/>'
|
||||||
@table_str_left += '<input class="num_only_value" type="hidden" value="0"/>'
|
@table_str_left += '<input class="num_only_value" type="hidden" value="0"/>'
|
||||||
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
|
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
|
||||||
@table_str_left += '<select class="select_num"><option value="">'+@please_choice+'</option>'
|
@table_str_left += '<select class="select_num"><option value="">' + @please_choice + "</option>"
|
||||||
if @field_property["choice_fields"] != []
|
if @field_property["choice_fields"] != []
|
||||||
@field_property["choice_fields"].each do |choice|
|
@field_property["choice_fields"].each do |choice|
|
||||||
@table_str_left += ('<option value="0">' + choice.to_s.titleize + '</option>')
|
@table_str_left += ('<option value="0">' + choice.to_s.titleize + "</option>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for @num in @field_property["range"][0] .. @field_property["range"][1]
|
for @num in @field_property["range"][0]..@field_property["range"][1]
|
||||||
@table_str_left += ('<option value="' + @num.to_s + '">' + @num.to_s + '</option>')
|
@table_str_left += ('<option value="' + @num.to_s + '">' + @num.to_s + "</option>")
|
||||||
end
|
end
|
||||||
@table_str_left += '</select></form></div>'
|
@table_str_left += "</select></form></div>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@table_str_left += '<div class= "cancer-btn-group cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;">'
|
@table_str_left += '<div class= "cancer-btn-group cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;">'
|
||||||
@field_property["choice_fields"].each do |create_choice|
|
@field_property["choice_fields"].each do |create_choice|
|
||||||
@table_str_left += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.to_s.titleize+'</button>'
|
@table_str_left += '<button class="cancer_table_btn btn btn-default btn-sm">' + create_choice.to_s.titleize + "</button>"
|
||||||
@table_str_left += '<input type="hidden" value="0" name="'+create_choice.to_s+'"/>'
|
@table_str_left += '<input type="hidden" value="0" name="' + create_choice.to_s + '"/>'
|
||||||
end
|
end
|
||||||
@table_str_left += '</div>'
|
@table_str_left += "</div>"
|
||||||
end
|
end
|
||||||
if @field_property["hint"].to_s != ""
|
if @field_property["hint"].to_s != ""
|
||||||
@table_str_left +='<div style="color: rgb(104, 104, 104);font-size:0.75em;clear:both;">'+@field_property["hint"]+'</div>'
|
@table_str_left += '<div style="color: rgb(104, 104, 104);font-size:0.75em;clear:both;">' + @field_property["hint"] + "</div>"
|
||||||
end
|
end
|
||||||
@table_str_left += '</div><div style="clear:both;"></div>'
|
@table_str_left += '</div><div style="clear:both;"></div>'
|
||||||
else
|
else
|
||||||
@table_str_right += '<div data-key='+num.to_s+'>'
|
@table_str_right += "<div data-key=" + num.to_s + ">"
|
||||||
break if @field_property["name"] == ""
|
break if @field_property["name"] == ""
|
||||||
@table_str_right += '<label for="'+@field_property["variable"]+'" style="float:left;'+(@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "")+'" class="cencer_table_name">'
|
@table_str_right += '<label for="' + @field_property["variable"] + '" style="float:left;' + (@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "") + '" class="cencer_table_name">'
|
||||||
@table_str_right += @field_property["name"]
|
@table_str_right += @field_property["name"]
|
||||||
@table_str_right += '</label>'
|
@table_str_right += "</label>"
|
||||||
if @field_property["comment_text"].present?
|
if @field_property["comment_text"].present?
|
||||||
@table_str_right += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
@table_str_right += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
||||||
@table_str_right += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
|
@table_str_right += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>"
|
||||||
else
|
else
|
||||||
@site_locales = current_site.in_use_locales
|
@site_locales = current_site.in_use_locales
|
||||||
@site_locales.delete(current_locale)
|
@site_locales.delete(current_locale)
|
||||||
|
@ -453,72 +457,72 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
if @field_property["comment_text"].present?
|
if @field_property["comment_text"].present?
|
||||||
@table_str_right += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
@table_str_right += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
||||||
@table_str_right += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
|
@table_str_right += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>"
|
||||||
else
|
else
|
||||||
@table_str_right += '<div style="margin-right: 2.125em;float: left;"></div>'
|
@table_str_right += '<div style="margin-right: 2.125em;float: left;"></div>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @field_property["is_num"] == 1
|
if @field_property["is_num"] == 1
|
||||||
if @field_property["is_float"] == 1
|
if @field_property["is_float"] == 1
|
||||||
@table_str_right += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/><input class="num_only_value" type="hidden" /></div>'
|
@table_str_right += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/><input class="num_only_value" type="hidden" /></div>'
|
||||||
else
|
else
|
||||||
if @field_property["range"] == []
|
if @field_property["range"] == []
|
||||||
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/></div>'
|
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/></div>'
|
||||||
else
|
else
|
||||||
@table_str_right += '<div class="num_group"><form class="for_num">'
|
@table_str_right += '<div class="num_group"><form class="for_num">'
|
||||||
@table_str_right += '<input class="num_only cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/>'
|
@table_str_right += '<input class="num_only cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/>'
|
||||||
@table_str_right += '<input class="num_only_value" type="hidden" value="0"/>'
|
@table_str_right += '<input class="num_only_value" type="hidden" value="0"/>'
|
||||||
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
|
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
|
||||||
@table_str_right += '<select class="select_num"><option value="">'+@please_choice+'</option>'
|
@table_str_right += '<select class="select_num"><option value="">' + @please_choice + "</option>"
|
||||||
if @field_property["choice_fields"] != []
|
if @field_property["choice_fields"] != []
|
||||||
@field_property["choice_fields"].each do |choice|
|
@field_property["choice_fields"].each do |choice|
|
||||||
@table_str_right += ('<option value="0">' + choice.to_s.titleize + '</option>')
|
@table_str_right += ('<option value="0">' + choice.to_s.titleize + "</option>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for @num in @field_property["range"][0] .. @field_property["range"][1]
|
for @num in @field_property["range"][0]..@field_property["range"][1]
|
||||||
@table_str_right += ('<option value="' + @num.to_s + '">' + @num.to_s + '</option>')
|
@table_str_right += ('<option value="' + @num.to_s + '">' + @num.to_s + "</option>")
|
||||||
end
|
end
|
||||||
@table_str_right += '</select></form></div>'
|
@table_str_right += "</select></form></div>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@table_str_right += '<div class= "cancer-btn-group cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;">'
|
@table_str_right += '<div class= "cancer-btn-group cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;">'
|
||||||
@field_property["choice_fields"].each do |create_choice|
|
@field_property["choice_fields"].each do |create_choice|
|
||||||
@table_str_right += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.to_s.titleize+'</button>'
|
@table_str_right += '<button class="cancer_table_btn btn btn-default btn-sm">' + create_choice.to_s.titleize + "</button>"
|
||||||
@table_str_right += '<input type="hidden" value="0" name="'+create_choice.to_s+'"/>'
|
@table_str_right += '<input type="hidden" value="0" name="' + create_choice.to_s + '"/>'
|
||||||
end
|
end
|
||||||
@table_str_right += '</div>'
|
@table_str_right += "</div>"
|
||||||
end
|
end
|
||||||
if @field_property["hint"].to_s != ""
|
if @field_property["hint"].to_s != ""
|
||||||
@table_str_right +='<div class="hint-texts">'+@field_property["hint"]+'</div>'
|
@table_str_right += '<div class="hint-texts">' + @field_property["hint"] + "</div>"
|
||||||
end
|
end
|
||||||
@table_str_right += '</div><div style="clear:both;"></div>'
|
@table_str_right += '</div><div style="clear:both;"></div>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@table_str_left += '</div>'
|
@table_str_left += "</div>"
|
||||||
@table_str_right += '</div>'
|
@table_str_right += "</div>"
|
||||||
@table_str += (@table_str_left+@table_str_right)
|
@table_str += (@table_str_left + @table_str_right)
|
||||||
@table_str +='<div style="clear:both;"></div>'
|
@table_str += '<div style="clear:both;"></div>'
|
||||||
@table_result_str = '<div id="cancer_predict_result" style="'+((@form_to_show.form_result_is_right == 0) ? 'float:right;' : '')+'"><span class="result_title">'+t("cancerpredict.table.result").to_s+'</span><div style="clear:both;"></div>'
|
@table_result_str = '<div id="cancer_predict_result" style="' + ((@form_to_show.form_result_is_right == 0) ? "float:right;" : "") + '"><span class="result_title">' + t("cancerpredict.table.result").to_s + '</span><div style="clear:both;"></div>'
|
||||||
@tab_name = ['table','text']
|
@tab_name = ["table", "text"]
|
||||||
@table_result_str +='<div class="texts_under_result">' + @form_to_show.texts_between_Result_and_result_block[current_locale]+'</div>'
|
@table_result_str += '<div class="texts_under_result">' + @form_to_show.texts_between_Result_and_result_block[current_locale] + "</div>"
|
||||||
@table_result_str += '<div id="result_contents"><div class="result_tab_group">'
|
@table_result_str += '<div id="result_contents"><div class="result_tab_group">'
|
||||||
@tab_name.each_with_index{|name,index| @table_result_str += ('<div id="result_'+name+'_tab" class="result_tab'+((index != 0) ? "" : " active")+'"><a>'+t("cancerpredict.table."+name).to_s+'</a></div><div style="clear:both;"></div>')}
|
@tab_name.each_with_index { |name, index| @table_result_str += ('<div id="result_' + name + '_tab" class="result_tab' + ((index != 0) ? "" : " active") + '"><a>' + t("cancerpredict.table." + name).to_s + '</a></div><div style="clear:both;"></div>') }
|
||||||
@table_result_str += '</div><div class="result_content_group">'
|
@table_result_str += '</div><div class="result_content_group">'
|
||||||
@tab_name.each{|name| @table_result_str += '<div id="result_'+name+'_content" class="result_content"><a>'+'no content'+'</a></div>'}
|
@tab_name.each { |name| @table_result_str += '<div id="result_' + name + '_content" class="result_content"><a>' + "no content" + "</a></div>" }
|
||||||
@table_result_str += '</div></div></div>'
|
@table_result_str += "</div></div></div>"
|
||||||
@table_button = '<div id="cancer_table_button_group">'
|
@table_button = '<div id="cancer_table_button_group">'
|
||||||
@submit_btn_str='<button id="cancer_table_submit">'+t('cancerpredict.table.Submit').to_s+'</button>'
|
@submit_btn_str = '<button id="cancer_table_submit">' + t("cancerpredict.table.Submit").to_s + "</button>"
|
||||||
@reset_btn_str='<button id="cancer_table_reset">'+t('cancerpredict.table.Reset').to_s+'</button>'
|
@reset_btn_str = '<button id="cancer_table_reset">' + t("cancerpredict.table.Reset").to_s + "</button>"
|
||||||
@table_button += (@submit_btn_str+@reset_btn_str+'<div style="clear:both;"></div></div></div>')
|
@table_button += (@submit_btn_str + @reset_btn_str + '<div style="clear:both;"></div></div></div>')
|
||||||
@table_result_choice_fileds = '<div id="cancer_table_right_result">' if @form_to_show.form_result_is_right == 1
|
@table_result_choice_fileds = '<div id="cancer_table_right_result">' if @form_to_show.form_result_is_right == 1
|
||||||
@table_result_choice_fileds = '<div id="cancer_table_left_result">' if @form_to_show.form_result_is_right == 0
|
@table_result_choice_fileds = '<div id="cancer_table_left_result">' if @form_to_show.form_result_is_right == 0
|
||||||
@table_result_choice_fileds += '<span class="result_title">'+t('cancerpredict.table.Therapy_choice').to_s+'</span><div style="clear:both;"></div>'
|
@table_result_choice_fileds += '<span class="result_title">' + t("cancerpredict.table.Therapy_choice").to_s + '</span><div style="clear:both;"></div>'
|
||||||
@table_result_choice_fileds += '<div id="choice_fields">'
|
@table_result_choice_fileds += '<div id="choice_fields">'
|
||||||
@form_to_show.form_show_in_result.each do |num,property|
|
@form_to_show.form_show_in_result.each do |num, property|
|
||||||
@field_property = {}
|
@field_property = {}
|
||||||
property.each do |key,value|
|
property.each do |key, value|
|
||||||
@value= value
|
@value = value
|
||||||
if @value.class == BSON::Document || @value.class == Hash
|
if @value.class == BSON::Document || @value.class == Hash
|
||||||
@disp_value = @value[current_locale.to_s] rescue ""
|
@disp_value = @value[current_locale.to_s] rescue ""
|
||||||
else
|
else
|
||||||
|
@ -527,14 +531,14 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
@disp_value = "" if @disp_value.nil?
|
@disp_value = "" if @disp_value.nil?
|
||||||
@field_property[key] = @disp_value
|
@field_property[key] = @disp_value
|
||||||
end
|
end
|
||||||
@table_result_choice_fileds += '<div data-key='+num.to_s+'>'
|
@table_result_choice_fileds += "<div data-key=" + num.to_s + ">"
|
||||||
break if @field_property["name"] == ""
|
break if @field_property["name"] == ""
|
||||||
@table_result_choice_fileds += '<label for="'+@field_property["variable"]+'" style="float:left;'+(@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "")+'" class="cencer_table_name">'
|
@table_result_choice_fileds += '<label for="' + @field_property["variable"] + '" style="float:left;' + (@field_property["comment_text"] == "" ? "margin-right: 2.125em;" : "") + '" class="cencer_table_name">'
|
||||||
@table_result_choice_fileds += @field_property["name"]
|
@table_result_choice_fileds += @field_property["name"]
|
||||||
@table_result_choice_fileds += '</label>'
|
@table_result_choice_fileds += "</label>"
|
||||||
if @field_property["comment_text"].present?
|
if @field_property["comment_text"].present?
|
||||||
@table_result_choice_fileds += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
@table_result_choice_fileds += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
||||||
@table_result_choice_fileds += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'></input>'
|
@table_result_choice_fileds += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "></input>"
|
||||||
else
|
else
|
||||||
@site_locales = current_site.in_use_locales
|
@site_locales = current_site.in_use_locales
|
||||||
@site_locales.delete(current_locale)
|
@site_locales.delete(current_locale)
|
||||||
|
@ -545,58 +549,59 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
if @field_property["comment_text"].present?
|
if @field_property["comment_text"].present?
|
||||||
@table_result_choice_fileds += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
@table_result_choice_fileds += '<button tabindex="0" class="cancer_help_btn" data-target="#show_help_modal" style="float:left;cursor: pointer;padding: 0em 0.475em;font-size: 1.25em;border-radius: 15px;background-color: rgb(210, 106, 2);border-color: rgb(210, 106, 2);color: white;"><i aria-hidden="true" class="fa fa-question"></i></button>'
|
||||||
@table_result_choice_fileds += '<input class="help_texts" type="hidden" value="'+@field_property["comment_text"]+'" name='+@field_property["variable"]+'/>'
|
@table_result_choice_fileds += '<input class="help_texts" type="hidden" value="' + @field_property["comment_text"] + '" name=' + @field_property["variable"] + "/>"
|
||||||
else
|
else
|
||||||
@table_result_choice_fileds += '<div style="margin-right: 2.125em;float: left;"></div>'
|
@table_result_choice_fileds += '<div style="margin-right: 2.125em;float: left;"></div>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @field_property["is_num"] == 1
|
if @field_property["is_num"] == 1
|
||||||
if @field_property["is_float"] == 1
|
if @field_property["is_float"] == 1
|
||||||
@table_result_choice_fileds += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/><input class="num_only_value" type="hidden" /></button>'
|
@table_result_choice_fileds += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/><input class="num_only_value" type="hidden" /></button>'
|
||||||
else
|
else
|
||||||
if @field_property["range"] == []
|
if @field_property["range"] == []
|
||||||
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'"/></div>'
|
@table_str_left += '<div class="num_group"><input class="num_only float_num cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '"/></div>'
|
||||||
else
|
else
|
||||||
@table_result_choice_fileds += '<div class="num_group"><form class="for_num">'
|
@table_result_choice_fileds += '<div class="num_group"><form class="for_num">'
|
||||||
@table_result_choice_fileds += '<input class="num_only cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;" data-range="'+@field_property["range"].to_s+'" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/><button class="btn-sub"></button><button class="btn-add"></button></div>'
|
@table_result_choice_fileds += '<input class="num_only cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;" data-range="' + @field_property["range"].to_s + '" onkeyup="value=value.replace(/[^\d]/g,\'\') "onbeforepaste="clipboardData.setData(\'text\',clipboardData.getData(\'text\').replace(/[^\d]/g,\'\'))"/><button class="btn-sub"></button><button class="btn-add"></button></div>'
|
||||||
@table_str_left += '<input class="num_only_value" type="hidden" value="0"/>'
|
@table_str_left += '<input class="num_only_value" type="hidden" value="0"/>'
|
||||||
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
|
@please_choice = (current_locale.to_s == "zh_tw") ? "請選擇" : "Please choice"
|
||||||
@table_result_choice_fileds += '<select class="select_num"><option value="">'+@please_choice+'</option>'
|
@table_result_choice_fileds += '<select class="select_num"><option value="">' + @please_choice + "</option>"
|
||||||
if @field_property["choice_fields"] != []
|
if @field_property["choice_fields"] != []
|
||||||
@field_property["choice_fields"].each do |choice|
|
@field_property["choice_fields"].each do |choice|
|
||||||
@table_result_choice_fileds += ('<option value="0">' + choice.to_s.titleize + '</option>')
|
@table_result_choice_fileds += ('<option value="0">' + choice.to_s.titleize + "</option>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for @num in @field_property["range"][0] .. @field_property["range"][1]
|
for @num in @field_property["range"][0]..@field_property["range"][1]
|
||||||
@table_result_choice_fileds += ('<option value="' + @num.to_s + '">' + @num.to_s + '</option>')
|
@table_result_choice_fileds += ('<option value="' + @num.to_s + '">' + @num.to_s + "</option>")
|
||||||
end
|
end
|
||||||
@table_result_choice_fileds += '</select></form></div>'
|
@table_result_choice_fileds += "</select></form></div>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@table_result_choice_fileds += '<div class= "cancer-btn-group cancer_form_field" id="'+@field_property["variable"]+'" style="float:left;clear:right;">'
|
@table_result_choice_fileds += '<div class= "cancer-btn-group cancer_form_field" id="' + @field_property["variable"] + '" style="float:left;clear:right;">'
|
||||||
@field_property["choice_fields"].each do |create_choice|
|
@field_property["choice_fields"].each do |create_choice|
|
||||||
@table_result_choice_fileds += '<button class="cancer_table_btn btn btn-default btn-sm">'+create_choice.to_s.titleize+'</button>'
|
@table_result_choice_fileds += '<button class="cancer_table_btn btn btn-default btn-sm">' + create_choice.to_s.titleize + "</button>"
|
||||||
@table_result_choice_fileds += '<input type="hidden" value="0" name="'+create_choice.to_s+'"></input>'
|
@table_result_choice_fileds += '<input type="hidden" value="0" name="' + create_choice.to_s + '"></input>'
|
||||||
end
|
end
|
||||||
@table_result_choice_fileds += '</div>'
|
@table_result_choice_fileds += "</div>"
|
||||||
end
|
end
|
||||||
if @field_property["hint"].to_s != ""
|
if @field_property["hint"].to_s != ""
|
||||||
@table_result_choice_fileds +='<div class="hint-texts">'+@field_property["hint"]+'</div>'
|
@table_result_choice_fileds += '<div class="hint-texts">' + @field_property["hint"] + "</div>"
|
||||||
end
|
end
|
||||||
@table_result_choice_fileds += '</div><div style="clear:both;"></div>'
|
@table_result_choice_fileds += '</div><div style="clear:both;"></div>'
|
||||||
end
|
end
|
||||||
@table_result_choice_fileds += '</div></div>'
|
@table_result_choice_fileds += "</div></div>"
|
||||||
@table_str += (@table_button+'<div id="cancer_predict_result_block" style="font-size:' + @size_active_size + ';">'+@table_result_str+@table_result_choice_fileds+'</div>'+'<div style="clear:both;"></div>')
|
@table_str += (@table_button + '<div id="cancer_predict_result_block" style="font-size:' + @size_active_size + ';">' + @table_result_str + @table_result_choice_fileds + "</div>" + '<div style="clear:both;"></div>')
|
||||||
return @table_str
|
return @table_str
|
||||||
end
|
end
|
||||||
|
|
||||||
def showSubmit
|
def showSubmit
|
||||||
@page_num = params[:page] || 1
|
@page_num = params[:page] || 1
|
||||||
@results = Cancerpredictrecord.where("title"=>@app_title).desc(:id).page(@page_num).per(10)
|
@results = Cancerpredictrecord.where("title" => @app_title).desc(:id).page(@page_num).per(10)
|
||||||
@variables = []
|
@variables = []
|
||||||
@names = []
|
@names = []
|
||||||
@form_to_show.form_show.each do |num,property|
|
@form_to_show.form_show.each do |num, property|
|
||||||
property.each do |key,value|
|
property.each do |key, value|
|
||||||
if key == "variable"
|
if key == "variable"
|
||||||
@variables.push value
|
@variables.push value
|
||||||
elsif key == "name"
|
elsif key == "name"
|
||||||
|
@ -606,10 +611,10 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
@result_variables = []
|
@result_variables = []
|
||||||
@result_names = []
|
@result_names = []
|
||||||
@indexs=[]
|
@indexs = []
|
||||||
@choicenames=[]
|
@choicenames = []
|
||||||
if @results.length != 0
|
if @results.length != 0
|
||||||
@results[0].result.each{|key,value| @result_variables.push key} rescue nil
|
@results[0].result.each { |key, value| @result_variables.push key } rescue nil
|
||||||
@result_variables.each do |variable|
|
@result_variables.each do |variable|
|
||||||
@index = @variables.index(variable.to_s)
|
@index = @variables.index(variable.to_s)
|
||||||
@result_names.push @names[@index] if !@index.nil?
|
@result_names.push @names[@index] if !@index.nil?
|
||||||
|
@ -625,36 +630,38 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
@pagination = create_pagination(@page_num.to_i)
|
@pagination = create_pagination(@page_num.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_cancer_tool_record
|
def export_cancer_tool_record
|
||||||
cancer_records = Cancerpredictrecord.where("title"=>@app_title).desc(:id)
|
cancer_records = Cancerpredictrecord.where("title" => @app_title).desc(:id)
|
||||||
dir_path = 'tmp/cancer_tool/'
|
dir_path = "tmp/cancer_tool/"
|
||||||
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
|
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
|
||||||
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
|
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
|
||||||
@filename = ("#{Time.now.year}_%02s_%02s_export_cancer_tool_record.xlsx"%[Time.now.month,Time.now.day]).gsub(" ","0")
|
@filename = ("#{Time.now.year}_%02s_%02s_export_cancer_tool_record.xlsx" % [Time.now.month, Time.now.day]).gsub(" ", "0")
|
||||||
Dir.chdir(dir_path) do
|
Dir.chdir(dir_path) do
|
||||||
File.open(@filename, 'w') do |f|
|
File.open(@filename, "w") do |f|
|
||||||
f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'export_cancer_tool_record.xlsx',:locals=> {:results=> cancer_records} )
|
f.write render_to_string(:handlers => [:axlsx], :formats => [:xlsx], :partial => "export_cancer_tool_record.xlsx", :locals => { :results => cancer_records })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
tmp_filename_data = File.read(dir_path +@filename)
|
tmp_filename_data = File.read(dir_path + @filename)
|
||||||
send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: @filename)
|
send_data(tmp_filename_data, type: "application/xlsx", disposition: "attachment", filename: @filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_first_field
|
def create_first_field
|
||||||
if Cancerpredictfields.where("title"=>(@app_title + "_back")).take_while{true}.count == 0
|
if Cancerpredictfields.where("title" => (@app_title + "_back")).take_while { true }.count == 0
|
||||||
@form_to_show = Cancerpredictfields.new()
|
@form_to_show = Cancerpredictfields.new()
|
||||||
@form_to_show.title = @app_title +"_back"
|
@form_to_show.title = @app_title + "_back"
|
||||||
@form_to_show.save
|
@form_to_show.save
|
||||||
end
|
end
|
||||||
@form_to_show
|
@form_to_show
|
||||||
if Cancerpredictfields.where("title"=>@app_title).take_while{true}.count == 0
|
if Cancerpredictfields.where("title" => @app_title).take_while { true }.count == 0
|
||||||
@form_to_show = Cancerpredictfields.new()
|
@form_to_show = Cancerpredictfields.new()
|
||||||
@form_to_show.title=@app_title
|
@form_to_show.title = @app_title
|
||||||
@form_to_show.save
|
@form_to_show.save
|
||||||
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
|
@form_to_show = Cancerpredictfields.where("title" => @app_title).first
|
||||||
Dir.chdir("public") do
|
Dir.chdir("public") do
|
||||||
@site_locales = Site.last.in_use_locales.each do |locale|
|
@site_locales = Site.last.in_use_locales.each do |locale|
|
||||||
I18n.with_locale(locale) do
|
I18n.with_locale(locale) do
|
||||||
@file_tmp = File.new("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt", 'w')
|
@file_tmp = File.new("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt", "w")
|
||||||
tmp_table_texts = create_table(locale)
|
tmp_table_texts = create_table(locale)
|
||||||
@file_tmp.write(tmp_table_texts)
|
@file_tmp.write(tmp_table_texts)
|
||||||
@file_tmp.close
|
@file_tmp.close
|
||||||
|
@ -662,52 +669,54 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
|
@form_to_show = Cancerpredictfields.where("title" => @app_title).first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def create_pagination(page=1,fields=Cancerpredictrecord.all,extra_params="")
|
|
||||||
|
def create_pagination(page = 1, fields = Cancerpredictrecord.all, extra_params = "")
|
||||||
page = 1 if page == 0
|
page = 1 if page == 0
|
||||||
per_page_num = 10.0
|
per_page_num = 10.0
|
||||||
all_page_num = (fields.count / per_page_num).ceil
|
all_page_num = (fields.count / per_page_num).ceil
|
||||||
all_page_num = 1 if all_page_num == 0
|
all_page_num = 1 if all_page_num == 0
|
||||||
pagination = '<div class="PageDetails">'+((I18n.locale.to_s == 'zh_tw') ? "第 #{page} 頁" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)")+'<ol class="PageList">'+
|
pagination = '<div class="PageDetails">' + ((I18n.locale.to_s == "zh_tw") ? "第 #{page} 頁" : "page #{page}") + "/" + ((I18n.locale.to_s == "zh_tw") ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)") + '<ol class="PageList">' +
|
||||||
((page == 1) ? '<li>['+I18n.t('cancerpredict.prev_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page-1).to_s+'"> ['+I18n.t('cancerpredict.prev_page')+'] </a></li>')
|
((page == 1) ? "<li>[" + I18n.t("cancerpredict.prev_page") + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + (page - 1).to_s + '"> [' + I18n.t("cancerpredict.prev_page") + "] </a></li>")
|
||||||
if all_page_num > 7
|
if all_page_num > 7
|
||||||
if page <= (all_page_num / 2)
|
if page <= (all_page_num / 2)
|
||||||
if page <= 7
|
if page <= 7
|
||||||
(1..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(1..page).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
else
|
else
|
||||||
(1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(1..3).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
pagination +='<li>...</li>'
|
pagination += "<li>...</li>"
|
||||||
(page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(page - 3..page).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
end
|
end
|
||||||
(page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(page + 1..page + 3).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
pagination +='<li>...</li>'
|
pagination += "<li>...</li>"
|
||||||
(all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(all_page_num - 2..all_page_num).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
else
|
else
|
||||||
(1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(1..3).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
pagination +='<li>...</li>'
|
pagination += "<li>...</li>"
|
||||||
(page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(page - 3..page).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
if all_page_num - page <= 7
|
if all_page_num - page <= 7
|
||||||
(page+1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(page + 1..all_page_num).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
else
|
else
|
||||||
(page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(page + 1..page + 3).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
pagination +='<li>...</li>'
|
pagination += "<li>...</li>"
|
||||||
(all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(all_page_num - 2..all_page_num).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
(1..all_page_num).to_a.each { |page_num| pagination += ((page_num == page) ? "<li>[" + page_num.to_s + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + page_num.to_s + '"> ' + page_num.to_s + " </a></li>") }
|
||||||
end
|
end
|
||||||
pagination += (((page==all_page_num) ? '<li>['+I18n.t('cancerpredict.next_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page+1).to_s+'"> ['+I18n.t('cancerpredict.next_page')+'] </a></li>')+'</ol></div>')
|
pagination += (((page == all_page_num) ? "<li>[" + I18n.t("cancerpredict.next_page") + "]</li>" : '<li><a href="' + (extra_params.blank? ? "?" : "?#{extra_params}&") + "page=" + (page + 1).to_s + '"> [' + I18n.t("cancerpredict.next_page") + "] </a></li>") + "</ol></div>")
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_mapping_file(mapping_file_id)
|
def read_mapping_file(mapping_file_id)
|
||||||
mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil
|
mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil
|
||||||
if !mapping_file.nil?
|
if !mapping_file.nil?
|
||||||
csv_rows = CSV.read(mapping_file.temp_file.file.path)
|
csv_rows = CSV.read(mapping_file.temp_file.file.path)
|
||||||
titles = csv_rows[0]
|
titles = csv_rows[0]
|
||||||
infos = {}
|
infos = {}
|
||||||
titles.each_with_index do |title,i|
|
titles.each_with_index do |title, i|
|
||||||
infos[title] = []
|
infos[title] = []
|
||||||
csv_rows[1..-1].each do |row|
|
csv_rows[1..-1].each do |row|
|
||||||
infos[title] << row[i].to_f
|
infos[title] << row[i].to_f
|
||||||
|
|
|
@ -1,81 +1,83 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
require 'rubyXL'
|
require "rubyXL"
|
||||||
require "json"
|
require "json"
|
||||||
|
|
||||||
class CancerpredictsController < ApplicationController
|
class CancerpredictsController < ApplicationController
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
@app_title = "cancerpredict"
|
@app_title = "cancerpredict"
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate
|
def calculate
|
||||||
create_first_field
|
create_first_field
|
||||||
if params['header'].to_i == 1
|
if params["header"].to_i == 1
|
||||||
locale = params['locale'].to_s rescue 'zh_tw'
|
locale = params["locale"].to_s rescue "zh_tw"
|
||||||
locale = 'zh_tw' if locale == 'zh_cn'
|
locale = "zh_tw" if locale == "zh_cn"
|
||||||
result = {}
|
result = {}
|
||||||
@head_images = {}
|
@head_images = {}
|
||||||
@form_to_show.head_images_id.each do |image_id|
|
@form_to_show.head_images_id.each do |image_id|
|
||||||
next if image_id.to_s == ""
|
next if image_id.to_s == ""
|
||||||
@image = Headimages.find_by(:id=>image_id.to_s)
|
@image = Headimages.find_by(:id => image_id.to_s)
|
||||||
@url = @image.temp_file.to_s
|
@url = @image.temp_file.to_s
|
||||||
@head_images[@image.sort_number.to_i] = ('<img class="head_logo" alt ="' + Pathname.new(@image.temp_file.file.file).basename.to_s+'" src="'+@url+'"/>')
|
@head_images[@image.sort_number.to_i] = ('<img class="head_logo" alt ="' + Pathname.new(@image.temp_file.file.file).basename.to_s + '" src="' + @url + '"/>')
|
||||||
end
|
end
|
||||||
result['head_images'] = Hash[@head_images.sort].values.join('')
|
result["head_images"] = Hash[@head_images.sort].values.join("")
|
||||||
@head_images = {}
|
@head_images = {}
|
||||||
@form_to_show.title_images_id.each do |image_id|
|
@form_to_show.title_images_id.each do |image_id|
|
||||||
next if image_id.to_s == ""
|
next if image_id.to_s == ""
|
||||||
@image = Headimages.find_by(:id=>image_id.to_s)
|
@image = Headimages.find_by(:id => image_id.to_s)
|
||||||
@url = @image.temp_file.to_s
|
@url = @image.temp_file.to_s
|
||||||
@head_images[@image.sort_number.to_i] = ('<img class="head_logo" alt ="' + Pathname.new(@image.temp_file.file.file).basename.to_s+'" src="'+@url+'"/>')
|
@head_images[@image.sort_number.to_i] = ('<img class="head_logo" alt ="' + Pathname.new(@image.temp_file.file.file).basename.to_s + '" src="' + @url + '"/>')
|
||||||
end
|
end
|
||||||
result['danger_texts'] = (@form_to_show.danger_texts[locale] rescue '')
|
result["danger_texts"] = (@form_to_show.danger_texts[locale] rescue "")
|
||||||
result['title'] = Hash[@head_images.sort].values.join('')
|
result["title"] = Hash[@head_images.sort].values.join("")
|
||||||
result['page_title'] = @form_to_show.title_texts[params[:locale]]
|
result["page_title"] = @form_to_show.title_texts[params[:locale]]
|
||||||
elsif params['get_mapping_data_from_csv'].to_i == 1
|
elsif params["get_mapping_data_from_csv"].to_i == 1
|
||||||
result = {}
|
result = {}
|
||||||
result['mapping_data_from_csv'] = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {}
|
result["mapping_data_from_csv"] = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {}
|
||||||
else
|
else
|
||||||
@record = Cancerpredictrecord.new
|
@record = Cancerpredictrecord.new
|
||||||
@record.title = @app_title
|
@record.title = @app_title
|
||||||
@choice_keys = []
|
@choice_keys = []
|
||||||
@choice_values = []
|
@choice_values = []
|
||||||
@choice_names = []
|
@choice_names = []
|
||||||
@form_to_show.form_show.values.each{|choice| @choice_keys.push choice[:variable]}
|
@form_to_show.form_show.values.each { |choice| @choice_keys.push choice[:variable] }
|
||||||
@form_to_show.form_show.values.each{|choice| @choice_values.push ((choice[:is_num] == 1) ? [] : choice[:choice_fields])}
|
@form_to_show.form_show.values.each { |choice| @choice_values.push ((choice[:is_num] == 1) ? [] : choice[:choice_fields]) }
|
||||||
@form_to_show.form_show.values.each{|choice| @choice_names.push choice[:name]}
|
@form_to_show.form_show.values.each { |choice| @choice_names.push choice[:name] }
|
||||||
@choice_keys.each_with_index{|key,i| @record.names[key] = @choice_names[i]}
|
@choice_keys.each_with_index { |key, i| @record.names[key] = @choice_names[i] }
|
||||||
@choice_keys.each_with_index{|key,i| @record.values[key] = @choice_values[i]}
|
@choice_keys.each_with_index { |key, i| @record.values[key] = @choice_values[i] }
|
||||||
params['data'].each do |rec_key,rec_value|
|
params["data"].each do |rec_key, rec_value|
|
||||||
@record.result[rec_key] = rec_value
|
@record.result[rec_key] = rec_value
|
||||||
end
|
end
|
||||||
@record.submit_time = Time.now.to_s
|
@record.submit_time = Time.now.to_s
|
||||||
@record.save
|
@record.save
|
||||||
locale = params['data']['locale'].to_s rescue 'zh_tw'
|
locale = params["data"]["locale"].to_s rescue "zh_tw"
|
||||||
locale = 'zh_tw' if locale == 'zh_cn'
|
locale = "zh_tw" if locale == "zh_cn"
|
||||||
result = {}
|
result = {}
|
||||||
mapping_data_from_csv = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {}
|
mapping_data_from_csv = JSON.parse(@form_to_show.mapping_data_from_csv) rescue {}
|
||||||
@form_to_show.all_variables.each do |v|
|
@form_to_show.all_variables.each do |v|
|
||||||
result[v] = 0
|
result[v] = 0
|
||||||
end
|
end
|
||||||
@form_to_show.form_show.each do |num,property|
|
@form_to_show.form_show.each do |num, property|
|
||||||
@variable = property[:variable]
|
@variable = property[:variable]
|
||||||
if @variable.present?
|
if @variable.present?
|
||||||
if property[:is_num] == 1
|
if property[:is_num] == 1
|
||||||
if property[:is_float] == 1
|
if property[:is_float] == 1
|
||||||
result[@variable] = params['data'][@variable].to_f rescue 0.0
|
result[@variable] = params["data"][@variable].to_f rescue 0.0
|
||||||
else
|
else
|
||||||
result[@variable] = params['data'][@variable].to_i rescue 0
|
result[@variable] = params["data"][@variable].to_i rescue 0
|
||||||
end
|
end
|
||||||
elsif property[:choice_fields].present?
|
elsif property[:choice_fields].present?
|
||||||
if !(@form_to_show.advance_mode)
|
if !(@form_to_show.advance_mode)
|
||||||
result[@variable] = params['data'][@variable].to_i rescue 0
|
result[@variable] = params["data"][@variable].to_i rescue 0
|
||||||
else
|
else
|
||||||
if property[:need_map_values] == 1
|
if property[:need_map_values] == 1
|
||||||
result[@variable] = property[:map_values][params['data'][@variable].to_i - 1]
|
result[@variable] = property[:map_values][params["data"][@variable].to_i - 1]
|
||||||
else
|
else
|
||||||
if property[:revert_value] != 1
|
if property[:revert_value] != 1
|
||||||
result[@variable] = params['data'][@variable].to_i - 1
|
result[@variable] = params["data"][@variable].to_i - 1
|
||||||
else
|
else
|
||||||
result[@variable] = ((property[:choice_fields].length - params['data'][@variable].to_i) rescue params['data'][@variable].to_i)
|
result[@variable] = ((property[:choice_fields].length - params["data"][@variable].to_i) rescue params["data"][@variable].to_i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -85,13 +87,13 @@ class CancerpredictsController < ApplicationController
|
||||||
mapping_hash = mapping_data_from_csv[@variable]
|
mapping_hash = mapping_data_from_csv[@variable]
|
||||||
temp_index = 0
|
temp_index = 0
|
||||||
temp_value = result[@variable]
|
temp_value = result[@variable]
|
||||||
mapping_hash.each_with_index do |(k,v),i|
|
mapping_hash.each_with_index do |(k, v), i|
|
||||||
if i == 0
|
if i == 0
|
||||||
index_val = v.index(temp_value) rescue nil
|
index_val = v.index(temp_value) rescue nil
|
||||||
if !index_val.nil?
|
if !index_val.nil?
|
||||||
temp_index = index_val
|
temp_index = index_val
|
||||||
else
|
else
|
||||||
closest_value = v.min_by{|x| (temp_value-x).abs}
|
closest_value = v.min_by { |x| (temp_value - x).abs }
|
||||||
temp_index = v.index(closest_value)
|
temp_index = v.index(closest_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -114,20 +116,20 @@ class CancerpredictsController < ApplicationController
|
||||||
@form_to_show.generate_eval_formula
|
@form_to_show.generate_eval_formula
|
||||||
eval_formula(result)
|
eval_formula(result)
|
||||||
end
|
end
|
||||||
result['lpv'] = result[formula_variables.last]
|
result["lpv"] = result[formula_variables.last]
|
||||||
result['lpv_variable'] = {}
|
result["lpv_variable"] = {}
|
||||||
formula_variables.each do |variable_name|
|
formula_variables.each do |variable_name|
|
||||||
result['lpv_variable']["#{variable_name}"] = result[variable_name]
|
result["lpv_variable"]["#{variable_name}"] = result[variable_name]
|
||||||
end
|
end
|
||||||
@years = @form_to_show.years
|
@years = @form_to_show.years
|
||||||
result['years'] = @years
|
result["years"] = @years
|
||||||
@therapy_choices = [I18n.t('cancerpredict.table.Surgeryonly')]
|
@therapy_choices = [I18n.t("cancerpredict.table.Surgeryonly")]
|
||||||
@form_to_show.form_show_in_result.values.each{|choice| @therapy_choices.push choice["name"][locale]}
|
@form_to_show.form_show_in_result.values.each { |choice| @therapy_choices.push choice["name"][locale] }
|
||||||
@therapy_names = @form_to_show.treatment_method
|
@therapy_names = @form_to_show.treatment_method
|
||||||
result['treatment_method'] = @therapy_names
|
result["treatment_method"] = @therapy_names
|
||||||
result['treatment_method_active_indices'] = @form_to_show.treatment_method_active_indices
|
result["treatment_method_active_indices"] = @form_to_show.treatment_method_active_indices
|
||||||
result['table'] = @form_to_show.result_table_translations[locale]
|
result["table"] = @form_to_show.result_table_translations[locale]
|
||||||
year = params['data']['year'] rescue nil
|
year = params["data"]["year"] rescue nil
|
||||||
if year.nil?
|
if year.nil?
|
||||||
year = @years.last.to_f
|
year = @years.last.to_f
|
||||||
else
|
else
|
||||||
|
@ -136,22 +138,23 @@ class CancerpredictsController < ApplicationController
|
||||||
year_index = @years.index(year)
|
year_index = @years.index(year)
|
||||||
@servive_ratio = eval(@form_to_show.tmp_years_settings_for_ruby[year_index])
|
@servive_ratio = eval(@form_to_show.tmp_years_settings_for_ruby[year_index])
|
||||||
@servive_ratio = (@servive_ratio * 100).round(2)
|
@servive_ratio = (@servive_ratio * 100).round(2)
|
||||||
result['texts'] = @form_to_show.result_text_translations[locale]
|
result["texts"] = @form_to_show.result_text_translations[locale]
|
||||||
result['extra_therapy_texts'] = @form_to_show.extra_therapy_texts[locale] rescue @form_to_show.extra_therapy_texts['zh_tw']
|
result["extra_therapy_texts"] = @form_to_show.extra_therapy_texts[locale] rescue @form_to_show.extra_therapy_texts["zh_tw"]
|
||||||
result['servive_ratio'] = @servive_ratio
|
result["servive_ratio"] = @servive_ratio
|
||||||
end
|
end
|
||||||
result = result.merge(params)
|
result = result.merge(params)
|
||||||
render :json=> result
|
render :json => result
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
uid = OrbitHelper.params[:uid] rescue ""
|
uid = OrbitHelper.params[:uid] rescue ""
|
||||||
tags = OrbitHelper.widget_tags
|
tags = OrbitHelper.widget_tags
|
||||||
categories = OrbitHelper.widget_categories || []
|
categories = OrbitHelper.widget_categories || []
|
||||||
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt")
|
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt")
|
||||||
preidct_js_url = '/assets/cancer_predict.js'
|
preidct_js_url = "/assets/cancer_predict.js"
|
||||||
if File.exist?(Cancerpredictfields::JSFileName)
|
if File.exist?(Cancerpredictfields::JSFileName)
|
||||||
js_filename = File.read(Cancerpredictfields::JSFileName)
|
js_filename = File.read(Cancerpredictfields::JSFileName)
|
||||||
if js_filename.include?('cancer_predict.js')
|
if js_filename.include?("cancer_predict.js")
|
||||||
asset = Rails.application.assets[js_filename]
|
asset = Rails.application.assets[js_filename]
|
||||||
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
|
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
|
||||||
else
|
else
|
||||||
|
@ -160,18 +163,19 @@ class CancerpredictsController < ApplicationController
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
"cancerpredict" => [],
|
"cancerpredict" => [],
|
||||||
"extras"=>{"table"=> @table_str,'preidct_js_url'=>preidct_js_url}
|
"extras" => { "table" => @table_str, "preidct_js_url" => preidct_js_url },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def widget
|
def widget
|
||||||
uid = OrbitHelper.params[:uid] rescue ""
|
uid = OrbitHelper.params[:uid] rescue ""
|
||||||
tags = OrbitHelper.widget_tags
|
tags = OrbitHelper.widget_tags
|
||||||
categories = OrbitHelper.widget_categories || []
|
categories = OrbitHelper.widget_categories || []
|
||||||
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt")
|
@table_str = File.read("#{Cancerpredictfields::ToolTablePrefix}#{I18n.locale}.txt")
|
||||||
preidct_js_url = '/assets/cancer_predict.js'
|
preidct_js_url = "/assets/cancer_predict.js"
|
||||||
if File.exist?(Cancerpredictfields::JSFileName)
|
if File.exist?(Cancerpredictfields::JSFileName)
|
||||||
js_filename = File.read(Cancerpredictfields::JSFileName)
|
js_filename = File.read(Cancerpredictfields::JSFileName)
|
||||||
if js_filename.include?('cancer_predict.js')
|
if js_filename.include?("cancer_predict.js")
|
||||||
asset = Rails.application.assets[js_filename]
|
asset = Rails.application.assets[js_filename]
|
||||||
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
|
preidct_js_url = "#{Rails.application.config.assets.prefix}/#{asset.digest_path}"
|
||||||
else
|
else
|
||||||
|
@ -180,25 +184,27 @@ class CancerpredictsController < ApplicationController
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
"cancerpredict" => [],
|
"cancerpredict" => [],
|
||||||
"extras"=>{"table"=> @table_str,'preidct_js_url'=>preidct_js_url}
|
"extras" => { "table" => @table_str, "preidct_js_url" => preidct_js_url },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_first_field
|
def create_first_field
|
||||||
if Cancerpredictfields.where("title"=>(@app_title + "_back")).count == 0
|
if Cancerpredictfields.where("title" => (@app_title + "_back")).count == 0
|
||||||
@form_to_show = Cancerpredictfields.new()
|
@form_to_show = Cancerpredictfields.new()
|
||||||
@form_to_show.title = @app_title +"_back"
|
@form_to_show.title = @app_title + "_back"
|
||||||
@form_to_show.save
|
@form_to_show.save
|
||||||
end
|
end
|
||||||
@form_to_show
|
@form_to_show
|
||||||
if Cancerpredictfields.where("title"=>@app_title).count == 0
|
if Cancerpredictfields.where("title" => @app_title).count == 0
|
||||||
@form_to_show = Cancerpredictfields.new()
|
@form_to_show = Cancerpredictfields.new()
|
||||||
@form_to_show.title=@app_title
|
@form_to_show.title = @app_title
|
||||||
@form_to_show.save
|
@form_to_show.save
|
||||||
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
|
@form_to_show = Cancerpredictfields.where("title" => @app_title).first
|
||||||
else
|
else
|
||||||
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
|
@form_to_show = Cancerpredictfields.where("title" => @app_title).first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_mapping_file(mapping_file)
|
def read_mapping_file(mapping_file)
|
||||||
if mapping_file.class != CancerPredictMappingFile
|
if mapping_file.class != CancerPredictMappingFile
|
||||||
mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil
|
mapping_file = CancerPredictMappingFile.find(mapping_file_id) rescue nil
|
||||||
|
@ -207,7 +213,7 @@ class CancerpredictsController < ApplicationController
|
||||||
csv_rows = CSV.read(mapping_file.temp_file.file.path)
|
csv_rows = CSV.read(mapping_file.temp_file.file.path)
|
||||||
titles = csv_rows[0]
|
titles = csv_rows[0]
|
||||||
infos = {}
|
infos = {}
|
||||||
titles.each_with_index do |title,i|
|
titles.each_with_index do |title, i|
|
||||||
infos[title] = []
|
infos[title] = []
|
||||||
csv_rows[1..-1].each do |row|
|
csv_rows[1..-1].each do |row|
|
||||||
infos[title] << row[i].to_f
|
infos[title] << row[i].to_f
|
||||||
|
|
Loading…
Reference in New Issue