2023-08-10 22:48:08 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ResultTableSerializer < ActiveModel::Serializer
|
|
|
|
include Canaid::Helpers::PermissionsHelper
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
2023-08-21 15:22:56 +08:00
|
|
|
attributes :name, :contents, :urls, :icon, :metadata, :parent_type
|
2023-08-10 22:48:08 +08:00
|
|
|
|
|
|
|
def contents
|
|
|
|
object.contents_utf_8
|
|
|
|
end
|
|
|
|
|
|
|
|
def icon
|
|
|
|
'fa-table'
|
|
|
|
end
|
|
|
|
|
2023-08-21 15:22:56 +08:00
|
|
|
def parent_type
|
|
|
|
:result
|
|
|
|
end
|
|
|
|
|
2023-08-10 22:48:08 +08:00
|
|
|
def urls
|
|
|
|
return if object.destroyed?
|
|
|
|
|
|
|
|
object.reload unless object.result
|
|
|
|
|
|
|
|
return {} unless can_manage_result?(scope[:user] || @instance_options[:user], object.result)
|
|
|
|
|
|
|
|
{
|
|
|
|
duplicate_url: duplicate_my_module_result_table_path(object.result.my_module, object.result, object),
|
|
|
|
delete_url: my_module_result_table_path(object.result.my_module, object.result, object),
|
2023-08-21 15:22:56 +08:00
|
|
|
update_url: my_module_result_table_path(object.result.my_module, object.result, object),
|
|
|
|
move_targets_url: move_targets_my_module_result_table_path(object.result.my_module, object.result, object),
|
|
|
|
move_url: move_my_module_result_table_path(object.result.my_module, object.result, object)
|
2023-08-10 22:48:08 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|