2022-05-24 17:30:15 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-04-22 19:07:51 +08:00
|
|
|
class StepSerializer < ActiveModel::Serializer
|
|
|
|
include Rails.application.routes.url_helpers
|
2022-05-18 17:12:53 +08:00
|
|
|
include ApplicationHelper
|
2022-05-25 21:04:14 +08:00
|
|
|
include CommentHelper
|
2022-04-22 19:07:51 +08:00
|
|
|
|
2022-05-18 17:12:53 +08:00
|
|
|
attributes :name, :position, :completed, :urls, :assets_view_mode, :assets_order,
|
2022-05-26 20:48:57 +08:00
|
|
|
:marvinjs_enabled, :marvinjs_context, :wopi_enabled, :wopi_context, :comments_count, :unseen_comments,
|
|
|
|
:storage_limit
|
2022-05-18 17:12:53 +08:00
|
|
|
|
|
|
|
def marvinjs_enabled
|
|
|
|
MarvinJsService.enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def marvinjs_context
|
|
|
|
if marvinjs_enabled
|
|
|
|
{
|
2022-05-24 17:30:15 +08:00
|
|
|
marvin_js_asset_url: marvin_js_assets_path,
|
2022-05-18 17:12:53 +08:00
|
|
|
icon: image_path('icon_small/marvinjs.svg')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-25 21:04:14 +08:00
|
|
|
def comments_count
|
|
|
|
object.comments.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def unseen_comments
|
|
|
|
has_unseen_comments?(object)
|
|
|
|
end
|
|
|
|
|
2022-05-18 17:12:53 +08:00
|
|
|
def wopi_enabled
|
|
|
|
wopi_enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def wopi_context
|
|
|
|
if wopi_enabled
|
|
|
|
{
|
|
|
|
create_wopi: create_wopi_file_path,
|
|
|
|
icon: image_path('office/office.svg')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2022-04-22 19:07:51 +08:00
|
|
|
|
2022-05-26 20:48:57 +08:00
|
|
|
def storage_limit
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2022-05-16 17:05:18 +08:00
|
|
|
def assets_order
|
|
|
|
object.current_view_state(@instance_options[:user]).state.dig('assets', 'sort')
|
|
|
|
end
|
2022-05-30 19:45:51 +08:00
|
|
|
|
2022-04-22 19:07:51 +08:00
|
|
|
def urls
|
|
|
|
{
|
2022-04-28 17:13:38 +08:00
|
|
|
delete_url: step_path(object),
|
|
|
|
state_url: toggle_step_state_step_path(object),
|
2022-04-29 18:29:42 +08:00
|
|
|
update_url: step_path(object),
|
|
|
|
elements_url: elements_step_path(object),
|
2022-05-12 18:05:41 +08:00
|
|
|
attachments_url: attachments_step_path(object),
|
2022-04-29 18:29:42 +08:00
|
|
|
create_table_url: step_tables_path(object),
|
|
|
|
create_text_url: step_texts_path(object),
|
2022-05-16 17:05:18 +08:00
|
|
|
create_checklist_url: step_checklists_path(object),
|
|
|
|
update_asset_view_mode_url: update_asset_view_mode_step_path(object),
|
2022-05-19 14:51:39 +08:00
|
|
|
update_view_state_step_url: update_view_state_step_path(object),
|
|
|
|
direct_upload_url: rails_direct_uploads_url,
|
2022-05-30 19:45:51 +08:00
|
|
|
upload_attachment_url: upload_attachment_step_path(object),
|
|
|
|
reorder_elements_url: reorder_step_step_orderable_elements_path(step_id: object.id)
|
2022-04-22 19:07:51 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|