-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor the codebase. * rename recent contributors utility file.
- Loading branch information
1 parent
4da40fc
commit 30dd907
Showing
15 changed files
with
1,031 additions
and
898 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
document.addEventListener('DOMContentLoaded', function () { | ||
|
||
/*Scroll to top when arrow up clicked BEGIN*/ | ||
$(window).scroll(function() { | ||
var height = $(window).scrollTop(); | ||
if (height > 100) { | ||
$('#back2Top').fadeIn(); | ||
} else { | ||
$('#back2Top').fadeOut(); | ||
} | ||
}); | ||
|
||
$("#back2Top").click(function(event) { | ||
event.preventDefault(); | ||
$("html, body").animate({ scrollTop: 0 }, "slow"); | ||
return false; | ||
}); | ||
/*Scroll to top when arrow up clicked END*/ | ||
|
||
var toolbox; | ||
|
||
(function() { | ||
|
||
var org = urlHash().getUrlHashParameter('o') || 'publiclab'; | ||
var repo = urlHash().getUrlHashParameter('r') || 'plots2'; | ||
var ftoLabel = urlHash().getUrlHashParameter('f') || 'first-timers-only'; | ||
var candidateLabel = urlHash().getUrlHashParameter('c') || 'fto-candidate'; | ||
var recencyLabel = urlHash().getUrlHashParameter('l') || 'week'; | ||
|
||
toolbox = CommunityToolbox(org, repo); | ||
|
||
let d = document.getElementById('toggle-contributors'); | ||
let recency_label = document.getElementById('recency-label'); | ||
d.addEventListener("click", (e) => { | ||
e.preventDefault(); | ||
if (recencyLabel=="week") { | ||
toolbox.showRecentContributors(org, repo, recencyLabel); | ||
d.innerHTML = "Show monthly"; | ||
recency_label.innerHTML = "last week: "; | ||
recencyLabel = "month"; | ||
}else if (recencyLabel=="month") { | ||
toolbox.showRecentContributors(org, repo, recencyLabel); | ||
d.innerHTML = "Show weekly"; | ||
recency_label.innerHTML = "last month: "; | ||
recencyLabel = "week"; | ||
} | ||
}) | ||
|
||
if (repo === 'all') { | ||
|
||
toolbox.getIssuesForOrg(org, { qs: { labels: ftoLabel } }) | ||
.then(displayIssues('.first-timers-only')); | ||
|
||
toolbox.getIssuesForOrg(org, { qs: { labels: candidateLabel } }) | ||
.then(displayIssues('.candidates')); | ||
|
||
toolbox.initialize(org, repo).then((res)=> { | ||
if(res) { | ||
// compile and display all contributors for given org | ||
toolbox.showAllContributors(org, repo); | ||
// Makes the toggle contributors list button click | ||
d.click(); | ||
} | ||
}) | ||
|
||
} else { | ||
|
||
toolbox.api.Issues | ||
.getIssuesForRepo(org, repo, { qs: { labels: ftoLabel } }) | ||
.then(displayIssues('.first-timers-only')); | ||
|
||
toolbox.api.Issues | ||
.getIssuesForRepo(org, repo, { qs: { labels: candidateLabel } }) | ||
.then(displayIssues('.candidates')); | ||
|
||
toolbox.initialize(org, repo).then((res)=> { | ||
if(res) { | ||
// compile and display all contributors for given repo | ||
toolbox.showRepoContributors(org, repo); | ||
// Makes the toggle contributors list button click | ||
d.click(); | ||
} | ||
}) | ||
} | ||
|
||
function displayIssues(selector) { | ||
return function displayIssues(issues) { | ||
if (typeof issues === "string") issues = JSON.parse(issues).items; | ||
issues.forEach(function(issue) { | ||
toolbox.issuesUI.insertIssue(issue, selector); | ||
}); | ||
} | ||
} | ||
|
||
})(); | ||
}) |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var insertContributorsExec = false; | ||
|
||
|
||
function insertContributors(AllContributors){ | ||
// This removes the spinner icon as soon as contributors list is loaded | ||
document.getElementById("spinner-icon").style.display = "none"; | ||
|
||
let totalContributors = 0; | ||
var usernames = AllContributors.map(function getContributorUsername(c) { | ||
return `@${c.login}`; | ||
}); | ||
var avatars = AllContributors.map(function getContributorAvatarURL(c) { | ||
return `<a href="#" title="${c.login}"><img width="100px" src="${c.avatar_url}"></a>`; | ||
}); | ||
totalContributors += AllContributors.length; | ||
if(insertContributorsExec) $('.contributors > .usernames').append(', '); | ||
$('.contributors-head').html('Contributors ('+totalContributors+'+)'); | ||
$('.contributors > .usernames').append(usernames.join(', ')); | ||
$('.contributors > .avatars').append(avatars.join('')); | ||
insertContributorsExec=true; | ||
} | ||
|
||
|
||
module.exports = { | ||
insertContributors: insertContributors, | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var moment = require('moment'); | ||
|
||
|
||
|
||
function generateIssueHtml(title, body, githubUrl, repo) { | ||
var repoName = githubUrl.split('/')[4], | ||
repoUrl = githubUrl.split('/').slice(0, 5).join('/'), | ||
html = '<div class="panel panel-default">\ | ||
<div class="panel-heading">\ | ||
<h3 class="panel-title" style="float:right;font-size:12px;"><b><a href="' + repoUrl + '">' + repoName + '</a></b></h3>\ | ||
<h3 class="panel-title"><b><a href="' + githubUrl + '">' + title + '</a></b></h3>\ | ||
</div>\ | ||
<div class="panel-body">\ | ||
' + body + '\ | ||
</div>\ | ||
</div>'; | ||
return html; | ||
} | ||
|
||
function insertIssue(issue, el) { | ||
var body = ""; | ||
body += "<div style='float:right;' class='labels'>" | ||
issue.labels.forEach(function(label) { | ||
body += "<a class='label label-default' href='" + label.url + "' style='background:#" + label.color + ";'>" + label.name + "</a> "; | ||
}); | ||
body += "</div>"; | ||
body += "<b>#" + issue.number + "</b> opened " + moment(issue.updated_at).fromNow() + " "; | ||
body += "by <a href='https://github.com/" + issue.user.login + "'>" + issue.user.login + "</a>"; | ||
body += " <i class='fa fa-comment-o'></i> " + issue.comments; | ||
$(el).append(generateIssueHtml(issue.title, body, issue.html_url, issue)); | ||
} | ||
|
||
|
||
module.exports = { | ||
generateIssueHtml: generateIssueHtml, | ||
insertIssue: insertIssue, | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var insertRecentContributorsExec = false; | ||
|
||
|
||
function insertRecentContributors(AllContributors){ | ||
let recentContributors = 0; | ||
let usernames = AllContributors.map((commit, i) => { | ||
return `<a href="${commit.author.html_url}">@${commit.author.login}</a>`; | ||
}) | ||
let avatars = AllContributors.map((commit, i) => { | ||
return `<a href="${commit.author.html_url}" class="hvr-Glow"><img width="100px" src="${commit.author.avatar_url}"></a>`; | ||
}) | ||
recentContributors += AllContributors.length; | ||
|
||
if(insertRecentContributorsExec) $('.recent-contributors > .usernames').append(', '); | ||
$('.recent-contributors-head').html('Recent Contributors ('+recentContributors+'+)'); | ||
$('.recent-contributors > .usernames').html(usernames.join(', ')); | ||
$('.recent-contributors > .avatars').html(avatars.join('')); | ||
insertRecentContributorsExec=true; | ||
} | ||
|
||
|
||
module.exports = { | ||
insertRecentContributors: insertRecentContributors, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.