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) => {
let html = `
${user.name}
${user.login}
${user.bio != null ? `
${user.bio}
` : ""}
${user.blog != null ? `- ${user.blog}
` : ""}
${user.email != null ? `- Email: ${user.email}
` : ""}
${user.location != null ? `- Location: ${user.location}
` : ""}
${user.company != null ? `- Company: ${user.company}
` : ""}
- Followers: ${user.followers}
- Following: ${user.following}
- Repositories: ${user.public_repos}
${orgsReturn != [] ? `
Organizations
${orgsReturn}` : ""}
`;
$("#"+container).html(html);
})
}, () =>
{
alert("User Does Not Exist");
window.location.href = "./GraphGenerator.html";
});
}
function parseOrgs(name) {
return new Promise( (resolve, reject) => {
let urlpath = `api/users/${name}/orgs`;
let orgs_final = [];
queryUrl(urlpath, (orgs) => {
var prom= [];
for(var i = 0;i < orgs.length; i++) {
prom.push( new Promise( (res, rej) => {
url = orgs[i].url;
queryUrl(url, (orgData) => {
orgs_final.push("");
res();
}, (error) => {
console.log(error);
rej(error);
console.error("error getting org info");
});
})
)
}
Promise.all(prom).then(function() {
resolve(orgs_final.join(" "));
})
}, (error) => {
resolve([]);
});
})
}
function graphUrl(user) {
return "/FriendsGraph.html?name="+user;
}
function timelineUrl(user) {
return "/TimeLineGraph.html?name="+user;
}