Website for visualizing a persons github network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. function profileGen(username, container)
  2. {
  3. queryAPIByUser("", username, (user) =>
  4. {
  5. if(!user.hasOwnProperty("id"))
  6. {
  7. alert("User Does Not Exist");
  8. window.location.href = "./GraphGenerator.html";
  9. }
  10. parseOrgs(user.login).then( (orgsReturn) => {
  11. let html =
  12. "<div class=\"card\" style=\"w-100; background-color:rgb(255,255,255);\"> \
  13. <img class=\"card-img-top\" src=\""+user.avatar_url+"\"></img> \
  14. <div class=\"row mx-0\" style=\"background-color:rgb(255,255,255);\"> \
  15. <div class=\"col-8\"> \
  16. <div class=\"card-body\" style=\"background-color:rgb(255,255,255);\">"+
  17. (user.name != null ? "<h5 class=\"card-title\">"+user.name+"</h5>" : "") +" \
  18. <h6 class=\"card-subtitle\">"+user.login+"</h5> \
  19. </div> \
  20. </div> \
  21. <div class=\"col-4\"> \
  22. <button type=\"button\" class=\"btn btn-link pt-3\"> \
  23. <a href=\""+makeUrl(user.login)+"\"> \
  24. <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"> \
  25. <path d=\"M5 9.2h3V19H5zM10.6 5h2.8v14h-2.8zm5.6 8H19v6h-2.8z\"/> \
  26. <path fill=\"none\" d=\"M0 0h24v24H0z\"/> \
  27. </svg> \
  28. </a> \
  29. </button> \
  30. </div> \
  31. </div> \
  32. <div class=\"card border-secondary mb-3 mx-auto text-left\" style=\"width:90%; \"> \
  33. <div class=\"card-body\" style=\"background-color:rgb(255,255,255);\"> \
  34. <p class=\"card-text\"><a href=\""+user.html_url+"\" class=\"card-link\">"+user.html_url+"</a></p> \ " +
  35. (user.blog != null ? "<p class=\"card-text \"><a href="+user.blog+" class=\"card-link\">"+user.blog+"</a></p>" : "")+" \
  36. </div> \
  37. </div> \
  38. <ul class=\"list-group list-group-flush\"> \
  39. <li class=\"list-group-item\">Followers: "+user.followers+"</li> \
  40. <li class=\"list-group-item\">Following: "+user.following+"</li> \
  41. <li class=\"list-group-item\">Repositories: "+user.public_repos+"</li>" +
  42. (user.bio != null ? "<li class=\"list-group-item\">Bio: "+user.bio+"</li>" : "")+
  43. (user.location != null ? "<li class=\"list-group-item\">Location: "+user.location+"</li>" : "")+
  44. (user.email != null ? "<li class=\"list-group-item\">Email: "+user.email+"</li>" : "")+
  45. (user.company != null ? "<li class=\"list-group-item\">Company: "+user.company+"</li>" : "")+
  46. (orgsReturn != [] ? "<li class=\"list-group-item\">"+orgsReturn+"</li>" : "")+ " \
  47. </ul> \
  48. </div>";
  49. $("#"+container).html(html);
  50. })
  51. }, () => {
  52. alert("User Does Not Exist");
  53. window.location.href = "./GraphGenerator.html";
  54. });
  55. }
  56. function parseOrgs(name) {
  57. return new Promise( (resolve, reject) => {
  58. let urlpath = `api/users/${name}/orgs`;
  59. let orgs_final = [];
  60. queryUrl(urlpath, (orgs) => {
  61. var prom= [];
  62. for(var i = 0;i < orgs.length; i++) {
  63. prom.push( new Promise( (res, rej) => {
  64. url = orgs[i].url;
  65. queryUrl(url, (orgData) => {
  66. orgs_final.push("<a href=\""+orgData.html_url+"\"><img src=\""+orgData.avatar_url+"\" class=\"img-fluid\" style=\"max-width:49%\"></img></a>");
  67. res();
  68. }, (error) => {
  69. console.log(error);
  70. rej(error);
  71. console.error("error getting org info");
  72. });
  73. })
  74. )
  75. }
  76. Promise.all(prom).then(function() {
  77. resolve(orgs_final.join(" "));
  78. })
  79. }, (error) => {
  80. resolve([]);
  81. });
  82. })
  83. }
  84. function queryUrl(url, successCallBack, errorCallBack) {
  85. url = url.split("https://api.github.com/").join("api/");
  86. $.ajax({
  87. type:'GET',
  88. url: url,
  89. crossDomain: true,
  90. dataType: "json",
  91. success: successCallBack,
  92. error:errorCallBack,
  93. timeout: 3000
  94. });
  95. }
  96. function makeUrl(user) {
  97. return "/FriendsGraph.html?name="+user;
  98. }