Class: CrudComponents::Presenters::Record
- Includes:
- ColumnSelection
- Defined in:
- lib/crud_components/presenters/record.rb
Overview
The single ‘record_presenter` local of the record partial.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#fieldset ⇒ Object
readonly
Returns the value of attribute fieldset.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#param_prefix ⇒ Object
readonly
Returns the value of attribute param_prefix.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
Attributes inherited from Base
Instance Method Summary collapse
-
#actions ⇒ Object
Row actions for this record; a derived :show button to the page we are already on would be noise.
-
#available_fields ⇒ Object
Every field this user may see on this record — declared fields plus the dynamic columns; the picker’s universe.
-
#initialize(view:, record:, fieldset: nil, actions: true, picked_columns: :auto, param_prefix: nil, extra_columns: nil) ⇒ Record
constructor
A new instance of Record.
- #title ⇒ Object
- #value_html(field) ⇒ Object
Methods included from ColumnSelection
#column_visible?, #field_groups, #fields, #group_heading, #group_icon, #visible_columns
Methods inherited from Base
#ability, #config, #css, #permission_context, #render_cell, #render_filter_control
Constructor Details
#initialize(view:, record:, fieldset: nil, actions: true, picked_columns: :auto, param_prefix: nil, extra_columns: nil) ⇒ Record
Returns a new instance of Record.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/crud_components/presenters/record.rb', line 9 def initialize(view:, record:, fieldset: nil, actions: true, picked_columns: :auto, param_prefix: nil, extra_columns: nil) super(view: view) @record = record @model = record.class @structure = Structure.for(@model) @fieldset = @structure.fieldset(fieldset || :show) @actions_enabled = actions @param_prefix = param_prefix # Dynamic columns work on a detail view too — user-defined properties # whose data lives outside the model's table, shown as extra rows. @dynamic_fields = Array(extra_columns).map { |c| c.to_field(@model).preload!([record]) } # A column picker can narrow/order this dl too, but a detail view has no # inline gear of its own (no `picker:` knob) — the gear is a standalone # `crud_column_picker` on the page. So pass `picked_columns:` an Array you # resolved (e.g. via `CrudComponents.selected_columns(params)`); `:auto` # here means "don't narrow" (no gear → a stray `?cols=` is ignored). # (`fields`, `column_visible?` and the picker logic come from ColumnSelection.) @picker = false @picked_columns = normalize_picked_columns(picked_columns) end |
Instance Attribute Details
#fieldset ⇒ Object (readonly)
Returns the value of attribute fieldset.
7 8 9 |
# File 'lib/crud_components/presenters/record.rb', line 7 def fieldset @fieldset end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/crud_components/presenters/record.rb', line 7 def model @model end |
#param_prefix ⇒ Object (readonly)
Returns the value of attribute param_prefix.
7 8 9 |
# File 'lib/crud_components/presenters/record.rb', line 7 def param_prefix @param_prefix end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
7 8 9 |
# File 'lib/crud_components/presenters/record.rb', line 7 def record @record end |
#structure ⇒ Object (readonly)
Returns the value of attribute structure.
7 8 9 |
# File 'lib/crud_components/presenters/record.rb', line 7 def structure @structure end |
Instance Method Details
#actions ⇒ Object
Row actions for this record; a derived :show button to the page we are already on would be noise.
48 49 50 51 52 53 54 |
# File 'lib/crud_components/presenters/record.rb', line 48 def actions return nil unless @actions_enabled @actions ||= Actions.new(view: view, subject: record, structure: structure, actions: structure.fieldset_actions(fieldset, on: :row), suppress_show: true) end |
#available_fields ⇒ Object
Every field this user may see on this record — declared fields plus the dynamic columns; the picker’s universe.
37 38 39 40 |
# File 'lib/crud_components/presenters/record.rb', line 37 def available_fields @available_fields ||= (structure.fieldset_fields(fieldset) + @dynamic_fields) .select { |f| f.permitted?(, record) } end |
#title ⇒ Object
31 32 33 |
# File 'lib/crud_components/presenters/record.rb', line 31 def title structure.label_for(record, view) end |
#value_html(field) ⇒ Object
42 43 44 |
# File 'lib/crud_components/presenters/record.rb', line 42 def value_html(field) render_cell(field, record, surface: :record) end |