-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcategory-info.js
121 lines (106 loc) · 5.02 KB
/
category-info.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
app.controller('gitHubDataController', function($scope, $http, $window, Category) {
var getCategoryInfo = $http.get('../category/category_info.json', {
cache: true
});
var getReposTopics = $http.get('./explore/github-data/labRepos_Topics.json', {
cache: true
});
var getReposInfo = $http.get('./explore/github-data/labReposInfo.json', {
cache: true
});
var getReposLogos = $http.get('./assets/images/logos/repo_logos.json', {
cache: true
});
//sort by alphabetical key
function sortAlphabetically(array, key) {
return array.sort(function(a, b) {
var x = a[key].toLowerCase();
var y = b[key].toLowerCase();
return x < y ? -1 : x > y ? 1 : 0;
});
}
getCategoryInfo.then(function(response) {
var catsObj = response.data.data;
$scope.cats = Object.keys(catsObj);
$scope.catData = [];
angular.forEach($scope.cats, function(value, key) {
var data = catsObj[value];
$scope.catData.push(data);
});
$scope.catData = sortAlphabetically($scope.catData, 'title');
var other = {
title: 'OTHER',
icon: {
path: '/assets/images/other_sandia.svg',
alt: 'Other'
},
description: 'Other software packages',
displayTitle: 'Other',
topics: ['snl-other']
};
$scope.catData.push(other);
getReposTopics.then(function(response) {
var reposObj = response.data.data;
var allRepos = Object.keys(reposObj);
$scope.topicRepos = [];
var inCategory = true;
for (var c in $scope.catData) {
var cat = $scope.catData[c];
var catRepos = [];
for (var r in reposObj) {
var repo = reposObj[r];
var topics = [];
for (var t in repo.repositoryTopics.nodes) {
var repoTopic = repo.repositoryTopics.nodes[t].topic.name;
topics.push(repoTopic);
}
var included = Category.containsTopics(cat.topics, topics);
if (included) {
catRepos.push({ nameWithOwner: r });
}
}
$scope.topicRepos.push(catRepos);
}
getReposLogos.then(function(response) {
var logos = response.data.data;
getReposInfo.then(function(response) {
var reposInfoObj = response.data.data;
for (var repo in reposInfoObj) {
//reposInfoObj[repo] is the actual repo object
for (var j in $scope.topicRepos) {
//var category is array of objects
var category = $scope.topicRepos[j];
for (var count in category) {
// category[count] is a specific repo within a category
//if we find a repo that is included in the category repos, we save more info on it
if (category[count].nameWithOwner == reposInfoObj[repo].nameWithOwner) {
category[count]['name'] = reposInfoObj[repo].name;
category[count]['description'] = reposInfoObj[repo].description;
//call unique logo function to get repo logo uniqueLogo(logos, filename, ownerAvatar)
category[count]['ownerAvatar'] = Category.uniqueLogo(logos, category[count].nameWithOwner.toLowerCase() + '.png', reposInfoObj[repo].owner.avatarUrl);
category[count]['ownerLogin'] = reposInfoObj[repo].owner.login;
category[count]['stars'] = reposInfoObj[repo].stargazers.totalCount;
category[count]['gitUrl'] = reposInfoObj[repo].url;
category[count]['homepageUrl'] = reposInfoObj[repo].homepageUrl;
}
}
}
}
//sort categories by stars descending
for (var i in $scope.topicRepos) {
$scope.topicRepos[i] = Category.sortStars($scope.topicRepos[i], 'stars');
}
});
//function for generating hash url for each repo
$scope.repoHref = function(nametag) {
$window.location.href = '../repo#' + nametag;
};
//function to generate hash url for each category
$scope.categoryHref = function(nametag) {
var result = nametag.replace(/ /g, '');
$window.location.href = '../category#' + result;
};
});
});
});
});