2022-11-23 12:54:09 +01:00
|
|
|
class Attachment::PendingPollComponent < ApplicationComponent
|
2022-12-07 18:36:03 +01:00
|
|
|
attr_reader :attachments
|
|
|
|
|
|
|
|
def initialize(poll_url:, attachment: nil, attachments: nil, context: nil)
|
2022-11-23 12:54:09 +01:00
|
|
|
@poll_url = poll_url
|
|
|
|
@attachments = if attachment.present?
|
|
|
|
[attachment]
|
|
|
|
else
|
|
|
|
attachments
|
|
|
|
end
|
2022-12-07 18:36:03 +01:00
|
|
|
|
|
|
|
@context = context
|
2022-11-23 12:54:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def render?
|
|
|
|
@attachments.any? { pending_attachment?(_1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def long_pending?
|
|
|
|
@attachments.any? do
|
2022-12-07 18:36:03 +01:00
|
|
|
pending_attachment?(_1) && _1.created_at < 60.seconds.ago
|
2022-11-23 12:54:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def poll_controller_options
|
|
|
|
{
|
|
|
|
controller: 'turbo-poll',
|
|
|
|
turbo_poll_url_value: @poll_url
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-12-07 18:36:03 +01:00
|
|
|
def as_dossier?
|
|
|
|
@context == :dossier
|
|
|
|
end
|
|
|
|
|
2022-11-23 12:54:09 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def pending_attachment?(attachment)
|
2023-12-06 15:10:44 +01:00
|
|
|
attachment.watermark_pending?
|
2022-11-23 12:54:09 +01:00
|
|
|
end
|
|
|
|
end
|