From 4ccc1924bdfc7db0e46e762f0359d336307da643 Mon Sep 17 00:00:00 2001 From: Bohung Date: Sat, 18 Jun 2022 23:13:29 +0800 Subject: [PATCH] Edit singup's uploaded filename display. Edit email contents of file upload or edit. --- app/controllers/seminars_controller.rb | 16 ++++++- app/models/seminar_signup_contribute.rb | 22 +++++++++ .../seminar_review_results/edit.html.erb | 5 +- .../_seminar_signup_render_table.html.erb | 4 +- app/views/email/add_file_email.html.erb | 3 +- app/views/email/edit_file_email.html.erb | 3 +- .../seminars/con_email_contents.html.erb | 47 +++++++++++++++++++ app/views/seminars/con_upload.html.erb | 28 ++++++----- 8 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 app/views/seminars/con_email_contents.html.erb diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index 0d8ae90..7a96d7a 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -515,7 +515,13 @@ class SeminarsController < ApplicationController signup = SeminarSignup.where(id:update_params['seminar_signup_id']).first seminar_id = signup.seminar_main_id @seminar = SeminarMain.where(id:seminar_id).first - send_mail('add_file',signup.email,seminar_id) + host_url = Site.first.root_url + if host_url == "http://" + host_url = request.protocol + request.host_with_port + end + extra_text = "
"+render_to_string("seminars/con_email_contents",:locals=>{:@seminar=>@seminar, + :@con=>@con,:@host_url=>host_url},:layout=>false) + send_mail('add_file',signup.email,seminar_id,extra_text) seminar_reviews = SeminarReview.where(:seminar_main_id=>signup.seminar_main_id).to_a seminar_reviews.each{|sr| sr.save} @seminar = signup.seminar_main @@ -559,7 +565,13 @@ class SeminarsController < ApplicationController signup = SeminarSignup.where(id:update_params['seminar_signup_id']).first seminar_id = signup.seminar_main_id @seminar = SeminarMain.where(id:seminar_id).first - send_mail('edit_file',signup.email,seminar_id) + host_url = Site.first.root_url + if host_url == "http://" + host_url = request.protocol + request.host_with_port + end + extra_text = "
"+render_to_string("seminars/con_email_contents",:locals=>{:@seminar=>@seminar, + :@con=>@con,:@host_url=>host_url},:layout=>false) + send_mail('edit_file',signup.email,seminar_id,extra_text) seminar_reviews = SeminarReview.where(:seminar_main_id=>signup.seminar_main_id).to_a seminar_reviews.each{|sr| sr.save} @seminar = signup.seminar_main diff --git a/app/models/seminar_signup_contribute.rb b/app/models/seminar_signup_contribute.rb index 6ebb194..0942997 100644 --- a/app/models/seminar_signup_contribute.rb +++ b/app/models/seminar_signup_contribute.rb @@ -8,6 +8,7 @@ class SeminarSignupContribute field :presentation_type , type: String , default: "" field :sort_number , type: Integer, default: 10000 mount_uploader :file, AssetUploader + field :filename, type: String field :description field :preferred_session field :final_session @@ -40,4 +41,25 @@ class SeminarSignupContribute end end end + before_save do + self.update_filename + end + def update_filename + if self.title.blank? + self.filename = self.file.file.filename rescue '' + else + if self.file.file + self.filename = self.title.sub(/#{::Regexp.escape(File.extname(self.title))}$/,'') + File.extname(self.file.file.filename) + else + self.filename = self.title + end + end + self.filename + end + def disp_filename + if self.filename.nil? + self.class.where(:id=>self.id).update_all(:filename=>self.update_filename) + end + self.filename + end end \ No newline at end of file diff --git a/app/views/admin/seminar_review_results/edit.html.erb b/app/views/admin/seminar_review_results/edit.html.erb index 8839c84..e724c80 100644 --- a/app/views/admin/seminar_review_results/edit.html.erb +++ b/app/views/admin/seminar_review_results/edit.html.erb @@ -56,6 +56,7 @@ end %> <% file_path = seminar_signup_contribute.file.path %> <% file_title = (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) %> + <% filename = seminar_signup_contribute.disp_filename %> <% file_url = seminar_signup_contribute.file.url %> <% file_extname = File.extname(file_path) %> <% if (file_extname.match(/pdf/i) rescue false) %> @@ -69,9 +70,9 @@ <% file_content = File.read(file_path) rescue "" %> <% if file_content.is_utf8? %> <% file_content = file_content.gsub(/(\r\n|\n)/,"
")%> - <% val = "
#{t(:download)}

#{file_title}

#{file_content}
"%> + <% val = "
#{t(:download)}

#{file_title}

#{file_content}
"%> <% else %> - <% val = link_to( file_title, file_url , {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text} ) if seminar_signup_contribute.file.file %> + <% val = link_to( file_title, file_url , {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text, :download=>filename} ) if seminar_signup_contribute.file.file %> <% end %> <% end %> <% else %> diff --git a/app/views/admin/seminars/_seminar_signup_render_table.html.erb b/app/views/admin/seminars/_seminar_signup_render_table.html.erb index 06d63be..03fd3c9 100644 --- a/app/views/admin/seminars/_seminar_signup_render_table.html.erb +++ b/app/views/admin/seminars/_seminar_signup_render_table.html.erb @@ -141,7 +141,7 @@ description = seminar_signup_contribute.description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
") rescue seminar_signup_contribute.description end end %> - <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text} if seminar_signup_contribute.file.file %> + <%= link_to seminar_signup_contribute.disp_filename , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text, :download=>seminar_signup_contribute.disp_filename} if seminar_signup_contribute.file.file %> <% else %> <%= val[0].html_safe.to_s rescue "" %> <% end %> @@ -185,7 +185,7 @@ description = seminar_signup_contribute.description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
") rescue seminar_signup_contribute.description end end %> - <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text} if seminar_signup_contribute.file.file %> + <%= link_to seminar_signup_contribute.disp_filename , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text, :download=>seminar_signup_contribute.disp_filename} if seminar_signup_contribute.file.file %> <% else %> <%= val.html_safe.to_s rescue "" %> <% end %> diff --git a/app/views/email/add_file_email.html.erb b/app/views/email/add_file_email.html.erb index c4eb60c..9d95eb0 100644 --- a/app/views/email/add_file_email.html.erb +++ b/app/views/email/add_file_email.html.erb @@ -5,4 +5,5 @@ <% end %> <% else %> <%= t('seminar.email_add_file_content') %> -<% end %> \ No newline at end of file +<% end %> +<%= (@data['extra_text'] rescue "").to_s.html_safe %> \ No newline at end of file diff --git a/app/views/email/edit_file_email.html.erb b/app/views/email/edit_file_email.html.erb index 5412b0e..4f097ed 100644 --- a/app/views/email/edit_file_email.html.erb +++ b/app/views/email/edit_file_email.html.erb @@ -5,4 +5,5 @@ <% end %> <% else %> <%= t('seminar.email_edit_file_content') %> -<% end %> \ No newline at end of file +<% end %> +<%= (@data['extra_text'] rescue "").to_s.html_safe %> \ No newline at end of file diff --git a/app/views/seminars/con_email_contents.html.erb b/app/views/seminars/con_email_contents.html.erb new file mode 100644 index 0000000..f390905 --- /dev/null +++ b/app/views/seminars/con_email_contents.html.erb @@ -0,0 +1,47 @@ + +<% + data2 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0] + show2 = !(data2.disabled) rescue false + name2 = data2['name'][I18n.locale] + description = "" + if show2 + description = @con.description.to_s + if @seminar.enable_summary_choice + if (@con.description.to_s.to_i.to_s == @con.description) + description = @seminar.summary_chioices[@con.description.to_i] rescue @con.description + else + description = @con.description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
") rescue @con.description + end + end + end + seminar_submission_fields = @seminar.seminar_submission_fields.where(:disabled=>false) +%> +

<%= @seminar.title rescue nil %>

+ + + + + + + <% if show2 %> + + + + + <% end %> + <% seminar_submission_fields.each do |sf| %> + + + + + <% end %> + +
+ <%= I18n.t('seminar_signup.file_name') %>:  + + <%= @con.disp_filename %> +
<%= name2.present? ? "#{name2}:" : '' %> <%= description.html_safe %>
<%= sf.title.present? ? "#{sf.title}:" : '' %> <%= sf.seminar_submission_values.where(:seminar_signup_contribute_id=>@con.id).first.get_value_by_locale(I18n.locale) rescue "" %>
\ No newline at end of file diff --git a/app/views/seminars/con_upload.html.erb b/app/views/seminars/con_upload.html.erb index 90ff858..c197961 100644 --- a/app/views/seminars/con_upload.html.erb +++ b/app/views/seminars/con_upload.html.erb @@ -54,17 +54,23 @@ @seminar_signup.seminar_signup_contributes.each do |seminar_signup_contribute| %> - <%= seminar_signup_contribute.title %> - <% description = seminar_signup_contribute.description.to_s %> - <% if @seminar.enable_summary_choice - if (seminar_signup_contribute.description.to_s.to_i.to_s == seminar_signup_contribute.description) - description = @seminar.summary_chioices[seminar_signup_contribute.description.to_i] rescue seminar_signup_contribute.description - else - description = seminar_signup_contribute.description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
") rescue seminar_signup_contribute.description - end - end %> - <%= description.html_safe %> - <%= link_to File.basename(seminar_signup_contribute.file.path), seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text} if seminar_signup_contribute.file.file %> + <% if show1 %> + <%= seminar_signup_contribute.title %> + <% end %> + <% if show2 %> + <% description = seminar_signup_contribute.description.to_s %> + <% if @seminar.enable_summary_choice + if (seminar_signup_contribute.description.to_s.to_i.to_s == seminar_signup_contribute.description) + description = @seminar.summary_chioices[seminar_signup_contribute.description.to_i] rescue seminar_signup_contribute.description + else + description = seminar_signup_contribute.description.map{|i| @seminar.summary_chioices[i.to_i] rescue "" }.join("
") rescue seminar_signup_contribute.description + end + end %> + <%= description.html_safe %> + <% end %> + <% if show3 %> + <%= link_to seminar_signup_contribute.disp_filename, seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(description.gsub("
"," , ")).text, :download=>seminar_signup_contribute.disp_filename} if seminar_signup_contribute.file.file %> + <% end %> <% if seminar_submission_field %> <%= seminar_signup_contribute.seminar_submission_values.where(:seminar_submission_field=>seminar_submission_field).first.get_value_by_locale(I18n.locale) %> <% end %>