<commit_before>
SearchMenuController.$inject = ['$rootScope', '$filter', '$location', '$route', 'searchProviderService', 'api'];
export default function SearchMenuController($rootScope, $filter, $location, $route, searchProviderService, api) {
    let providerLabels = {};

    const SUPERDESK_PROVIDER = {
        _id: '',
        name: 'Superdesk',
    };

    /**
     * Activate search shortcut
     *
     * @param {Object} provider
     */
    this.loadSearchShortcut = (provider) => {
        const repo = provider ? (provider._id || provider.search_provider || provider.source) : '';

        $location.url('/search?repo=' + repo);
        $route.reload();
    };

    /**
     * Get provider label
     *
     * Keep it undefined until there is some value so one time watch will work.
     *
     * @param {Object} provider
     */
    this.providerLabel = (provider) => provider && (provider.name || providerLabels[provider.source]) || undefined;

    // init search providers
    if ($rootScope.config && $rootScope.config.features && $rootScope.config.features.searchShortcut) {
        api.search_providers.query({max_results: 200, is_closed: {$ne: true}})
            .then((result) => {
                this.providers = $filter('sortByName')(result._items, 'search_provider');

                const defaultProvider = this.providers.find((provider) => provider.is_default);

                if (defaultProvider) {
                    this.providers = this.providers.filter((provider) => provider !== defaultProvider);
                    this.providers.unshift(SUPERDESK_PROVIDER);
                    this.providers.unshift(defaultProvider);
                } else {
                    this.providers.unshift(SUPERDESK_PROVIDER);
                }

                console.info('providers', this.providers);
            });

        searchProviderService.getAllowedProviderTypes()
            .then((providerTypes) => {
                providerLabels = searchProviderService.getProviderLabels(providerTypes);
            });
    }
}<commit_msg>fix(search-providers): avoid closed providers in search menu<commit_after>
SearchMenuController.$inject = ['$rootScope', '$filter', '$location', '$route', 'searchProviderService', 'api'];
export default function SearchMenuController($rootScope, $filter, $location, $route, searchProviderService, api) {
    let providerLabels = {};

    const SUPERDESK_PROVIDER = {
        _id: '',
        name: 'Superdesk',
    };

    /**
     * Activate search shortcut
     *
     * @param {Object} provider
     */
    this.loadSearchShortcut = (provider) => {
        const repo = provider === SUPERDESK_PROVIDER ?
            '' : (provider._id || provider.search_provider || provider.source);

        $location.url('/search?repo=' + repo);
        $route.reload();
    };

    /**
     * Get provider label
     *
     * Keep it undefined until there is some value so one time watch will work.
     *
     * @param {Object} provider
     */
    this.providerLabel = (provider) => provider && (provider.name || providerLabels[provider.source]) || undefined;

    // init search providers
    if ($rootScope.config && $rootScope.config.features && $rootScope.config.features.searchShortcut) {
        api.search_providers.query({max_results: 200, where: {is_closed: {$ne: true}}})
            .then((result) => {
                this.providers = $filter('sortByName')(result._items, 'search_provider');

                const defaultProvider = this.providers.find((provider) => provider.is_default);

                if (defaultProvider) {
                    this.providers = this.providers.filter((provider) => provider !== defaultProvider);
                    this.providers.unshift(SUPERDESK_PROVIDER);
                    this.providers.unshift(defaultProvider);
                } else {
                    this.providers.unshift(SUPERDESK_PROVIDER);
                }
            });

        searchProviderService.getAllowedProviderTypes()
            .then((providerTypes) => {
                providerLabels = searchProviderService.getProviderLabels(providerTypes);
            });
    }
}
{'fraction_non_alphanumeric': 0.13098964603900795, 'fraction_numerical': 0.0014447387430772936, 'mean_word_length': 2.4217462932454694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4437636', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1073, 'n_words': 212}