Browse Source

Merge branch 'master' of https://github.com/jrtechs/github-graphs

pull/11/head
CetaceanNation 5 years ago
parent
commit
bc400249e1
10 changed files with 124 additions and 43 deletions
  1. +1
    -1
      public/FriendsGraph.html
  2. +1
    -1
      public/GraphGenerator.html
  3. +1
    -1
      public/TimeLineGraph.html
  4. +1
    -1
      public/about.html
  5. +1
    -1
      public/index.html
  6. +82
    -27
      public/js/friendsGraph.js
  7. +2
    -1
      public/js/githubAPI.js
  8. +12
    -5
      public/js/profileGen.js
  9. +1
    -1
      public/js/profileTimeLine.js
  10. +22
    -4
      routes/api.js

+ 1
- 1
public/FriendsGraph.html View File

@ -31,7 +31,7 @@
<div id="navigation"> <div id="navigation">
<ul class="nav"> <ul class="nav">
<li class="nav-item"> <li class="nav-item">
<a href="./FriendsGraph.html">
<a href="./GraphGenerator.html">
Generate graphs Generate graphs
</a> </a>
</li> </li>

+ 1
- 1
public/GraphGenerator.html View File

@ -23,7 +23,7 @@
<div id="navigation"> <div id="navigation">
<ul class="nav"> <ul class="nav">
<li class="nav-item"> <li class="nav-item">
<a href="./graphgenerator.html">
<a href="./GraphGenerator.html">
Generate graphs Generate graphs
</a> </a>
</li> </li>

+ 1
- 1
public/TimeLineGraph.html View File

@ -86,7 +86,7 @@
</div> </div>
<ul id="navigation" class="nav justify-content-end"> <ul id="navigation" class="nav justify-content-end">
<li class="nav-item"> <li class="nav-item">
<a href="./FriendsGraph.html">
<a href="./GraphGenerator.html">
Generate graphs Generate graphs
</a> </a>
</li> </li>

+ 1
- 1
public/about.html View File

@ -20,7 +20,7 @@
<div id="navigation"> <div id="navigation">
<ul class="nav"> <ul class="nav">
<li class="nav-item"> <li class="nav-item">
<a href="./graphgenerator.html">
<a href="./GraphGenerator.html">
Generate graphs Generate graphs
</a> </a>
</li> </li>

+ 1
- 1
public/index.html View File

@ -26,7 +26,7 @@
<div id="navigation"> <div id="navigation">
<ul class="nav"> <ul class="nav">
<li class="nav-item"> <li class="nav-item">
<a href="./graphgenerator.html">
<a href="./GraphGenerator.html">
Generate graphs Generate graphs
</a> </a>
</li> </li>

+ 82
- 27
public/js/friendsGraph.js View File

@ -64,12 +64,15 @@ function addPersonToGraph(profileData)
* @param apiPath * @param apiPath
* @returns {Promise<any>} * @returns {Promise<any>}
*/ */
function addFriends(username, apiPath)
function addFriends(username, apiPath, page)
{ {
console.log(username + " page=" + page);
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject)
{ {
queryAPIByUser(apiPath, username, function(data)
queryAPIByUser(apiPath + "?page=" + page, username, function(data)
{ {
console.log(data);
console.log(data.length);
for(var i = 0; i < data.length; i++) for(var i = 0; i < data.length; i++)
{ {
if(!alreadyInGraph(data[i].id)) if(!alreadyInGraph(data[i].id))
@ -77,7 +80,18 @@ function addFriends(username, apiPath)
addPersonToGraph(data[i]); addPersonToGraph(data[i]);
} }
} }
resolve();
if(data.length === 30)
{
addFriends(username, apiPath, page+ 1).then(function()
{
resolve();
})
}
else
{
resolve();
}
}, },
function(error) function(error)
{ {
@ -96,6 +110,7 @@ function addFriends(username, apiPath)
*/ */
function edgeInGraph(id1, id2) function edgeInGraph(id1, id2)
{ {
console.log("edge check");
for(var i = 0;i < edges.length; i++) for(var i = 0;i < edges.length; i++)
{ {
if(edges[i].from === id1 && edges[i].to === id2) if(edges[i].from === id1 && edges[i].to === id2)
@ -133,41 +148,82 @@ function addConnection(person1, person2)
} }
/**
* Processes all the connections of a user and adds them to the graph
*
* @param user has .id and .name
* @returns {Promise<any>}
*/
function processUserConnections(user)
function processConnections(user, apiPoint, page)
{ {
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject)
{ {
queryAPIByUser(API_FOLLOWING, user.name,
queryAPIByUser(apiPoint + "?page=" + page, user.name,
function(data) function(data)
{ {
for(var i = 0; i < data.length; i++) for(var i = 0; i < data.length; i++)
{ {
addConnection(user, data[i]) addConnection(user, data[i])
} }
queryAPIByUser(API_FOLLOWERS, user.name, function(data2)
if(data.length === 30)
{
processConnections(user, apiPoint, page + 1).then(function()
{ {
for(var i = 0; i < data2.length; i++)
{
addConnection(user, data2[i]);
}
resolve(); resolve();
},
function(error)
{
reject(error);
}); });
},
function(error)
}
else
{
resolve();
}
}, function(error)
{
console.log(error);
resolve();
})
})
}
/**
* Processes all the connections of a user and adds them to the graph
*
* @param user has .id and .name
* @returns {Promise<any>}
*/
function processUserConnections(user)
{
return new Promise(function(resolve, reject)
{
processConnections(user, API_FOLLOWING, 1).then(function()
{
processConnections(user, API_FOLLOWERS, 1).then(function()
{ {
reject(error);
resolve();
}) })
})
// queryAPIByUser(API_FOLLOWING, user.name,
// function(data)
// {
// for(var i = 0; i < data.length; i++)
// {
// addConnection(user, data[i])
// }
//
// queryAPIByUser(API_FOLLOWERS, user.name, function(data2)
// {
// for(var i = 0; i < data2.length; i++)
// {
// addConnection(user, data2[i]);
// }
// resolve();
// },
// function(error)
// {
// // reject(error);
// resolve();
// });
// },
// function(error)
// {
// // reject(error);
// resolve();
// })
}); });
} }
@ -247,10 +303,9 @@ function createFriendsGraph(username, containerName, graphsTitle)
edges = []; edges = [];
addSelfToGraph(username).then(function() addSelfToGraph(username).then(function()
{ {
console.log("added self");
addFriends(username, API_FOLLOWERS).then(function()
addFriends(username, API_FOLLOWERS,1).then(function()
{ {
addFriends(username, API_FOLLOWING).then(function()
addFriends(username, API_FOLLOWING,1).then(function()
{ {
createConnections().then(function() createConnections().then(function()
{ {

+ 2
- 1
public/js/githubAPI.js View File

@ -32,6 +32,7 @@ const API_ORGANIZATIONS = "/orgs";
*/ */
function queryAPIByUser(apiPath, user, successCallBack, errorCallBack) { function queryAPIByUser(apiPath, user, successCallBack, errorCallBack) {
const urlpath = APIROOT + API_USER_PATH + user + apiPath; const urlpath = APIROOT + API_USER_PATH + user + apiPath;
console.log(urlpath);
$.ajax({ $.ajax({
type:'GET', type:'GET',
url: urlpath, url: urlpath,
@ -39,6 +40,6 @@ function queryAPIByUser(apiPath, user, successCallBack, errorCallBack) {
dataType: "json", dataType: "json",
success: successCallBack, success: successCallBack,
error:errorCallBack, error:errorCallBack,
timeout: 1500
timeout: 4000
}); });
} }

+ 12
- 5
public/js/profileGen.js View File

@ -1,17 +1,24 @@
function profileGen(username, container) {
queryAPIByUser("", username, (user) => {
function profileGen(username, container)
{
queryAPIByUser("", username, (user) =>
{
if(!user.hasOwnProperty("id"))
{
alert("User Does Not Exist");
window.location.href = "./GraphGenerator.html";
}
parseOrgs(user.login).then( (orgsReturn) => { parseOrgs(user.login).then( (orgsReturn) => {
let html = let html =
"<div class=\"card\" style=\"w-100\"> \ "<div class=\"card\" style=\"w-100\"> \
<img class=\"card-img-top\" src=\""+user.avatar_url+"\"></img> \ <img class=\"card-img-top\" src=\""+user.avatar_url+"\"></img> \
<div class=\"row mx-0\"> \
<div class=\"col-9\"> \
<div class=\"row\"> \
<div class=\"col-8\"> \
<div class=\"card-body\"> \ <div class=\"card-body\"> \
<h5 class=\"card-title\">"+user.name+"</h1> \ <h5 class=\"card-title\">"+user.name+"</h1> \
<h6 class=\"card-subtitle\">"+user.login+"</h2> \ <h6 class=\"card-subtitle\">"+user.login+"</h2> \
</div> \ </div> \
</div> \ </div> \
<div class=\"col-sm\"> \
<div class=\"col-4\"> \
<button type=\"button\" class=\"btn btn-link pt-3\"> \ <button type=\"button\" class=\"btn btn-link pt-3\"> \
<a href=\""+makeUrl(user.login)+"\"> \ <a href=\""+makeUrl(user.login)+"\"> \
<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"> \ <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"> \

+ 1
- 1
public/js/profileTimeLine.js View File

@ -126,7 +126,7 @@ function createProfileTimeLine(username, containerName)
{id: 1, content: 'Repositories', value: 2} {id: 1, content: 'Repositories', value: 2}
]); ]);
console.log("up up duper");
Promise.all(prom).then(function() Promise.all(prom).then(function()
{ {
// note that months are zero-based in the JavaScript Date object // note that months are zero-based in the JavaScript Date object

+ 22
- 4
routes/api.js View File

@ -9,7 +9,7 @@ const GITHUB_API = "https://api.github.com";
const configLoader = require('../configManager'); const configLoader = require('../configManager');
const authenticate = "?client_id=" + configLoader.getClientID() +
const authenticate = "client_id=" + configLoader.getClientID() +
"&client_secret=" + configLoader.getClientSecret(); "&client_secret=" + configLoader.getClientSecret();
@ -25,9 +25,17 @@ function queryGitHubAPI(requestURL)
{ {
if(apiData == null) if(apiData == null)
{ {
const queryRUL = GITHUB_API + requestURL + authenticate;
var queryURL;
if(requestURL.includes("?page="))
{
queryURL = GITHUB_API + requestURL + "&" + authenticate;
}
else
{
queryURL = GITHUB_API + requestURL + "?" + authenticate;
}
got(queryRUL, { json: true }).then(response =>
got(queryURL, { json: true }).then(response =>
{ {
resolve(response.body); resolve(response.body);
cache.put(requestURL, response.body); cache.put(requestURL, response.body);
@ -50,7 +58,17 @@ function queryGitHubAPI(requestURL)
routes.get('/*', (request, result) => routes.get('/*', (request, result) =>
{ {
const gitHubAPIURL = request.url;
var gitHubAPIURL = request.url;
// if(request.query.hasOwnProperty("page"))
// {
// gitHubAPIURL += "?page=" + request.query.page;
// }
console.log(request.query);
console.log(gitHubAPIURL);
result.setHeader('Content-Type', 'application/json'); result.setHeader('Content-Type', 'application/json');
queryGitHubAPI(gitHubAPIURL).then(function(data) queryGitHubAPI(gitHubAPIURL).then(function(data)

Loading…
Cancel
Save