forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 4
Homework Week 2 Midy #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ghost
wants to merge
4
commits into
SocialHackerCreteClass:Midyan-Hamdoun
Choose a base branch
from
unknown repository
base: Midyan-Hamdoun
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" | ||
/> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta name="apple-mobile-web-app-capable" content="yes" /> | ||
<meta name="mobile-web-app-capable" content="yes" /> | ||
<meta name="format-detection" content="telephone=no" /> | ||
<link rel="apple-touch-icon" href="./hyf.png" /> | ||
<link rel="shortcut icon" type="image/png" href="./hyf.png" /> | ||
<title>HYF-GITHUB</title> | ||
<link | ||
href="https://fonts.googleapis.com/css?family=Roboto:400,700" | ||
rel="stylesheet" | ||
/> | ||
<link rel="stylesheet" href="./style.css" /> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script src="./Util.js"></script> | ||
<script src="./Observable.js"></script> | ||
<script src="./Model.js"></script> | ||
<script src="./HeaderView.js"></script> | ||
<script src="./RepoView.js"></script> | ||
<script src="./ContributorsView.js"></script> | ||
<script src="./ErrorView.js"></script> | ||
<script src="./App.js"></script> | ||
</body> | ||
</html> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta name="apple-mobile-web-app-capable" content="yes" /> | ||
<meta name="mobile-web-app-capable" content="yes" /> | ||
<meta name="format-detection" content="telephone=no" /> | ||
<link rel="apple-touch-icon" href="./hyf.png" /> | ||
<link rel="shortcut icon" type="image/png" href="./hyf.png" /> | ||
<title>HYF-GITHUB</title> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet" /> | ||
<link rel="stylesheet" href="./style.css" /> | ||
</head> | ||
|
||
<body> | ||
<div id="hyf-title">HYF Repositories</div> | ||
<div id="root"></div> | ||
<ul id="contributors-list"></ul> | ||
<script src="./Util.js"></script> | ||
<script src="./Observable.js"></script> | ||
<script src="./Model.js"></script> | ||
<script src="./HeaderView.js"></script> | ||
<script src="./RepoView.js"></script> | ||
<script src="./ContributorsView.js"></script> | ||
<script src="./ErrorView.js"></script> | ||
<script src="./App.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
body { | ||
font-family: 'Lato'; | ||
font-size: 17px; | ||
} | ||
|
||
.alert-error { | ||
color: red; | ||
} | ||
|
||
#root { | ||
display: flex; | ||
align-content: center; | ||
justify-items: center; | ||
} | ||
|
||
.repo, li { | ||
margin-bottom: 10px; | ||
box-shadow: 0 4px 2px -2px gray; | ||
border: 0.4px gray solid; | ||
padding: 10px; | ||
width: 60%; | ||
} | ||
|
||
#hyf-title { | ||
background-color: blueviolet; | ||
color: white; | ||
height: 100px; | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: 40px; | ||
} | ||
|
||
li { | ||
list-style-type: none; | ||
} | ||
|
||
img { | ||
width: 25%; | ||
vertical-align: middle; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,34 +21,122 @@ | |
parent.appendChild(elem); | ||
Object.entries(options).forEach(([key, value]) => { | ||
if (key === 'text') { | ||
elem.textContent = value; | ||
elem.innerHTML = value; | ||
} else { | ||
elem.setAttribute(key, value); | ||
} | ||
}); | ||
return elem; | ||
} | ||
|
||
function renderRepoDetails(repo, ul) { | ||
createAndAppend('li', ul, { text: repo.name }); | ||
function renderRepoDetails(repo, parent) { | ||
createAndAppend('div', parent, { | ||
text: ` | ||
<b>Repository:</b> <a href="${repo.html_url}" target="_blank">${repo.name}</a><br> | ||
<b>Description:</b> ${repo.description}<br> | ||
<b>Forks:</b> ${repo.forks_count}<br> | ||
<b>Updated:</b> ${formatDate(repo.updated_at)}`, | ||
class: 'repo' | ||
}); | ||
} | ||
|
||
function renderContributorsDetails(contributor, parent) { | ||
createAndAppend('li', parent, { | ||
text: `<img src="${contributor.avatar_url}" alt="${contributor.login}"> | ||
<a target="_blank" href="${contributor.html_url}">${contributor.login}</a> | ||
<b>${contributor.contributions}</b>` | ||
}); | ||
} | ||
|
||
function addNamesToDropDown(repo, select) { | ||
createAndAppend('option', select, { | ||
text: repo.name, | ||
value: repo.name | ||
}); | ||
} | ||
|
||
function formatDate(date) { | ||
const newDate = new Date(date); | ||
let hours = newDate.getHours(); | ||
let amPm; | ||
let minutes = newDate.getMinutes().toString(); | ||
let seconds = newDate.getSeconds().toString(); | ||
|
||
if (minutes < 10) { | ||
minutes = `0${hours}`; | ||
} | ||
if (seconds < 10) { | ||
seconds = `0${seconds}`; | ||
} | ||
if (newDate.getHours() > 12) { | ||
hours = hours - 12; | ||
amPm = 'PM' | ||
} else { | ||
amPm = 'AM' | ||
} | ||
return `${newDate.getMonth() + 1}/${newDate.getDate()}/${newDate.getFullYear()}, ${hours}:${minutes}:${seconds} ${amPm}`; | ||
} | ||
|
||
function sortObjects(a, b) { | ||
const nameA = a.name.toUpperCase(); | ||
const nameB = b.name.toUpperCase(); | ||
|
||
let comparison = 0; | ||
if (nameA > nameB) { | ||
comparison = 1; | ||
} else if (nameA < nameB) { | ||
comparison = -1; | ||
} | ||
return comparison; | ||
} | ||
|
||
function getContributors(repo) { | ||
fetchJSON(`https://api.github.com/repos/HackYourFuture/${repo}/contributors`, (err, contributors) => { | ||
const root = document.getElementById('repo-container'); | ||
if (err) { | ||
createAndAppend('div', root, { | ||
text: err.message, | ||
class: 'alert-error', | ||
}); | ||
return; | ||
} | ||
const ul = document.getElementById('contributors-container'); | ||
contributors.forEach(contributor => renderContributorsDetails(contributor, ul)); | ||
}); | ||
} | ||
|
||
function main(url) { | ||
fetchJSON(url, (err, repos) => { | ||
const root = document.getElementById('root'); | ||
const root = document.getElementById('repo-container'); | ||
if (err) { | ||
createAndAppend('div', root, { | ||
text: err.message, | ||
class: 'alert-error', | ||
}); | ||
return; | ||
} | ||
const ul = createAndAppend('ul', root); | ||
repos.forEach(repo => renderRepoDetails(repo, ul)); | ||
|
||
const repoContainer = document.getElementById('repo-container'); | ||
const select = document.getElementById('names'); | ||
|
||
repos.sort(sortObjects); | ||
repos.forEach(repo => addNamesToDropDown(repo, select)); | ||
renderRepoDetails(repos[0], repoContainer); | ||
getContributors(repos[0].name); | ||
select.addEventListener('change', () => { | ||
document.getElementById('contributors-container').innerHTML = ''; | ||
repoContainer.innerHTML = ''; | ||
// This here finds the index of the repo we are looking for | ||
// using the value selected in `select` | ||
renderRepoDetails( | ||
repos[repos.findIndex(el => el.name === select.options[select.selectedIndex].value)], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to use this instead of select here in order to make this function reusable if needed |
||
repoContainer | ||
); | ||
getContributors(select.options[select.selectedIndex].value); | ||
}) | ||
}); | ||
} | ||
|
||
const HYF_REPOS_URL = | ||
'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; | ||
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; | ||
window.onload = () => main(HYF_REPOS_URL); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!