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.

122 lines
6.2 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
  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-7 p-0\"> \
  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-2 p-0\"> \
  22. <button type=\"button\" class=\"btn btn-link pt-3\"> \
  23. <a href=\""+graphUrl(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 class=\"col-2 p-0\"> \
  32. <button type=\"button\" class=\"btn btn-link pt-3\"> \
  33. <a href=\""+timelineUrl(user.login)+"\"> \
  34. <svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"> \
  35. <defs> \
  36. <path id=\"a\" d=\"M0 0h24v24H0z\"/> \
  37. </defs> \
  38. <clipPath> \
  39. <use xlink:href=\"#a\" overflow=\"visible\"/> \
  40. </clipPath> \
  41. <defs> \
  42. <path id=\"b\" d=\"M0 0h24v24H0z\"/></defs><clipPath><use xlink:href=\"#b\" overflow=\"visible\"/> \
  43. </clipPath> \
  44. <path d=\"M23 8c0 1.1-.9 2-2 2-.18 0-.35-.02-.51-.07l-3.56 3.55c.05.16.07.34.07.52 0 1.1-.9 2-2 2s-2-.9-2-2c0-.18.02-.36.07-.52l-2.55-2.55c-.16.05-.34.07-.52.07s-.36-.02-.52-.07l-4.55 4.56c.05.16.07.33.07.51 0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2c.18 0 .35.02.51.07l4.56-4.55C8.02 9.36 8 9.18 8 9c0-1.1.9-2 2-2s2 .9 2 2c0 .18-.02.36-.07.52l2.55 2.55c.16-.05.34-.07.52-.07s.36.02.52.07l3.55-3.56C19.02 8.35 19 8.18 19 8c0-1.1.9-2 2-2s2 .9 2 2z\"/> \
  45. </svg> \
  46. </a> \
  47. </button> \
  48. </div> \
  49. </div> \
  50. <div class=\"card-body py-1\" style=\"background-color:rgb(255,255,255);\"> \
  51. <p class=\"card-text\"><a href=\""+user.html_url+"\" class=\"card-link\">"+user.html_url+"</a></p> \ " +
  52. (user.blog != null ? "<p class=\"card-text \"><a href="+user.blog+" class=\"card-link\">"+user.blog+"</a></p>" : "")+" \
  53. </div> \
  54. <ul class=\"list-group list-group-flush\"> \
  55. <li class=\"list-group-item\">Followers: "+user.followers+"</li> \
  56. <li class=\"list-group-item\">Following: "+user.following+"</li> \
  57. <li class=\"list-group-item\">Repositories: "+user.public_repos+"</li>" +
  58. (user.bio != null ? "<li class=\"list-group-item\">Bio: "+user.bio+"</li>" : "")+
  59. (user.location != null ? "<li class=\"list-group-item\">Location: "+user.location+"</li>" : "")+
  60. (user.email != null ? "<li class=\"list-group-item\">Email: "+user.email+"</li>" : "")+
  61. (user.company != null ? "<li class=\"list-group-item\">Company: "+user.company+"</li>" : "")+
  62. (orgsReturn != [] ? "<li class=\"list-group-item\">"+orgsReturn+"</li>" : "")+ " \
  63. </ul> \
  64. </div>";
  65. $("#"+container).html(html);
  66. })
  67. }, () => {
  68. alert("User Does Not Exist");
  69. window.location.href = "./GraphGenerator.html";
  70. });
  71. }
  72. function parseOrgs(name) {
  73. return new Promise( (resolve, reject) => {
  74. let urlpath = `api/users/${name}/orgs`;
  75. let orgs_final = [];
  76. queryUrl(urlpath, (orgs) => {
  77. var prom= [];
  78. for(var i = 0;i < orgs.length; i++) {
  79. prom.push( new Promise( (res, rej) => {
  80. url = orgs[i].url;
  81. queryUrl(url, (orgData) => {
  82. orgs_final.push("<a href=\""+orgData.html_url+"\"><img src=\""+orgData.avatar_url+"\" class=\"img-fluid\" style=\"max-width:49%\"></img></a>");
  83. res();
  84. }, (error) => {
  85. console.log(error);
  86. rej(error);
  87. console.error("error getting org info");
  88. });
  89. })
  90. )
  91. }
  92. Promise.all(prom).then(function() {
  93. resolve(orgs_final.join(" "));
  94. })
  95. }, (error) => {
  96. resolve([]);
  97. });
  98. })
  99. }
  100. function queryUrl(url, successCallBack, errorCallBack) {
  101. url = url.split("https://api.github.com/").join("api/");
  102. $.ajax({
  103. type:'GET',
  104. url: url,
  105. crossDomain: true,
  106. dataType: "json",
  107. success: successCallBack,
  108. error:errorCallBack,
  109. timeout: 3000
  110. });
  111. }
  112. function graphUrl(user) {
  113. return "/FriendsGraph.html?name="+user;
  114. }
  115. function timelineUrl(user) {
  116. return "/TimeLineGraph.html?name="+user;
  117. }