Module: Anubis::Tenant::Data::Load

Includes:
Core::Data::Load
Included in:
Anubis::Tenant::DataController
Defined in:
app/controllers/anoubis/tenant/data/load.rb

Overview

Module loads data from external sources for Anubis::Tenant::DataController

Instance Method Summary collapse

Methods included from Core::Data::Load

#load_autocomplete_data, #load_data_by_id, #load_data_by_title, #load_new_data, #load_parent_data, #load_table_data, #load_table_data_count

Instance Method Details

#load_menu_dataObject

Loads current menu data. Procedure loads menu data from MySQL database or from Redis cache and places it in self.etc.menu Etc#menu



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/anoubis/tenant/data/load.rb', line 12

def load_menu_data
  menu_json = self.redis.get(self.redis_prefix + 'menu_' + params[:controller])
  menu_locale_json = self.redis.get(self.redis_prefix + 'menu_'+params[:controller]+'_'+self.locale)
  if !menu_json || !menu_locale_json
    menu = Anubis::Tenant::MenuLocale.eager_load(menu: :menu).where(locale: Anubis::Tenant::MenuLocale.locales[self.locale.to_sym]).where(['menus.mode = ? AND menus.status = 0', params[:controller]]).first
    if menu
      menu_json = {
        mode: menu.menu.mode,
        menu_id: menu.menu_id,
        parent_menu_id: menu.menu.menu_id,
        action: menu.menu.action,
        tab: menu.menu.tab,
        position: menu.menu.position,
        state: menu.menu.state
      }
      if menu.menu.menu
        menu_json[:parent_mode] = menu.menu.menu.mode
      end
      menu_json = menu_json.to_json
      self.redis.set(self.redis_prefix + 'menu_'+params[:controller], menu_json)
      menu_locale_json = {
        title: menu.title,
        page_title: menu.page_title,
        short_title: menu.short_title
      }.to_json
      self.redis.set(self.redis_prefix + 'menu_'+params[:controller]+'_'+self.locale, menu_locale_json)
    end
  end
  if menu_json && menu_locale_json
    self.etc.menu = Anubis::Etc::Menu.new JSON.parse(menu_json, {:symbolize_names => true}).merge(JSON.parse(menu_locale_json, {:symbolize_names => true}))
    if self.writer
      self.etc.menu.access = 'write'
    else
      self.etc.menu.access = 'read'
    end
  end
end