<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

angular.module('clobberer', ['relengapi', 'initial_data']);
angular
  .module('clobberer')
  .controller('ClobberController', function($scope, restapi, initial_data) {

    $scope.branches = initial_data.branches;
    $scope.selectedBranch = initial_data.selected_branch || $scope.branches[0];

    /* Tracks all checkbox models */ 
    $scope.selectedBuilders = null;
  
    /* When a user selects a new branch. */ 
    $scope.expandBranch = function(branch) {
        $scope.selectedBuilders = {};
        $scope.selectAllBuilders = false; 
        $scope.branchData = undefined;
        $scope.builderFilter = undefined;
         
        restapi.get('/clobberer/lastclobber/branch/by-builder/' + branch).
            then(function (data, status, headers, config) {
                console.log(data);
                $scope.branchData = data.data.result;
            });
    };

    /* Returns builder names from branchData filtered by builderFilter. */
    $scope.availableBuilders = function() {
        var builders = [];
        for (builder in $scope.branchData) {
                if ($scope.builderFilter == undefined ||
                    builder.toLowerCase().match(
                      $scope.builderFilter.toLowerCase()) != null) {
                    builders.push(builder);
                }
        }
        return builders; 
    };

    $scope.submitClobbers = function() {
        var clobberData = [];
        var clobberTimes = [];
        /* Break transformation of branchData into steps to avoid deep loops */
        for (builderName in  $scope.selectedBuilders) {
            if ($scope.selectedBuilders[builderName] == true) {
                clobberTimes = clobberTimes.concat($scope.branchData[builderName]);
            }
        }
        var arrayLength = clobberTimes.length;
        for (var index = 0; index < arrayLength; index++) {
            clobberData.push({
                "branch": clobberTimes[index].branch,
                "builddir": clobberTimes[index].builddir
            })
        }
        restapi.post('/clobberer/clobber', clobberData).
        then(function(response) {
            $scope.expandBranch($scope.selectedBranch);
        });
    };
  
    $scope.selectAllBuilders = false; 
    $scope.toggleSelectedBuilders = function() {
        var builders = $scope.availableBuilders();
        for (index in builders) {
            $scope.selectedBuilders[builders[index]] = !$scope.selectAllBuilders;
        }
    };
    
    /*To determine if any ng-checkbox models in an object are checked*/
    $scope.objHasSelectedCheckboxes = function(obj) {
        for (key in obj) {
            if (obj[key] == true) {
                return true;
            }
        }
        return false;
    };
    
    if ($scope.selectedBranch != null) {
        $scope.expandBranch($scope.selectedBranch);
    }

    // Taskcluster

    $scope.purgeCacheButtonDisabled = function() {
      if ($scope.TCBranches === null) {
        return true;
      } else {
        return false;
      }
    };

    $scope.toggleWorkerTypes = function() {
      if ($scope.currentWorkerTypes().length > 0) {
        for (let workerType in $scope.selectedTCBranch.workerTypes) {
          $scope.selectedTCWorkerTypes[workerType] = false;
        }
        $scope.toggleWorkerTypesButton = false;

      } else {
        for (let workerType in $scope.selectedTCBranch.workerTypes) {
          $scope.selectedTCWorkerTypes[workerType] = true;
        }
        $scope.toggleWorkerTypesButton = true;
      }
    };

    $scope.clearSelectedTCWorkerTypes = function() {
      $scope.selectedTCWorkerTypes = {};
    };

    $scope.currentWorkerTypes = function() {
      return Object.keys($scope.selectedTCWorkerTypes)
                .filter(function(i) { return $scope.selectedTCWorkerTypes[i] === true; });
    };

    $scope.listWorkerTypes = function() {
      workerTypes = [];
      if ($scope.selectedTCBranch !== null) {
        for (let workerType in $scope.selectedTCBranch.workerTypes) {
          workerTypes.push($scope.selectedTCBranch.workerTypes[workerType]);
        }
      }
      return workerTypes;
    };

    $scope.loadBranches = function() {<commit_msg>Ticket 371 : Changed let to var, fixes #372<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

angular.module('clobberer', ['relengapi', 'initial_data']);
angular
  .module('clobberer')
  .controller('ClobberController', function($scope, restapi, initial_data) {

    $scope.branches = initial_data.branches;
    $scope.selectedBranch = initial_data.selected_branch || $scope.branches[0];

    /* Tracks all checkbox models */ 
    $scope.selectedBuilders = null;
  
    /* When a user selects a new branch. */ 
    $scope.expandBranch = function(branch) {
        $scope.selectedBuilders = {};
        $scope.selectAllBuilders = false; 
        $scope.branchData = undefined;
        $scope.builderFilter = undefined;
         
        restapi.get('/clobberer/lastclobber/branch/by-builder/' + branch).
            then(function (data, status, headers, config) {
                console.log(data);
                $scope.branchData = data.data.result;
            });
    };

    /* Returns builder names from branchData filtered by builderFilter. */
    $scope.availableBuilders = function() {
        var builders = [];
        for (builder in $scope.branchData) {
                if ($scope.builderFilter == undefined ||
                    builder.toLowerCase().match(
                      $scope.builderFilter.toLowerCase()) != null) {
                    builders.push(builder);
                }
        }
        return builders; 
    };

    $scope.submitClobbers = function() {
        var clobberData = [];
        var clobberTimes = [];
        /* Break transformation of branchData into steps to avoid deep loops */
        for (builderName in  $scope.selectedBuilders) {
            if ($scope.selectedBuilders[builderName] == true) {
                clobberTimes = clobberTimes.concat($scope.branchData[builderName]);
            }
        }
        var arrayLength = clobberTimes.length;
        for (var index = 0; index < arrayLength; index++) {
            clobberData.push({
                "branch": clobberTimes[index].branch,
                "builddir": clobberTimes[index].builddir
            })
        }
        restapi.post('/clobberer/clobber', clobberData).
        then(function(response) {
            $scope.expandBranch($scope.selectedBranch);
        });
    };
  
    $scope.selectAllBuilders = false; 
    $scope.toggleSelectedBuilders = function() {
        var builders = $scope.availableBuilders();
        for (index in builders) {
            $scope.selectedBuilders[builders[index]] = !$scope.selectAllBuilders;
        }
    };
    
    /*To determine if any ng-checkbox models in an object are checked*/
    $scope.objHasSelectedCheckboxes = function(obj) {
        for (key in obj) {
            if (obj[key] == true) {
                return true;
            }
        }
        return false;
    };
    
    if ($scope.selectedBranch != null) {
        $scope.expandBranch($scope.selectedBranch);
    }

    // Taskcluster

    $scope.purgeCacheButtonDisabled = function() {
      if ($scope.TCBranches === null) {
        return true;
      } else {
        return false;
      }
    };

    $scope.toggleWorkerTypes = function() {
      if ($scope.currentWorkerTypes().length > 0) {
        for (var workerType in $scope.selectedTCBranch.workerTypes) {
          $scope.selectedTCWorkerTypes[workerType] = false;
        }
        $scope.toggleWorkerTypesButton = false;

      } else {
        for (var workerType in $scope.selectedTCBranch.workerTypes) {
          $scope.selectedTCWorkerTypes[workerType] = true;
        }
        $scope.toggleWorkerTypesButton = true;
      }
    };

    $scope.clearSelectedTCWorkerTypes = function() {
      $scope.selectedTCWorkerTypes = {};
    };

    $scope.currentWorkerTypes = function() {
      return Object.keys($scope.selectedTCWorkerTypes)
                .filter(function(i) { return $scope.selectedTCWorkerTypes[i] === true; });
    };

    $scope.listWorkerTypes = function() {
      workerTypes = [];
      if ($scope.selectedTCBranch !== null) {
        for (let workerType in $scope.selectedTCBranch.workerTypes) {
          workerTypes.push($scope.selectedTCBranch.workerTypes[workerType]);
        }
      }
      return workerTypes;
    };

    $scope.loadBranches = function() {
{'fraction_non_alphanumeric': 0.11957255343082114, 'fraction_numerical': 0.0022497187851518562, 'mean_word_length': 2.171958615768819, 'pattern_counts': {'":': 4, '<': 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': '5520656', 'n_tokens_mistral': 2509, 'n_tokens_neox': 2452, 'n_words': 513}