add the feature that will collect user input and user can edit the form in the admin page.

This commit is contained in:
chiu 2019-12-11 23:59:17 +08:00
parent 1e41d84353
commit 7982622ca8
12 changed files with 296 additions and 54 deletions

View File

@ -15,11 +15,74 @@ class Admin::CancerpredictsController < OrbitAdminController
@categories = @module_app.categories.enabled @categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, @tags) @filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified] @table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
if request.xhr?
render :partial => "index"
end
end end
def edit 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
@form_to_show.form_show[num.to_s][key.to_s] = value[1..-2].split(',').collect!{|n| n.to_i}
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
#render :html => sub_value.gsub('"','') and return
@form_to_show.form_show[ num.to_s ][ sub_property ][params[:locale].to_s] = sub_value.gsub('"','')[1..-2].split(',').collect!{|n| n}
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
@form_to_show.save
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=[]
@results[0].result.each{|key,value| @result_variables.push key}
@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
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

View File

@ -10,6 +10,13 @@ class CancerpredictsController < ApplicationController
tags = OrbitHelper.widget_tags tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || [] categories = OrbitHelper.widget_categories || []
create_first_field create_first_field
@record = Cancerpredictrecord.new
@record.title = @app_title
params['data'].each do |rec_key,rec_value|
@record.result[rec_key] = rec_value
end
@record.submit_time = Time.now.to_s
@record.save
locale = params['data']['locale'].to_s rescue 'zh_tw' locale = params['data']['locale'].to_s rescue 'zh_tw'
locale = 'zh_tw' if locale == 'zh_cn' locale = 'zh_tw' if locale == 'zh_cn'
result = {} result = {}

View File

@ -0,0 +1,19 @@
class Cancerpredictrecord
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitModel::Impression
# encoding: utf-8
include OrbitTag::Taggable
include OrbitCategory::Categorizable
field :title ,type:String ,default:""
field :submit_time ,type:String ,default:""
field :result , type:Hash , default:{}
field :submit_numbers , type:Fixnum , default: 1
scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])}
scope :is_approved, ->{where(:approved => true)}
before_save :set_submit_times
def set_submit_times
self.submit_time = Cancerpredictrecord.where(:title=> "cancerpredict").length + 1
end
end

View File

@ -1,6 +1,7 @@
<div style="clear:both;"></div> <div style="clear:both;"></div>
<% @i = 0 %> <% @i = 0 %>
<table> <%=form_for @form_to_show ,:url=>{:controller=>"cancerpredicts" ,:action=>"edit"} do |form|%>
<table>
<thead> <thead>
<tr> <tr>
<% @form_to_show.form_show.values[1].each do |key,vlaue|%> <% @form_to_show.form_show.values[1].each do |key,vlaue|%>
@ -8,27 +9,88 @@
<%end%> <%end%>
</tr> </tr>
</thead> </thead>
<%=form_for @form_to_show ,:url=>{:controller=>"cancerpredicts" ,:action=>"edit"} do |form|%>
<tbody> <tbody>
<%= form.fields_for :form_show do |formfield|%> <%= form.fields_for :form_show do |formfield|%>
<% @form_to_show.form_show.each do |num,property| %> <% @form_to_show.form_show.each do |num,property| %>
<%=formfield.fields_for num.to_s do |make_fields|%>
<tr> <tr>
<% property.each do |key,value|%> <% property.each do |key,value|%>
<% @value= value %> <% @value= value %>
<% if @value.class == BSON::Document || @value.class == Hash %> <% if @value.class == BSON::Document || @value.class == Hash %>
<% @disp_value = @value[I18n.locale.to_s] rescue "" %> <% @disp_value = @value[I18n.locale.to_s] rescue "" %>
<%else%> <%else%>
<%Fixnum%>
<% @disp_value = @value %> <% @disp_value = @value %>
<%end%> <%end%>
<td><%= formfield.text_field key,{:value=>@disp_value}%></td> <% if @value.class == Fixnum %>
<% if @value == 1%>
<td><%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%></td>
<% else%>
<td><%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%></td>
<%end%>
<% elsif @value.class == BSON::Document || @value.class == Hash %>
<%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%>
<td><%= locale_fields.text_field key,{:value=>@disp_value}%></td>
<%end%>
<% else %>
<td><%= make_fields.text_field key,{:value=>@disp_value}%></td>
<%end%>
<%end%> <%end%>
</tr> </tr>
<%end%> <%end%>
<%end%> <%end%>
</tbody>
<%end%> <%end%>
</table> </tbody>
</table>
<span class="show_span"><%=t('cancerpredict.table.Results')%></span>
<div style="clear:both;"></div>
<label for="form_result_is_right" style="float: left;">結果在右邊</label>
<% if @form_to_show.form_result_is_right.to_i == 1%>
<div><%= form.check_box "form_result_is_right",{:checked=>true,:class=>"checkbox",:style=>"float: left;position: relative;left: 0;transform: none!important;margin-left: 1em;",:id=>"form_result_is_right"}%></div>
<% else%>
<div><%= form.check_box "form_result_is_right",{:checked=>false,:class=>"checkbox",:style=>"float: left;position: relative;left: 0;transform: none!important;margin-left: 1em;",:id=>"form_result_is_right"}%></div>
<%end%>
<table>
<thead>
<tr>
<% @form_to_show.form_show_in_result.values[1].each do |key,vlaue|%>
<th><%=key%></th>
<%end%>
</tr>
</thead>
<tbody>
<%= form.fields_for :form_show_in_result do |formfield|%>
<% @form_to_show.form_show_in_result.each do |num,property| %>
<%=formfield.fields_for num.to_s do |make_fields|%>
<tr>
<% property.each do |key,value|%>
<% @value= value %>
<% if @value.class == BSON::Document || @value.class == Hash %>
<% @disp_value = @value[I18n.locale.to_s] rescue "" %>
<%else%>
<% @disp_value = @value %>
<%end%>
<% if @value.class == Fixnum %>
<% if @value == 1%>
<td><%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%></td>
<% else%>
<td><%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%></td>
<%end%>
<% elsif @value.class == BSON::Document || @value.class == Hash %>
<%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%>
<td><%= locale_fields.text_field key,{:value=>@disp_value}%></td>
<%end%>
<% else %>
<td><%= make_fields.text_field key,{:value=>@disp_value}%></td>
<%end%>
<%end%>
</tr>
<%end%>
<%end%>
<%end%>
</tbody>
</table>
<%=form.submit "#{t(:updatefont)}",{:id=>"updatebtn"}%>
<%end%>
<style type="text/css"> <style type="text/css">
thead > tr > th{ thead > tr > th{
border:1px solid; border:1px solid;
@ -39,6 +101,7 @@
} }
tbody > tr > td{ tbody > tr > td{
border:1px solid; border:1px solid;
position: relative;
} }
.show_li,.show_li *{ .show_li,.show_li *{
list-style:none; list-style:none;
@ -51,4 +114,29 @@
color:blue; color:blue;
cursor:pointer; cursor:pointer;
} }
.checkbox{
left: 50%;
position: absolute;
transform: translate(-50%, -50%) !important;
top: 50%;
}
#updatebtn{
margin-top: 1em;
right: 1em;
background-color: rgb(210, 105, 0);
color: white;
border: 0em;
padding: 0.125em 0.5em;
border-radius: 0.5em;
}
.show_span{
margin: 1em;
float: left;
background-color: rgb(210, 105, 0);
color: white;
border: 0em;
padding: 0.125em 0.5em;
border-radius: 0.5em;
width: fit-content;
}
</style> </style>

View File

@ -0,0 +1,63 @@
<table>
<thead>
<tr>
<% @result_names.each do |name|%>
<th><%=name.to_s.html_safe %></th>
<%end%>
</tr>
</thead>
<tbody>
<% @results.each do |result| %>
<tr>
<% result.result.each_with_index do |(key,value),i| %>
<% if key != "locale" %>
<% if @choicenames[i] == "" %>
<td><%= value %></td>
<% else %>
<td><%= @choicenames[i][value.to_i-1] %></td>
<% end %>
<% end %>
<%end%>
</tr>
<%end%>
</tbody>
<style type="text/css">
thead > tr > th{
border:1px solid;
background: bisque;
}
tbody{
background:white;
}
tbody > tr > td{
border:1px solid;
position: relative;
}
.show_li,.show_li *{
list-style:none;
color:balck;
}
.show_li ul{
display:none;
}
#clicktosee{
color:blue;
cursor:pointer;
}
.checkbox{
left: 50%;
position: absolute;
transform: translate(-50%, -50%) !important;
top: 50%;
}
#updatebtn{
margin-top: 1em;
position: fixed;
right: 1em;
background-color: rgb(210, 105, 0);
color: white;
border: 0em;
padding: 0.125em 0.5em;
border-radius: 0.5em;
}
</style>

View File

@ -1,30 +1,22 @@
$:.push File.expand_path("../lib", __FILE__) # -*- encoding: utf-8 -*-
app_path = File.expand_path(__dir__) # stub: cancerpredict 0.0.1 ruby lib
template_path = ENV['PWD'] + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
puts 'copying module'
all_template.each do |folder|
if folder.split('/')[-1] != 'mobile'
begin
system ('cp -r '+ app_path + '/modules/ ' + folder)
rescue
puts 'error copy'
end
end
end
# Maintain your gem's version:
require "cancerpredict/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "cancerpredict" s.name = "cancerpredict"
s.version = Cancerpredict::VERSION s.version = "0.0.1"
s.authors = ["Ruling Digital"]
s.email = ["orbit@rulingcom.com"]
s.homepage = "http://www.rulingcom.com"
s.summary = "Cancer_Predict for Orbit"
s.description = "Cancer_Predict for Orbit"
s.license = "MIT"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.test_files = Dir["test/**/*"] s.require_paths = ["lib"]
s.authors = ["Ruling Digital"]
s.date = "2019-12-09"
s.description = "Cancer_Predict for Orbit"
s.email = ["orbit@rulingcom.com"]
s.files = ["MIT-LICENSE", "README.rdoc", "Rakefile", "app/assets/images/cancerpredict", "app/assets/images/cancerpredict/triangle_add.png", "app/assets/images/cancerpredict/triangle_sub.png", "app/assets/javascripts/admin/cancerpredict.js", "app/assets/javascripts/cancer_predict.js", "app/assets/javascripts/jquery.smartmenus.bootstrap.min.js", "app/assets/javascripts/jquery.smartmenus.min.js", "app/assets/javascripts/react.js", "app/assets/stylesheets/admin/cancerpredict.css", "app/assets/stylesheets/cancer_predict.css", "app/controllers/admin/cancerpredicts_controller.rb", "app/controllers/cancerpredicts_controller.rb", "app/helpers/admin/cancerpredicts_helper.rb", "app/models/cancerpredictfields.rb", "app/views/admin/cancerpredicts", "app/views/admin/cancerpredicts/_form.html.erb", "app/views/admin/cancerpredicts/_form_file.html.erb", "app/views/admin/cancerpredicts/_form_link.html.erb", "app/views/admin/cancerpredicts/_index.html.erb", "app/views/admin/cancerpredicts/index.html.erb", "app/views/admin/cancerpredicts/new.html.erb", "app/views/admin/cancerpredicts/settings.html.erb", "app/views/admin/cancerpredicts/update.html.erb", "app/views/cancerpredicts", "app/views/cancerpredicts/index.html.erb", "config/locales/en.yml", "config/locales/zh_tw.yml", "config/routes.rb", "lib/cancerpredict", "lib/cancerpredict.rb", "lib/cancerpredict/engine.rb", "lib/cancerpredict/version.rb", "lib/tasks/cancerpredict_tasks.rake", "test/cancerpredict_test.rb", "test/controllers/admin/cancerpredicts_controller_test.rb", "test/dummy", "test/dummy/README.rdoc", "test/dummy/Rakefile", "test/dummy/app", "test/dummy/app/assets", "test/dummy/app/assets/images", "test/dummy/app/assets/javascripts", "test/dummy/app/assets/javascripts/application.js", "test/dummy/app/assets/stylesheets", "test/dummy/app/assets/stylesheets/application.css", "test/dummy/app/controllers", "test/dummy/app/controllers/application_controller.rb", "test/dummy/app/controllers/concerns", "test/dummy/app/helpers", "test/dummy/app/helpers/application_helper.rb", "test/dummy/app/mailers", "test/dummy/app/models", "test/dummy/app/models/concerns", "test/dummy/app/views", "test/dummy/app/views/layouts", "test/dummy/app/views/layouts/application.html.erb", "test/dummy/bin", "test/dummy/bin/bundle", "test/dummy/bin/rails", "test/dummy/bin/rake", "test/dummy/config", "test/dummy/config.ru", "test/dummy/config/application.rb", "test/dummy/config/boot.rb", "test/dummy/config/environment.rb", "test/dummy/config/environments", "test/dummy/config/environments/development.rb", "test/dummy/config/environments/production.rb", "test/dummy/config/environments/test.rb", "test/dummy/config/initializers", "test/dummy/config/initializers/backtrace_silencers.rb", "test/dummy/config/initializers/cookies_serializer.rb", "test/dummy/config/initializers/filter_parameter_logging.rb", "test/dummy/config/initializers/inflections.rb", "test/dummy/config/initializers/mime_types.rb", "test/dummy/config/initializers/session_store.rb", "test/dummy/config/initializers/wrap_parameters.rb", "test/dummy/config/locales", "test/dummy/config/locales/en.yml", "test/dummy/config/routes.rb", "test/dummy/config/secrets.yml", "test/dummy/lib", "test/dummy/lib/assets", "test/dummy/log", "test/dummy/public", "test/dummy/public/404.html", "test/dummy/public/422.html", "test/dummy/public/500.html", "test/dummy/public/favicon.ico", "test/helpers/admin/cancerpredicts_helper_test.rb", "test/integration/navigation_test.rb", "test/test_helper.rb"]
s.homepage = "http://www.rulingcom.com"
s.licenses = ["MIT"]
s.rubygems_version = "2.2.2"
s.summary = "Cancer_Predict for Orbit"
s.test_files = ["test/cancerpredict_test.rb", "test/dummy", "test/dummy/README.rdoc", "test/dummy/bin", "test/dummy/bin/bundle", "test/dummy/bin/rake", "test/dummy/bin/rails", "test/dummy/log", "test/dummy/app", "test/dummy/app/assets", "test/dummy/app/assets/javascripts", "test/dummy/app/assets/javascripts/application.js", "test/dummy/app/assets/images", "test/dummy/app/assets/stylesheets", "test/dummy/app/assets/stylesheets/application.css", "test/dummy/app/mailers", "test/dummy/app/helpers", "test/dummy/app/helpers/application_helper.rb", "test/dummy/app/controllers", "test/dummy/app/controllers/application_controller.rb", "test/dummy/app/controllers/concerns", "test/dummy/app/views", "test/dummy/app/views/layouts", "test/dummy/app/views/layouts/application.html.erb", "test/dummy/app/models", "test/dummy/app/models/concerns", "test/dummy/Rakefile", "test/dummy/lib", "test/dummy/lib/assets", "test/dummy/public", "test/dummy/public/422.html", "test/dummy/public/500.html", "test/dummy/public/favicon.ico", "test/dummy/public/404.html", "test/dummy/config.ru", "test/dummy/config", "test/dummy/config/environments", "test/dummy/config/environments/production.rb", "test/dummy/config/environments/development.rb", "test/dummy/config/environments/test.rb", "test/dummy/config/environment.rb", "test/dummy/config/boot.rb", "test/dummy/config/routes.rb", "test/dummy/config/application.rb", "test/dummy/config/secrets.yml", "test/dummy/config/locales", "test/dummy/config/locales/en.yml", "test/dummy/config/initializers", "test/dummy/config/initializers/wrap_parameters.rb", "test/dummy/config/initializers/cookies_serializer.rb", "test/dummy/config/initializers/mime_types.rb", "test/dummy/config/initializers/inflections.rb", "test/dummy/config/initializers/backtrace_silencers.rb", "test/dummy/config/initializers/filter_parameter_logging.rb", "test/dummy/config/initializers/session_store.rb", "test/test_helper.rb", "test/helpers/admin/cancerpredicts_helper_test.rb", "test/controllers/admin/cancerpredicts_controller_test.rb", "test/integration/navigation_test.rb"]
s.installed_by_version = "2.2.2" if s.respond_to? :installed_by_version
end end

View File

@ -1,6 +1,7 @@
en: en:
cancerpredict: cancerpredict:
cancerpredict: Predict breast cancer cancerpredict: adjust the predict breast cancer tool
submitResult: see submit results of the users
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

View File

@ -1,6 +1,7 @@
zh_tw: zh_tw:
cancerpredict: cancerpredict:
cancerpredict: 乳癌預測 cancerpredict: 乳癌預測工具調整
submitResult: 查看用戶繳交表單結果
table: table:
welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊 welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊
Reset: 重置 Reset: 重置

View File

@ -6,6 +6,9 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
get 'cancerpredicts' , to: 'cancerpredicts#index' get 'cancerpredicts' , to: 'cancerpredicts#index'
get 'editCancerpredicts' , to: 'cancerpredicts#edit' get 'editCancerpredicts' , to: 'cancerpredicts#edit'
post 'editCancerpredicts' , to: 'cancerpredicts#edit'
patch 'editCancerpredicts' , to: 'cancerpredicts#edit'
get 'cancerpredicts/showSubmit' , to: 'cancerpredicts#showSubmit'
resources :cancerpredicts resources :cancerpredicts
end end
end end

View File

@ -21,6 +21,11 @@ module Cancerpredict
:priority=>1, :priority=>1,
:active_for_action=>{'admin/cancerpredicts'=>'index'}, :active_for_action=>{'admin/cancerpredicts'=>'index'},
:available_for => 'users' :available_for => 'users'
context_link 'cancerpredict.submitResult',
:link_path=>"admin_cancerpredicts_showSubmit_path" ,
:priority=>1,
:active_for_action=>{'admin/cancerpredicts'=>'show_submit'},
:available_for => 'users'
end end
end end
end end

View File

@ -23,4 +23,4 @@ gem "breadcrumb_widget", git: "http://gitlab.tp.rulingcom.com/saurabh/breadcrumb
gem "announcement_link_widget", git: "http://gitlab.tp.rulingcom.com/harry/announcement-link-widget.git" gem "announcement_link_widget", git: "http://gitlab.tp.rulingcom.com/harry/announcement-link-widget.git"
gem 'patchfile', git: 'http://gitlab.tp.rulingcom.com/chiu/patch_file.git' gem 'patchfile', git: 'http://gitlab.tp.rulingcom.com/chiu/patch_file.git'
gem 'cancerpredict', branch: 'final_version' , git: 'http://gitlab.tp.rulingcom.com/chiu/cancer_predict.git' gem 'cancerpredict', git: 'http://gitlab.tp.rulingcom.com/chiu/cancer_predict.git'