<commit_before>'use strict';

//  NOTICE:
//    The $scope here prototypically inherits from the $scope of TeststepsController.
//    ng-include also creates a scope.
angular.module('irontest').controller('MQTeststepController', ['$scope', 'IronTestUtils', '$timeout', '$http',
    'Upload', '$window', 'Teststeps',
  function($scope, IronTestUtils, $timeout, $http, Upload, $window, Teststeps) {
    var timer;
    $scope.steprun = {};
    $scope.textMessageActiveTabIndex = 0;

    var clearPreviousRunAndAssertionVerificationStatus = function() {
      if (timer) $timeout.cancel(timer);
      $scope.steprun = {};
      $scope.assertionVerificationResult = null;
    };

    $scope.destinationTypeChanged = function(isValid) {
      var teststep = $scope.teststep;
      if (teststep.otherProperties.destinationType === 'Topic') {
        teststep.action = 'Publish';
      } else {              //  destinationType is Queue
        teststep.action = null;
      }
      $scope.actionChanged(isValid);
    };

    $scope.actionChanged = function(isValid) {
      clearPreviousRunAndAssertionVerificationStatus();

      var teststep = $scope.teststep;

      // initialize new action
      if (teststep.action === 'Enqueue' || teststep.action === 'Publish') {
        if (!teststep.otherProperties.messageFrom) {
          teststep.otherProperties.messageFrom = 'Text';
        }
      }

      //  save test step
      $scope.update(isValid);
    };

    $scope.endpointInfoIncomplete = function() {
      var endpointOtherProperties = $scope.teststep.endpoint.otherProperties;
      return !endpointOtherProperties.queueManagerName || !endpointOtherProperties.host ||
          !endpointOtherProperties.port || !endpointOtherProperties.svrConnChannelName;
    }

    $scope.actionInfoIncomplete = function() {
      var teststep = $scope.teststep;
      if (!teststep.action) {
        return true;
      } else if (teststep.otherProperties.destinationType === 'Queue') {
        return !teststep.otherProperties.queueName || (
          teststep.action === 'Enqueue' && (
            teststep.otherProperties.messageFrom === 'Text' && !teststep.request ||
            teststep.otherProperties.messageFrom === 'File' && !teststep.otherProperties.messageFilename
          )
        );
      } else if (teststep.otherProperties.destinationType === 'Topic') {
        return !teststep.otherProperties.topicString;
      } else {
        return true;
      }
    }

    $scope.doAction = function() {
      clearPreviousRunAndAssertionVerificationStatus();

      var teststep = new Teststeps($scope.teststep);
      $scope.steprun.status = 'ongoing';
      teststep.$run(function(basicTeststepRun) {
        $scope.steprun.response = basicTeststepRun.response.value;
        $scope.steprun.status = 'finished';
        timer = $timeout(function() {
          $scope.steprun.status = null;
        }, 15000);
      }, function(error) {
        $scope.steprun.status = 'failed';
        IronTestUtils.openErrorHTTPResponseModal(error);
      });
    };

    $scope.toggleRFH2Header = function(isValid) {
      var header = $scope.teststep.otherProperties.rfh2Header;
      if (header.enabled === true && header.folders.length === 0) {
        $scope.addRFH2Folder(isValid);
      } else {
        $scope.textMessageTabSelected(0);
        $scope.update(isValid);
      }
    };

    $scope.addRFH2Folder = function(isValid) {
      var folders = $scope.teststep.otherProperties.rfh2Header.folders;
      folders.push({ string: '<RFH2Folder></RFH2Folder>' });
      $scope.textMessageActiveTabIndex = folders.length;
      $scope.update(isValid);
    };<commit_msg>refine code<commit_after>'use strict';

//  NOTICE:
//    The $scope here prototypically inherits from the $scope of TeststepsController.
//    ng-include also creates a scope.
angular.module('irontest').controller('MQTeststepController', ['$scope', 'IronTestUtils', '$timeout', '$http',
    'Upload', '$window', 'Teststeps',
  function($scope, IronTestUtils, $timeout, $http, Upload, $window, Teststeps) {
    var timer;
    $scope.steprun = {};
    $scope.textMessageActiveTabIndex = 0;

    var clearPreviousRunStatus = function() {
      if (timer) $timeout.cancel(timer);
      $scope.steprun = {};
    };

    $scope.destinationTypeChanged = function(isValid) {
      var teststep = $scope.teststep;
      if (teststep.otherProperties.destinationType === 'Topic') {
        teststep.action = 'Publish';
      } else {              //  destinationType is Queue
        teststep.action = null;
      }
      $scope.actionChanged(isValid);
    };

    $scope.actionChanged = function(isValid) {
      clearPreviousRunStatus();

      var teststep = $scope.teststep;

      // initialize new action
      if (teststep.action === 'Enqueue' || teststep.action === 'Publish') {
        if (!teststep.otherProperties.messageFrom) {
          teststep.otherProperties.messageFrom = 'Text';
        }
      }

      //  save test step
      $scope.update(isValid);
    };

    $scope.endpointInfoIncomplete = function() {
      var endpointOtherProperties = $scope.teststep.endpoint.otherProperties;
      return !endpointOtherProperties.queueManagerName || !endpointOtherProperties.host ||
          !endpointOtherProperties.port || !endpointOtherProperties.svrConnChannelName;
    }

    $scope.actionInfoIncomplete = function() {
      var teststep = $scope.teststep;
      if (!teststep.action) {
        return true;
      } else if (teststep.otherProperties.destinationType === 'Queue') {
        return !teststep.otherProperties.queueName || (
          teststep.action === 'Enqueue' && (
            teststep.otherProperties.messageFrom === 'Text' && !teststep.request ||
            teststep.otherProperties.messageFrom === 'File' && !teststep.otherProperties.messageFilename
          )
        );
      } else if (teststep.otherProperties.destinationType === 'Topic') {
        return !teststep.otherProperties.topicString;
      } else {
        return true;
      }
    }

    $scope.doAction = function() {
      clearPreviousRunStatus();

      var teststep = new Teststeps($scope.teststep);
      $scope.steprun.status = 'ongoing';
      teststep.$run(function(basicTeststepRun) {
        $scope.steprun.response = basicTeststepRun.response.value;
        $scope.steprun.status = 'finished';
        timer = $timeout(function() {
          $scope.steprun.status = null;
        }, 15000);
      }, function(error) {
        $scope.steprun.status = 'failed';
        IronTestUtils.openErrorHTTPResponseModal(error);
      });
    };

    $scope.toggleRFH2Header = function(isValid) {
      var header = $scope.teststep.otherProperties.rfh2Header;
      if (header.enabled === true && header.folders.length === 0) {
        $scope.addRFH2Folder(isValid);
      } else {
        $scope.textMessageTabSelected(0);
        $scope.update(isValid);
      }
    };

    $scope.addRFH2Folder = function(isValid) {
      var folders = $scope.teststep.otherProperties.rfh2Header.folders;
      folders.push({ string: '<RFH2Folder></RFH2Folder>' });
      $scope.textMessageActiveTabIndex = folders.length;
      $scope.update(isValid);
    };
{'fraction_non_alphanumeric': 0.13177971979470107, 'fraction_numerical': 0.004161464835622139, 'mean_word_length': 2.859743040685225, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5531662', 'n_tokens_mistral': 2063, 'n_tokens_neox': 2040, 'n_words': 351}