<commit_before>angular.module('StarcounterLib', [])
  .directive('uiDatagrid', function () {
    var directiveDefinitionObject = {
      restrict: 'A',
      compile: function compile(tElement, tAttrs, transclude) {

        var defaultSettings = {
          rows: 6,
          cols: 3,
          outsideClickDeselects: false,
          autoComplete: []
        };

        var $container = $('<div class="dataTable"></div>');

        return function postLink(scope, element, attrs, controller) {
          var expression = attrs.datarows;
          var match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/),
            lhs, rhs, valueIdent, keyIdent;
          if (!match) {
            throw Error("Expected datarows in form of '_item_ in _collection_' but got '" +
              expression + "'.");
          }
          lhs = match[1];
          rhs = match[2];

          $(element).append($container);

          var settings = angular.extend({}, defaultSettings, scope.$eval(attrs.uiDatagrid));
          var columns = [];
          var colHeaders = [];

          $(element).find('datacolumn').each(function (index) {
            var $this = $(this)
              , pattern = new RegExp("^(" + lhs + "\\.)")
              , value = $this.attr('value').replace(pattern, '')
              , title = $this.attr('title')
              , type = scope.$eval($this.attr('type'))
              , options = $this.attr('options')
              , tmp;

            var column = scope.$eval(options) || {};
            column.data = value;

            colHeaders.push(title);

            switch(type) {
              case 'autocomplete':
                settings['autoComplete'].push({
                  match: function (row, col) {
                    if (col === index) {
                      return true;
                    }
                  },
                  source: function (row, col) {
                    var childScope = scope.$new();
                    childScope.item = $container.data('handsontable').getData()[row];
                    var parsed = childScope.$eval(options);
                    return parsed;
                  }
                });
                break;

              case 'checkbox':
                column.type = Handsontable.CheckboxCell;
                tmp = $this.attr('checkedTemplate');
                if(typeof tmp !== 'undefined') {
                  column.checkedTemplate = scope.$eval(tmp); //if undefined then defaults to Boolean true
                }
                tmp = $this.attr('uncheckedTemplate');
                if(typeof tmp !== 'undefined') {
                  column.uncheckedTemplate = scope.$eval(tmp); //if undefined then defaults to Boolean true
                }
                break;

              default:
                if(typeof type === 'object') {
                  column.type = type;
                }
            }

            if($this.attr('readOnly')) {
              column.readOnly = true;
            }

            columns.push(column);
          });

          if (columns.length > 0) {
            settings['columns'] = columns;
          }

          if (colHeaders.length > 0) {
            settings['colHeaders'] = colHeaders;
          }

          settings['data'] = scope[rhs];
          $container.handsontable(settings);

          $container.on('datachange.handsontable', function (event, changes, source) {
            if (source === 'loadData') {
              return;
            }
            scope.$apply(function () {
              scope.dataChange = !scope.dataChange;
            });
          });

          $container.on('selectionbyprop.handsontable', function (event, r, p, r2, p2) {
            scope.$emit('datagridSelection', $container, r, p, r2, p2);
          });

          scope.$watch('dataChange', function (value) {
            $container.handsontable("loadData", scope[rhs]);
          });
        }
      }
    };
    return directiveDefinitionObject;
  });<commit_msg>refresh columns configuration when data source is changed<commit_after>angular.module('ui.directives', [])
  .directive('uiDatagrid', function () {
    var directiveDefinitionObject = {
      restrict: 'A',
      compile: function compile(tElement, tAttrs, transclude) {

        var defaultSettings = {
          startRows: 0,
          startCols: 3,
          outsideClickDeselects: false,
          autoComplete: []
        };

        var $container = $('<div class="dataTable"></div>');

        return function postLink(scope, element, attrs, controller) {
          var expression = attrs.datarows;
          var match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/),
            lhs, rhs, valueIdent, keyIdent;
          if (!match) {
            throw Error("Expected datarows in form of '_item_ in _collection_' but got '" +
              expression + "'.");
          }
          lhs = match[1];
          rhs = match[2];

          $(element).append($container);

          var settings = angular.extend({}, defaultSettings, scope.$eval(attrs.uiDatagrid));
          var columns = [];
          var colHeaders = [];

          $(element).find('datacolumn').each(function (index) {
            var $this = $(this)
              , pattern = new RegExp("^(" + lhs + "\\.)")
              , value = $this.attr('value').replace(pattern, '')
              , title = $this.attr('title')
              , type = scope.$eval($this.attr('type'))
              , options = $this.attr('options')
              , tmp;

            var column = scope.$eval(options) || {};
            column.data = value;

            colHeaders.push(title);

            switch (type) {
              case 'autocomplete':
                settings['autoComplete'].push({
                  match: function (row, col) {
                    if (col === index) {
                      return true;
                    }
                  },
                  source: function (row, col) {
                    var childScope = scope.$new();
                    childScope.item = $container.data('handsontable').getData()[row];
                    var parsed = childScope.$eval(options);
                    return parsed;
                  }
                });
                break;

              case 'checkbox':
                column.type = Handsontable.CheckboxCell;
                tmp = $this.attr('checkedTemplate');
                if (typeof tmp !== 'undefined') {
                  column.checkedTemplate = scope.$eval(tmp); //if undefined then defaults to Boolean true
                }
                tmp = $this.attr('uncheckedTemplate');
                if (typeof tmp !== 'undefined') {
                  column.uncheckedTemplate = scope.$eval(tmp); //if undefined then defaults to Boolean true
                }
                break;

              default:
                if (typeof type === 'object') {
                  column.type = type;
                }
            }

            if ($this.attr('readOnly')) {
              column.readOnly = true;
            }

            columns.push(column);
          });

          if (typeof scope[rhs] !== 'undefined') {
            settings['data'] = scope[rhs];
            if (columns.length > 0) {
              settings['columns'] = columns;
              settings['startCols'] = columns.length;
            }
          }

          if (colHeaders.length > 0) {
            settings['colHeaders'] = colHeaders;
          }

          $container.handsontable(settings);

          $container.on('datachange.handsontable', function (event, changes, source) {
            if (source === 'loadData') {
              return;
            }
            scope.$apply(function () {
              scope.dataChange = !scope.dataChange;
            });
          });

          $container.on('selectionbyprop.handsontable', function (event, r, p, r2, p2) {
            scope.$emit('datagridSelection', $container, r, p, r2, p2);
          });

          scope.$watch('dataChange', function (value) {
            if (scope[rhs] !== $container.handsontable('getData') && columns.length > 0) {
              var update = {
                columns: columns,
                startCols: columns.length
              }
              $container.handsontable("updateSettings", update);
            }
            $container.handsontable("loadData", scope[rhs]);
          });
        }
      }
    };
    return directiveDefinitionObject;
  });
{'fraction_non_alphanumeric': 0.13488317205569977, 'fraction_numerical': 0.002478168515459051, 'mean_word_length': 1.442363112391931, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '4114389', 'n_tokens_mistral': 2206, 'n_tokens_neox': 2092, 'n_words': 449}