Skip to content

Commit

Permalink
Merge pull request #54 from BertCotton/MyCompletedPRs
Browse files Browse the repository at this point in the history
My completed prs
  • Loading branch information
BertCotton authored Aug 31, 2017
2 parents ebbf47c + 34c2f6a commit d64850a
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 25 deletions.
5 changes: 4 additions & 1 deletion TfsAdvanced.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.15
VisualStudioVersion = 15.0.26730.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{28430696-29B7-46F4-9140-2EF000FB2D29}"
EndProject
Expand Down Expand Up @@ -53,4 +53,7 @@ Global
{23D45B3D-C188-48F3-9078-35B61B1F293D} = {28430696-29B7-46F4-9140-2EF000FB2D29}
{F88AE0D1-17B4-427E-8023-42A183EB05D3} = {28430696-29B7-46F4-9140-2EF000FB2D29}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {26745B40-C9AB-4327-8314-D7E3F85B161E}
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions src/TfsAdvanced.MessageBus/MessageBus.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>TfsAdvanced.MessageBus</AssemblyName>
<RootNamespace>TfsAdvanced.MessageBus</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.2.0" />
<PackageReference Include="ServiceConnect" Version="4.0.6" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/TfsAdvanced.MessageBus/MessageBusExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Autofac;
using ServiceConnect;
using ServiceConnect.Interfaces;

namespace TfsAdvanced.MessageBus
{
public static class MessageBusExtensions
{
public static void AddMessageBus(this ContainerBuilder builder)
{
var bus = Bus.Initialize();
builder.RegisterInstance(bus).As<IBus>();
}
}
}
13 changes: 13 additions & 0 deletions src/TfsAdvanced.MessageBus/MessageBuses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TfsAdvanced.MessageBus
{
public class MessageBuses
{
public static string NEW_MESSAGES = "NewMessage";
public static string UPDATED_MESSAGES = "UpdatedMEssages";

}
}
10 changes: 10 additions & 0 deletions src/TfsAdvanced.MessageBus/Messages/NewPullRequestMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TfsAdvanced.MessageBus.Messages
{
public class NewPullRequestMessage
{
}
}
14 changes: 14 additions & 0 deletions src/TfsAdvanced.MessageBus/Messages/UpdatedPullRequestMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using ServiceConnect.Interfaces;

namespace TfsAdvanced.MessageBus.Messages
{
public class UpdatedPullRequestMessage : Message
{
public UpdatedPullRequestMessage(Guid correlationId) : base(correlationId)
{
}
}
}
3 changes: 2 additions & 1 deletion src/TfsAdvanced/SocketConnections/ResponseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum ResponseType
UpdatedCurrentUserPullRequest,
UpdatedPullRequest,
NewPullRequest,
CurrentUserCompletedPullRequest
CurrentUserCompletedPullRequest,
NewCurrentUserCompletedPullRequest
}
}
30 changes: 22 additions & 8 deletions src/TfsAdvanced/SocketConnections/WebSocketUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private async Task SendNewPullRequests(WebSocket webSocket, IEnumerable<PullRequ
{
IDictionary<string, object> responseObject = new Dictionary<string, object>
{
{"Type", ResponseType.UpdatedPullRequest},
{"Type", ResponseType.NewPullRequest},
{"Data", newPullRequests}
};
await SendMessage(webSocket, responseObject);
Expand Down Expand Up @@ -134,17 +134,29 @@ private async Task SendPullRequestList(WebSocket webSocket, IEnumerable<PullRequ
}

private async Task HandleCompletedPullRequests(WebSocket webSocket, string currentUserUniqueName)
{
var repositoryLastUpdated = completedPullRequestRepository.GetLastUpdated();
{
var currentUserCompletedMessages = completedPullRequestRepository.GetAll().Where(x => x.Creator.UniqueName == currentUserUniqueName).ToList();
if (!currentUserCompletedMessages.Any())
return;

var repositoryLastUpdated = currentUserCompletedMessages.OrderByDescending(x => x.ClosedDate).First().ClosedDate;
if (!repositoryLastUpdated.HasValue)
return;

if (repositoryLastUpdated > lastCompletedPullRequestUpdated)
{
var currentUserCompletedMessages = completedPullRequestRepository.GetAll().Where(x => x.Creator.UniqueName == currentUserUniqueName);
await SendCompletedPullRequests(webSocket, currentUserCompletedMessages);
lastCompletedPullRequestUpdated = repositoryLastUpdated;
await SendCompletedPullRequests(webSocket, currentUserCompletedMessages, ResponseType.CurrentUserCompletedPullRequest);
// If this is the first time loading, don't send all the completed ones
if (lastCompletedPullRequestUpdated > DateTime.MinValue)
{
var newlyCompleted = currentUserCompletedMessages.Where(x => x.ClosedDate.HasValue && x.ClosedDate.Value > lastCompletedPullRequestUpdated);
await SendCompletedPullRequests(webSocket, newlyCompleted, ResponseType.NewCurrentUserCompletedPullRequest);
}
lastCompletedPullRequestUpdated = repositoryLastUpdated.Value;
}
}


private async Task SendMessage(WebSocket webSocket, IDictionary<string, object> message)
{
try
Expand All @@ -159,14 +171,16 @@ private async Task SendMessage(WebSocket webSocket, IDictionary<string, object>
}


private async Task SendCompletedPullRequests(WebSocket webSocket, IEnumerable<PullRequest> completedPullRequests)
private async Task SendCompletedPullRequests(WebSocket webSocket, IEnumerable<PullRequest> completedPullRequests, ResponseType responseType)
{
IDictionary<string, object> responseObject = new Dictionary<string, object>
{
{"Type", ResponseType.CurrentUserCompletedPullRequest},
{"Type", responseType},
{"Data", completedPullRequests}
};
await SendMessage(webSocket, responseObject);
}


}
}
Binary file added src/TfsAdvanced/wwwroot/images/thumbs-up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 28 additions & 4 deletions src/TfsAdvanced/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ <h2 class="text-center">TFS Advanced is Loading</h2>

var messageType = message["Type"];
var data = message["Data"];

localStorage.setItem("HasUpdate", "true");
console.log("Message Push. Type :", messageType, ", Count: ", data.length);
$("#brand").attr('title', "Last Server Response: " + new Date());
switch (messageType) {
Expand All @@ -148,22 +148,46 @@ <h2 class="text-center">TFS Advanced is Loading</h2>
break;
case "updatedCurrentUserPullRequest":
localStorage.setItem("CurrentUserPullRequests", JSON.stringify(data));
document.getElementById('mainPage').dispatchEvent(newMyPullRequestsEvent);
//window.dispatchEvent(newMyPullRequestsEvent);
break;
case "updatedPullRequest":
localStorage.setItem("PullRequests", JSON.stringify(data));
document.getElementById('mainPage').dispatchEvent(newPullRequestsEvent);
console.log("Updated pull requests");
//window.dispatchEvent(updatedPullRequestsEvent);
break;
case "currentUserCompletedPullRequest":
localStorage.setItem("CurrentUserCompletedPullRequests", JSON.stringify(data));
document.getElementById('mainPage').dispatchEvent(newCompletedPullRequestsEvent);
//window.dispatchEvent(newCompletedPullRequestsEvent);
break;
case "newCurrentUserCompletedPullRequest":
CurrentUserCompletedPullRequestNotificationToast(data);
break;
}

};

});

function CurrentUserCompletedPullRequestNotificationToast(pullRequests) {
$.each(pullRequests,
function(index, pullRequest) {
var notification = new Notification('Your Pull Request Was Completed!',
{
icon: '/images/thumbs-up.png',
body: pullRequest.Repository.Name + " | " + pullRequest.Title

});

notification.onclick = function (event) {
event.preventDefault();
window.open(pullRequest.Url, '_blank');
notification.close().bind(notification);
};


});
}

function NotificationToast(pullRequests) {
$.each(pullRequests,
function(index, pullRequest) {
Expand Down
25 changes: 14 additions & 11 deletions src/TfsAdvanced/wwwroot/js/pullRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ $("#myCompletedPullRequestPanel").on("click",
});

function fetchData() {

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

formatPage();
if (localStorage.getItem("HasUpdate") === "true") {
HandlMyPullRequests();
HandleTeamPullRequests();
HandleMyCompletedPullRequests();

formatPage();
//window.addEventListener(updatedPullRequestsEvent, HandleTeamPullRequests, false);
//window.addEventListener(newCompletedPullRequestsEvent, HandleMyCompletedPullRequests, false);
//window.addEventListener(newMyPullRequestsEvent, HandlMyPullRequests, false);
localStorage.setItem("HasUpdate", "false");
}
window.setTimeout(fetchData, 500);

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

}

function HandlMyPullRequests() {

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

if (!myPullRequests)
Expand All @@ -34,7 +37,7 @@ function HandlMyPullRequests() {
}
}

function HandleTeamPullRequests() {
function HandleTeamPullRequests(event) {
var pullRequests = JSON.parse(localStorage.getItem("PullRequests"));
if(!pullRequests)
return;
Expand Down

0 comments on commit d64850a

Please sign in to comment.