From 817ecf0377797e8e77ae5c1400439a034a4b66a3 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Mon, 3 Feb 2020 15:27:29 +0800 Subject: [PATCH] fix --- .../admin/cancerpredicts_controller.rb | 55 +++++++++++-------- app/controllers/cancerpredicts_controller.rb | 4 +- app/helpers/admin/cancerpredicts_helper.rb | 40 ++++++++++++-- app/views/admin/cancerpredicts/index.html.erb | 12 ++-- .../admin/cancerpredicts/showSubmit.html.erb | 1 + cancerpredict.gemspec | 45 +-------------- config/locales/en.yml | 2 + config/locales/zh_tw.yml | 2 + 8 files changed, 81 insertions(+), 80 deletions(-) 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 = '
'+((I18n.locale.to_s == 'zh_tw') ? "第 #{page} 頁" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)")+'
    '+ + ((page == 1) ? '
  1. ['+t('cancerpredict.prev_page')+']
  2. ' : '
  3. ['+t('cancerpredict.prev_page')+']
  4. ') + if all_page_num > 7 + if page <= (all_page_num / 2) + if page <= 7 + (1..page).to_a.each{|page_num| pagination += ((page_num == page) ? '
  5. ['+page_num.to_s+']
  6. ' : '
  7. '+page_num.to_s+'
  8. ')} + else + (1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '
  9. ['+page_num.to_s+']
  10. ' : '
  11. '+page_num.to_s+'
  12. ')} + pagination +='
  13. ...
  14. ' + (page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '
  15. ['+page_num.to_s+']
  16. ' : '
  17. '+page_num.to_s+'
  18. ')} + end + (page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '
  19. ['+page_num.to_s+']
  20. ' : '
  21. '+page_num.to_s+'
  22. ')} + pagination +='
  23. ...
  24. ' + (all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  25. ['+page_num.to_s+']
  26. ' : '
  27. '+page_num.to_s+'
  28. ')} + else + (1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '
  29. ['+page_num.to_s+']
  30. ' : '
  31. '+page_num.to_s+'
  32. ')} + pagination +='
  33. ...
  34. ' + (page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '
  35. ['+page_num.to_s+']
  36. ' : '
  37. '+page_num.to_s+'
  38. ')} + if all_page_num - page <= 7 + (page+1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  39. ['+page_num.to_s+']
  40. ' : '
  41. '+page_num.to_s+'
  42. ')} + else + (page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '
  43. ['+page_num.to_s+']
  44. ' : '
  45. '+page_num.to_s+'
  46. ')} + pagination +='
  47. ...
  48. ' + (all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  49. ['+page_num.to_s+']
  50. ' : '
  51. '+page_num.to_s+'
  52. ')} + end + end + else + (1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  53. ['+page_num.to_s+']
  54. ' : '
  55. '+page_num.to_s+'
  56. ')} + end + pagination += (((page==all_page_num) ? '
  57. ['+t('cancerpredict.next_page')+']
  58. ' : '
  59. ['+t('cancerpredict.next_page')+']
  60. ')+'
') + end end diff --git a/app/views/admin/cancerpredicts/index.html.erb b/app/views/admin/cancerpredicts/index.html.erb index c6bf933..8b5548b 100644 --- a/app/views/admin/cancerpredicts/index.html.erb +++ b/app/views/admin/cancerpredicts/index.html.erb @@ -138,9 +138,9 @@

<%= t('cancerpredict.text_descibe') %>
- <%= form.fields_for 'text_descibe' do |locale_fields|%> - <%= locale_fields.text_field I18n.locale.to_s,{:value=> @form_to_show.text_descibe[I18n.locale.to_s],:style=>'width:100%;'} %> - <%end%> + <%= t('cancerpredict.font_size') %>
<% @size=['small','medium','large'] %> @@ -207,13 +207,13 @@
<% @create_items = ['years','table_above_texts','text_above_texts','surgery_only_texts','extra_texts','extra_therapy_texts','danger_texts','texts_between_Result_and_result_block'] %> <% @create_items.each do |item|%> - + <% if @form_to_show[item].class == BSON::Document || @form_to_show[item].class == Hash %> <%= form.fields_for item do |locale_fields|%> - <%= locale_fields.text_field I18n.locale.to_s,{:value=>@form_to_show[item][I18n.locale.to_s] ,:id=> item} %> + <%= locale_fields.text_field I18n.locale.to_s,{:value=>@form_to_show[item][I18n.locale.to_s] ,:id=> item,:style=>'width:calc(100% - 16em)'} %> <% end %> <% else %> - <%= form.text_field item,{:value=>@form_to_show[item],:id=> item} %> + <%= form.text_field item,{:value=>@form_to_show[item],:id=> item,:style=>'width:calc(100% - 16em)'} %> <% end %>
<% end %> diff --git a/app/views/admin/cancerpredicts/showSubmit.html.erb b/app/views/admin/cancerpredicts/showSubmit.html.erb index 0ddb918..251581a 100644 --- a/app/views/admin/cancerpredicts/showSubmit.html.erb +++ b/app/views/admin/cancerpredicts/showSubmit.html.erb @@ -42,6 +42,7 @@ <%end%> +<%=create_pagination(@page_num).html_safe%>