Bladeren bron

Fix file url in backtrace

Gaël Métais 10 jaren geleden
bovenliggende
commit
99c4b240ec
2 gewijzigde bestanden met toevoegingen van 17 en 61 verwijderingen
  1. 0 49
      front/src/js/controllers/timelineCtrl.js
  2. 17 12
      front/src/js/directives/offendersDirectives.js

+ 0 - 49
front/src/js/controllers/timelineCtrl.js

@@ -111,38 +111,6 @@ timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams',
         $scope.profilerData = $scope.executionTree;
     }
 
-
-    function parseBacktrace(str) {
-        if (!str) {
-            return null;
-        }
-
-        var out = [];
-        var splited = str.split(' / ');
-        splited.forEach(function(trace) {
-            var fnName = null, fileAndLine;
-
-            var withFnResult = /^([^\s\(]+) \((.+:\d+)\)$/.exec(trace);
-            if (withFnResult === null) {
-                fileAndLine = trace;
-            } else {
-                fnName = withFnResult[1];
-                fileAndLine = withFnResult[2];
-            }
-
-            var fileAndLineSplit = /^(.*):(\d+)$/.exec(fileAndLine);
-            var filePath = fileAndLineSplit[1];
-            var line = fileAndLineSplit[2];
-
-            out.push({
-                fnName: fnName,
-                filePath: filePath,
-                line: line
-            });
-        });
-        return out;
-    }
-
     $scope.changeScript = function() {
         initExecutionTree();
         initTimeline();
@@ -167,23 +135,6 @@ timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams',
         return lineIndex;
     };
 
-    $scope.onNodeDetailsClick = function(node) {
-        var isOpen = node.showDetails;
-        if (!isOpen) {
-            // Close all other nodes
-            $scope.executionTree.forEach(function(currentNode) {
-                currentNode.showDetails = false;
-            });
-
-            // Parse the backtrace
-            if (!node.parsedBacktrace) {
-                node.parsedBacktrace = parseBacktrace(node.data.backtrace);
-            }
-
-        }
-        node.showDetails = !isOpen;
-    };
-
 
     $scope.backToDashboard = function() {
         $location.path('/result/' + $scope.runId);

+ 17 - 12
front/src/js/directives/offendersDirectives.js

@@ -560,8 +560,8 @@
         } else {
             for (var i = 0 ; i < parsedBacktrace.length ; i++) {
                 html += '<div>';
-                html += '<div>' + (parsedBacktrace[i].fnName || '(anonymous)') + '</div>';
-                html += '<div class="trace"><url-link url="trace.filePath" max-length="40"></url-link>:' + parsedBacktrace[i].line + '</div>';
+                html += '<div>' + (parsedBacktrace[i].fnName || '(anonymous function)') + '</div>';
+                html += '<div class="trace">' + getUrlLink(parsedBacktrace[i].filePath, 40) + ':' + parsedBacktrace[i].line + '</div>';
                 html += '</div>';
             }
         }
@@ -729,21 +729,26 @@
         };
     }]);
 
+    function shortenUrl(url, maxLength) {
+        if (!maxLength) {
+            maxLength = 110;
+        }
 
-    offendersDirectives.filter('shortenUrl', function() {
-        return function(url, maxLength) {
-            if (!maxLength) {
-                maxLength = 110;
-            }
+        // Why dividing by 2.1? Because it adds a 5% margin.
+        var leftLength = Math.floor((maxLength - 5) / 2.1);
+        var rightLength = Math.ceil((maxLength - 5) / 2.1);
 
-            // Why dividing by 2.1? Because it adds a 5% margin.
-            var leftLength = Math.floor((maxLength - 5) / 2.1);
-            var rightLength = Math.ceil((maxLength - 5) / 2.1);
+        return (url.length > maxLength) ? url.substr(0, leftLength) + ' ... ' + url.substr(-rightLength) : url;
+    }
 
-            return (url.length > maxLength) ? url.substr(0, leftLength) + ' ... ' + url.substr(-rightLength) : url;
-        };
+    offendersDirectives.filter('shortenUrl', function() {
+        return shortenUrl;
     });
 
+    function getUrlLink(url, maxLength) {
+        return '<a href="' + url + '" target="_blank" title="' + url + '">' + shortenUrl(url, maxLength) + '</a>';
+    }
+
     offendersDirectives.directive('urlLink', function() {
         return {
             restrict: 'E',