<commit_before>/* global Uint8Array */
hqDefine("app_manager/js/details/case_claim", function () {
    var get = hqImport('hqwebapp/js/initial_page_data').get,
        generateSemiRandomId = function () {
        // https://stackoverflow.com/a/2117523
            return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
                return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16);
            });
        },
        subscribeToSave = function (model, observableNames, saveButton) {
            _.each(observableNames, function (name) {
                model[name].subscribe(function () {
                    saveButton.fire('change');
                });
            });
        };

    var itemsetModel = function (options, saveButton) {
        options = _.defaults(options, {
            'instance_id': '',
            'instance_uri': '',
            'nodeset': '',
            'label': '',
            'value': '',
            'sort': '',
        });
        var self = ko.mapping.fromJS(options);

        self.lookupTableNodeset = ko.pureComputed({
            write: function (value) {
                self.nodeset(value);
                var reg = /instance\(['"]([\w\-:]+)['"]\)/g,
                    matches = reg.exec(value);
                if (matches && matches.length > 1) {
                    var instanceId = matches[1],
                        itemList = _.findWhere(get('js_options').item_lists, {'id': instanceId});

                    self.instance_id(instanceId);
                    if (itemList) {
                        self.instance_uri(itemList['uri']);
                    }
                }
            },
            read: function () {
                // is the nodeset a lookup table that we know about?
                var itemLists = get('js_options').item_lists,
                    itemListNodesets = _.map(itemLists, function (item) {
                        return "instance('" + item.id + "')" + item.path;
                    });
                if (itemListNodesets.indexOf(self.nodeset()) !== -1) {

                    return self.nodeset();
                } else {
                    return '';
                }
            },
        });

        subscribeToSave(self, ['nodeset', 'label', 'value', 'sort'], saveButton);

        return self;
    };

    var searchPropertyModel = function (options, saveButton) {
        options = _.defaults(options, {
            name: '',
            label: '',
            appearance: '',
            defaultValue: '',
            itemsetOptions: {},
        });
        var self = {};
        self.uniqueId = generateSemiRandomId();
        self.name = ko.observable(options.name);
        self.label = ko.observable(options.label);
        self.appearance = ko.observable(options.appearance);
        self.defaultValue = ko.observable(options.defaultValue);

        self.itemset = itemsetModel(options.itemsetOptions, saveButton);

        subscribeToSave(self, ['name', 'label', 'appearance', 'defaultValue'], saveButton);

        return self;
    };

    var defaultPropertyModel = function (options, saveButton) {
        options = _.defaults(options, {
            property: '',
            defaultValue: '',
        });
        var self = ko.mapping.fromJS(options);

        subscribeToSave(self, ['property', 'defaultValue'], saveButton);

        return self;
    };

    var searchConfigKeys = [
        'autoLaunch', 'blacklistedOwnerIdsExpression', 'defaultSearch', 'includeClosed', 'searchAgainLabel',
        'searchButtonDisplayCondition', 'searchCommandLabel', 'searchFilter', 'searchRelevant', 'sessionVar',
    ];
    var searchConfigModel = function (options, lang, searchFilterObservable, saveButton) {
        hqImport("hqwebapp/js/assert_properties").assertRequired(options, searchConfigKeys);

        options.searchCommandLabel = options.searchCommandLabel[lang] || "";
        options.searchAgainLabel = options.searchAgainLabel[lang] || "";
        var self = ko.mapping.fromJS(_.pick(options, _.without(searchConfigKeys, 'searchRelevant')));

        self.workflow = ko.computed({
            read: function () {
                if (self.autoLaunch()) {
                    if (self.defaultSearch()) {
                        return "es_only";
                    }
                    return "auto_launch";
                } else if (self.defaultSearch()) {
                    return "see_more";
                }
                return "classic";
            },
            write: function (value) {
                self.autoLaunch(_.contains(["es_only", "auto_launch"], value));
                self.defaultSearch(_.contains["es_only", "see_more"], value);
            },
        });<commit_msg>Added missing parens<commit_after>/* global Uint8Array */
hqDefine("app_manager/js/details/case_claim", function () {
    var get = hqImport('hqwebapp/js/initial_page_data').get,
        generateSemiRandomId = function () {
        // https://stackoverflow.com/a/2117523
            return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
                return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16);
            });
        },
        subscribeToSave = function (model, observableNames, saveButton) {
            _.each(observableNames, function (name) {
                model[name].subscribe(function () {
                    saveButton.fire('change');
                });
            });
        };

    var itemsetModel = function (options, saveButton) {
        options = _.defaults(options, {
            'instance_id': '',
            'instance_uri': '',
            'nodeset': '',
            'label': '',
            'value': '',
            'sort': '',
        });
        var self = ko.mapping.fromJS(options);

        self.lookupTableNodeset = ko.pureComputed({
            write: function (value) {
                self.nodeset(value);
                var reg = /instance\(['"]([\w\-:]+)['"]\)/g,
                    matches = reg.exec(value);
                if (matches && matches.length > 1) {
                    var instanceId = matches[1],
                        itemList = _.findWhere(get('js_options').item_lists, {'id': instanceId});

                    self.instance_id(instanceId);
                    if (itemList) {
                        self.instance_uri(itemList['uri']);
                    }
                }
            },
            read: function () {
                // is the nodeset a lookup table that we know about?
                var itemLists = get('js_options').item_lists,
                    itemListNodesets = _.map(itemLists, function (item) {
                        return "instance('" + item.id + "')" + item.path;
                    });
                if (itemListNodesets.indexOf(self.nodeset()) !== -1) {

                    return self.nodeset();
                } else {
                    return '';
                }
            },
        });

        subscribeToSave(self, ['nodeset', 'label', 'value', 'sort'], saveButton);

        return self;
    };

    var searchPropertyModel = function (options, saveButton) {
        options = _.defaults(options, {
            name: '',
            label: '',
            appearance: '',
            defaultValue: '',
            itemsetOptions: {},
        });
        var self = {};
        self.uniqueId = generateSemiRandomId();
        self.name = ko.observable(options.name);
        self.label = ko.observable(options.label);
        self.appearance = ko.observable(options.appearance);
        self.defaultValue = ko.observable(options.defaultValue);

        self.itemset = itemsetModel(options.itemsetOptions, saveButton);

        subscribeToSave(self, ['name', 'label', 'appearance', 'defaultValue'], saveButton);

        return self;
    };

    var defaultPropertyModel = function (options, saveButton) {
        options = _.defaults(options, {
            property: '',
            defaultValue: '',
        });
        var self = ko.mapping.fromJS(options);

        subscribeToSave(self, ['property', 'defaultValue'], saveButton);

        return self;
    };

    var searchConfigKeys = [
        'autoLaunch', 'blacklistedOwnerIdsExpression', 'defaultSearch', 'includeClosed', 'searchAgainLabel',
        'searchButtonDisplayCondition', 'searchCommandLabel', 'searchFilter', 'searchRelevant', 'sessionVar',
    ];
    var searchConfigModel = function (options, lang, searchFilterObservable, saveButton) {
        hqImport("hqwebapp/js/assert_properties").assertRequired(options, searchConfigKeys);

        options.searchCommandLabel = options.searchCommandLabel[lang] || "";
        options.searchAgainLabel = options.searchAgainLabel[lang] || "";
        var self = ko.mapping.fromJS(_.pick(options, _.without(searchConfigKeys, 'searchRelevant')));

        self.workflow = ko.computed({
            read: function () {
                if (self.autoLaunch()) {
                    if (self.defaultSearch()) {
                        return "es_only";
                    }
                    return "auto_launch";
                } else if (self.defaultSearch()) {
                    return "see_more";
                }
                return "classic";
            },
            write: function (value) {
                self.autoLaunch(_.contains(["es_only", "auto_launch"], value));
                self.defaultSearch(_.contains(["es_only", "see_more"], value));
            },
        });
{'fraction_non_alphanumeric': 0.13726104669382638, 'fraction_numerical': 0.006894390473205891, 'mean_word_length': 1.7253060062624537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '678979', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2442, 'n_words': 456}