-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
118 lines (95 loc) · 4.39 KB
/
Copy pathApp.js
File metadata and controls
118 lines (95 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict';
/* global Util, Repository, Contributor */
class App {
constructor(url) {
this.initialize(url);
}
/**
* Initialization
* @param {string} url The GitHub URL for obtaining the organization's repositories.
*/
async initialize(url) {
const root = document.getElementById('root');
try {
const data = await Util.fetchJSON(url);
this.data = data.map(repo => new Repository(repo));
await renderContainer(data)
} catch (error) {
this.renderError(error);
}
function renderIndex0(data){
for (let i = 0; i < data.length; i++){
let Image0Link = Util.createAndAppend('li', contributorsUl, {})
let contributor0Name = Util.createAndAppend('img', Image0Link, {src: data[i].avatar_url, class: 'imageSrc'});
let contributor0Link = Util.createAndAppend('a', Image0Link, {text: data[i].login, target: "_blank", href: data[i].html_url, id: 'link'});
let contributor0Badge = Util.createAndAppend('li', Image0Link, {text:"Contributions: " + data[i].contributions, class: 'badge'});
} //end for
data.forEach((repo) => {
for (let i = 0; i < newArray.length; i++) {
Util.createAndAppend('option', selectList, {id: "myOption", value: i, text: newArray[i]});
}
});
function removeNodes(container){
while (ul.hasChildNodes()) {
ul.removeChild(ul.firstChild);
}
while (contributorsUl.hasChildNodes()) {
contributorsUl.removeChild(contributorsUl.firstChild);
}
} //end removeNodes
selectList.onchange = function(selectedIndex){
let repoName = Util.createAndAppend('li', ul, { text: "Repository: ", class: 'nameInContainer', function: removeNodes()});
Util.createAndAppend('a', repoName, { text: newArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]});
Util.createAndAppend('li', ul, {text: "Description: " + descriptionArray[this.selectedIndex], class: 'descriptionInContainer'});
Util.createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'});
Util.createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'});
let dates = new Date (updatedAt[this.selectedIndex]);
dates = dates.toUTCString();
Util.createAndAppend('li', ul, {text: "Updated at: " + dates, class: 'updatedAtInContainer'});
}// end of onchange
}// end renderIndex0
}
/**
* Removes all child elements from a container element
* @param {*} container Container element to clear
*/
clearContainer(container) {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
}
/**
* Fetch contributor information for the selected repository and render the
* repo and its contributors as HTML elements in the DOM.
* @param {number} index The array index of the repository.
*/
async fetchContributorsAndRender(index) {
try {
const repo = this.repos[index];
const contributors = await repo.fetchContributors();
const container = document.getElementById('container');
this.clearContainer(container);
const leftDiv = Util.createAndAppend('div', container);
const rightDiv = Util.createAndAppend('div', container);
const contributorList = Util.createAndAppend('ul', rightDiv);
repo.render(leftDiv);
contributors
.map(contributor => new Contributor(contributor))
.forEach(contributor => contributor.render(contributorList));
} catch (error) {
this.renderError(error);
}
}
/**
* Render an error to the DOM.
* @param {Error} error An Error object describing the error.
*/
renderError(err) {
let catsrc = 'https://us.123rf.com/450wm/photodeti/photodeti1702/photodeti170200132/72587923-cat-holding-stop-sign-isolated-on-white-background-.jpg?ver=6';
Util.createAndAppend('div', root, { text: err.message, class: 'alert-error' }),
Util.createAndAppend('img', root, {id: 'catImage', src: catsrc});
}
}
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
let index0API = 'https://api.github.com/repos/HackYourFuture/alumni/contributors';
window.onload = () => new App(HYF_REPOS_URL);