2022-04-29 12:29:42 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ChecklistSerializer < ActiveModel::Serializer
|
2022-06-03 11:52:10 +02:00
|
|
|
include Canaid::Helpers::PermissionsHelper
|
2022-05-03 15:15:49 +02:00
|
|
|
include Rails.application.routes.url_helpers
|
2022-07-08 12:51:43 +02:00
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
2022-05-03 15:15:49 +02:00
|
|
|
|
2022-08-01 13:25:29 +02:00
|
|
|
attributes :id, :name, :urls, :icon, :sa_name, :checklist_items
|
2022-05-03 15:15:49 +02:00
|
|
|
|
2022-05-30 13:45:51 +02:00
|
|
|
def icon
|
|
|
|
'fa-list-ul'
|
|
|
|
end
|
|
|
|
|
2022-08-01 13:25:29 +02: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 12:51:43 +02: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 15:15:49 +02:00
|
|
|
def urls
|
2022-06-07 12:10:10 +02:00
|
|
|
return {} if object.destroyed? || !can_manage_step?(scope[:user] || @instance_options[:user], object.step)
|
2022-05-03 15:15:49 +02:00
|
|
|
|
|
|
|
{
|
2022-08-22 14:02:19 +02:00
|
|
|
duplicate_url: duplicate_step_checklist_path(object.step, object),
|
2022-05-05 12:56:31 +02:00
|
|
|
delete_url: step_checklist_path(object.step, object),
|
2022-05-11 15:51:26 +02:00
|
|
|
update_url: step_checklist_path(object.step, object),
|
2022-05-26 14:02:02 +02:00
|
|
|
reorder_url: reorder_step_checklist_checklist_items_path(object.step, object),
|
2022-05-11 15:51:26 +02:00
|
|
|
create_item_url: step_checklist_checklist_items_path(object.step, object)
|
2022-05-03 15:15:49 +02:00
|
|
|
}
|
|
|
|
end
|
2022-04-29 12:29:42 +02:00
|
|
|
end
|