Class: Jav::Fields::HasBaseField
- Includes:
- Concerns::UseResource
- Defined in:
- lib/jav/fields/has_base_field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attach_scope ⇒ Object
Returns the value of attribute attach_scope.
-
#description ⇒ Object
Returns the value of attribute description.
-
#discreet_pagination ⇒ Object
Returns the value of attribute discreet_pagination.
-
#display ⇒ Object
Returns the value of attribute display.
-
#hide_search_input ⇒ Object
Returns the value of attribute hide_search_input.
-
#link_to_child_resource ⇒ Object
readonly
Returns the value of attribute link_to_child_resource.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#searchable ⇒ Object
readonly
Returns the value of attribute searchable.
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #autocomplete, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #in_sidebar, #index_text_align, #model, #null_values, #nullable, #panel_name, #readonly, #required, #sortable, #stacked, #user, #view, #visible
Attributes included from Concerns::IsDisabled
Attributes included from Concerns::HasHTMLAttributes
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#component_for_view(view = :index) ⇒ Object
Adds the view override component has_one, has_many, has_and_belongs_to_many fields don't have edit views.
- #default_name ⇒ Object
-
#field_label ⇒ Object
What the user sees in the text field.
-
#field_value ⇒ Object
The value.
- #frame_url ⇒ Object
- #has_own_panel? ⇒ Boolean
-
#initialize(id, **args, &block) ⇒ HasBaseField
constructor
A new instance of HasBaseField.
- #placeholder ⇒ Object
- #resource ⇒ Object
- #target_resource ⇒ Object
- #turbo_frame ⇒ Object
- #visible_in_reflection? ⇒ Boolean
Methods included from Concerns::UseResource
Methods inherited from BaseField
#assign_value, #custom?, #custom_name?, #database_id, #fill_field, #hidden_in_reflection?, #hydrate, #model_errors, #name, #plural_name, #resolve_attribute, #to_permitted_param, #translation_key, #type, #updatable, #update_using, #value, #view_component_name, #visible?
Methods included from FieldExtensions::HasFieldName
Methods included from Concerns::HasDefault
Methods included from Concerns::IsDisabled
Methods included from Concerns::IsReadonly
Methods included from Concerns::IsRequired
Methods included from Concerns::HasHTMLAttributes
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on, #show_on_create, #show_on_update, #visible_on?
Methods included from Concerns::IsResourceItem
#is_field?, #is_main_panel?, #is_panel?, #is_row?, #is_sidebar?, #is_tab?, #is_tab_group?, #is_tool?
Constructor Details
#initialize(id, **args, &block) ⇒ HasBaseField
Returns a new instance of HasBaseField.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jav/fields/has_base_field.rb', line 9 def initialize(id, **args, &block) super @scope = args[:scope].presence @attach_scope = args[:attach_scope].presence @display = args[:display].presence || :show @searchable = args[:searchable] == true @hide_search_input = args[:hide_search_input] || false @description = args[:description] @use_resource = args[:use_resource] || nil @discreet_pagination = args[:discreet_pagination] || false @link_to_child_resource = args[:link_to_child_resource] || false end |
Instance Attribute Details
#attach_scope ⇒ Object
Returns the value of attribute attach_scope.
6 7 8 |
# File 'lib/jav/fields/has_base_field.rb', line 6 def attach_scope @attach_scope end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/jav/fields/has_base_field.rb', line 6 def description @description end |
#discreet_pagination ⇒ Object
Returns the value of attribute discreet_pagination.
6 7 8 |
# File 'lib/jav/fields/has_base_field.rb', line 6 def discreet_pagination @discreet_pagination end |
#display ⇒ Object
Returns the value of attribute display.
6 7 8 |
# File 'lib/jav/fields/has_base_field.rb', line 6 def display @display end |
#hide_search_input ⇒ Object
Returns the value of attribute hide_search_input.
6 7 8 |
# File 'lib/jav/fields/has_base_field.rb', line 6 def hide_search_input @hide_search_input end |
#link_to_child_resource ⇒ Object (readonly)
Returns the value of attribute link_to_child_resource.
7 8 9 |
# File 'lib/jav/fields/has_base_field.rb', line 7 def link_to_child_resource @link_to_child_resource end |
#scope ⇒ Object
Returns the value of attribute scope.
6 7 8 |
# File 'lib/jav/fields/has_base_field.rb', line 6 def scope @scope end |
#searchable ⇒ Object (readonly)
Returns the value of attribute searchable.
7 8 9 |
# File 'lib/jav/fields/has_base_field.rb', line 7 def searchable @searchable end |
Instance Method Details
#authorized? ⇒ Boolean
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/jav/fields/has_base_field.rb', line 84 def method = :"view_#{id}?" service = resource. if service.has_method? method service.(method, raise_exception: false) else true end end |
#component_for_view(view = :index) ⇒ Object
Adds the view override component has_one, has_many, has_and_belongs_to_many fields don't have edit views
78 79 80 81 82 |
# File 'lib/jav/fields/has_base_field.rb', line 78 def component_for_view(view = :index) view = :show if view.in? %i[new create update edit] super end |
#default_name ⇒ Object
95 96 97 |
# File 'lib/jav/fields/has_base_field.rb', line 95 def default_name use_resource&.name || super end |
#field_label ⇒ Object
What the user sees in the text field
46 47 48 49 50 |
# File 'lib/jav/fields/has_base_field.rb', line 46 def field_label value.send(target_resource.class.title) rescue StandardError nil end |
#field_value ⇒ Object
The value
39 40 41 42 43 |
# File 'lib/jav/fields/has_base_field.rb', line 39 def field_value value.send(database_value) rescue StandardError nil end |
#frame_url ⇒ Object
31 32 33 34 35 36 |
# File 'lib/jav/fields/has_base_field.rb', line 31 def frame_url Jav::Services::URIService.parse(@resource.record_path) .append_path(id.to_s) .append_query(turbo_frame: turbo_frame.to_s) .to_s end |
#has_own_panel? ⇒ Boolean
68 69 70 |
# File 'lib/jav/fields/has_base_field.rb', line 68 def has_own_panel? true end |
#placeholder ⇒ Object
64 65 66 |
# File 'lib/jav/fields/has_base_field.rb', line 64 def placeholder @placeholder || I18n.t("jav.choose_an_option") end |
#resource ⇒ Object
23 24 25 |
# File 'lib/jav/fields/has_base_field.rb', line 23 def resource @resource || Jav::App.get_resource_by_model_name(@model.class) end |
#target_resource ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jav/fields/has_base_field.rb', line 52 def target_resource return use_resource if use_resource.present? if @model.class.reflect_on_association(id).klass.present? Jav::App.get_resource_by_model_name @model.class.reflect_on_association(id).klass.to_s elsif @model.class.reflect_on_association(id).[:class_name].present? Jav::App.get_resource_by_model_name @model.class.reflect_on_association(id).[:class_name] else Jav::App.get_resource_by_name id.to_s end end |
#turbo_frame ⇒ Object
27 28 29 |
# File 'lib/jav/fields/has_base_field.rb', line 27 def turbo_frame "#{self.class.name.demodulize.to_s.underscore}_#{display}_#{frame_id}" end |
#visible_in_reflection? ⇒ Boolean
72 73 74 |
# File 'lib/jav/fields/has_base_field.rb', line 72 def visible_in_reflection? false end |