<commit_before>/*************************************************
 * Copyright (c) 2016 Ansible, Inc.
 *
 * All Rights Reserved
 *************************************************/

import { templateUrl } from '../../shared/template-url/template-url.factory';
import InventoriesManage from './inventory-manage.controller';
import BreadcrumbsController from './breadcrumbs/breadcrumbs.controller';
import HostsListController from './hosts/hosts-list.controller';
import GroupsListController from './groups/groups-list.controller';

export default {
    name: 'inventoryManage',
    data: {
        socket: {
            "groups": {
                "jobs": ["status_changed"]
            }
        }
    },
    // instead of a single 'searchPrefix' attribute, provide hard-coded search params
    url: '/inventories/:inventory_id/manage?{group:int}{group_search:queryset}{host_search:queryset}',
    params: {
        group: {
            array: true
        },
        group_search: {
            value: {
                page_size: '20',
                page: '1',
                order_by: 'name',
            },
            squash: true,
            dynamic: true
        },
        host_search: {
            value: {
                page_size: '20',
                page: '1',
                order_by: 'name',
            },
            squash: true,
            dynamic: true
        }
    },
    ncyBreadcrumb: {
        skip: true // Never display this state in ncy-breadcrumb.
    },
    // enforce uniqueness in group param
    onEnter: function($stateParams) {
        $stateParams.group = _.uniq($stateParams.group);
    },
    resolve: {
        groupsUrl: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
            return $stateParams.group && $stateParams.group.length > 0 ?
                // nested context - provide this node's children
                InventoryManageService.childGroupsUrl(_.last($stateParams.group)) :
                // root context - provide root nodes
                InventoryManageService.rootGroupsUrl($stateParams.inventory_id);
        }],
        hostsUrl: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
            return $stateParams.group && $stateParams.group.length > 0 ?
                // nested context - provide all hosts managed by nodes
                InventoryManageService.childHostsUrl(_.last($stateParams.group)) :
                // root context - provide all hosts in an inventory
                InventoryManageService.rootHostsUrl($stateParams.inventory_id);
        }],
        inventoryData: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
            return InventoryManageService.getInventory($stateParams.inventory_id).then(res => res.data);
        }],
        breadCrumbData: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
            return $stateParams.group && $stateParams.group.length > 0 ?
                // nested context - provide breadcrumb data
                InventoryManageService.getBreadcrumbs($stateParams.group).then(res => res.data.results) :
                // root context
                false;
        }],
        groupsDataset: ['InventoryGroups', 'QuerySet', '$stateParams', 'groupsUrl', (list, qs, $stateParams, groupsUrl) => {
            let path = groupsUrl;
            return qs.search(path, $stateParams[`${list.iterator}_search`]);
        }],
        hostsDataset: ['InventoryHosts', 'QuerySet', '$stateParams', 'hostsUrl', (list, qs, $stateParams, hostsUrl) => {
            let path = hostsUrl;
            return qs.search(path, $stateParams[`${list.iterator}_search`]);
        }]
    },
    views: {
        // target the ui-view with name "groupBreadcrumbs" at the root view
        'groupBreadcrumbs@': {
            controller: BreadcrumbsController,
            templateUrl: templateUrl('inventories/manage/breadcrumbs/breadcrumbs')
        },
        // target the un-named ui-view @ root level
        '@': {
            templateUrl: templateUrl('inventories/manage/inventory-manage'),
            controller: InventoriesManage
        },
        // target ui-views with name@inventoryManage state
        'groupsList@inventoryManage': {
            templateProvider: function(InventoryGroups, generateList, $templateRequest, $stateParams, GetBasePath) {
                let list = _.cloneDeep(InventoryGroups);
                if($stateParams && $stateParams.group) {
                    list.basePath = GetBasePath('groups') + $stateParams.group[$stateParams.group.length-1] + '/children';
                }
                let html = generateList.build({
                    list: list,
                    mode: 'edit'
                });
                html = generateList.wrapPanel(html);
                // Include the custom group delete modal template
                return $templateRequest(templateUrl('inventories/manage/groups/groups-list')).then((template) => {
                    return html.concat(template);
                });
            },
            controller: GroupsListController
        },
        'hostsList@inventoryManage': {
            templateProvider: function(InventoryHosts, generateList, $stateParams, GetBasePath) {
                let list = _.cloneDeep(InventoryHosts);
                if($stateParams && $stateParams.group) {
                    list.basePath = GetBasePath('groups') + $stateParams.group[$stateParams.group.length-1] + '/all_hosts';
                }
                let html = generateList.build({
                    list: list,
                    mode: 'edit'
                });
                return generateList.wrapPanel(html);
            },
            controller: HostsListController
        }
    }
};<commit_msg>Fixed basePath at the root level of the inventory manage (thanks @jared)<commit_after>/*************************************************
 * Copyright (c) 2016 Ansible, Inc.
 *
 * All Rights Reserved
 *************************************************/

import { templateUrl } from '../../shared/template-url/template-url.factory';
import InventoriesManage from './inventory-manage.controller';
import BreadcrumbsController from './breadcrumbs/breadcrumbs.controller';
import HostsListController from './hosts/hosts-list.controller';
import GroupsListController from './groups/groups-list.controller';

export default {
    name: 'inventoryManage',
    data: {
        socket: {
            "groups": {
                "jobs": ["status_changed"]
            }
        }
    },
    // instead of a single 'searchPrefix' attribute, provide hard-coded search params
    url: '/inventories/:inventory_id/manage?{group:int}{group_search:queryset}{host_search:queryset}',
    params: {
        group: {
            array: true
        },
        group_search: {
            value: {
                page_size: '20',
                page: '1',
                order_by: 'name',
            },
            squash: true,
            dynamic: true
        },
        host_search: {
            value: {
                page_size: '20',
                page: '1',
                order_by: 'name',
            },
            squash: true,
            dynamic: true
        }
    },
    ncyBreadcrumb: {
        skip: true // Never display this state in ncy-breadcrumb.
    },
    // enforce uniqueness in group param
    onEnter: function($stateParams) {
        $stateParams.group = _.uniq($stateParams.group);
    },
    resolve: {
        groupsUrl: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
            return $stateParams.group && $stateParams.group.length > 0 ?
                // nested context - provide this node's children
                InventoryManageService.childGroupsUrl(_.last($stateParams.group)) :
                // root context - provide root nodes
                InventoryManageService.rootGroupsUrl($stateParams.inventory_id);
        }],
        hostsUrl: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
            return $stateParams.group && $stateParams.group.length > 0 ?
                // nested context - provide all hosts managed by nodes
                InventoryManageService.childHostsUrl(_.last($stateParams.group)) :
                // root context - provide all hosts in an inventory
                InventoryManageService.rootHostsUrl($stateParams.inventory_id);
        }],
        inventoryData: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
            return InventoryManageService.getInventory($stateParams.inventory_id).then(res => res.data);
        }],
        breadCrumbData: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
            return $stateParams.group && $stateParams.group.length > 0 ?
                // nested context - provide breadcrumb data
                InventoryManageService.getBreadcrumbs($stateParams.group).then(res => res.data.results) :
                // root context
                false;
        }],
        groupsDataset: ['InventoryGroups', 'QuerySet', '$stateParams', 'groupsUrl', (list, qs, $stateParams, groupsUrl) => {
            let path = groupsUrl;
            return qs.search(path, $stateParams[`${list.iterator}_search`]);
        }],
        hostsDataset: ['InventoryHosts', 'QuerySet', '$stateParams', 'hostsUrl', (list, qs, $stateParams, hostsUrl) => {
            let path = hostsUrl;
            return qs.search(path, $stateParams[`${list.iterator}_search`]);
        }]
    },
    views: {
        // target the ui-view with name "groupBreadcrumbs" at the root view
        'groupBreadcrumbs@': {
            controller: BreadcrumbsController,
            templateUrl: templateUrl('inventories/manage/breadcrumbs/breadcrumbs')
        },
        // target the un-named ui-view @ root level
        '@': {
            templateUrl: templateUrl('inventories/manage/inventory-manage'),
            controller: InventoriesManage
        },
        // target ui-views with name@inventoryManage state
        'groupsList@inventoryManage': {
            templateProvider: function(InventoryGroups, generateList, $templateRequest, $stateParams, GetBasePath) {
                let list = _.cloneDeep(InventoryGroups);
                if($stateParams && $stateParams.group) {
                    list.basePath = GetBasePath('groups') + _.last($stateParams.group) + '/children';
                }
                else {
                    //reaches here if the user is on the root level group
                    list.basePath = GetBasePath('inventory') + $stateParams.inventory_id + '/root_groups';
                }
                let html = generateList.build({
                    list: list,
                    mode: 'edit'
                });
                html = generateList.wrapPanel(html);
                // Include the custom group delete modal template
                return $templateRequest(templateUrl('inventories/manage/groups/groups-list')).then((template) => {
                    return html.concat(template);
                });
            },
            controller: GroupsListController
        },
        'hostsList@inventoryManage': {
            templateProvider: function(InventoryHosts, generateList, $stateParams, GetBasePath) {
                let list = _.cloneDeep(InventoryHosts);
                if($stateParams && $stateParams.group) {
                    list.basePath = GetBasePath('groups') + _.last($stateParams.group) + '/all_hosts';
                }
                else {
                    //reaches here if the user is on the root level group
                    list.basePath = GetBasePath('inventory') + $stateParams.inventory_id + '/hosts';
                }
                let html = generateList.build({
                    list: list,
                    mode: 'edit'
                });
                return generateList.wrapPanel(html);
            },
            controller: HostsListController
        }
    }
};
{'fraction_non_alphanumeric': 0.1272816567078661, 'fraction_numerical': 0.002291888352295981, 'mean_word_length': 2.0182806324110674, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 19, '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': '2890964', 'n_tokens_mistral': 3207, 'n_tokens_neox': 3079, 'n_words': 639}