-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·255 lines (213 loc) · 9.64 KB
/
index.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GitHub - Thomas Pickup</title>
<!-- Bootstrap CSS Import -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Page CSS Import -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<section class="content-section">
<div class="container">
<!-- Introduction -->
<div id="gh_picture" class="text-center mb-2"></div>
<div class="clearfix"></div>
<h2 id="gh_name" class="section-heading text-center"></h2>
<div id="gh_profile"></div>
<!-- Recent Activity
<hr class="section-heading-spacer">
<div class="clearfix"></div>
<h2 class="section-heading">Recent Activity</h2>
-->
<!-- Repositories -->
<hr class="section-heading-spacer">
<div class="clearfix"></div>
<h2 class="section-heading">Repositories</h2>
<p class="lead">Feel free to search through my repositories, just start typing in the search box!</p>
<hr>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="gh_search_prepend">Search</span>
</div>
<input id="gh_search" type="text" class="form-control">
</div>
<div id="gh_lastupdatedrepo"></div>
</div>
</section>
<!-- Bootstrap JS Import -->
<script src="js/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<!-- GitHub Script -->
<script type="text/javascript">
var username = 'thomaspickup';
var userAPI = 'https://api.github.com/users/'+ username;
var repoAPI = 'https://api.github.com/users/'+ username + '/repos?sort=pushed';
function createCard(repository, multiplier, difference) {
cardOutput = '';
cardOutput = cardOutput + '<div class="col-sm-6" height="100%"><div class="card" style="background-color:rgba(0, 0, 0, 0); border-color:rgba(0, 0, 0, 0)"><div class="card-body">';
cardOutput = cardOutput + '<h4 class="card-title"><a href="' + repository.html_url + '">';
cardOutput = cardOutput + repository.name;
cardOutput = cardOutput + '</a></h4>';
cardOutput = cardOutput + '<h6 class="card-subtitle mb-2 text-muted">';
cardOutput = cardOutput + repository.language + " | ";
cardOutput = cardOutput + difference + " " + multiplier + " Ago.";
cardOutput = cardOutput + '</h6>';
cardOutput = cardOutput + '<p class="card-text lead">';
if (repository.description != null) {
cardOutput = cardOutput + repository.description;
} else {
cardOutput = cardOutput + "No Description Yet. :(";
}
cardOutput = cardOutput + '</p>';
cardOutput = cardOutput + '</div></div></div>';
return cardOutput;
}
$('#gh_search').keyup(function() {
// Set to pending icon
$('#gh_lastupdatedrepo').html("<img class='mx-auto d-block' style='height: 60px; width: 60px;' src='img/spinner.gif'/>");
// Get the search results
var searchTerm = $('#gh_search').val().toLowerCase();
requestJSON(userAPI, function(json) {
var outhtml = '';
var repositories;
$.getJSON(repoAPI, function(json){
repositories = json;
outputPageContent();
});
function outputPageContent() {
if (repositories.length == 0) {
outhtml = outhtml + '<p>No repos!</p>';
} else {
outhtml = '<div class="card-deck">';
outhtml = outhtml + '<div class="row">';
numRepos = repositories.length;
numSelected = 0;
for (i = 0; i < numRepos; i++) {
if (repositories[i].name.toLowerCase().indexOf(searchTerm) !== -1) {
numSelected += 1;
// FINDS MILISECONDS FOR JSON OBJECT
var milisecs = Date.parse(repositories[i].pushed_at);
var lastUpdate = new Date(milisecs);
// FINDS THE DATE TIME NOW
var now = new Date(Date.now());
// GETS THE TIME DIFFERENCE AND WORKS OUT DIFFERENCE IN DAYS
var timeDiff = Math.abs(now.getTime() - lastUpdate.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
// SETS DIFFERENCE TO 0 READY FOR IF STATEMENT BELOW
var difference = 0;
var multiplier = "Days";
// CONVERTS TO DAY(S) OR MONTH(S)
if (diffDays >= 30) {
difference = Math.ceil(diffDays / 30);
multiplier = "Month";
if (difference >= 2) {
multiplier = "Months";
}
} else {
difference = diffDays;
if (diffDays == 1) {
multiplier = "Day";
}
}
outhtml = outhtml + createCard(repositories[i], multiplier, difference);
}
}
if (numSelected == 0) {
outhtml = outhtml + '<div class="col-sm-12" height="100%"><div class="card" style="background-color:rgba(0, 0, 0, 0); border-color:rgba(0, 0, 0, 0)"><div class="card-body">';
outhtml = outhtml + "<h4 class='card-title text-center'>No Repositories Found!</h4>";
outhtml = outhtml + "</div></div>";
}
outhtml = outhtml + '</div></div>';
}
$('#gh_lastupdatedrepo').html(outhtml);
}
}); // end requestJSON Ajax call
function requestJSON(url, callback) {
$.ajax({
url: url,
complete: function(xhr) {
callback.call(null, xhr.responseJSON);
}
});
}
});
$(function setupLastUpdatedRepo() {
requestJSON(userAPI, function(json) {
var outhtml = '';
var repositories;
$.getJSON(repoAPI, function(json){
repositories = json;
outputPageContent();
});
var profile;
$.getJSON(userAPI, function(json) {
profile = json;
setupProfile();
});
function setupProfile() {
profile_picture = "<img class='profile_picture' src='" + profile["avatar_url"] + "'/>";
output = "<p class='lead'>" + profile["bio"] + "</p>";
output = output + "<div class='btn-block btn-group' role='group'>"
+ '<a class="btn btn-outline-secondary" role="button">'
+ profile["location"] + '</a>'
+ '<a href="' + profile["blog"] + '" class="btn btn-outline-secondary" role="button">Home Page</a>'
+ '<a class="btn btn-outline-secondary" role="button">#' + profile["public_repos"] + ' Repos</a>'
+ "</div>";
$('#gh_name').html(profile['name']);
$('#gh_picture').html(profile_picture);
$('#gh_profile').html(output);
}
function outputPageContent() {
if(repositories.length == 0) { outhtml = outhtml + '<p>No repos!</p>'; }
else {
outhtml = '<div class="card-deck">';
outhtml = outhtml + '<div class="row">';
for (i = 0; i < 6; i++) {
// FINDS MILISECONDS FOR JSON OBJECT
var milisecs = Date.parse(repositories[i].pushed_at);
var lastUpdate = new Date(milisecs);
// FINDS THE DATE TIME NOW
var now = new Date(Date.now());
// GETS THE TIME DIFFERENCE AND WORKS OUT DIFFERENCE IN DAYS
var timeDiff = Math.abs(now.getTime() - lastUpdate.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
// SETS DIFFERENCE TO 0 READY FOR IF STATEMENT BELOW
var difference = 0;
var multiplier = "Days";
// CONVERTS TO DAY(S) OR MONTH(S)
if (diffDays >= 30) {
difference = Math.ceil(diffDays / 30);
multiplier = "Month";
if (difference >= 2) {
multiplier = "Months";
}
} else {
difference = diffDays;
if (diffDays == 1) {
multiplier = "Day";
}
}
// CREATES CARD FOR OUTPUTTING TO SCREEN
outhtml = outhtml + createCard(repositories[i], multiplier, difference);
}
outhtml = outhtml + '</div></div>';
}
$('#gh_lastupdatedrepo').html(outhtml);
}
}); // end requestJSON Ajax call
function requestJSON(url, callback) {
$.ajax({
url: url,
complete: function(xhr) {
callback.call(null, xhr.responseJSON);
}
});
}
});
function onLoad() {
setupLastUpdatedRepos();
}
window.onload = onLoad;
</script>
</body>