<commit_before>(function() {
    'use strict';

    angular
        .module('app.widgets')
        .directive('widgetSelection', widgetSelection)
        .controller('SelectionChoicesController', SelectionChoicesController)
        .controller('WidgetSettingsCtrl-selection', WidgetSettingsCtrlSelection)
        .config(function (WidgetsProvider) {
            WidgetsProvider.$get().registerType({
                type: 'selection',
                displayName: 'Selection',
                icon: 'th',
                description: 'A widget allowing a selection between multiple choices'
            });
        });

    widgetSelection.$inject = ['$rootScope', '$uibModal', 'OHService'];
    function widgetSelection($rootScope, $modal, OHService) {
        // Usage: <widget-selection ng-model="widget" />
        //
        // Creates: A Selection widget
        //
        var directive = {
            bindToController: true,
            controller: SelectionController,
            controllerAs: 'vm',
            link: link,
            restrict: 'AE',
            templateUrl: 'app/widgets/selection/selection.tpl.html',
            scope: {
                ngModel: '='
            }
        };
        return directive;

        function link(scope, element, attrs) {
            element[0].parentElement.parentElement.className += " activefeedback";
        }
    }
    SelectionController.$inject = ['$rootScope', '$scope', '$filter', '$uibModal', 'OHService'];
    function SelectionController ($rootScope, $scope, $filter, $uibModal, OHService) {
        var vm = this;
        this.widget = this.ngModel;

        function updateValue() {
            vm.item = OHService.getItem(vm.widget.item);
            if (!vm.item || vm.item.state === vm.value) return;
            vm.value = vm.item.transformedState || vm.item.state;
            vm.state = vm.item.state;

            if (!vm.choices) {
                switch (vm.widget.choices_source) {
                    case 'server':
                        vm.choices = vm.item.stateDescription.options.map(function (option) {
                            return { cmd: option.value, label: option.label };
                        });
                        break;
                    case 'csv':
                        vm.choices = vm.widget.choices.split(',').map(function (choice) {
                            choice = choice.split('=');
                            if (choice.length === 2) {
                                return { cmd: choice[0], label: choice[1] };
                            } else {
                                return { cmd: choice[0], label: choice[0] };
                            }
                        });
                        break;
                    default:
                        vm.choices = vm.widget.choices;
                }
            }

            function filterChoice(choice, i, choices) {
                if (choice.cmd === vm.state) return true;
                return false;
            }
            if ($filter('filter')(vm.choices, filterChoice).length > 0) {
                vm.currentChoice = $filter('filter')(vm.choices, filterChoice)[0];
                if (vm.currentChoice.label)
                    vm.value = vm.currentChoice.label;
            }
        }

        OHService.onUpdate($scope, vm.widget.item, function () {<commit_msg>Use strict comparator for current selection widget choice (#336)<commit_after>(function() {
    'use strict';

    angular
        .module('app.widgets')
        .directive('widgetSelection', widgetSelection)
        .controller('SelectionChoicesController', SelectionChoicesController)
        .controller('WidgetSettingsCtrl-selection', WidgetSettingsCtrlSelection)
        .config(function (WidgetsProvider) {
            WidgetsProvider.$get().registerType({
                type: 'selection',
                displayName: 'Selection',
                icon: 'th',
                description: 'A widget allowing a selection between multiple choices'
            });
        });

    widgetSelection.$inject = ['$rootScope', '$uibModal', 'OHService'];
    function widgetSelection($rootScope, $modal, OHService) {
        // Usage: <widget-selection ng-model="widget" />
        //
        // Creates: A Selection widget
        //
        var directive = {
            bindToController: true,
            controller: SelectionController,
            controllerAs: 'vm',
            link: link,
            restrict: 'AE',
            templateUrl: 'app/widgets/selection/selection.tpl.html',
            scope: {
                ngModel: '='
            }
        };
        return directive;

        function link(scope, element, attrs) {
            element[0].parentElement.parentElement.className += " activefeedback";
        }
    }
    SelectionController.$inject = ['$rootScope', '$scope', '$filter', '$uibModal', 'OHService'];
    function SelectionController ($rootScope, $scope, $filter, $uibModal, OHService) {
        var vm = this;
        this.widget = this.ngModel;

        function updateValue() {
            vm.item = OHService.getItem(vm.widget.item);
            if (!vm.item || vm.item.state === vm.value) return;
            vm.value = vm.item.transformedState || vm.item.state;
            vm.state = vm.item.state;

            if (!vm.choices) {
                switch (vm.widget.choices_source) {
                    case 'server':
                        vm.choices = vm.item.stateDescription.options.map(function (option) {
                            return { cmd: option.value, label: option.label };
                        });
                        break;
                    case 'csv':
                        vm.choices = vm.widget.choices.split(',').map(function (choice) {
                            choice = choice.split('=');
                            if (choice.length === 2) {
                                return { cmd: choice[0], label: choice[1] };
                            } else {
                                return { cmd: choice[0], label: choice[0] };
                            }
                        });
                        break;
                    default:
                        vm.choices = vm.widget.choices;
                }
            }

            function filterChoice(choice, i, choices) {
                if (choice.cmd === vm.state) return true;
                return false;
            }
            if ($filter('filter')(vm.choices, filterChoice, true).length > 0) {
                vm.currentChoice = $filter('filter')(vm.choices, filterChoice, true)[0];
                if (vm.currentChoice.label)
                    vm.value = vm.currentChoice.label;
            }
        }

        OHService.onUpdate($scope, vm.widget.item, function () {
{'fraction_non_alphanumeric': 0.12007037091335582, 'fraction_numerical': 0.002785515320334262, 'mean_word_length': 1.4477933261571583, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4930521', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1633, 'n_words': 340}