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) {
|
|
|
|
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
|
|
|
|
|
|
|
treeherder.filter('platformName', function() {
|
|
|
|
// fix the platform name from the raw name in the db, with the more
|
|
|
|
// "human read-able" one from Config.js
|
|
|
|
return function(input, name) {
|
|
|
|
var newName = Config.OSNames[name];
|
|
|
|
if (newName) {
|
|
|
|
return newName;
|
|
|
|
}
|
|
|
|
// if it's not found in Config.js, then return it unchanged.
|
|
|
|
return name;
|
|
|
|
};
|
2014-05-06 22:33: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 re = new RegExp('(?:Bug (\\d+))', 'ig');
|
|
|
|
var str = input || '';
|
|
|
|
return str.replace(re,
|
|
|
|
'<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=$1" target="_blank">Bug $1</a>'
|
|
|
|
);
|
|
|
|
};
|
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) {
|
|
|
|
return text.
|
|
|
|
replace(/&/g, '&').
|
|
|
|
replace(/</g, '<').
|
|
|
|
replace(/>/g, '>').
|
|
|
|
replace(/'/g, ''').
|
|
|
|
replace(/"/g, '"');
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
});
|