{"size": 3020, "ext": "js", "max_stars_repo_path": "public/js/app/layout/layout.service.js", "max_stars_repo_name": "leonardo-freitas-1995/Routes-NodeServer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/js/app/layout/layout.service.js", "max_issues_repo_name": "leonardo-freitas-1995/Routes-NodeServer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/js/app/layout/layout.service.js", "max_forks_repo_name": "leonardo-freitas-1995/Routes-NodeServer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.2072072072, "max_line_length": 120, "alphanum_fraction": 0.4986754967}
(function () {
    angular
        .module('routesApp')
        .factory('layout', Service);
    Service.$inject = ['$location', '$mdMedia', '$mdSidenav', 'identityService', 'language', 'notifier', 'authService'];
    function Service($location, $mdMedia, $mdSidenav, identityService, language, notifier, authService) {

        var pages = {
            "dashboard": {name: "sidenav.dashboard", url: "/dashboard"},
            "profile": {name: "common.profile", url: "/profile"},
            "products": {name: "sidenav.products", url: "/products"},
        };
        
        var commonSidenav = [
            pages.dashboard
        ];
        
        var accessSidenavs = [
            {
                role: "admin",
                items: [
                    pages.products
                ]
            }
        ];

        var sidenavItems = [];

        var breadcrumbs = {
            "/dashboard": [
                pages.dashboard
            ],
            "/profile": [
                pages.profile
            ],
            "/products": [
                pages.products
            ]
        };

        var fullPageRoutes = [
            "/index"
        ];

        return {
            hasSidenav: hasSidenav,
            isSidenavFixed: isSidenavFixed,
            getBreadcrumbs: getBreadcrumbs,
            toggleSidenav: toggleSidenav,
            getCurrentUserInfo: getCurrentUserInfo,
            getSidenavItems: getSidenavItems,
            getAccessSidenavItems: getAccessSidenavItems,
            goTo: goTo,
            isActiveView: isActiveView,
            openMenu: openMenu,
            signout: signout,
            hasRoleAccess: hasRoleAccess
        };

        function hasSidenav(){
            return !fullPageRoutes.contains($location.path());
        }
        
        function isSidenavFixed(){
            return $mdMedia('gt-md');
        }

        function getBreadcrumbs(){
            return breadcrumbs[$location.path()];
        }

        function toggleSidenav(){
            $mdSidenav('left').toggle();
        }

        function getCurrentUserInfo(attr){
            return identityService.currentUser[attr] || null;
        }

        function getSidenavItems(){
            return commonSidenav;
        }

        function getAccessSidenavItems(){
            return accessSidenavs;
        }

        function goTo(path, params){
            $location.path(path).search(params || {});
        }

        function isActiveView(path){
            return $location.path() === path;
        }

        function openMenu($mdOpenMenu, $event){
            $mdOpenMenu($event);
        }

        function signout(){
            authService.logoutUser().then(function () {
                notifier.success('common.logoutSuccess');
                $location.path('/index');
            });
        }

        function hasRoleAccess(role){
            return identityService.isAuthorized(role) || identityService.isAuthorized("root");
        }
    }
})();