diff --git a/app/controllers/admin/cancerpredicts_controller.rb b/app/controllers/admin/cancerpredicts_controller.rb index 14af14e..3d19715 100644 --- a/app/controllers/admin/cancerpredicts_controller.rb +++ b/app/controllers/admin/cancerpredicts_controller.rb @@ -1,7 +1,10 @@ # encoding: utf-8 -require 'rubyXL' class Admin::CancerpredictsController < OrbitAdminController - #include Admin::CancerpredictsHelper + require 'spreadsheet' + require 'rubyXL' + require 'fileutils' + require "axlsx" + helper Admin::CancerpredictsHelper before_action ->(module_app = @app_title) { set_variables module_app } before_action :create_first_field #before_action :load_access_levels @@ -9,7 +12,6 @@ class Admin::CancerpredictsController < OrbitAdminController super @app_title = "cancerpredict" end - def index @tags = @module_app.tags @categories = @module_app.categories.enabled @@ -192,10 +194,12 @@ class Admin::CancerpredictsController < OrbitAdminController end Dir.chdir("public") do @site_locales = Site.last.in_use_locales.each do |locale| - @file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w') - tmp_table_texts = create_table(locale) - @file_tmp.write(tmp_table_texts) - @file_tmp.close + I18n.with_locale(locale) do + @file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w') + tmp_table_texts = create_table(locale) + @file_tmp.write(tmp_table_texts) + @file_tmp.close + end end end Dir.chdir("public") do @@ -437,7 +441,8 @@ class Admin::CancerpredictsController < OrbitAdminController return @table_str end def showSubmit - @results = Cancerpredictrecord.where("title"=>@app_title).take_while{true} + @page_num = params[:page] || 1 + @results = Cancerpredictrecord.where("title"=>@app_title).asc(:id).page(@page_num).per(10) @variables = [] @names = [] @form_to_show.form_show.each do |num,property| @@ -452,18 +457,20 @@ class Admin::CancerpredictsController < OrbitAdminController @result_variables = [] @result_names = [] @indexs=[] - @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] + if @results.length != 0 + @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 + @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 end end @@ -481,10 +488,12 @@ class Admin::CancerpredictsController < OrbitAdminController @form_to_show = Cancerpredictfields.where("title"=>@app_title).first Dir.chdir("public") do @site_locales = Site.last.in_use_locales.each do |locale| - @file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w') - tmp_table_texts = create_table(locale) - @file_tmp.write(tmp_table_texts) - @file_tmp.close + I18n.with_locale(locale) do + @file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w') + tmp_table_texts = create_table(locale) + @file_tmp.write(tmp_table_texts) + @file_tmp.close + end end end else diff --git a/app/controllers/cancerpredicts_controller.rb b/app/controllers/cancerpredicts_controller.rb index 45c024b..262f028 100644 --- a/app/controllers/cancerpredicts_controller.rb +++ b/app/controllers/cancerpredicts_controller.rb @@ -158,10 +158,10 @@ class CancerpredictsController < ApplicationController result['pstage_3']*1.134+result['pstage_4']*2.172+result['lvi_yes']*0.3321-0.04 rescue 'error') @years = @form_to_show.years result['table'] = '
'+@form_to_show.table_above_texts[locale]+'
' - result['table'] += '第' + result['table'] += (''+(locale == 'zh_tw' ? '第' : '')+'') result['years'] = @years @years.each{|year| result['table'] += ('')} - result['table'] += '年' + result['table'] += (''+(locale == 'zh_tw' ? '年' : '')+'') @table_head = (locale == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)'] @head_name = ['Treatment','Additional_Benefit','Overall_Survival'] @therapy_choices = (locale == "zh_tw") ? ['純手術'] :['Surgery only'] diff --git a/app/helpers/admin/cancerpredicts_helper.rb b/app/helpers/admin/cancerpredicts_helper.rb index 7f8b751..659972b 100644 --- a/app/helpers/admin/cancerpredicts_helper.rb +++ b/app/helpers/admin/cancerpredicts_helper.rb @@ -1,7 +1,37 @@ -require "net/http" -require "uri" -require 'json' - module Admin::CancerpredictsHelper - + def create_pagination(page=1,fields=Cancerpredictrecord.all,extra_params="") + page = 1 if page == 0 + per_page_num = 10.0 + all_page_num = (fields.count / per_page_num).ceil + pagination = '