From 7982622ca8100c832ea00b4aafc5a9f4e56a10d3 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 11 Dec 2019 23:59:17 +0800 Subject: [PATCH] add the feature that will collect user input and user can edit the form in the admin page. --- .../admin/cancerpredicts_controller.rb | 69 +++++++++- app/controllers/cancerpredicts_controller.rb | 7 + app/models/cancerpredictrecord.rb | 19 +++ app/views/admin/cancerpredicts/edit.html.erb | 0 app/views/admin/cancerpredicts/index.html.erb | 128 +++++++++++++++--- .../admin/cancerpredicts/showSubmit.html.erb | 63 +++++++++ cancerpredict.gemspec | 48 +++---- config/locales/en.yml | 3 +- config/locales/zh_tw.yml | 3 +- config/routes.rb | 3 + lib/cancerpredict/engine.rb | 5 + modules/built_in_extensions.rb | 2 +- 12 files changed, 296 insertions(+), 54 deletions(-) create mode 100644 app/models/cancerpredictrecord.rb create mode 100644 app/views/admin/cancerpredicts/edit.html.erb create mode 100644 app/views/admin/cancerpredicts/showSubmit.html.erb diff --git a/app/controllers/admin/cancerpredicts_controller.rb b/app/controllers/admin/cancerpredicts_controller.rb index 8d4be00..0d43159 100644 --- a/app/controllers/admin/cancerpredicts_controller.rb +++ b/app/controllers/admin/cancerpredicts_controller.rb @@ -15,11 +15,74 @@ class Admin::CancerpredictsController < OrbitAdminController @categories = @module_app.categories.enabled @filter_fields = filter_fields(@categories, @tags) @table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified] - if request.xhr? - render :partial => "index" - end end 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 def create_first_field if Cancerpredictfields.where("title"=>(@app_title + "_back")).take_while{true}.count == 0 diff --git a/app/controllers/cancerpredicts_controller.rb b/app/controllers/cancerpredicts_controller.rb index b093efa..68b6ca6 100644 --- a/app/controllers/cancerpredicts_controller.rb +++ b/app/controllers/cancerpredicts_controller.rb @@ -10,6 +10,13 @@ class CancerpredictsController < ApplicationController tags = OrbitHelper.widget_tags categories = OrbitHelper.widget_categories || [] 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 = 'zh_tw' if locale == 'zh_cn' result = {} diff --git a/app/models/cancerpredictrecord.rb b/app/models/cancerpredictrecord.rb new file mode 100644 index 0000000..bb712f7 --- /dev/null +++ b/app/models/cancerpredictrecord.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/cancerpredicts/edit.html.erb b/app/views/admin/cancerpredicts/edit.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/admin/cancerpredicts/index.html.erb b/app/views/admin/cancerpredicts/index.html.erb index 92a7b84..3041b2f 100644 --- a/app/views/admin/cancerpredicts/index.html.erb +++ b/app/views/admin/cancerpredicts/index.html.erb @@ -1,34 +1,96 @@
<% @i = 0 %> - - - - <% @form_to_show.form_show.values[1].each do |key,vlaue|%> - - <%end%> - - - <%=form_for @form_to_show ,:url=>{:controller=>"cancerpredicts" ,:action=>"edit"} do |form|%> +<%=form_for @form_to_show ,:url=>{:controller=>"cancerpredicts" ,:action=>"edit"} do |form|%> +
<%=key%>
+ + + <% @form_to_show.form_show.values[1].each do |key,vlaue|%> + + <%end%> + + <%= form.fields_for :form_show do |formfield|%> <% @form_to_show.form_show.each do |num,property| %> - - <% property.each do |key,value|%> - <% @value= value %> - <% if @value.class == BSON::Document || @value.class == Hash %> - <% @disp_value = @value[I18n.locale.to_s] rescue "" %> - <%else%> - <%Fixnum%> - <% @disp_value = @value %> + <%=formfield.fields_for num.to_s do |make_fields|%> + + <% 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%> + + <% else%> + + <%end%> + <% elsif @value.class == BSON::Document || @value.class == Hash %> + <%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%> + + <%end%> + <% else %> + + <%end%> <%end%> - + <%end%> - <%end%> <%end%> +
<%=key%>
<%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%><%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%><%= locale_fields.text_field key,{:value=>@disp_value}%><%= make_fields.text_field key,{:value=>@disp_value}%><%= formfield.text_field key,{:value=>@disp_value}%>
+ <%=t('cancerpredict.table.Results')%> +
+ + <% if @form_to_show.form_result_is_right.to_i == 1%> +
<%= 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"}%>
+ <% else%> +
<%= 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"}%>
<%end%> - + + + + <% @form_to_show.form_show_in_result.values[1].each do |key,vlaue|%> + + <%end%> + + + + <%= 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|%> + + <% 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%> + + <% else%> + + <%end%> + <% elsif @value.class == BSON::Document || @value.class == Hash %> + <%=make_fields.fields_for I18n.locale.to_s do |locale_fields|%> + + <%end%> + <% else %> + + <%end%> + <%end%> + + <%end%> + <%end%> + <%end%> + +
<%=key%>
<%= make_fields.check_box key,{:checked=>true,:class=>"checkbox",:style=>"float:left;"}%><%= make_fields.check_box key,{:checked=>false,:class=>"checkbox",:style=>"float:left;"}%><%= locale_fields.text_field key,{:value=>@disp_value}%><%= make_fields.text_field key,{:value=>@disp_value}%>
+ <%=form.submit "#{t(:updatefont)}",{:id=>"updatebtn"}%> +<%end%> \ No newline at end of file diff --git a/app/views/admin/cancerpredicts/showSubmit.html.erb b/app/views/admin/cancerpredicts/showSubmit.html.erb new file mode 100644 index 0000000..3173200 --- /dev/null +++ b/app/views/admin/cancerpredicts/showSubmit.html.erb @@ -0,0 +1,63 @@ + + + + <% @result_names.each do |name|%> + + <%end%> + + + +<% @results.each do |result| %> + + <% result.result.each_with_index do |(key,value),i| %> + <% if key != "locale" %> + <% if @choicenames[i] == "" %> + + <% else %> + + <% end %> + <% end %> + <%end%> + +<%end%> + + \ No newline at end of file diff --git a/cancerpredict.gemspec b/cancerpredict.gemspec index 6b0d547..4a1a180 100644 --- a/cancerpredict.gemspec +++ b/cancerpredict.gemspec @@ -1,30 +1,22 @@ -$:.push File.expand_path("../lib", __FILE__) -app_path = File.expand_path(__dir__) -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| - s.name = "cancerpredict" - s.version = Cancerpredict::VERSION - 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" +# -*- encoding: utf-8 -*- +# stub: cancerpredict 0.0.1 ruby lib - s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] - s.test_files = Dir["test/**/*"] +Gem::Specification.new do |s| + s.name = "cancerpredict" + s.version = "0.0.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 52a8deb..4350afd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,6 +1,7 @@ en: cancerpredict: - cancerpredict: Predict breast cancer + cancerpredict: adjust the predict breast cancer tool + submitResult: see submit results of the users table: welcome: Welcome to The after breast cancer healing system of Taiwanprepare!\nTo start, please enter the relevant information below. Reset: Reset diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 59eceb7..eae146d 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,6 +1,7 @@ zh_tw: cancerpredict: - cancerpredict: 乳癌預測 + cancerpredict: 乳癌預測工具調整 + submitResult: 查看用戶繳交表單結果 table: welcome: 歡迎使用台灣準備乳癌癒後系統!\n若要開始 請在下方輸入相關資訊 Reset: 重置 diff --git a/config/routes.rb b/config/routes.rb index 6edb019..9fdb478 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,9 @@ Rails.application.routes.draw do namespace :admin do get 'cancerpredicts' , to: 'cancerpredicts#index' get 'editCancerpredicts' , to: 'cancerpredicts#edit' + post 'editCancerpredicts' , to: 'cancerpredicts#edit' + patch 'editCancerpredicts' , to: 'cancerpredicts#edit' + get 'cancerpredicts/showSubmit' , to: 'cancerpredicts#showSubmit' resources :cancerpredicts end end diff --git a/lib/cancerpredict/engine.rb b/lib/cancerpredict/engine.rb index 4747a8e..e75d628 100644 --- a/lib/cancerpredict/engine.rb +++ b/lib/cancerpredict/engine.rb @@ -21,6 +21,11 @@ module Cancerpredict :priority=>1, :active_for_action=>{'admin/cancerpredicts'=>'index'}, :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 diff --git a/modules/built_in_extensions.rb b/modules/built_in_extensions.rb index 154ccba..bd4c098 100644 --- a/modules/built_in_extensions.rb +++ b/modules/built_in_extensions.rb @@ -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 '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'
<%=name.to_s.html_safe %>
<%= value %><%= @choicenames[i][value.to_i-1] %>