Method: Morpheus::Cli::LibraryFormsCommand#_get

Defined in:
lib/morpheus/cli/commands/library_forms_command.rb

#_get(id, options) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/morpheus/cli/commands/library_forms_command.rb', line 102

def _get(id, options)
  params = {}
  params.merge!(parse_query_options(options))
  if id.to_s !~ /\A\d{1,}\Z/
    # option_type_form = find_by_name(:option_type_form, id)
    option_type_form = find_option_type_form_by_name_or_id(id)
    return 1, "Form not found" if option_type_form.nil?
    id = option_type_form['id']
  end
  @option_type_forms_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @option_type_forms_interface.dry.get(id.to_i, params)
    return
  end
  json_response = @option_type_forms_interface.get(id.to_i, params)
  render_response(json_response, options, rest_object_key) do
    option_type_form = json_response[rest_object_key]
    print_h1 "Form Details", options
    print cyan
    print_description_list({
      "ID" => 'id',
      "Name" => 'name',
      "Code" => 'code',
      "Description" => 'description',
      "Labels" => lambda {|it| format_list(it['labels']) },
    }, option_type_form, options)
    
    # show option types
    print_h2 "Form Inputs"
    #print format_option_types_table(option_type_form['options'], options, nil, true)
    print format_option_types_table(option_type_form['options'], options, 'config.customOptions')
    print reset,"\n"

    # show Field Groups
    field_groups = option_type_form['fieldGroups']
    if field_groups && field_groups.size > 0
      field_groups.each do |field_group|
        print_h2 "#{field_group['name']}"
        #print format_option_types_table(field_group['options'], options, nil, true)
        if field_group['options'] && !field_group['options'].empty?
          print format_option_types_table(field_group['options'], options, 'config.customOptions')
          print reset,"\n"
        else
          print cyan, "This field group is empty", reset, "\n\n"
        end
      end
    end
  end
end