<commit_before>'use strict';

(function() {
  angular.module('ncsaas')
    .controller('ProjectListController', ['$location', 'projectsService', ProjectListController]);

  function ProjectListController($location, projectsService) {
    var vm = this;

    vm.list = {};
    vm.deleteProject = deleteProject;

    // pagination
    vm.changePageSize = changePageSize;
    vm.changePage = changePage;
    vm.getNumber = getNumber;
    vm.pageSizes = [5, 10, 20, 50];
    vm.currentPageSize = projectsService.pageSize;
    vm.pages = projectsService.pages ? projectsService.pages : 5;
    vm.currentPage = projectsService.page;

    function deleteProject(project, index) {
      var confirmDelete = confirm('Confirm project deletion?');
      if (confirmDelete) {
        projectsService.$delete(project.uuid).then(
          function(response) {
            vm.list.splice(index, 1);
          },
          handleProjectDeletionException
        );
      } else {
        alert('Project was not deleted.');
      }
    }

    function handleProjectDeletionException(response) {
      var message = response.data.status || response.data.detail;
      alert(message);
    }

    function activate() {
      initList();
    }

    function initList() {
      projectsService.getList(null, true, true).then(function(response) {
        vm.pages = projectsService.pages;
        vm.list = response;
      });
    }

    function changePageSize(pageSize) {
      vm.currentPageSize = pageSize;
      vm.currentPage = 1;
      projectsService.page = 1;
      projectsService.pageSize = pageSize;
      initList();
    }

    function changePage(page) {
      vm.currentPage = page;
      projectsService.page = page;
      initList();
    }

    function getNumber(num) {
      return new Array(num);
    }

    activate();

  }

  angular.module('ncsaas')
    .controller('ProjectAddController', ['$state', 'projectsService', 'customersService', ProjectAddController]);

  function ProjectAddController($state, projectsService, customersService) {
    var vm = this;

    vm.project = projectsService.createProject();
    vm.customersList = customersService.getCustomersList();
    vm.save = save;

    function save() {
      // TODO: refactor this function to use named urls and uuid field instead - SAAS-108
      vm.project.$save(function() {
        var url = vm.project.url,
          array = url.split ('/').filter(function(el) {
            return el.length !== 0;
          }),
          uuidNew = array[4];
        $state.go('project', {uuid:uuidNew});
      });
    }

  }

  angular.module('ncsaas')
    .controller('ProjectDetailUpdateController', [
      '$stateParams',
      '$rootScope',
      'projectsService',
      ProjectDetailUpdateController
    ]);

  function ProjectDetailUpdateController($stateParams, $rootScope, projectsService) {
    var vm = this;

    vm.activeTab = 'eventlog';
    vm.project = projectsService.getProject($stateParams.uuid);
    vm.update = update;

    function update() {
      vm.project.$update();
    }

  }

})();
<commit_msg>Add search to projects controller (saas-176)<commit_after>'use strict';

(function() {
  angular.module('ncsaas')
    .controller('ProjectListController', ['$location', 'projectsService', ProjectListController]);

  function ProjectListController($location, projectsService) {
    var vm = this;

    vm.list = {};
    vm.deleteProject = deleteProject;

    // search
    vm.searchInput = '';
    vm.search = search;

    // pagination
    vm.changePageSize = changePageSize;
    vm.changePage = changePage;
    vm.getNumber = getNumber;
    vm.pageSizes = [5, 10, 20, 50];
    vm.currentPageSize = projectsService.pageSize;
    vm.pages = projectsService.pages ? projectsService.pages : 5;
    vm.currentPage = projectsService.page;

    function deleteProject(project, index) {
      var confirmDelete = confirm('Confirm project deletion?');
      if (confirmDelete) {
        projectsService.$delete(project.uuid).then(
          function(response) {
            vm.list.splice(index, 1);
          },
          handleProjectDeletionException
        );
      } else {
        alert('Project was not deleted.');
      }
    }

    function handleProjectDeletionException(response) {
      var message = response.data.status || response.data.detail;
      alert(message);
    }

    function search() {
      projectsService.getList({name: vm.searchInput}, true, true).then(function(response) {
        vm.list = response;
      });
    }

    function activate() {
      initList();
    }

    function initList() {
      projectsService.getList(null, true, true).then(function(response) {
        vm.pages = projectsService.pages;
        vm.list = response;
      });
    }

    function changePageSize(pageSize) {
      vm.currentPageSize = pageSize;
      vm.currentPage = 1;
      projectsService.page = 1;
      projectsService.pageSize = pageSize;
      initList();
    }

    function changePage(page) {
      vm.currentPage = page;
      projectsService.page = page;
      initList();
    }

    function getNumber(num) {
      return new Array(num);
    }

    activate();

  }

  angular.module('ncsaas')
    .controller('ProjectAddController', ['$state', 'projectsService', 'customersService', ProjectAddController]);

  function ProjectAddController($state, projectsService, customersService) {
    var vm = this;

    vm.project = projectsService.createProject();
    vm.customersList = customersService.getCustomersList();
    vm.save = save;

    function save() {
      // TODO: refactor this function to use named urls and uuid field instead - SAAS-108
      vm.project.$save(function() {
        var url = vm.project.url,
          array = url.split ('/').filter(function(el) {
            return el.length !== 0;
          }),
          uuidNew = array[4];
        $state.go('project', {uuid:uuidNew});
      });
    }

  }

  angular.module('ncsaas')
    .controller('ProjectDetailUpdateController', [
      '$stateParams',
      '$rootScope',
      'projectsService',
      ProjectDetailUpdateController
    ]);

  function ProjectDetailUpdateController($stateParams, $rootScope, projectsService) {
    var vm = this;

    vm.activeTab = 'eventlog';
    vm.project = projectsService.getProject($stateParams.uuid);
    vm.update = update;

    function update() {
      vm.project.$update();
    }

  }

})();

{'fraction_non_alphanumeric': 0.12585776668746101, 'fraction_numerical': 0.0054585152838427945, 'mean_word_length': 2.7198375870069604, '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': '2132723', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1785, 'n_words': 357}