{"size": 1837, "ext": "js", "max_stars_repo_path": "src/arches_common/pkg/extensions/functions/unique-boolean-value/unique-boolean-value.js", "max_stars_repo_name": "bcgov/BCHeritage_arches", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/arches_common/pkg/extensions/functions/unique-boolean-value/unique-boolean-value.js", "max_issues_repo_name": "bcgov/BCHeritage_arches", "max_issues_repo_issues_event_min_datetime": "2022-02-08T00:13:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-08T14:01:15.000Z", "max_forks_repo_path": "src/arches_common/pkg/extensions/functions/unique-boolean-value/unique-boolean-value.js", "max_forks_repo_name": "bcgov/BCHeritage_arches", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 10, "max_forks_count": null, "avg_line_length": 36.74, "max_line_length": 113, "alphanum_fraction": 0.5394665215}
define(['jquery',
    'underscore',
    'arches',
    'knockout',
    'knockout-mapping',
    'viewmodels/function',
    'bindings/chosen',
    'views/components/simple-switch',
    ''],
function($, _, arches, ko, koMapping, FunctionViewModel, chosen) {
    return ko.components.register('views/components/functions/unique-boolean-value', {
        viewModel: function(params) {
            FunctionViewModel.apply(this, arguments);
            var nodegroups = {};
            var sortedCards = [];
            this.triggering_nodegroups = params.config.triggering_nodegroups;
            this.loading = ko.observable(false);

            this.graph.nodes.forEach(function(card){
                if (card.datatype === 'boolean')
                {
                    sortedCards.push(card);
                    nodegroups[card.nodeid] = true;
                }
            }, this);

            sortedCards.sort(function(a, b){ if ( a.name === b.name) return 0; return a.name > b.name ? 1 : -1 })
            this.cards = ko.observableArray(sortedCards);

            this.unique_value = params.config.unique_value
            this.node_id = params.config.node_id
            this.node_id.subscribe(function(newValue) {
                this.node_id(newValue);
                console.log("New value: "+newValue);
                this.graph.nodes.forEach(function(node) {
                    if (node.nodeid == newValue)
                    {
                        this.triggering_nodegroups([node.nodegroup_id]);
                    }
                }, this)
            }, this);

            window.setTimeout(function(){$("select[data-bind^=chosen]").trigger("chosen:updated");}, 300);
        },
        template: {
            require: 'text!templates/views/components/functions/unique-boolean-value.htm'
        }
    });
});
