Class: Marty::ConfigView

Inherits:
Grid
  • Object
show all
Includes:
Extras::Layout
Defined in:
app/components/marty/config_view.rb

Constant Summary

Constants included from Extras::Layout

Extras::Layout::BOOL_MAP, Extras::Layout::MAP_BOOL

Constants included from Permissions

Permissions::NETZKE_ENDPOINTS

Instance Method Summary collapse

Methods included from Extras::Layout

#bool_getter, #bool_setter, #dispfield, #enum_array, #enum_column, #enum_setter, #fieldset, #get_sorter, #hbox, #hspacer, #jsonb_field, #nullable_bool_column, #range_column, #range_field, #range_getter, #range_setter, #textarea_field, #tooltip, #vbox, #vspacer

Methods inherited from Grid

#child_components, #class_can?, #configure_form_window, #get_json_sorter, #has_search_action?, #initialize, #linked_components

Methods included from Permissions

#can_call_endpoint?, #can_perform_action?, #can_perform_actions, #current_user_roles, extended, #has_any_perm?, #has_marty_permissions, #has_perm?

Constructor Details

This class inherits a constructor from Marty::Grid

Instance Method Details

#configure(c) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'app/components/marty/config_view.rb', line 9

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

#default_form_itemsObject



39
40
41
42
43
44
45
46
47
48
# File 'app/components/marty/config_view.rb', line 39

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

#my_jsonb_getterObject



19
20
21
# File 'app/components/marty/config_view.rb', line 19

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

#my_jsonb_pretty_getterObject



23
24
25
26
27
28
# File 'app/components/marty/config_view.rb', line 23

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

#my_jsonb_setterObject



30
31
32
33
34
35
36
37
# File 'app/components/marty/config_view.rb', line 30

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