<commit_before>// The main search module that allows users to view the Preference Terms Dictionary

(function ($) {
    "use strict";
    var search    = fluid.registerNamespace("ctr.components.search");
    var templates = fluid.registerNamespace("ctr.components.templates");

    // TODO:  Create session-scoped variables for query, status, record type, and language, and use if no data is provided.

    search.clearSearchFilter = function(that) {
        that.applier.change("searchSettings.query", undefined);
    };

    search.showClearButton = function (that, show) {
        // Wire in support for clearing the search easily
        var clearButton = that.locate("clear");
        if (show) {
            clearButton.attr("tabIndex",0);
            clearButton.show();
        }
        else {
            clearButton.attr("tabIndex",-1);
            clearButton.hide();
        }
    };

    // Change the search offset and trigger a refresh when a page navigation link is clicked
    search.changePage = function(that,event) {
        var element = $(event.currentTarget);
        var offset = parseInt(element.attr('offset'));

        // If we click on a link that has the same offset as the current value, no change functions are fired.
        that.applier.change("searchSettings.offset", offset);
    };

    // Generate navigation links when the page is refreshed, as the number of pages may have changed
    search.updatePagination = function(that) {
        var container = that.locate("pageLinks");
        container.html("");

        var pages = 1;
        // If the limits are off, we have one page of results, guaranteed
        if (that.model.searchSettings.limit !== -1) {
            if (that.model.count && that.model.count > 0) {
                pages = Math.ceil(that.model.count/that.model.searchSettings.limit);
            }
        }

        var currentPage = 1;
        if (that.model.limit !== -1) {
            currentPage = Math.floor(that.model.searchSettings.offset/that.model.searchSettings.limit) + 1;
        }

        var navStart    = that.locate("navStart");
        var navPrevious = that.locate("navPrevious");
        var navNext     = that.locate("navNext");
        var navEnd      = that.locate("navEnd");

        if (pages === 1) {
            templates.prependTo(container,"search-navigation-page-link",{offset: 0, page: 1});
        }
        else {

            if (currentPage > 1 ) {
                navPrevious.attr('offset', (currentPage - 2) * that.model.searchSettings.limit);
            }

            if (pages > 1 && currentPage < pages) {
                navNext.attr('offset', currentPage * that.model.searchSettings.limit);
                navEnd.attr('offset', (pages-1) * that.model.searchSettings.limit);
            }

            for (var a = pages - 1; a >= 0; a--) {
                var page = a+1;
                var pageOffset = a * that.model.searchSettings.limit;

                if (page === currentPage) {
                    templates.prependTo(container,"search-navigation-page-current-link",{offset: pageOffset, page: page});
                }
                else {
                    templates.prependTo(container,"search-navigation-page-link",{offset: pageOffset, page: page});
                }
            }
        }

        // Fire a "nav loaded" event so that we can wire up the appropriate listeners
        that.events.navBarLoaded.fire();
    };
<commit_msg>Fixed display of page navigation link when there is only one page.<commit_after>// The main search module that allows users to view the Preference Terms Dictionary

(function ($) {
    "use strict";
    var search    = fluid.registerNamespace("ctr.components.search");
    var templates = fluid.registerNamespace("ctr.components.templates");

    // TODO:  Create session-scoped variables for query, status, record type, and language, and use if no data is provided.

    search.clearSearchFilter = function(that) {
        that.applier.change("searchSettings.query", undefined);
    };

    search.showClearButton = function (that, show) {
        // Wire in support for clearing the search easily
        var clearButton = that.locate("clear");
        if (show) {
            clearButton.attr("tabIndex",0);
            clearButton.show();
        }
        else {
            clearButton.attr("tabIndex",-1);
            clearButton.hide();
        }
    };

    // Change the search offset and trigger a refresh when a page navigation link is clicked
    search.changePage = function(that,event) {
        var element = $(event.currentTarget);
        var offset = parseInt(element.attr('offset'));

        // If we click on a link that has the same offset as the current value, no change functions are fired.
        that.applier.change("searchSettings.offset", offset);
    };

    // Generate navigation links when the page is refreshed, as the number of pages may have changed
    search.updatePagination = function(that) {
        var container = that.locate("pageLinks");
        container.html("");

        var pages = 1;
        // If the limits are off, we have one page of results, guaranteed
        if (that.model.searchSettings.limit !== -1) {
            if (that.model.count && that.model.count > 0) {
                pages = Math.ceil(that.model.count/that.model.searchSettings.limit);
            }
        }

        var currentPage = 1;
        if (that.model.limit !== -1) {
            currentPage = Math.floor(that.model.searchSettings.offset/that.model.searchSettings.limit) + 1;
        }

        var navStart    = that.locate("navStart");
        var navPrevious = that.locate("navPrevious");
        var navNext     = that.locate("navNext");
        var navEnd      = that.locate("navEnd");

        if (pages === 1) {
            templates.prependTo(container,"search-navigation-page-current-link",{offset: 0, page: 1});
        }
        else {

            if (currentPage > 1 ) {
                navPrevious.attr('offset', (currentPage - 2) * that.model.searchSettings.limit);
            }

            if (pages > 1 && currentPage < pages) {
                navNext.attr('offset', currentPage * that.model.searchSettings.limit);
                navEnd.attr('offset', (pages-1) * that.model.searchSettings.limit);
            }

            for (var a = pages - 1; a >= 0; a--) {
                var page = a+1;
                var pageOffset = a * that.model.searchSettings.limit;

                if (page === currentPage) {
                    templates.prependTo(container,"search-navigation-page-current-link",{offset: pageOffset, page: page});
                }
                else {
                    templates.prependTo(container,"search-navigation-page-link",{offset: pageOffset, page: page});
                }
            }
        }

        // Fire a "nav loaded" event so that we can wire up the appropriate listeners
        that.events.navBarLoaded.fire();
    };

{'fraction_non_alphanumeric': 0.11628240011456394, 'fraction_numerical': 0.005155377344980667, 'mean_word_length': 2.0577933450087564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '2873556', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1809, 'n_words': 505}