<commit_before>define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/_base/array',
    'dojo/on',
    'dojo/query',
    'dojo/dom-class',
    'dojo/dom-style',
    'dojo/dom-attr',
    'dojo/fx',
    'dojo/html',
    'dijit/_WidgetBase',
    'dijit/_TemplatedMixin',
    'dojo/text!./templates/Folder.html'
], function (
    declare,
    lang,
    array,
    on,
    query,
    domClass,
    domStyle,
    domAttr,
    fx,
    html,
    WidgetBase,
    TemplatedMixin,
    folderTemplate
) {
    var _DynamicFolder = declare([WidgetBase, TemplatedMixin], {
        control: null,
        sublayerInfo: null,
        icons: null,
        // ^args
        templateString: folderTemplate,
        _expandClickHandler: null,
        _handlers: [],
        postCreate: function () {
            this.inherited(arguments);
            // Should the control be visible or hidden (depends on subLayerInfos)?
            if (this.control.controlOptions.subLayerInfos && !this.control.controlOptions.includeUnspecifiedLayers) {
                var subLayerInfos = array.map(this.control.controlOptions.subLayerInfos, function (sli) {
                    return sli.id;
                });
                if (array.indexOf(subLayerInfos, this.sublayerInfo.id) < 0) {
                    domClass.add(this.domNode, 'layerControlHidden');
                }
            }
            // Should the control be visible or hidden?
            if (this.control.controlOptions.layerIds && array.indexOf(this.control.controlOptions.layerIds, this.sublayerInfo.id) < 0) {
                domClass.add(this.domNode, 'layerControlHidden');
            }
            var checkNode = this.checkNode;
            domAttr.set(checkNode, 'data-sublayer-id', this.sublayerInfo.id);
            domAttr.set(checkNode, 'data-layer-folder', true);
            domClass.add(checkNode, this.control.layer.id + '-layerControlSublayerCheck');

            this._handlers.push(on(checkNode, 'click', lang.hitch(this, function (event) {

                // prevent click event from bubbling
                if (event.stopPropagation) {
                    event.stopPropagation();
                }

                if (!this._hasAnyInvisibleLayer()) {
                    this._setFolderCheckbox(false, checkNode);
                } else {
                    this._setFolderCheckbox(true, checkNode);
                }
                this._checkboxScaleRange();
            })));
            html.set(this.labelNode, this.sublayerInfo.name);
            this._expandClick();
            if (this.sublayerInfo.minScale !== 0 || this.sublayerInfo.maxScale !== 0) {
                this._checkboxScaleRange();
                this._handlers.push(this.control.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange')));
            }
        },
        // add on event to expandClickNode
        _expandClick: function () {
            var i = this.icons;
            this._handlers.push(this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, function () {
                var expandNode = this.expandNode,
                    iconNode = this.expandIconNode;
                if (domStyle.get(expandNode, 'display') === 'none') {
                    fx.wipeIn({
                        node: expandNode,
                        duration: 300
                    }).play();
                    domClass.replace(iconNode, i.folderOpen, i.folder);
                } else {
                    fx.wipeOut({
                        node: expandNode,
                        duration: 300
                    }).play();
                    domClass.replace(iconNode, i.folder, i.folderOpen);
                }
            })));
        },
        // toggles visibility of all sublayers
        _setFolderCheckbox: function (checked, checkNode, isChildFolder) {
            var i = this.icons,
                dataChecked = (checked) ? 'checked' : 'unchecked',
                slNodes = this._getSubLayerNodes();
            checkNode = checkNode || this.checkNode;
            array.forEach(slNodes, lang.hitch(this, function (node) {

                // child is folder
                if (domAttr.get(node, 'data-layer-folder')) {
                    var folderControl = this._getFolderControl(node);
                    if (folderControl) {
                        folderControl._setFolderCheckbox(checked, node, true);
                    }
                // child is sub layer
                } else {
                    domAttr.set(node, 'data-checked', dataChecked);
                    if (checked) {
                        domClass.replace(node, i.checked, i.unchecked);
                    } else {
                        domClass.replace(node, i.unchecked, i.checked);
                    }
                }
            }));

            // wait until all folders in hierarchy have been
            // processed before setting the layer's visible layers
            if (!isChildFolder) {
                this.control._setVisibleLayers();
            }
        },

        _hasAnyVisibleLayer: function () {
            var slNodes = this._getSubLayerNodes();
            return array.some(slNodes, lang.hitch(this, function (node) {
                if (domAttr.get(node, 'data-layer-folder')) {
                    var folderControl = this._getFolderControl(node);
                    if (folderControl) {
                        return folderControl._hasAnyVisibleLayer();
                    }
                    return true;
                }
                return (domAttr.get(node, 'data-checked') === 'checked');
            }));
        },

        _hasAnyInvisibleLayer: function () {
            var slNodes = this._getSubLayerNodes();
            return array.some(slNodes, lang.hitch(this, function (node) {
                if (domAttr.get(node, 'data-layer-folder')) {
                    var folderControl = this._getFolderControl(node);
                    if (folderControl) {
                        return folderControl._hasAnyInvisibleLayer();
                    }
                    return true;
                }
                return (domAttr.get(node, 'data-checked') !== 'checked');
            }));
        },

        _getSubLayerNodes: function () {
            var layerIds = this.control.controlOptions.layerIds;
            var subLayerInfos = [];
            if (this.control.controlOptions.subLayerInfos && !this.control.controlOptions.includeUnspecifiedLayers) {
                subLayerInfos = array.map(this.control.controlOptions.subLayerInfos, function (sli) {
                    return sli.id;
                });
            }

            var subLayerNodes = query('.' + this.control.layer.id + '-layerControlSublayerCheck', this.domNode);
            return array.filter(subLayerNodes, lang.hitch(this, function (node) {
                var subLayerID = parseInt(domAttr.get(node, 'data-sublayer-id'), 10);
                // is the sublayer contained in this folder
                if (array.indexOf(this.sublayerInfo.subLayerIds, subLayerID) < 0) {
                    return false;
                // is the sublayer included in layer's layerIds (if they are defined)
                } else if (layerIds.length && array.indexOf(layerIds, subLayerID) < 0) {
                    return false;
                // is the sublayer included in layer's subLayerInfos (if they are defined)
                } else if (subLayerInfos.length && array.indexOf(subLayerInfos, subLayerID) < 0) {
                    return false;
                }
                return true;
            }));
        },

        _getFolderControl: function (node) {
            var subLayerID = parseInt(domAttr.get(node, 'data-sublayer-id'), 10);
            var controls = array.filter(this.control._folderControls, function (control) {<commit_msg>ensure that layerIds variable is assigned a value..<commit_after>define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/_base/array',
    'dojo/on',
    'dojo/query',
    'dojo/dom-class',
    'dojo/dom-style',
    'dojo/dom-attr',
    'dojo/fx',
    'dojo/html',
    'dijit/_WidgetBase',
    'dijit/_TemplatedMixin',
    'dojo/text!./templates/Folder.html'
], function (
    declare,
    lang,
    array,
    on,
    query,
    domClass,
    domStyle,
    domAttr,
    fx,
    html,
    WidgetBase,
    TemplatedMixin,
    folderTemplate
) {
    var _DynamicFolder = declare([WidgetBase, TemplatedMixin], {
        control: null,
        sublayerInfo: null,
        icons: null,
        // ^args
        templateString: folderTemplate,
        _expandClickHandler: null,
        _handlers: [],
        postCreate: function () {
            this.inherited(arguments);
            // Should the control be visible or hidden (depends on subLayerInfos)?
            if (this.control.controlOptions.subLayerInfos && !this.control.controlOptions.includeUnspecifiedLayers) {
                var subLayerInfos = array.map(this.control.controlOptions.subLayerInfos, function (sli) {
                    return sli.id;
                });
                if (array.indexOf(subLayerInfos, this.sublayerInfo.id) < 0) {
                    domClass.add(this.domNode, 'layerControlHidden');
                }
            }
            // Should the control be visible or hidden?
            if (this.control.controlOptions.layerIds && array.indexOf(this.control.controlOptions.layerIds, this.sublayerInfo.id) < 0) {
                domClass.add(this.domNode, 'layerControlHidden');
            }
            var checkNode = this.checkNode;
            domAttr.set(checkNode, 'data-sublayer-id', this.sublayerInfo.id);
            domAttr.set(checkNode, 'data-layer-folder', true);
            domClass.add(checkNode, this.control.layer.id + '-layerControlSublayerCheck');

            this._handlers.push(on(checkNode, 'click', lang.hitch(this, function (event) {

                // prevent click event from bubbling
                if (event.stopPropagation) {
                    event.stopPropagation();
                }

                if (!this._hasAnyInvisibleLayer()) {
                    this._setFolderCheckbox(false, checkNode);
                } else {
                    this._setFolderCheckbox(true, checkNode);
                }
                this._checkboxScaleRange();
            })));
            html.set(this.labelNode, this.sublayerInfo.name);
            this._expandClick();
            if (this.sublayerInfo.minScale !== 0 || this.sublayerInfo.maxScale !== 0) {
                this._checkboxScaleRange();
                this._handlers.push(this.control.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange')));
            }
        },
        // add on event to expandClickNode
        _expandClick: function () {
            var i = this.icons;
            this._handlers.push(this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, function () {
                var expandNode = this.expandNode,
                    iconNode = this.expandIconNode;
                if (domStyle.get(expandNode, 'display') === 'none') {
                    fx.wipeIn({
                        node: expandNode,
                        duration: 300
                    }).play();
                    domClass.replace(iconNode, i.folderOpen, i.folder);
                } else {
                    fx.wipeOut({
                        node: expandNode,
                        duration: 300
                    }).play();
                    domClass.replace(iconNode, i.folder, i.folderOpen);
                }
            })));
        },
        // toggles visibility of all sublayers
        _setFolderCheckbox: function (checked, checkNode, isChildFolder) {
            var i = this.icons,
                dataChecked = (checked) ? 'checked' : 'unchecked',
                slNodes = this._getSubLayerNodes();
            checkNode = checkNode || this.checkNode;
            array.forEach(slNodes, lang.hitch(this, function (node) {

                // child is folder
                if (domAttr.get(node, 'data-layer-folder')) {
                    var folderControl = this._getFolderControl(node);
                    if (folderControl) {
                        folderControl._setFolderCheckbox(checked, node, true);
                    }
                // child is sub layer
                } else {
                    domAttr.set(node, 'data-checked', dataChecked);
                    if (checked) {
                        domClass.replace(node, i.checked, i.unchecked);
                    } else {
                        domClass.replace(node, i.unchecked, i.checked);
                    }
                }
            }));

            // wait until all folders in hierarchy have been
            // processed before setting the layer's visible layers
            if (!isChildFolder) {
                this.control._setVisibleLayers();
            }
        },

        _hasAnyVisibleLayer: function () {
            var slNodes = this._getSubLayerNodes();
            return array.some(slNodes, lang.hitch(this, function (node) {
                if (domAttr.get(node, 'data-layer-folder')) {
                    var folderControl = this._getFolderControl(node);
                    if (folderControl) {
                        return folderControl._hasAnyVisibleLayer();
                    }
                    return true;
                }
                return (domAttr.get(node, 'data-checked') === 'checked');
            }));
        },

        _hasAnyInvisibleLayer: function () {
            var slNodes = this._getSubLayerNodes();
            return array.some(slNodes, lang.hitch(this, function (node) {
                if (domAttr.get(node, 'data-layer-folder')) {
                    var folderControl = this._getFolderControl(node);
                    if (folderControl) {
                        return folderControl._hasAnyInvisibleLayer();
                    }
                    return true;
                }
                return (domAttr.get(node, 'data-checked') !== 'checked');
            }));
        },

        _getSubLayerNodes: function () {
            var layerIds = this.control.controlOptions.layerIds || [];
            var subLayerInfos = [];
            if (this.control.controlOptions.subLayerInfos && !this.control.controlOptions.includeUnspecifiedLayers) {
                subLayerInfos = array.map(this.control.controlOptions.subLayerInfos, function (sli) {
                    return sli.id;
                });
            }

            var subLayerNodes = query('.' + this.control.layer.id + '-layerControlSublayerCheck', this.domNode);
            return array.filter(subLayerNodes, lang.hitch(this, function (node) {
                var subLayerID = parseInt(domAttr.get(node, 'data-sublayer-id'), 10);
                // is the sublayer contained in this folder
                if (array.indexOf(this.sublayerInfo.subLayerIds, subLayerID) < 0) {
                    return false;
                // is the sublayer included in layer's layerIds (if they are defined)
                } else if (layerIds.length && array.indexOf(layerIds, subLayerID) < 0) {
                    return false;
                // is the sublayer included in layer's subLayerInfos (if they are defined)
                } else if (subLayerInfos.length && array.indexOf(subLayerInfos, subLayerID) < 0) {
                    return false;
                }
                return true;
            }));
        },

        _getFolderControl: function (node) {
            var subLayerID = parseInt(domAttr.get(node, 'data-sublayer-id'), 10);
            var controls = array.filter(this.control._folderControls, function (control) {
{'fraction_non_alphanumeric': 0.10907482305358948, 'fraction_numerical': 0.0021486349848331646, 'mean_word_length': 1.551596259271203, 'pattern_counts': {'":': 0, '<': 13, '<?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': '529904', 'n_tokens_mistral': 4261, 'n_tokens_neox': 4054, 'n_words': 807}