<commit_before>'use strict';

(function() {

  angular.module('ncsaas').directive('responsiveTable', responsiveTable);

  responsiveTable.$inject = ['$timeout', '$interval', '$compile', 'ENV'];

  function responsiveTable($timeout, $interval, $compile, ENV) {
    return {
      restrict: 'E',
      scope: {
        controller: '=tableCtrl'
      },
      template: '<table class="table table-striped"/>',
      link: function(scope, element) {
        var options = scope.controller.tableOptions;
        var table;

        scope.$watch('controller.tableOptions', function(newTableOptions) {
          if (table) {
            // Table should be initialized once
            return;
          }
          if (newTableOptions && newTableOptions.columns) {
            options = newTableOptions;
            table = initTable();
            connectRowButtons(table);
            connectWatcher(table);
          }
        });

        function initTable() {
          var exportButtons = getExportButtons(
            options.columns.length,
            options.rowActions,
            ['copyHtml5', 'csvHtml5', 'excelHtml5', 'pdfHtml5', 'print']
          );
          var exportCollection = {
            extend: 'collection',
            text: '<i class="fa fa-download"></i> Export as <span class="caret"></span>',
            autoClose: true,
            fade: 0,
            buttons: exportButtons
          };
          var buttons = [exportCollection];
          if (options.tableActions) {
            var tableButtons = getTableButtons(options.tableActions);
            buttons = buttons.concat(tableButtons);
          }
          buttons.push({
            text: '<i class="fa fa-refresh"></i> Refresh',
            action: function() {
              $timeout(function() {
                scope.controller.resetCache();
              });
            }
          });

          var columns = options.columns;
          if (options.rowActions && options.rowActions.length) {
            var actionColumn = getActionColumn(options.rowActions, options.actionsColumnWidth);
            columns.push(actionColumn);
          }

          var table = $(element.find('table')[0]).DataTable({
            responsive: true,
            processing: true,
            serverSide: true,
            ordering: !!scope.controller.tableOptions.enableOrdering,
            autoWidth: false,
            ajax: serverDataTableCallback,
            dom: '<"html5buttons"B>lTfgitp',
            buttons: buttons,
            columns: columns,
            language: {
              emptyTable: options.noDataText,
              zeroRecords: options.noMatchesText
            },
            fnDrawCallback: function() {
              $(element).find('tr').each(function(index, element) {
                $compile(element)(scope);
              });
            }
          });
          return table;
        }

        function connectWatcher(table) {
          scope.$watchCollection('controller.list', function() {
            table.draw(false);
          });

          var timer = $interval(
            scope.controller.resetCache.bind(scope.controller),
            ENV.countersTimerInterval * 1000
          );
          scope.$on('$destroy', function() {
            $interval.cancel(timer);
          });
        }

        function getTableButtons(actions) {
          return actions.map(function(action) {
            return {
              text: action.name,
              action: function() {
                $timeout(function() {
                  action.callback();
                });
              },
              className: action.disabled && 'disabled' || '',
              titleAttr: action.titleAttr
            };
          });
        }

        function connectRowButtons(table) {
          if (!options.rowActions || options.rowActions instanceof Function) {
            return;
          }
          table.on('click', 'button', function(event) {
            $(this).blur();
            var target = $(event.target).closest('button');
            var rowIndex = parseInt(target.attr('row-index'));
            var actionIndex = parseInt(target.attr('action-index'));
            var action = options.rowActions[actionIndex];
            var row = scope.controller.list[rowIndex];<commit_msg>Disabled resources table refresh on expand (WAL-137).<commit_after>'use strict';

(function() {

  angular.module('ncsaas').directive('responsiveTable', responsiveTable);

  responsiveTable.$inject = ['$timeout', '$interval', '$compile', 'ENV'];

  function responsiveTable($timeout, $interval, $compile, ENV) {
    return {
      restrict: 'E',
      scope: {
        controller: '=tableCtrl'
      },
      template: '<table class="table table-striped"/>',
      link: function(scope, element) {
        var options = scope.controller.tableOptions;
        var table;

        scope.$watch('controller.tableOptions', function(newTableOptions) {
          if (table) {
            // Table should be initialized once
            return;
          }
          if (newTableOptions && newTableOptions.columns) {
            options = newTableOptions;
            table = initTable();
            connectRowButtons(table);
            connectWatcher(table);
            registerEvents(table);
          }
        });

        function initTable() {
          var exportButtons = getExportButtons(
            options.columns.length,
            options.rowActions,
            ['copyHtml5', 'csvHtml5', 'excelHtml5', 'pdfHtml5', 'print']
          );
          var exportCollection = {
            extend: 'collection',
            text: '<i class="fa fa-download"></i> Export as <span class="caret"></span>',
            autoClose: true,
            fade: 0,
            buttons: exportButtons
          };
          var buttons = [exportCollection];
          if (options.tableActions) {
            var tableButtons = getTableButtons(options.tableActions);
            buttons = buttons.concat(tableButtons);
          }
          buttons.push({
            text: '<i class="fa fa-refresh"></i> Refresh',
            action: function() {
              $timeout(function() {
                scope.controller.resetCache();
              });
            }
          });

          var columns = options.columns;
          if (options.rowActions && options.rowActions.length) {
            var actionColumn = getActionColumn(options.rowActions, options.actionsColumnWidth);
            columns.push(actionColumn);
          }

          var table = $(element.find('table')[0]).DataTable({
            responsive: true,
            processing: true,
            serverSide: true,
            ordering: !!scope.controller.tableOptions.enableOrdering,
            autoWidth: false,
            ajax: serverDataTableCallback,
            dom: '<"html5buttons"B>lTfgitp',
            buttons: buttons,
            columns: columns,
            language: {
              emptyTable: options.noDataText,
              zeroRecords: options.noMatchesText
            },
            fnDrawCallback: function() {
              $(element).find('tr').each(function(index, element) {
                $compile(element)(scope);
              });
            }
          });
          return table;
        }

        function connectWatcher(table) {
          scope.$watchCollection('controller.list', function() {
            table.draw(false);
          });

          var timer = $interval(
            scope.controller.resetCache.bind(scope.controller),
            ENV.countersTimerInterval * 1000
          );
          scope.$on('$destroy', function() {
            $interval.cancel(timer);
          });
        }

        function getTableButtons(actions) {
          return actions.map(function(action) {
            return {
              text: action.name,
              action: function() {
                $timeout(function() {
                  action.callback();
                });
              },
              className: action.disabled && 'disabled' || '',
              titleAttr: action.titleAttr
            };
          });
        }

        function registerEvents(table) {
          table.on('click', 'tr', function() {
            var tr = $(this).closest('tr');
            var row = table.row(tr);
            if (row.child.isShown()) {
              scope.controller.toggleRefresh(true);
            }
            else {
              scope.controller.toggleRefresh(false);
            }
          });
        }

        function connectRowButtons(table) {
          if (!options.rowActions || options.rowActions instanceof Function) {
            return;
          }
          table.on('click', 'button', function(event) {
            $(this).blur();
            var target = $(event.target).closest('button');
            var rowIndex = parseInt(target.attr('row-index'));
            var actionIndex = parseInt(target.attr('action-index'));
            var action = options.rowActions[actionIndex];
            var row = scope.controller.list[rowIndex];
{'fraction_non_alphanumeric': 0.12230057293962097, 'fraction_numerical': 0.002754517408550022, 'mean_word_length': 1.6744254566882735, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2389637', 'n_tokens_mistral': 2236, 'n_tokens_neox': 2198, 'n_words': 428}