page/middleware.js
function parseNavItem (item) {
        if (item.route === req.path) {
            item.isActive = true;
        }

        // replace object by array structure
        var childArray = [];
        for (var child in item.children) {
            var subItem = parseNavItem( item.children[ child ] );
            if (subItem.isActive || subItem.hasActiveChildren) {
                item.hasActiveChildren = true;
            }
            // check if user can access item
            if (userHasAccess(subItem)) {
                childArray.push(subItem);
            }
        }
        // sort by _w
        childArray.sort(function (a, b) { return a._w - b._w });
        item.children = childArray;

        return item;
    }
function parseNavItem (item) {
        if (item.route === req.path) {
            item.isActive = true;
        }

        // replace object by array structure
        var childArray = [];
        for (var child in item.children) {
            var subItem = parseNavItem( item.children[ child ] );
            if (subItem.isActive || subItem.hasActiveChildren) {
                item.hasActiveChildren = true;
            }
            // check if user can access item
            if (userHasAccess(subItem)) {
                childArray.push(subItem);
            }
        }
        // sort by _w
        childArray.sort(function (a, b) { return a._w - b._w });
        item.children = childArray;

        return item;
    }
function parseNavItem ( item ) { if ( item . route === req . path ) { item . isActive = true ; } // replace object by array structure var childArray = [ ] ; for ( var child in item . children ) { var subItem = parseNavItem ( item . children [ child ] ) ; if ( subItem . isActive || subItem . hasActiveChildren ) { item . hasActiveChildren = true ; } // check if user can access item if ( userHasAccess ( subItem ) ) { childArray . push ( subItem ) ; } } // sort by _w childArray . sort ( function ( a , b ) { return a . _w - b . _w } ) ; item . children = childArray ; return item ; }
Method recursively iterates over items and adds `isActive` and `hasActiveChild` fields
Method recursively iterates over items and adds isActive and hasActiveChild fields