fix
This commit is contained in:
parent
62045584fc
commit
d8255b6ad0
|
@ -1,7 +1,10 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
require 'rubyXL'
|
|
||||||
class Admin::CancerpredictsController < OrbitAdminController
|
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 ->(module_app = @app_title) { set_variables module_app }
|
||||||
before_action :create_first_field
|
before_action :create_first_field
|
||||||
#before_action :load_access_levels
|
#before_action :load_access_levels
|
||||||
|
@ -9,7 +12,6 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
super
|
super
|
||||||
@app_title = "cancerpredict"
|
@app_title = "cancerpredict"
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tags = @module_app.tags
|
@tags = @module_app.tags
|
||||||
@categories = @module_app.categories.enabled
|
@categories = @module_app.categories.enabled
|
||||||
|
@ -192,12 +194,14 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
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
|
||||||
@file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w')
|
@file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.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
|
||||||
end
|
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)
|
||||||
|
@ -437,7 +441,8 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
return @table_str
|
return @table_str
|
||||||
end
|
end
|
||||||
def showSubmit
|
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 = []
|
@variables = []
|
||||||
@names = []
|
@names = []
|
||||||
@form_to_show.form_show.each do |num,property|
|
@form_to_show.form_show.each do |num,property|
|
||||||
|
@ -452,13 +457,14 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
@result_variables = []
|
@result_variables = []
|
||||||
@result_names = []
|
@result_names = []
|
||||||
@indexs=[]
|
@indexs=[]
|
||||||
|
@choicenames=[]
|
||||||
|
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?
|
||||||
@indexs.push @index if !@index.nil?
|
@indexs.push @index if !@index.nil?
|
||||||
end
|
end
|
||||||
@choicenames=[]
|
|
||||||
@indexs.each do |index|
|
@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
|
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 ""
|
@choicenames.push ""
|
||||||
|
@ -467,6 +473,7 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
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()
|
||||||
|
@ -481,12 +488,14 @@ class Admin::CancerpredictsController < OrbitAdminController
|
||||||
@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
|
||||||
@file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.txt', 'w')
|
@file_tmp = File.new('cancer_tool_table_tmp_'+locale.to_s+'.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
|
||||||
end
|
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
|
||||||
|
|
|
@ -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')
|
result['pstage_3']*1.134+result['pstage_4']*2.172+result['lvi_yes']*0.3321-0.04 rescue 'error')
|
||||||
@years = @form_to_show.years
|
@years = @form_to_show.years
|
||||||
result['table'] = '<input id="current_year" type="hidden" value="'+@years[-1].to_s+'" index="0"/><p id="cancer_table_texts">'+@form_to_show.table_above_texts[locale]+'</p>'
|
result['table'] = '<input id="current_year" type="hidden" value="'+@years[-1].to_s+'" index="0"/><p id="cancer_table_texts">'+@form_to_show.table_above_texts[locale]+'</p>'
|
||||||
result['table'] += '<a style="display: inline-block;">第</a><a style="display: inline-block;">'
|
result['table'] += ('<a style="display: inline-block;">'+(locale == 'zh_tw' ? '第' : '')+'</a><a style="display: inline-block;">')
|
||||||
result['years'] = @years
|
result['years'] = @years
|
||||||
@years.each{|year| result['table'] += ('<button class="cancer_years cancer_table_btn btn btn-default btn-sm">'+year.to_s+'</button>')}
|
@years.each{|year| result['table'] += ('<button class="cancer_years cancer_table_btn btn btn-default btn-sm">'+year.to_s+'</button>')}
|
||||||
result['table'] += '</a><a style="display: inline-block;">年</a>'
|
result['table'] += ('</a><a style="display: inline-block;">'+(locale == 'zh_tw' ? '年' : '')+'</a>')
|
||||||
@table_head = (locale == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)']
|
@table_head = (locale == "zh_tw") ? ['治療','額外治療效益','總生存率(%)'] :['Treatment','Additional Benefit','Overall Survival(%)']
|
||||||
@head_name = ['Treatment','Additional_Benefit','Overall_Survival']
|
@head_name = ['Treatment','Additional_Benefit','Overall_Survival']
|
||||||
@therapy_choices = (locale == "zh_tw") ? ['純手術'] :['Surgery only']
|
@therapy_choices = (locale == "zh_tw") ? ['純手術'] :['Surgery only']
|
||||||
|
|
|
@ -1,7 +1,37 @@
|
||||||
require "net/http"
|
|
||||||
require "uri"
|
|
||||||
require 'json'
|
|
||||||
|
|
||||||
module Admin::CancerpredictsHelper
|
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 = '<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>['+t('cancerpredict.prev_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page-1).to_s+'"> ['+t('cancerpredict.prev_page')+'] </a></li>')
|
||||||
|
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) ? '<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
|
||||||
|
(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>'
|
||||||
|
(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
|
||||||
|
(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>'
|
||||||
|
(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
|
||||||
|
(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>'
|
||||||
|
(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
|
||||||
|
(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
|
||||||
|
(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>'
|
||||||
|
(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
|
||||||
|
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>')}
|
||||||
|
end
|
||||||
|
pagination += (((page==all_page_num) ? '<li>['+t('cancerpredict.next_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page+1).to_s+'"> ['+t('cancerpredict.next_page')+'] </a></li>')+'</ol></div>')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -138,9 +138,9 @@
|
||||||
</p>
|
</p>
|
||||||
<span class="show_span"><%= t('cancerpredict.text_descibe') %></span>
|
<span class="show_span"><%= t('cancerpredict.text_descibe') %></span>
|
||||||
<div style="clear:both;"></div>
|
<div style="clear:both;"></div>
|
||||||
<%= form.fields_for 'text_descibe' do |locale_fields|%>
|
<textarea class="ckeditor" id="cancerpredictfields_text_descibe_<%=I18n.locale.to_s%>" name="cancerpredictfields[text_descibe][<%=I18n.locale.to_s%>]">
|
||||||
<%= locale_fields.text_field I18n.locale.to_s,{:value=> @form_to_show.text_descibe[I18n.locale.to_s],:style=>'width:100%;'} %>
|
<%= @form_to_show.text_descibe[I18n.locale.to_s] %>
|
||||||
<%end%>
|
</textarea>
|
||||||
<span class="show_span"><%= t('cancerpredict.font_size') %></span>
|
<span class="show_span"><%= t('cancerpredict.font_size') %></span>
|
||||||
<div style="clear:both;"></div>
|
<div style="clear:both;"></div>
|
||||||
<% @size=['small','medium','large'] %>
|
<% @size=['small','medium','large'] %>
|
||||||
|
@ -207,13 +207,13 @@
|
||||||
<div style="clear:both;"></div>
|
<div style="clear:both;"></div>
|
||||||
<% @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 = ['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|%>
|
<% @create_items.each do |item|%>
|
||||||
<label for="<%=item%>" style="float: left;margin-right:1em;"><%= t('cancerpredict.'+item)+':' %></label>
|
<label for="<%=item%>" style="float: left;margin-right:1em;width:11em;"><%= t('cancerpredict.'+item)+':' %></label>
|
||||||
<% if @form_to_show[item].class == BSON::Document || @form_to_show[item].class == Hash %>
|
<% if @form_to_show[item].class == BSON::Document || @form_to_show[item].class == Hash %>
|
||||||
<%= form.fields_for item do |locale_fields|%>
|
<%= 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 %>
|
<% end %>
|
||||||
<% else %>
|
<% 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 %>
|
||||||
<div style="clear:both;"></div>
|
<div style="clear:both;"></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
<%end%>
|
<%end%>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<%=create_pagination(@page_num).html_safe%>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
thead > tr > th{
|
thead > tr > th{
|
||||||
border:1px solid;
|
border:1px solid;
|
||||||
|
|
|
@ -1,49 +1,6 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
# stub: cancerpredict 0.0.1 ruby lib
|
# stub: cancerpredict 0.0.1 ruby lib
|
||||||
routes_text = File.read(ENV['PWD']+'/config/routes.rb')
|
|
||||||
insert_texts = ['get "cancerpredictResult",to: "cancerpredicts#calculate"','post "cancerpredictResult",to: "cancerpredicts#calculate"']
|
|
||||||
insert_flag = 0
|
|
||||||
insert_texts.each do |insert_text|
|
|
||||||
if !routes_text.include?(insert_text)
|
|
||||||
insert_index = routes_text.index('get "/admin/license_denied" => "store_api#render_license_denied"')
|
|
||||||
routes_text.insert(insert_index,insert_text+"\n")
|
|
||||||
insert_flag = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
app_path = File.expand_path(__dir__)
|
|
||||||
if insert_flag == 1
|
|
||||||
f = File.open(ENV['PWD']+'/config/routes.rb','w')
|
|
||||||
f.write(routes_text)
|
|
||||||
f.close
|
|
||||||
end
|
|
||||||
template_path = ENV['PWD'] + '/app/templates'
|
|
||||||
all_template = Dir.glob(template_path+'/*/')
|
|
||||||
puts 'copying module'
|
|
||||||
check_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.min.js"%>'
|
|
||||||
edit_texts = '<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"%>'
|
|
||||||
all_template.each do |folder|
|
|
||||||
if !folder.include?('mobile')
|
|
||||||
if folder.split('/')[-1] != 'mobile'
|
|
||||||
begin
|
|
||||||
system ('cp -r '+ app_path + '/modules/. ' + folder+'/modules/.')
|
|
||||||
rescue
|
|
||||||
puts 'error copy'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
texts = File.read(folder+'partial/_head.html.erb')
|
|
||||||
insert_flag = 0
|
|
||||||
if texts.include?(check_texts)
|
|
||||||
texts = texts.gsub(check_texts,edit_texts)
|
|
||||||
insert_flag = 1
|
|
||||||
end
|
|
||||||
if insert_flag == 1
|
|
||||||
puts 'editing _head.html.erb'
|
|
||||||
f = File.open(folder+'partial/_head.html.erb','w')
|
|
||||||
f.write(texts)
|
|
||||||
f.close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "cancerpredict"
|
s.name = "cancerpredict"
|
||||||
s.version = "0.0.1"
|
s.version = "0.0.1"
|
||||||
|
|
|
@ -23,6 +23,8 @@ en:
|
||||||
extra_therapy_texts: Extra therapy texts
|
extra_therapy_texts: Extra therapy texts
|
||||||
danger_texts: Warning texts
|
danger_texts: Warning texts
|
||||||
texts_between_Result_and_result_block: Texts between "Result" and "Result block"
|
texts_between_Result_and_result_block: Texts between "Result" and "Result block"
|
||||||
|
prev_page: Previous page
|
||||||
|
next_page: Next page
|
||||||
table:
|
table:
|
||||||
welcome: Welcome to The after breast cancer healing system of Taiwanprepare!\nTo start, please enter the relevant information below.
|
welcome: Welcome to The after breast cancer healing system of Taiwanprepare!\nTo start, please enter the relevant information below.
|
||||||
Reset: Reset
|
Reset: Reset
|
||||||
|
|
|
@ -23,6 +23,8 @@ zh_tw:
|
||||||
extra_therapy_texts: 額外治療的文字
|
extra_therapy_texts: 額外治療的文字
|
||||||
danger_texts: 警告文字
|
danger_texts: 警告文字
|
||||||
texts_between_Result_and_result_block: 在"結果"和"結果區塊"之間的文字
|
texts_between_Result_and_result_block: 在"結果"和"結果區塊"之間的文字
|
||||||
|
prev_page: 上一頁
|
||||||
|
next_page: 下一頁
|
||||||
table:
|
table:
|
||||||
welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊
|
welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊
|
||||||
Reset: 重置
|
Reset: 重置
|
||||||
|
|
Loading…
Reference in New Issue