<commit_before>'use strict';

angular.module('irontest').controller('TestcasesController', ['$scope', 'Testcases', 'Teststeps', 'TestcaseRuns',
    '$stateParams', '$state', 'uiGridConstants', '$timeout', 'IronTestUtils', '$sce', '$window', '$uibModal',
  function($scope, Testcases, Teststeps, TestcaseRuns, $stateParams, $state, uiGridConstants, $timeout, IronTestUtils,
      $sce, $window, $uibModal) {
    $scope.BASIC_INFO_TAB_INDEX = 0;
    $scope.PROPERTIES_TAB_INDEX = 1;
    $scope.TEST_STEPS_TAB_INDEX = 2;
    $scope.DATA_TABLE_TAB_INDEX = 3;
    $scope.HTTP_STUBS_TAB_INDEX = 4;

    $scope.activeTabIndex = ($window.localStorage.lastSelectedTabOnTestcaseEditView) ?
      parseInt($window.localStorage.lastSelectedTabOnTestcaseEditView) : $scope.TEST_STEPS_TAB_INDEX;

    $scope.tabSelected = function(tabIndex) {
      //  store tab index
      $window.localStorage.lastSelectedTabOnTestcaseEditView = tabIndex;

      if (tabIndex === $scope.BASIC_INFO_TAB_INDEX) {
          $scope.handleTestcaseRunResultOutlineAreaDisplay();
      }
    };

    var timer;
    $scope.autoSave = function(isValid) {
      if (timer) $timeout.cancel(timer);
      timer = $timeout(function() {
        $scope.update(isValid);
      }, 2000);
    };

    $scope.$watch('testcase.teststeps', function() {
      if ($scope.testcase) {
        $scope.teststepGridOptions.data = $scope.testcase.teststeps;
      }
    });

    $scope.teststepGridOptions = {
      enableSorting: false, enableColumnMenus: false,
      rowTemplate: '<div grid="grid" class="ui-grid-draggable-row" draggable="true"><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader, \'custom\': true }" ui-grid-cell></div></div>',
      columnDefs: [
        {
          name: 'sequence', displayName: 'NO.', width: 55, minWidth: 55,
          cellTemplate: 'teststepGridSequenceCellTemplate.html'
        },
        {
          name: 'name', width: '45%', minWidth: 100,
          cellTemplate: 'teststepGridNameCellTemplate.html'
        },
        { name: 'type', width: 80, minWidth: 80 },
        { name: 'description' },
        {
          name: 'delete', width: 70, minWidth: 70, enableSorting: false, enableFiltering: false,
          cellTemplate: 'teststepGridDeleteCellTemplate.html'
        },
      ],
      onRegisterApi: function (gridApi) {
        $scope.teststepGridApi = gridApi;

        gridApi.draggableRows.on.rowDropped($scope, function (info) {
          var toSequence;
          if (info.fromIndex > info.toIndex) {    // row moved up
            toSequence = $scope.testcase.teststeps[info.toIndex + 1].sequence;
          } else {                            // row moved down
            toSequence = $scope.testcase.teststeps[info.toIndex - 1].sequence;
          }

          var testcase = new Testcases({
            id: $scope.testcase.id,
            teststeps: [
              { sequence: info.draggedRowEntity.sequence },    //  from sequence<commit_msg>refine UI<commit_after>'use strict';

angular.module('irontest').controller('TestcasesController', ['$scope', 'Testcases', 'Teststeps', 'TestcaseRuns',
    '$stateParams', '$state', 'uiGridConstants', '$timeout', 'IronTestUtils', '$sce', '$window', '$uibModal',
  function($scope, Testcases, Teststeps, TestcaseRuns, $stateParams, $state, uiGridConstants, $timeout, IronTestUtils,
      $sce, $window, $uibModal) {
    $scope.BASIC_INFO_TAB_INDEX = 0;
    $scope.PROPERTIES_TAB_INDEX = 1;
    $scope.TEST_STEPS_TAB_INDEX = 2;
    $scope.DATA_TABLE_TAB_INDEX = 3;
    $scope.HTTP_STUBS_TAB_INDEX = 4;

    $scope.activeTabIndex = ($window.localStorage.lastSelectedTabOnTestcaseEditView) ?
      parseInt($window.localStorage.lastSelectedTabOnTestcaseEditView) : $scope.TEST_STEPS_TAB_INDEX;

    $scope.tabSelected = function(tabIndex) {
      //  store tab index
      $window.localStorage.lastSelectedTabOnTestcaseEditView = tabIndex;

      if (tabIndex === $scope.BASIC_INFO_TAB_INDEX) {
          $scope.handleTestcaseRunResultOutlineAreaDisplay();
      }
    };

    var timer;
    $scope.autoSave = function(isValid) {
      if (timer) $timeout.cancel(timer);
      timer = $timeout(function() {
        $scope.update(isValid);
      }, 2000);
    };

    $scope.$watch('testcase.teststeps', function() {
      if ($scope.testcase) {
        $scope.teststepGridOptions.data = $scope.testcase.teststeps;
      }
    });

    $scope.teststepGridOptions = {
      enableSorting: false, enableColumnMenus: false,
      rowTemplate: '<div grid="grid" class="ui-grid-draggable-row" draggable="true"><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader, \'custom\': true }" ui-grid-cell></div></div>',
      columnDefs: [
        {
          name: 'sequence', displayName: 'NO.', width: 62, minWidth: 62,
          cellTemplate: 'teststepGridSequenceCellTemplate.html'
        },
        {
          name: 'name', width: '45%', minWidth: 100,
          cellTemplate: 'teststepGridNameCellTemplate.html'
        },
        { name: 'type', width: 80, minWidth: 80 },
        { name: 'description' },
        {
          name: 'delete', width: 78, minWidth: 78, enableSorting: false, enableFiltering: false,
          cellTemplate: 'teststepGridDeleteCellTemplate.html'
        },
      ],
      onRegisterApi: function (gridApi) {
        $scope.teststepGridApi = gridApi;

        gridApi.draggableRows.on.rowDropped($scope, function (info) {
          var toSequence;
          if (info.fromIndex > info.toIndex) {    // row moved up
            toSequence = $scope.testcase.teststeps[info.toIndex + 1].sequence;
          } else {                            // row moved down
            toSequence = $scope.testcase.teststeps[info.toIndex - 1].sequence;
          }

          var testcase = new Testcases({
            id: $scope.testcase.id,
            teststeps: [
              { sequence: info.draggedRowEntity.sequence },    //  from sequence
{'fraction_non_alphanumeric': 0.13858165256994145, 'fraction_numerical': 0.009108653220559532, 'mean_word_length': 2.8721662468513856, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4631004', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1880, 'n_words': 338}