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

  angular.module('kct.directives.kctTable')
    .directive('kctTable', ['$filter', KctTableDirective])
  ;

  function KctTableDirective($filter) {
    var _defaultConfig = {
      query        : '',
      currentPage  : 1,
      itemsPerPage : 10,
      order        : {
        predicate : ''
      }
    };
    return {
      restrict : 'A',
      scope    : true,
      compile  : compile
    };

    function compile(cElement) {
      var _headElement = cElement.find('thead'),
          _bodyElement = cElement.find('tbody'),
          _tdElements = _bodyElement.find('td'),
          _columns = _extractColumns();

      _constructHeader();

      _constructBody();

      return {
        post : post
      };

      function post(pScope, pElement, pAttrs) {
        var _this = pScope.vm = {},
            _config,
            _list = pScope.$eval(pAttrs.kctTableList);

        _this.sortTable = sortTable;
        _this.showCaret = showCaret;
        _this.update = update;

        init();

        function init() {
          var _effectiveConfig;
          if (!pScope.$eval(pAttrs.kctTableConfig)) {
            _effectiveConfig = _defaultConfig;
          } else {
            _effectiveConfig = _.assign({}, _defaultConfig, pScope.$eval(pAttrs.kctTableConfig));
            _effectiveConfig.currentPage = 1;
          }
          _.set(pScope, pAttrs.kctTableConfig, _effectiveConfig);
          _config = pScope.$eval(pAttrs.kctTableConfig);

          _initSorting();

          _this.filteredList = $filter('filter')(_list, _config.query);
          _this.fillerArray = [];

          pScope.$watchCollection(pAttrs.kctTableList, update);
          pScope.$watch(pAttrs.kctTableConfig + '.query', update);
          pScope.$watch(pAttrs.kctTableConfig + '.order.predicate', update);
          pScope.$watch(pAttrs.kctTableConfig + '.order.sortReverse', update);

          if (pAttrs.kctTablePaginated !== void 0) {
            pScope.$watch(pAttrs.kctTableConfig + '.currentPage', update);
            pScope.$watch(pAttrs.kctTableConfig + '.itemsPerPage', update);
          }

          function _initSorting() {
            var sortedColumn = _.find(_columns, 'initSorting');
            _config.order = {
              predicate   : sortedColumn.attribute,
              sortReverse : sortedColumn.initSorting === 'desc'
            };
          }

        }

        function sortTable(predicate) {
          if (_config.order.predicate !== predicate) {
            _config.order.predicate = predicate;
            _config.order.sortReverse = false;
          } else {
            _config.order.sortReverse = !_config.order.sortReverse;
          }
        }

        function showCaret(predicate, sortReverse) {
          return _config.order.predicate === predicate && _config.order.sortReverse === sortReverse;
        }

        function update() {
          // Filtering
          _this.filteredList = _this.sortedList = $filter('filter')(_list, _config.query);
          _config.totalItems = _this.filteredList.length;

          // Deciding range
          var from = (_config.currentPage - 1) * _config.itemsPerPage,
              to = _.min([_this.filteredList.length - 1, from + _config.itemsPerPage - 1]);

          // Sorting
          if (_config.order.predicate.length) {
            _this.sortedList = $filter('orderBy')(_this.filteredList, _config.order.predicate, _config.order.sortReverse);
          }

          // Applying range
          _this.sortedList = _.take(_this.sortedList, to + 1);
          _this.sortedList = _.takeRight(_this.sortedList, to - from + 1);

          // Filling last page
          if (Math.max(1, Math.ceil(_this.filteredList.length / _config.itemsPerPage)) === _config.currentPage) {
            _this.fillerArray.length = 0;

            for (var i = 0; i < _config.itemsPerPage - _this.sortedList.length; ++i) {
              _this.fillerArray.push({});
            }

          } else {
            _this.fillerArray.length = 0;
          }

        }
      }

      function _extractColumns() {
        var columns = [];
        _tdElements.each(function(index, td) {
          var tdEl = angular.element(td),
              column = {};

          column.attribute = tdEl.attr('kct-table-attribute');

          column.isSortable = tdEl.attr('kct-table-sortable') !== void 0 || !!/(sortable)/i.exec(tdEl.attr('class'));
          if (column.isSortable) {
            column.initSorting = tdEl.attr('kct-table-initial-sorting');
          }

          column.hasTitle = !!_headElement.find('tr th[kct-table-attribute=\'' + column.attribute + '\']').length;
          if (!column.hasTitle) {
            column.hasTitle = !!tdEl.attr('kct-table-title') || !!column.attribute;
          }
          columns.push(column);
        });
        return columns;
      }

      function _constructHeader() {
        var cacheRowHeader = _headElement.find('tr').clone(),
            rowHeader;

        if (_headElement.length) {
          _headElement.empty();

          rowHeader = angular.element(document.createElement('tr'));
          _headElement.empty().append(rowHeader);<commit_msg>kctTable bug fix<commit_after>(function() {
  'use strict';

  angular.module('kct.directives.kctTable')
    .directive('kctTable', ['$filter', KctTableDirective])
  ;

  function KctTableDirective($filter) {
    var _defaultConfig = {
      query        : '',
      currentPage  : 1,
      itemsPerPage : 10,
      order        : {
        predicate : ''
      }
    };
    return {
      restrict : 'A',
      scope    : true,
      compile  : compile
    };

    function compile(cElement) {
      var _headElement = cElement.find('thead'),
          _bodyElement = cElement.find('tbody'),
          _tdElements = _bodyElement.find('td'),
          _columns = _extractColumns();

      _constructHeader();

      _constructBody();

      return {
        post : post
      };

      function post(pScope, pElement, pAttrs) {
        var _this = pScope.vm = {},
            _config,
            _list = pScope.$eval(pAttrs.kctTableList);

        _this.sortTable = sortTable;
        _this.showCaret = showCaret;
        _this.update = update;

        init();

        function init() {
          var _effectiveConfig;
          if (!pScope.$eval(pAttrs.kctTableConfig)) {
            _effectiveConfig = _defaultConfig;
          } else {
            _effectiveConfig = _.assign({}, _defaultConfig, pScope.$eval(pAttrs.kctTableConfig));
            _effectiveConfig.currentPage = 1;
          }
          _.set(pScope, pAttrs.kctTableConfig, _effectiveConfig);
          _config = pScope.$eval(pAttrs.kctTableConfig);

          _initSorting();

          _this.filteredList = $filter('filter')(_list, _config.query);
          _this.fillerArray = [];

          pScope.$watchCollection(pAttrs.kctTableList, update);
          pScope.$watch(pAttrs.kctTableConfig + '.query', update);
          pScope.$watch(pAttrs.kctTableConfig + '.order.predicate', update);
          pScope.$watch(pAttrs.kctTableConfig + '.order.sortReverse', update);

          if (pAttrs.kctTablePaginated !== void 0) {
            pScope.$watch(pAttrs.kctTableConfig + '.currentPage', update);
            pScope.$watch(pAttrs.kctTableConfig + '.itemsPerPage', update);
          }

          function _initSorting() {
            var sortedColumn = _.find(_columns, 'initSorting');
            if (sortedColumn) {
              _config.order = {
                predicate   : sortedColumn.attribute,
                sortReverse : sortedColumn.initSorting === 'desc'
              };
            }
          }

        }

        function sortTable(predicate) {
          if (_config.order.predicate !== predicate) {
            _config.order.predicate = predicate;
            _config.order.sortReverse = false;
          } else {
            _config.order.sortReverse = !_config.order.sortReverse;
          }
        }

        function showCaret(predicate, sortReverse) {
          return _config.order.predicate === predicate && _config.order.sortReverse === sortReverse;
        }

        function update() {
          // Filtering
          _this.filteredList = _this.sortedList = $filter('filter')(pScope.$eval(pAttrs.kctTableList), _config.query);
          _config.totalItems = _this.filteredList.length;

          // Deciding range
          var from = (_config.currentPage - 1) * _config.itemsPerPage,
              to = _.min([_this.filteredList.length - 1, from + _config.itemsPerPage - 1]);

          // Sorting
          if (_config.order.predicate.length) {
            _this.sortedList = $filter('orderBy')(_this.filteredList, _config.order.predicate, _config.order.sortReverse);
          }

          // Applying range
          _this.sortedList = _.take(_this.sortedList, to + 1);
          _this.sortedList = _.takeRight(_this.sortedList, to - from + 1);

          // Filling last page
          if (Math.max(1, Math.ceil(_this.filteredList.length / _config.itemsPerPage)) === _config.currentPage) {
            _this.fillerArray.length = 0;

            for (var i = 0; i < _config.itemsPerPage - _this.sortedList.length; ++i) {
              _this.fillerArray.push({});
            }

          } else {
            _this.fillerArray.length = 0;
          }

        }
      }

      function _extractColumns() {
        var columns = [];
        _tdElements.each(function(index, td) {
          var tdEl = angular.element(td),
              column = {};

          column.attribute = tdEl.attr('kct-table-attribute');

          column.isSortable = tdEl.attr('kct-table-sortable') !== void 0 || !!/(sortable)/i.exec(tdEl.attr('class'));
          if (column.isSortable && column.attribute) {
            column.initSorting = tdEl.attr('kct-table-initial-sorting');
          }

          column.hasTitle = !!_headElement.find('tr th[kct-table-attribute=\'' + column.attribute + '\']').length;
          if (!column.hasTitle) {
            column.hasTitle = !!tdEl.attr('kct-table-title') || !!column.attribute;
          }
          columns.push(column);
        });
        return columns;
      }

      function _constructHeader() {
        var cacheRowHeader = _headElement.find('tr').clone(),
            rowHeader;

        if (_headElement.length) {
          _headElement.empty();

          rowHeader = angular.element(document.createElement('tr'));
          _headElement.empty().append(rowHeader);
{'fraction_non_alphanumeric': 0.1284560570071259, 'fraction_numerical': 0.0028503562945368173, 'mean_word_length': 1.971767363071711, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6266977', 'n_tokens_mistral': 3155, 'n_tokens_neox': 3029, 'n_words': 492}