<commit_before>angular.module('Aggie')

.controller('IncidentSelectModalController', [
  '$rootScope',
  '$scope',
  '$q',
  '$location',
  '$modal',
  '$modalStack',
  'Incident',
  'Report',
  'FlashService',
  function($rootScope, $scope, $q, $location, $modal, $modalStack, Incident, Report, flash) {

    $scope.setIncident = function(reports) {
      $modalStack.dismissAll();
      var modalInstance = $modal.open({
        windowClass: 'report-to-existing',
        size: 'lg',
        controller: 'IncidentSelectModalInstanceController',
        templateUrl: '/templates/incidents/report_incident_modal.html',
        resolve: {
          incidents: ['Incident', function(Incident) {
            return Incident.query().$promise;
          }],
          reports: function() {
            if (!reports) {
              reports = $scope.filterSelected($scope.reports);
            }

            return reports;
          }
        }
      });

      modalInstance.result.then(function(incidentId) {
        var ids = reports.map(function(report) {
          return report._id;
        });

        Report.linkToIncident({ ids: ids, incident: incidentId });
      });
    };
  }
])

.controller('IncidentSelectModalInstanceController', [
  '$rootScope',
  '$scope',
  '$modalInstance',
  'incidents',
  'reports',
  'Tags',
  'Incident',
  'paginationOptions',
  function($rootScope, $scope, $modalInstance, incidents, reports, Tags, Incident, paginationOptions) {
    $scope.reports = angular.copy(reports);
    $scope.incidents = incidents.results;
    $scope.modal = $modalInstance;
    $scope._showErrors = false;

    $scope.select = function(incident) {
      // report._incident = incident._id;
      $modalInstance.close(incident._id);
    };

    $scope.showErrors = function() {
      return $scope._showErrors;
    };

    $scope.save = function(form) {
      if (form.$invalid) {
        $scope._showErrors = true;
        return;
      }

      $modalInstance.close($scope.reports);
    };

    $scope.tagsToString = Tags.tagsToString;

    $scope.close = function() {
      $modalInstance.dismiss('cancel');
    };

    $scope.pagination = {
      page: 1,
      perPage: paginationOptions.perPage,
      start: 1,
      end: $scope.incidents.length,
      total: incidents.total
    };

    $scope.getPage = function(page) {

      Incident.query({ page: page - 1 }).$promise
        .then(function(incidents) {
          $scope.incidents = incidents.results;
          var perPage = $scope.pagination.perPage;
          var start = (page - 1) * perPage;
          var l = $scope.incidents.length;
          $scope.pagination.start = start + 1;
          $scope.pagination.end = (page - 1) * perPage + l;
          $scope.pagination.page = page;

        });
    };

    $scope.isFirstPage = function() {
      return $scope.pagination.page === 1;
    };

    $scope.isLastPage = function() {
      // Horrible hack
      return $scope.pagination.end % $scope.pagination.perPage !== 0;
    };
  }
]);<commit_msg>7402: Better last page check for incident table<commit_after>angular.module('Aggie')

.controller('IncidentSelectModalController', [
  '$rootScope',
  '$scope',
  '$q',
  '$location',
  '$modal',
  '$modalStack',
  'Incident',
  'Report',
  'FlashService',
  function($rootScope, $scope, $q, $location, $modal, $modalStack, Incident, Report, flash) {

    $scope.setIncident = function(reports) {
      $modalStack.dismissAll();
      var modalInstance = $modal.open({
        windowClass: 'report-to-existing',
        size: 'lg',
        controller: 'IncidentSelectModalInstanceController',
        templateUrl: '/templates/incidents/report_incident_modal.html',
        resolve: {
          incidents: ['Incident', function(Incident) {
            return Incident.query().$promise;
          }],
          reports: function() {
            if (!reports) {
              reports = $scope.filterSelected($scope.reports);
            }

            return reports;
          }
        }
      });

      modalInstance.result.then(function(incidentId) {
        var ids = reports.map(function(report) {
          return report._id;
        });

        Report.linkToIncident({ ids: ids, incident: incidentId });
      });
    };
  }
])

.controller('IncidentSelectModalInstanceController', [
  '$rootScope',
  '$scope',
  '$modalInstance',
  'incidents',
  'reports',
  'Tags',
  'Incident',
  'paginationOptions',
  function($rootScope, $scope, $modalInstance, incidents, reports, Tags, Incident, paginationOptions) {
    $scope.reports = angular.copy(reports);
    $scope.incidents = incidents.results;
    $scope.modal = $modalInstance;
    $scope._showErrors = false;

    $scope.select = function(incident) {
      // report._incident = incident._id;
      $modalInstance.close(incident._id);
    };

    $scope.showErrors = function() {
      return $scope._showErrors;
    };

    $scope.save = function(form) {
      if (form.$invalid) {
        $scope._showErrors = true;
        return;
      }

      $modalInstance.close($scope.reports);
    };

    $scope.tagsToString = Tags.tagsToString;

    $scope.close = function() {
      $modalInstance.dismiss('cancel');
    };

    $scope.pagination = {
      page: 1,
      perPage: paginationOptions.perPage,
      start: 1,
      end: $scope.incidents.length,
      total: incidents.total
    };

    $scope.getPage = function(page) {

      Incident.query({ page: page - 1 }).$promise
        .then(function(incidents) {
          $scope.incidents = incidents.results;
          var perPage = $scope.pagination.perPage;
          var start = (page - 1) * perPage;
          var l = $scope.incidents.length;
          $scope.pagination.start = start + 1;
          $scope.pagination.end = (page - 1) * perPage + l;
          $scope.pagination.page = page;

        });
    };

    $scope.isFirstPage = function() {
      return $scope.pagination.page === 1;
    };

    $scope.isLastPage = function() {
      return $scope.pagination.end === incidents.total;
    };
  }
]);
{'fraction_non_alphanumeric': 0.14740313272877165, 'fraction_numerical': 0.0031327287716405605, 'mean_word_length': 2.438775510204082, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3834472', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1812, 'n_words': 326}