2013-07-11 21:52:04 +04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* Filters */
|
2013-07-25 03:41:50 +04:00
|
|
|
|
2013-07-25 23:38:17 +04:00
|
|
|
treeherder.filter('showOrHide', function() {
|
2013-07-25 03:41:50 +04:00
|
|
|
// determine whether this is a label for a job group (like mochitest)
|
|
|
|
return function(input, isCollapsed) {
|
2015-10-31 00:02:16 +03:00
|
|
|
if (isCollapsed === true) {
|
2013-07-25 23:38:17 +04:00
|
|
|
return "show" + input;
|
2013-07-25 03:41:50 +04:00
|
|
|
} else {
|
2013-07-25 23:38:17 +04:00
|
|
|
return "hide" + input;
|
2013-07-25 03:41:50 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2014-01-15 03:13:49 +04:00
|
|
|
|
2014-07-23 21:43:31 +04:00
|
|
|
treeherder.filter('platformName', ['thPlatformNameMap', function(thPlatformNameMap) {
|
2014-01-15 03:13:49 +04:00
|
|
|
// fix the platform name from the raw name in the db, with the more
|
2014-07-23 21:43:31 +04:00
|
|
|
// "human read-able" one
|
2014-01-15 03:13:49 +04:00
|
|
|
return function(input, name) {
|
2015-07-18 00:26:53 +03:00
|
|
|
var newName = platformNameMap[name];
|
|
|
|
if (newName) {
|
|
|
|
return newName;
|
|
|
|
}
|
|
|
|
// if it's not found, then return it unchanged.
|
|
|
|
return name;
|
2014-01-15 03:13:49 +04:00
|
|
|
};
|
2014-07-23 21:43:31 +04:00
|
|
|
}]);
|
2014-03-27 23:12:00 +04:00
|
|
|
|
|
|
|
treeherder.filter('stripHtml', function() {
|
|
|
|
return function(input) {
|
2014-03-27 23:37:28 +04:00
|
|
|
var str = input || '';
|
|
|
|
return str.replace(/<\/?[^>]+>/gi, '');
|
2014-03-27 23:12:00 +04:00
|
|
|
};
|
2014-05-06 22:33:31 +04:00
|
|
|
});
|
2014-03-27 23:12:00 +04:00
|
|
|
|
2014-04-17 03:02:41 +04:00
|
|
|
treeherder.filter('linkifyBugs', function() {
|
|
|
|
return function(input) {
|
|
|
|
var str = input || '';
|
2015-01-28 01:18:27 +03:00
|
|
|
var clear_attr = 'ignore-job-clear-on-click';
|
2015-03-12 22:05:59 +03:00
|
|
|
|
|
|
|
var bug_matches = str.match(/-- ([0-9]+)|bug.([0-9]+)/ig);
|
|
|
|
var pr_matches = str.match(/PR#([0-9]+)/ig);
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
var bug_title = 'bugzilla.mozilla.org';
|
|
|
|
var bug_url = '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=$1" ' +
|
|
|
|
'data-bugid=$1 ' + 'title=' + bug_title + '>$1</a>';
|
|
|
|
var pr_title = 'github.com';
|
|
|
|
var pr_url = '<a href="https://github.com/mozilla-b2g/gaia/pull/$1" ' +
|
|
|
|
'data-prid=$1 ' + 'title=' + pr_title + '>$1</a>';
|
|
|
|
|
2015-01-29 17:40:21 +03:00
|
|
|
if (bug_matches) {
|
2015-03-12 22:05:59 +03:00
|
|
|
// Separate passes to preserve prefix
|
|
|
|
str = str.replace(/Bug ([0-9]+)/g, "Bug " + bug_url);
|
|
|
|
str = str.replace(/bug ([0-9]+)/g, "bug " + bug_url);
|
|
|
|
str = str.replace(/-- ([0-9]+)/g, "-- " + bug_url);
|
2015-01-29 17:40:21 +03:00
|
|
|
}
|
2015-03-12 22:05:59 +03:00
|
|
|
|
|
|
|
if (pr_matches) {
|
|
|
|
// Separate passes to preserve prefix
|
|
|
|
str = str.replace(/PR#([0-9]+)/g, "PR#" + pr_url);
|
|
|
|
str = str.replace(/pr#([0-9]+)/g, "pr#" + pr_url);
|
|
|
|
}
|
|
|
|
|
2015-01-29 17:40:21 +03:00
|
|
|
return str;
|
2014-04-17 03:02:41 +04:00
|
|
|
};
|
2014-05-06 22:33:31 +04:00
|
|
|
});
|
|
|
|
|
2014-08-29 01:42:38 +04:00
|
|
|
treeherder.filter('initials', function() {
|
|
|
|
return function(input) {
|
|
|
|
var str = input || '';
|
2014-09-03 03:13:04 +04:00
|
|
|
var words = str.split(' ');
|
|
|
|
var first = words[0].replace(/[^A-Z]/gi, '')[0];
|
|
|
|
var last = words.slice(-1)[0].replace(/[^A-Z]/gi, '')[0];
|
|
|
|
var initials = first + last;
|
|
|
|
|
2014-08-29 01:42:38 +04:00
|
|
|
return '<span class="label label-initials">' + initials + '</span>';
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2014-05-06 22:33:31 +04:00
|
|
|
function inTag(str, index, start, end) {
|
|
|
|
var prePart = str.substr(0, index);
|
|
|
|
return prePart.split(start).length > prePart.split(end).length;
|
|
|
|
}
|
|
|
|
|
|
|
|
treeherder.filter('highlightCommonTerms', function(){
|
|
|
|
return function(input, compareStr){
|
|
|
|
var tokens = compareStr.split(/[^a-zA-Z0-9_-]+/);
|
|
|
|
tokens.sort(function(a, b){
|
|
|
|
return b.length - a.length;
|
|
|
|
});
|
|
|
|
angular.forEach(tokens, function(elem){
|
|
|
|
if (elem.length > 0){
|
|
|
|
input = input.replace(new RegExp(elem, "gi"), function(token, index, str){
|
|
|
|
if (inTag(str, index, "<", ">") || inTag(str, index, "&", ";")){
|
|
|
|
return token;
|
|
|
|
}else{
|
|
|
|
return "<strong>"+token+"</strong>";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return input;
|
|
|
|
};
|
|
|
|
});
|
2014-04-17 03:02:41 +04:00
|
|
|
|
2014-07-16 18:28:40 +04:00
|
|
|
treeherder.filter('escapeHTML', function() {
|
|
|
|
return function(text){
|
|
|
|
if (text) {
|
2015-07-18 00:26:53 +03:00
|
|
|
return text.
|
|
|
|
replace(/&/g, '&').
|
|
|
|
replace(/</g, '<').
|
|
|
|
replace(/>/g, '>').
|
|
|
|
replace(/'/g, ''').
|
|
|
|
replace(/"/g, '"');
|
2014-07-16 18:28:40 +04:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
});
|
2015-07-19 14:19:27 +03:00
|
|
|
|
|
|
|
treeherder.filter('getRevisionUrl', ['thServiceDomain', function(thServiceDomain) {
|
|
|
|
return function(revision, projectName) {
|
|
|
|
if (revision) {
|
2015-07-28 20:22:03 +03:00
|
|
|
return thServiceDomain + '/#/jobs?repo=' + projectName + '&revision=' + revision;
|
2015-07-19 14:19:27 +03:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
}]);
|