From 39162784220c4a931527d1917b1e9f641339a7de Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 9 Oct 2021 21:11:47 -0500 Subject: [PATCH] Add about/community info guidelines/social page --- SharedLibraryCore/BaseController.cs | 8 +- .../Configuration/ApplicationConfiguration.cs | 3 + .../CommunityInformationConfiguration.cs | 40 ++++++++++ WebfrontCore/Controllers/AboutController.cs | 44 +++++++++++ WebfrontCore/Extensions/WebfrontExtensions.cs | 10 +++ WebfrontCore/ViewModels/CommunityInfo.cs | 12 +++ WebfrontCore/Views/About/Index.cshtml | 70 ++++++++++++++++++ WebfrontCore/Views/Shared/_Layout.cshtml | 42 ++++++++--- WebfrontCore/wwwroot/css/src/main.scss | 6 ++ .../wwwroot/images/community/banner.png | Bin 0 -> 32120 bytes .../wwwroot/images/community/github.svg | 1 + 11 files changed, 226 insertions(+), 10 deletions(-) create mode 100644 SharedLibraryCore/Configuration/CommunityInformationConfiguration.cs create mode 100644 WebfrontCore/Controllers/AboutController.cs create mode 100644 WebfrontCore/Extensions/WebfrontExtensions.cs create mode 100644 WebfrontCore/ViewModels/CommunityInfo.cs create mode 100644 WebfrontCore/Views/About/Index.cshtml create mode 100644 WebfrontCore/wwwroot/images/community/banner.png create mode 100644 WebfrontCore/wwwroot/images/community/github.svg diff --git a/SharedLibraryCore/BaseController.cs b/SharedLibraryCore/BaseController.cs index 343068573..495b6d674 100644 --- a/SharedLibraryCore/BaseController.cs +++ b/SharedLibraryCore/BaseController.cs @@ -57,6 +57,7 @@ namespace SharedLibraryCore ViewBag.Version = Manager.Version; ViewBag.IsFluid = false; ViewBag.EnableColorCodes = Manager.GetApplicationSettings().Configuration().EnableColorCodes; + ViewBag.Language = Utilities.CurrentLocalization.Culture.TwoLetterISOLanguageName; Client ??= new EFClient() { @@ -125,6 +126,9 @@ namespace SharedLibraryCore SignInAsync(new ClaimsPrincipal(claimsIdentity)).Wait(); } + var communityName = Manager.GetApplicationSettings().Configuration().CommunityInformation?.Name; + var shouldUseCommunityName = !string.IsNullOrWhiteSpace(communityName) && !communityName.Contains("IW4MAdmin"); + ViewBag.Authorized = Authorized; ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontUrl; ViewBag.User = Client; @@ -133,7 +137,9 @@ namespace SharedLibraryCore ViewBag.SocialTitle = SocialTitle; ViewBag.Pages = Pages; ViewBag.Localization = Utilities.CurrentLocalization.LocalizationIndex; - ViewBag.CustomBranding = Manager.GetApplicationSettings().Configuration().WebfrontCustomBranding ?? "IW4MAdmin"; + ViewBag.CustomBranding = shouldUseCommunityName + ? communityName + : Manager.GetApplicationSettings().Configuration().WebfrontCustomBranding ?? "IW4MAdmin"; ViewBag.EnableColorCodes = Manager.GetApplicationSettings().Configuration().EnableColorCodes; ViewBag.EnablePrivilegedUserPrivacy = Manager.GetApplicationSettings().Configuration().EnablePrivilegedUserPrivacy; diff --git a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs index 6aff83723..cf9ebdc66 100644 --- a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs +++ b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs @@ -11,6 +11,9 @@ namespace SharedLibraryCore.Configuration { public class ApplicationConfiguration : IBaseConfiguration { + [ConfigurationIgnore] + public CommunityInformationConfiguration CommunityInformation { get; set; } = new CommunityInformationConfiguration(); + [LocalizedDisplayName("SETUP_ENABLE_WEBFRONT")] [ConfigurationLinked("WebfrontBindUrl", "ManualWebfrontUrl", "WebfrontPrimaryColor", "WebfrontSecondaryColor", "WebfrontCustomBranding")] diff --git a/SharedLibraryCore/Configuration/CommunityInformationConfiguration.cs b/SharedLibraryCore/Configuration/CommunityInformationConfiguration.cs new file mode 100644 index 000000000..71fca4cc7 --- /dev/null +++ b/SharedLibraryCore/Configuration/CommunityInformationConfiguration.cs @@ -0,0 +1,40 @@ +namespace SharedLibraryCore.Configuration +{ + public class CommunityInformationConfiguration + { + public string Name { get; set; } = "IW4MAdmin - Configure In IW4MAdminSettings.json"; + public string Description { get; set; } = + "IW4MAdmin is an administration tool for IW4x, Pluto T6, Pluto IW5, CoD4x, TeknoMW3, and most Call of Duty® dedicated servers. It allows complete control of your server; from changing maps, to banning players, IW4MAdmin monitors and records activity on your server(s). With plugin support, extending its functionality is a breeze."; + public bool EnableBanner { get; set; } = true; + + public SocialAccountConfiguration[] SocialAccounts { get; set; } = + { + new SocialAccountConfiguration + { + Title = "IW4MAdmin Website", + Url = "https://raidmax.org/IW4MAdmin", + IconId = "oi-globe" + }, + new SocialAccountConfiguration + { + Title = "IW4MAdmin Github", + Url = "https://github.com/RaidMax/IW4M-Admin/", + IconUrl = "github.svg" + }, + new SocialAccountConfiguration + { + Title = "IW4MAdmin Youtube", + Url = "https://www.youtube.com/watch?v=xpxEO4Qi0cQ", + IconUrl = "https://raw.githubusercontent.com/edent/SuperTinyIcons/master/images/svg/youtube.svg" + } + }; + } + + public class SocialAccountConfiguration + { + public string Title { get; set; } + public string Url { get; set; } + public string IconUrl { get; set; } + public string IconId { get; set; } + } +} \ No newline at end of file diff --git a/WebfrontCore/Controllers/AboutController.cs b/WebfrontCore/Controllers/AboutController.cs new file mode 100644 index 000000000..751bd31ee --- /dev/null +++ b/WebfrontCore/Controllers/AboutController.cs @@ -0,0 +1,44 @@ +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using SharedLibraryCore; +using SharedLibraryCore.Configuration; +using SharedLibraryCore.Interfaces; +using WebfrontCore.Extensions; +using WebfrontCore.ViewModels; + +namespace WebfrontCore.Controllers +{ + public class AboutController : BaseController + { + private readonly ApplicationConfiguration _appConfig; + + public AboutController(IManager manager, ApplicationConfiguration appConfig) : base(manager) + { + _appConfig = appConfig; + } + + public IActionResult Index() + { + ViewBag.Description = Localization["WEBFRONT_DESCRIPTION_ABOUT"].FormatExt( + _appConfig.ShouldUseFallbackBranding() + ? _appConfig.WebfrontCustomBranding + : _appConfig.CommunityInformation.Name); + ViewBag.Title = _appConfig.ShouldUseFallbackBranding() + ? Localization["WEBFRONT_NAV_ABOUT"] + : _appConfig.CommunityInformation.Name; + + var info = new CommunityInfo + { + GlobalRules = _appConfig.GlobalRules, + ServerRules = + _appConfig.Servers.ToDictionary( + config => Manager.GetServers().FirstOrDefault(server => + server.IP == config.IPAddress && server.Port == config.Port)?.Hostname, + config => config.Rules), + CommunityInformation = _appConfig.CommunityInformation + }; + + return View(info); + } + } +} \ No newline at end of file diff --git a/WebfrontCore/Extensions/WebfrontExtensions.cs b/WebfrontCore/Extensions/WebfrontExtensions.cs new file mode 100644 index 000000000..8c55aea9f --- /dev/null +++ b/WebfrontCore/Extensions/WebfrontExtensions.cs @@ -0,0 +1,10 @@ +using SharedLibraryCore.Configuration; + +namespace WebfrontCore.Extensions +{ + public static class WebfrontExtensions + { + public static bool ShouldUseFallbackBranding(this ApplicationConfiguration appConfig) => + string.IsNullOrWhiteSpace(appConfig?.CommunityInformation?.Name) || appConfig.CommunityInformation.Name.Contains("IW4MAdmin"); + } +} \ No newline at end of file diff --git a/WebfrontCore/ViewModels/CommunityInfo.cs b/WebfrontCore/ViewModels/CommunityInfo.cs new file mode 100644 index 000000000..5ccf5be8e --- /dev/null +++ b/WebfrontCore/ViewModels/CommunityInfo.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using SharedLibraryCore.Configuration; + +namespace WebfrontCore.ViewModels +{ + public class CommunityInfo + { + public string[] GlobalRules { get; set; } + public Dictionary ServerRules { get; set; } + public CommunityInformationConfiguration CommunityInformation { get; set; } + } +} \ No newline at end of file diff --git a/WebfrontCore/Views/About/Index.cshtml b/WebfrontCore/Views/About/Index.cshtml new file mode 100644 index 000000000..37d075048 --- /dev/null +++ b/WebfrontCore/Views/About/Index.cshtml @@ -0,0 +1,70 @@ +@model WebfrontCore.ViewModels.CommunityInfo +@{ + var allRules = Model.ServerRules.Prepend(new KeyValuePair(ViewBag.Localization["WEBFRONT_ABOUT_GLOBAL_RULES"], Model.GlobalRules)); +} + +
+ @if (Model.CommunityInformation.EnableBanner) + { + + } + + @if (!string.IsNullOrWhiteSpace(Model.CommunityInformation.Name)) + { +

+ +

+ } + + @if (!string.IsNullOrWhiteSpace(Model.CommunityInformation.Description)) + { + + } + +

@ViewBag.Localization["WEBFRONT_ABOUT_COMMUNITY_GUIDELINES"]

+ + @foreach (var (serverName, rules) in allRules) + { + if (rules?.Length == 0) + { + continue; + } + + var start = 1; +
+
+ +
+ @foreach (var rule in rules) + { +
+ @start. + +
+ start++; + } +
+ } +
\ No newline at end of file diff --git a/WebfrontCore/Views/Shared/_Layout.cshtml b/WebfrontCore/Views/Shared/_Layout.cshtml index aea49e916..fe57c7ed1 100644 --- a/WebfrontCore/Views/Shared/_Layout.cshtml +++ b/WebfrontCore/Views/Shared/_Layout.cshtml @@ -2,7 +2,7 @@ var loc = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex; } - + @@ -34,22 +34,46 @@