<commit_before>(function() {
  'use strict';

  angular
  .module('roboconf.instances')
  .controller('InstancesListingController', instancesListingController);

  instancesListingController.$inject = ['$scope', 'rUtils', '$routeParams', 'rShare', '$window', 'rClient'];
  function instancesListingController($scope, rUtils, $routeParams, rShare, $window, rClient) {

    // Fields
    $scope.responseStatus = -1;
    $scope.appName = $routeParams.appName;
    $scope.searchFilter = '';
    $scope.searchVisible = true;
    $scope.template = '';
    $scope.askToDelete = false;
    $scope.orderingCriteria = 'instance.name';
    $scope.details = 'LIFECYCLE';

    // Menu actions
    $scope.menuActions = [
      {title: 'Create a New Instance', link: '#/app/' + $routeParams.appName + '/instances/new'},
      {title: 'separator'},
      {title: 'Deploy and Start All', fn: function() {
        performAll('deploy-all', false);
      }},
      {title: 'Stop All', fn: function() {
        performAll('stop-all', false);
      }},
      {title: 'Undeploy All', link: '', fn: function() {
        performAll('undeploy-all', false);
      }},
      {title: 'separator'},
      {title: 'Sort by name', link: '', fn: function() {
        if ($scope.orderingCriteria === 'instance.name') {
          $scope.orderingCriteria = '-instance.name';
        } else {
          $scope.orderingCriteria = 'instance.name';
        }
      }},
      {title: 'Sort by state', link: '', fn: function() {
        if ($scope.orderingCriteria === 'instance.status') {
          $scope.orderingCriteria = '-instance.status';
        } else {
          $scope.orderingCriteria = 'instance.status';
        }
      }}
    ];

    // Function declarations
    $scope.loadInstances = loadInstances;
    $scope.showInstance = showInstance;
    $scope.hideInstance = hideInstance;
    $scope.formatStatus = formatStatus;
    $scope.isNodeToHide = isNodeToHide;
    $scope.changeState = changeState;
    $scope.performAll = performAll;
    $scope.createChildInstance = createChildInstance;
    $scope.replicateInstance = replicateInstance;
    $scope.deleteInstance = deleteInstance;
    $scope.showDetailsSection = showDetailsSection;

    // Initial actions
    loadInstances();

    // Functions
    function loadInstances() {
      rClient.listInstances($scope.appName).then(function(instances) {
        $scope.responseStatus = 0;
        $scope.rootNodes = rUtils.buildInstancesTree(instances);

      }, function(response) {
        $scope.responseStatus = response.status;
      });
    }

    function showInstance(node, t) {
      var instance = node.instance;
      $scope.selectedInstance = instance;
      rUtils.showRightBlock(t);

      var isRoot = false;
      if (instance && instance.component && instance.component.installer) {
        isRoot = instance.component.installer.toLowerCase() === 'target';
      }

      var parentNotDeployed = isParentNotDeployed(node);
      $scope.template = findTemplateUrl(instance.status, isRoot, parentNotDeployed);
    }

    function showDetailsSection(section) {
      $scope.details = section;
    }

    function hideInstance() {
      $scope.selectedInstance = null;
      rUtils.hideRightBlock();
    }

    function createChildInstance() {
      if ($scope.selectedInstance) {
        rShare.feedLastItem($scope.selectedInstance);
        $window.location = '#/app/' + $scope.appName + '/instances/new';
      }
    }

    function replicateInstance() {
      if ($scope.selectedInstance) {
        $scope.selectedInstance.copy = true;
        createChildInstance();
      }
    }

    function deleteInstance() {

      rClient.deleteInstance($scope.appName, $scope.selectedInstance.path).then(function() {
        $scope.askToDelete = false;
        var node = findNode($scope.selectedInstance);
        var array = node.parent ? node.parent.children : $scope.rootNodes;
        var index = array.indexOf(node);
        if (index) {
          array.splice(index, 1);
        }

        hideInstance();
      });
    }

    function changeState(newState) {
      rClient.changeState($scope.appName, $scope.selectedInstance.path, newState);
      $scope.selectedInstance.status = 'CUSTOM';
    }

    function performAll(action, useInstance) {

      var path = useInstance ? $scope.selectedInstance.path : null;
      rClient.performActionOnInstance($scope.appName, path, action).then($scope.loadInstances);
      if (useInstance) {
        $scope.selectedInstance.status = 'CUSTOM';<commit_msg>roboconf/roboconf-platform#597 "Deploy this instance" button not working<commit_after>(function() {
  'use strict';

  angular
  .module('roboconf.instances')
  .controller('InstancesListingController', instancesListingController);

  instancesListingController.$inject = ['$scope', 'rUtils', '$routeParams', 'rShare', '$window', 'rClient'];
  function instancesListingController($scope, rUtils, $routeParams, rShare, $window, rClient) {

    // Fields
    $scope.responseStatus = -1;
    $scope.appName = $routeParams.appName;
    $scope.searchFilter = '';
    $scope.searchVisible = true;
    $scope.template = '';
    $scope.askToDelete = false;
    $scope.orderingCriteria = 'instance.name';
    $scope.details = 'LIFECYCLE';

    // Menu actions
    $scope.menuActions = [
      {title: 'Create a New Instance', link: '#/app/' + $routeParams.appName + '/instances/new'},
      {title: 'separator'},
      {title: 'Deploy and Start All', fn: function() {
        performAll('deploy-all', false);
      }},
      {title: 'Stop All', fn: function() {
        performAll('stop-all', false);
      }},
      {title: 'Undeploy All', link: '', fn: function() {
        performAll('undeploy-all', false);
      }},
      {title: 'separator'},
      {title: 'Sort by name', link: '', fn: function() {
        if ($scope.orderingCriteria === 'instance.name') {
          $scope.orderingCriteria = '-instance.name';
        } else {
          $scope.orderingCriteria = 'instance.name';
        }
      }},
      {title: 'Sort by state', link: '', fn: function() {
        if ($scope.orderingCriteria === 'instance.status') {
          $scope.orderingCriteria = '-instance.status';
        } else {
          $scope.orderingCriteria = 'instance.status';
        }
      }}
    ];

    // Function declarations
    $scope.loadInstances = loadInstances;
    $scope.showInstance = showInstance;
    $scope.hideInstance = hideInstance;
    $scope.formatStatus = formatStatus;
    $scope.isNodeToHide = isNodeToHide;
    $scope.changeState = changeState;
    $scope.performAll = performAll;
    $scope.createChildInstance = createChildInstance;
    $scope.replicateInstance = replicateInstance;
    $scope.deleteInstance = deleteInstance;
    $scope.showDetailsSection = showDetailsSection;

    // Initial actions
    loadInstances();

    // Functions
    function loadInstances() {
      rClient.listInstances($scope.appName).then(function(instances) {
        $scope.responseStatus = 0;
        $scope.rootNodes = rUtils.buildInstancesTree(instances);

      }, function(response) {
        $scope.responseStatus = response.status;
      });
    }

    function showInstance(node, t) {
      var instance = node.instance;
      $scope.selectedInstance = instance;
      rUtils.showRightBlock(t);

      var isRoot = false;
      if (instance && instance.component && instance.component.installer) {
        isRoot = instance.component.installer.toLowerCase() === 'target';
      }

      var parentNotDeployed = isParentNotDeployed(node);
      $scope.template = findTemplateUrl(instance.status, isRoot, parentNotDeployed);
    }

    function showDetailsSection(section) {
      $scope.details = section;
    }

    function hideInstance() {
      $scope.selectedInstance = null;
      rUtils.hideRightBlock();
    }

    function createChildInstance() {
      if ($scope.selectedInstance) {
        rShare.feedLastItem($scope.selectedInstance);
        $window.location = '#/app/' + $scope.appName + '/instances/new';
      }
    }

    function replicateInstance() {
      if ($scope.selectedInstance) {
        $scope.selectedInstance.copy = true;
        createChildInstance();
      }
    }

    function deleteInstance() {

      rClient.deleteInstance($scope.appName, $scope.selectedInstance.path).then(function() {
        $scope.askToDelete = false;
        var node = findNode($scope.selectedInstance);
        var array = node.parent ? node.parent.children : $scope.rootNodes;
        var index = array.indexOf(node);
        if (index) {
          array.splice(index, 1);
        }

        hideInstance();
      });
    }

    function changeState(newState) {
      rClient.changeInstanceState($scope.appName, $scope.selectedInstance.path, newState);
      $scope.selectedInstance.status = 'CUSTOM';
    }

    function performAll(action, useInstance) {

      var path = useInstance ? $scope.selectedInstance.path : null;
      rClient.performActionOnInstance($scope.appName, path, action).then($scope.loadInstances);
      if (useInstance) {
        $scope.selectedInstance.status = 'CUSTOM';
{'fraction_non_alphanumeric': 0.1376327603197197, 'fraction_numerical': 0.00098543742472353, 'mean_word_length': 2.898420827998293, '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': '5824725', 'n_tokens_mistral': 2653, 'n_tokens_neox': 2577, 'n_words': 483}