-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathui.js
More file actions
82 lines (75 loc) · 3.15 KB
/
ui.js
File metadata and controls
82 lines (75 loc) · 3.15 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
class UI {
constructor() {
this.profile = document.getElementById('profile');
}
showProfile(user) {
this.profile.innerHTML = `
<div class="card card-body mb-3">
<div class="row">
<div class="col-md-3">
<img src="${user.avatar_url}" alt="" class="img-fluid mb-2">
<a href="${user.html_url}" target="_blank" class="btn btn-primary btn-block"> View Profile</a>
</div>
<div class="col-md-9">
<span class="badge badge-primary"> Public Repos: ${user.public_repos}</span>
<span class="badge badge-secondary"> Public Gists: ${user.public_gists}</span>
<span class="badge badge-success"> Followers: ${user.followers}</span>
<span class="badge badge-info"> Following: ${user.following}</span>
<br> <br>
<ul class="list-group">
<li class="list-group-item">Company : ${user.company}</li>
<li class="list-group-item">Website : ${user.blog}</li>
<li class="list-group-item">Location : ${user.location}</li>
<li class="list-group-item">Member Since : ${user.created_at}</li>
</ul>
</div>
</div>
</div>
<h3 class="page-heading mb-3"> Latest Repos</h3>
<div id="repos"></div>
</div>
`;
}
showRepos(repos) {
let output = '';
repos.forEach(function(repo) {
output += `
<div class="card card-body mb-2">
<div class="row">
<div class="col-sm-6">
<a href="${repo.html_url}" target="_blank">${repo.name}</a>
<p class="pt-2">${repo.description}</p>
</div>
<div class="col-sm-6">
<span class="badge badge-primary"> Starts: ${repo.stargazers_count}</span>
<span class="badge badge-info"> Watchers: ${repo.watchers_count}</span>
<span class="badge badge-light"> Forks: ${repo.forms_count}</span>
</div>
</div>
</div>
`;
});
document.getElementById('repos').innerHTML = output;
}
showAlert(message, className) {
this.clearAlert();
const div = document.createElement('div');
div.className = className;
div.appendChild(document.createTextNode(message));
const container = document.querySelector('.searchContainer');
const search = document.querySelector('.search');
container.insertBefore(div, search);
setTimeout(() => {
this.clearAlert();
}, 2000);
}
clearAlert() {
const currentAlert = document.querySelector('.alert');
if(currentAlert) {
currentAlert.remove();
}
}
clearProfile() {
this.profile.innerHTML = '';
}
}