diff --git a/public/js/createOrgRepoGraph.js b/public/js/createOrgRepoGraph.js index 93880d4..4f9cbee 100644 --- a/public/js/createOrgRepoGraph.js +++ b/public/js/createOrgRepoGraph.js @@ -6,31 +6,19 @@ * @param page * @returns {Promise} */ -function addOrgUsers(orgname, page) +function addOrgUsers(orgname) { return new Promise(function(resolve, reject) { - queryAPIByOrg(API_ORG_MEMBERS + "?page=" + page, orgname, function(data) + getOrganizationMembers(orgname, (data)=> { for(var i = 0;i < data.length; i++) { addPersonToGraph(data[i]); } - - if(data.length === 30) - { - addOrgUsers(orgname, page + 1).then(function() - { - resolve(); - }); - } - else - { - total = 2*(data.length + (page * 30)); - resolve(); - } - - }, function(error) + total = data.length; + resolve(); + }, (error)=> { console.log(error); resolve(); @@ -38,6 +26,7 @@ function addOrgUsers(orgname, page) }) } + /** * Creates a graph * @param username @@ -51,7 +40,7 @@ function createOrgRepoGraph(orgname, containerName, graphsTitle) nodes = []; edges = []; - addOrgUsers(orgname, 1).then(function() + addOrgUsers(orgname).then(function() { createConnections().then( () => { var container = document.getElementById(containerName); diff --git a/public/js/githubAPI.js b/public/js/githubAPI.js index c339ac4..0e8bcc2 100644 --- a/public/js/githubAPI.js +++ b/public/js/githubAPI.js @@ -79,8 +79,13 @@ function getOrganizationRepositories(orgName, suc, err) { //ex: http://localhost:7000/api/org/repositories/ComputerScienceHouse const urlpath = APIROOT + "/org/repositories/" + orgName; - console.log("what is even happening rn."); - console.log(urlpath); + runAjax(urlpath, suc, err); +} + + +function getOrganizationMembers(orgName, suc, err) +{ + const urlpath = APIROOT + "/org/users/" + orgName; runAjax(urlpath, suc, err); } diff --git a/routes/api.js b/routes/api.js index fc981e6..2ecc147 100644 --- a/routes/api.js +++ b/routes/api.js @@ -222,6 +222,41 @@ function queryFriends(user) } +/** + * + * Fetches all of the members of an organization from the + * API or cache + * + * /orgs/RITlug/members?page=1 + * + * @param {*} orgName + */ +function getOrganizationMembers(orgName) +{ + const cacheHit = cache.get("/org/users/" + orgName); + return new Promise((resolve, reject)=> + { + if(cacheHit == null) + { + fetchAllWithPagination(API_ORGS_PATH + orgName + "/members", 1, []).then((mems)=> + { + var minimized = minimizeFriends(mems); + resolve(minimized); + cache.put("/org/users/" + orgName, minimized); + }).catch((err)=> + { + console.log(err) + }) + } + else + { + console.log("Org members cache hit"); + resolve(cacheHit); + } + }); +} + + /** * Minimizes the JSON for a list of repositories * @@ -275,6 +310,9 @@ function queryRepositories(user, orgsOrUsers) } +/** + * /users/name/following/followers + */ routes.get("/friends/:name", (request, result)=> { queryFriends(request.params.name).then(friends=> @@ -290,6 +328,23 @@ routes.get("/friends/:name", (request, result)=> }); + +routes.get("/org/users/:name", (request, result)=> +{ + getOrganizationMembers(request.params.name).then(friends=> + { + result.json(friends) + .end(); + }).catch(error=> + { + result.status(500) + .json({error: 'API error fetching friends'}) + .end(); + }); +}); + + + routes.get("/repositories/:name", (request, result)=> { queryRepositories(request.params.name, API_USER_PATH).then(repos=>