     return $location.path '/'
 
   m.active = false for m in $scope.endpoint.methods
-  initMethod $scope.currentMethod
+  $scope.currentMethod.active = true
 
   $log.debug 'CURRENT METHOD', $scope.currentMethod
 

  $scope.$watch methodWatch, updateLocation

Controllers.controller 'EndpointDetails', EndpointCtrl

Controllers.controller 'ResponseCtrl', ($q, $timeout, $scope, $log, xmlParser, TreeParsing) ->


  $scope.hasParams = -> Object.keys($scope.params).length > 0
  $scope.parsedData = []
  $scope.tree = expanded: false
  $scope.totalPromises = 0
  $scope.currentParsed = 0
  $scope.percentDone = 0

  startId = TreeParsing.nextId()

  ct = ($scope.headers['content-type'] ? '')
  if APPL_JSON.test ct
    parsed = try
      JSON.parse($scope.res.response)
    catch e
      {}
    $scope.formattedResponse = JSON.stringify(parsed, null, 2) if parsed?

  setTree = (tree) ->
    $scope.parsedData = tree
    $log.debug "Next id = #{ TreeParsing.nextId() }"
  
  $scope.makeBrowseableResponse = ->
    return if $scope.parsedData.length # Already done.
    promises = []
    if $scope.res.response?.length
      if APPL_JSON.test ct
        parsed = try
          JSON.parse($scope.res.response)
        catch e
          {}
        for k, v of parsed
          promises.push TreeParsing.parseObj k, v
      else if TEXT_XML.test(ct) or APPL_XML.test(ct)
        try
          dom = xmlParser.parse $scope.res.response
          promises.push TreeParsing.parseDOMElem(dom.documentElement)
        catch e
          $log.error 'Error parsing xml', e

    if promises.length
      $q.all(promises)
        .then((parsed) -> TreeParsing.expandTree parsed, not $scope.tree.expanded)
        .then setTree, $log.error

  $scope.browseable = APPL_JSON.test(ct) or APPL_XML.test(ct) or TEXT_XML.test(ct)

  $scope.isHTML = TEXT_HTML.test ct

  processingInstructions = /<\?[^?]*\?>/g
  $scope.cleanHTML = $scope.res.response.replace(processingInstructions, '')
