Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
ghjk
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavbhatt committed May 26, 2017
1 parent 17dab37 commit d93def1
Show file tree
Hide file tree
Showing 22 changed files with 19,337 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Somsubhra Bairi <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
91 changes: 91 additions & 0 deletions docs/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
html * {
font-family: 'Roboto', sans-serif;
}

.form-group {
width: 100%;
}
#username, #repository, #get-stats-button {
margin-top: 10px;
width: 100%;
}

#stats-result {
margin-top: 50px;
margin-bottom: 40px;
}

.error {
background-color: rgba(231, 76, 60, 0.2);
border: solid 1px rgba(231, 76, 60, 0.4);
padding: 20px;
font-size: 18px;
border-radius: 5px;
text-align: center;
}

.total-downloads {
margin-bottom: 25px;
text-align: center;
}

.total-downloads h2 {
display: inline;
font-size: 18px;
margin-right: 10px;
}

.release {
background-color: rgba(127, 140, 141, 0.2);
border: solid 1px rgba(127, 140, 141, 0.4);
padding: 20px;
border-radius: 5px;
margin-bottom: 10px;
}

.latest-release {
background-color: rgba(52, 152, 219, 0.2);
border: solid 1px rgba(52, 152, 219, 0.4);
}

.latest-release-hr {
border-top-color: rgba(52, 152, 219, 0.4);
}

.release-hr {
border-top-color: rgba(127, 140, 141, 0.4);
}

#loader-gif {
position: absolute;
bottom: 15%;
left: 47%;
}

#description {
text-align: center;
}

html {
position: relative;
min-height: 100%;
}
body {
margin-bottom: 40px;
}

#footer {
position: absolute;
bottom: 0;
width: 100%;
height: 40px;
background-color: rgba(210, 210, 210, 0.2);
padding: 10px;
text-align: center;
border-top: 1px solid rgba(210, 210, 210, 0.4);
}

#ads {
margin-top: 20px;
}

Binary file added docs/img/favicon.ico
Binary file not shown.
Binary file added docs/img/gif-load.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 180 additions & 0 deletions docs/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
var apiRoot = "https://api.github.com/";

function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for(var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if(pair[0] == variable) {
return pair[1];
}
}
return "";
}

// validate the user input
function validateInput() {
if ($("#username").val().length > 0 && $("#repository").val().length > 0) {
$("#get-stats-button").prop("disabled", false);
} else {
$("#get-stats-button").prop("disabled", true);
}
}

// Callback function for getting user repositories
function getUserRepos() {
var user = $("#username").val();

var autoComplete = $('#repository').typeahead();
var repoNames = [];

var url = apiRoot + "users/" + user + "/repos";
$.getJSON(url, function(data) {
$.each(data, function(index, item) {
repoNames.push(item.name);
});
});

autoComplete.data('typeahead').source = repoNames;
}

// Display the stats
function showStats(data) {

var err = false;
var errMessage = '';

if(data.status == 404) {
err = true;
errMessage = "The project does not exist!";
}

if(data.status == 403) {
err = true;
errMessage = "You've exceeded GitHub's rate limiting.<br />Please try again in about an hour.";
}

if(data.length == 0) {
err = true;
errMessage = "There are no releases for this project";
}

var html = '';

if(err) {
html = "<div class='col-md-6 col-md-offset-3 error output'>" + errMessage + "</div>";
} else {
html += "<div class='col-md-6 col-md-offset-3 output'>";
var latest = true;
var totalDownloadCount = 0;

$.each(data, function(index, item) {
var releaseTag = item.tag_name;
var releaseURL = item.html_url;
var releaseAssets = item.assets;
var hasAssets = releaseAssets.length != 0;
var releaseAuthor = item.author;
var publishDate = item.published_at.split("T")[0];

if(latest) {
html += "<div class='row release latest-release'>" +
"<h2><a href='" + releaseURL + "' target='_blank'>" +
"<span class='glyphicon glyphicon-tag'></span>&nbsp&nbsp" +
"Latest Release: " + releaseTag +
"</a></h2><hr class='latest-release-hr'>";
latest = false;
} else {
html += "<div class='row release'>" +
"<h4><a href='" + releaseURL + "' target='_blank'>" +
"<span class='glyphicon glyphicon-tag'></span>&nbsp&nbsp" +
releaseTag +
"</a></h4><hr class='release-hr'>";
}

html += "<h4><span class='glyphicon glyphicon-info-sign'></span>&nbsp&nbsp" +
"Release Info:</h4>";

html += "<ul>";

html += "<li><span class='glyphicon glyphicon-user'></span>&nbsp&nbspRelease Author: " +
"<a href='" + releaseAuthor.html_url + "'>" + releaseAuthor.login +"</a><br></li>";

html += "<li><span class='glyphicon glyphicon-calendar'></span>&nbsp&nbspPublished on: " +
publishDate + "</li>";

html += "</ul>";

if(hasAssets) {
html += "<h4><span class='glyphicon glyphicon-download'></span>" +
"&nbsp&nbspDownload Info: </h4>";

html += "<ul>";
$.each(releaseAssets, function(index, asset) {
var assetSize = (asset.size / 1048576.0).toFixed(2);
var lastUpdate = asset.updated_at.split("T")[0];
html += "<li>" + asset.name + " (" + assetSize + " MiB) - Downloaded " +
asset.download_count + " times.<br><i>Last updated on " + lastUpdate + "</i></li>";
totalDownloadCount += asset.download_count;
});
html += "</ul>";
}
html += "</div>";
});

if(totalDownloadCount > 0) {
totalDownloadCount = totalDownloadCount.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,');
var totalHTML = "<div class='row total-downloads'>";
totalHTML += "<h2><span class='glyphicon glyphicon-download'></span>" +
"&nbsp&nbspTotal Downloads</h2> ";
totalHTML += "<span>" + totalDownloadCount + "</span>";
totalHTML += "</div>";
html = totalHTML + html;
}

html += "</div>";
}

var resultDiv = $("#stats-result");
resultDiv.hide();
resultDiv.html(html);
$("#loader-gif").hide();
resultDiv.slideDown();
}

// Callback function for getting release stats
function getStats() {
var user = $("#username").val();
var repository = $("#repository").val();

var url = apiRoot + "repos/" + user + "/" + repository + "/releases";
$.getJSON(url, showStats).fail(showStats);
}

// The main function
$(function() {
$("#loader-gif").hide();

validateInput();
$("#username, #repository").keyup(validateInput);

$("#username").change(getUserRepos);

$("#get-stats-button").click(function() {
window.location = "?username=" + $("#username").val() +
"&repository=" + $("#repository").val();
});

var username = getQueryVariable("username");
var repository = getQueryVariable("repository");

if(username != "" && repository != "") {
$("#username").val(username);
$("#repository").val(repository);
validateInput();
getUserRepos();
$(".output").hide();
$("#description").hide();
$("#loader-gif").show();
getStats();
}
});
Loading

0 comments on commit d93def1

Please sign in to comment.