Sha256: 05437330b22e44a12aa8bb0134ae5db107f5890a2cc5e932aaa6f58fcb2fa3ec

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 KB

Contents

/**
 Copyright 2014 Red Hat, Inc.

 This software is licensed to you under the GNU General Public
 License as published by the Free Software Foundation; either version
 2 of the License (GPLv2) or (at your option) any later version.
 There is NO WARRANTY for this software, express or implied,
 including the implied warranties of MERCHANTABILITY,
 NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
 have received a copy of GPLv2 along with this software; if not, see
 http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
 **/

/**
 * @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];
        } else {
            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

18 entries across 18 versions & 1 rubygems

Version Path
bastion-0.1.14 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.2.2 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.2.1 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.2.0 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.13 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.12 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.11 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.10 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.9 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.8 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.7 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.6 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.5 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.4 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.3 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.2 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.1 app/assets/javascripts/bastion/menu/menu-expander.service.js
bastion-0.1.0 app/assets/javascripts/bastion/menu/menu-expander.service.js