Sha256: 96e323f72a470a52191b168f46c50ff8e4df104003c3f41da683844f3564a8a8

Contents?: true

Size: 1.38 KB

Versions: 76

Compression:

Stored size: 1.38 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.attributes = [:key, :value, :description]
    c.editing    = :both
    c.store_config.merge!(sorters: [{property: :key, direction: 'ASC'}])
  end

  def my_jsonb_getter
    lambda { |r| v = Marty::Config[r.key]; !v.nil? && v.to_json || '' }
  end

  def my_jsonb_pretty_getter
    lambda { |r| v = Marty::Config[r.key]
      !v.nil? && (JSON.pretty_generate(v) rescue v.to_json) || '' }
  end

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

  def default_form_items
    [
      :key,
      jsonb_field(:value, {
                    getter: my_jsonb_pretty_getter,
                    setter: my_jsonb_setter,
                  }),
      textarea_field(:description),
    ]
  end

  attribute :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

  attribute :description do |c|
    c.flex = 1
  end
end

ConfigView = Marty::ConfigView

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
marty-2.5.2 app/components/marty/config_view.rb
marty-2.5.1 app/components/marty/config_view.rb
marty-2.5.0 app/components/marty/config_view.rb
marty-2.4.9 app/components/marty/config_view.rb
marty-2.4.8 app/components/marty/config_view.rb
marty-2.4.7 app/components/marty/config_view.rb
marty-2.4.6 app/components/marty/config_view.rb
marty-2.4.5 app/components/marty/config_view.rb
marty-2.4.4 app/components/marty/config_view.rb
marty-2.4.3 app/components/marty/config_view.rb
marty-2.4.2 app/components/marty/config_view.rb
marty-2.4.1 app/components/marty/config_view.rb
marty-2.4.0 app/components/marty/config_view.rb
marty-2.3.15 app/components/marty/config_view.rb
marty-2.3.14 app/components/marty/config_view.rb
marty-2.3.13 app/components/marty/config_view.rb
marty-2.3.12 app/components/marty/config_view.rb
marty-2.3.11 app/components/marty/config_view.rb
marty-2.3.10 app/components/marty/config_view.rb
marty-2.3.9 app/components/marty/config_view.rb