<commit_before>var DrilldownOptionFilterControl = function (options) {
    var self = this;

    self.notification = new DrilldownFinalNotification(options.notifications);
    self.controls = ko.observableArray(ko.utils.arrayMap(options.controls, function (select) {
        return new DrilldownOption(select, options.drilldown_map);
    }));

    self.init = function () {
        for (var op; op < options.selected.length; op++) {
            self.controls()[op].selected(options.selected[op]);
            self.updateNextDrilldown(self.controls()[op].level);
        }
    };

    self.updateNextDrilldown = function (trigger_level) {
        var current_control = self.controls()[trigger_level];
        var current_selection = current_control.selected(),
            current_options = current_control.control_options();

        if (trigger_level+1 === self.controls().length) {
            self.notification.changeMessage(current_selection);
            return null;
        }
        self.notification.changeMessage('');

        var current_index = _.indexOf(_.pluck(current_options, 'val'), current_selection);
        for (var l = trigger_level+1; l < self.controls().length; l++) {
            if (current_index >= 0 && l === trigger_level+1) {
                var next_options = current_options[current_index].next;
                self.controls()[trigger_level+1].control_options(next_options);
            } else {
                self.controls()[l].control_options([]);
            }
        }
    };

};

var DrilldownFinalNotification = function (notifications) {
    var self = this;
    self.notifications = notifications;
    self.message = ko.observable();

    self.is_visible = ko.computed(function () {
        return !!self.message();
    });

    self.changeMessage = function (key) {
        self.message(self.notifications[key]);
        $('.drilldown-notification-tooltip').tooltip();
    };
};

var DrilldownOption = function (select, drilldown_map) {
    var self = this;
    self.label = select.label;
    self.default_text = select.default_text;
    self.slug = select.slug;
    self.level = select.level;

    self.control_options = ko.observableArray((self.level === 0) ? drilldown_map : []);
    self.selected = ko.observable();

    self.is_visible = ko.computed(function () {
        return !!(self.control_options().length);
    });

    self.show_next_drilldown = ko.computed(function () {
        return !(self.control_options().length);
    });
};

$.fn.drilldownOptionFilter = function (options) {
    this.each(function(i) {
        var viewModel = new DrilldownOptionFilterControl(options);
        ko.applyBindings(viewModel, $(this).get(i));
        viewModel.init();
    });
};<commit_msg>small bug<commit_after>var DrilldownOptionFilterControl = function (options) {
    var self = this;

    self.notification = new DrilldownFinalNotification(options.notifications);
    self.controls = ko.observableArray(ko.utils.arrayMap(options.controls, function (select) {
        return new DrilldownOption(select, options.drilldown_map);
    }));

    self.init = function () {
        for (var op = 0; op < options.selected.length; op++) {
            self.controls()[op].selected(options.selected[op]);
            self.updateNextDrilldown(self.controls()[op].level);
        }
    };

    self.updateNextDrilldown = function (trigger_level) {
        var current_control = self.controls()[trigger_level];
        var current_selection = current_control.selected(),
            current_options = current_control.control_options();

        if (trigger_level+1 === self.controls().length) {
            self.notification.changeMessage(current_selection);
            return null;
        }
        self.notification.changeMessage('');

        var current_index = _.indexOf(_.pluck(current_options, 'val'), current_selection);
        for (var l = trigger_level+1; l < self.controls().length; l++) {
            if (current_index >= 0 && l === trigger_level+1) {
                var next_options = current_options[current_index].next;
                self.controls()[trigger_level+1].control_options(next_options);
            } else {
                self.controls()[l].control_options([]);
            }
        }
    };

};

var DrilldownFinalNotification = function (notifications) {
    var self = this;
    self.notifications = notifications;
    self.message = ko.observable();

    self.is_visible = ko.computed(function () {
        return !!self.message();
    });

    self.changeMessage = function (key) {
        self.message(self.notifications[key]);
        $('.drilldown-notification-tooltip').tooltip();
    };
};

var DrilldownOption = function (select, drilldown_map) {
    var self = this;
    self.label = select.label;
    self.default_text = select.default_text;
    self.slug = select.slug;
    self.level = select.level;

    self.control_options = ko.observableArray((self.level === 0) ? drilldown_map : []);
    self.selected = ko.observable();

    self.is_visible = ko.computed(function () {
        return !!(self.control_options().length);
    });

    self.show_next_drilldown = ko.computed(function () {
        return !(self.control_options().length);
    });
};

$.fn.drilldownOptionFilter = function (options) {
    this.each(function(i) {
        var viewModel = new DrilldownOptionFilterControl(options);
        ko.applyBindings(viewModel, $(this).get(i));
        viewModel.init();
    });
};
{'fraction_non_alphanumeric': 0.13646328096455973, 'fraction_numerical': 0.0023748629886737303, 'mean_word_length': 2.871994342291372, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1892181', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1579, 'n_words': 262}