Class: DcBigMenu

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/dc_big_menu.rb

Overview

Schema information

Collection name: dc_big_menu : Big menus

_id                  BSON::ObjectId       _id
created_at           Time                 created_at
updated_at           Time                 updated_at
caption              String               caption
picture              String               picture
parent               BSON::ObjectId       parent
link                 String               link
page_id              BSON::ObjectId       page_id
order                Integer              order
active               Mongoid::Boolean     active
policy_id            BSON::ObjectId       policy_id
created_by           BSON::ObjectId       created_by
updated_by           BSON::ObjectId       updated_by
dc_site_id           Object               dc_site_id

This menu system is still experimental. It can be used for sites with menu which has many sub menus each linked to its own document. Unlike other menu models which provide menu in single document (with embedded documents as sub menus) this menu system provides one document for every menu option.

Class Method Summary collapse

Class Method Details

.add_sub_menu(site, parent, rez, level) ⇒ Object

Process submenu. Subroutine of choices4_menu.



73
74
75
76
77
78
79
# File 'app/models/dc_big_menu.rb', line 73

def self.add_sub_menu(site, parent, rez, level)
#TODO Make this faster  
  only(:_id,:parent,:caption).where(dc_site_id: site._id, parent: parent).sort( order: 1).to_a.each do |m|
    rez << ['- '*(level+1) + ' ' + m.caption, m._id]
    self.add_sub_menu(site, m._id, rez, level+1)
  end
end

.choices4_menu(site) ⇒ Object

Returns available menu choices for selecting menu



84
85
86
87
88
# File 'app/models/dc_big_menu.rb', line 84

def self.choices4_menu(site)
  rez   = []
  self.add_sub_menu(site, nil, rez, -1)
  rez
end