AngularJS isPublic menu in MEAN.js

I am creating a webapp using MEAN.js and I have a navigation menu problem.

There are a couple of questions that seem to be related to my problem, but none of the answers resolve this for me, and it looks like most of them are attributed to a documentation error.

I'm trying to set up publicItem to public and this is how I do it in my core.client.config.js:

Menus.addMenuItem('topbar', 'About Us', 'about', 'item', '/about', true, null, 1);

      

All assigned jobs, even orders. However, the public parameter true

does nothing.

Currently I just set everything topbar

to isPublic in menus.client.service.js, but this is not ideal as I would like to control who can see what!

this.addMenu('topbar', true);

      

Any help would be appreciated!

+3


source to share


1 answer


The problem is public / modules / core / services / menus.client.service.js The shouldRender function called for menus, each item and sub item does not check isPublic. So just add:

// A private function for rendering decision 
var shouldRender = function(user) {
    if(this.isPublic){
        return true;
    }
    ...
}

      

and change the last line to:

//Adding the topbar menu
this.addMenu('topbar', true);

      

because otherwise the menu will never be displayed.

Now you can call addMenuItem and addSubMenuItem like this:

Menus.addMenuItem('topbar', 'Articles', 'articles', 'dropdown', '/articles(/create)?', <true/false>);
Menus.addSubMenuItem('topbar', 'articles', 'List Articles', 'articles');
Menus.addSubMenuItem('topbar', 'articles', 'New Article', 'articles/create');

      

Note that if you don't specify true or false, menu items will inherit from their parent. When we set up a menu to post, every child is public. Once we set the menu item private, the children are also private.



If you want to change the visibility of the SubMenu, be careful with the number of arguments. The sixth argument must be true.

Menus.addSubMenuItem('topbar', 'articles', 'List Articles', 'articles');

      

^^ changes to vv

Menus.addSubMenuItem('topbar', 'articles', 'List Articles', 'articles', '/articles', true);

      

You can, of course, change the signature of the functions to avoid this. Just replace menuItemUIRoute and isPublic in menus.client.service.js

 // Add submenu item object
this.addSubMenuItem = function(menuId, rootMenuItemURL, menuItemTitle, menuItemURL, isPublic, menuItemUIRoute, roles, position) {
    // Validate that the menu exists

      

Then you can add SubMenu like this:

Menus.addSubMenuItem('topbar', 'articles', 'List Articles', 'articles', true);

      

+1


source







All Articles