From 5ae31cd21b4267225a2dc4f305da184c65ab2cbf Mon Sep 17 00:00:00 2001 From: misya Date: Wed, 7 May 2025 14:38:28 +0800 Subject: [PATCH] standardise table format --- Areas/MMS/Controllers/MarineController.cs | 81 +++++----- Areas/MMS/Models/PDFGenerator/TarBallPDF.cs | 43 ++++-- Areas/MMS/Views/Marine/TarBallForm.cshtml | 158 ++++++++++---------- DBContext/MMSSystemContext.cs | 4 + Models/MarineTarball.cs | 12 +- 5 files changed, 171 insertions(+), 127 deletions(-) diff --git a/Areas/MMS/Controllers/MarineController.cs b/Areas/MMS/Controllers/MarineController.cs index d638957..9a49ca2 100644 --- a/Areas/MMS/Controllers/MarineController.cs +++ b/Areas/MMS/Controllers/MarineController.cs @@ -21,7 +21,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers _networkAccessService = networkAccessService; } - private bool TryAccessNetworkPath() + private bool TryAccessNetworkPath() //check if the path is accessible { try { @@ -71,6 +71,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers }) .ToList(); + Console.WriteLine($"Marine Tarballs Count: {marineTarballs.Count}"); return View(marineTarballs); } @@ -109,7 +110,12 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers TarBallNo = marine.ClassifyID == "NO", IsSand = marine.ClassifyID == "SD", IsNonSandy = marine.ClassifyID == "NS", - IsCoquina = marine.ClassifyID == "CO" + IsCoquina = marine.ClassifyID == "CO", + marine.OptionalName1, + marine.OptionalName2, + marine.OptionalName3, + marine.OptionalName4, + marine.FirstSampler }).FirstOrDefault(); if (tarballData == null) @@ -118,7 +124,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers // 2. Get photos from station folder (with date matching) var sampleDateString = tarballData.DateSample.ToString("yyyyMMdd"); var stationFolder = Path.Combine(PhotoBasePath, tarballData.StationID); - var stationImages = new List(); + var stationImages = new Dictionary(); if (Directory.Exists(stationFolder)) { @@ -150,37 +156,33 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers "OPTIONAL04" }; - // Sort logic - bool hasValidFormat = allImages.Any(f => - imageTypesInOrder.Any(t => Path.GetFileNameWithoutExtension(f).ToUpper().Contains(t))); - - if (hasValidFormat) + // Match images to their types + foreach (var imageType in imageTypesInOrder) { - stationImages = allImages - .OrderBy(f => - { - var fileName = Path.GetFileNameWithoutExtension(f).ToUpper(); - var typeIndex = imageTypesInOrder.FindIndex(t => fileName.Contains(t)); - return typeIndex >= 0 ? typeIndex : int.MaxValue; - }) - .ThenBy(f => f) - .Take(8) - .ToList(); - } - else - { - stationImages = allImages - .OrderBy(f => f) - .Take(8) - .ToList(); - Console.WriteLine($"WARNING: No images matched keywords. Sorted alphabetically."); + var matchedImage = allImages.FirstOrDefault(f => + Path.GetFileNameWithoutExtension(f).ToUpper().Contains(imageType)); + if (matchedImage != null) + { + stationImages[imageType] = matchedImage; + } } } - // Validate minimum images - if (stationImages.Count < 4) + // Validate mandatory images + var mandatoryImages = new List { - return StatusCode(400, $"Minimum 4 images required for {tarballData.DateSample:yyyy/MM/dd}. Found: {stationImages.Count}"); + "LEFTSIDECOASTALVIEW", + "RIGHTSIDECOASTALVIEW", + "DRAWINGVERTICALLINES", + "DRAWINGHORIZONTALLINES" + }; + + foreach (var mandatoryImage in mandatoryImages) + { + if (!stationImages.ContainsKey(mandatoryImage)) + { + return StatusCode(400, $"Missing mandatory image: {mandatoryImage}"); + } } // 3. Generate PDF @@ -198,14 +200,19 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers tarballData.IsSand, tarballData.IsNonSandy, tarballData.IsCoquina, - stationImages.Count > 0 ? stationImages[0] : null, - stationImages.Count > 1 ? stationImages[1] : null, - stationImages.Count > 2 ? stationImages[2] : null, - stationImages.Count > 3 ? stationImages[3] : null, - stationImages.Count > 4 ? stationImages[4] : null, - stationImages.Count > 5 ? stationImages[5] : null, - stationImages.Count > 6 ? stationImages[6] : null, - stationImages.Count > 7 ? stationImages[7] : null + stationImages.ContainsKey("LEFTSIDECOASTALVIEW") ? stationImages["LEFTSIDECOASTALVIEW"] : null, + stationImages.ContainsKey("RIGHTSIDECOASTALVIEW") ? stationImages["RIGHTSIDECOASTALVIEW"] : null, + stationImages.ContainsKey("DRAWINGVERTICALLINES") ? stationImages["DRAWINGVERTICALLINES"] : null, + stationImages.ContainsKey("DRAWINGHORIZONTALLINES") ? stationImages["DRAWINGHORIZONTALLINES"] : null, + stationImages.ContainsKey("OPTIONAL01") ? stationImages["OPTIONAL01"] : null, + stationImages.ContainsKey("OPTIONAL02") ? stationImages["OPTIONAL02"] : null, + stationImages.ContainsKey("OPTIONAL03") ? stationImages["OPTIONAL03"] : null, + stationImages.ContainsKey("OPTIONAL04") ? stationImages["OPTIONAL04"] : null, + tarballData.OptionalName1, + tarballData.OptionalName2, + tarballData.OptionalName3, + tarballData.OptionalName4, + tarballData.FirstSampler ).GeneratePdf(); // 4. Return file diff --git a/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs b/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs index 8b5e9bb..6ca266e 100644 --- a/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs +++ b/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs @@ -10,7 +10,9 @@ namespace PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator string longitude, string latitude, DateTime dateSample, TimeSpan timeSample, string classifyID, bool tarBallYes, bool tarBallNo, bool isSand, bool isNonSandy, bool isCoquina, string photoPath1, string photoPath2, string photoPath3, string photoPath4, - string photoPath5, string photoPath6, string photoPath7, string photoPath8 + string photoPath5, string photoPath6, string photoPath7, string photoPath8, + string optionalName1, string optionalName2, string optionalName3, string optionalName4, + string firstSampler ) : IDocument { @@ -27,14 +29,19 @@ namespace PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator private readonly bool _isSand = isSand; private readonly bool _isNonSandy = isNonSandy; private readonly bool _isCoquina = isCoquina; - private readonly string? _photoPath1 = photoPath1; //having '?' makes it nullable, ELSE the string must always have a value - private readonly string? _photoPath2 = photoPath2; //"but why keep '?' for photopath 1 to 4? - private readonly string? _photoPath3 = photoPath3; //A: to make - private readonly string? _photoPath4 = photoPath4; + private readonly string _photoPath1 = photoPath1; + private readonly string _photoPath2 = photoPath2; + private readonly string _photoPath3 = photoPath3; + private readonly string _photoPath4 = photoPath4; private readonly string? _photoPath5 = photoPath5; private readonly string? _photoPath6 = photoPath6; private readonly string? _photoPath7 = photoPath7; private readonly string? _photoPath8 = photoPath8; + private readonly string? _optionalName1 = optionalName1; + private readonly string? _optionalName2 = optionalName2; + private readonly string? _optionalName3 = optionalName3; + private readonly string? _optionalName4 = optionalName4; + private readonly string _firstSampler = firstSampler; private Image? LoadImage(string? imagePath) { @@ -286,8 +293,10 @@ namespace PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator .Image(LoadImage(_photoPath6) ?? null) // Just pass null if no image .FitArea(); - table.Cell().Element(CellStyle).Text("Figure 5:").FontSize(12).AlignLeft(); - table.Cell().Element(CellStyle).Text("Figure 6:").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text($"Figure 5: {_optionalName1}") + .FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text($"Figure 6: {_optionalName2}") + .FontSize(12).AlignLeft(); table.Cell().Element(CellStyle).Height(150) .Image(LoadImage(_photoPath7) ?? null) // Just pass null if no image @@ -296,8 +305,10 @@ namespace PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator .Image(LoadImage(_photoPath8) ?? null) // Just pass null if no image .FitArea(); - table.Cell().Element(CellStyle).Text("Figure 7:").FontSize(12).AlignLeft(); - table.Cell().Element(CellStyle).Text("Figure 8:").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text($"Figure 7: {_optionalName3}") + .FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text($"Figure 8: {_optionalName4}") + .FontSize(12).AlignLeft(); }); // Note Section @@ -322,7 +333,12 @@ namespace PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator columns.RelativeColumn(1); }); - table.Cell().RowSpan(2).Element(CellStyle).Text("REPORTED BY :").Bold().FontSize(12); + table.Cell().RowSpan(2).Element(CellStyle) + .Text(text => + { + text.Span("REPORTED BY: ").Bold().FontSize(12); + text.Span(_firstSampler).FontSize(10); + }); table.Cell().Element(CellStyle).Text("Signature").FontSize(12); table.Cell().Element(CellStyle).Text(""); table.Cell().Element(CellStyle).Text("Date").FontSize(12); @@ -331,7 +347,12 @@ namespace PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator table.Cell().Element(CellStyle).Text("Designation").FontSize(12); table.Cell().ColumnSpan(3).Element(CellStyle).Text(""); - table.Cell().RowSpan(2).Element(CellStyle).Text("CHECKED BY :").Bold().FontSize(12); + table.Cell().RowSpan(2).Element(CellStyle) + .Text(text => + { + text.Span("CHECKED BY: ").Bold().FontSize(12); + text.Span("Rifaie Azhari").FontSize(10); + }); table.Cell().Element(CellStyle).Text("Signature").FontSize(12); table.Cell().ColumnSpan(2).Element(CellStyle).Text(""); //table.Cell().Element(CellStyle).Text("Date").FontSize(12); diff --git a/Areas/MMS/Views/Marine/TarBallForm.cshtml b/Areas/MMS/Views/Marine/TarBallForm.cshtml index 8313817..3ef37bc 100644 --- a/Areas/MMS/Views/Marine/TarBallForm.cshtml +++ b/Areas/MMS/Views/Marine/TarBallForm.cshtml @@ -20,8 +20,8 @@ } div { - padding-top: 10px; - padding-bottom: 10px; + padding-top: 5px; + padding-bottom: 5px; } h4 { @@ -38,39 +38,22 @@ border: 1px solid #ccc; padding: 10px; } - - .tbhead { - text-align: center; - } - - /* Default arrow style (grey) */ - .sort-arrow { - color: #aaa; /* Light grey for default state */ - font-size: 12px; /* Adjust size for better visibility */ - line-height: 1; /* Ensure proper spacing */ - display: inline-block; /* Stack arrows vertically */ - margin: 0; /* Remove extra spacing */ - } - - /* Active arrow style (darker grey) */ - .sort-arrow.active { - color: #333; /* Dark grey for active state */ - font-weight: bold; /* Optional: Make it bold for emphasis */ - } + +

Month

Year

@@ -80,40 +63,17 @@
- +
- - - + + - - - - - - - - - +
No. - Date - - - - Station - - - DateStation Status PDF
{{ index + 1 }}{{ new Date(data.date).toLocaleDateString('en-GB') }}{{ data.station }} - - - - View PDF - Download PDF -
@@ -121,14 +81,14 @@ @section Scripts { + +