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-08-01 19:25:29 +08:00
|
|
|
attributes :id, :name, :urls, :icon, :sa_name, :checklist_items
|
2022-05-03 21:15:49 +08:00
|
|
|
|
2022-05-30 19:45:51 +08:00
|
|
|
def icon
|
|
|
|
'fa-list-ul'
|
|
|
|
end
|
|
|
|
|
2022-08-01 19:25:29 +08:00
|
|
|
def checklist_items
|
|
|
|
object.checklist_items.map do |item|
|
|
|
|
ChecklistItemSerializer.new(item, scope: { user: scope[:user] || @instance_options[:user] }).as_json
|
|
|
|
end
|
|
|
|
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-08-22 20:02:19 +08:00
|
|
|
duplicate_url: duplicate_step_checklist_path(object.step, object),
|
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
|