2022-04-29 18:29:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ChecklistSerializer < ActiveModel::Serializer
|
2022-06-03 17:52:10 +08:00
|
|
|
include Canaid::Helpers::PermissionsHelper
|
2022-05-03 21:15:49 +08:00
|
|
|
include Rails.application.routes.url_helpers
|
2022-07-08 18:51:43 +08:00
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
2022-05-03 21:15:49 +08:00
|
|
|
|
2022-07-08 18:51:43 +08:00
|
|
|
attributes :id, :name, :urls, :icon, :sa_name
|
2022-05-11 21:51:26 +08:00
|
|
|
has_many :checklist_items, serializer: ChecklistItemSerializer
|
2022-05-03 21:15:49 +08:00
|
|
|
|
2022-05-30 19:45:51 +08:00
|
|
|
def icon
|
|
|
|
'fa-list-ul'
|
|
|
|
end
|
|
|
|
|
2022-07-08 18:51:43 +08:00
|
|
|
def sa_name
|
|
|
|
@user = scope[:user] || @instance_options[:user]
|
|
|
|
custom_auto_link(object.name,
|
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: object.step.protocol.team)
|
|
|
|
end
|
|
|
|
|
2022-05-03 21:15:49 +08:00
|
|
|
def urls
|
2022-06-07 18:10:10 +08:00
|
|
|
return {} if object.destroyed? || !can_manage_step?(scope[:user] || @instance_options[:user], object.step)
|
2022-05-03 21:15:49 +08:00
|
|
|
|
|
|
|
{
|
2022-05-05 18:56:31 +08:00
|
|
|
delete_url: step_checklist_path(object.step, object),
|
2022-05-11 21:51:26 +08:00
|
|
|
update_url: step_checklist_path(object.step, object),
|
2022-05-26 20:02:02 +08:00
|
|
|
reorder_url: reorder_step_checklist_checklist_items_path(object.step, object),
|
2022-05-11 21:51:26 +08:00
|
|
|
create_item_url: step_checklist_checklist_items_path(object.step, object)
|
2022-05-03 21:15:49 +08:00
|
|
|
}
|
|
|
|
end
|
2022-04-29 18:29:42 +08:00
|
|
|
end
|