Refine code

This commit is contained in:
rulingcom 2024-09-03 23:51:23 +08:00
parent ee69221b8f
commit a4db1fcd2f
6 changed files with 32 additions and 27 deletions

View File

@ -361,9 +361,9 @@ class AsksController < ApplicationController
email_er.email_id = email.id
email_er.save
@group_mail = email_er.mail
@manager_emails = email_er.reviewer_emails
@mail_sentdate = DateTime.now
group_mail = email_er.mail
manager_emails = email_er.reviewer_emails
mail_sentdate = DateTime.now
site = current_site rescue Site.first
mail_from = site.title_translations[site.default_locale]
@ -375,9 +375,9 @@ class AsksController < ApplicationController
email_er.email.update_attributes(
:mail_lang=> site.default_locale,
:create_user=>(current_user rescue nil),
:mail_sentdate=>@mail_sentdate,
:mail_sentdate=>mail_sentdate,
:module_app=>@module_app,
:mail_to=>@group_mail,
:mail_to=>group_mail,
:mail_subject=>mail_subject,
:template=>'asks/email',
:template_data=>{
@ -394,16 +394,16 @@ class AsksController < ApplicationController
"site_host" => host_url,
"usage_rule" => @usage_rule
},
:mail_reply_to => (@manager_emails.empty? ? nil : @manager_emails)
:mail_reply_to => (manager_emails.empty? ? nil : manager_emails)
)
if !@manager_emails.empty?
if !manager_emails.empty?
Email.new(
:mail_lang=> site.default_locale,
:create_user=>(current_user rescue nil),
:mail_sentdate=>@mail_sentdate,
:mail_sentdate=>mail_sentdate,
:module_app=>@module_app,
:mail_to=>@manager_emails,
:mail_subject=>mail_subject+" #{@group_mail}",
:mail_to=>manager_emails,
:mail_subject=>mail_subject+" #{group_mail}",
:template=>'asks/email',
:template_data=>{
# "title" => email_er.title,

View File

@ -155,15 +155,18 @@ class AskCategorySetting
field :default_setting_required, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: false,appointment: false,recaptcha: true,agree_show: false,agree_usage: true}
field :default_setting_field_name, type: Hash,default: {}
field :default_setting_prompt_word, type: Hash,default: {}
field :use_default, type: Boolean, default: false
field :custom_fields, type: Hash,default: {}
field :usage_rule, type: String, default: ''
field :category_id, type: String
field :title_layout, type: Integer, default: 0
field :need_check_customs, type: Array, default: [] #From AskSetting
field :reject_customs, type: Array, default: [] #From AskSetting
field :agree_customs, type: Array, default: [] #From AskSetting
field :category_id, type: String
field :use_default, type: Boolean, default: false
scope :enabled, ->{any_of([{:use_default.ne=>true}, {:use_default=>true, :default_sort_number.nin=>[nil, {}]}])}
scope :custom_enabled, ->{where({:use_default.ne=>true})}
end

View File

@ -5,7 +5,7 @@ class AskQuestion
include OrbitCategory::Categorizable
# include OrbitTag::Taggable
# 欄位
# 欄位定義
field :serial_number, type: Integer
field :ip, type: String
field :name, type: String
@ -29,9 +29,8 @@ class AskQuestion
field :agree_usage, type: Boolean, default: false
field :review_time, type: DateTime
belongs_to :reviewer , :class_name=>"MemberProfile", :foreign_key => :reviewer_id
belongs_to :reviewer, class_name: "MemberProfile", foreign_key: :reviewer_id
# validates_presence_of :name, :identity, :mail, :title, :content
before_create do
last_serial_number = AskSetting.update_last_serial_number
self.serial_number = last_serial_number
@ -43,9 +42,10 @@ class AskQuestion
def verify_email
verify_email = Email.where(:id=>self.verify_email_id).first
end
def reviewer_emails
email_address = AskAdmin.or(:category_ids.in => [self.category_id, [], nil]).pluck(:email).select { |s| s.present? }.uniq rescue []
authorizes = Authorization.where(:module_app_id=>ModuleApp.where(:key=>'ask').first.id).to_a rescue []
authorizes = Authorization.where(module_app_id: ModuleApp.where(key: 'ask').first.id).to_a rescue []
authorizes.each do |a|
if a.category_id
next if a.category_id != self.category_id
@ -54,7 +54,7 @@ class AskQuestion
u = a.user
email_address << u.email if u && u.email
elsif a.role_id
email_address = email_address + MemberProfile.where(:role_ids=>a.role_id).pluck(:email).select{|s| s.present?}.uniq
email_address = email_address + MemberProfile.where(role_ids: a.role_id).pluck(:email).select { |s| s.present? }.uniq
else
a.destroy
end
@ -62,6 +62,7 @@ class AskQuestion
email_address = email_address.flatten
email_address.uniq
end
def get_serial_number(last_serial_number=nil, display_length=nil)
if display_length.nil? && last_serial_number.nil?
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
@ -70,7 +71,9 @@ class AskQuestion
display_length = [last_serial_number.to_s.length + 1, 4].max if display_length.nil?
display_format_string(self.serial_number, display_length)
end
def display_format_string(num, str_length)
return format("%0#{str_length}d", num)
format("%0#{str_length}d", num)
end
end
end

View File

@ -182,7 +182,6 @@
situation_class_relation = {
"is_waiting"=>"label-important",
"is_processed"=>"label-warning",
"is_referral"=>"",
"is_published"=>"label-success"
}
situation_trans = AskTicketStatus.all.map{|a| [a.key, a.title]}.to_h
@ -203,7 +202,7 @@
<% when 'serial_number' %>
<%= b.get_serial_number(last_serial_number, display_length) %>
<% when 'situation' %>
<span class='label <%=situation_class_relation[b.situation]%>'><%= situation_trans[b.situation] %></span>
<span class='label <%= situation_class_relation[b.situation].to_s %>'><%= situation_trans[b.situation] %></span>
<% when 'ask_category_id' %>
<%= b.category.title rescue 'category not set' %>
<% when 'sex' %>

View File

@ -8,6 +8,6 @@
<%= @data['reply'].to_s.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %>
</p>
<br />
<p>此為系統自動發信,請勿直接回覆</p>
<p><%= t('ask.email_automation_hint') %></p>
</body>
</html>