Feature: Repository Monitor

Subscribe to be notified of database changes.
This commit is contained in:
Gary Sharp
2013-04-11 16:11:42 +10:00
parent b5531e64bd
commit 4869005c82
29 changed files with 657 additions and 216 deletions
+48 -4
View File
@@ -2,6 +2,7 @@
@{
Html.BundleDeferred("~/Style/Shadowbox");
Html.BundleDeferred("~/ClientScripts/Modules/Shadowbox");
Html.BundleDeferred("~/ClientScripts/Modules/jQuery-SignalR");
}
<table id="jobShowResources">
<tr>
@@ -21,6 +22,7 @@
</div>
<script type="text/javascript">
$(function () {
var jobId = parseInt('@(Model.Job.Id)');
$Comments = $('#Comments');
$CommentOutput = $Comments.find('.commentOutput');
$CommentOutputContainer = $Comments.find('.commentOutputContainer');
@@ -62,7 +64,8 @@
data: data,
success: function (d) {
if (d.Result == 'OK') {
addComment(d.Comment, false);
// Should be added via Repository Notifications
// addComment(d.Comment, false);
$CommentInput.val('').attr('disabled', false).focus();
} else {
alert('Unable to post comment: ' + d.Result);
@@ -91,9 +94,10 @@
data: data,
success: function (d) {
if (d == 'OK') {
$this.closest('div').slideUp(300).delay(300).queue(function () {
$(this).remove();
});
// Should be removed via Repository Notifications
//$this.closest('div').slideUp(300).delay(300).queue(function () {
// $(this).remove();
//});
} else {
alert('Unable to remove comment: ' + d);
}
@@ -114,6 +118,21 @@
return false;
}
function loadLiveComment(id) {
$.ajax({
url: '@Url.Action(MVC.API.Job.Comment())',
dataType: 'json',
data: { id: id },
success: function (d) {
if (d && d.JobId == jobId) {
addComment(d, false);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Unable to load live comment ' + id + ': ' + textStatus);
}
});
}
function addComment(c, quick) {
var e = $('<div><span class="author" /><span class="remove" /><span class="timestamp" /><span class="comment" /></div>');
e.attr('data-logid', c.Id);
@@ -134,6 +153,31 @@
$CommentOutput.animate({ scrollTop: $CommentOutput[0].scrollHeight }, 250)
}
}
// Sign up for Live Events
function liveMessageRecieved(d) {
if (d) {
switch (d.EventType) {
case 0: // Added
loadLiveComment(d.EntityKey[0]);
break;
case 1: // Removed
$CommentOutput.children('div[data-logid="' + d.EntityKey[0] + '"]').slideUp(300).delay(300).queue(function () {
$(this).remove();
});
break;
}
}
}
var liveMessagesConnection = $.connection('@(Url.Content("~/API/Repository/Notifications"))')
liveMessagesConnection.received(liveMessageRecieved);
liveMessagesConnection.error(function (e) {
alert('Error: ' + JSON.stringify(e));
});
liveMessagesConnection.start(function () {
liveMessagesConnection.send('/addToGroups:JobLog');
});
});
</script>
</td>