akveo / blur-admin

AngularJS Bootstrap Admin Panel Framework
http://akveo.github.io/blur-admin/
Other
11.37k stars 3.09k forks source link

Hide title depending on the result of the localStorage #423

Open danielswater opened 5 years ago

danielswater commented 5 years ago

After the user logs in to the system, I store his data in a localStorage, within a service. Based on this, I need to set up a menu with the permissions of each user. Each menu item is in a BlurAdmin module. I can recover the data, however I can not hide the link, if the user does not have the permission. Here is the code:

`(function() { 'use strict';

angular.module('BlurAdmin.pages.dashboard', [])
    .config(routeConfig);

/** @ngInject */
function routeConfig($stateProvider) {

    $stateProvider
        .state('dashboard', {
            resolve: {
                user: function(baSidebarService, $q){
                    var user = JSON.parse(baSidebarService.getStorage());
                    console.log(user)
                      var roles = ["GERENTE","ADMIN"];
                    user.roles.forEach(function(role){
                        if(roles.includes(role.nome)){
                            console.log('ok')
                        }
                        else{
                            return;
                        }
                    })                        
                }
            },
            // if baSidebarService.getStorage() == true
            url: '/dashboard',
            templateUrl: 'app/pages/dashboard/dashboard.html',
            title: "Dashboard",                
            sidebarMeta: {
                icon: 'ion-android-home',
                order: 0,
            },
        });
}

})(); `

Note that within the loop, I make a check if the user data is the same as the rules. The problem is that even though I check that they are different, I can not hide the Dashboard link. I already tried everything, with no success.

How could I do this, for example, depending on localStorage data:

// if baSidebarService.getStorage() == true url: $scope.dashboard, templateUrl: $scope.template, title: $scope.title, sidebarMeta: $scope.sidebar,