<commit_before>/// <reference path="jmxPlugin.ts"/>

namespace Jmx {

  _module.controller("Jmx.TreeHeaderController", ["$scope", ($scope) => {
    $scope.expandAll = () => {
      (<any>$('#jmxtree')).treeview('expandAll', { silent: true });
    };

    $scope.contractAll = () => {
      (<any>$('#jmxtree')).treeview('collapseAll', { silent: true });
    };

    const treeElement: any = $('#jmxtree');
    const search = _.debounce(
      filter => treeElement.treeview('search', [
        filter,
        {
          ignoreCase: true,
          exactMatch: false,
          revealResults: true
        }
      ]), 300, { leading: false, trailing: true });

    $scope.filter = '';
    $scope.$watch('filter', (filter, previous) => {
      if (filter !== previous) {
        search(filter);
      }
    });
  }]);

  _module.controller("Jmx.MBeansController", ["$scope", "$location", "workspace", "$route", ($scope, $location: ng.ILocationService, workspace: Workspace, $route: angular.route.IRouteService) => {

    $scope.num = 1;

    $scope.$on("$routeChangeSuccess", function (event, current, previous) {
      // lets do this asynchronously to avoid Error: $digest already in progress
      setTimeout(updateSelectionFromURL, 50);
    });

    $scope.$on("$routeUpdate", function (ev, params) {
      if (params && params.params && params.params.tab && params.params.tab.match(/notree$/)) {
        $route.reload();
      }
    });

    $scope.select = (node:NodeSelection) => {
      $scope.workspace.updateSelectionNode(node);
      Core.$apply($scope);
    };

    function updateSelectionFromURL() {
      updateTreeSelectionFromURL($location, $('#jmxtree'));
    }

    $scope.populateTree = () => {
      var treeElement = $('#jmxtree');
      $scope.tree = workspace.tree;
      enableTree($scope, $location, workspace, treeElement, $scope.tree.children);
      setTimeout(updateSelectionFromURL, 50);
    };

    $scope.$on('$destroy', () => {
      // Bootstrap tree view leaks the node elements into the data structure
      // so let's clean this up when the user leaves the view
      const cleanTreeFolder = (node:Folder) => {
          delete node['$el'];
          if (node.nodes) node.nodes.forEach(cleanTreeFolder);
      };
      cleanTreeFolder($scope.tree);
      // Then call the tree clean-up method
      const treeElement: any = $('#jmxtree');
      treeElement.treeview('remove');
    });

    $scope.$on('jmxTreeUpdated', $scope.populateTree);

    $scope.populateTree();
  }]);
}<commit_msg>Add TODOs<commit_after>/// <reference path="jmxPlugin.ts"/>

namespace Jmx {

  _module.controller("Jmx.TreeHeaderController", ["$scope", ($scope) => {
    $scope.expandAll = () => {
      (<any>$('#jmxtree')).treeview('expandAll', { silent: true });
    };

    $scope.contractAll = () => {
      (<any>$('#jmxtree')).treeview('collapseAll', { silent: true });
    };

    const treeElement: any = $('#jmxtree');
    const search = _.debounce(
      filter => treeElement.treeview('search', [
        filter,
        {
          ignoreCase: true,
          exactMatch: false,
          revealResults: true
        }
      ]), 300, { leading: false, trailing: true });

    $scope.filter = '';
    $scope.$watch('filter', (filter, previous) => {
      if (filter !== previous) {
        // TODO: display a badge with the search result count
        search(filter);
      }
    });
  }]);

  _module.controller("Jmx.MBeansController", ["$scope", "$location", "workspace", "$route", ($scope, $location: ng.ILocationService, workspace: Workspace, $route: angular.route.IRouteService) => {

    $scope.num = 1;

    $scope.$on("$routeChangeSuccess", function (event, current, previous) {
      // lets do this asynchronously to avoid Error: $digest already in progress
      setTimeout(updateSelectionFromURL, 50);
    });

    $scope.$on("$routeUpdate", function (ev, params) {
      if (params && params.params && params.params.tab && params.params.tab.match(/notree$/)) {
        $route.reload();
      }
    });

    $scope.select = (node:NodeSelection) => {
      $scope.workspace.updateSelectionNode(node);
      Core.$apply($scope);
    };

    function updateSelectionFromURL() {
      updateTreeSelectionFromURL($location, $('#jmxtree'));
    }

    $scope.populateTree = () => {
      var treeElement = $('#jmxtree');
      $scope.tree = workspace.tree;
      enableTree($scope, $location, workspace, treeElement, $scope.tree.children);
      setTimeout(updateSelectionFromURL, 50);
    };

    $scope.$on('$destroy', () => {
      // TODO: clear search filter results
      // Bootstrap tree view leaks the node elements into the data structure
      // so let's clean this up when the user leaves the view
      const cleanTreeFolder = (node:Folder) => {
          delete node['$el'];
          if (node.nodes) node.nodes.forEach(cleanTreeFolder);
      };
      cleanTreeFolder($scope.tree);
      // Then call the tree clean-up method
      const treeElement: any = $('#jmxtree');
      treeElement.treeview('remove');
    });

    $scope.$on('jmxTreeUpdated', $scope.populateTree);

    $scope.populateTree();
  }]);
}
{'fraction_non_alphanumeric': 0.17141749078921853, 'fraction_numerical': 0.0031025790188093853, 'mean_word_length': 2.8840361445783134, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '3067073', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1491, 'n_words': 323}