Sha256: 32164b1f159443561cbfded5fc471f133ce5916b7bfca42bd7ecba72dcbc8a67

Contents?: true

Size: 1.1 KB

Versions: 22

Compression:

Stored size: 1.1 KB

Contents

/**
 * @ngdoc service
 * @name  Bastion.menu.service:menuExpander
 *
 * @description
 *   Provides a way to add additional menu items from other modules.
 *
 *   Expects menus to be an array of objects of the form:
 *      {url: 'http://redhat.com', label: 'Red Hat'}
 *
 * @usage
 *   angular.module('SomeOtherModule', ['Bastion.menu']);
 *
 *   angular.module('SomeOtherModule').run(['MenuExpander', function (menuExpander) {
 *       menuExpander.setMenu('system', [{'url': 'http://redhat.com', 'label': 'Red Hat'}]);
 *   }]);
 */
angular.module('Bastion.menu').service('MenuExpander', [function () {
    this.menu = {};

    this.getMenu = function (menuName) {
        if (this.menu.hasOwnProperty(menuName)) {
            return this.menu[menuName];
        }

        return [];
    };

    this.setMenu = function (menuName, items) {
        if (this.menu.hasOwnProperty(menuName)) {
            this.menu[menuName] = _.uniq(_.union(this.menu[menuName], items), false, function (item) {
                return item.url;
            }, this);
        } else {
            this.menu[menuName] = items;
        }
    };
}]);

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bastion-3.4.1 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.4.0 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.3.6 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.3.5 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.3.4 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.3.3 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.3.2 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.3.1 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.3.0 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.2.2 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.2.1 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.2.0 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.1.0 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.0.1 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-3.0.0 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-2.1.0 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-2.0.4 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-2.0.3 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-2.0.2 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-2.0.1 app/assets/javascripts/bastion/menu/menu-expander.service.js