<commit_before>/* A base view model to provide a common implementation of knockout client-side table behaviour.
 * Use "call" to apply. E.g. BaseTableViewModel.call(self, args..)
 * Copyright (c) 2014 University of Oxford.
 */
define([
    "knockout",
    "jquery",
    "underscore"
], function (ko, $, _) {
    "use strict";

    return function (entries, initialSortField, initialSortDescending, filterableFields, mapFunction) {
        var self = this;

        self.entries = ko.observableArray(entries);

        // Meta state
        self.filter = ko.observable("");
        self.sortField = ko.observable(initialSortField);
        self.reverseSort = ko.observable(initialSortDescending);
        self.updateSort = function (field) {
            if (self.sortField() === field) {
                self.reverseSort(!self.reverseSort());
            } else {
                self.reverseSort(false);
                self.sortField(field);
            }
        };

        self.visibleEntries = ko.computed(function () {
            // Wrap with underscore
            var iterable = _(self.entries()).chain();

            // Filter
            if (self.filter() && !/^\s*$/.test(self.filter())) {
                var filter = self.filter().toLowerCase();

                iterable = iterable.filter(function (disease) {
                    return _(filterableFields).some(function (field) {
                        return (ko.utils.recursivePeek(disease[field]) || "").toLowerCase().indexOf(filter) !== -1;
                    });
                });
            }

            // Convert to view models
            if (mapFunction) {
                iterable = iterable.map(mapFunction);
            }

            // Hide
            iterable = iterable.filter(function (entry) { return !(ko.utils.recursiveUnwrap(entry.hide) || false); });

            // Sort
            var sortField = self.sortField();
            iterable = iterable.sortBy(function (disease) {
                var sortable = ko.utils.recursivePeek(disease[sortField]) || "";
                if (typeof sortable === "string" || sortable instanceof String) {
                    sortable = sortable.toLowerCase();
                }
                if (typeof sortable === "boolean" || sortable instanceof Boolean) {<commit_msg>Allow JS tables to be sorted by subfields<commit_after>/* A base view model to provide a common implementation of knockout client-side table behaviour.
 * Use "call" to apply. E.g. BaseTableViewModel.call(self, args..)
 * Copyright (c) 2014 University of Oxford.
 */
define([
    "knockout",
    "jquery",
    "underscore"
], function (ko, $, _) {
    "use strict";

    return function (entries, initialSortField, initialSortDescending, filterableFields, mapFunction) {
        var self = this;

        self.entries = ko.observableArray(entries);

        // Meta state
        self.filter = ko.observable("");
        self.sortField = ko.observable(initialSortField);
        self.reverseSort = ko.observable(initialSortDescending);
        self.updateSort = function (field) {
            if (self.sortField() === field) {
                self.reverseSort(!self.reverseSort());
            } else {
                self.reverseSort(false);
                self.sortField(field);
            }
        };

        self.visibleEntries = ko.computed(function () {
            // Wrap with underscore
            var iterable = _(self.entries()).chain();

            // Filter
            if (self.filter() && !/^\s*$/.test(self.filter())) {
                var filter = self.filter().toLowerCase();

                iterable = iterable.filter(function (disease) {
                    return _(filterableFields).some(function (field) {
                        return (ko.utils.recursivePeek(disease[field]) || "").toLowerCase().indexOf(filter) !== -1;
                    });
                });
            }

            // Convert to view models
            if (mapFunction) {
                iterable = iterable.map(mapFunction);
            }

            // Hide
            iterable = iterable.filter(function (entry) { return !(ko.utils.recursiveUnwrap(entry.hide) || false); });

            // Sort
            var sortField = self.sortField();
            iterable = iterable.sortBy(function (disease) {
                var sortChain = sortField.split(".");
                var sortable = ko.utils.recursivePeek(disease) || "";
                for (var i = 0; i < sortChain.length; i = i + 1) {
                    sortable = ko.utils.recursivePeek(sortable[sortChain[i]]) || "";
                }
                if (typeof sortable === "string" || sortable instanceof String) {
                    sortable = sortable.toLowerCase();
                }
                if (typeof sortable === "boolean" || sortable instanceof Boolean) {
{'fraction_non_alphanumeric': 0.1279093717816684, 'fraction_numerical': 0.0024716786817713696, 'mean_word_length': 1.7956246401842257, 'pattern_counts': {'":': 0, '<': 4, '<?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': '5391329', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1238, 'n_words': 285}