Sha256: ea7de21ae7ae7faa87ebd023aa8381f208dc6c9ca41dd0749ca7ed80d6b0e671

Contents?: true

Size: 1.47 KB

Versions: 17

Compression:

Stored size: 1.47 KB

Contents

class Marty::ConfigView < Marty::Grid
  has_marty_permissions \
  create: :admin,
  read: :admin,
  update: :admin,
  delete: :admin

  include Marty::Extras::Layout

  def configure(c)
    super

    c.title   = I18n.t('config', default: "Config")
    c.model   = "Marty::Config"
    c.columns = [:key, :value, :description]

    c.enable_extended_search = false
    c.data_store.sorters     = {property: :key, direction: 'ASC'}
  end

  # need a getter / setter to call the []= and [] methods now
  # since value is no longer stored as is
  def my_jsonb_getter
    lambda { |r| Marty::Config[r.key].to_json }
  end

  def my_jsonb_setter
    lambda { |r, v|
      decoded = ActiveSupport::JSON.decode(v) rescue nil
      r.set_value(decoded)
    }
  end

  def default_fields_for_forms
    [
      :key,
      {
        name:        :value,
        width:       "100%",
        height:      150,
        xtype:       :textareafield,
        auto_scroll: true,
        spellcheck:  false,
        allow_blank: false,
        field_style: {
          font_family: 'courier new',
          font_size:   '12px'
        },
        getter:  my_jsonb_getter,
        setter:  my_jsonb_setter,
      },
      textarea_field(:description),
    ]
  end

  column :key do |c|
    c.flex = 1
  end

  column :value do |c|
    c.flex = 3
    c.getter  = my_jsonb_getter
    c.setter  = my_jsonb_setter
  end
  column :description do |c|
    c.flex = 1
    c.width = 200
  end

end

ConfigView = Marty::ConfigView

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
marty-0.5.41 app/components/marty/config_view.rb
marty-0.5.40 app/components/marty/config_view.rb
marty-0.5.39 app/components/marty/config_view.rb
marty-0.5.38 app/components/marty/config_view.rb
marty-0.5.36 app/components/marty/config_view.rb
marty-0.5.35 app/components/marty/config_view.rb
marty-0.5.34 app/components/marty/config_view.rb
marty-0.5.33 app/components/marty/config_view.rb
marty-0.5.32 app/components/marty/config_view.rb
marty-0.5.31 app/components/marty/config_view.rb
marty-0.5.30 app/components/marty/config_view.rb
marty-0.5.29 app/components/marty/config_view.rb
marty-0.5.28 app/components/marty/config_view.rb
marty-0.5.27 app/components/marty/config_view.rb
marty-0.5.26 app/components/marty/config_view.rb
marty-0.5.25 app/components/marty/config_view.rb
marty-0.5.24 app/components/marty/config_view.rb