<commit_before>'use strict';

// Team controller
angular.module('admin').controller('TeamController', ['$scope', '$stateParams', '$location', 'Authentication', 'Teams',
  function ($scope, $stateParams, $location, Authentication, Teams) {
    $scope.authentication = Authentication;
    $scope.showTeamAdded = false; 
    $scope.showTeamDeleted = false; 


    // Create new Team
    $scope.create = function (isValid) {
      $scope.error = null;

      if (!isValid) {
        $scope.$broadcast('show-errors-check-validity', 'teamForm');
        
        return false;
      }

      

      // Create new team object
      var team = new Teams({
        name: this.name
      });

      // Redirect after save
      team.$save(function (response) {
        $location.path('/teams');

        $scope.showTeamAdded = true;

        // Clear form fields
        $scope.name = '';
      }, function (errorResponse) {
        $scope.error = errorResponse.data.message;
      });
    };

    $scope.removeAll = function(){
      if(confirm('Press OK to confirm deletion.')){
        console.log($scope.teams.length);
        
        for(var i=0; i < $scope.teams.length; i++){
          console.log($scope.teams[i]);
          $scope.teams[i].$remove();
        }
        $scope.teams.splice(0, $scope.teams.length);
      }
    };

    $scope.updateTeams = function(){
      Teams.query(function(refreshedTeams){<commit_msg>Prevents app crashing if duplicate team is entered<commit_after>'use strict';

// Team controller
angular.module('admin').controller('TeamController', ['$scope', '$stateParams', '$location', 'Authentication', 'Teams',
  function ($scope, $stateParams, $location, Authentication, Teams) {
    $scope.authentication = Authentication;
    $scope.showTeamAdded = false; 
    $scope.showTeamDeleted = false;
    $scope.teams = null;  


    // Create new Team
    $scope.create = function (isValid) {
      $scope.error = null;
      $scope.teamToSave = this.name; 

      if (!isValid) {
        $scope.$broadcast('show-errors-check-validity', 'teamForm');
        
        return false;
      }
      $scope.find(); 
      $scope.teams.$promise.then(function(data){
        console.log(data);
        console.log($scope.teams.length);
        for(var i=0; i < $scope.teams.length; i++){
          console.log($scope.teams[i].name);
          if($scope.teams[i].name === $scope.teamToSave){
            console.log('duplicate name encountered');
            confirm('A team already exists with this name. Please choose another name.');
            return false; 
          }
        }
        // Create new team object
        var team = new Teams({
          name: $scope.teamToSave
        });

        // Redirect after save
        team.$save(function (response) {
          $location.path('/teams');

          $scope.showTeamAdded = true;

          // Clear form fields
          $scope.name = '';
        }, function (errorResponse) {
          $scope.error = errorResponse.data.message;
        });
      });

    };

    $scope.removeAll = function(){
      if(confirm('Press OK to confirm deletion.')){
        console.log($scope.teams.length);
        
        for(var i=0; i < $scope.teams.length; i++){
          console.log($scope.teams[i]);
          $scope.teams[i].$remove();
        }
        $scope.teams.splice(0, $scope.teams.length);
      }
    };

    $scope.updateTeams = function(){
      Teams.query(function(refreshedTeams){
{'fraction_non_alphanumeric': 0.15207373271889402, 'fraction_numerical': 0.0014400921658986176, 'mean_word_length': 2.2306976744186047, 'pattern_counts': {'":': 0, '<': 6, '<?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': '3871787', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1010, 'n_words': 202}