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
|
|
|
|
2023-08-21 15:22:56 +08:00
|
|
|
attributes :id, :name, :urls, :icon, :sa_name, :checklist_items, :parent_type
|
2022-05-03 21:15:49 +08:00
|
|
|
|
2022-05-30 19:45:51 +08:00
|
|
|
def icon
|
|
|
|
'fa-list-ul'
|
|
|
|
end
|
|
|
|
|
2023-08-21 15:22:56 +08:00
|
|
|
def parent_type
|
|
|
|
:step
|
|
|
|
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
|
2023-10-06 19:50:23 +08:00
|
|
|
if object.destroyed? || !can_manage_step?(scope[:user] || @instance_options[:user], object.step)
|
|
|
|
return { checklist_items_url: step_checklist_checklist_items_path(object.step, object) }
|
|
|
|
end
|
2022-05-03 21:15:49 +08:00
|
|
|
|
|
|
|
{
|
2023-09-22 01:24:58 +08:00
|
|
|
checklist_items_url: step_checklist_checklist_items_path(object.step, object),
|
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),
|
2023-08-21 15:22:56 +08:00
|
|
|
create_item_url: step_checklist_checklist_items_path(object.step, object),
|
|
|
|
move_targets_url: move_targets_step_checklist_path(object.step, object),
|
|
|
|
move_url: move_step_checklist_path(object.step, object)
|
2022-05-03 21:15:49 +08:00
|
|
|
}
|
|
|
|
end
|
2022-04-29 18:29:42 +08:00
|
|
|
end
|