2022-05-11 21:51:26 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ChecklistItemSerializer < ActiveModel::Serializer
|
2022-06-03 17:52:10 +08:00
|
|
|
include Canaid::Helpers::PermissionsHelper
|
2022-05-11 21:51:26 +08:00
|
|
|
include Rails.application.routes.url_helpers
|
2022-07-08 18:51:43 +08:00
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
2022-05-11 21:51:26 +08:00
|
|
|
|
2022-07-08 18:51:43 +08:00
|
|
|
attributes :id, :text, :checked, :position, :urls, :sa_text
|
|
|
|
|
|
|
|
def sa_text
|
|
|
|
@user = scope[:user] || @instance_options[:user]
|
|
|
|
custom_auto_link(object.text,
|
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: object.checklist.step.protocol.team)
|
|
|
|
end
|
2022-05-11 21:51:26 +08:00
|
|
|
|
|
|
|
def urls
|
2022-07-14 21:09:28 +08:00
|
|
|
urls_list = {}
|
|
|
|
return urls_list if object.destroyed? || !object.persisted?
|
|
|
|
|
|
|
|
step = object.checklist.step
|
|
|
|
my_module = object.checklist.step.protocol.my_module
|
|
|
|
|
2022-07-20 16:14:48 +08:00
|
|
|
if can_manage_step?(scope[:user] || @instance_options[:user], step)
|
|
|
|
urls_list[:update_url] = step_checklist_checklist_item_path(step, object.checklist, object)
|
|
|
|
urls_list[:delete_url] = step_checklist_checklist_item_path(step, object.checklist, object)
|
|
|
|
end
|
|
|
|
|
|
|
|
return urls_list unless my_module
|
|
|
|
|
2022-07-14 21:09:28 +08:00
|
|
|
if !object.checked && can_check_my_module_steps?(scope[:user] || @instance_options[:user], my_module) ||
|
|
|
|
object.checked && can_uncheck_my_module_steps?(scope[:user] || @instance_options[:user], my_module)
|
|
|
|
urls_list[:toggle_url] =
|
|
|
|
toggle_step_checklist_checklist_item_path(step, object.checklist, object)
|
|
|
|
end
|
|
|
|
|
|
|
|
urls_list
|
2022-05-11 21:51:26 +08:00
|
|
|
end
|
|
|
|
end
|