<commit_before>'use strict';

/**
 */
angular.module('openolitor-admin')
  .controller('TourenDetailController', ['$scope', '$rootScope', '$filter', 'localeSensitiveComparator',
    'TourenService', 'TourenDetailModel', 'KundenOverviewModel', 'NgTableParams', 'cloneObj', '$routeParams', '$location', 'DetailNavigationService',
    function($scope, $rootScope, $filter, localeSensitiveComparator,TourenService, TourenDetailModel,KundenOverviewModel, NgTableParams, cloneObj, $routeParams, $location, DetailNavigationService) {
      $rootScope.viewId = 'D-Tou';
      
      $scope.unsortedTourlieferungen = [];
      $scope.sortedTourlieferungen = [];
      $scope.loading = false;

      $scope.query = {
        aktiveAbos: true
      };

      var defaults = {
        model: {
          id: undefined,
          name: '',
          beschreibung: undefined,
          tourlieferungen: []
        }
      };

      $scope.listToUse = function(id) {
        if ($filter('filter')($scope.sortedTourlieferungen,{id:id},true)[0] === undefined){
           return $scope.unsortedTourlieferungen;
        }
        else { return $scope.sortedTourlieferungen; }
      };

      $scope.navigateToKunde = function(id) {
          $scope.filteredEntries = [];
          var listKundeIds = []
          var list = $scope.listToUse(id)
          var currentKundeId = $filter('filter')(list,{id:id},true)[0];

          angular.forEach(list, function(tour){
              listKundeIds.push(tour.kundeId);
          });

          var allEntries = KundenOverviewModel.query({
          }, function() {
              angular.forEach(listKundeIds, function(kundeId){
                  $scope.filteredEntries.push($filter('filter')(allEntries,{id:kundeId},true)[0]);
              });
              DetailNavigationService.detailFromOverview(currentKundeId.kundeId, $scope, 'kunden', $location.url());
          });
      };

      $scope.save = function() {
        return $scope.tour.$save(function() {
          $scope.tourForm.$setPristine();
        });
      };

      $scope.created = function(id) {
        $location.path('/touren/' + id);
      };

      $scope.delete = function() {
        if (!$scope.isDeletable()) {
          return;
        }
        return $scope.tour.$delete();
      };

      $scope.isDeletable = function() {
        if ($scope.tour) {
          return $scope.tour.anzahlAbonnenten === 0;
        }
      };

      $scope.backToList = function() {
        $location.path('/touren');
      };

      $scope.loadTour = function() {
        TourenDetailModel.get({
          id: $routeParams.id,
          aktiveOnly: $scope.query.aktiveAbos
        }, function(result) {
          $scope.tour = result;
          $scope.unsortedTourlieferungen = [];
          $scope.sortedTourlieferungen = [];
          $scope.checkUnsorted();
        });
      };

      $scope.onSort = function(movedTourlieferung, partFrom, partTo) {
        //check if there is other entries from same customer
        if (partFrom === $scope.unsortedTourlieferungen && partTo === $scope.sortedTourlieferungen) {
          angular.forEach($scope.unsortedTourlieferungen, function(tourlieferung) {
            if(movedTourlieferung.kundeId === tourlieferung.kundeId) {
              $scope.unsortedTourlieferungen.splice($scope.unsortedTourlieferungen.indexOf(movedTourlieferung));
              $scope.sortedTourlieferungen.splice($scope.sortedTourlieferungen.indexOf(movedTourlieferung), 0, tourlieferung);
            }
          });
        }
        if (partFrom === $scope.sortedTourlieferungen && partTo === $scope.sortedTourlieferungen) {
          angular.forEach($scope.sortedTourlieferungen, function(tourlieferung) {<commit_msg>OO#453 abos availabe for tours are active and planned<commit_after>'use strict';

/**
 */
angular.module('openolitor-admin')
  .controller('TourenDetailController', ['$scope', '$rootScope', '$filter', 'localeSensitiveComparator',
    'TourenService', 'TourenDetailModel', 'KundenOverviewModel', 'NgTableParams', 'cloneObj', '$routeParams', '$location', 'DetailNavigationService',
    function($scope, $rootScope, $filter, localeSensitiveComparator,TourenService, TourenDetailModel,KundenOverviewModel, NgTableParams, cloneObj, $routeParams, $location, DetailNavigationService) {
      $rootScope.viewId = 'D-Tou';
      
      $scope.unsortedTourlieferungen = [];
      $scope.sortedTourlieferungen = [];
      $scope.loading = false;

      $scope.query = {
        aktiveAbos: true
      };

      var defaults = {
        model: {
          id: undefined,
          name: '',
          beschreibung: undefined,
          tourlieferungen: []
        }
      };

      $scope.listToUse = function(id) {
        if ($filter('filter')($scope.sortedTourlieferungen,{id:id},true)[0] === undefined){
           return $scope.unsortedTourlieferungen;
        }
        else { return $scope.sortedTourlieferungen; }
      };

      $scope.navigateToKunde = function(id) {
          $scope.filteredEntries = [];
          var listKundeIds = []
          var list = $scope.listToUse(id)
          var currentKundeId = $filter('filter')(list,{id:id},true)[0];

          angular.forEach(list, function(tour){
              listKundeIds.push(tour.kundeId);
          });

          var allEntries = KundenOverviewModel.query({
          }, function() {
              angular.forEach(listKundeIds, function(kundeId){
                  $scope.filteredEntries.push($filter('filter')(allEntries,{id:kundeId},true)[0]);
              });
              DetailNavigationService.detailFromOverview(currentKundeId.kundeId, $scope, 'kunden', $location.url());
          });
      };

      $scope.save = function() {
        return $scope.tour.$save(function() {
          $scope.tourForm.$setPristine();
        });
      };

      $scope.created = function(id) {
        $location.path('/touren/' + id);
      };

      $scope.delete = function() {
        if (!$scope.isDeletable()) {
          return;
        }
        return $scope.tour.$delete();
      };

      $scope.isDeletable = function() {
        if ($scope.tour) {
          return $scope.tour.anzahlAbonnenten === 0;
        }
      };

      $scope.backToList = function() {
        $location.path('/touren');
      };

      $scope.loadTour = function() {
        TourenDetailModel.get({
          id: $routeParams.id,
          aktiveOrPlanned: $scope.query.aktiveAbos
        }, function(result) {
          $scope.tour = result;
          $scope.unsortedTourlieferungen = [];
          $scope.sortedTourlieferungen = [];
          $scope.checkUnsorted();
        });
      };

      $scope.onSort = function(movedTourlieferung, partFrom, partTo) {
        //check if there is other entries from same customer
        if (partFrom === $scope.unsortedTourlieferungen && partTo === $scope.sortedTourlieferungen) {
          angular.forEach($scope.unsortedTourlieferungen, function(tourlieferung) {
            if(movedTourlieferung.kundeId === tourlieferung.kundeId) {
              $scope.unsortedTourlieferungen.splice($scope.unsortedTourlieferungen.indexOf(movedTourlieferung));
              $scope.sortedTourlieferungen.splice($scope.sortedTourlieferungen.indexOf(movedTourlieferung), 0, tourlieferung);
            }
          });
        }
        if (partFrom === $scope.sortedTourlieferungen && partTo === $scope.sortedTourlieferungen) {
          angular.forEach($scope.sortedTourlieferungen, function(tourlieferung) {
{'fraction_non_alphanumeric': 0.13996537488347316, 'fraction_numerical': 0.0017312558263417232, 'mean_word_length': 2.5109864422627397, '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': '671428', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2206, 'n_words': 310}