Skip to content

Commit 5af0524

Browse files
author
hkedia321
committed
add past week option
1 parent 418a291 commit 5af0524

File tree

3 files changed

+71
-9
lines changed

3 files changed

+71
-9
lines changed

src/popup.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ <h6 class="center">
3131
<input placeholder="Required for getting data from github" id="githubUsername" type="text">
3232
<label for="githubUsername">Your Github Username</label>
3333
</div>
34-
<div class="col s12"><span>Fetch your contributions between:</span></div>
34+
<div class="col s12"><span>Fetch your contributions between:</span>
35+
<input type="checkbox" class="filled-in" id="lastWeekContribution"/>
36+
<label for="lastWeekContribution">Show past 7 days from today</label>
37+
</div>
38+
3539
<div class="input-field col s6">
36-
<input placeholder="2017-10-30" id="startingDate" type="text" class="datepicker">
40+
<input id="startingDate" type="text" class="datepicker" placeholder=" ">
3741
<label for="startingDate">Starting Date</label>
3842
</div>
3943
<div class="input-field col s6">
40-
<input placeholder="2017-11-06" id="endingDate" type="text" class="datepicker">
44+
<input id="endingDate" type="text" class="datepicker" placeholder=" ">
4145
<label for="endingDate">Ending Date</label>
4246
</div>
4347
<div class="col s12"><span>Date should be in YYYY-MM-DD format</span></div>

src/scripts/main.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
/* global $,Materialize*/
12
var enableToggleElement = document.getElementById("enable");
23
var githubUsernameElement = document.getElementById("githubUsername");
4+
var lastWeekContributionElement=document.getElementById("lastWeekContribution");
35
var startingDateElement = document.getElementById("startingDate");
46
var endingDateElement = document.getElementById("endingDate");
57
var showOpenLabelElement = document.getElementById("showOpenLabel");
@@ -8,7 +10,7 @@ var userReasonElement = document.getElementById("userReason");
810

911
function handleBodyOnLoad(){
1012
// prefill name
11-
chrome.storage.local.get(["githubUsername","enableToggle","startingDate","endingDate","showOpenLabel","showClosedLabel","userReason"],function(items){
13+
chrome.storage.local.get(["githubUsername","enableToggle","startingDate","endingDate","showOpenLabel","showClosedLabel","userReason","lastWeekContribution"],function(items){
1214
if(items.githubUsername){
1315
githubUsernameElement.value=items.githubUsername;
1416
}
@@ -42,6 +44,14 @@ function handleBodyOnLoad(){
4244
if(items.userReason){
4345
userReasonElement.value = items.userReason;
4446
}
47+
if(items.lastWeekContribution){
48+
lastWeekContributionElement.checked=items.lastWeekContribution;
49+
handleLastWeekContributionChange();
50+
}
51+
else if(items.lastWeekContribution!==false){
52+
lastWeekContributionElement.checked=true;
53+
handleLastWeekContributionChange();
54+
}
4555
});
4656
}
4757
function handleEnableChange(){
@@ -56,6 +66,42 @@ function handleEndingDateChange(){
5666
var value = endingDateElement.value;
5767
chrome.storage.local.set({"endingDate": value});
5868
}
69+
function handleLastWeekContributionChange(){
70+
var value = lastWeekContributionElement.checked;
71+
if(value){
72+
startingDateElement.disabled=true;
73+
endingDateElement.disabled=true;
74+
endingDateElement.value=getToday();
75+
startingDateElement.value=getLastWeek();
76+
handleEndingDateChange();
77+
handleStartingDateChange();
78+
}
79+
else{
80+
startingDateElement.disabled=false;
81+
endingDateElement.disabled=false;
82+
}
83+
chrome.storage.local.set({"lastWeekContribution": value});
84+
}
85+
function getLastWeek(){
86+
var today = new Date();
87+
var lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
88+
var lastWeekMonth = lastWeek.getMonth() + 1;
89+
var lastWeekDay = lastWeek.getDate();
90+
var lastWeekYear = lastWeek.getFullYear();
91+
var lastWeekDisplayPadded =("0000" + lastWeekYear .toString()).slice(-4) +"-" + ("00" + lastWeekMonth.toString()).slice(-2)+ "-" + ("00" + lastWeekDay .toString()).slice(-2);
92+
return lastWeekDisplayPadded;
93+
}
94+
function getToday(){
95+
var today = new Date();
96+
var Week = new Date(today.getFullYear(), today.getMonth(), today.getDate());
97+
var WeekMonth = Week.getMonth() + 1;
98+
var WeekDay = Week.getDate();
99+
var WeekYear = Week.getFullYear();
100+
var WeekDisplayPadded =("0000" + WeekYear .toString()).slice(-4) +"-" + ("00" + WeekMonth.toString()).slice(-2)+ "-" + ("00" + WeekDay .toString()).slice(-2);
101+
return WeekDisplayPadded;
102+
}
103+
104+
59105
function handleGithubUsernameChange(){
60106
var value = githubUsernameElement.value;
61107
chrome.storage.local.set({"githubUsername": value});
@@ -82,6 +128,7 @@ enableToggleElement.addEventListener("change", handleEnableChange);
82128
githubUsernameElement.addEventListener("keyup", handleGithubUsernameChange);
83129
startingDateElement.addEventListener("keyup", handleStartingDateChange);
84130
endingDateElement.addEventListener("keyup", handleEndingDateChange);
131+
lastWeekContributionElement.addEventListener("change", handleLastWeekContributionChange);
85132
showOpenLabelElement.addEventListener("change", handleOpenLabelChange);
86133
showClosedLabelElement.addEventListener("change", handleClosedLabelChange);
87134
userReasonElement.addEventListener("keyup", handleUserReasonChange);

src/scripts/scrumHelper.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ chrome.storage.local.get(["githubUsername","enableToggle","startingDate","ending
5858

5959
// fetch github data
6060
function fetchGithubData(){
61-
var issueUrl="https://api.github.com/search/issues?q=author%3A"+githubUsername+"+org%3Afossasia+created%3A"+startingDate+".."+endingDate;
61+
var issueUrl="https://api.github.com/search/issues?q=author%3A"+githubUsername+"+org%3Afossasia+created%3A"+startingDate+".."+endingDate+"&per_page=100";
6262
$.ajax({
6363
dataType: "json",
6464
type: "GET",
@@ -71,7 +71,7 @@ function fetchGithubData(){
7171
}
7272
});
7373
// fetch github prs review data
74-
var prUrl="https://api.github.com/search/issues?q=commenter%3A"+githubUsername+"+org%3Afossasia+updated%3A"+startingDate+".."+endingDate;
74+
var prUrl="https://api.github.com/search/issues?q=commenter%3A"+githubUsername+"+org%3Afossasia+updated%3A"+startingDate+".."+endingDate+"&per_page=100";
7575
$.ajax({
7676
dataType: "json",
7777
type: "GET",
@@ -170,7 +170,8 @@ function writeGithubPrsReviews(){
170170
var obj={
171171
number:number,
172172
html_url:html_url,
173-
title:title
173+
title:title,
174+
state:item.state
174175
};
175176
githubPrsReviewDataProccessed[project].push(obj);
176177
}
@@ -186,7 +187,12 @@ function writeGithubPrsReviews(){
186187
for(var pr in githubPrsReviewDataProccessed[repo]){
187188
var pr_arr=githubPrsReviewDataProccessed[repo][pr];
188189
var prText="";
189-
prText+="<a href='"+pr_arr.html_url+"' target='_blank'>#"+pr_arr.number+"</a> ("+pr_arr.title+")";
190+
prText+="<a href='"+pr_arr.html_url+"' target='_blank'>#"+pr_arr.number+"</a> ("+pr_arr.title+") ";
191+
if(pr_arr.state==="open")
192+
prText+=issue_opened_button;
193+
else
194+
prText+=issue_closed_button;
195+
prText+="&nbsp;&nbsp;";
190196
repoLi+=prText;
191197
}
192198
}
@@ -195,7 +201,12 @@ function writeGithubPrsReviews(){
195201
for(var pr1 in githubPrsReviewDataProccessed[repo]){
196202
var pr_arr1=githubPrsReviewDataProccessed[repo][pr1];
197203
var prText1="";
198-
prText1+="<li><a href='"+pr_arr1.html_url+"' target='_blank'>#"+pr_arr1.number+"</a> ("+pr_arr1.title+")</li>";
204+
prText1+="<li><a href='"+pr_arr1.html_url+"' target='_blank'>#"+pr_arr1.number+"</a> ("+pr_arr1.title+") ";
205+
if(pr_arr1.state==="open")
206+
prText1+=issue_opened_button;
207+
else
208+
prText1+=issue_closed_button;
209+
prText1+="&nbsp;&nbsp;</li>";
199210
repoLi+=prText1;
200211
}
201212
repoLi+="</ul>";

0 commit comments

Comments
 (0)