2022-05-24 17:30:15 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-04-22 19:07:51 +08:00
|
|
|
class StepSerializer < ActiveModel::Serializer
|
2022-06-03 17:52:10 +08:00
|
|
|
include Canaid::Helpers::PermissionsHelper
|
2022-04-22 19:07:51 +08:00
|
|
|
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
|
2023-03-15 23:01:01 +08:00
|
|
|
include InputSanitizeHelper
|
2022-04-22 19:07:51 +08:00
|
|
|
|
2023-07-13 15:45:53 +08:00
|
|
|
attributes :name, :position, :completed, :attachments_manageble, :urls, :assets_view_mode,
|
|
|
|
:marvinjs_enabled, :marvinjs_context, :created_by, :created_at, :assets_order,
|
2023-07-24 19:28:44 +08:00
|
|
|
:wopi_enabled, :wopi_context, :comments_count, :unseen_comments, :storage_limit,
|
2024-04-03 19:23:10 +08:00
|
|
|
:type, :open_vector_editor_context, :collapsed
|
|
|
|
|
|
|
|
def collapsed
|
|
|
|
step_states = @instance_options[:user].settings.fetch('task_step_states', {})
|
|
|
|
step_states[object.id.to_s] == true
|
|
|
|
end
|
2022-05-18 17:12:53 +08:00
|
|
|
|
|
|
|
def marvinjs_enabled
|
|
|
|
MarvinJsService.enabled?
|
|
|
|
end
|
2023-07-24 19:28:44 +08:00
|
|
|
|
|
|
|
def type
|
|
|
|
'Step'
|
|
|
|
end
|
2022-05-18 17:12:53 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-08-17 15:33:20 +08:00
|
|
|
def open_vector_editor_context
|
|
|
|
if can_manage_step?(object)
|
|
|
|
{
|
|
|
|
new_sequence_asset_url: new_gene_sequence_asset_url(parent_type: 'Step', parent_id: object.id),
|
|
|
|
icon: image_path('icon_small/sequence-editor.svg')
|
|
|
|
}
|
|
|
|
end
|
2023-08-02 20:13:04 +08:00
|
|
|
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
|
2022-05-27 18:49:10 +08:00
|
|
|
object.current_view_state(@instance_options[:user]).state.dig('assets', 'sort') unless object.destroyed?
|
2022-05-16 17:05:18 +08:00
|
|
|
end
|
2022-05-30 19:45:51 +08:00
|
|
|
|
2022-07-14 21:09:28 +08:00
|
|
|
def attachments_manageble
|
|
|
|
can_manage_step?(object)
|
|
|
|
end
|
|
|
|
|
2022-04-22 19:07:51 +08:00
|
|
|
def urls
|
2022-06-03 17:52:10 +08:00
|
|
|
urls_list = {
|
|
|
|
elements_url: elements_step_path(object),
|
|
|
|
attachments_url: attachments_step_path(object)
|
|
|
|
}
|
|
|
|
|
2022-07-18 22:56:06 +08:00
|
|
|
if object.my_module && can_complete_my_module_steps?(object.my_module)
|
|
|
|
urls_list[:state_url] = toggle_step_state_step_path(object)
|
|
|
|
end
|
2022-07-14 21:09:28 +08:00
|
|
|
|
2023-03-14 16:12:54 +08:00
|
|
|
if can_manage_protocol_in_module?(object.protocol) || can_manage_protocol_draft_in_repository?(object.protocol)
|
2022-08-24 19:45:39 +08:00
|
|
|
urls_list[:duplicate_step_url] = duplicate_step_path(object)
|
|
|
|
end
|
|
|
|
|
2022-06-03 21:26:16 +08:00
|
|
|
if can_manage_step?(object)
|
|
|
|
urls_list.merge!({
|
|
|
|
delete_url: step_path(object),
|
|
|
|
update_url: step_path(object),
|
|
|
|
create_table_url: step_tables_path(object),
|
|
|
|
create_text_url: step_texts_path(object),
|
|
|
|
create_checklist_url: step_checklists_path(object),
|
|
|
|
update_asset_view_mode_url: update_asset_view_mode_step_path(object),
|
2023-08-10 22:48:08 +08:00
|
|
|
update_view_state_url: update_view_state_step_path(object),
|
2022-06-03 21:26:16 +08:00
|
|
|
direct_upload_url: rails_direct_uploads_url,
|
|
|
|
upload_attachment_url: upload_attachment_step_path(object),
|
2022-08-24 19:45:39 +08:00
|
|
|
reorder_elements_url: reorder_step_step_orderable_elements_path(step_id: object.id)
|
2022-06-03 21:26:16 +08:00
|
|
|
})
|
|
|
|
end
|
2022-06-03 17:52:10 +08:00
|
|
|
|
|
|
|
urls_list
|
2022-04-22 19:07:51 +08:00
|
|
|
end
|
2023-02-03 15:12:33 +08:00
|
|
|
|
2023-02-06 03:00:20 +08:00
|
|
|
def created_at
|
2023-02-03 15:12:33 +08:00
|
|
|
object.created_at.strftime('%B %d, %Y at %H:%M')
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_by
|
|
|
|
object.user.full_name
|
|
|
|
end
|
2022-04-22 19:07:51 +08:00
|
|
|
end
|