|
30 | 30 | }); |
31 | 31 | return elem; |
32 | 32 | } |
33 | | - |
34 | | - |
| 33 | + |
35 | 34 | function main(url) { |
36 | 35 | while (root.firstChild) { |
37 | 36 | root.removeChild(root.firstChild); |
|
41 | 40 | if (err) { |
42 | 41 | createAndAppend('div', root, { text: err.message, class: 'alert-error' }); |
43 | 42 | } |
44 | | - const newArray = []; |
| 43 | + let newArray = []; |
45 | 44 | let forkArray = []; |
46 | 45 | let languageArray = []; |
47 | 46 | let descriptionArray = []; |
48 | 47 | let updatedAt = []; |
49 | 48 | let htmlArray = []; |
50 | | - let contributorsArray = []; |
| 49 | + data.sort((a, b) => (a.name).localeCompare(b.name)); |
| 50 | + |
| 51 | + |
51 | 52 | for (let i = 0; i < data.length; i++){ |
52 | 53 | newArray.push(data[i].name); |
53 | | - newArray.sort(); |
54 | 54 | descriptionArray.push(data[i].description); |
55 | 55 | forkArray.push(data[i].forks); |
56 | 56 | languageArray.push(data[i].language); |
57 | 57 | updatedAt.push(data[i].updated_at); |
58 | | - contributorsArray.push(data[i].contributors_url); |
59 | | - contributorsArray.sort(); |
60 | | - htmlArray.push(data[i].html_url); |
61 | | - htmlArray.sort(); |
| 58 | + htmlArray.push(data[i].html_url); |
| 59 | + var date = new Date ((data[i].updated_at)); |
| 60 | + date = date.toUTCString(); |
62 | 61 | } |
63 | 62 |
|
64 | 63 |
|
65 | | - let app = document.getElementById('root'); |
66 | | - const header = createAndAppend('h1', app, { text: "Hack Your Future Repositories", class: 'title' }); |
67 | | - const subHeader = createAndAppend('h3', app, { text: "Select a repository: ", class: 'subtitle'}); |
68 | | - const selectList = createAndAppend('select', app, { text: 'Select a Repo', id: "mySelect" }); |
69 | | - const container = createAndAppend('div', app, {class: 'container'}); |
70 | | - const card = createAndAppend('div', container, {text: "Information about this repository: ", class: 'card'}); |
| 64 | + const root = document.getElementById('root'); |
| 65 | + createAndAppend('h1', root, { text: "Hack Your Future Repositories", class: 'title' }); |
| 66 | + createAndAppend('h3', root, { text: "Select a repository: ", class: 'subtitle'}); |
| 67 | + const selectList = createAndAppend('select', root, {id: "mySelect" }); |
| 68 | + const headerDiv = createAndAppend('div', root, {class: 'headerdiv'}); |
| 69 | + createAndAppend('h3', headerDiv, { text: "Repository Information", class: 'subtitle', id: 'repoHeader' }); |
| 70 | + createAndAppend('h3', headerDiv, { text: "Contributors", class: 'subtitle', id:'contributorHeader' }); |
| 71 | + const container = createAndAppend('div', root, {class: 'container'}); |
| 72 | + const card = createAndAppend('div', container, { class: 'card'}); |
71 | 73 | const ul = createAndAppend('ul', card, {id: "myUl", }); |
72 | | - const contributorsheader = createAndAppend('h1', root, { text: "Contributors", class: 'title' }); |
73 | | - const contributorsContainer = createAndAppend('div', root, { class: 'container'}) |
74 | | - const contributorsCard = createAndAppend('div', contributorsContainer, {text: "Contributors to this Repository", class: 'card'}); |
| 74 | + const contributorsCard = createAndAppend('div', container, {class: 'card'}); |
75 | 75 | const contributorsUl = createAndAppend('ul', contributorsCard, {id: 'contributorsUl'}); |
76 | | - |
77 | | - |
| 76 | + const Index0Name = createAndAppend ('li', ul, {text: "Repository: ", class: 'nameInContainer'}); |
| 77 | + const Index0Link = createAndAppend ('a', Index0Name, {text: newArray[0], target: "_blank", href: htmlArray[0]}); |
| 78 | + const Index0Description = createAndAppend('li', ul, {text: "Description: " + descriptionArray[0], class:"descriptionInContainer"}); |
| 79 | + const Index0Fork = createAndAppend ('li', ul, {text: "Number of Forks: " + forkArray[0], class: 'forksInContainer'}); |
| 80 | + const Index0Language = createAndAppend ('li', ul, {text: "Language: " + languageArray[0], class: 'updatedAtInContainer'}); |
| 81 | + const Index0UpdatedAt = createAndAppend ('li', ul, {text: "Updated at: " + date, class: 'updatedAtInContainer'}) |
| 82 | + |
| 83 | + |
78 | 84 |
|
79 | 85 | data.forEach((repo) => { |
80 | 86 | for (let i = 0; i < newArray.length; i++) { |
|
90 | 96 | contributorsUl.removeChild(contributorsUl.firstChild); |
91 | 97 | } |
92 | 98 | } //end removeNodes |
93 | | - |
| 99 | + |
94 | 100 | selectList.onchange = function(selectedIndex){ |
95 | | - let repoName = createAndAppend('li', ul, { text: "Repository: ", class: 'nameInContainer', function: removeNodes()}); |
96 | | - createAndAppend('a', repoName, { text: newArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]}); |
97 | | - createAndAppend('li', ul, {text: "Description: " + descriptionArray[this.selectedIndex], class: 'descriptionInContainer'}); |
98 | | - createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'}); |
99 | | - createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'}); |
100 | | - createAndAppend('li', ul, {text: "Updated at: " + updatedAt[this.selectedIndex], id: 'updatedAtInContainer'}) |
101 | | - fetchJSON('https://api.github.com/repos/HackYourFuture/' + newArray[this.selectedIndex] + '/contributors', (err, data) => { |
102 | | - let getName = []; |
103 | | - let getLink = []; |
104 | | - let getBadge = []; |
105 | | - let login = []; |
106 | | - for (let i = 0; i < data.length; i++){ |
107 | | - getName.push(data[i].avatar_url); |
108 | | - getLink.push(data[i].html_url); |
109 | | - getBadge.push(data[i].contributions); |
110 | | - login.push(data[i].login); |
111 | | - |
| 101 | + fetchJSON('https://api.github.com/repos/HackYourFuture/' + newArray[this.selectedIndex] + '/contributors', (err, data) => { |
| 102 | + for (let i = 0; i < data.length; i++){ |
112 | 103 | let imageLink = createAndAppend('li', contributorsUl, {}) |
113 | | - let contributorName = createAndAppend('img', imageLink, {src: data[i].avatar_url}); |
| 104 | + let contributorName = createAndAppend('img', imageLink, {src: data[i].avatar_url, class: 'imageSrc'}); |
114 | 105 | let contributorLink = createAndAppend('a', imageLink, {text: data[i].login, target: "_blank", href: data[i].html_url, id: 'link'}); |
115 | 106 | let contributorBadge = createAndAppend('li', imageLink, {text:"Contributions: " + data[i].contributions, class: 'badge'}); |
116 | 107 | } //end for |
117 | | - data.forEach((repo) => { |
118 | | - });//end for each |
119 | 108 | }); //end fetchJSON |
| 109 | + let repoName = createAndAppend('li', ul, { text: "Repository: ", class: 'nameInContainer', function: removeNodes()}); |
| 110 | + createAndAppend('a', repoName, { text: newArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]}); |
| 111 | + createAndAppend('li', ul, {text: "Description: " + descriptionArray[this.selectedIndex], class: 'descriptionInContainer'}); |
| 112 | + createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'}); |
| 113 | + createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'}); |
| 114 | + let dates = new Date (updatedAt[this.selectedIndex]); |
| 115 | + dates = dates.toUTCString(); |
| 116 | + createAndAppend('li', ul, {text: "Updated at: " + dates, class: 'updatedAtInContainer'}); |
120 | 117 |
|
121 | | - }// end of onchange |
122 | | - }); //end of Fetch |
123 | | - |
124 | | - |
| 118 | + }// end of onchange |
125 | 119 |
|
126 | | - |
127 | | - } |
| 120 | + }); //end of Fetch |
| 121 | + } //end main |
| 122 | + |
128 | 123 |
|
129 | 124 | const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; |
130 | 125 | window.onload = () => main(HYF_REPOS_URL); |
|
0 commit comments