Skip to content

Commit 81168d2

Browse files
committed
Added users to the org view and connected all the repositories in the org to the org.
1 parent 45c0980 commit 81168d2

2 files changed

Lines changed: 86 additions & 19 deletions

File tree

public/js/createOrgRepoGraph.js

Lines changed: 83 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function alreadyInGraph(userID)
5050
*/
5151
function addSelfAsOrg(orgData) {
5252
nodes.push( {
53-
id:orgData.id,
53+
id:0,
5454
name:orgData.login,
5555
image:orgData.avatar_url,
5656
background: '#eeeeee',
@@ -66,6 +66,12 @@ function addSelfAsRepo(repoData) {
6666
name:repoData.name,
6767
label: repoData.name,
6868
});
69+
70+
edges.push(
71+
{
72+
to: 0,
73+
from: repoData.id
74+
});
6975
}
7076

7177

@@ -295,6 +301,61 @@ function bringUpProfileView(id)
295301
}
296302
}
297303

304+
305+
function addOrgUserToGraph(profileData)
306+
{
307+
nodes.push(
308+
{
309+
id:profileData.id,
310+
name:profileData.login,
311+
shape: 'circularImage',
312+
image:profileData.avatar_url
313+
});
314+
}
315+
316+
317+
function connectOrgUsers()
318+
{
319+
return new Promise(function(resolve, reject)
320+
{
321+
resolve();
322+
})
323+
}
324+
325+
326+
function addOrgUsers(orgname, page)
327+
{
328+
return new Promise(function(resolve, reject)
329+
{
330+
queryAPIByOrg(API_ORG_MEMBERS + "?page=" + page, orgname, function(data)
331+
{
332+
for(var i = 0;i < data.length; i++)
333+
{
334+
addOrgUserToGraph(data[i]);
335+
}
336+
337+
if(data.length === 30)
338+
{
339+
addOrgUsers(orgname, page + 1).then(function()
340+
{
341+
resolve();
342+
});
343+
}
344+
else
345+
{
346+
resolve();
347+
}
348+
349+
}, function(error)
350+
{
351+
console.log(error);
352+
resolve();
353+
})
354+
})
355+
}
356+
357+
358+
298359
/**
299360
* Creates a graph
300361
* @param username
@@ -308,24 +369,28 @@ function createOrgRepoGraph(orgname, containerName, graphsTitle)
308369
nodes = [];
309370
edges = [];
310371
addOrgToGraph(orgname).then(function() {
311-
addRepos(orgname, API_REPOS,1).then(function() {
312-
$("#" + progressID).html("");
313-
314-
createConnections().then( () => {
315-
var container = document.getElementById(containerName);
316-
var data = {
317-
nodes: nodes,
318-
edges: edges
319-
};
320-
var network = new vis.Network(container, data, options);
321-
322-
network.on("click", function (params) {
323-
params.event = "[original event]";
324-
if(Number(this.getNodeAt(params.pointer.DOM)) !== NaN) {
325-
bringUpProfileView(Number(this.getNodeAt(params.pointer.DOM)));
326-
}
372+
addRepos(orgname, API_REPOS,1).then(function()
373+
{
374+
addOrgUsers(orgname, 1).then(function()
375+
{
376+
$("#" + progressID).html("");
377+
378+
createConnections().then( () => {
379+
var container = document.getElementById(containerName);
380+
var data = {
381+
nodes: nodes,
382+
edges: edges
383+
};
384+
var network = new vis.Network(container, data, options);
385+
386+
network.on("click", function (params) {
387+
params.event = "[original event]";
388+
if(Number(this.getNodeAt(params.pointer.DOM)) !== NaN) {
389+
bringUpProfileView(Number(this.getNodeAt(params.pointer.DOM)));
390+
}
391+
});
327392
});
328-
})
393+
});
329394

330395
})
331396
}).catch(function(error) {

public/js/githubAPI.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const API_USER_PATH = "/users/";
1313

1414
const API_ORG_PATH = "/orgs/";
1515

16-
const API_REPOS = "/repos/";
16+
const API_ORG_MEMBERS = "/members";
17+
18+
const API_REPOS = "/repos";
1719

1820
const API_FOLLOWING = "/following";
1921

0 commit comments

Comments
 (0)