2022-05-06 17:59:22 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class TableSerializer < ActiveModel::Serializer
|
2022-06-03 17:52:10 +08:00
|
|
|
include Canaid::Helpers::PermissionsHelper
|
2022-05-06 17:59:22 +08:00
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
2023-08-21 15:22:56 +08:00
|
|
|
attributes :name, :contents, :urls, :icon, :metadata, :parent_type
|
2022-05-06 17:59:22 +08:00
|
|
|
|
|
|
|
def contents
|
|
|
|
object.contents_utf_8
|
|
|
|
end
|
|
|
|
|
2022-05-30 19:45:51 +08:00
|
|
|
def icon
|
|
|
|
'fa-table'
|
|
|
|
end
|
|
|
|
|
2023-08-21 15:22:56 +08:00
|
|
|
def parent_type
|
|
|
|
:step
|
|
|
|
end
|
|
|
|
|
2022-05-06 17:59:22 +08:00
|
|
|
def urls
|
|
|
|
return if object.destroyed?
|
|
|
|
|
|
|
|
object.reload unless object.step
|
|
|
|
|
2022-06-07 18:10:10 +08:00
|
|
|
return {} unless can_manage_step?(scope[:user] || @instance_options[:user], object.step)
|
2022-06-03 17:52:10 +08:00
|
|
|
|
2022-05-06 17:59:22 +08:00
|
|
|
{
|
2022-08-22 20:02:19 +08:00
|
|
|
duplicate_url: duplicate_step_table_path(object.step, object),
|
2022-05-06 17:59:22 +08:00
|
|
|
delete_url: step_table_path(object.step, object),
|
2023-08-21 15:22:56 +08:00
|
|
|
update_url: step_table_path(object.step, object),
|
|
|
|
move_targets_url: move_targets_step_table_path(object.step, object),
|
|
|
|
move_url: move_step_table_path(object.step, object)
|
2022-05-06 17:59:22 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|