Files
Disco/Disco.Web/Views/User/Show.cshtml
T
2025-08-09 16:17:10 +10:00

170 lines
7.5 KiB
Plaintext

@model Disco.Web.Models.User.ShowModel
@using Disco.Services.Users.UserFlags;
@{
Authorization.Require(Claims.User.Show);
ViewBag.Title = Html.ToBreadcrumb("Users", MVC.User.Index(), string.Format("User: {0} ({1})", Model.User.DisplayName, Model.User.FriendlyId()));
var requiresLive = Authorization.HasAny(Claims.User.ShowComments, Claims.User.ShowAttachments);
if (requiresLive)
{
Html.BundleDeferred("~/ClientScripts/Modules/jQuery-SignalR");
}
}
<div id="User_Show" data-userid="@Model.User.UserId">
@if (Model.User.UserFlagAssignments.CanShowAny())
{
<div id="User_Show_Flags">
@foreach (var flag in Model.User.UserFlagAssignments.Where(f => !f.RemovedDate.HasValue).Select(f => Tuple.Create(f, UserFlagService.GetUserFlag(f.UserFlagId))))
{
if (flag.Item2.permission.CanShow())
{
<i class="flag fa fa-@(flag.Item2.flag.Icon) fa-fw fa-lg d-@(flag.Item2.flag.IconColour)">
<span class="details">
<span class="name">@flag.Item2.flag.Name</span>@if (flag.Item1.Comments != null)
{<span class="comments">@flag.Item1.Comments.ToHtmlComment()</span>}<span class="added">@CommonHelpers.FriendlyDateAndUser(flag.Item1.AddedDate, flag.Item1.AddedUser)</span>
</span>
</i>
}
}
</div>
<script type="text/javascript">
$(function () {
$('#User_Show_Flags')
.appendTo('#layout_PageHeading')
.tooltip({
items: 'i.flag',
content: function () {
var $this = $(this);
return $this.children('.details').html();
},
tooltipClass: 'FlagAssignment_Tooltip',
position: {
my: "right top",
at: "right bottom",
collision: "flipfit flip"
},
hade: {
effect: ''
},
close: function (e, ui) {
ui.tooltip.hover(
function () {
$(this).stop(true).fadeTo(100, 1);
},
function () {
$(this).fadeOut(100, function () { $(this).remove(); });
});
}
});
});
</script>
}
@Html.Partial(MVC.User.Views.UserParts._Subject, Model)
<script type="text/javascript">
$(function () {
var $tabs = $('#UserDetailTabs');
if ($tabs.children().length > 1) {
$tabs.tabs({
activate: function (event, ui) {
window.setTimeout(function () {
var $window = $(window);
var tabHeight = $tabs.height();
var tabOffset = $tabs.offset();
var windowScrollTop = $window.scrollTop();
var windowHeight = $window.height();
var tabTopNotShown = windowScrollTop - tabOffset.top;
if (tabTopNotShown > 0) {
$('html').animate({ scrollTop: tabOffset.top }, 125);
} else {
var tabBottomNotShown = ((windowScrollTop + windowHeight) - (tabHeight + tabOffset.top)) * -1;
if (tabBottomNotShown > 0) {
if (tabHeight > windowHeight)
$('html').animate({ scrollTop: tabOffset.top }, 125);
else
$('html').animate({ scrollTop: windowScrollTop + tabBottomNotShown }, 125);
}
}
}, 1);
}
});
} else {
$tabs.hide();
}
});
</script>
<div id="UserDetailTabs">
<ul id="UserDetailTabItems"></ul>
@if (Authorization.HasAny(Claims.User.ShowComments, Claims.User.ShowJobs))
{
@Html.Partial(MVC.User.Views.UserParts._CommentsAndJobs, Model)
}
@if (Authorization.Has(Claims.User.ShowAssignmentHistory))
{
@Html.Partial(MVC.User.Views.UserParts._AssignmentHistory, Model)
}
@if (Authorization.Has(Claims.User.ShowAttachments))
{
@Html.Partial(MVC.User.Views.UserParts._Resources, Model)
}
@if (Authorization.Has(Claims.User.ShowFlagAssignments) || Model.User.UserFlagAssignments.CanShowAny())
{
@Html.Partial(MVC.User.Views.UserParts._Flags, Model)
}
@if (Authorization.Has(Claims.User.ShowAuthorization))
{
@Html.Partial(MVC.User.Views.UserParts._Authorization, Model)
}
</div>
@if (requiresLive)
{
<script>
$(function () {
if (!document.DiscoFunctions)
return;
const userId = $('#User_Show').attr('data-userid');
// Connect to Hub
var hub = $.connection.userUpdates;
// 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 = { UserId: userId };
$.connection.hub.error(function (error) {
console.log('Server connection error: ' + error);
});
$.connection.hub.disconnected(function () {
// Disable UI
$('#AttachmentsContainer').find('span.action.enabled').addClass('disabled');
$('#Comments').find('button').prop('disabled', true);
});
$.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);
});
});
</script>
}
</div>