Add ask_status_histories and add release comment, release file field.

This commit is contained in:
rulingcom 2024-09-03 23:58:34 +08:00
parent d2edc29945
commit 18a591d1f2
8 changed files with 257 additions and 94 deletions

View File

@ -6,6 +6,9 @@ class Admin::AsksController < OrbitAdminController
before_action :set_askquestion, only: [:edit, :destroy, :update, :print] before_action :set_askquestion, only: [:edit, :destroy, :update, :print]
layout :compute_layout layout :compute_layout
helper_method :ask_thead helper_method :ask_thead
def show
@ask_status_histories = @ask_question.ask_status_histories.reverse
end
def compute_layout def compute_layout
if action_name=='print' if action_name=='print'
false 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] temp_params['custom_values'][to_save[0]] = [temp_params['custom_values'][to_save[0]].original_filename ,to_save[1].file.url]
end end
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) @ask_question.update_attributes(temp_params)
if @ask_question.send_email? if @ask_question.send_email?
build_email(@ask_question) build_email(@ask_question)
@ -410,6 +413,12 @@ class Admin::AsksController < OrbitAdminController
site = Site.first site = Site.first
mail_from = site.title_translations[site['default_locale']] 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( email_er.email.update_attributes(
:mail_lang=> site['default_locale'], :mail_lang=> site['default_locale'],
:create_user=>current_user, :create_user=>current_user,
@ -419,7 +428,9 @@ class Admin::AsksController < OrbitAdminController
:mail_subject=>mail_from+" #{t('ask.reply')}", :mail_subject=>mail_from+" #{t('ask.reply')}",
:template=>'admin/asks/email', :template=>'admin/asks/email',
:template_data=>{ :template_data=>{
"reply" => email_er.reply "host_url" => host_url,
"reply" => email_er.reply,
"attachment" => (new_history ? new_history.file.url : nil)
} }
) )
end end

View File

@ -30,11 +30,27 @@ class AskQuestion
field :review_time, type: DateTime 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
has_many :ask_status_histories
attr_accessor :release_comment, :release_file, :user
before_create do before_create do
last_serial_number = AskSetting.update_last_serial_number last_serial_number = AskSetting.update_last_serial_number
self.serial_number = last_serial_number self.serial_number = last_serial_number
end 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 def email
mail = Email.where(:id=>self.email_id).first mail = Email.where(:id=>self.email_id).first
end end
@ -79,5 +95,24 @@ class AskQuestion
def send_email? def send_email?
self.send_email == 1 self.send_email == 1
end 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
end end

View File

@ -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

View File

@ -39,4 +39,8 @@ class AskTicketStatus
end end
trans trans
end end
def self.default_sorting
self.all.sort_by{|a| [a.is_default ? 0 : 1, DefaultKeys.index(a.key)] }
end
end end

View File

@ -41,102 +41,180 @@
}) })
}) })
</script> </script>
<div class="input-area"> <div class="input-area">
<div id="ask-asks"> <div class="row-fluid">
<table class="table"> <div id="ask-asks" class="span8">
<tr> <div class="row-fluid">
<td><%= AskQuestion.human_attribute_name(:name) %><%= @ask_question.name %></td> <div class="span4"><%= AskQuestion.human_attribute_name(:name) %><%= @ask_question.name %></div>
<!-- <td><%# AskQuestion.human_attribute_name(:identity) %> <div class="span4"><%= AskQuestion.human_attribute_name(:mail) %><%= @ask_question.mail %></div>
<%# Tag.where({:id => @ask_question[:identity]}).each do |tag| %> <div class="span4"><%= AskQuestion.human_attribute_name(:phone) %><%= @ask_question.phone %></div>
<%# tag.name %> </div>
<%# end %> <% ask_setting.custom_fields.each do |k,v| %>
</td> --> <%
<td><%= AskQuestion.human_attribute_name(:mail) %><%= @ask_question.mail %></td> required_pattern = v['required']=='true' ? '*' : ''
<td><%= AskQuestion.human_attribute_name(:phone) %><%= @ask_question.phone %></td> %>
<!-- <td><%# AskQuestion.human_attribute_name(:fax) %><%# @ask_question.fax %></td> --> <div class="control-group">
</tr> <label class="control-label">
<tr> <%= required_pattern %>
<td colspan="5"><%= t('ask.serial_number') %><%= @ask_question.get_serial_number %></td> <%= v['field'][I18n.locale] %>
</tr> </label>
<tr>
<td colspan="5"><%= t('ask.ip') %><%= @ask_question.ip %></td>
</tr>
<tr>
<td colspan="5"><%= t('title') %><%= @ask_question.title %></td>
</tr>
<% if ask_setting.default_setting['appointment'] %>
<tr>
<td colspan="5"><%= AskQuestion.human_attribute_name(:appointment) %><%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
<!-- <td colspan="5"><%# AskQuestion.human_attribute_name(:name) %><%# @ask_question.name %></td> -->
</tr>
<% end %>
<tr>
<!-- <td colspan="5"><%# AskQuestion.human_attribute_name(:name) %><br/><%# @ask_question.name.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %></td> -->
</tr>
<tr>
<td colspan="5">
<%= f.label :reply %>
<br/> <%= f.text_area :reply, rows: 10, style: 'width: 500px' %>
</td>
</tr>
<tr>
<td colspan="5">
<%= f.label :comment %>
<br/> <%= @ask_question.comment %></td>
</tr>
<tr>
<td colspan="5"><%= f.label :agree_show %><%= @ask_question.agree_show ? t('ask.yes') : t('ask.no') %>
</td>
</tr>
<tr>
<td colspan="5"><%= f.label t('situation') %>
<%= f.select :situation, AskTicketStatus.all.map{|a| [a.title, a.key]} %>
</td>
</tr>
<tr>
<td colspan="5">
<%= f.label :send_email, class: "control-label muted" %>
<div class="controls"> <div class="controls">
<label class="radio inline"> <%= show_on_front(k,v,@ask_question,true) %>
<%= f.radio_button :send_email, 1 %>
<%= t('ask.system_Email') %>
</label>
<label class="radio inline">
<%= f.radio_button :send_email, 0 %>
<%= t('ask.no') %>
</label>
<label class="radio inline">
<%= f.radio_button :send_email, 2 %>
<%= t('ask.phone') %>
</label>
<label class="radio inline">
<%= f.radio_button :send_email, 3 %>
<%= t('ask.fax') %>
</label>
<label class="radio inline">
<%= f.radio_button :send_email, 4 %>
<%= t('ask.paper') %>
</label>
</div> </div>
</td> </div>
</tr> <% end %>
</table>
<%= ask_setting.custom_fields.collect do |k,v| <div>
required_pattern = v['required']=='true' ? '*' : '' <div class="control-group">
"<div class=\"control-group\"> <label class="control-label muted"><%= t('ask.serial_number') %></label>
<label class=\"control-label\">#{required_pattern}#{v['field'][I18n.locale]}</label> <div class="controls">
<div class=\"controls\"> <%= @ask_question.get_serial_number %>
#{show_on_front(k,v,@ask_question,true)} </div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('ask.ip') %></label>
<div class="controls">
<%= @ask_question.ip %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('title') %></label>
<div class="controls">
<%= @ask_question.title %>
</div>
</div>
<% if ask_setting.default_setting['appointment'] %>
<div class="control-group">
<label class="control-label muted">
<%= AskQuestion.human_attribute_name(:appointment) %>
</label>
<div class="controls">
<%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") if @ask_question.appointment %>
</div> </div>
</div>" </div>
end.join.html_safe %> <% end %>
<% if !@ask_question.comment.blank? %>
<div class="control-group">
<%= f.label :comment, class: "control-label muted" %>
<div class="controls">
<%= @ask_question.comment %>
</div>
</div>
<% end %>
<div class="control-group">
<%= f.label :agree_show, class: "control-label muted" %>
<div class="controls">
<%= @ask_question.agree_show ? t('ask.yes') : t('ask.no') %>
</div>
</div>
<div>
<%= f.label t('situation'), class: "control-label muted" %>
<div class="controls">
<%= f.select :situation, AskTicketStatus.default_sorting.map{|a| [a.title, a.key] } %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t(:tags) %></label>
<%= select_tags(f, @module_app) %>
</div>
<div class="control-group">
<%= f.label :send_email, class: "control-label muted" %>
<div class="controls">
<label class="radio inline">
<%= f.radio_button :send_email, 1 %>
<%= t('ask.system_Email') %>
</label>
<label class="radio inline">
<%= f.radio_button :send_email, 0 %>
<%= t('ask.no') %>
</label>
<label class="radio inline">
<%= f.radio_button :send_email, 2 %>
<%= t('ask.phone') %>
</label>
<label class="radio inline">
<%= f.radio_button :send_email, 3 %>
<%= t('ask.fax') %>
</label>
<label class="radio inline">
<%= f.radio_button :send_email, 4 %>
<%= t('ask.paper') %>
</label>
</div>
</div>
<div class="control-group">
<%= f.label :reply, class: "control-label muted" %>
<div class="controls">
<%= f.text_area :reply, rows: 10, style: 'max-width: 500px; width: 100%;' %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= f.label :comment %></label>
<div class="controls">
<%= f.text_area :release_comment, :id => "#{f.object_name}_comment" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t(:file_) %></label>
<div class="controls">
<%= f.file_field :release_file %>
</div>
</div>
</div>
</div>
<div class="span4">
<!-- 顯示歷史紀錄 -->
<div class="history-records">
<h3><%= t('history_records') %></h3>
<% if f.object.ask_status_histories.present? %>
<% status_mapping = AskTicketStatus.default_sorting.map{|a| [a.key, a.title]}.to_h %>
<table class="table">
<thead>
<tr>
<th><%= t('status') %></th>
<th><%= t('ask.modified_by') %></th>
<th><%= t('ask.remark') %></th>
<th><%= t('ask.attachment') %></th>
<th><%= t('ask.updated_at') %></th>
</tr>
</thead>
<tbody>
<% f.object.ask_status_histories.each do |ask_status_history| %>
<tr>
<td>
<%= status_mapping[ask_status_history.status] %>
</td>
<td>
<%= ask_status_history.modified_by_name %>
</td>
<td>
<%= ask_status_history.comment %>
</td>
<td>
<%= link_to(ask_status_history[:file], ask_status_history.file.url) if ask_status_history.file.present? %>
</td>
<td>
<%= ask_status_history.created_at.strftime("%Y-%m-%d %H:%M:%S") %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p><%= t('no_history_records') %></p>
<% end %>
</div>
</div>
</div> </div>
</div> </div>
<% <%

View File

@ -7,6 +7,14 @@
<p> <p>
<%= @data['reply'].to_s.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %> <%= @data['reply'].to_s.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %>
</p> </p>
<% attachment = @data['attachment']
if attachment.present? %>
<% filename = File.basename(attachment) %>
<p>
<%= t('ask.attachment') %>:
<a title="<%= filename %>" target="_blank" href="<%= @data['host_url'] + attachment %>"><%= filename %></a>
</p>
<% end %>
<br /> <br />
<p><%= t('ask.email_automation_hint') %></p> <p><%= t('ask.email_automation_hint') %></p>
</body> </body>

View File

@ -133,6 +133,10 @@ en:
new_question: New question new_question: New question
verify_success: "Verify Successfully!" verify_success: "Verify Successfully!"
this_link_has_expired: "This Link has been clicked and expired!" this_link_has_expired: "This Link has been clicked and expired!"
modified_by: Modified by
remark: Remark
attachment: Attachment
updated_at: Updated at
mongoid: mongoid:
attributes: attributes:

View File

@ -143,6 +143,10 @@ zh_tw:
new_question: 新的發問 new_question: 新的發問
verify_success: "驗證成功" verify_success: "驗證成功"
this_link_has_expired: "此連結已經點選並已失效!" this_link_has_expired: "此連結已經點選並已失效!"
modified_by: 修改者
remark: 備註
attachment: 附件
updated_at: 更新時間
mongoid: mongoid:
attributes: attributes: