From 8521df85f56252f988bfbef7f6de8ed8a33887bf Mon Sep 17 00:00:00 2001 From: RaidMax Date: Fri, 29 Mar 2019 21:56:56 -0500 Subject: [PATCH] finish initial rework of profile page with meta pagination --- Application/Application.csproj | 4 +- Application/ApplicationManager.cs | 81 ++++++++++++++---- Plugins/Stats/Plugin.cs | 13 +-- SharedLibraryCore/Dtos/PlayerInfo.cs | 4 - SharedLibraryCore/Dtos/ProfileMeta.cs | 4 +- SharedLibraryCore/Services/MetaService.cs | 18 ++-- SharedLibraryCore/Services/PenaltyService.cs | 18 ++++ WebfrontCore/Controllers/BaseController.cs | 4 +- WebfrontCore/Controllers/ClientController.cs | 61 ++----------- .../ProfileMetaListViewComponent.cs | 5 +- .../Views/Client/Profile/Index.cshtml | 5 +- .../Components/ProfileMetaList/_List.cshtml | 56 ++++++++++-- WebfrontCore/wwwroot/css/bootstrap-custom.css | 3 + .../wwwroot/css/bootstrap-custom.scss | 4 + WebfrontCore/wwwroot/js/loader.js | 85 ++++++++++--------- WebfrontCore/wwwroot/js/profile.js | 2 + 16 files changed, 227 insertions(+), 140 deletions(-) diff --git a/Application/Application.csproj b/Application/Application.csproj index 99421ecbe..f44efd9fb 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -6,7 +6,7 @@ 2.2.2 false RaidMax.IW4MAdmin.Application - 2.2.5.8 + 2.2.5.9 RaidMax Forever None IW4MAdmin @@ -31,7 +31,7 @@ true true - 2.2.5.8 + 2.2.5.9 2.2.5.8 diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index b120c55d1..7d0943ff0 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -12,6 +12,7 @@ using SharedLibraryCore.Events; using SharedLibraryCore.Exceptions; using SharedLibraryCore.Helpers; using SharedLibraryCore.Interfaces; +using SharedLibraryCore.Objects; using SharedLibraryCore.Services; using System; using System.Collections.Generic; @@ -388,7 +389,7 @@ namespace IW4MAdmin.Application #endregion #region META - async Task> getProfileMeta(int clientId, int offset, int count) + async Task> getProfileMeta(int clientId, int offset, int count, DateTime? startAt) { var metaList = new List(); @@ -400,25 +401,31 @@ namespace IW4MAdmin.Application var lastMapMeta = await _metaService.GetPersistentMeta("LastMapPlayed", new EFClient() { ClientId = clientId }); - metaList.Add(new ProfileMeta() + if (lastMapMeta != null) { - Id = lastMapMeta.MetaId, - Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_MAP"], - Value = lastMapMeta.Value, - Show = true, - Type = ProfileMeta.MetaType.Information - }); + metaList.Add(new ProfileMeta() + { + Id = lastMapMeta.MetaId, + Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_MAP"], + Value = lastMapMeta.Value, + Show = true, + Type = ProfileMeta.MetaType.Information + }); + } var lastServerMeta = await _metaService.GetPersistentMeta("LastServerPlayed", new EFClient() { ClientId = clientId }); - metaList.Add(new ProfileMeta() + if (lastServerMeta != null) { - Id = lastServerMeta.MetaId, - Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_SERVER"], - Value = lastServerMeta.Value, - Show = true, - Type = ProfileMeta.MetaType.Information - }); + metaList.Add(new ProfileMeta() + { + Id = lastServerMeta.MetaId, + Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_SERVER"], + Value = lastServerMeta.Value, + Show = true, + Type = ProfileMeta.MetaType.Information + }); + } var client = await GetClientService().Get(clientId); @@ -450,6 +457,7 @@ namespace IW4MAdmin.Application }); metaList.Add(new ProfileMeta() + { Id = client.ClientId, Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_CONNECTIONS"], @@ -458,10 +466,51 @@ namespace IW4MAdmin.Application Type = ProfileMeta.MetaType.Information }); + metaList.Add(new ProfileMeta() + { + Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_MASKED"], + Value = client.Masked ? Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_TRUE"] : Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_FALSE"], + Sensitive = true, + Type = ProfileMeta.MetaType.Information + }); + return metaList; - }; + } + + async Task> getPenaltyMeta(int clientId, int offset, int count, DateTime? startAt) + { + if (count <= 1) + { + return new List(); + } + + var penalties = await GetPenaltyService().GetAllClientPenaltiesAsync(clientId, count, offset, startAt); + + return penalties.Select(_penalty => new ProfileMeta() + { + Id = _penalty.PenaltyId, + Type = _penalty.PunisherId == clientId ? ProfileMeta.MetaType.Penalized : ProfileMeta.MetaType.ReceivedPenalty, + Value = new PenaltyInfo + { + Id = _penalty.PenaltyId, + OffenderName = _penalty.Offender.Name, + OffenderId = _penalty.OffenderId, + PunisherName = _penalty.Punisher.Name, + PunisherId = _penalty.PunisherId, + Offense = _penalty.Offense, + PenaltyType = _penalty.Type.ToString(), + TimeRemaining = _penalty.Expires.HasValue ? (DateTime.Now > _penalty.Expires ? "" : _penalty.Expires.ToString()) : DateTime.MaxValue.ToString(), + AutomatedOffense = _penalty.AutomatedOffense, + Expired = _penalty.Expires.HasValue && _penalty.Expires <= DateTime.UtcNow + }, + When = _penalty.When, + Sensitive = _penalty.Type == Penalty.PenaltyType.Flag + }) + .ToList(); + } MetaService.AddRuntimeMeta(getProfileMeta); + MetaService.AddRuntimeMeta(getPenaltyMeta); #endregion #region INIT diff --git a/Plugins/Stats/Plugin.cs b/Plugins/Stats/Plugin.cs index 5b083370a..892af0967 100644 --- a/Plugins/Stats/Plugin.cs +++ b/Plugins/Stats/Plugin.cs @@ -124,7 +124,7 @@ namespace IW4MAdmin.Plugins.Stats "/Stats/TopPlayersAsync"); // meta data info - async Task> getStats(int clientId, int offset, int count) + async Task> getStats(int clientId, int offset, int count, DateTime? startAt) { if (count > 1) { @@ -186,7 +186,7 @@ namespace IW4MAdmin.Plugins.Stats }; } - async Task> getAnticheatInfo(int clientId, int offset, int count) + async Task> getAnticheatInfo(int clientId, int offset, int count, DateTime? startAt) { if (count > 1) { @@ -280,7 +280,7 @@ namespace IW4MAdmin.Plugins.Stats }; } - async Task> getMessages(int clientId, int offset, int count) + async Task> getMessages(int clientId, int offset, int count, DateTime? startAt) { if (count <= 1) { @@ -291,7 +291,8 @@ namespace IW4MAdmin.Plugins.Stats new ProfileMeta() { Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_MESSAGES"], - Value = await ctx.Set().CountAsync(), + Value = await ctx.Set() + .CountAsync(_message => _message.ClientId == clientId), Type = ProfileMeta.MetaType.Information } }; @@ -301,7 +302,9 @@ namespace IW4MAdmin.Plugins.Stats List messageMeta; using (var ctx = new DatabaseContext(disableTracking: true)) { - var messages = ctx.Set().Where(m => m.ClientId == clientId) + var messages = ctx.Set() + .Where(m => m.ClientId == clientId) + .Where(_message => _message.TimeSent < startAt) .OrderByDescending(_message => _message.TimeSent) .Skip(offset) .Take(count); diff --git a/SharedLibraryCore/Dtos/PlayerInfo.cs b/SharedLibraryCore/Dtos/PlayerInfo.cs index eb1f4cb0e..f6d991045 100644 --- a/SharedLibraryCore/Dtos/PlayerInfo.cs +++ b/SharedLibraryCore/Dtos/PlayerInfo.cs @@ -18,10 +18,6 @@ namespace SharedLibraryCore.Dtos public List IPs { get; set; } public bool HasActivePenalty { get; set; } public string ActivePenaltyType { get; set; } - //public int ConnectionCount { get; set; } - //public string LastSeen { get; set; } - //public string FirstSeen { get; set; } - //public string TimePlayed { get; set; } public bool Authenticated { get; set; } public List Meta { get; set; } public bool Online { get; set; } diff --git a/SharedLibraryCore/Dtos/ProfileMeta.cs b/SharedLibraryCore/Dtos/ProfileMeta.cs index b0a30c978..07b4abd3f 100644 --- a/SharedLibraryCore/Dtos/ProfileMeta.cs +++ b/SharedLibraryCore/Dtos/ProfileMeta.cs @@ -13,7 +13,9 @@ namespace SharedLibraryCore.Dtos Other, Information, AliasUpdate, - ChatMessage + ChatMessage, + Penalized, + ReceivedPenalty, } public DateTime When { get; set; } diff --git a/SharedLibraryCore/Services/MetaService.cs b/SharedLibraryCore/Services/MetaService.cs index 7910d24ef..96f81c1be 100644 --- a/SharedLibraryCore/Services/MetaService.cs +++ b/SharedLibraryCore/Services/MetaService.cs @@ -11,7 +11,7 @@ namespace SharedLibraryCore.Services { public class MetaService { - private static List>>> _metaActions = new List>>>(); + private static List>>> _metaActions = new List>>>(); /// /// adds or updates meta key and value to the database @@ -71,7 +71,7 @@ namespace SharedLibraryCore.Services /// aads a meta task to the runtime meta list /// /// - public static void AddRuntimeMeta(Func>> metaAction) + public static void AddRuntimeMeta(Func>> metaAction) { _metaActions.Add(metaAction); } @@ -83,16 +83,24 @@ namespace SharedLibraryCore.Services /// number of meta items to retrieve /// offset from the first item /// - public static async Task> GetRuntimeMeta(int clientId, int offset = 0, int count = int.MaxValue) + public static async Task> GetRuntimeMeta(int clientId, int offset = 0, int count = int.MaxValue, DateTime? startAt = null) { var meta = new List(); foreach (var action in _metaActions) { - meta.AddRange(await action(clientId, offset, count)); + var metaItems = await action(clientId, offset, count, startAt); + meta.AddRange(metaItems); } - return meta; + if (count == 1) + { + return meta; + } + + return meta.OrderByDescending(_meta => _meta.When) + .Take(count) + .ToList(); } } } diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs index d131b1e97..82f43f578 100644 --- a/SharedLibraryCore/Services/PenaltyService.cs +++ b/SharedLibraryCore/Services/PenaltyService.cs @@ -159,6 +159,24 @@ namespace SharedLibraryCore.Services } } + public async Task> GetAllClientPenaltiesAsync(int clientId, int count, int offset, DateTime? startAt) + { + using (var ctx = new DatabaseContext(true)) + { + var iqPenalties = ctx.Penalties.AsNoTracking() + .Include(_penalty => _penalty.Offender.CurrentAlias) + .Include(_penalty => _penalty.Punisher.CurrentAlias) + .Where(_penalty => _penalty.Active) + .Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId) + .Where(_penalty => _penalty.When < startAt) + .OrderByDescending(_penalty => _penalty.When) + .Skip(offset) + .Take(count); + + return await iqPenalties.ToListAsync(); + } + } + /// /// Get a read-only copy of client penalties /// diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs index 80c0902cf..d4f2978b2 100644 --- a/WebfrontCore/Controllers/BaseController.cs +++ b/WebfrontCore/Controllers/BaseController.cs @@ -59,7 +59,7 @@ namespace WebfrontCore.Controllers { ClientId = -1, Level = EFClient.Permission.User, - CurrentAlias = new EFAlias() { Name = "Web Console Guest" } + CurrentAlias = new EFAlias() { Name = "Webfront Guest" } }; if (!HttpContext.Connection.RemoteIpAddress.GetAddressBytes().SequenceEqual(LocalHost)) @@ -70,6 +70,7 @@ namespace WebfrontCore.Controllers Client.NetworkId = User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertLong(); Client.Level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), User.Claims.First(c => c.Type == ClaimTypes.Role).Value); Client.CurrentAlias = new EFAlias() { Name = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value }; + Authorized = Client.ClientId >= 0; } catch (InvalidOperationException) @@ -93,7 +94,6 @@ namespace WebfrontCore.Controllers Authorized = true; } - Authorized = Client.ClientId >= 0; ViewBag.Authorized = Authorized; ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontUrl; ViewBag.User = Client; diff --git a/WebfrontCore/Controllers/ClientController.cs b/WebfrontCore/Controllers/ClientController.cs index 0eb081ea9..6ad7706d6 100644 --- a/WebfrontCore/Controllers/ClientController.cs +++ b/WebfrontCore/Controllers/ClientController.cs @@ -15,6 +15,7 @@ namespace WebfrontCore.Controllers public async Task ProfileAsync(int id) { var client = await Manager.GetClientService().Get(id); + if (client == null) { return NotFound(); @@ -22,10 +23,6 @@ namespace WebfrontCore.Controllers var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.IPAddress); -#if DEBUG - Authorized = true; -#endif - var clientDto = new PlayerInfo() { Name = client.Name, @@ -55,42 +52,7 @@ namespace WebfrontCore.Controllers LinkedAccounts = client.LinkedAccounts }; - var meta = await MetaService.GetRuntimeMeta(client.ClientId, 0, 1); - var penaltyMeta = await Manager.GetPenaltyService() - .ReadGetClientPenaltiesAsync(client.ClientId); - var administeredPenaltiesMeta = await Manager.GetPenaltyService() - .ReadGetClientPenaltiesAsync(client.ClientId, false); - - if (Authorized && client.Level > EFClient.Permission.Trusted) - { - clientDto.Meta.Add(new ProfileMeta() - { - Key = Localization["WEBFRONT_CLIENT_META_MASKED"], - Value = client.Masked ? Localization["WEBFRONT_CLIENT_META_TRUE"] : Localization["WEBFRONT_CLIENT_META_FALSE"], - Sensitive = true, - When = DateTime.MinValue - }); - } - - //if (Authorized) - //{ - // clientDto.Meta.AddRange(client.AliasLink.Children - // .GroupBy(a => a.Name) - // .Select(a => a.First()) - // .Select(a => new ProfileMeta() - // { - // Value = $"{Localization["WEBFRONT_CLIENT_META_JOINED"]} {a.Name}", - // Sensitive = true, - // When = a.DateAdded, - // Type = ProfileMeta.MetaType.AliasUpdate - // })); - //} - - if (Authorized) - { - penaltyMeta.ForEach(p => p.Value.Offense = p.Value.AutomatedOffense ?? p.Value.Offense); - administeredPenaltiesMeta.ForEach(p => p.Value.Offense = p.Value.AutomatedOffense ?? p.Value.Offense); - } + var meta = await MetaService.GetRuntimeMeta(client.ClientId, 0, 1, DateTime.UtcNow); var currentPenalty = activePenalties.FirstOrDefault(); @@ -105,20 +67,7 @@ namespace WebfrontCore.Controllers } clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.Sensitive)); - clientDto.Meta.AddRange(Authorized ? penaltyMeta : penaltyMeta.Where(m => !m.Sensitive)); - clientDto.Meta.AddRange(Authorized ? administeredPenaltiesMeta : administeredPenaltiesMeta.Where(m => !m.Sensitive)); - clientDto.Meta.AddRange(client.Meta.Select(m => new ProfileMeta() - { - When = m.Created, - Key = m.Key, - Value = m.Value, - Show = false, - })); - - clientDto.Meta = clientDto.Meta - .OrderByDescending(m => m.When) - .ToList(); - + ViewBag.Title = clientDto.Name.Substring(clientDto.Name.Length - 1).ToLower()[0] == 's' ? clientDto.Name + "'" : clientDto.Name + "'s"; @@ -179,9 +128,9 @@ namespace WebfrontCore.Controllers return View("Find/Index", clientsDto); } - public async Task Meta(int id, int count, int offset) + public async Task Meta(int id, int count, int offset, DateTime? startAt) { - var meta = await MetaService.GetRuntimeMeta(id, offset, count); + var meta = await MetaService.GetRuntimeMeta(id, startAt == null ? offset : 0, count, startAt ?? DateTime.UtcNow); if (meta.Count == 0) { diff --git a/WebfrontCore/ViewComponents/ProfileMetaListViewComponent.cs b/WebfrontCore/ViewComponents/ProfileMetaListViewComponent.cs index b12c2b83c..5987753f0 100644 --- a/WebfrontCore/ViewComponents/ProfileMetaListViewComponent.cs +++ b/WebfrontCore/ViewComponents/ProfileMetaListViewComponent.cs @@ -1,14 +1,15 @@ using Microsoft.AspNetCore.Mvc; using SharedLibraryCore.Services; +using System; using System.Threading.Tasks; namespace WebfrontCore.ViewComponents { public class ProfileMetaListViewComponent : ViewComponent { - public async Task InvokeAsync(int clientId, int count, int offset) + public async Task InvokeAsync(int clientId, int count, int offset, DateTime? startAt) { - var meta = await MetaService.GetRuntimeMeta(clientId, offset, count); + var meta = await MetaService.GetRuntimeMeta(clientId, offset, count, startAt ?? DateTime.UtcNow); return View("_List", meta); } } diff --git a/WebfrontCore/Views/Client/Profile/Index.cshtml b/WebfrontCore/Views/Client/Profile/Index.cshtml index 13d552b68..1c691d9de 100644 --- a/WebfrontCore/Views/Client/Profile/Index.cshtml +++ b/WebfrontCore/Views/Client/Profile/Index.cshtml @@ -79,7 +79,6 @@
-
@for (int i = 0; i < informationMeta.Count; i += 3) { @@ -117,6 +116,10 @@
+
+ +
+ @section targetid { } diff --git a/WebfrontCore/Views/Shared/Components/ProfileMetaList/_List.cshtml b/WebfrontCore/Views/Shared/Components/ProfileMetaList/_List.cshtml index cb9fe9d09..7cfb511eb 100644 --- a/WebfrontCore/Views/Shared/Components/ProfileMetaList/_List.cshtml +++ b/WebfrontCore/Views/Shared/Components/ProfileMetaList/_List.cshtml @@ -1,20 +1,62 @@ @model List -@{Layout = null;} +@{ + Layout = null; -
- - @SharedLibraryCore.Utilities.GetTimePassed(Model.FirstOrDefault()?.When ?? DateTime.Now, true) -
+ string formatPenalty(SharedLibraryCore.Dtos.ProfileMeta meta) + { + var penalty = meta.Value as SharedLibraryCore.Dtos.PenaltyInfo; -@foreach (var meta in Model) + string localizationKey = meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized ? + $"WEBFRONT_CLIENT_META_PENALIZED_{penalty.PenaltyType.ToUpper()}" : + $"WEBFRONT_CLIENT_META_WAS_PENALIZED_{penalty.PenaltyType.ToUpper()}"; + + string localizationMessage = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex[localizationKey]; + var regexMatch = System.Text.RegularExpressions.Regex.Match(localizationMessage, @"^{{([^{}]+)}}.+$"); + string penaltyType = regexMatch.Groups[1].Value.ToString(); + + localizationMessage = localizationMessage.Replace(penaltyType, $"{penaltyType}"); + + return meta.Type == SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized ? + string.Format(localizationMessage, + $"{penalty.OffenderName}", + $"{penalty.Offense}") + .Replace("{", "") + .Replace("}", "") : + string.Format(localizationMessage, + $"{penalty.PunisherName}", + $"{penalty.Offense}", + penalty.Offense) + .Replace("{", "") + .Replace("}", ""); + } +} + +@if (Model.Count > 0) +{ +
+ + @SharedLibraryCore.Utilities.GetTimePassed(Model.First().When, true) +
+} + +@if (Model.Count == 0) +{ +
@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_NONE"]
+} + +@foreach (var meta in Model.OrderByDescending(_meta => _meta.When)) { @switch (meta.Type) { case SharedLibraryCore.Dtos.ProfileMeta.MetaType.ChatMessage: -
+
> @meta.Value
break; + case SharedLibraryCore.Dtos.ProfileMeta.MetaType.ReceivedPenalty: + case SharedLibraryCore.Dtos.ProfileMeta.MetaType.Penalized: +
@Html.Raw(formatPenalty(meta))
+ break; } } \ No newline at end of file diff --git a/WebfrontCore/wwwroot/css/bootstrap-custom.css b/WebfrontCore/wwwroot/css/bootstrap-custom.css index 202dcc565..6dc8073b1 100644 --- a/WebfrontCore/wwwroot/css/bootstrap-custom.css +++ b/WebfrontCore/wwwroot/css/bootstrap-custom.css @@ -6375,6 +6375,9 @@ form *, select { padding: 5px; visibility: hidden; } +.loader-load-more { + border-radius: 0; } + .input-border-transition { -webkit-transition: border 500ms ease-out; -moz-transition: border 500ms ease-out; diff --git a/WebfrontCore/wwwroot/css/bootstrap-custom.scss b/WebfrontCore/wwwroot/css/bootstrap-custom.scss index c2a87ccd6..d430b9551 100644 --- a/WebfrontCore/wwwroot/css/bootstrap-custom.scss +++ b/WebfrontCore/wwwroot/css/bootstrap-custom.scss @@ -163,6 +163,10 @@ form *, select { visibility: hidden; } +.loader-load-more { + border-radius: 0; +} + .input-border-transition { -webkit-transition: border 500ms ease-out; -moz-transition: border 500ms ease-out; diff --git a/WebfrontCore/wwwroot/js/loader.js b/WebfrontCore/wwwroot/js/loader.js index 944800aad..f5dcf2559 100644 --- a/WebfrontCore/wwwroot/js/loader.js +++ b/WebfrontCore/wwwroot/js/loader.js @@ -1,5 +1,6 @@ let loaderOffset = 10; let loadCount = 10; +let startAt = null; let isLoaderLoading = false; let loadUri = ''; let loaderResponseId = ''; @@ -19,13 +20,14 @@ function loadMoreItems() { showLoader(); isLoaderLoading = true; - $.get(loadUri, { offset: loaderOffset, count : loadCount }) + $.get(loadUri, { offset: loaderOffset, count: loadCount, startAt: startAt }) .done(function (response) { $(loaderResponseId).append(response); if (response.trim().length === 0) { staleLoader(); } $(document).trigger("loaderFinished", response); + startAt = $(response).filter('.loader-data-time').last().data('time'); hideLoader(); isLoaderLoading = false; }) @@ -37,47 +39,52 @@ function loadMoreItems() { } function setupListeners() { -if ($(loaderResponseId).length === 1) { -/* - https://stackoverflow.com/questions/19731730/jquery-js-detect-users-scroll-attempt-without-any-window-overflow-to-scroll - */ + if ($(loaderResponseId).length === 1) { + /* + https://stackoverflow.com/questions/19731730/jquery-js-detect-users-scroll-attempt-without-any-window-overflow-to-scroll + */ - $('html').bind('mousewheel DOMMouseScroll', function (e) { - var delta = e.originalEvent.wheelDelta || -e.originalEvent.detail; + $('html').bind('mousewheel DOMMouseScroll', function (e) { + var delta = e.originalEvent.wheelDelta || -e.originalEvent.detail; - if (delta < 0 && !hasScrollBar) { - loadMoreItems(); - } - }); - - /* - 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 - .off('scroll', ScrollHandler) - .on('scroll', ScrollHandler); - }); - - function ScrollHandler(e) { - //throttle event: - hasScrollBar = true; - clearTimeout(_throttleTimer); - _throttleTimer = setTimeout(function () { - - //do work - if ($window.scrollTop() + $window.height() > $document.height() - 100) { - loadMoreItems(); + if (delta < 0 && !hasScrollBar) { + loadMoreItems(); } + }); - }, _throttleDelay); + /* + 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 + .off('scroll', ScrollHandler) + .on('scroll', ScrollHandler); + $('.loader-load-more').click(function (e) { + if (!isLoaderLoading) { + loadMoreItems(); + } + }) + }); + + function ScrollHandler(e) { + //throttle event: + hasScrollBar = true; + clearTimeout(_throttleTimer); + _throttleTimer = setTimeout(function () { + + //do work + if ($window.scrollTop() + $window.height() > $document.height() - 100) { + loadMoreItems(); + } + + }, _throttleDelay); + } } -} } \ No newline at end of file diff --git a/WebfrontCore/wwwroot/js/profile.js b/WebfrontCore/wwwroot/js/profile.js index 915418510..74de5c6fc 100644 --- a/WebfrontCore/wwwroot/js/profile.js +++ b/WebfrontCore/wwwroot/js/profile.js @@ -13,6 +13,7 @@ /* * load context of chat */ + $(document).off('click', '.client-message'); $(document).on('click', '.client-message', function (e) { showLoader(); const location = $(this); @@ -33,6 +34,7 @@ /* * load info on ban/flag */ + $(document).off('click', '.automated-penalty-info-detailed'); $(document).on('click', '.automated-penalty-info-detailed', function (e) { showLoader(); const location = $(this).parent();