treeherder/ui/js/filters.js

129 строки
3.9 KiB
JavaScript
Исходник Обычный вид История

2013-07-11 21:52:04 +04:00
'use strict';
/* Filters */
treeherder.filter('showOrHide', function() {
// determine whether this is a label for a job group (like mochitest)
return function(input, isCollapsed) {
if (isCollapsed === true) {
return "show" + input;
} else {
return "hide" + input;
}
};
});
treeherder.filter('platformName', ['thPlatformNameMap', function(thPlatformNameMap) {
// fix the platform name from the raw name in the db, with the more
// "human read-able" one
return function(input, name) {
var newName = platformNameMap[name];
if (newName) {
return newName;
}
// if it's not found, then return it unchanged.
return name;
};
}]);
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
treeherder.filter('linkifyBugs', function() {
return function(input) {
var str = input || '';
var clear_attr = 'ignore-job-clear-on-click';
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>';
if (bug_matches) {
// 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);
}
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);
}
return str;
};
2014-05-06 22:33:31 +04:00
});
treeherder.filter('initials', function() {
return function(input) {
var str = input || '';
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;
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;
};
});
treeherder.filter('escapeHTML', function() {
return function(text){
if (text) {
return text.
replace(/&/g, '&amp;').
replace(/</g, '&lt;').
replace(/>/g, '&gt;').
replace(/'/g, '&#39;').
replace(/"/g, '&quot;');
}
return '';
};
});
treeherder.filter('getRevisionUrl', ['thServiceDomain', function(thServiceDomain) {
return function(revision, projectName) {
if (revision) {
return thServiceDomain + '/#/jobs?repo=' + projectName + '&revision=' + revision;
}
return '';
};
}]);