2018-09-05 15:55:04 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
2018-10-07 01:53:31 +08:00
|
|
|
class TaskSerializer < ActiveModel::Serializer
|
2020-08-07 22:51:57 +08:00
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2018-09-07 17:58:02 +08:00
|
|
|
type :tasks
|
2020-08-20 21:49:48 +08:00
|
|
|
attributes :id, :name, :started_on, :due_date, :description, :state, :archived, :status_id, :status_name,
|
|
|
|
:prev_status_id, :prev_status_name, :next_status_id, :next_status_name
|
2018-11-28 18:33:00 +08:00
|
|
|
has_many :output_tasks, key: :outputs,
|
|
|
|
serializer: TaskSerializer,
|
|
|
|
class_name: 'MyModule'
|
|
|
|
has_many :input_tasks, key: :inputs,
|
|
|
|
serializer: TaskSerializer,
|
|
|
|
class_name: 'MyModule'
|
2021-08-18 16:00:01 +08:00
|
|
|
has_many :task_comments, key: :comments, serializer: CommentSerializer
|
|
|
|
|
|
|
|
include TimestampableModel
|
2018-11-28 18:33:00 +08:00
|
|
|
|
2020-08-20 21:49:48 +08:00
|
|
|
def status_id
|
|
|
|
object.my_module_status_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_name
|
|
|
|
object.my_module_status.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def prev_status_id
|
|
|
|
object.my_module_status.previous_status&.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def prev_status_name
|
|
|
|
object.my_module_status.previous_status&.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_status_id
|
|
|
|
object.my_module_status.next_status&.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_status_name
|
|
|
|
object.my_module_status.next_status&.name
|
|
|
|
end
|
|
|
|
|
2018-11-28 18:33:00 +08:00
|
|
|
def output_tasks
|
|
|
|
object.my_modules
|
|
|
|
end
|
|
|
|
|
|
|
|
def input_tasks
|
|
|
|
object.my_module_antecessors
|
|
|
|
end
|
2020-07-02 23:03:29 +08:00
|
|
|
|
|
|
|
def description
|
|
|
|
if instance_options[:rte_rendering]
|
2020-08-07 22:51:57 +08:00
|
|
|
custom_auto_link(object.tinymce_render(:description),
|
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: instance_options[:team])
|
2020-07-02 23:03:29 +08:00
|
|
|
else
|
|
|
|
object.description
|
|
|
|
end
|
|
|
|
end
|
2018-09-05 15:55:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|