Module: BrowseModelsControl

Defined in:
app/controls/browse_models_control.rb

Instance Method Summary collapse

Instance Method Details

#all_collectionsObject

Return array of all models found in application.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controls/browse_models_control.rb', line 32

def all_collections
  collections = []
  DrgCms.paths(:forms).each do |path|
    models_dir = File.expand_path("../models", path)
    Dir["#{models_dir}/*.rb"].each do |model_file|
      model_file =~ /(.*)\/(.*).rb/
      # check if model exists
      collection = $2.camelize.constantize.new rescue nil
      collections << collection.class.to_s.underscore if collection&.respond_to?(:_id)
    end
  end
  collections.sort
end

#all_fieldsObject

List field definition for single model



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controls/browse_models_control.rb', line 60

def all_fields
  @records = []
  model = params[:id].classify.constantize
  document = model.new
  document.attribute_names.each do |attribute_name|
    options = model.fields[attribute_name].options
    description = I18n.t("helpers.help.#{params[:id]}.#{attribute_name}")
    description = I18n.t("helpers.label.#{params[:id]}.#{attribute_name}") if description.match('missing:')
    description = attribute_name if description.match('missing:')

    @records << DcMemory.new({id: attribute_name,
                 'collection' =>  params[:id],
                 'field' => attribute_name, 
                 'type' => options[:type],
                 'description' => description, 
                 '_default' => options[:default]
                })
  end
# embedded documents
  document.embedded_relations.each do |a_embedded|
    embedded = a_embedded.last
    description = I18n.t("helpers.help.#{params[:id]}.#{embedded.key}")
    description = I18n.t("helpers.label.#{params[:id]}.#{embedded.key}") if description.match('missing:')
    description = embedded.key if description.match('missing:')

    @records << DcMemory.new({ id: embedded.key,
                 'collection' =>  params[:id],
                 'field' => embedded.key, 
                 'type' => 'Embedded:' + embedded.class_name,
                 'description' => description
                })
  end

  @records
end

#collectionsObject

List all collections



49
50
51
52
53
54
55
# File 'app/controls/browse_models_control.rb', line 49

def collections
  @records = []
  all_collections.each do |collection|
    @records << DcMemory.new({'id' =>  collection, 'description' => t("helpers.label.#{collection}.tabletitle") })
  end
  @records
end