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

  angular.module('app.suggestions')
    .controller('SuggestionsIndexController', SuggestionsIndexController);

  var customSuggestionFilters = {
    contains: function contains (term, value, row, col) {
      return value.toLowerCase().indexOf(term.toLowerCase()) > -1
          || row.isSelected;
    },
    startsWith: function startsWith (term, value, row, col) {
      return value.toLowerCase().indexOf(term.toLowerCase()) === 0
          || row.isSelected;
    }
  };

  SuggestionsIndexController.$inject = ['$scope', 'socket', 'uiGridConstants',
                                        'ngDialog', 'SuggestionFactory', 'APP_CONFIG'];

  function SuggestionsIndexController($scope, socket, uiGridConstants,
                                      ngDialog, SuggestionFactory, APP_CONFIG) {
    $scope.suggestionsGridSelectionCount = 0;
    $scope.MODULE_PATH = APP_CONFIG.MODULE_PATH;
    $scope.newSuggestionClick = newSuggestionClick;
    $scope.notifyClick = notifyClick;

    $scope.suggestionsGrid = {
      enableFiltering: true,
      enableRowSelection: true,
      enableRowHeaderSelection: false,
      rowHeight: 24,
      multiSelect: true,
      enableSelectAll: false,
      enableHorizontalScrollbar: uiGridConstants.scrollbars.NEVER,
      columnDefs: [
        {
          name: 'id', type: 'number', visible: false,
          sort: {
            direction: uiGridConstants.ASC,
            priority: 0
          }
        },
        {
          name: 'title', type: 'string',
          filter: {
            condition: customSuggestionFilters.contains
          },
          width: '*',
          minWidth: 30
        },
        {
          name: 'author', type: 'string',
          filter: {
            condition: customSuggestionFilters.contains
          }
        },
        {
          name: 'isbn',
          type: 'string',
          displayName: 'ISBN',
          maxWidth: 130
        },
        {
          name: 'subject', type: 'string', visible: false,
          filter: {
            condition: customSuggestionFilters.contains
          }
        },
        {
          name: 'type',
          type: 'string',
          displayName: 'Format',
          filter: {
            condition: customSuggestionFilters.startsWith
          },
          width: 95
        },
        {
          name: 'patron',
          type: 'string',
          maxWidth: 130
        },
        {
          name: 'createdAt',
          type: 'date',
          displayName: 'Date',
          cellFilter: 'date:"yyyy-MM-dd"',
          width: 90,
        }
      ],
      onRegisterApi: onRegisterApi
    };

    onLoad();

    function onLoad() {

      fetchSuggestions();

      socket.on('suggestions:created', function (suggestion) {
        $scope.suggestionsGrid.data.push(new SuggestionFactory(suggestion));
        $scope.suggestionsGridApi.core.notifyDataChange(uiGridConstants.dataChange.EDIT);
      });

      socket.on('notices:sent', function () {
        $scope.suggestionsGridApi.selection.clearSelectedRows();
        fetchSuggestions();
      });
    }

    function fetchSuggestions() {
      SuggestionFactory.query(function (data) {
        $scope.suggestionsGrid.data = data;
      });
    }

    function onRegisterApi(gridApi) {
      $scope.suggestionsGridApi = gridApi;

      $scope.refreshClick = function refreshClick () {
        $scope.suggestionsGridApi.selection.clearSelectedRows();
        $scope.suggestionsGridApi.core.clearAllFilters();
        $scope.suggestionsGridApi.grid.resetColumnSorting();
      };

      gridApi.selection.on.rowSelectionChanged($scope, function (row) {
        $scope.suggestionsGridSelectionCount = gridApi.selection.getSelectedRows().length;
      });

      gridApi.selection.on.rowSelectionChangedBatch($scope, function (rows) {
        $scope.suggestionsGridSelectionCount = gridApi.selection.getSelectedRows().length;
      });
    }

    function newSuggestionClick() {
      ngDialog.open({
        template: APP_CONFIG.MODULE_PATH + 'suggestions/suggestions.new.html',
        className: 'ngdialog-theme-default',
        scope: $scope
      });
    }

    function notifyClick() {
      ngDialog.open({
        template: APP_CONFIG.MODULE_PATH + 'notifier/notifier.index.html',
        className: 'ngdialog-theme-default',
        scope: $scope,
        data: $scope.suggestionsGridApi.selection.getSelectedRows()
      });
    }
  }

  angular.module('app.suggestions')
    .controller('SuggestionsNewController', SuggestionsNewController);

  SuggestionsNewController.$inject = ['$scope', '$state', 'SuggestionFactory',
                                      'ItemTypesFactory', 'toastr'];

  function SuggestionsNewController($scope, $state, SuggestionFactory,
                                    ItemTypesFactory, toastr) {

    $scope.createNewSuggestion = createNewSuggestion;

    ItemTypesFactory.get(function (itemtypes) {
      $scope.itemtypes = itemtypes;
    });

    function createNewSuggestion() {
      SuggestionFactory.save($scope.suggestion, function success(value, responseHeaders) {
        $state.go('suggestions#index');
      }, function error(httpResponse) {
        toastr.error('Oops, something went wrong!');
        console.error('REST Error: ' + httpResponse.data.message);
      });

      $scope.closeThisDialog();
    }
  }

})();<commit_msg>custom filters for all columns<commit_after>(function() {
  'use strict';

  angular.module('app.suggestions')
    .controller('SuggestionsIndexController', SuggestionsIndexController);

  var customSuggestionFilters = {
    contains: function contains (term, value, row, col) {
      return value.toLowerCase().indexOf(term.toLowerCase()) > -1
          || row.isSelected;
    },
    startsWith: function startsWith (term, value, row, col) {
      return value.toLowerCase().indexOf(term.toLowerCase()) === 0
          || row.isSelected;
    }
  };

  SuggestionsIndexController.$inject = ['$scope', 'socket', 'uiGridConstants',
                                        'ngDialog', 'SuggestionFactory', 'APP_CONFIG'];

  function SuggestionsIndexController($scope, socket, uiGridConstants,
                                      ngDialog, SuggestionFactory, APP_CONFIG) {
    $scope.suggestionsGridSelectionCount = 0;
    $scope.MODULE_PATH = APP_CONFIG.MODULE_PATH;
    $scope.newSuggestionClick = newSuggestionClick;
    $scope.notifyClick = notifyClick;

    $scope.suggestionsGrid = {
      enableFiltering: true,
      enableRowSelection: true,
      enableRowHeaderSelection: false,
      rowHeight: 24,
      multiSelect: true,
      enableSelectAll: false,
      enableHorizontalScrollbar: uiGridConstants.scrollbars.NEVER,
      columnDefs: [
        {
          name: 'id', type: 'number', visible: false,
          sort: {
            direction: uiGridConstants.ASC,
            priority: 0
          }
        },
        {
          name: 'title', type: 'string',
          filter: {
            condition: customSuggestionFilters.contains
          },
          width: '*',
          minWidth: 30
        },
        {
          name: 'author', type: 'string',
          filter: {
            condition: customSuggestionFilters.contains
          }
        },
        {
          name: 'isbn',
          type: 'string',
          displayName: 'ISBN',
          maxWidth: 130,
          filter: {
            condition: customSuggestionFilters.contains
          }
        },
        {
          name: 'subject', type: 'string', visible: false,
          filter: {
            condition: customSuggestionFilters.contains
          }
        },
        {
          name: 'type',
          type: 'string',
          displayName: 'Format',
          filter: {
            condition: customSuggestionFilters.startsWith
          },
          width: 95
        },
        {
          name: 'patron',
          type: 'string',
          axWidth: 130,
          filter: {
            condition: customSuggestionFilters.contains
          }
        },
        {
          name: 'createdAt',
          type: 'date',
          displayName: 'Date',
          cellFilter: 'date:"yyyy-MM-dd"',
          width: 90,
          filter: {
            condition: customSuggestionFilters.contains
          }
        }
      ],
      onRegisterApi: onRegisterApi
    };

    onLoad();

    function onLoad() {

      fetchSuggestions();

      socket.on('suggestions:created', function (suggestion) {
        $scope.suggestionsGrid.data.push(new SuggestionFactory(suggestion));
        $scope.suggestionsGridApi.core.notifyDataChange(uiGridConstants.dataChange.EDIT);
      });

      socket.on('notices:sent', function () {
        $scope.suggestionsGridApi.selection.clearSelectedRows();
        fetchSuggestions();
      });
    }

    function fetchSuggestions() {
      SuggestionFactory.query(function (data) {
        $scope.suggestionsGrid.data = data;
      });
    }

    function onRegisterApi(gridApi) {
      $scope.suggestionsGridApi = gridApi;

      $scope.refreshClick = function refreshClick () {
        $scope.suggestionsGridApi.selection.clearSelectedRows();
        $scope.suggestionsGridApi.core.clearAllFilters();
        $scope.suggestionsGridApi.grid.resetColumnSorting();
      };

      gridApi.selection.on.rowSelectionChanged($scope, function (row) {
        $scope.suggestionsGridSelectionCount = gridApi.selection.getSelectedRows().length;
      });

      gridApi.selection.on.rowSelectionChangedBatch($scope, function (rows) {
        $scope.suggestionsGridSelectionCount = gridApi.selection.getSelectedRows().length;
      });
    }

    function newSuggestionClick() {
      ngDialog.open({
        template: APP_CONFIG.MODULE_PATH + 'suggestions/suggestions.new.html',
        className: 'ngdialog-theme-default',
        scope: $scope
      });
    }

    function notifyClick() {
      ngDialog.open({
        template: APP_CONFIG.MODULE_PATH + 'notifier/notifier.index.html',
        className: 'ngdialog-theme-default',
        scope: $scope,
        data: $scope.suggestionsGridApi.selection.getSelectedRows()
      });
    }
  }

  angular.module('app.suggestions')
    .controller('SuggestionsNewController', SuggestionsNewController);

  SuggestionsNewController.$inject = ['$scope', '$state', 'SuggestionFactory',
                                      'ItemTypesFactory', 'toastr'];

  function SuggestionsNewController($scope, $state, SuggestionFactory,
                                    ItemTypesFactory, toastr) {

    $scope.createNewSuggestion = createNewSuggestion;

    ItemTypesFactory.get(function (itemtypes) {
      $scope.itemtypes = itemtypes;
    });

    function createNewSuggestion() {
      SuggestionFactory.save($scope.suggestion, function success(value, responseHeaders) {
        $state.go('suggestions#index');
      }, function error(httpResponse) {
        toastr.error('Oops, something went wrong!');
        console.error('REST Error: ' + httpResponse.data.message);
      });

      $scope.closeThisDialog();
    }
  }

})();
{'fraction_non_alphanumeric': 0.11736624031705999, 'fraction_numerical': 0.0032426589803638984, 'mean_word_length': 2.2229317851959363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '934944', 'n_tokens_mistral': 3124, 'n_tokens_neox': 2967, 'n_words': 497}