Module: BrowseModelsControl

Includes:
DcApplicationHelper
Defined in:
app/controllers/browse_models_control.rb

Instance Attribute Summary

Attributes included from DcApplicationHelper

#design, #form, #ids, #menu, #menu_item, #options, #page, #page_title, #part, #parts, #record_footer, #site, #tables

Instance Method Summary collapse

Methods included from DcApplicationHelper

#_origin, #dc_add2_record_cookie, #dc_big_table, #dc_choices4, #dc_choices4_all_collections, #dc_choices4_cmsmenu, #dc_choices4_field, #dc_choices4_folders_list, #dc_choices4_menu, #dc_choices4_site_policies, #dc_date_time, #dc_deprecate, #dc_dont?, #dc_edit_mode?, #dc_edit_title, #dc_error_messages_for, #dc_flash_messages, #dc_format_date_time, #dc_get_site, #dc_icon4_boolean, #dc_iframe_edit, #dc_internal_var, #dc_label_for, #dc_limit_string, #dc_link_for_create, #dc_link_for_edit, #dc_link_for_edit1, #dc_link_menu_tag, #dc_link_to, #dc_menu_class, #dc_name4_id, #dc_name4_value, #dc_new_title, #dc_page_bottom, #dc_page_class, #dc_page_edit_menu, #dc_page_top, #dc_render, #dc_render_design, #dc_render_design_part, #dc_render_from_site, #dc_render_partial, #dc_replace_in_design, #dc_submit_tag, #dc_table_title, #dc_user_can_view, #dc_user_has_role, #decamelize_type, #forms_merge, #t, #t_name, #t_tablename

Instance Method Details

#all_collectionsObject

Return array of all models found in application.



47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/browse_models_control.rb', line 47

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| 
      collection_name = determine_model(model_file)
      collections << collection_name if collection_name
    end
  end
  collections.sort
end

#collectionsObject

List all collections



62
63
64
65
66
67
68
# File 'app/controllers/browse_models_control.rb', line 62

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

#determine_model(path) ⇒ Object

Determine model class from filename.



34
35
36
37
38
39
40
41
42
# File 'app/controllers/browse_models_control.rb', line 34

def determine_model(path)
  path =~ /(.*)\/(.*).rb/
  begin
    $2.camelize.constantize 
    $2
  rescue Exception # it happends
    nil
  end
end

#fieldsObject

List field definition for single model



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/browse_models_control.rb', line 73

def 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 << {'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 << {'collection' =>  params[:id], 
                 'field' => embedded.key, 
                 'type' => 'Embedded:' + embedded.class_name,
                 'description' => description
                }
  end

  @records
end