From 75378400e78851b43f9e70dcac86053045d70d16 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sun, 4 Aug 2019 17:06:07 -0500 Subject: [PATCH] Add flag icon on client profile --- .../Views/Stats/_MessageContext.cshtml | 9 ++- SharedLibraryCore/Services/ClientService.cs | 2 +- SharedLibraryCore/Utilities.cs | 2 +- WebfrontCore/Controllers/ActionController.cs | 73 ++++++++++++++++++- WebfrontCore/ViewModels/ActionInfo.cs | 1 + WebfrontCore/Views/Action/_ActionForm.cshtml | 2 +- .../Views/Client/Profile/Index.cshtml | 4 + .../Views/Server/_ClientActivity.cshtml | 29 ++++++-- WebfrontCore/wwwroot/css/main.scss | 2 +- WebfrontCore/wwwroot/js/action.js | 13 ++++ WebfrontCore/wwwroot/js/loader.js | 22 +++--- WebfrontCore/wwwroot/js/server.js | 2 +- WebfrontCore/wwwroot/js/stats.js | 11 +-- version.txt | 1 + 14 files changed, 143 insertions(+), 30 deletions(-) diff --git a/Plugins/Web/StatsWeb/Views/Stats/_MessageContext.cshtml b/Plugins/Web/StatsWeb/Views/Stats/_MessageContext.cshtml index 34ae40317..476885a55 100644 --- a/Plugins/Web/StatsWeb/Views/Stats/_MessageContext.cshtml +++ b/Plugins/Web/StatsWeb/Views/Stats/_MessageContext.cshtml @@ -8,7 +8,14 @@
@foreach (var message in Model) { - @message.Name@message.Message
+ @message.Name + + — + + + + +
}
\ No newline at end of file diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index 77d0525dc..7b1ac4afd 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -581,7 +581,7 @@ namespace SharedLibraryCore.Services ClientId = _client.ClientId, Name = _client.CurrentAlias.Name, IPAddress = _client.CurrentAlias.IPAddress.ConvertIPtoString(), - LastConnection = _client.LastConnection + LastConnection = _client.FirstConnection }) .OrderByDescending(_client => _client.ClientId) .Take(10); diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index 4568467f8..f3d23735d 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -154,7 +154,7 @@ namespace SharedLibraryCore /// /// /// - public static string FixIW4ForwardSlash(this string str) => Regex.Match(str, @"(^\/+.*$)|(^.*\/+$)").Value.Replace("/", " /"); + public static string FixIW4ForwardSlash(this string str) => str.Replace("/", " /"); /// /// Get the IW Engine color code corresponding to an admin level diff --git a/WebfrontCore/Controllers/ActionController.cs b/WebfrontCore/Controllers/ActionController.cs index 59ecbacb6..6fe30377a 100644 --- a/WebfrontCore/Controllers/ActionController.cs +++ b/WebfrontCore/Controllers/ActionController.cs @@ -41,7 +41,8 @@ namespace WebfrontCore.Controllers } } }, - Action = "BanAsync" + Action = "BanAsync", + ShouldRefresh = true }; return View("_ActionForm", info); @@ -99,7 +100,8 @@ namespace WebfrontCore.Controllers Label = Localization["WEBFRONT_ACTION_LABEL_REASON"], } }, - Action = "UnbanAsync" + Action = "UnbanAsync", + ShouldRefresh = true }; return View("_ActionForm", info); @@ -167,7 +169,8 @@ namespace WebfrontCore.Controllers .ToDictionary(p => p.ToString(), p=> p.ToLocalizedLevelName()) }, }, - Action = "EditAsync" + Action = "EditAsync", + ShouldRefresh = true }; return View("_ActionForm", info); @@ -247,5 +250,69 @@ namespace WebfrontCore.Controllers var clients = await Manager.GetClientService().GetRecentClients(); return View("~/Views/Shared/Components/Client/_RecentClients.cshtml", clients); } + + public IActionResult FlagForm() + { + var info = new ActionInfo() + { + ActionButtonLabel = Localization["WEBFRONT_ACTION_FLAG_NAME"], + Name = "Flag", + Inputs = new List() + { + new InputInfo() + { + Name = "reason", + Label = Localization["WEBFRONT_ACTION_LABEL_REASON"], + } + }, + Action = "FlagAsync", + ShouldRefresh = true + }; + + return View("_ActionForm", info); + } + + public async Task FlagAsync(int targetId, string reason) + { + var server = Manager.GetServers().First(); + + return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new + { + serverId = server.EndPoint, + command = $"!flag @{targetId} {reason}" + })); + } + + public IActionResult UnflagForm() + { + var info = new ActionInfo() + { + ActionButtonLabel = Localization["WEBFRONT_ACTION_UNFLAG_NAME"], + Name = "Unflag", + Inputs = new List() + { + new InputInfo() + { + Name = "reason", + Label = Localization["WEBFRONT_ACTION_LABEL_REASON"], + } + }, + Action = "UnflagAsync", + ShouldRefresh = true + }; + + return View("_ActionForm", info); + } + + public async Task UnflagAsync(int targetId, string reason) + { + var server = Manager.GetServers().First(); + + return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new + { + serverId = server.EndPoint, + command = $"!unflag @{targetId} {reason}" + })); + } } } diff --git a/WebfrontCore/ViewModels/ActionInfo.cs b/WebfrontCore/ViewModels/ActionInfo.cs index fd7bac379..6e3da2ab5 100644 --- a/WebfrontCore/ViewModels/ActionInfo.cs +++ b/WebfrontCore/ViewModels/ActionInfo.cs @@ -11,5 +11,6 @@ namespace WebfrontCore.ViewModels public List Inputs { get; set; } public string ActionButtonLabel { get; set; } public string Action { get; set; } + public bool ShouldRefresh { get; set; } } } diff --git a/WebfrontCore/Views/Action/_ActionForm.cshtml b/WebfrontCore/Views/Action/_ActionForm.cshtml index bd5db4dc4..cc9ea9553 100644 --- a/WebfrontCore/Views/Action/_ActionForm.cshtml +++ b/WebfrontCore/Views/Action/_ActionForm.cshtml @@ -2,7 +2,7 @@ @{ Layout = null; } -
+ @foreach (var input in Model.Inputs) { string inputType = input.Type ?? "text"; diff --git a/WebfrontCore/Views/Client/Profile/Index.cshtml b/WebfrontCore/Views/Client/Profile/Index.cshtml index e43e3d239..a564d868d 100644 --- a/WebfrontCore/Views/Client/Profile/Index.cshtml +++ b/WebfrontCore/Views/Client/Profile/Index.cshtml @@ -5,6 +5,7 @@ var loc = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex; string gravatarUrl = Model.Meta.FirstOrDefault(m => m.Key == "GravatarEmail")?.Value; bool isTempBanned = Model.ActivePenaltyType == "TempBan"; + bool isFlagged = Model.LevelInt == (int)SharedLibraryCore.Database.Models.EFClient.Permission.Flagged; var informationMeta = Model.Meta .Where(_meta => _meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Information) .OrderBy(_meta => _meta.Order) @@ -56,6 +57,8 @@ @if (ViewBag.Authorized) {
+ + @if (Model.LevelInt < (int)ViewBag.User.Level && !Model.HasActivePenalty) { @@ -74,6 +77,7 @@ } } + @if (Model.LevelInt != -1) { diff --git a/WebfrontCore/Views/Server/_ClientActivity.cshtml b/WebfrontCore/Views/Server/_ClientActivity.cshtml index 5e8e355d0..558f2c742 100644 --- a/WebfrontCore/Views/Server/_ClientActivity.cshtml +++ b/WebfrontCore/Views/Server/_ClientActivity.cshtml @@ -17,15 +17,27 @@ if (Model.ChatHistory[i].Message == "CONNECTED") { - @Model.ChatHistory[i].Name
+ + + +
} if (Model.ChatHistory[i].Message == "DISCONNECTED") { - @Model.ChatHistory[i].Name
+ + + +
} if (Model.ChatHistory[i].Message != "CONNECTED" && Model.ChatHistory[i].Message != "DISCONNECTED") { - @Model.ChatHistory[i].Name — @Model.ChatHistory[i].Message.Substring(0, Math.Min(65, Model.ChatHistory[i].Message.Length))
+ + + + + — + +
} } } @@ -83,12 +95,17 @@ if (Model.ChatHistory[i].Message == "CONNECTED") { - @Model.ChatHistory[i].Name
+ + + +
} if (Model.ChatHistory[i].Message == "DISCONNECTED") { - - @Model.ChatHistory[i].Name
+ + + +
} if (Model.ChatHistory[i].Message != "CONNECTED" && Model.ChatHistory[i].Message != "DISCONNECTED") { diff --git a/WebfrontCore/wwwroot/css/main.scss b/WebfrontCore/wwwroot/css/main.scss index d04b78dae..73e8156e5 100644 --- a/WebfrontCore/wwwroot/css/main.scss +++ b/WebfrontCore/wwwroot/css/main.scss @@ -302,7 +302,7 @@ form *, select { } .text-color-code-58 { - animation: color-change 60s infinite; + animation: color-change 54s infinite; } @keyframes color-change { diff --git a/WebfrontCore/wwwroot/js/action.js b/WebfrontCore/wwwroot/js/action.js index 857847de5..d0061e95a 100644 --- a/WebfrontCore/wwwroot/js/action.js +++ b/WebfrontCore/wwwroot/js/action.js @@ -42,6 +42,7 @@ $(document).ready(function () { $('#actionModal').trigger('action_form_received', actionType); }) .fail(function (jqxhr, textStatus, error) { + $('#actionModal .modal-body-content').html(''); $('#actionModal .modal-message').text('Error — ' + error); $('#actionModal').modal(); $('#actionModal .modal-message').fadeIn('fast'); @@ -54,6 +55,7 @@ $(document).ready(function () { $(document).on('submit', '.action-form', function (e) { e.preventDefault(); $(this).append($('#target_id input')); + $('#actionModal').data('should-refresh', $('#actionModal').find('.refreshable').length !== 0); const data = $(this).serialize(); showLoader(); $.get($(this).attr('action') + '/?' + data) @@ -102,4 +104,15 @@ $(document).ready(function () { }); } }); + + /* + * handle close event to refresh if need be + */ + $("#actionModal").on("hidden.bs.modal", function () { + let shouldRefresh = $(this).data('should-refresh'); + + if (shouldRefresh !== undefined && shouldRefresh) { + location.reload(); + } + }); }); \ No newline at end of file diff --git a/WebfrontCore/wwwroot/js/loader.js b/WebfrontCore/wwwroot/js/loader.js index aa7610e0c..f8f26769f 100644 --- a/WebfrontCore/wwwroot/js/loader.js +++ b/WebfrontCore/wwwroot/js/loader.js @@ -41,9 +41,19 @@ function loadMoreItems() { loaderOffset += loadCount; } +var hasScrollBar = false; + function _ScrollHandler(e) { //throttle event: + /* + https://stackoverflow.com/questions/3898130/check-if-a-user-has-scrolled-to-the-bottom + */ + var $window = $(window); + var $document = $(document); hasScrollBar = true; + let _throttleTimer = null; + let _throttleDelay = 100; + clearTimeout(_throttleTimer); _throttleTimer = setTimeout(function () { @@ -69,18 +79,10 @@ function setupListeners() { } }); - /* - https://stackoverflow.com/questions/3898130/check-if-a-user-has-scrolled-to-the-bottom - */ - var _throttleTimer = null; - var _throttleDelay = 100; - var $window = $(window); - var $document = $(document); - var hasScrollBar = false; - $document.ready(function () { - $window + $(document).ready(function () { + $(window) .off('scroll', _ScrollHandler) .on('scroll', _ScrollHandler); $('.loader-load-more:not(.disabled)').click(function (e) { diff --git a/WebfrontCore/wwwroot/js/server.js b/WebfrontCore/wwwroot/js/server.js index 913cd5634..187566edc 100644 --- a/WebfrontCore/wwwroot/js/server.js +++ b/WebfrontCore/wwwroot/js/server.js @@ -80,7 +80,7 @@ function refreshClientActivity() { cache: false }) .done(function (response) { - const clientCount = $(response).find('.col-6 span').length; + const clientCount = $(response).find('a').length; $('#server_header_' + serverId + ' .server-clientcount').text(clientCount); $('#server_clientactivity_' + serverId).html(response); }) diff --git a/WebfrontCore/wwwroot/js/stats.js b/WebfrontCore/wwwroot/js/stats.js index 71714b33c..85b6ac653 100644 --- a/WebfrontCore/wwwroot/js/stats.js +++ b/WebfrontCore/wwwroot/js/stats.js @@ -20,7 +20,7 @@ if (interval < 1) interval = 1; - let primaryColor = window.getComputedStyle(document.body).getPropertyValue('--primary').trim(); + //let primaryColor = $('.nav-tabs .nav-link.active').first().css('background-color') return new CanvasJS.Chart(id, { backgroundColor: 'transparent', @@ -56,10 +56,11 @@ dockInsidePlotArea: true }, data: [{ - type: 'splineArea', - color: primaryColor.endsWith('80') ? primaryColor : primaryColor + '40', - markerSize: 3.5, - dataPoints: fixedData + type: 'spline', + color: '#c0c0c0', + markerSize: 0, + dataPoints: fixedData, + lineThickness: 2 }] }); } diff --git a/version.txt b/version.txt index c6f222934..62a76413d 100644 --- a/version.txt +++ b/version.txt @@ -4,6 +4,7 @@ Version 2.4: -added recently connected players dropdown option on webfront -added "dashboard" to home view with quick stats -added ability to customize accent color and branding on webfront +-added flag button to client profile -hid flagged status of users on webfront unless logged in Version 2.3: