<commit_before>
angular.module('openspecimen')
  .directive('osTabs', function() {
    return {
      restrict: 'E',

      transclude: true,

      controller: function($scope) {
        this.selected = 0;

        $scope.tabs = [];

        this.addTab = function(tab) {
          angular.extend(tab, {selected: false});
          $scope.tabs.push(tab);
        }

        this.selectTab = function($index) {
          if (this.selected == $index) {
            return;
          }

          angular.extend($scope.tabs[this.selected], {selected: false});

          this.selected = $index;
          angular.extend($scope.tabs[this.selected], {selected: true});
          $scope.tabs[this.selected].onSelect();
        }
      },

      link: function(scope, element, attrs, ctrl) {
        scope.tabs[ctrl.selected].selected = true;

        scope.selectTab = function(tab) {
          ctrl.selectTab(tab);
        }
      },

      templateUrl: 'modules/common/tabs.html'
    };
  })

  .directive('osTab', function() {
    return {
      restrict: 'E',
      require : '^osTabs',
      template: '<div ng-transclude ng-show="selected"></div>',
      transclude: true,
      replace : true,
      scope : {
        title : '@',
        onSelect : '&'
      },

      link: function(scope, element, attrs, tabsCtrl) {
        tabsCtrl.addTab(scope);
      }
    };
  });<commit_msg>OPSMN-4265: When the tabs are rendered using ng-repeat, the parent <os-tabs> link/controller is invoked before the child <os-tag> gets a chance to register itself with the parent controller.<commit_after>
angular.module('openspecimen')
  .directive('osTabs', function() {
    return {
      restrict: 'E',

      transclude: true,

      controller: function($scope) {
        this.selected = 0;

        $scope.tabs = [];

        this.addTab = function(tab) {
          angular.extend(tab, {selected: false});
          $scope.tabs.push(tab);

          if ($scope.tabs.length == 1) {
            tab.selected = true;
          }
        }

        this.selectTab = function($index) {
          if (this.selected == $index) {
            return;
          }

          angular.extend($scope.tabs[this.selected], {selected: false});

          this.selected = $index;
          angular.extend($scope.tabs[this.selected], {selected: true});
          $scope.tabs[this.selected].onSelect();
        }
      },

      link: function(scope, element, attrs, ctrl) {
        // scope.tabs[ctrl.selected].selected = true;

        scope.selectTab = function(tab) {
          ctrl.selectTab(tab);
        }
      },

      templateUrl: 'modules/common/tabs.html'
    };
  })

  .directive('osTab', function() {
    return {
      restrict: 'E',
      require : '^osTabs',
      template: '<div ng-transclude ng-show="selected"></div>',
      transclude: true,
      replace : true,
      scope : {
        title : '@',
        onSelect : '&'
      },

      link: function(scope, element, attrs, tabsCtrl) {
        tabsCtrl.addTab(scope);
      }
    };
  });
{'fraction_non_alphanumeric': 0.15070746956235603, 'fraction_numerical': 0.002303389272787101, 'mean_word_length': 1.9571984435797665, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2622563', 'n_tokens_mistral': 921, 'n_tokens_neox': 895, 'n_words': 174}