Module: Spree::Admin::System::WaitingRoomSessionsHelper
- Defined in:
- app/helpers/spree/admin/system/waiting_room_sessions_helper.rb
Overview
Shared badge/derived-value logic for the Guests tab (_guests_table.html.erb's Queue and Heartbeat columns, _guest_raw.html.erb's modal) -- kept in one place so both never drift into disagreeing about what "Admitted" or "Stale ping" means for the same document.
Instance Method Summary collapse
-
#guest_heartbeat_status(guest) ⇒ Object
Only meaningful before a guest is resolved: once left_at or allow_to_enter_room_at is set, Heartbeat::Sweep's query (allow_to_enter_room_at == nil, left_at == nil) no longer looks at this doc's last_ping_at at all, so showing a ping state past that point would describe a check the server itself has stopped making.
-
#guest_people_ahead(guest, frontier_position) ⇒ Object
Same formula the app itself shows the guest (see waiting_room_provider.dart's _peopleAheadOfYou): position minus the lobby's live frontier_position, floored at 1 so a guest at the very front never reads "0 ahead" (session presence, not this count, is what actually admits them).
-
#guest_queue_status(guest) ⇒ Object
Mutually exclusive lifecycle stage, in the order a guest actually moves through them.
Instance Method Details
#guest_heartbeat_status(guest) ⇒ Object
Only meaningful before a guest is resolved: once left_at or allow_to_enter_room_at is set, Heartbeat::Sweep's query (allow_to_enter_room_at == nil, left_at == nil) no longer looks at this doc's last_ping_at at all, so showing a ping state past that point would describe a check the server itself has stopped making.
27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/spree/admin/system/waiting_room_sessions_helper.rb', line 27 def guest_heartbeat_status(guest) return nil if guest[:left_at] || guest[:allow_to_enter_room_at] last_ping_at = guest[:last_ping_at] return ['Never pinged', 'badge-secondary'] if last_ping_at.nil? stale = last_ping_at < SpreeCmCommissioner::WaitingRoom::Heartbeat::Sweep::HEARTBEAT_TTL_SECONDS.seconds.ago stale ? ['Stale ping', 'badge-warning'] : ['Active ping', 'badge-success'] end |
#guest_people_ahead(guest, frontier_position) ⇒ Object
Same formula the app itself shows the guest (see waiting_room_provider.dart's _peopleAheadOfYou): position minus the lobby's live frontier_position, floored at 1 so a guest at the very front never reads "0 ahead" (session presence, not this count, is what actually admits them). Nil until Positions::Stamp assigns this guest a position at all.
41 42 43 44 45 46 |
# File 'app/helpers/spree/admin/system/waiting_room_sessions_helper.rb', line 41 def guest_people_ahead(guest, frontier_position) position = guest[:position] return nil if position.nil? [position - frontier_position.to_i, 1].max end |
#guest_queue_status(guest) ⇒ Object
Mutually exclusive lifecycle stage, in the order a guest actually moves through them. Left is checked first because Heartbeat::Sweep can mark left_at on a doc that was still mid-call (call_dispatched_at set but never granted) -- left always wins once set.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/spree/admin/system/waiting_room_sessions_helper.rb', line 11 def guest_queue_status(guest) if guest[:left_at] ['Left queue', 'badge-secondary'] elsif guest[:allow_to_enter_room_at] %w[Admitted badge-success] elsif guest[:call_dispatched_at] ['Being called', 'badge-info'] else %w[Waiting badge-primary] end end |