<commit_before>/**
 * select2 wrapper for easier use within GIMS
 * Basic usage is:
 * <gims-select api="filterSet" model="mySelectedFilterSet"></gims-select>
 *
 * Or specify name attribute to change default behavior
 * <gims-select api="filterSet" model="mySelectedFilterSet" name="myFilterName" placeholder="Select a questionnaire" style="width:100%;"></gims-select>
 *
 * To enable "ID mode", specify name="id" in element. This will reload the current URL
 * with the ID of the selected item instead of GET parameter (see for example: /contribute/questionnaire)
 *
 * To specify additional GET parameter for API calls, use attribute queryparams:
 * <gims-select api="questionnaire" queryparams="questionnaireQueryParams" /></gims-select>
 *
 * To set advanced templates on list elements, send string template via custom-selection-template and custom-format-template attribute
 * Dynamic content is eval() by javascript. Escape content to eval with [[expression]].
 * Complexe structures like functions are evaluated too
 * <gims-select custom-selection-template="This element is [[item.name]] and is is [[item.id]]." /></gims-select>
 * <gims-select custom-result-template="[[_.map(item.paths, function(path){return '<i class=\'fa fa-gims-filter\'></i> \'+path+\'';}).join('')]]"/></gims-select>
 * <gims-select custom-selection-template="{{template}}"/></gims-select>
 *
 * The css class select2list allow to display list elements in the select2 in full with. It allows advanced styling by custom-template attribute
 * <gims-select container-css-class="select2list" /></gims-select>
 *
 * current-context-element attribute is used only in custom-template. Allow to generate content using current page context id (e.g using return URL id)
 * <gims-select current-context-element="{{filter.id}}" custom-selection-template="<a href='returnUrl=/admin/xxx/edit/[[$scope.currentContextElement]]'>edit</a>" /></gims-select>
 *
 * To see more about custom-template usage, see admin/filter.js controller.
 */
angular.module('myApp.directives').directive('gimsSelect', function() {
    'use strict';

    return {
        restrict: 'E', // Only usage possible is with element
        require: 'ngModel',
        replace: true,
        transclude: true,
        template: '<input type="hidden" ui-select2="options" ng-model="model" ng-disabled="disabled"/>',
        scope: {
            api: '@',
            name: '@',
            placeholder: '@',
            format: '@',
            customSelectionTemplate: '@',
            customResultTemplate: '@',
            containerCssClass: '@',
            currentContextElement: '@',
            queryparams: '=',
            disabled: '=',
            model: '=' // TODO: could not find a way to use real 'ng-model'. So for now we use custom 'model' attribute and bi-bind it to real ng-model. Ugly, but working
        },
        compile: function() {

            return function(scope, elm, attrs) {

                // If in tag mode, open select2 when getting focus via keyboard
                if (attrs.multiple)
                {
                    var select2Focus = function() {
                        var select2 = $(this).data('select2');
                        setTimeout(function() {
                            if (!select2.opened()) {
                                select2.open();
                            }
                        }, 0);
                    };

                    elm.one('select2-focus', select2Focus).on("select2-blur", function() {
                        $(this).one('select2-focus', select2Focus);
                    });
                }
            };
        },
        // The linking function will add behavior to the template
        link: function() {
        },
        controller: function($scope, $attrs, Restangular, CachedRestangular, $location, $route, $routeParams) {
            var items = [];
            var api = $scope.api;
            var name = $scope.name || api; // default key to same name as route
            var fromUrl = name == 'id' ? $routeParams.id : $location.search()[name];
            var idsFromUrl = fromUrl ? fromUrl.split(',') : [];
            idsFromUrl = _.map(idsFromUrl, function(id) {
                return parseInt(id);
            });


            // Update URL when value changes
            if (!$route.current.$$route.reloadOnSearch || name == 'id') {
                $scope.$watch($attrs.ngModel, function(o) {

                    // Either get the single ID, or the multiple IDs
                    var id;
                    if (_.isString(o)) {
                        id = o;
                    }
                    else if (o && o.id) {
                        id = o.id;<commit_msg>Revert "Open select2 when in tag mode and get focus via keyboard #2550"<commit_after>/**
 * select2 wrapper for easier use within GIMS
 * Basic usage is:
 * <gims-select api="filterSet" model="mySelectedFilterSet"></gims-select>
 *
 * Or specify name attribute to change default behavior
 * <gims-select api="filterSet" model="mySelectedFilterSet" name="myFilterName" placeholder="Select a questionnaire" style="width:100%;"></gims-select>
 *
 * To enable "ID mode", specify name="id" in element. This will reload the current URL
 * with the ID of the selected item instead of GET parameter (see for example: /contribute/questionnaire)
 *
 * To specify additional GET parameter for API calls, use attribute queryparams:
 * <gims-select api="questionnaire" queryparams="questionnaireQueryParams" /></gims-select>
 *
 * To set advanced templates on list elements, send string template via custom-selection-template and custom-format-template attribute
 * Dynamic content is eval() by javascript. Escape content to eval with [[expression]].
 * Complexe structures like functions are evaluated too
 * <gims-select custom-selection-template="This element is [[item.name]] and is is [[item.id]]." /></gims-select>
 * <gims-select custom-result-template="[[_.map(item.paths, function(path){return '<i class=\'fa fa-gims-filter\'></i> \'+path+\'';}).join('')]]"/></gims-select>
 * <gims-select custom-selection-template="{{template}}"/></gims-select>
 *
 * The css class select2list allow to display list elements in the select2 in full with. It allows advanced styling by custom-template attribute
 * <gims-select container-css-class="select2list" /></gims-select>
 *
 * current-context-element attribute is used only in custom-template. Allow to generate content using current page context id (e.g using return URL id)
 * <gims-select current-context-element="{{filter.id}}" custom-selection-template="<a href='returnUrl=/admin/xxx/edit/[[$scope.currentContextElement]]'>edit</a>" /></gims-select>
 *
 * To see more about custom-template usage, see admin/filter.js controller.
 */
angular.module('myApp.directives').directive('gimsSelect', function() {
    'use strict';

    return {
        restrict: 'E', // Only usage possible is with element
        require: 'ngModel',
        replace: true,
        transclude: true,
        template: '<input type="hidden" ui-select2="options" ng-model="model" ng-disabled="disabled"/>',
        scope: {
            api: '@',
            name: '@',
            placeholder: '@',
            format: '@',
            customSelectionTemplate: '@',
            customResultTemplate: '@',
            containerCssClass: '@',
            currentContextElement: '@',
            queryparams: '=',
            disabled: '=',
            model: '=' // TODO: could not find a way to use real 'ng-model'. So for now we use custom 'model' attribute and bi-bind it to real ng-model. Ugly, but working
        },
        // The linking function will add behavior to the template
        link: function() {
        },
        controller: function($scope, $attrs, Restangular, CachedRestangular, $location, $route, $routeParams) {
            var items = [];
            var api = $scope.api;
            var name = $scope.name || api; // default key to same name as route
            var fromUrl = name == 'id' ? $routeParams.id : $location.search()[name];
            var idsFromUrl = fromUrl ? fromUrl.split(',') : [];
            idsFromUrl = _.map(idsFromUrl, function(id) {
                return parseInt(id);
            });


            // Update URL when value changes
            if (!$route.current.$$route.reloadOnSearch || name == 'id') {
                $scope.$watch($attrs.ngModel, function(o) {

                    // Either get the single ID, or the multiple IDs
                    var id;
                    if (_.isString(o)) {
                        id = o;
                    }
                    else if (o && o.id) {
                        id = o.id;
{'fraction_non_alphanumeric': 0.13202150783663197, 'fraction_numerical': 0.003775311749227777, 'mean_word_length': 2.351993865030675, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '4599728', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2256, 'n_words': 712}