Class: Avo::Fields::StatusField
- Defined in:
- lib/avo/fields/status_field.rb
Defined Under Namespace
Classes: EditComponent, IndexComponent, ShowComponent
Instance Attribute Summary
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #model, #null_values, #nullable, #panel_name, #readonly, #required, #resource, #sortable, #updatable, #user, #view, #visible
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
-
#initialize(id, **args, &block) ⇒ StatusField
constructor
A new instance of StatusField.
- #status ⇒ Object
Methods inherited from BaseField
#component_for_view, #custom?, #database_id, #fill_field, #has_own_panel?, #hydrate, #model_errors, #name, #placeholder, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?
Methods included from FieldExtensions::HasFieldName
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(id, **args, &block) ⇒ StatusField
Returns a new instance of StatusField.
4 5 6 7 8 9 |
# File 'lib/avo/fields/status_field.rb', line 4 def initialize(id, **args, &block) super(id, **args, &block) @loading_when = args[:loading_when].present? ? [args[:loading_when]].flatten : [:waiting, :running] @failed_when = args[:failed_when].present? ? [args[:failed_when]].flatten : [:failed] end |
Instance Method Details
#status ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/avo/fields/status_field.rb', line 11 def status status = "success" if value.present? status = "failed" if @failed_when.include? value.to_sym status = "loading" if @loading_when.include? value.to_sym end status end |