cancer_predict/app/controllers/admin/cancerpredicts_controller.rb

167 lines
5.7 KiB
Ruby
Raw Normal View History

2019-11-15 00:44:28 +00:00
# encoding: utf-8
require 'rubyXL'
class Admin::CancerpredictsController < OrbitAdminController
2019-11-15 09:02:17 +00:00
#include Admin::CancerpredictsHelper
2019-11-15 00:44:28 +00:00
before_action ->(module_app = @app_title) { set_variables module_app }
2019-11-23 03:15:11 +00:00
before_action :create_first_field
2019-11-15 00:44:28 +00:00
#before_action :load_access_levels
def initialize
super
@app_title = "cancerpredict"
end
def index
@tags = @module_app.tags
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
end
2019-11-23 08:14:56 +00:00
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
2019-12-14 04:21:09 +00:00
@form_to_show.form_show[num.to_s][key.to_s] = YAML.load(value)
else
@form_to_show.form_show[num.to_s][key.to_s] = []
end
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
2019-12-14 04:21:09 +00:00
@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
end
end
2019-12-14 04:21:09 +00:00
params["cancerpredictfields"]["form_show_in_result"].each do |num,property|
property.each do |key,value|
if value != "0" && value != "1"
if key != params[:locale]
if @form_to_show.form_show_in_result[num.to_s][key.to_s].class != Array
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value
else
if value.length > 2
@form_to_show.form_show_in_result[num.to_s][key.to_s] = YAML.load(value)
else
@form_to_show.form_show_in_result[num.to_s][key.to_s] = []
end
end
else
value.each do |sub_property,sub_value|
if @form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s].class != Array
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value
else
if sub_value.length > 2
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = YAML.load(sub_value)
else
@form_to_show.form_show_in_result[ num.to_s ][ sub_property ][params[:locale].to_s] = []
end
end
end
end
else
@form_to_show.form_show_in_result[num.to_s][key.to_s] = value.to_i
end
end
end
@form_to_show.form_result_is_right = params["cancerpredictfields"]["form_result_is_right"]
@form_to_show.text_descibe[I18n.locale.to_s] = params["cancerpredictfields"]["text_descibe"]
@size = ['small','medium','large']
@size.each{|size| @form_to_show[size] = params["cancerpredictfields"][size]}
@file_path = Rails.root.to_s + '/app/assets/images/predict_tool'
if !Dir.exist? @file_path
#FileUtils.mkdir_p @file_path
end
# if @file.nil? != true
# @file_name = @file.original_filename
# @file_content = @file.read
# FileUtils.cp(@file , @file_path)
# @file_content.force_encoding('UTF-8')
# Dir.chdir(@file_path)
# @filetowrite
# if !File.file?(@file_name)
# @filetowrite = File.new(@file_name,"w")
# else
# @filetowrite = File.open(@file_name,"w")
# end
# @filetowrite.write(@file_content)
# @filetowrite.close
# Dir.chdir(Rails.root.to_s)
# else
# @file_name = @font_settings.font_file_name
# end
@field_name = {"font_file_name" => @file_name,"font_dir" => @file_path}
@field_name.each do |name,value|
@font_settings["old_" + name.to_s] = @font_settings[name.to_s]
@font_settings[name.to_s] = value.to_s
end
@form_to_show.save
2019-12-14 04:21:09 +00:00
#params.cancerpredictfields
#render :html => params["cancerpredictfields"]["form_result_is_right"].to_s
render :html => params["cancerpredictfields"].to_s
#redirect_to admin_cancerpredicts_path
end
def showSubmit
@results = Cancerpredictrecord.where("title"=>@app_title).take_while{true}
@variables = []
@names = []
@form_to_show.form_show.each do |num,property|
property.each do |key,value|
if key == "variable"
@variables.push value
elsif key == "name"
@names.push value[I18n.locale.to_s]
end
end
end
@result_variables = []
@result_names = []
@indexs=[]
2019-12-14 04:21:09 +00:00
@results[0].result.each{|key,value| @result_variables.push key} rescue nil
@result_variables.each do |variable|
@index = @variables.index(variable.to_s)
@result_names.push @names[@index] if !@index.nil?
@indexs.push @index if !@index.nil?
end
@choicenames=[]
@indexs.each do |index|
if @form_to_show.form_show[index.to_s]["is_num"] == 1 || @form_to_show.form_show[index.to_s]["is_float"] == 1
@choicenames.push ""
else
@choicenames.push @form_to_show.form_show[index.to_s]["choice_fields"][I18n.locale.to_s]
end
end
#render :html => @result_names.to_s
2019-11-23 08:14:56 +00:00
end
2019-11-23 03:15:11 +00:00
def create_first_field
2019-11-23 08:14:56 +00:00
if Cancerpredictfields.where("title"=>(@app_title + "_back")).take_while{true}.count == 0
@form_to_show = Cancerpredictfields.new()
@form_to_show.title = @app_title +"_back"
@form_to_show.save
end
@form_to_show
if Cancerpredictfields.where("title"=>@app_title).take_while{true}.count == 0
@form_to_show = Cancerpredictfields.new()
@form_to_show.title=@app_title
@form_to_show.save
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
else
@form_to_show = Cancerpredictfields.where("title"=>@app_title).first
2019-11-23 03:15:11 +00:00
end
2019-11-23 08:14:56 +00:00
end
2019-11-15 00:44:28 +00:00
end