From c99354fc76b3affb3d439a8e77abe9b71576e610 Mon Sep 17 00:00:00 2001 From: BoHung Chiu Date: Wed, 12 Apr 2023 11:33:32 +0800 Subject: [PATCH] Fix bug and add sort number. --- .../seminar-field-forms-submission.js | 1 + app/assets/javascripts/seminar-field-forms.js | 1 + app/controllers/seminars_controller.rb | 8 ++--- app/helpers/admin/seminars_field_helper.rb | 30 +++++++--------- app/models/seminar_main.rb | 7 ++++ app/models/seminar_signup_field.rb | 4 ++- app/models/seminar_submission_field.rb | 4 ++- app/views/admin/seminar_signups/edit.html.erb | 2 +- .../admin/seminars/_attribute_field.html.erb | 5 +-- .../_attribute_submission_field.html.erb | 5 +-- .../seminars/_get_display_fields.html.erb | 8 ++--- app/views/admin/seminars/_node.html.erb | 2 +- .../seminars/_support_member_form_js.erb | 1 + app/views/admin/seminars/export.xlsx.axlsx | 6 ++-- .../seminars/seminar_signup_field.html.erb | 36 +++++++++++++++++-- .../seminar_submission_field.html.erb | 36 +++++++++++++++++-- app/views/seminars/_contribute_form.html.erb | 2 +- .../seminars/con_email_contents.html.erb | 2 +- app/views/seminars/show.html.erb | 4 +-- config/routes.rb | 2 ++ 20 files changed, 121 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/seminar-field-forms-submission.js b/app/assets/javascripts/seminar-field-forms-submission.js index 8259abf..15ff538 100644 --- a/app/assets/javascripts/seminar-field-forms-submission.js +++ b/app/assets/javascripts/seminar-field-forms-submission.js @@ -101,6 +101,7 @@ function setData(l, type, ol) { _add_more: ["add_more_" +l, fields+"["+l+"]["+type+"][add_more]"], _calendar: ["calendar_" +l, fields+"["+l+"]["+type+"][calendar]"], _cross_lang: ["cross_lang_" +l, fields+"["+l+"]["+type+"][cross_lang]"], + _sort_number: ["sort_number_" +l, fields+"["+l+"][sort_number]", l], _disabled: ["disabled_" +l, fields+"["+l+"][disabled]"], _format: ["format_" +l, fields+"["+l+"]["+type+"][format]"], _initial: ["initial_" +l, fields+"["+l+"]["+type+"][initial]"], diff --git a/app/assets/javascripts/seminar-field-forms.js b/app/assets/javascripts/seminar-field-forms.js index 8118423..3f4b401 100644 --- a/app/assets/javascripts/seminar-field-forms.js +++ b/app/assets/javascripts/seminar-field-forms.js @@ -101,6 +101,7 @@ function setData(l, type, ol) { _add_more: ["add_more_" +l, fields+"["+l+"]["+type+"][add_more]"], _calendar: ["calendar_" +l, fields+"["+l+"]["+type+"][calendar]"], _cross_lang: ["cross_lang_" +l, fields+"["+l+"]["+type+"][cross_lang]"], + _sort_number: ["sort_number_" +l, fields+"["+l+"][sort_number]", l], _disabled: ["disabled_" +l, fields+"["+l+"][disabled]"], _format: ["format_" +l, fields+"["+l+"]["+type+"][format]"], _initial: ["initial_" +l, fields+"["+l+"]["+type+"][initial]"], diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index 7d2ca1e..8a9f5a3 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -26,8 +26,8 @@ class SeminarsController < ApplicationController seminars = seminars.map do |seminar| link_url = OrbitHelper.url_to_plugin_show(seminar.to_param, 'seminar') registration_is_open = seminar.registration_status.present? - sign_up_not_yet = seminar.signup_start_date && @time_now && @seminar.signup_start_date > @time_now - sign_up_overdue = seminar.signup_end_date && @time_now && (@seminar.signup_end_date + 1.day <= @time_now) + sign_up_not_yet = seminar.signup_start_date && time_now && seminar.signup_start_date > time_now + sign_up_overdue = seminar.signup_end_date && time_now && (seminar.signup_end_date + 1.day <= time_now) signup_is_full = seminar.signup_is_full? seminar_url = (@custom_slug ? OrbitHelper.url_to_show(@custom_slug) : OrbitHelper.url_to_show(seminar.to_param)) if !registration_is_open @@ -330,8 +330,8 @@ class SeminarsController < ApplicationController seminar = SeminarMain.find_by(uid: params[:uid]) registration_is_open = seminar.registration_status.present? - sign_up_not_yet = seminar.signup_start_date && @time_now && @seminar.signup_start_date > @time_now - sign_up_overdue = seminar.signup_end_date && @time_now && (@seminar.signup_end_date + 1.day <= @time_now) + sign_up_not_yet = seminar.signup_start_date && time_now && seminar.signup_start_date > time_now + sign_up_overdue = seminar.signup_end_date && time_now && (seminar.signup_end_date + 1.day <= time_now) signup_is_full = seminar.signup_is_full? seminar_url = (@custom_slug ? OrbitHelper.url_to_show(@custom_slug) : OrbitHelper.url_to_show(seminar.to_param)) if !registration_is_open diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index d2cc36f..8e4f04e 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -10,13 +10,13 @@ module Admin::SeminarsFieldHelper include OrbitFormHelper - def block_helper(member,index,disable = false,attribute_type=nil,signup=nil, to_require=true) + def block_helper(seminar_main,index,disable = false,attribute_type=nil,signup=nil, to_require=true) unless self.disabled @index = index @require = to_require @markup_options = markup_options.merge(:disabled=>disable, :required => to_require) - @member = member - @attribute_value = @member.get_value_from_field_id(id,signup) + @seminar_main = seminar_main + @attribute_value = @seminar_main.get_value_from_field_id(id,signup) @attribute_type = attribute_type @new_attribute = @attribute_value.nil? @attribute_value = @attribute_value || signup.seminar_signup_values.build(seminar_signup_field_id: id) @@ -146,11 +146,11 @@ module Admin::SeminarsFieldHelper @prefiled_value ||=[] @prefiled_value = Array(@prefiled_value) control_group_wrapper_for_sm do - @member.summary_chioices.map.with_index do |value,key| + @seminar_main.summary_chioices.map.with_index do |value,key| key = key.to_s label_tag("#{get_basic_field_name_org}_#{self.id}_#{key}",radio_button_tag(get_field_name_base, key , ((@prefiled_value.include?(key) || @prefiled_value.include?(key.to_i)) ? true : false), {:required=>@require,:id=>"#{get_basic_field_name_org}_#{self.id}_#{key}"})+value,@markup_options.merge(:class=>"radio inline")) end.join.html_safe - end if @member.enable_summary_choice + end if @seminar_main.enable_summary_choice end def render_select prompt = @panel_setting["initial"][I18n.locale.to_s] rescue nil @@ -168,7 +168,7 @@ module Admin::SeminarsFieldHelper key = can_muti_lang_input_for_sm? ? "#{key}" : I18n.locale place_holder= typeD["placeholder"][key] rescue '' name1 = can_muti_lang_input_for_sm? ? (get_field_name_base + "[#{key}]") : get_field_name_base - text_area_tag(name1, value,@markup_options.merge(:placeholder=>place_holder,:class=>'ckeditor input-medium form-control')) + text_area_tag(name1, value, @markup_options.merge(:placeholder=>place_holder,:class=>'ckeditor input-medium form-control')) end end @@ -178,7 +178,7 @@ module Admin::SeminarsFieldHelper key_field = can_muti_lang_input_for_sm? ? "#{key}" : I18n.locale place_holder= typeA["placeholder"][key_field] rescue '' name1 = can_muti_lang_input_for_sm? ? ([get_field_name_base,add_more_blank,"[#{key_field}]"].join) : ([get_field_name_base,add_more_blank].join) - text_field_tag(name1, value,@markup_options.merge(:placeholder=>place_holder,:class=>'input-medium form-control')) + text_field_tag(name1, value, @markup_options.merge(:placeholder=>place_holder,:class=>'input-medium form-control')) end end @@ -302,15 +302,13 @@ protected def controls_wrapper_for_sm(*add_more_params,&block) - result = Array.new - add_more_counter = "" - - if can_add_more - add_more_counter = add_more_params[0][:counter] - add_more_value = add_more_params[0][:value] - end - + result = Array.new + add_more_counter = "" + if can_add_more + add_more_counter = add_more_params[0][:counter] + add_more_value = add_more_params[0][:value] + end if can_muti_lang_input_for_sm? result << lang_panel_tabbable_wrapper(add_more_params,&block) @@ -326,8 +324,6 @@ protected value = @prefiled_value result << yield(nil,value) end - - end if self.markup == "address" result diff --git a/app/models/seminar_main.rb b/app/models/seminar_main.rb index b77d129..afc4886 100644 --- a/app/models/seminar_main.rb +++ b/app/models/seminar_main.rb @@ -89,6 +89,13 @@ class SeminarMain if self.signup_limit_changed? self.sync_signup_count end + if !(self.new_record?) && self.title_changed? + name_hash = {} + self.title_translations.each do |l, t| + name_hash["name.#{l}"] = t + end + Page.where(:parent_page_id=>self.id).update_all(name_hash) + end module_app_key = "seminar" add_module_app_member_ids = [] remove_module_app_member_ids = [] diff --git a/app/models/seminar_signup_field.rb b/app/models/seminar_signup_field.rb index c0d87f3..4f5ee8d 100644 --- a/app/models/seminar_signup_field.rb +++ b/app/models/seminar_signup_field.rb @@ -6,10 +6,11 @@ class SeminarSignupField include ::Admin::SeminarsFieldHelper field :key, type: String + field :sort_number, type: Integer # field :af_count field :title, type: String, localize: true field :markup, default: "text_field" - field :option_list, type: Hash,default: {} + field :option_list, type: Hash, default: {} field :markup_options, type: Hash field :built_in, type: Boolean, default: false field :disabled, type: Boolean, default: false @@ -26,6 +27,7 @@ class SeminarSignupField belongs_to :seminar_main has_many :seminar_signup_values, autosave: true, dependent: :destroy accepts_nested_attributes_for :seminar_signup_values, :allow_destroy => true + index({seminar_main_id: 1, sort_number: 1, _id: 1, disabled: -1}, { unique: false, background: false }) before_save :check_option_list before_save do |record| record.instance_variable_set(:@key_changed, record.key_changed?) diff --git a/app/models/seminar_submission_field.rb b/app/models/seminar_submission_field.rb index c86a56c..ea48ff1 100644 --- a/app/models/seminar_submission_field.rb +++ b/app/models/seminar_submission_field.rb @@ -6,10 +6,11 @@ class SeminarSubmissionField include ::Admin::SeminarsFieldHelper field :key, type: String + field :sort_number, type: Integer # field :af_count field :title, type: String, localize: true field :markup, default: "text_field" - field :option_list, type: Hash,default: {} + field :option_list, type: Hash, default: {} field :markup_options, type: Hash field :built_in, type: Boolean, default: false field :disabled, type: Boolean, default: false @@ -26,6 +27,7 @@ class SeminarSubmissionField belongs_to :seminar_main has_many :seminar_submission_values, autosave: true, dependent: :destroy accepts_nested_attributes_for :seminar_submission_values, :allow_destroy => true + index({seminar_main_id: 1, sort_number: 1, _id: 1, disabled: -1}, { unique: false, background: false }) before_save :check_option_list before_save do |record| record.instance_variable_set(:@key_changed, record.key_changed?) diff --git a/app/views/admin/seminar_signups/edit.html.erb b/app/views/admin/seminar_signups/edit.html.erb index 93a2955..a1f1682 100644 --- a/app/views/admin/seminar_signups/edit.html.erb +++ b/app/views/admin/seminar_signups/edit.html.erb @@ -166,7 +166,7 @@ <% end %> <% @form_index = 0 %> - <% @seminar.seminar_signup_fields.asc(:_id).each do |rf| %> + <% @seminar.seminar_signup_fields.where(:disabled=>false).asc(:sort_number, :_id).each do |rf| %>
diff --git a/app/views/admin/seminars/_attribute_field.html.erb b/app/views/admin/seminars/_attribute_field.html.erb index 46df8ba..e4d0525 100644 --- a/app/views/admin/seminars/_attribute_field.html.erb +++ b/app/views/admin/seminars/_attribute_field.html.erb @@ -3,9 +3,10 @@ @af_counter = attribute_field_counter %>
+ <%= hidden_field "#{@field_name}[seminar_signup_fields_attributes][#{@af_counter}]", "sort_number", :value=> @af_counter, :class=>"sort_number" %>
-
- <%= hidden_field "#{@field_name}[seminar_signup_fields_attributes][#{@af_counter}]","disabled",:value=>attribute_field.disabled,:class=>"toggle-check", :data=>{:deploy=>"right"} %> +
+ <%= hidden_field "#{@field_name}[seminar_signup_fields_attributes][#{@af_counter}]", "disabled", :value=>attribute_field.disabled, :class=>"toggle-check", :data=>{:deploy=> "right"} %>
diff --git a/app/views/admin/seminars/_attribute_submission_field.html.erb b/app/views/admin/seminars/_attribute_submission_field.html.erb index 30a089d..12eadb1 100644 --- a/app/views/admin/seminars/_attribute_submission_field.html.erb +++ b/app/views/admin/seminars/_attribute_submission_field.html.erb @@ -3,9 +3,10 @@ @af_counter = attribute_submission_field_counter %>
+ <%= hidden_field "#{@field_name}[seminar_submission_fields_attributes][#{@af_counter}]", "sort_number", :value=> @af_counter, :class=>"sort_number" %>
-
- <%= hidden_field "#{@field_name}[seminar_submission_fields_attributes][#{@af_counter}]","disabled",:value=>attribute_submission_field.disabled,:class=>"toggle-check", :data=>{:deploy=>"right"} %> +
+ <%= hidden_field "#{@field_name}[seminar_submission_fields_attributes][#{@af_counter}]", "disabled", :value=>attribute_submission_field.disabled, :class=>"toggle-check", :data=>{:deploy=> "right"} %>
diff --git a/app/views/admin/seminars/_get_display_fields.html.erb b/app/views/admin/seminars/_get_display_fields.html.erb index 14e98f8..a6bf344 100644 --- a/app/views/admin/seminars/_get_display_fields.html.erb +++ b/app/views/admin/seminars/_get_display_fields.html.erb @@ -35,7 +35,7 @@ <% default_hidden << "seminar_signup_fields.#{s.key}" if (field_set.hidden) %> <% end %> <% end %> - <% @seminar.seminar_signup_fields.each do |s| %> + <% @seminar.seminar_signup_fields.where(:disabled=>false).asc(:sort_number, :_id).each do |s| %> <% next if s.title.blank? %> <% default_hidden << "seminar_signup_fields.#{s.key}" %> <% @field_names << "seminar_signup_fields.#{s.key}" %> @@ -63,7 +63,7 @@ <% default_hidden << "seminar_signup_contributes.description" if !show3 %> <% @field_names << 'seminar_signup_contributes.description' %> <% @field_name_translations << t('seminar_signup.description') %> - <% @seminar.seminar_submission_fields.each do |s| %> + <% @seminar.seminar_submission_fields.where(:disabled=>false).asc(:sort_number, :_id).each do |s| %> <% @field_names << "seminar_submission_fields.#{s.key}" %> <% if s.markup != "seminar_preferred_session" @field_name_translations << s.title @@ -111,7 +111,7 @@ <% @field_name_translations << t(th) %> <% end %> <% end %> - <% seminar_signup_fields = SeminarSignupField.where(:key.nin=>["", nil]).uniq{|s| s.key} %> + <% seminar_signup_fields = SeminarSignupField.where(:key.nin=>["", nil], :disabled=>false).asc(:seminar_main_id, :sort_number, :_id).uniq{|s| s.key} %> <% seminar_signup_field_customs = SeminarSignupFieldCustom.where(:seminar_signup_field_id.in=> seminar_signup_fields.map(&:id)).to_a %> <% if seminar_signup_field_customs.count != 0 %> <% seminar_signup_field_customs.each do |field_set| %> @@ -141,7 +141,7 @@ <% default_show << "seminar_signup_contributes.description" if show3 %> <% @field_names << 'seminar_signup_contributes.description' %> <% @field_name_translations << t('seminar_signup.description') %> - <% seminar_submission_fields = SeminarSubmissionField.where(:key.nin=>["", nil]).uniq{|s| s.key} %> + <% seminar_submission_fields = SeminarSubmissionField.where(:key.nin=>["", nil], :disabled=>false).asc(:seminar_main_id, :sort_number, :_id).uniq{|s| s.key} %> <% seminar_submission_fields.each do |s| %> <% next if s.title.blank? %> <% @field_names << "seminar_submission_fields.#{s.key}" %> diff --git a/app/views/admin/seminars/_node.html.erb b/app/views/admin/seminars/_node.html.erb index d07e507..c378347 100644 --- a/app/views/admin/seminars/_node.html.erb +++ b/app/views/admin/seminars/_node.html.erb @@ -27,7 +27,7 @@ <%= link_to content_tag(:i, nil, class: "icon-eye-open"), (link_url.split('/').last.include?("?") ? "#{link_url}&editmode=on" : "#{link_url}?editmode=on" ), class: "view-page open-slide tip", title: t("structure.view"), data: {title: node.name} if node.page_type.eql?('page') %> <%#= link_to content_tag(:i, nil, class: "icons-mobile"), (node.root? ? "/?editmode=on&mobile=1" : "/" + I18n.locale.to_s + node.url + "?editmode=on&mobile=1"), class: "view-page open-slide tip mobile-view-btn", title: "Edit Mobile Page", data: {title: "Edit Mobile Page"} if node.page_type.eql?("page") && current_site.mobile_on && node.enabled_for_mobile %> <% unless name.eql? "sitemap" %> - <%= link_to content_tag(:i, nil, class: "icon-edit"), edit_page_path(node.id,:type => node.page_type), class: "open-slide tip page edit", title: t("structure.edit_#{node.page_type}"), data: {title: t("structure.edit_#{node.page_type}")} if node.class.to_s.downcase.eql?("page") && !(node.root?) %> + <%= link_to content_tag(:i, nil, class: "icon-edit"), edit_page_path(node.id,:type => node.page_type), class: "open-slide tip page edit", title: t("structure.edit_#{node.page_type}"), data: {title: t("structure.edit_#{node.page_type}")} if node.class.to_s.downcase.eql?("page") %> <%= link_to content_tag(:i, nil, class: "icons-link"), new_page_path(:parent_page => node.id.to_s,:type => "link"), class: "open-slide tip link", title: t("structure.add_link"), data: {title: t("structure.add_link"), id: 'new', parent: node.id.to_s} if node.class.to_s.eql?('Page') && level < 3 %> <%= link_to content_tag(:i, nil, class: "icons-newspaper"), new_page_path(:parent_page => node.id.to_s,:type => "page"), class: "open-slide tip page", title: t("structure.add_page"), data: {title: t("structure.add_page"), id: 'new', parent: node.id.to_s} if node.class.to_s.eql?('Page') && level < 3 %> <%= link_to content_tag(:i, nil, class: "icons-retweet"), "/pages/#{node.id}/import_widgets",:method => :post, :remote => true, "data-confirm" => "This will override your current widgets and widget settings. Do you wish to continue?.", class: "import-widgets tip", title: t("structure.import_widgets"), data: {title: t("structure.import_widgets")} if level > 1 && node.page_type != "link" %> diff --git a/app/views/admin/seminars/_support_member_form_js.erb b/app/views/admin/seminars/_support_member_form_js.erb index 12dabb9..25aa036 100644 --- a/app/views/admin/seminars/_support_member_form_js.erb +++ b/app/views/admin/seminars/_support_member_form_js.erb @@ -3,6 +3,7 @@ \ No newline at end of file diff --git a/app/views/admin/seminars/seminar_submission_field.html.erb b/app/views/admin/seminars/seminar_submission_field.html.erb index 37b57d5..9e7a942 100644 --- a/app/views/admin/seminars/seminar_submission_field.html.erb +++ b/app/views/admin/seminars/seminar_submission_field.html.erb @@ -17,8 +17,8 @@

<%= @attribute.title %>

-
- <%= render partial: "attribute_submission_field",collection: @attribute.seminar_submission_fields.asc(:_id)%> +
+ <%= render partial: "attribute_submission_field",collection: @attribute.seminar_submission_fields.asc(:sort_number, :_id)%>
@@ -33,4 +33,34 @@ <% content_for :page_specific_javascript do -%> <%= render 'support_member_form_js' %> -<% end -%> \ No newline at end of file +<% end -%> + + \ No newline at end of file diff --git a/app/views/seminars/_contribute_form.html.erb b/app/views/seminars/_contribute_form.html.erb index b6e1f43..83294ce 100644 --- a/app/views/seminars/_contribute_form.html.erb +++ b/app/views/seminars/_contribute_form.html.erb @@ -83,7 +83,7 @@
<% end %> - <% @seminar.seminar_submission_fields.asc(:_id).each do |rf| %> + <% @seminar.seminar_submission_fields.where(:disabled=>false).asc(:sort_number, :_id).each do |rf| %>
<%= rf.block_helper(@seminar,@form_index,false,"seminar_signup_contribute",@con, rf.to_require,rf) %>
diff --git a/app/views/seminars/con_email_contents.html.erb b/app/views/seminars/con_email_contents.html.erb index f390905..e25f57d 100644 --- a/app/views/seminars/con_email_contents.html.erb +++ b/app/views/seminars/con_email_contents.html.erb @@ -18,7 +18,7 @@ end end end - seminar_submission_fields = @seminar.seminar_submission_fields.where(:disabled=>false) + seminar_submission_fields = @seminar.seminar_submission_fields.where(:disabled=>false).asc(:sort_number, :_id) %>

<%= @seminar.title rescue nil %>

diff --git a/app/views/seminars/show.html.erb b/app/views/seminars/show.html.erb index b77212b..87b6710 100644 --- a/app/views/seminars/show.html.erb +++ b/app/views/seminars/show.html.erb @@ -203,7 +203,7 @@ <% end %> - <% @seminar.seminar_signup_fields.asc(:_id).each do |rf| %> + <% @seminar.seminar_signup_fields.where(:disabled=>false).asc(:sort_number, :_id).each do |rf| %>
@@ -278,7 +278,7 @@ } <% - @seminar.seminar_signup_fields.asc(:_id).each do |rf| + @seminar.seminar_signup_fields.where(:disabled=>false).asc(:sort_number, :_id).each do |rf| if rf.markup == 'checkbox' %> diff --git a/config/routes.rb b/config/routes.rb index 576d277..75ef0b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,8 @@ Rails.application.routes.draw do end end end + SeminarSignupField.create_indexes + SeminarSubmissionField.create_indexes end locales = Site.first.in_use_locales rescue I18n.available_locales