#145 add comments for devices
This commit is contained in:
@@ -2,8 +2,15 @@
|
||||
@using Disco.Services.Devices.DeviceFlags;
|
||||
@{
|
||||
ViewBag.Title = Html.ToBreadcrumb("Devices", MVC.Device.Index(), string.Format("Device: {0}", Model.Device.SerialNumber));
|
||||
|
||||
var requiresLive = Authorization.HasAny(Claims.Device.ShowComments, Claims.Device.ShowAttachments);
|
||||
|
||||
if (requiresLive)
|
||||
{
|
||||
Html.BundleDeferred("~/ClientScripts/Modules/jQuery-SignalR");
|
||||
}
|
||||
}
|
||||
<div id="Device_Show">
|
||||
<div id="Device_Show" data-deviceserialnumber="@Model.Device.SerialNumber">
|
||||
<div id="Device_Show_Status">
|
||||
<i class="fa fa-square deviceStatus @(Model.Device.StatusCode())"></i> @Model.Device.Status()
|
||||
<script type="text/javascript">
|
||||
@@ -93,9 +100,9 @@
|
||||
</script>
|
||||
<div id="DeviceDetailTabs">
|
||||
<ul id="DeviceDetailTabItems"></ul>
|
||||
@if (Authorization.Has(Claims.Device.ShowJobs))
|
||||
@if (Authorization.HasAny(Claims.Device.ShowComments, Claims.Device.ShowJobs))
|
||||
{
|
||||
@Html.Partial(MVC.Device.Views.DeviceParts._Jobs, Model)
|
||||
@Html.Partial(MVC.Device.Views.DeviceParts._CommentsAndJobs, Model)
|
||||
}
|
||||
@if (Authorization.Has(Claims.Device.ShowDetails))
|
||||
{
|
||||
@@ -118,4 +125,74 @@
|
||||
@Html.Partial(MVC.Device.Views.DeviceParts._Certificates, Model)
|
||||
}
|
||||
</div>
|
||||
@if (requiresLive)
|
||||
{
|
||||
<script>
|
||||
$(function () {
|
||||
if (!document.DiscoFunctions)
|
||||
return;
|
||||
|
||||
const deviceSerialNumber = $('#Device_Show').attr('data-deviceserialnumber');
|
||||
// Connect to Hub
|
||||
var hub = $.connection.deviceUpdates;
|
||||
|
||||
// Map Functions
|
||||
if (document.DiscoFunctions.onCommentAdded)
|
||||
hub.client.commentAdded = document.DiscoFunctions.onCommentAdded;
|
||||
if (document.DiscoFunctions.onCommentRemoved)
|
||||
hub.client.commentRemoved = document.DiscoFunctions.onCommentRemoved;
|
||||
if (document.DiscoFunctions.onAttachmentAdded)
|
||||
hub.client.attachmentAdded = document.DiscoFunctions.onAttachmentAdded;
|
||||
if (document.DiscoFunctions.onAttachmentRemoved)
|
||||
hub.client.attachmentRemoved = document.DiscoFunctions.onAttachmentRemoved;
|
||||
|
||||
$.connection.hub.qs = { DeviceSerialNumber: deviceSerialNumber };
|
||||
$.connection.hub.error(onHubFailed);
|
||||
$.connection.hub.disconnected(onHubFailed);
|
||||
|
||||
$.connection.hub.reconnecting(function () {
|
||||
$('#AttachmentsContainer').find('span.action.enabled').addClass('disabled');
|
||||
$('#Comments').find('button').prop('disabled', true);
|
||||
});
|
||||
$.connection.hub.reconnected(function () {
|
||||
$('#AttachmentsContainer').find('span.action.enabled').removeClass('disabled');
|
||||
$('#Comments').find('button').prop('disabled', false);
|
||||
});
|
||||
|
||||
// Start Connection
|
||||
$.connection.hub.start(function () {
|
||||
$('#AttachmentsContainer').find('span.action.enabled').removeClass('disabled');
|
||||
$('#Comments').find('button').prop('disabled', false);
|
||||
}).fail(onHubFailed);
|
||||
|
||||
function onHubFailed(error) {
|
||||
// Disable UI
|
||||
$('#AttachmentsContainer').find('span.action.enabled').addClass('disabled');
|
||||
$('#Comments').find('button').prop('disabled', true);
|
||||
|
||||
// Show Dialog Message
|
||||
if ($('.disconnected-dialog').length == 0) {
|
||||
$('<div>')
|
||||
.addClass('dialog disconnected-dialog')
|
||||
.html('<h3><span class="fa-stack fa-lg"><i class="fa fa-wifi fa-stack-1x"></i><i class="fa fa-ban fa-stack-2x error"></i></span>Disconnected from the Disco ICT Server</h3><div>This page is not receiving live updates. Please ensure you are connected to the server, then refresh this page to enable features.</div>')
|
||||
.dialog({
|
||||
resizable: false,
|
||||
title: 'Disconnected',
|
||||
width: 400,
|
||||
modal: true,
|
||||
buttons: {
|
||||
'Refresh Now': function () {
|
||||
$(this).dialog('option', 'buttons', null);
|
||||
window.location.reload(true);
|
||||
},
|
||||
'Close': function () {
|
||||
$(this).dialog('destroy');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user