mirror of
https://github.com/harness/drone.git
synced 2025-05-13 23:50:47 +08:00
cleanup the angular filters
This commit is contained in:
parent
31b1ed1f48
commit
746eea068f
@ -1,30 +1,126 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('app').filter('gravatar', function() {
|
(function () {
|
||||||
return function(gravatar) {
|
|
||||||
return "https://secure.gravatar.com/avatar/"+gravatar+"?s=48&d=mm"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
angular.module('app').filter('fromNow', function() {
|
/**
|
||||||
|
* fromNow is a helper function that returns a human readable
|
||||||
|
* string for the elapsed time between the given unix date and the
|
||||||
|
* current time (ex. 10 minutes ago).
|
||||||
|
*/
|
||||||
|
function fromNow() {
|
||||||
return function(date) {
|
return function(date) {
|
||||||
return moment(new Date(date*1000)).fromNow();
|
return moment(new Date(date*1000)).fromNow();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
angular.module('app').filter('toDuration', function() {
|
/**
|
||||||
|
* toDuration is a helper function that returns a human readable
|
||||||
|
* string for the given duration in seconds (ex. 1 hour and 20 minutes).
|
||||||
|
*/
|
||||||
|
function toDuration() {
|
||||||
return function(seconds) {
|
return function(seconds) {
|
||||||
return moment.duration(seconds, "seconds").humanize();
|
return moment.duration(seconds, "seconds").humanize();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
angular.module('app').filter('toDate', function() {
|
/**
|
||||||
|
* toDate is a helper function that returns a human readable
|
||||||
|
* string gor the given unix date.
|
||||||
|
*/
|
||||||
|
function toDate() {
|
||||||
return function(date) {
|
return function(date) {
|
||||||
return moment(new Date(date*1000)).format('ll');
|
return moment(new Date(date*1000)).format('ll');
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
angular.module('app').filter('pullRequests', function() {
|
/**
|
||||||
|
* shortHash is a helper function that returns the shortened
|
||||||
|
* version of a commit sha, similar to the --short flag.
|
||||||
|
*/
|
||||||
|
function shortHash() {
|
||||||
|
return function(sha) {
|
||||||
|
if (sha === undefined) { return ""; }
|
||||||
|
return sha.substr(0,10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gravatar is a helper function that return the user's gravatar
|
||||||
|
* image URL given an email hash.
|
||||||
|
*/
|
||||||
|
function gravatar() {
|
||||||
|
return function(hash) {
|
||||||
|
if (hash === undefined) { return ""; }
|
||||||
|
return "https://secure.gravatar.com/avatar/"+hash+"?s=48&d=mm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gravatarLarge is a helper function that return the user's gravatar
|
||||||
|
* image URL given an email hash.
|
||||||
|
*/
|
||||||
|
function gravatarLarge() {
|
||||||
|
return function(hash) {
|
||||||
|
if (hash === undefined) { return ""; }
|
||||||
|
return "https://secure.gravatar.com/avatar/"+hash+"?s=128&d=mm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fullName is a helper funcation that returns the full name (slug)
|
||||||
|
* for the given repository (ie drone/drone)
|
||||||
|
*/
|
||||||
|
function fullName() {
|
||||||
|
return function(repo) {
|
||||||
|
if (repo === undefined) { return ""; }
|
||||||
|
return repo.owner+"/"+repo.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fullName is a helper funcation that returns the full, canonical
|
||||||
|
* path for the given repository (ie drone/drone)
|
||||||
|
*/
|
||||||
|
function fullPath() {
|
||||||
|
return function(repo) {
|
||||||
|
if (repo === undefined) { return ""; }
|
||||||
|
return repo.host+"/"+repo.owner+"/"+repo.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* badgeMarkdown is a helper funcation that returns a markdown string
|
||||||
|
* for the given repository's build status badge.
|
||||||
|
*/
|
||||||
|
function badgeMarkdown() {
|
||||||
|
return function(repo) {
|
||||||
|
if (repo === undefined) { return ""; }
|
||||||
|
var scheme = window.location.protocol;
|
||||||
|
var host = window.location.host;
|
||||||
|
var path = repo.host+'/'+repo.owner+'/'+repo.name;
|
||||||
|
return '[]('+scheme+'//'+host+'/'+path+')'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* badgeMarkup is a helper funcation that returns an html string
|
||||||
|
* for the given repository's build status badge.
|
||||||
|
*/
|
||||||
|
function badgeMarkup() {
|
||||||
|
return function(repo) {
|
||||||
|
if (repo === undefined) { return ""; }
|
||||||
|
var scheme = window.location.protocol;
|
||||||
|
var host = window.location.host;
|
||||||
|
var path = repo.host+'/'+repo.owner+'/'+repo.name;
|
||||||
|
return '[]('+scheme+'//'+host+'/'+path+')'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pullRequests is a helper funcation that filters a list of commits
|
||||||
|
* and returns the subset of those commits that are pull requests.
|
||||||
|
*/
|
||||||
|
function pullRequests() {
|
||||||
return function(commits) {
|
return function(commits) {
|
||||||
var filtered = [];
|
var filtered = [];
|
||||||
angular.forEach(commits, function(commit) {
|
angular.forEach(commits, function(commit) {
|
||||||
@ -34,49 +130,13 @@ angular.module('app').filter('pullRequests', function() {
|
|||||||
});
|
});
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
angular.module('app').filter('fullName', function() {
|
|
||||||
return function(repo) {
|
|
||||||
return repo.owner+"/"+repo.name;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
angular.module('app').filter('fullPath', function() {
|
/**
|
||||||
return function(repo) {
|
* remoteName is a helper funcation that returns a user-friendly
|
||||||
if (repo == undefined) { return ""; }
|
* name for the given remote type.
|
||||||
return repo.host+"/"+repo.owner+"/"+repo.name;
|
*/
|
||||||
}
|
function remoteName() {
|
||||||
});
|
|
||||||
|
|
||||||
angular.module('app').filter('shortHash', function() {
|
|
||||||
return function(sha) {
|
|
||||||
if (!sha) { return ""; }
|
|
||||||
return sha.substr(0,10)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
angular.module('app').filter('badgeMarkdown', function() {
|
|
||||||
return function(repo) {
|
|
||||||
if (repo == undefined) { return ""; }
|
|
||||||
var scheme = window.location.protocol;
|
|
||||||
var host = window.location.host;
|
|
||||||
var path = repo.host+'/'+repo.owner+'/'+repo.name;
|
|
||||||
return '[]('+scheme+'//'+host+'/'+path+')'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
angular.module('app').filter('badgeMarkup', function() {
|
|
||||||
return function(repo) {
|
|
||||||
if (repo == undefined) { return ""; }
|
|
||||||
var scheme = window.location.protocol;
|
|
||||||
var host = window.location.host;
|
|
||||||
var path = repo.host+'/'+repo.owner+'/'+repo.name;
|
|
||||||
return '<a href="'+scheme+'//'+host+'/'+path+'"><img src="'+scheme+'//'+host+'/v1/badge/'+path+'/status.svg?branch=master" /></a>'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
angular.module('app').filter('remoteName', function() {
|
|
||||||
return function(name) {
|
return function(name) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'gitlab.com' : return 'GitLab';
|
case 'gitlab.com' : return 'GitLab';
|
||||||
@ -86,9 +146,13 @@ angular.module('app').filter('remoteName', function() {
|
|||||||
case 'stash.atlassian.com' : return 'Atlassian Stash';
|
case 'stash.atlassian.com' : return 'Atlassian Stash';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
angular.module('app').filter('remoteIcon', function() {
|
/**
|
||||||
|
* remoteIcon is a helper funcation that returns an icon to represent
|
||||||
|
* the given remote type.
|
||||||
|
*/
|
||||||
|
function remoteIcon() {
|
||||||
return function(name) {
|
return function(name) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'gitlab.com' : return 'fa-git-square';
|
case 'gitlab.com' : return 'fa-git-square';
|
||||||
@ -98,10 +162,14 @@ angular.module('app').filter('remoteIcon', function() {
|
|||||||
case 'stash.atlassian.com' : return 'fa-bitbucket-square';
|
case 'stash.atlassian.com' : return 'fa-bitbucket-square';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
angular.module('app').filter('unique', function() {
|
* unique is a helper funcation that returns a unique array
|
||||||
|
* of fields from the given list of complex data strucrures.
|
||||||
|
* I copied it from Stackoverflow, so don't ask me how it works...
|
||||||
|
*/
|
||||||
|
function unique() {
|
||||||
return function(input, key) {
|
return function(input, key) {
|
||||||
var unique = {};
|
var unique = {};
|
||||||
var uniqueList = [];
|
var uniqueList = [];
|
||||||
@ -116,4 +184,23 @@ angular.module('app').filter('unique', function() {
|
|||||||
}
|
}
|
||||||
return uniqueList;
|
return uniqueList;
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
|
||||||
|
angular
|
||||||
|
.module('app')
|
||||||
|
.filter('badgeMarkdown', badgeMarkdown)
|
||||||
|
.filter('badgeMarkup', badgeMarkup)
|
||||||
|
.filter('fromNow', fromNow)
|
||||||
|
.filter('fullName', fullName)
|
||||||
|
.filter('fullPath', fullPath)
|
||||||
|
.filter('gravatar', gravatar)
|
||||||
|
.filter('gravatarLarge', gravatarLarge)
|
||||||
|
.filter('pullRequests', pullRequests)
|
||||||
|
.filter('remoteIcon', remoteIcon)
|
||||||
|
.filter('remoteName', remoteName)
|
||||||
|
.filter('shortHash', shortHash)
|
||||||
|
.filter('toDate', toDate)
|
||||||
|
.filter('toDuration', toDuration)
|
||||||
|
.filter('unique', unique);
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user