<commit_before>angular.module('topologyApp', ['kubernetesUI', 'ui.bootstrap'])
.config(['$httpProvider', function($httpProvider) {
  $httpProvider.defaults.headers.common['X-CSRF-Token'] = jQuery('meta[name=csrf-token]').attr('content');
}])
.controller('containerTopologyController', ['$scope', '$http', '$interval', "$location", function($scope, $http, $interval, $location) {
  $scope.vs = null;

  $scope.refresh = function() {
    var id;
    if ($location.absUrl().match("show/$") || $location.absUrl().match("show$")) {
      id = '';
    } else {
      id = '/'+ (/container_topology\/show\/(\d+)/.exec($location.absUrl())[1]);
    }

    var currentSelectedKinds = $scope.kinds;
    var url = '/container_topology/data'+id;

    $http.get(url).success(function(data) {
      $scope.items = data.data.items;
      $scope.relations = data.data.relations;
      $scope.kinds = data.data.kinds;

      if (currentSelectedKinds && (Object.keys(currentSelectedKinds).length != Object.keys($scope.kinds).length)) {
        $scope.kinds = currentSelectedKinds;
      }
    });
  };

  $scope.checkboxModel = {
    value: false
  };
  $scope.legendTooltip = "Click here to show/hide entities of this type";

  $scope.show_hide_names = function() {
     var vertices = $scope.vs;

     if ($scope.checkboxModel.value) {
       vertices.selectAll("text.attached-label")
         .style("display", "block");
     } else {
       vertices.selectAll("text.attached-label")
         .style("display", "none");
     }
  };

  $scope.refresh();
  var promise = $interval($scope.refresh, 1000 * 60 * 3);

  $scope.$on('$destroy', function() {
    $interval.cancel(promise);
  });

  $scope.$on("render", function(ev, vertices, added) {
    /*
     * We are passed two selections of <g> elements:
     * vertices: All the elements
     * added: Just the ones that were added
     */

    added.attr("class", function(d) {
      return d.item.kind;
    });

    added.append("circle")
      .attr("r", function(d) {
        return getDimensions(d).r;
      })
      .style("stroke", function(d) {
        switch (d.item.status) {
          case "OK":
          case "On":
          case "Ready":
          case "Running":
          case "Succeeded":
          case "Valid":
            return "#3F9C35";
          case "NotReady":
          case "Failed":
          case "Error":
          case "Unreachable":
            return "#CC0000";
          case 'Warning':
          case 'Waiting':
          case 'Pending':
            return "#EC7A08";
          case 'Unknown':
          case 'Terminated':
            return "#bbb";
        }
      });

    added.append("title");

    added.on("dblclick", function(d) {
      return dblclick(d);
    });

    added.append("text")
        .text(function(d) {
          return getIcon(d);
        })
      .attr('class', function(d) {
          switch(d.item.kind) {
            case 'ContainerManager':
              return 'icon '+ d.item.display_kind;
            default:
              return 'icon';
          }
        })
      .attr("y", function(d) {
        return getDimensions(d).y;
      })
      .attr("x", function(d) {
        return getDimensions(d).x;
      });

    added.append("text")
      .attr("x", 26)
      .attr("y", 24)
      .text(function(d) {
        return d.item.name;
      })
      .attr('class', 'attached-label')
      .style("display", function(d) {
        if ($scope.checkboxModel.value) {
          return "block";
        } else {
          return "none";
        }
      });

    added.selectAll("title").text(function(d) {
      var status = [
        "Name: " + d.item.name,
        "Type: " + d.item.display_kind,
        "Status: " + d.item.status
      ];

      if (d.item.kind == 'Host' || d.item.kind == 'VM') {
        status.push("Provider: " + d.item.provider);
      }

      return status.join("\n");
    });

    $scope.vs = vertices;

    /* Don't do default rendering */
    ev.preventDefault();
  });

  function class_name(d) {
    switch (d.item.kind) {
      case "ContainerService":
      case "ContainerRoute":
      case "ContainerNode":
      case "ContainerReplicator":
        return "container_" + d.item.display_kind.toLowerCase();

      case "Vm":
      case "Host":
      case "Container":
        return d.item.kind.toLowerCase();

      case "Pod":
        return "container_group";

      case "ContainerManager":
        return "vendor-" + _.snakeCase(d.item.display_kind);
    }
  }

  function dblclick(d) {
    var entity_url = "";
    var action = '/show/' + d.item.miq_id;
    switch (d.item.kind) {
      case "ContainerManager":
        entity_url = "ems_container";
        break;
      case "Container":
        entity_url = class_name(d);
        action = '/explorer';
      default :
        entity_url = class_name(d);
    }

    var url = '/' + entity_url + action;
    window.location.assign(url);
  }

  function getIcon(d) {
    switch (d.item.kind) {
      case 'Container':
        return '\uF1B2'; // fa-cube
      case "ContainerNode":
        return '\uE621';  // pficon-container-node
      case "ContainerRoute":
        return '\uE625'; // pficon-route<commit_msg>Fix #5993 navigating from topology to a specific container<commit_after>angular.module('topologyApp', ['kubernetesUI', 'ui.bootstrap'])
.config(['$httpProvider', function($httpProvider) {
  $httpProvider.defaults.headers.common['X-CSRF-Token'] = jQuery('meta[name=csrf-token]').attr('content');
}])
.controller('containerTopologyController', ['$scope', '$http', '$interval', "$location", function($scope, $http, $interval, $location) {
  $scope.vs = null;

  $scope.refresh = function() {
    var id;
    if ($location.absUrl().match("show/$") || $location.absUrl().match("show$")) {
      id = '';
    } else {
      id = '/'+ (/container_topology\/show\/(\d+)/.exec($location.absUrl())[1]);
    }

    var currentSelectedKinds = $scope.kinds;
    var url = '/container_topology/data'+id;

    $http.get(url).success(function(data) {
      $scope.items = data.data.items;
      $scope.relations = data.data.relations;
      $scope.kinds = data.data.kinds;

      if (currentSelectedKinds && (Object.keys(currentSelectedKinds).length != Object.keys($scope.kinds).length)) {
        $scope.kinds = currentSelectedKinds;
      }
    });
  };

  $scope.checkboxModel = {
    value: false
  };
  $scope.legendTooltip = "Click here to show/hide entities of this type";

  $scope.show_hide_names = function() {
     var vertices = $scope.vs;

     if ($scope.checkboxModel.value) {
       vertices.selectAll("text.attached-label")
         .style("display", "block");
     } else {
       vertices.selectAll("text.attached-label")
         .style("display", "none");
     }
  };

  $scope.refresh();
  var promise = $interval($scope.refresh, 1000 * 60 * 3);

  $scope.$on('$destroy', function() {
    $interval.cancel(promise);
  });

  $scope.$on("render", function(ev, vertices, added) {
    /*
     * We are passed two selections of <g> elements:
     * vertices: All the elements
     * added: Just the ones that were added
     */

    added.attr("class", function(d) {
      return d.item.kind;
    });

    added.append("circle")
      .attr("r", function(d) {
        return getDimensions(d).r;
      })
      .style("stroke", function(d) {
        switch (d.item.status) {
          case "OK":
          case "On":
          case "Ready":
          case "Running":
          case "Succeeded":
          case "Valid":
            return "#3F9C35";
          case "NotReady":
          case "Failed":
          case "Error":
          case "Unreachable":
            return "#CC0000";
          case 'Warning':
          case 'Waiting':
          case 'Pending':
            return "#EC7A08";
          case 'Unknown':
          case 'Terminated':
            return "#bbb";
        }
      });

    added.append("title");

    added.on("dblclick", function(d) {
      return dblclick(d);
    });

    added.append("text")
        .text(function(d) {
          return getIcon(d);
        })
      .attr('class', function(d) {
          switch(d.item.kind) {
            case 'ContainerManager':
              return 'icon '+ d.item.display_kind;
            default:
              return 'icon';
          }
        })
      .attr("y", function(d) {
        return getDimensions(d).y;
      })
      .attr("x", function(d) {
        return getDimensions(d).x;
      });

    added.append("text")
      .attr("x", 26)
      .attr("y", 24)
      .text(function(d) {
        return d.item.name;
      })
      .attr('class', 'attached-label')
      .style("display", function(d) {
        if ($scope.checkboxModel.value) {
          return "block";
        } else {
          return "none";
        }
      });

    added.selectAll("title").text(function(d) {
      var status = [
        "Name: " + d.item.name,
        "Type: " + d.item.display_kind,
        "Status: " + d.item.status
      ];

      if (d.item.kind == 'Host' || d.item.kind == 'VM') {
        status.push("Provider: " + d.item.provider);
      }

      return status.join("\n");
    });

    $scope.vs = vertices;

    /* Don't do default rendering */
    ev.preventDefault();
  });

  function class_name(d) {
    switch (d.item.kind) {
      case "ContainerService":
      case "ContainerRoute":
      case "ContainerNode":
      case "ContainerReplicator":
        return "container_" + d.item.display_kind.toLowerCase();

      case "Vm":
      case "Host":
      case "Container":
        return d.item.kind.toLowerCase();

      case "Pod":
        return "container_group";

      case "ContainerManager":
        return "vendor-" + _.snakeCase(d.item.display_kind);
    }
  }

  function dblclick(d) {
    var entity_url = "";
    var action = '/show/' + d.item.miq_id;
    switch (d.item.kind) {
      case "ContainerManager":
        entity_url = "ems_container";
        break;
      default :
        entity_url = class_name(d);
    }

    var url = '/' + entity_url + action;
    window.location.assign(url);
  }

  function getIcon(d) {
    switch (d.item.kind) {
      case 'Container':
        return '\uF1B2'; // fa-cube
      case "ContainerNode":
        return '\uE621';  // pficon-container-node
      case "ContainerRoute":
        return '\uE625'; // pficon-route
{'fraction_non_alphanumeric': 0.166779333655239, 'fraction_numerical': 0.006373732496378561, 'mean_word_length': 2.10990990990991, 'pattern_counts': {'":': 45, '<': 5, '<?xml version=': 0, '>': 5, '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': '4674110', 'n_tokens_mistral': 3325, 'n_tokens_neox': 3222, 'n_words': 621}