From 99c4b240ecea28a9f3d7b4600dde851d8ba560fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Mon, 16 Mar 2015 12:54:31 +0100 Subject: [PATCH] Fix file url in backtrace --- front/src/js/controllers/timelineCtrl.js | 49 ------------------- .../src/js/directives/offendersDirectives.js | 31 +++++++----- 2 files changed, 18 insertions(+), 62 deletions(-) diff --git a/front/src/js/controllers/timelineCtrl.js b/front/src/js/controllers/timelineCtrl.js index f21046e..9105831 100644 --- a/front/src/js/controllers/timelineCtrl.js +++ b/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); diff --git a/front/src/js/directives/offendersDirectives.js b/front/src/js/directives/offendersDirectives.js index 18aecd6..66cf50f 100644 --- a/front/src/js/directives/offendersDirectives.js +++ b/front/src/js/directives/offendersDirectives.js @@ -560,8 +560,8 @@ } else { for (var i = 0 ; i < parsedBacktrace.length ; i++) { html += '
'; - html += '
' + (parsedBacktrace[i].fnName || '(anonymous)') + '
'; - html += '
:' + parsedBacktrace[i].line + '
'; + html += '
' + (parsedBacktrace[i].fnName || '(anonymous function)') + '
'; + html += '
' + getUrlLink(parsedBacktrace[i].filePath, 40) + ':' + parsedBacktrace[i].line + '
'; html += '
'; } } @@ -729,21 +729,26 @@ }; }]); + function shortenUrl(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); + + return (url.length > maxLength) ? url.substr(0, leftLength) + ' ... ' + url.substr(-rightLength) : url; + } 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); - - return (url.length > maxLength) ? url.substr(0, leftLength) + ' ... ' + url.substr(-rightLength) : url; - }; + return shortenUrl; }); + function getUrlLink(url, maxLength) { + return '' + shortenUrl(url, maxLength) + ''; + } + offendersDirectives.directive('urlLink', function() { return { restrict: 'E',