Module: Avo::Concerns::FrameLoadingMode
- Extended by:
- ActiveSupport::Concern
- Included in:
- Fields::FrameBaseField, Resources::Items::Tab
- Defined in:
- lib/avo/concerns/frame_loading_mode.rb
Instance Method Summary collapse
-
#auto_load_for ⇒ Object
Seconds the browser should remember the opened frame and auto-load it on return (sliding window).
-
#default_manual_auto_load_for ⇒ Object
How long a manual frame remembers an opened frame when neither the field nor the global config pins an explicit ‘auto_load_for`.
-
#frame_loading_defaults ⇒ Object
Global defaults this host falls back to when no per-call ‘loading:` is given.
-
#lazy_loading_mode? ⇒ Boolean
True when ‘loading: :lazy` — render a native lazy frame.
-
#loading_mode ⇒ Object
The cold-start render mode: ‘:manual`, `:lazy`, or `nil` when unset.
-
#manual? ⇒ Boolean
True when the frame should render as a manual placeholder (Load button) on cold start.
Instance Method Details
#auto_load_for ⇒ Object
Seconds the browser should remember the opened frame and auto-load it on return (sliding window). Accepts an ‘ActiveSupport::Duration` or a raw integer. Returns `nil` (no memory window) when the frame isn’t manual.
Manual frames default to ‘default_manual_auto_load_for`. A developer can override the window — or opt out entirely with `auto_load_for: 0`/`nil`, which closes the frame again on the next refresh.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/avo/concerns/frame_loading_mode.rb', line 80 def auto_load_for return @auto_load_for if defined?(@auto_load_for) = @loading.is_a?(Hash) ? @loading.symbolize_keys : {} window = if .key?(:auto_load_for) # An explicit per-field value wins, including `0`/`nil` (opt out). [:auto_load_for] elsif manual? # Otherwise manual frames fall back to the configured default window. default_manual_auto_load_for end # `0`/`nil` (or a negative) means "no memory" — close again on refresh. seconds = window&.to_i @auto_load_for = (seconds if seconds&.positive?) end |
#default_manual_auto_load_for ⇒ Object
How long a manual frame remembers an opened frame when neither the field nor the global config pins an explicit ‘auto_load_for`.
41 42 43 |
# File 'lib/avo/concerns/frame_loading_mode.rb', line 41 def default_manual_auto_load_for frame_loading_defaults.fetch(:auto_load_for, 15.minutes) end |
#frame_loading_defaults ⇒ Object
Global defaults this host falls back to when no per-call ‘loading:` is given. Tabs have none (keeping the eager-inline default); association fields override this to read `Avo.configuration.associations`.
35 36 37 |
# File 'lib/avo/concerns/frame_loading_mode.rb', line 35 def frame_loading_defaults {} end |
#lazy_loading_mode? ⇒ Boolean
True when ‘loading: :lazy` — render a native lazy frame.
69 70 71 |
# File 'lib/avo/concerns/frame_loading_mode.rb', line 69 def lazy_loading_mode? loading_mode == :lazy end |
#loading_mode ⇒ Object
The cold-start render mode: ‘:manual`, `:lazy`, or `nil` when unset. A Hash without an explicit `mode:` defaults to `:manual`, so `loading: 5.minutes` is “manual + memory”. With no per-call `loading:` at all, fall back to the host’s global default.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/avo/concerns/frame_loading_mode.rb', line 49 def loading_mode return @loading_mode if defined?(@loading_mode) @loading_mode = if @loading.is_a?(Hash) (@loading.symbolize_keys[:mode] || :manual).to_sym elsif @loading.present? @loading.to_sym else frame_loading_defaults[:loading] end end |
#manual? ⇒ Boolean
True when the frame should render as a manual placeholder (Load button) on cold start. Covers ‘loading: :manual` and `loading: :manual`.
64 65 66 |
# File 'lib/avo/concerns/frame_loading_mode.rb', line 64 def manual? loading_mode == :manual end |