app/controllers/bhf/application_controller.rb in bhf-0.6.32 vs app/controllers/bhf/application_controller.rb in bhf-0.7.0.rc1

- old
+ new

@@ -1,8 +1,8 @@ class Bhf::ApplicationController < ActionController::Base - before_filter :init_time, :check_admin_account, :setup_current_account, :load_config, :set_title + before_filter :init_time, :check_admin_account, :setup_current_account, :load_config, :set_title, :set_areas helper_method :current_account layout 'bhf/application' def index @@ -31,61 +31,47 @@ def current_account @current_account end - def load_config - @config = Bhf::Settings.new(roles_yml(get_account_roles)) - end - - def roles_yml(roles = nil) - if roles.is_a?(String) - load_yml("/#{roles}") - elsif roles.is_a?(Array) - files = roles.each_with_object({'pages' => []}) do |r, account_roles| - pages = load_yml("/#{r}")['pages'] - account_roles['pages'] += pages if pages + def get_account_roles(area = nil) + return unless current_account + + if area + if current_account.respond_to?(:area_role) + return current_account.area_role(area) + elsif current_account.respond_to?(:area_roles) + return current_account.area_roles(area).collect(&:to_bhf_s) end - - merged_files = {'pages' => []} - files['pages'].each do |pages| - merged = false - pages.each do |page| - merged_files['pages'].each do |m_page| - if m_page.include?(page[0]) - merged = true - m_page[page[0]] << page[1] - end - end - end - if !merged - merged_files['pages'] << pages - end - end - merged_files - else - load_yml end - end - def load_yml(suffix = nil) - YAML::load(IO.read("config/bhf#{suffix}.yml")) - end - - def get_account_roles - return unless current_account - if current_account.respond_to?(:role) current_account.role.is_a?(String) ? current_account.role : current_account.role.to_bhf_s elsif current_account.respond_to?(:roles) current_account.roles.collect(&:to_bhf_s) end end + def load_config + @config = Bhf::ConfigParser::parse(get_account_roles(params[:bhf_area]), params[:bhf_area]) + end def set_title @app_title = Rails.application.class.to_s.split('::').first @title = Bhf::Engine.config.page_title || ("#{@app_title} &ndash; Admin").html_safe + end + + def set_areas + @areas = [] + if current_account and current_account.respond_to?(:bhf_areas) + current_account.bhf_areas.each do |area| + @areas << OpenStruct.new( + name: t("bhf.areas.links.#{area.to_bhf_s}", default: area.to_bhf_s), + selected: params[:bhf_area] == area.to_bhf_s, + path: main_app.bhf_path(area.to_bhf_s) + ) + end + end end def set_message(type, model = nil) key = model && ActiveModel::Naming.singular(model)