From 452e0e07053c8f5f17e4e3184870fbe553013f2a Mon Sep 17 00:00:00 2001 From: bohung Date: Fri, 4 Nov 2022 12:38:27 +0800 Subject: [PATCH 1/2] Fix bug, --- app/models/seminar_signup_field_custom.rb | 2 +- app/views/admin/seminars/_get_display_fields.html.erb | 7 ++++--- app/views/admin/seminars/export.xlsx.axlsx | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/models/seminar_signup_field_custom.rb b/app/models/seminar_signup_field_custom.rb index 658cc5e..baa6a2a 100644 --- a/app/models/seminar_signup_field_custom.rb +++ b/app/models/seminar_signup_field_custom.rb @@ -6,6 +6,6 @@ class SeminarSignupFieldCustom field :hidden, type: Boolean, default: true belongs_to :seminar_main def seminar_signup_field - SeminarSignupField.find(self.seminar_signup_field_id) rescue nil + SeminarSignupField.find(self.seminar_signup_field_id) rescue nil end end diff --git a/app/views/admin/seminars/_get_display_fields.html.erb b/app/views/admin/seminars/_get_display_fields.html.erb index 35cc0f4..54e84db 100644 --- a/app/views/admin/seminars/_get_display_fields.html.erb +++ b/app/views/admin/seminars/_get_display_fields.html.erb @@ -30,8 +30,8 @@ <% end %> <% if @seminar.seminar_signup_field_customs.count != 0 %> <% @seminar.seminar_signup_field_customs.each do |field_set| %> - <% s = SeminarSignupField.where(id:field_set.seminar_signup_field_id).first %> - <% next if s.key.blank? %> + <% s = field_set.seminar_signup_field %> + <% next if (s.nil? || s.key.blank?) %> <% default_hidden << "seminar_signup_field_custom.#{s.key}" if (field_set.hidden) %> <% end %> <% end %> @@ -113,7 +113,8 @@ <% seminar_signup_field_customs = SeminarSignupFieldCustom.all.map{|field_set| SeminarSignupField.where(id: field_set.seminar_signup_field_id).first}.select{|s| !s.nil?}.uniq{|s| s.key } %> <% if seminar_signup_field_customs.count != 0 %> <% seminar_signup_field_customs.each do |s| %> - <% next if s.key.blank? %> + <% s = field_set.seminar_signup_field %> + <% next if (s.nil? || s.key.blank?) %> <% default_hidden << "seminar_signup_field_custom.#{s.key}" if (field_set.hidden) %> <% end %> <% end %> diff --git a/app/views/admin/seminars/export.xlsx.axlsx b/app/views/admin/seminars/export.xlsx.axlsx index 15b7269..cee1dd2 100644 --- a/app/views/admin/seminars/export.xlsx.axlsx +++ b/app/views/admin/seminars/export.xlsx.axlsx @@ -55,10 +55,10 @@ wb.add_worksheet(name: (@seminar.title.to_s[0..27]+'...')) do |sheet| @seminar.seminar_signup_fields.asc(:_id).each do |rf| if rf.can_muti_lang_input? @site_in_use_locales.each do |l| - row2 << nl2br(show_attribute_value(@seminar.get_attribute_value(rf,signup.id).get_value_by_locale(l))) rescue ' ' + row2 << (@seminar.get_attribute_value(rf,signup.id).get_value_by_locale(l) rescue '') end else - row2 << nl2br(show_attribute_value(@seminar.get_attribute_value(rf,signup.id).get_value_by_locale(I18n.locale))) rescue ' ' + row2 << (@seminar.get_attribute_value(rf,signup.id).get_value_by_locale(I18n.locale) rescue '') end end types = (0...row2.count).map{|i| types[i]} From eefb9f92f6a818924e79a01c2678d2763a599ae9 Mon Sep 17 00:00:00 2001 From: bohung Date: Fri, 4 Nov 2022 12:38:55 +0800 Subject: [PATCH 2/2] Add style to export xlsx file. --- app/views/admin/seminars/export.xlsx.axlsx | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/app/views/admin/seminars/export.xlsx.axlsx b/app/views/admin/seminars/export.xlsx.axlsx index cee1dd2..952357c 100644 --- a/app/views/admin/seminars/export.xlsx.axlsx +++ b/app/views/admin/seminars/export.xlsx.axlsx @@ -33,15 +33,20 @@ wb.add_worksheet(name: (@seminar.title.to_s[0..27]+'...')) do |sheet| row << rf.title end end - - sheet.add_row row - - @seminar_signups.each do |signup| - types = {} + highlight_style = wb.styles.add_style( + :bg_color => 'ffeb3b', + :b => true, + :border => { :style => :thick, :color => "000000", :edges => [:top, :left, :bottom, :right] }, + :alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true} + ) + sheet.add_row row, :style => (0...row.count).collect{ highlight_style } + date_time_style = wb.styles.add_style({:format_code => 'yyyy/mm/dd hh:mm', :alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}}) + wrap_text_style = wb.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}}) + types = [:time] + styles = [date_time_style] + @seminar_signups.each_with_index do |signup, i| row2 = [] - - row2 << "#{signup.created_at} " - types[1] = :string + row2 << signup.created_at row2 << "#{signup.display_serial_number}" row2 << "#{signup[:name]} " row2 << "#{signup.unit} " @@ -51,7 +56,6 @@ wb.add_worksheet(name: (@seminar.title.to_s[0..27]+'...')) do |sheet| row2 << "#{signup.address} " row2 << "#{signup[:email]} " row2 << "#{signup.note} " - @seminar.seminar_signup_fields.asc(:_id).each do |rf| if rf.can_muti_lang_input? @site_in_use_locales.each do |l| @@ -61,10 +65,14 @@ wb.add_worksheet(name: (@seminar.title.to_s[0..27]+'...')) do |sheet| row2 << (@seminar.get_attribute_value(rf,signup.id).get_value_by_locale(I18n.locale) rescue '') end end - types = (0...row2.count).map{|i| types[i]} - sheet.add_row row2 , :types => types + if i == 0 + (0...(row2.count - 1)).each do |i| + types << :string + styles << wrap_text_style + end + end + sheet.add_row row2 , :types => types, :style => styles end - end