-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCategory.service.js
39 lines (37 loc) · 1.1 KB
/
Category.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
app.service('Category', function() {
//sort repos in descending order of stars
this.sortStars = function(array, key) {
return array.sort(function(a, b) {
var x = a[key];
var y = b[key];
return x > y ? -1 : x < y ? 1 : 0;
});
};
//check if repo is tagged as one of the categories
this.containsTopics = function(catTopics, repoTopics) {
for (var i = 0; i < catTopics.length; i++) {
if ($.inArray(catTopics[i], repoTopics) != -1) {
return true;
}
}
return false;
};
this.uniqueLogo = function(logos, fileName, ownerAvatar) {
var match = false;
var file;
for (var f in logos) {
if (logos[f] == fileName) {
match = true;
file = logos[f];
}
}
//if repo has unique logo use it
if (match) {
return '/assets/images/logos/' + file;
}
//if repo does not have unique logo use org logo
else if (!match) {
return ownerAvatar;
}
};
});