Class: Marty::ReportSelect

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

Constant Summary collapse

REPORT_ATTR_SET =

FIXME: should be in a library

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 included from Permissions

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

Instance Method Details

#configure(c) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/marty/report_select.rb', line 26

def configure(c)
  super

  c.items =
    [
      :tag_grid,
      :script_grid,
      fieldset(I18n.t('reporting.report_select'),
               {
                 xtype:        :netzkeremotecombo,
                 name:         'nodename',
                 attr_type:    :string,
                 virtual:      true,
                 hide_label:   true,
                 width:        200,
               },
               {},
              ),
    ]
  c.bbar = nil
end

#node_listObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/components/marty/report_select.rb', line 56

def node_list
  sset = Marty::ScriptSet.new root_sess[:selected_tag_id]
  engine = sset.get_engine(root_sess[:selected_script_name])

  return [] unless engine

  nodes = engine.enumerate_nodes.select do |n|
    attrs = Set.new(engine.enumerate_attrs_by_node(n))
    attrs.superset? REPORT_ATTR_SET
  end

  nodes.map do |node|
    roles = engine.evaluate(node, 'roles') rescue nil

    next if roles && !roles.any? { |r| Marty::User.has_role(r) }

    begin
      title, format = engine.evaluate(node, ['title', 'format'])
      format ? [node, "#{title} (#{format})"] : nil
    rescue StandardError
      [node, node]
    end
  end.compact.sort { |a, b| a[1] <=> b[1] }
end