Repository URL to install this package:
|
Version:
2.23.0 ▾
|
module JPlatform
class Ticket < ::PlatformResource
include PlatformConcern
include ActionView::Helpers::SanitizeHelper
schema do
string :social_account_id, :project_ticket_list_id, :social_message_id, :status, :status_cd, :resolution_id, :creator_id, :assignee_id, :priority, :is_hot, :comment, :tag_names, :due_on, :external_conversation, :default_social_account, :available_social_accounts, :social_message_origin_ids, :updated_at, :resolved_at, :processed_at, :first_assigned_at, :overdue
end
belongs_to :project_ticket_list, class_name: 'JPlatform::ProjectTicketList'
belongs_to :project, class_name: 'JPlatform::Project'
belongs_to :ticket_list, class_name: 'JPlatform::TicketList'
belongs_to :creator, class_name: 'JPlatform::User'
belongs_to :assignee, class_name: 'JPlatform::User'
belongs_to :resolution, class_name: 'JPlatform::Ticket::Resolution'
belongs_to :social_message, class_name: 'SocialMessage'
delegate :author_name, :type, to: :social_message, prefix: true, allow_nil: true
delegate :network, :message, to: :social_message, allow_nil: true
has_many :feed_items, class_name: 'JPlatform::Ticket::FeedItem'
has_many :activities, class_name: 'JPlatform::Ticket::Activity'
has_many :comments, class_name: 'JPlatform::Ticket::Comment'
validates :project_ticket_list_id, presence: true
validates :social_message_origin_ids, length: { maximum: 150 }
validates :resolution_id, presence: true, if: ->(ticket) { ticket.is_resolved? }
PRIORITIES = { low: 1, normal: 3, high: 5 }
STATUSES = { new: 1, in_progress: 5, resolved: 9 }
def self.statuses
dropdown_arr(STATUSES)
end
# For the edit dropdowns
def self.select_statuses
dropdown_arr(STATUSES.reject{ |s| s == :resolved})
end
def self.priorities
dropdown_arr(PRIORITIES)
end
def creator_full_name; attributes[:creator_full_name] || creator.try(:full_name) end
def assignee_full_name; attributes[:assignee_full_name] || assignee.try(:full_name) end
alias_method :customer_name, :social_message_author_name
def due_on
Date.parse(super) if super.present?
end
# Failsafes for priority / status returning nil
def priority
super || "normal"
end
def status
super || "new"
end
def to_s
strip_tags(message) if message
end
def default_reply_text
reply_text = ""
if "#{self.network}".downcase.include?('twitter')
reply_text = "#{self.try(:reply_to_author_name)} "
end
reply_text.gsub(/^\s*/, '')
end
# Workaround AR fetching nil
# Remove when https://github.com/rails/activeresource/pull/68 is merged
alias_method :_social_message, :social_message
def social_message
!!social_message_id ? _social_message: nil
end
alias_method :_assignee, :assignee
def assignee
!!assignee_id ? _assignee : nil
end
alias_method :_resolution, :resolution
def resolution
!!resolution_id ? _resolution : nil
end
STATUSES.each do |status, status_cd|
define_method "is_#{status}?" do
self.status_cd.to_i == status_cd
end
end
def high_priority?
self.priority.to_s.downcase == 'high'
end
def has_new_status?
self.processed_at.nil?
end
def is_assigned_to(user)
self.assignee_id == user.id
end
def is_assigned?
self.assignee_id.present?
end
def is_overdue?
self.due_on && !self.is_resolved? && Date.today > self.due_on
end
def to_partial_path; "j_platform/tickets/ticket" end
private
def self.dropdown_arr(input_hash)
input_hash.map { |p| [p.first.to_s.titleize, p.first.to_s] }
end
end
end