Skip to content

Commit

Permalink
Merge pull request #53 from BertCotton/javascriptEvent
Browse files Browse the repository at this point in the history
The pull requests are now updated when the event is fired not on a po…
  • Loading branch information
BertCotton authored Aug 31, 2017
2 parents 1a452a0 + bd5131f commit ebbf47c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/TfsAdvanced/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</head>
<body ng-controller="MainController">
<nav class="navbar navbar-fixed-top navbar-dark bg-inverse" ng-controller="NavController">
<span class="navbar-brand nav-link">TFS Advanced</span>
<span class="navbar-brand nav-link" id="brand">TFS Advanced</span>
<ul class="nav navbar-nav hidden-xs" style="display: none">
<li>
<a id="pullRequestLink" class="nav-link" onclick="navigateTo(this, '/views/pullRequests.html')">Pull Requests</a>
Expand All @@ -36,9 +36,6 @@
</li>
</ul>
</li>
<li>
<div id="socketStatus" ></div>
</li>
</ul>
</nav>
<div style="margin-top: 52px" id="mainPage">
Expand Down Expand Up @@ -144,19 +141,23 @@ <h2 class="text-center">TFS Advanced is Loading</h2>
var data = message["Data"];

console.log("Message Push. Type :", messageType, ", Count: ", data.length);

$("#brand").attr('title', "Last Server Response: " + new Date());
switch (messageType) {
case "newPullRequest":
NotificationToast(data);
break;
case "updatedCurrentUserPullRequest":
localStorage.setItem("CurrentUserPullRequests", JSON.stringify(data));
document.getElementById('mainPage').dispatchEvent(newMyPullRequestsEvent);
break;
case "updatedPullRequest":
localStorage.setItem("PullRequests", JSON.stringify(data));
document.getElementById('mainPage').dispatchEvent(newPullRequestsEvent);
break;
case "currentUserCompletedPullRequest":
localStorage.setItem("CurrentUserCompletedPullRequests", JSON.stringify(data));
document.getElementById('mainPage').dispatchEvent(newCompletedPullRequestsEvent);
break;
}

};
Expand All @@ -166,7 +167,7 @@ <h2 class="text-center">TFS Advanced is Loading</h2>
function NotificationToast(pullRequests) {
$.each(pullRequests,
function(index, pullRequest) {

console.log("New PullRequest: ", pullRequest);
var notification = new Notification('New Pull Request from ' + pullRequest.Creator.Name,
{
icon: '/images/site.png',
Expand Down
7 changes: 6 additions & 1 deletion src/TfsAdvanced/wwwroot/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
$(".datetime-shorttime").each(function (idx, elem) {
$(elem).text($.format.date($(elem).text(), "MMMM dd h:mm a"));
});
}
}

var newPullRequestsEvent = new Event('NewPullRequests');
var updatedPullRequestsEvent = new Event("UpdatedPullRequests");
var newCompletedPullRequestsEvent = new Event("NewCompletedPullRequests");
var newMyPullRequestsEvent = new Event("NewMyPullRequests");
28 changes: 15 additions & 13 deletions src/TfsAdvanced/wwwroot/js/pullRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ $("#myCompletedPullRequestPanel").on("click",
});

function fetchData() {
var pullRequests = JSON.parse(localStorage.getItem("PullRequests"));
var myPullRequests = JSON.parse(localStorage.getItem("CurrentUserPullRequests"));
var myCompletedPullRequests = JSON.parse(localStorage.getItem("CurrentUserCompletedPullRequests"));

HandlMyPullRequests(myPullRequests);
HandleTeamPullRequests(pullRequests);
HandleMyCompletedPullRequests(myCompletedPullRequests);


HandlMyPullRequests();
HandleTeamPullRequests();
HandleMyCompletedPullRequests();

formatPage();
window.setTimeout(fetchData, 1000);

document.getElementById("mainPage").addEventListener(updatedPullRequestsEvent, HandleTeamPullRequests, false);
document.getElementById("mainPage").addEventListener(newCompletedPullRequestsEvent, HandleMyCompletedPullRequests, false);
document.getElementById("mainPage").addEventListener(newMyPullRequestsEvent, HandlMyPullRequests, false);

}

function HandlMyPullRequests(myPullRequests) {
function HandlMyPullRequests() {
var myPullRequests = JSON.parse(localStorage.getItem("CurrentUserPullRequests"));

if (!myPullRequests)
return;
Expand All @@ -33,8 +34,8 @@ function HandlMyPullRequests(myPullRequests) {
}
}

function HandleTeamPullRequests(pullRequests) {

function HandleTeamPullRequests() {
var pullRequests = JSON.parse(localStorage.getItem("PullRequests"));
if(!pullRequests)
return;
if (pullRequests.length === 0) {
Expand Down Expand Up @@ -66,7 +67,8 @@ function sortByDate(pullRequests, reverse = false) {
});
}

function HandleMyCompletedPullRequests(pullRequests) {
function HandleMyCompletedPullRequests() {
var pullRequests = JSON.parse(localStorage.getItem("CurrentUserCompletedPullRequests"));
if(!pullRequests)
return;
else if (pullRequests.length === 0) {
Expand Down

0 comments on commit ebbf47c

Please sign in to comment.