<commit_before>'use strict';

angular.module('myApp.view4', ['ngRoute', 'ngAnimate'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/PlanSelection', {
    templateUrl: 'view4/view4.html',
    controller: 'View4Ctrl'
  });
}])
//filter for displaying sectors names from array with selected sectors
//sort arrays items by it length
.filter('selectedNames', function(){
  return function(list){
    var string = "";
    list.sort(function compare(a, b) {
      if (a.name.length < b.name.length) {
        return -1;
      }
      else if (a.name.length > b.name.length) {
        return 1;
      }
      else {
        return 0;
      }
    }).forEach(function plansList(element, index, array){
      string = string + element.name + "; "
    });
    return string
  }
})
// service for HTTPRequest
.factory('HealthCareSector', ['$http', function($http) {
  return $http.get('http://localhost:8080/app/Healthcare Sector.json')
    .success(function(data) {
      return angular.fromJson(data);
    })
    .error(function(err) {
      return err;
    });
}])

.factory('additionalSectors', ['$http', function($http) {
  return $http.get('http://localhost:8080/app/Additional Sectors.json')
    .success(function(data) {
      return angular.fromJson(data);
    })
    .error(function(err) {
      return err;
    });
}])
//TODO: add to cache industrySectors array and get it from cache if it is not undefined
.controller('View4Ctrl', ['$scope','HealthCareSector','additionalSectors','$cacheFactory',function($scope,HealthCareSector,additionalSectors,$cacheFactory) {
  $scope.showDetails = true;
//array with selected sectors and all sectors for each industry type
//use array with selected sectors for display its names and total amount of selected sectors for each industry type
  (function(){
    if(!angular.isUndefined($cacheFactory.get('industrySectors'))){
      $scope.industrySectors = $cacheFactory.get('industrySectors').get('industrySectors');//find cache value in cacheId
      $scope.selectedHC = true;
    }
    else{
      $scope.cache = $cacheFactory('industrySectors');
      $scope.industrySectors = [{name:"Healthcare Sector", selected:[], list: []},{name:"Technology Sector", selected:[], list: []},{name:"Basic Materials Sector", selected:[], list: []}];
      HealthCareSector.success(function(data){
        $scope.selectedHC = true;
        $scope.industrySectors[0].list = data.list;
      });
      $scope.cache.put('industrySectors', $scope.industrySectors)
    }
  })();<commit_msg>rewrite comments and add TODO statment<commit_after>'use strict';
//TODO:write unit-test for view4
angular.module('myApp.view4', ['ngRoute', 'ngAnimate'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/PlanSelection', {
    templateUrl: 'view4/view4.html',
    controller: 'View4Ctrl'
  });
}])
//filter for displaying sectors names from array with selected sectors
//sort arrays items by it length
.filter('selectedNames', function(){
  return function(list){
    var string = "";
    list.sort(function compare(a, b) {
      if (a.name.length < b.name.length) {
        return -1;
      }
      else if (a.name.length > b.name.length) {
        return 1;
      }
      else {
        return 0;
      }
    }).forEach(function plansList(element, index, array){
      string = string + element.name + "; "
    });
    return string
  }
})
// service for HTTPRequest
.factory('HealthCareSector', ['$http', function($http) {
  return $http.get('http://localhost:8080/app/Healthcare Sector.json')
    .success(function(data) {
      return angular.fromJson(data);
    })
    .error(function(err) {
      return err;
    });
}])

.factory('additionalSectors', ['$http', function($http) {
  return $http.get('http://localhost:8080/app/Additional Sectors.json')
    .success(function(data) {
      return angular.fromJson(data);
    })
    .error(function(err) {
      return err;
    });
}])
//when user leaves from view4 - array with selected and list sectors is added to cache and got form cache when user returns to view4 from another view
.controller('View4Ctrl', ['$scope','HealthCareSector','additionalSectors','$cacheFactory',function($scope,HealthCareSector,additionalSectors,$cacheFactory) {
  $scope.showDetails = true;
//array with selected sectors and all sectors for each industry type
//use array with selected sectors for display its names and total amount of selected sectors for each industry type
  (function(){
    if(!angular.isUndefined($cacheFactory.get('industrySectors'))){
      $scope.industrySectors = $cacheFactory.get('industrySectors').get('industrySectors');//find cached value in cacheId
      $scope.selectedHC = true;
    }
    else{
      $scope.cache = $cacheFactory('industrySectors');//create cacheId and put there value if this cacheId not found
      $scope.industrySectors = [{name:"Healthcare Sector", selected:[], list: []},{name:"Technology Sector", selected:[], list: []},{name:"Basic Materials Sector", selected:[], list: []}];
      HealthCareSector.success(function(data){
        $scope.selectedHC = true;
        $scope.industrySectors[0].list = data.list;
      });
      $scope.cache.put('industrySectors', $scope.industrySectors)
    }
  })();
{'fraction_non_alphanumeric': 0.1523845715371461, 'fraction_numerical': 0.00703021090632719, 'mean_word_length': 3.746618575293057, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5729046', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1561, 'n_words': 372}