This commit is contained in:
BOHUNG 2020-02-03 15:26:04 +08:00
parent 62045584fc
commit d8255b6ad0
8 changed files with 81 additions and 80 deletions

View File

@ -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

View File

@ -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'] = '<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
@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(%)']
@head_name = ['Treatment','Additional_Benefit','Overall_Survival']
@therapy_choices = (locale == "zh_tw") ? ['純手術'] :['Surgery only']

View File

@ -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 = '<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

View File

@ -138,9 +138,9 @@
</p>
<span class="show_span"><%= t('cancerpredict.text_descibe') %></span>
<div style="clear:both;"></div>
<%= 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%>
<textarea class="ckeditor" id="cancerpredictfields_text_descibe_<%=I18n.locale.to_s%>" name="cancerpredictfields[text_descibe][<%=I18n.locale.to_s%>]">
<%= @form_to_show.text_descibe[I18n.locale.to_s] %>
</textarea>
<span class="show_span"><%= t('cancerpredict.font_size') %></span>
<div style="clear:both;"></div>
<% @size=['small','medium','large'] %>
@ -207,13 +207,13 @@
<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.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 %>
<%= 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 %>
<div style="clear:both;"></div>
<% end %>

View File

@ -42,6 +42,7 @@
<%end%>
</tbody>
</table>
<%=create_pagination(@page_num).html_safe%>
<style type="text/css">
thead > tr > th{
border:1px solid;

View File

@ -1,49 +1,6 @@
# -*- encoding: utf-8 -*-
# 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|
s.name = "cancerpredict"
s.version = "0.0.1"

View File

@ -23,6 +23,8 @@ en:
extra_therapy_texts: Extra therapy texts
danger_texts: Warning texts
texts_between_Result_and_result_block: Texts between "Result" and "Result block"
prev_page: Previous page
next_page: Next page
table:
welcome: Welcome to The after breast cancer healing system of Taiwanprepare!\nTo start, please enter the relevant information below.
Reset: Reset

View File

@ -23,6 +23,8 @@ zh_tw:
extra_therapy_texts: 額外治療的文字
danger_texts: 警告文字
texts_between_Result_and_result_block: 在"結果"和"結果區塊"之間的文字
prev_page: 上一頁
next_page: 下一頁
table:
welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊
Reset: 重置