Skip to content

Commit

Permalink
some minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh570 committed Jul 24, 2019
1 parent 7d48833 commit b355974
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 65 deletions.
32 changes: 14 additions & 18 deletions dist/community-toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -82160,23 +82160,23 @@ CommunityToolbox = function CommunityToolbox(org, repo) {


// Function for fetching and showing recent contributors
function showRecentContributors(org, repo, recencyLabel, forMonths=1) {
function showRecentContributors(org, repo, recencyLabel, forMonths=6) {
return recentContribsUtil.fetchAllRecentContribsInDb(org, repo).then((result)=>{
if(recencyLabel==="month") {
return recentContribsUtil.fetchContribsLastMonth(org, repo, forMonths)
.then(function gotCommits(commits) {
// Stores the CURRENTLY ACTIVE recent contribs data
.then(function gotMonthlyContribs(monthContribs) {
// Stores the CURRENTLY ACTIVE recent contribs data which is utilized by filter
model_utils.deleteItem('recent-contribs-data').then((res)=> {
model_utils.setItem('recent-contribs-data', commits);
model_utils.setItem('recent-contribs-data', monthContribs);
})
// Push data to UI
recentContributorsUI.insertRecentContributors(commits);
recentContributorsUI.insertRecentContributors(monthContribs);
return;
});
} else {
return recentContribsUtil.fetchContribsLastWeek(org, repo)
.then((weekly_contribs) => {
// Stores the CURRENTLY ACTIVE recent contribs data
// Stores the CURRENTLY ACTIVE recent contribs data which is utilized by filter
model_utils.deleteItem('recent-contribs-data').then((res)=> {
model_utils.setItem('recent-contribs-data', weekly_contribs);
})
Expand Down Expand Up @@ -82532,7 +82532,7 @@ function fetchAllRecentMonthContribs(org, repos, queryTime) {
let monthInd = monthsQuery.findMonthInd(queryTime);

// We take only 10 repos just for API quota reasons
let splicedRepos = repos.splice(0,1);
let splicedRepos = repos.splice(0,10);

let promises = splicedRepos.map(function mapToEachRepo(repo, i) {
return fetchRecentMonthContribs.fetchRecentMonthContribs(org, repo, queryTime)
Expand Down Expand Up @@ -82576,8 +82576,7 @@ module.exports = {
},{"../../models/utils":405,"./fetchRecentMonthContribs":416,"./queryTime":421}],416:[function(require,module,exports){
let model_utils = require('../../models/utils')
let monthsQuery = require('./queryTime')
let withinThisWeekOrNot = require('./withinThisWeekOrNot')
let withinThisMonthOrNot = require('./withinThisMonthOrNot')
let withinMonthsOrNot = require('./withinMonthsOrNot')
let freshFetch = require('./freshFetch')

// Fetches recent month commits for a particular repository
Expand All @@ -82596,7 +82595,7 @@ function fetchRecentMonthContribs(org, repo, queryTime) {
if(wholeContribsList!=undefined && wholeContribsList!=null) {
wholeContribsList.map((contributor, index) => {
let commit_date = contributor['commit']['committer']['date'];
let check = withinThisMonthOrNot.within_this_month(commit_date, monthsInd);
let check = withinMonthsOrNot.within_months(commit_date, monthsInd);
if(check) {
contribs.push(contributor);
}
Expand Down Expand Up @@ -82630,7 +82629,7 @@ function fetchRecentMonthContribs(org, repo, queryTime) {
module.exports = {
fetchRecentMonthContribs: fetchRecentMonthContribs
}
},{"../../models/utils":405,"./freshFetch":417,"./queryTime":421,"./withinThisMonthOrNot":423,"./withinThisWeekOrNot":424}],417:[function(require,module,exports){
},{"../../models/utils":405,"./freshFetch":417,"./queryTime":421,"./withinMonthsOrNot":423}],417:[function(require,module,exports){
let model_utils = require('../../models/utils')
let monthsQuery = require('./queryTime')

Expand Down Expand Up @@ -82666,7 +82665,6 @@ function freshFetch(org, repo, queryTime) {

return Promise.all(proms)
.then(() => {
console.log("going in promise all of freshFetch");
// Save each repo's commits data to the database
let currTime = (new Date).getTime();
model_utils.setItem(`recent-${repo}-${monthsInd}-month-commits`, result);
Expand Down Expand Up @@ -82711,7 +82709,6 @@ function getContribsLastMonth(org, repo, forMonths) {
// We make queryTime 1 month behind the current time, to pass it as query in the request
let d = (new Date);
let temp = forMonths*30;
console.log('temp: ', temp);
d.setDate(d.getDate() - temp);
let queryTime = d.toISOString();
if(repo==='all') {
Expand All @@ -82723,7 +82720,6 @@ function getContribsLastMonth(org, repo, forMonths) {
else {
return fetchRecentMonthContribs.fetchRecentMonthContribs(org, repo, queryTime)
.then(function gotRecentCommitsInStorage(month_commits) {
console.log("getContribsLastMonth = ", month_commits)
return month_commits;
})
}
Expand Down Expand Up @@ -82806,7 +82802,7 @@ let storeAllRecentContribsInDb = require('./storeAllRecentContribsInDb')



function fetchContribsLastMonth(org, repo, forMonths=1) {
function fetchContribsLastMonth(org, repo, forMonths=6) {
return getContribsLastMonth.getContribsLastMonth(org, repo, forMonths)
.then((contribs) => {
return contribs;
Expand Down Expand Up @@ -82845,7 +82841,7 @@ function findMonthInd(queryTime) {
if (diff > 60e3) {
monthsBack = Math.floor((Math.floor(diff / 60e3))/(60*24*30));
}
console.log("monthsBack = ", monthsBack);

return monthsBack;
}

Expand Down Expand Up @@ -82903,7 +82899,7 @@ module.exports = {
},{"../../models/utils":405,"../repoUtil/fetchRepoUtil":425,"./fetchAllRecentMonthContribs":415}],423:[function(require,module,exports){
// Utility function that checks if a given date is behind the current date
// by 7 or less
function within_this_month(date, months) {
function within_months(date, months) {
let current = (new Date).getTime();
let past_date = (new Date(`${date}`)).getTime();
let measure = Math.ceil(Math.abs(current - past_date) / (1000*3600*24));
Expand All @@ -82917,7 +82913,7 @@ function within_this_month(date, months) {

// EXPORTS
module.exports = {
within_this_month: within_this_month
within_months: within_months
}
},{}],424:[function(require,module,exports){
// Utility function that checks if a given date is behind the current date
Expand Down
7 changes: 5 additions & 2 deletions examples/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ document.addEventListener('DOMContentLoaded', function () {

toolbox.initialize(org, repo).then((res)=> {
if(res) {
// Fetches and shows recent contributors' list
toolbox.showRecentContributors(org, repo, recencyLabel);
// compile and display all contributors for given org
toolbox.showAllContributors(org, repo);
toolbox.dropdownInit();
Expand All @@ -70,6 +72,7 @@ document.addEventListener('DOMContentLoaded', function () {

toolbox.initialize(org, repo).then((res)=> {
if(res) {
// Fetches and shows recent contributors' list
toolbox.showRecentContributors(org, repo, recencyLabel);
// compile and display all contributors for given repo
toolbox.showRepoContributors(org, repo);
Expand Down Expand Up @@ -115,11 +118,11 @@ document.addEventListener('DOMContentLoaded', function () {
toolbox.filter(org, 'mostrecentfirst');
})

$('.past').click((e) => {
$(".past").click((e) => {
e.preventDefault();
let timeSpan = e.target.textContent;
$('#dropdownMenuButtonRCS > #content').html(timeSpan);
let forMonths=1;
let forMonths = 6;
if(timeSpan.includes('Week')) {
timeSpan = 'week';
}else {
Expand Down
54 changes: 28 additions & 26 deletions examples/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
switcher.style.removeProperty('right');
switcher.style.removeProperty('background-color');
}
}, 1000)
}, 2000)


// Toggles the theme of the page
Expand Down Expand Up @@ -98,35 +98,37 @@
switcher.style.backgroundColor = '#34A7C1';

}
}, 500);
}, 300);
});


// Converts images' theme inside recent contributors section according to the mode selected
// every time the toggle button is clicked
$('.past').click((e) => {
e.preventDefault();
console.log("night mode adapt");
setTimeout(() => {
var recentContribsSectionImgs = document.getElementsByClassName('recent-contributors')[0].getElementsByTagName("img");
let check=localStorage.getItem('currentToggle');
let images = [...recentContribsSectionImgs ];
if(check==="night") {
buttonClickCallbackNightTheme = (e) => {
e.preventDefault();
setTimeout(() => {
var recentContribsSectionImgs = document.getElementsByClassName('recent-contributors')[0].getElementsByTagName("img");
let check=localStorage.getItem('currentToggle');
let images = [...recentContribsSectionImgs ];
if(check==="night") {
images.forEach((image) => {
image.style.filter = 'grayscale(1) invert(1)';
image.style.transitionProperty = 'filter';
image.style.transitionDuration = '0.5s';
image.style.transitionTimingFunction = 'linear';
})
}else {
images.forEach((image) => {
image.style.filter = 'grayscale(1) invert(1)';
image.style.transitionProperty = 'filter';
image.style.transitionDuration = '0.5s';
image.style.transitionTimingFunction = 'linear';
image.style.filter = 'grayscale(0) invert(0)';
image.style.transitionProperty = 'filter';
image.style.transitionDuration = '0.5s';
image.style.transitionTimingFunction = 'linear';
})
}else {
images.forEach((image) => {
image.style.filter = 'grayscale(0) invert(0)';
image.style.transitionProperty = 'filter';
image.style.transitionDuration = '0.5s';
image.style.transitionTimingFunction = 'linear';
})
}
}, 500);
})
}
}, 300);
}

// Converts images' theme inside recent contributors section according to the mode selected
// every time the toggle button is clicked
$('.past').click((e) => buttonClickCallbackNightTheme(e));
$('.sort-options').click((e) => buttonClickCallbackNightTheme(e));

})
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ <h2 class="recent-contributors-head">Recent Contributors</h2>
<strong>Sort <span><i class="fa fa-angle-down"></i></span></strong>
</div>
<div class="dropdown-menu" style="height: auto; width: auto;" aria-labelledby="dropdownMenuButtonRC">
<div id="alphabetic" style="width: auto; height: 2em; text-align: center; cursor: pointer;">
<div class="sort-options" id="alphabetic" style="width: auto; height: 2em; text-align: center; cursor: pointer;">
<p class="dropdown-item sort-items d-inline-block mx-auto">alphabetical</p>
</div>
<div id="mostrecentfirst" style="width: auto; height: 2em; text-align: center; cursor: pointer;">
<div class="sort-options" id="mostrecentfirst" style="width: auto; height: 2em; text-align: center; cursor: pointer;">
<p class="dropdown-item sort-items d-inline-block mx-auto">most recent first</p>
</div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/scripts/community-toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,23 @@ CommunityToolbox = function CommunityToolbox(org, repo) {


// Function for fetching and showing recent contributors
function showRecentContributors(org, repo, recencyLabel, forMonths=1) {
function showRecentContributors(org, repo, recencyLabel, forMonths=6) {
return recentContribsUtil.fetchAllRecentContribsInDb(org, repo).then((result)=>{
if(recencyLabel==="month") {
return recentContribsUtil.fetchContribsLastMonth(org, repo, forMonths)
.then(function gotCommits(commits) {
// Stores the CURRENTLY ACTIVE recent contribs data
.then(function gotMonthlyContribs(monthContribs) {
// Stores the CURRENTLY ACTIVE recent contribs data which is utilized by filter
model_utils.deleteItem('recent-contribs-data').then((res)=> {
model_utils.setItem('recent-contribs-data', commits);
model_utils.setItem('recent-contribs-data', monthContribs);
})
// Push data to UI
recentContributorsUI.insertRecentContributors(commits);
recentContributorsUI.insertRecentContributors(monthContribs);
return;
});
} else {
return recentContribsUtil.fetchContribsLastWeek(org, repo)
.then((weekly_contribs) => {
// Stores the CURRENTLY ACTIVE recent contribs data
// Stores the CURRENTLY ACTIVE recent contribs data which is utilized by filter
model_utils.deleteItem('recent-contribs-data').then((res)=> {
model_utils.setItem('recent-contribs-data', weekly_contribs);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function fetchAllRecentMonthContribs(org, repos, queryTime) {
let monthInd = monthsQuery.findMonthInd(queryTime);

// We take only 10 repos just for API quota reasons
let splicedRepos = repos.splice(0,1);
let splicedRepos = repos.splice(0,10);

let promises = splicedRepos.map(function mapToEachRepo(repo, i) {
return fetchRecentMonthContribs.fetchRecentMonthContribs(org, repo, queryTime)
Expand Down
5 changes: 2 additions & 3 deletions src/utils/recentContribsUtil/fetchRecentMonthContribs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
let model_utils = require('../../models/utils')
let monthsQuery = require('./queryTime')
let withinThisWeekOrNot = require('./withinThisWeekOrNot')
let withinThisMonthOrNot = require('./withinThisMonthOrNot')
let withinMonthsOrNot = require('./withinMonthsOrNot')
let freshFetch = require('./freshFetch')

// Fetches recent month commits for a particular repository
Expand All @@ -20,7 +19,7 @@ function fetchRecentMonthContribs(org, repo, queryTime) {
if(wholeContribsList!=undefined && wholeContribsList!=null) {
wholeContribsList.map((contributor, index) => {
let commit_date = contributor['commit']['committer']['date'];
let check = withinThisMonthOrNot.within_this_month(commit_date, monthsInd);
let check = withinMonthsOrNot.within_months(commit_date, monthsInd);
if(check) {
contribs.push(contributor);
}
Expand Down
1 change: 0 additions & 1 deletion src/utils/recentContribsUtil/freshFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function freshFetch(org, repo, queryTime) {

return Promise.all(proms)
.then(() => {
console.log("going in promise all of freshFetch");
// Save each repo's commits data to the database
let currTime = (new Date).getTime();
model_utils.setItem(`recent-${repo}-${monthsInd}-month-commits`, result);
Expand Down
2 changes: 0 additions & 2 deletions src/utils/recentContribsUtil/getContribsLastMonth.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function getContribsLastMonth(org, repo, forMonths) {
// We make queryTime 1 month behind the current time, to pass it as query in the request
let d = (new Date);
let temp = forMonths*30;
console.log('temp: ', temp);
d.setDate(d.getDate() - temp);
let queryTime = d.toISOString();
if(repo==='all') {
Expand All @@ -40,7 +39,6 @@ function getContribsLastMonth(org, repo, forMonths) {
else {
return fetchRecentMonthContribs.fetchRecentMonthContribs(org, repo, queryTime)
.then(function gotRecentCommitsInStorage(month_commits) {
console.log("getContribsLastMonth = ", month_commits)
return month_commits;
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/recentContribsUtil/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let storeAllRecentContribsInDb = require('./storeAllRecentContribsInDb')



function fetchContribsLastMonth(org, repo, forMonths=1) {
function fetchContribsLastMonth(org, repo, forMonths=6) {
return getContribsLastMonth.getContribsLastMonth(org, repo, forMonths)
.then((contribs) => {
return contribs;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/recentContribsUtil/queryTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function findMonthInd(queryTime) {
if (diff > 60e3) {
monthsBack = Math.floor((Math.floor(diff / 60e3))/(60*24*30));
}
console.log("monthsBack = ", monthsBack);

return monthsBack;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Utility function that checks if a given date is behind the current date
// by 7 or less
function within_this_month(date, months) {
function within_months(date, months) {
let current = (new Date).getTime();
let past_date = (new Date(`${date}`)).getTime();
let measure = Math.ceil(Math.abs(current - past_date) / (1000*3600*24));
Expand All @@ -14,5 +14,5 @@ function within_this_month(date, months) {

// EXPORTS
module.exports = {
within_this_month: within_this_month
within_months: within_months
}

0 comments on commit b355974

Please sign in to comment.