<commit_before>(function (enplug, document) {
    'use strict';

    /**
     * Controls the parent dashboard application. Exposes convenient UI controls to developers:
     *
     * - Page status: loading, error, 404.
     * - Loading indicator (with loading, success and error states)
     * - Confirm box with custom text
     * - Confirm unsaved changes box
     * - Change the page header title and buttons
     *
     * @class
     * @extends Sender
     */
    function DashboardSender() {

        // Call parent constructor with namespace
        enplug.classes.Sender.call(this, 'dashboard');

        /**
         * The buttons most recently registered with the dashboard header.
         * Stored locally so that we can respond to click events
         * @type {{ id:string, action:function, text:string, class:string }[]}
         */
        var currentButtons = [];

        /**
         * The last callback registered with the dashboard title bar.
         * @type {function}
         */
        var currentDisplayCallback = function () {};

        /**
         * Keeps track of whether the dashboard is loading mode so clients can check.
         * @type {boolean}
         */
        var isLoading = true;

        /**
         * Sets the last part of the title bar breadcrumb.
         * Set an empty title '' to clear the title.
         * Re-setting this value wipes out the old one.
         *
         * The home/default page for an app should have no title set.
         *
         * @param {string} title
         * @param {function} [onSuccess]
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.setHeaderTitle = function (title, onSuccess, onError) {
            this.validate(title, 'string', 'Header title must be a string.');
            return this.method({
                name: 'set.title',
                params: title,
                successCallback: onSuccess,
                errorCallback: onError,
            });
        };

        /**
         * Sets the current callback for the title bar breadcrumb display selector dropdown.
         * Attaching a callback enables the dropdown, it is disabled by default.
         * The title is reset when the dashboard changes routes.
         *
         * the callback is fired when a display is selected, the callback will get the ID
         * value when a single display is fired, or null when the 'All' selection is selected
         *
         * @param {function} callback -- the callback to call when the display is changed
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.setDisplaySelectorCallback = function (callback, onError) {
            this.validate(callback, 'function', 'To enable the display selector in the page title you must supply a callback function.');

            // throw away previous callback
            currentDisplayCallback = callback;

            return this.method({
                name: 'set.selectorCallback',
                params: callback,
                persistent: true,
                successCallback: function (displayType) {
                    if (typeof currentDisplayCallback === 'function' && displayType !== undefined) {
                        currentDisplayCallback(displayType);
                    }

                    return displayType;
                },

                errorCallback: onError,
            });
        };

        /**
         * Hides or shows the display dropdown selector in the page title breadcrumb bar.
         * Send true to show the selector, false to hide it.
         *
         * @param {boolean} show
         * @param {function} [onSuccess]
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.setDisplaySelectorVisibility = function (show, onSuccess, onError) {
            this.validate(show, 'boolean', 'Setting the display selector visibility requires a boolean argument, true to show or false to hide.');

            return this.method({
                name: 'set.selectorEnabled',
                params: show,
                successCallback: onSuccess,
                errorCallback: onError,
            });
        };

        /**
         * Switches to account view aka "All" selection of instance selector
         *
         * @param {function} [onSuccess]
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.switchToAccountView = function (onSuccess, onError) {
            return this.method({
                name: 'switchToAccountView',
                successCallback: onSuccess,
                errorCallback: onError,
            });
        };

        /**
         * Sets the primary action buttons for a page in the titlebar.
         *
         * Accepts either a single button object, or an array of buttons.
         * Each button must have a button.action callback.
         *
         * @param {{ text:string, class:string, action:function, disabled:boolean }[]} buttons
         * @param {function} [onSuccess]
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.setHeaderButtons = function (buttons, onSuccess, onError) {
            this.validate(buttons, 'object', 'Header buttons must be an object (single) or array (multiple).');

            // Reset any buttons we may have stored<commit_msg>Replace switchToAccountView with a generic switchToView<commit_after>(function (enplug, document) {
    'use strict';

    /**
     * Controls the parent dashboard application. Exposes convenient UI controls to developers:
     *
     * - Page status: loading, error, 404.
     * - Loading indicator (with loading, success and error states)
     * - Confirm box with custom text
     * - Confirm unsaved changes box
     * - Change the page header title and buttons
     *
     * @class
     * @extends Sender
     */
    function DashboardSender() {

        // Call parent constructor with namespace
        enplug.classes.Sender.call(this, 'dashboard');

        /**
         * The buttons most recently registered with the dashboard header.
         * Stored locally so that we can respond to click events
         * @type {{ id:string, action:function, text:string, class:string }[]}
         */
        var currentButtons = [];

        /**
         * The last callback registered with the dashboard title bar.
         * @type {function}
         */
        var currentDisplayCallback = function () {};

        /**
         * Keeps track of whether the dashboard is loading mode so clients can check.
         * @type {boolean}
         */
        var isLoading = true;

        /**
         * Sets the last part of the title bar breadcrumb.
         * Set an empty title '' to clear the title.
         * Re-setting this value wipes out the old one.
         *
         * The home/default page for an app should have no title set.
         *
         * @param {string} title
         * @param {function} [onSuccess]
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.setHeaderTitle = function (title, onSuccess, onError) {
            this.validate(title, 'string', 'Header title must be a string.');
            return this.method({
                name: 'set.title',
                params: title,
                successCallback: onSuccess,
                errorCallback: onError,
            });
        };

        /**
         * Sets the current callback for the title bar breadcrumb display selector dropdown.
         * Attaching a callback enables the dropdown, it is disabled by default.
         * The title is reset when the dashboard changes routes.
         *
         * the callback is fired when a display is selected, the callback will get the ID
         * value when a single display is fired, or null when the 'All' selection is selected
         *
         * @param {function} callback -- the callback to call when the display is changed
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.setDisplaySelectorCallback = function (callback, onError) {
            this.validate(callback, 'function', 'To enable the display selector in the page title you must supply a callback function.');

            // throw away previous callback
            currentDisplayCallback = callback;

            return this.method({
                name: 'set.selectorCallback',
                params: callback,
                persistent: true,
                successCallback: function (displayType) {
                    if (typeof currentDisplayCallback === 'function' && displayType !== undefined) {
                        currentDisplayCallback(displayType);
                    }

                    return displayType;
                },

                errorCallback: onError,
            });
        };

        /**
         * Hides or shows the display dropdown selector in the page title breadcrumb bar.
         * Send true to show the selector, false to hide it.
         *
         * @param {boolean} show
         * @param {function} [onSuccess]
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.setDisplaySelectorVisibility = function (show, onSuccess, onError) {
            this.validate(show, 'boolean', 'Setting the display selector visibility requires a boolean argument, true to show or false to hide.');

            return this.method({
                name: 'set.selectorEnabled',
                params: show,
                successCallback: onSuccess,
                errorCallback: onError,
            });
        };

        /**
         * Switches to account view aka "All" selection of instance selector or DisplayGroup view
         *
         * @param {boolean} displayGroupId
         * @param {function} [onSuccess]
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.switchToView = function (displayGroupId, onSuccess, onError) {
            return this.method({
                name: 'switchToView',
                params: displayGroupId,
                successCallback: onSuccess,
                errorCallback: onError,
            });
        };


        /**
         * Sets the primary action buttons for a page in the titlebar.
         *
         * Accepts either a single button object, or an array of buttons.
         * Each button must have a button.action callback.
         *
         * @param {{ text:string, class:string, action:function, disabled:boolean }[]} buttons
         * @param {function} [onSuccess]
         * @param {function} [onError]
         * @returns {number} callId
         */
        this.setHeaderButtons = function (buttons, onSuccess, onError) {
            this.validate(buttons, 'object', 'Header buttons must be an object (single) or array (multiple).');

            // Reset any buttons we may have stored
{'fraction_non_alphanumeric': 0.08658282819144124, 'fraction_numerical': 0.0005428390482222021, 'mean_word_length': 1.7648824412206103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3778571', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2567, 'n_words': 977}