Class: Avo::Resources::DbConfig

Inherits:
BaseResource
  • Object
show all
Defined in:
app/avo/resources/db_config.rb

Defined Under Namespace

Classes: ForceChangeType

Constant Summary collapse

VALUE_TYPE_CONVERSIONS =
{
  "String" => :text,
  "Integer" => :number,
  "Boolean" => :boolean,
  "Hash" => :code,
  "Array" => :text,
  "Float" => :number
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.plural_nameObject



84
85
86
# File 'app/avo/resources/db_config.rb', line 84

def self.plural_name
  "Configurations"
end

.singular_nameObject



88
89
90
# File 'app/avo/resources/db_config.rb', line 88

def self.singular_name
  "Configuration"
end

Instance Method Details

#fieldsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/avo/resources/db_config.rb', line 47

def fields
  field :id, as: :id
  field :key

  if record.present?
    field :value, as: VALUE_TYPE_CONVERSIONS[record.value_type], update_using: ->{
      return value unless record.value_type == "Boolean"

      case value
      when "1"
        "true"
      when "0"
        "false"
      else
        value
      end
    }, visible: -> { !resource.view.new? }
  else
    field :value, visible: -> { !resource.view.new? }
  end

  field :value_type,
    as: :select,
    name: "Type",
    options: DBConfig::Record::VALUE_TYPES, disabled: -> { record.persisted? },
    help: -> {
      return if !record.persisted?

      path, data = Avo::Resources::DbConfig::ForceChangeType.link_arguments(resource: resource)

      "Can't change the type of a configuration that has already been set.<br>
      Click #{link_to("here", path, data: data).html_safe} to force the type change."
    }

  field :eager_load, as: :boolean
end