<commit_before>module Jmx {
  export function ChartEditController($scope, $location, workspace:Workspace) {
    $scope.workspace = workspace;
    $scope.selectedAttributes = [];
    $scope.selectedMBeans = [];
    $scope.metrics = {};
    $scope.mbeans = {};

    // TODO move this function to $routeScope
    $scope.size = (value) => {
      if (angular.isObject(value)) {
        return Object.size(value);
      } else if (angular.isArray(value)) {
        return value.length;
      } else return 1;
    };

    $scope.canViewChart = () => {
      return $scope.selectedAttributes.length && $scope.selectedMBeans.length &&
              $scope.size($scope.mbeans) > 0 && $scope.size($scope.metrics) > 0;
    };

    $scope.showAttributes = () => {
      return $scope.canViewChart() && $scope.size($scope.metrics) > 1;
    };

    $scope.showElements = () => {
      return $scope.canViewChart() && $scope.size($scope.mbeans) > 1;
    };

    $scope.viewChart = () => {
      // lets add the attributes and mbeans into the URL so we can navigate back to the charts view
      var search = $location.search();
      // if we have selected all attributes, then lets just remove the attribute
      if ($scope.selectedAttributes.length === $scope.size($scope.metrics)) {
        delete search["att"];
      } else {
        search["att"] = $scope.selectedAttributes;
      }
      // if we are on an mbean with no children lets discard an unnecessary parameter
      if ($scope.selectedMBeans.length === $scope.size($scope.mbeans) && $scope.size($scope.mbeans) === 1) {
        delete search["el"];
      } else {
        search["el"] = $scope.selectedMBeans;
      }
      $location.search(search);
      $location.path("jmx/charts");
    };

    $scope.$watch('workspace.selection', function () {
      if (workspace.moveIfViewInvalid()) return;

      $scope.selectedAttributes = [];
      $scope.selectedMBeans = [];
      $scope.metrics = {};
      $scope.mbeans = {};
      var mbeanCounter = 0;
      var resultCounter = 0;
      var jolokia = $scope.workspace.jolokia;
      var node = $scope.workspace.selection;
      if (node && jolokia) {
        // lets iterate through all the children
        var children = node.children;
        if (!children) {
          children = [node];
        }
        if (children) {
          children.forEach((mbeanNode) => {
            var mbean = mbeanNode.objectName;
            var name = mbeanNode.title;
            if (name && mbean) {
              mbeanCounter++;
              $scope.mbeans[name] = name;
              // we need to escape the mbean path for list
              var listKey = encodeMBeanPath(mbean);
              jolokia.list(listKey, onSuccess((meta) => {
                var attributes = meta.attr;
                if (attributes) {
                  for (var key in attributes) {
                    var value = attributes[key];
                    if (value) {
                      var typeName = value['type'];
                      if (isNumberTypeName(typeName)) {
                        if (!$scope.metrics[key]) {
                          //console.log("Number attribute " + key + " for " + mbean);<commit_msg>fix chart edit UI on non-folder mbeans<commit_after>module Jmx {
  export function ChartEditController($scope, $location, workspace:Workspace) {
    $scope.workspace = workspace;
    $scope.selectedAttributes = [];
    $scope.selectedMBeans = [];
    $scope.metrics = {};
    $scope.mbeans = {};

    // TODO move this function to $routeScope
    $scope.size = (value) => {
      if (angular.isObject(value)) {
        return Object.size(value);
      } else if (angular.isArray(value)) {
        return value.length;
      } else return 1;
    };

    $scope.canViewChart = () => {
      return $scope.selectedAttributes.length && $scope.selectedMBeans.length &&
              $scope.size($scope.mbeans) > 0 && $scope.size($scope.metrics) > 0;
    };

    $scope.showAttributes = () => {
      return $scope.canViewChart() && $scope.size($scope.metrics) > 1;
    };

    $scope.showElements = () => {
      return $scope.canViewChart() && $scope.size($scope.mbeans) > 1;
    };

    $scope.viewChart = () => {
      // lets add the attributes and mbeans into the URL so we can navigate back to the charts view
      var search = $location.search();
      // if we have selected all attributes, then lets just remove the attribute
      if ($scope.selectedAttributes.length === $scope.size($scope.metrics)) {
        delete search["att"];
      } else {
        search["att"] = $scope.selectedAttributes;
      }
      // if we are on an mbean with no children lets discard an unnecessary parameter
      if ($scope.selectedMBeans.length === $scope.size($scope.mbeans) && $scope.size($scope.mbeans) === 1) {
        delete search["el"];
      } else {
        search["el"] = $scope.selectedMBeans;
      }
      $location.search(search);
      $location.path("jmx/charts");
    };

    $scope.$watch('workspace.selection', function () {
      if (workspace.moveIfViewInvalid()) return;

      $scope.selectedAttributes = [];
      $scope.selectedMBeans = [];
      $scope.metrics = {};
      $scope.mbeans = {};
      var mbeanCounter = 0;
      var resultCounter = 0;
      var jolokia = $scope.workspace.jolokia;
      var node = $scope.workspace.selection;
      if (node && jolokia) {
        // lets iterate through all the children
        var children = node.children;
        if (!children || !children.length) {
          children = [node];
        }
        if (children) {
          children.forEach((mbeanNode) => {
            var mbean = mbeanNode.objectName;
            var name = mbeanNode.title;
            if (name && mbean) {
              mbeanCounter++;
              $scope.mbeans[name] = name;
              // we need to escape the mbean path for list
              var listKey = encodeMBeanPath(mbean);
              jolokia.list(listKey, onSuccess((meta) => {
                var attributes = meta.attr;
                if (attributes) {
                  for (var key in attributes) {
                    var value = attributes[key];
                    if (value) {
                      var typeName = value['type'];
                      if (isNumberTypeName(typeName)) {
                        if (!$scope.metrics[key]) {
                          //console.log("Number attribute " + key + " for " + mbean);
{'fraction_non_alphanumeric': 0.1359328879913003, 'fraction_numerical': 0.0024856299518409195, 'mean_word_length': 2.0211168465509153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '6882628', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1780, 'n_words': 430}