From 18a591d1f22972a1da11994209690ca3673cd682 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Tue, 3 Sep 2024 23:58:34 +0800 Subject: [PATCH] Add ask_status_histories and add release comment, release file field. --- app/controllers/admin/asks_controller.rb | 15 +- app/models/ask_question.rb | 35 +++ app/models/ask_status_history.rb | 19 ++ app/models/ask_ticket_status.rb | 4 + app/views/admin/asks/_form.html.erb | 262 +++++++++++++++-------- app/views/admin/asks/email.html.erb | 8 + config/locales/en.yml | 4 + config/locales/zh_tw.yml | 4 + 8 files changed, 257 insertions(+), 94 deletions(-) create mode 100644 app/models/ask_status_history.rb diff --git a/app/controllers/admin/asks_controller.rb b/app/controllers/admin/asks_controller.rb index fd97887..b46da32 100644 --- a/app/controllers/admin/asks_controller.rb +++ b/app/controllers/admin/asks_controller.rb @@ -6,6 +6,9 @@ class Admin::AsksController < OrbitAdminController before_action :set_askquestion, only: [:edit, :destroy, :update, :print] layout :compute_layout helper_method :ask_thead + def show + @ask_status_histories = @ask_question.ask_status_histories.reverse + end def compute_layout if action_name=='print' false @@ -389,7 +392,7 @@ class Admin::AsksController < OrbitAdminController temp_params['custom_values'][to_save[0]] = [temp_params['custom_values'][to_save[0]].original_filename ,to_save[1].file.url] end end - temp_params = temp_params.merge({reviewer: current_user.member_profile, review_time: DateTime.now}) + temp_params = temp_params.merge({reviewer: current_user.member_profile, review_time: DateTime.now, user: current_user}) @ask_question.update_attributes(temp_params) if @ask_question.send_email? build_email(@ask_question) @@ -410,6 +413,12 @@ class Admin::AsksController < OrbitAdminController site = Site.first mail_from = site.title_translations[site['default_locale']] + new_history = email_er.new_history + host_url = Site.first.root_url rescue "http://" + if host_url == "http://" + host_url = request.protocol + request.host_with_port + end + email_er.email.update_attributes( :mail_lang=> site['default_locale'], :create_user=>current_user, @@ -419,7 +428,9 @@ class Admin::AsksController < OrbitAdminController :mail_subject=>mail_from+" #{t('ask.reply')}:", :template=>'admin/asks/email', :template_data=>{ - "reply" => email_er.reply + "host_url" => host_url, + "reply" => email_er.reply, + "attachment" => (new_history ? new_history.file.url : nil) } ) end diff --git a/app/models/ask_question.rb b/app/models/ask_question.rb index 54ef4bb..86c5c2f 100644 --- a/app/models/ask_question.rb +++ b/app/models/ask_question.rb @@ -30,11 +30,27 @@ class AskQuestion field :review_time, type: DateTime belongs_to :reviewer, class_name: "MemberProfile", foreign_key: :reviewer_id + has_many :ask_status_histories + + attr_accessor :release_comment, :release_file, :user before_create do last_serial_number = AskSetting.update_last_serial_number self.serial_number = last_serial_number end + + before_save :create_ask_status_history + + def release_comment=(v) + @changed = true + @release_comment = v + end + + def release_file=(v) + @changed = true + @release_file = v + end + def email mail = Email.where(:id=>self.email_id).first end @@ -79,5 +95,24 @@ class AskQuestion def send_email? self.send_email == 1 end + + def new_history + @new_history + end + + private + + def create_ask_status_history + if changed? || @changed + @new_history = AskStatusHistory.create( + ask_question: self, + status: self.situation, + comment: @release_comment, + file: @release_file, + user: @user + ) + else + @new_history = nil + end end end diff --git a/app/models/ask_status_history.rb b/app/models/ask_status_history.rb new file mode 100644 index 0000000..cc62ee4 --- /dev/null +++ b/app/models/ask_status_history.rb @@ -0,0 +1,19 @@ +class AskStatusHistory + include Mongoid::Document + include Mongoid::Timestamps + + field :status, type: String + field :comment, type: String + belongs_to :user + belongs_to :ask_question + + mount_uploader :file, AssetUploader + + def modified_by_name + if user.present? && user.member_profile.present? + user.member_profile.name + end + end +end + + diff --git a/app/models/ask_ticket_status.rb b/app/models/ask_ticket_status.rb index 6985389..29d317c 100644 --- a/app/models/ask_ticket_status.rb +++ b/app/models/ask_ticket_status.rb @@ -39,4 +39,8 @@ class AskTicketStatus end trans end + + def self.default_sorting + self.all.sort_by{|a| [a.is_default ? 0 : 1, DefaultKeys.index(a.key)] } + end end \ No newline at end of file diff --git a/app/views/admin/asks/_form.html.erb b/app/views/admin/asks/_form.html.erb index b019e4c..b1cf3e0 100644 --- a/app/views/admin/asks/_form.html.erb +++ b/app/views/admin/asks/_form.html.erb @@ -41,102 +41,180 @@ }) }) +
-
- - - - - - - - - - - - - - - - - - <% if ask_setting.default_setting['appointment'] %> - - - - - <% end %> - - - - - - - - - - - - - - - - - - - - -
<%= AskQuestion.human_attribute_name(:name) %>:<%= @ask_question.name %><%= AskQuestion.human_attribute_name(:mail) %>:<%= @ask_question.mail %><%= AskQuestion.human_attribute_name(:phone) %>:<%= @ask_question.phone %>
<%= t('ask.serial_number') %>:<%= @ask_question.get_serial_number %>
<%= t('ask.ip') %>:<%= @ask_question.ip %>
<%= t('title') %>:<%= @ask_question.title %>
<%= AskQuestion.human_attribute_name(:appointment) %>:<%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %>
- <%= f.label :reply %> -
<%= f.text_area :reply, rows: 10, style: 'width: 500px' %> -
- <%= f.label :comment %> -
<%= @ask_question.comment %>
<%= f.label :agree_show %><%= @ask_question.agree_show ? t('ask.yes') : t('ask.no') %> -
<%= f.label t('situation') %> - <%= f.select :situation, AskTicketStatus.all.map{|a| [a.title, a.key]} %> -
- <%= f.label :send_email, class: "control-label muted" %> - +
+
+
+
<%= AskQuestion.human_attribute_name(:name) %>:<%= @ask_question.name %>
+
<%= AskQuestion.human_attribute_name(:mail) %>:<%= @ask_question.mail %>
+
<%= AskQuestion.human_attribute_name(:phone) %>:<%= @ask_question.phone %>
+
+ <% ask_setting.custom_fields.each do |k,v| %> + <% + required_pattern = v['required']=='true' ? '*' : '' + %> +
+
- - - - - - - - - + <%= show_on_front(k,v,@ask_question,true) %>
-
- <%= ask_setting.custom_fields.collect do |k,v| - required_pattern = v['required']=='true' ? '*' : '' - "
- -
- #{show_on_front(k,v,@ask_question,true)} +
+ <% end %> + +
+
+ +
+ <%= @ask_question.get_serial_number %> +
+
+ +
+ +
+ <%= @ask_question.ip %> +
+
+ +
+ +
+ <%= @ask_question.title %> +
+
+ + <% if ask_setting.default_setting['appointment'] %> +
+ +
+ <%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") if @ask_question.appointment %>
-
" - end.join.html_safe %> +
+ <% end %> + + <% if !@ask_question.comment.blank? %> +
+ <%= f.label :comment, class: "control-label muted" %> +
+ <%= @ask_question.comment %> +
+
+ <% end %> +
+ <%= f.label :agree_show, class: "control-label muted" %> +
+ <%= @ask_question.agree_show ? t('ask.yes') : t('ask.no') %> +
+
+
+ <%= f.label t('situation'), class: "control-label muted" %> +
+ <%= f.select :situation, AskTicketStatus.default_sorting.map{|a| [a.title, a.key] } %> +
+
+
+ + <%= select_tags(f, @module_app) %> +
+
+ <%= f.label :send_email, class: "control-label muted" %> + +
+ + + + + + + + + +
+
+
+ <%= f.label :reply, class: "control-label muted" %> +
+ <%= f.text_area :reply, rows: 10, style: 'max-width: 500px; width: 100%;' %> +
+
+
+ +
+ <%= f.text_area :release_comment, :id => "#{f.object_name}_comment" %> +
+
+
+ +
+ <%= f.file_field :release_file %> +
+
+
+
+
+ +
+

<%= t('history_records') %>

+ <% if f.object.ask_status_histories.present? %> + <% status_mapping = AskTicketStatus.default_sorting.map{|a| [a.key, a.title]}.to_h %> + + + + + + + + + + + + <% f.object.ask_status_histories.each do |ask_status_history| %> + + + + + + + + <% end %> + +
<%= t('status') %><%= t('ask.modified_by') %><%= t('ask.remark') %><%= t('ask.attachment') %><%= t('ask.updated_at') %>
+ <%= status_mapping[ask_status_history.status] %> + + <%= ask_status_history.modified_by_name %> + + <%= ask_status_history.comment %> + + <%= link_to(ask_status_history[:file], ask_status_history.file.url) if ask_status_history.file.present? %> + + <%= ask_status_history.created_at.strftime("%Y-%m-%d %H:%M:%S") %> +
+ <% else %> +

<%= t('no_history_records') %>

+ <% end %> +
+
<% diff --git a/app/views/admin/asks/email.html.erb b/app/views/admin/asks/email.html.erb index 787578a..1aa2a47 100644 --- a/app/views/admin/asks/email.html.erb +++ b/app/views/admin/asks/email.html.erb @@ -7,6 +7,14 @@

<%= @data['reply'].to_s.gsub(/[(\n)(\r)]/, "\n" => "
", "\r" => "" ).html_safe %>

+ <% attachment = @data['attachment'] + if attachment.present? %> + <% filename = File.basename(attachment) %> +

+ <%= t('ask.attachment') %>: + <%= filename %> +

+ <% end %>

<%= t('ask.email_automation_hint') %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index ed18bf8..cbfc95e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -133,6 +133,10 @@ en: new_question: New question verify_success: "Verify Successfully!" this_link_has_expired: "This Link has been clicked and expired!" + modified_by: Modified by + remark: Remark + attachment: Attachment + updated_at: Updated at mongoid: attributes: diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 1b17c53..c6c8bcd 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -143,6 +143,10 @@ zh_tw: new_question: 新的發問 verify_success: "驗證成功" this_link_has_expired: "此連結已經點選並已失效!" + modified_by: 修改者 + remark: 備註 + attachment: 附件 + updated_at: 更新時間 mongoid: attributes: