<commit_before>import EventEmitter from 'events';
import _ from 'underscore';

class MenuManager extends EventEmitter {

    menuItemsFlat = {};
    menuItemsTree = [];

    constructor (wrapper) {
        super();
        this.wrapper = wrapper;

        this.wrapper.on('preReady', () => {
            this.wrapper.groupManager.on('newGroup', (group) => {
                let groupMenuItems = group.getMenuItems();
                this.indexMenuItems(groupMenuItems);
            });
        });
    }

    indexMenuItems (routes) {
        let sortedRoutes = _(routes).chain()
        .sortBy((menuItem) => menuItem.path.substr(1).split('/').length)
        .sortBy('weight')
        .value();

        sortedRoutes.forEach((route) => {
            this.menuItemsFlat[route.path] = {
                route: route.name ? route.name : '',
                path: route.path,
                title: route.title,
                children: []
            }
        });

        sortedRoutes.forEach(route => {
            let menuItemPathSplit = route.path.split('/');
            let parentPath = menuItemPathSplit;
            parentPath.pop();
            parentPath = parentPath.join('/');

            // Fix for dynamic paths.
            if (!this.menuItemsFlat[parentPath]) {
                this.menuItemsFlat[parentPath] = {
                    children: []
                }
            }

            if ( menuItemPathSplit.length > 1 ) this.menuItemsFlat[parentPath].children.push(this.menuItemsFlat[route.path]);
            else this.menuItemsTree.push(this.menuItemsFlat[route.path]);
        });
    }

    getMenuItemByPath (path) {
        if (this.menuItemsFlat && this.menuItemsFlat[path]) {
            return this.menuItemsFlat[path];
        }
    }

    getSubMenu (context) {
        let submenu = [];

        context.items.forEach((item) => {
            if (item.path === context.$router.currentRoute.path.substr(0, item.path.length)) {
                submenu = item.children;
            }
        });

        return submenu;
    }

}

export default MenuManager;<commit_msg>will now seperate path from plugin name<commit_after>import EventEmitter from 'events';
import _ from 'underscore';

class MenuManager extends EventEmitter {

    menuItemsFlat = {};
    menuItemsTree = [];

    constructor (wrapper) {
        super();
        this.wrapper = wrapper;

        this.wrapper.on('preReady', () => {
            this.wrapper.groupManager.on('newGroup', (group) => {
                let groupMenuItems = group.getMenuItems();

                _(group.plugins).each((plugin) => {
                    if (typeof plugin.settingsForm === 'function') {
                        groupMenuItems.push({
                            title: plugin.settingsForm()['title'],
                            path: '/groups/' + group.slug + '/group-settings/' + plugin.name
                        });
                    }
                });

                this.indexMenuItems(groupMenuItems);
            });
        });
    }

    indexMenuItems (routes) {
        let sortedRoutes = _(routes).chain()
        .sortBy((menuItem) => menuItem.path.substr(1).split('/').length)
        .sortBy('weight')
        .value();

        sortedRoutes.forEach((route) => {
            this.menuItemsFlat[route.path] = {
                route: route.name ? route.name : '',
                path: route.path,
                title: route.title,
                children: []
            }
        });

        sortedRoutes.forEach(route => {
            let menuItemPathSplit = route.path.split('/');
            let parentPath = menuItemPathSplit;
            parentPath.pop();
            parentPath = parentPath.join('/');

            // Fix for dynamic paths.
            if (!this.menuItemsFlat[parentPath]) {
                this.menuItemsFlat[parentPath] = {
                    children: []
                }
            }

            if ( menuItemPathSplit.length > 1 ) this.menuItemsFlat[parentPath].children.push(this.menuItemsFlat[route.path]);
            else this.menuItemsTree.push(this.menuItemsFlat[route.path]);
        });
    }

    getMenuItemByPath (path) {
        if (this.menuItemsFlat && this.menuItemsFlat[path]) {
            return this.menuItemsFlat[path];
        }
    }

    getSubMenu (context) {
        let submenu = [];

        context.items.forEach((item) => {
            if (item.path === context.$router.currentRoute.path.substr(0, item.path.length)) {
                submenu = item.children;
            }
        });

        return submenu;
    }

}

export default MenuManager;
{'fraction_non_alphanumeric': 0.12977758583459295, 'fraction_numerical': 0.0012956164975167351, 'mean_word_length': 1.6378132118451025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4604546', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1230, 'n_words': 200}