From 771cea72ad3ba051c5b603fd104768e4397a90cc Mon Sep 17 00:00:00 2001 From: smallbenji Date: Sun, 24 Nov 2024 23:25:59 +0100 Subject: [PATCH] misc. changes --- .../Controllers/HeaderNavController.cs | 6 +-- pointMaster/Controllers/PointController.cs | 39 +++++++++++++++++-- pointMaster/Controllers/StatsApiController.cs | 2 +- pointMaster/Views/Patrulje/Index.cshtml | 2 +- pointMaster/Views/Point/Index.cshtml | 1 + pointMaster/Views/Point/PatruljeInfo.cshtml | 34 ++++++++++++++++ pointMaster/Views/Point/SkiftPatrulje.cshtml | 2 +- pointMaster/Views/Point/SkiftPost.cshtml | 2 +- pointMaster/Views/Shared/_Layout.cshtml | 5 ++- pointMaster/Views/Stats/Index.cshtml | 2 +- pointMaster/js/src/main.ts | 5 ++- 11 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 pointMaster/Views/Point/PatruljeInfo.cshtml diff --git a/pointMaster/Controllers/HeaderNavController.cs b/pointMaster/Controllers/HeaderNavController.cs index 0128535..e739095 100644 --- a/pointMaster/Controllers/HeaderNavController.cs +++ b/pointMaster/Controllers/HeaderNavController.cs @@ -24,12 +24,12 @@ namespace pointMaster.Controllers vm.links.Add(new NavUrl("Patruljer", "/Patrulje")); vm.links.Add(new NavUrl("Point", "/Point")); vm.links.Add(new NavUrl("Poster", "/Poster")); - vm.links.Add(new NavUrl("Statistikker", "/stats")); + vm.links.Add(new NavUrl("Statistikker", "/Stats")); } if (User.Identity != null && User.Identity.IsAuthenticated) { - vm.links.Add(new NavUrl("Giv point", "/point/givpoint")); - vm.links.Add(new NavUrl("Vælg post", "/point/skiftpost")); + vm.links.Add(new NavUrl("Giv point", "/Point/GivPoint")); + vm.links.Add(new NavUrl("Vælg post", "/Point/SkiftPost")); vm.links.Add(new NavUrl("Log ud", "/account/signout")); } else diff --git a/pointMaster/Controllers/PointController.cs b/pointMaster/Controllers/PointController.cs index e6156fd..9e1d4d5 100644 --- a/pointMaster/Controllers/PointController.cs +++ b/pointMaster/Controllers/PointController.cs @@ -6,7 +6,6 @@ using pointMaster.Models; namespace pointMaster.Controllers { - [Authorize(Policy = Roles.Postmaster)] public class PointController : Controller { private readonly DataContext context; @@ -15,7 +14,7 @@ namespace pointMaster.Controllers { this.context = context; } - + [Authorize(Policy = Roles.Postmaster)] public async Task Index() { var vm = new PointViewModel(); @@ -31,7 +30,7 @@ namespace pointMaster.Controllers return View(vm); } - + [Authorize(Policy = Roles.Postmaster)] public async Task SkiftPatrulje() { var vm = new SkiftPatruljeViewModel(); @@ -49,9 +48,31 @@ namespace pointMaster.Controllers return View(vm); } - + public async Task GivPoint(int id = 0) { + if (!HttpContext.User.Identity.IsAuthenticated) + { + var patruljeData = new PatruljeInfoModel(); + + var data = await context.Patruljer.Include(x => x.Points).ThenInclude(x => x.Poster).FirstOrDefaultAsync(x => x.Id == id); + + if (data != null) + { + patruljeData.patrulje = data; + + patruljeData.totalPoints = data.Points.Sum(x => x.Points); + + patruljeData.totalTurnout = data.Points.Sum(x => x.Turnout); + } + else + { + return NotFound(); + } + + return View("PatruljeInfo", patruljeData); + } + if (id == 0) { if (string.IsNullOrEmpty(Request.Cookies["Post"])) @@ -98,6 +119,7 @@ namespace pointMaster.Controllers return View(vm); } + [Authorize(Policy = Roles.Postmaster)] [HttpPost] public async Task GivPoint(int id, GivPointViewModel point) { @@ -129,6 +151,7 @@ namespace pointMaster.Controllers return RedirectToAction("Index"); } + [Authorize(Policy = Roles.Postmaster)] public async Task SkiftPost() { var vm = new SelectPostViewModel(); @@ -138,6 +161,7 @@ namespace pointMaster.Controllers return View(vm); } + [Authorize(Policy = Roles.Postmaster)] public IActionResult SelectPost(int id) { var cookieOptions = new CookieOptions(); @@ -150,6 +174,7 @@ namespace pointMaster.Controllers return Redirect("/"); } + [Authorize(Policy = Roles.Editor)] public ActionResult DeletePoint(int id) { var point = context.Points.FirstOrDefault(p => p.Id == id); @@ -183,4 +208,10 @@ namespace pointMaster.Controllers public List points { get; set; } = null!; public bool AllowedToDelete { get; set; } = false; } + public class PatruljeInfoModel + { + public Patrulje patrulje { get; set; } = null!; + public int totalPoints { get; set; } + public int totalTurnout { get; set; } + } } diff --git a/pointMaster/Controllers/StatsApiController.cs b/pointMaster/Controllers/StatsApiController.cs index 98fa4fa..4a367c9 100644 --- a/pointMaster/Controllers/StatsApiController.cs +++ b/pointMaster/Controllers/StatsApiController.cs @@ -6,6 +6,7 @@ using pointMaster.Data; namespace pointMaster.Controllers { + [Authorize(Policy = Roles.Editor)] [ApiController] [Route("api")] public class StatsApiController : ControllerBase @@ -17,7 +18,6 @@ namespace pointMaster.Controllers this.dataContext = dataContext; } - [Authorize(Policy = Roles.Editor)] [HttpGet("GetPointsOverTime")] public async Task GetList() { diff --git a/pointMaster/Views/Patrulje/Index.cshtml b/pointMaster/Views/Patrulje/Index.cshtml index 7fc7e52..b9e2188 100644 --- a/pointMaster/Views/Patrulje/Index.cshtml +++ b/pointMaster/Views/Patrulje/Index.cshtml @@ -9,7 +9,7 @@ {
-

@patrulje.Name

+

@patrulje.Id @patrulje.Name

Points: @Model.patruljePoints[patrulje.Id]

Turnout: @Model.patruljeTurnout[patrulje.Id]

diff --git a/pointMaster/Views/Point/Index.cshtml b/pointMaster/Views/Point/Index.cshtml index 3a1b4b5..89e1cb8 100644 --- a/pointMaster/Views/Point/Index.cshtml +++ b/pointMaster/Views/Point/Index.cshtml @@ -2,6 +2,7 @@ @{ ViewData["Title"] = "Point"; } +

Point

Giv point diff --git a/pointMaster/Views/Point/PatruljeInfo.cshtml b/pointMaster/Views/Point/PatruljeInfo.cshtml new file mode 100644 index 0000000..2c75a5d --- /dev/null +++ b/pointMaster/Views/Point/PatruljeInfo.cshtml @@ -0,0 +1,34 @@ +@model pointMaster.Controllers.PatruljeInfoModel + +

@Model.patrulje.Name

+ +

Total points: @Model.totalPoints

+

total turnout: @Model.totalTurnout

+
+ + + + + + + + + @if (Model.patrulje.Points.Any()) + { + @foreach (var point in Model.patrulje.Points) + { + + + + + + } + } + else + { + + + + } + +
Post navnPointsTurnout
@point.Poster.Name@point.Turnout@point.Points
Ingen point givet
\ No newline at end of file diff --git a/pointMaster/Views/Point/SkiftPatrulje.cshtml b/pointMaster/Views/Point/SkiftPatrulje.cshtml index 97b7353..0774d9b 100644 --- a/pointMaster/Views/Point/SkiftPatrulje.cshtml +++ b/pointMaster/Views/Point/SkiftPatrulje.cshtml @@ -10,6 +10,6 @@ \ No newline at end of file diff --git a/pointMaster/Views/Point/SkiftPost.cshtml b/pointMaster/Views/Point/SkiftPost.cshtml index 7e23014..9e89b5a 100644 --- a/pointMaster/Views/Point/SkiftPost.cshtml +++ b/pointMaster/Views/Point/SkiftPost.cshtml @@ -6,6 +6,6 @@ \ No newline at end of file diff --git a/pointMaster/Views/Shared/_Layout.cshtml b/pointMaster/Views/Shared/_Layout.cshtml index 3609050..d2004b3 100644 --- a/pointMaster/Views/Shared/_Layout.cshtml +++ b/pointMaster/Views/Shared/_Layout.cshtml @@ -15,7 +15,10 @@