From d6b6600ce98eddbcb33d1452c5f1431637d75408 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Sun, 3 Nov 2024 13:22:48 -0700 Subject: [PATCH 1/3] Custom Widgets --- .gitignore | 1 + Controllers/Vehicle/ReportController.cs | 8 ++++++++ Helper/FileHelper.cs | 24 ++++++++++++++++++++++++ Helper/StaticHelper.cs | 1 + Models/Report/ReportViewModel.cs | 1 + Views/Vehicle/_Report.cshtml | 15 +++++++++++++++ Views/Vehicle/_ReportWidgets.cshtml | 2 ++ wwwroot/defaults/en_US.json | 2 +- wwwroot/js/reports.js | 9 +++++++++ 9 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Views/Vehicle/_ReportWidgets.cshtml diff --git a/.gitignore b/.gitignore index 5112fe00..1122c142 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ config/userConfig.json CarCareTracker.csproj.user Properties/launchSettings.json data/cartracker-log.db +data/widgets.html diff --git a/Controllers/Vehicle/ReportController.cs b/Controllers/Vehicle/ReportController.cs index d80d107f..7d4810f5 100644 --- a/Controllers/Vehicle/ReportController.cs +++ b/Controllers/Vehicle/ReportController.cs @@ -22,6 +22,8 @@ public IActionResult GetReportPartialView(int vehicleId) var odometerRecords = _odometerRecordDataAccess.GetOdometerRecordsByVehicleId(vehicleId); var userConfig = _config.GetUserConfig(User); var viewModel = new ReportViewModel(); + //check if custom widgets are configured + viewModel.CustomWidgetsConfigured = _fileHelper.WidgetsExist(); //get totalCostMakeUp viewModel.CostMakeUpForVehicle = new CostMakeUpForVehicle { @@ -528,5 +530,11 @@ public IActionResult GetCostByMonthByVehicle(int vehicleId, List sel }).ToList(); return PartialView("_GasCostByMonthReport", groupedRecord); } + [HttpGet] + public IActionResult GetAdditionalWidgets() + { + var widgets = _fileHelper.GetWidgets(); + return PartialView("_ReportWidgets", widgets); + } } } diff --git a/Helper/FileHelper.cs b/Helper/FileHelper.cs index e3c70fa3..5e2a7f64 100644 --- a/Helper/FileHelper.cs +++ b/Helper/FileHelper.cs @@ -16,6 +16,8 @@ public interface IFileHelper int ClearTempFolder(); int ClearUnlinkedThumbnails(List linkedImages); int ClearUnlinkedDocuments(List linkedDocuments); + string GetWidgets(); + bool WidgetsExist(); } public class FileHelper : IFileHelper { @@ -368,5 +370,27 @@ public int ClearUnlinkedDocuments(List linkedDocuments) } return filesDeleted; } + public string GetWidgets() + { + if (File.Exists(StaticHelper.AdditionalWidgetsPath)) + { + try + { + //read file + var widgets = File.ReadAllText(StaticHelper.AdditionalWidgetsPath); + return widgets; + } + catch (Exception ex) + { + _logger.LogError(ex.Message); + return string.Empty; + } + } + return string.Empty; + } + public bool WidgetsExist() + { + return File.Exists(StaticHelper.AdditionalWidgetsPath); + } } } diff --git a/Helper/StaticHelper.cs b/Helper/StaticHelper.cs index a9f12fcf..e994dcb8 100644 --- a/Helper/StaticHelper.cs +++ b/Helper/StaticHelper.cs @@ -12,6 +12,7 @@ public static class StaticHelper public static string VersionNumber = "1.4.0"; public static string DbName = "data/cartracker.db"; public static string UserConfigPath = "config/userConfig.json"; + public static string AdditionalWidgetsPath = "data/widgets.html"; public static string GenericErrorMessage = "An error occurred, please try again later"; public static string ReminderEmailTemplate = "defaults/reminderemailtemplate.txt"; public static string DefaultAllowedFileExtensions = ".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx"; diff --git a/Models/Report/ReportViewModel.cs b/Models/Report/ReportViewModel.cs index 7696f3d8..87a6c54b 100644 --- a/Models/Report/ReportViewModel.cs +++ b/Models/Report/ReportViewModel.cs @@ -8,5 +8,6 @@ public class ReportViewModel public ReminderMakeUpForVehicle ReminderMakeUpForVehicle { get; set; } = new ReminderMakeUpForVehicle(); public List Years { get; set; } = new List(); public List Collaborators { get; set; } = new List(); + public bool CustomWidgetsConfigured { get; set; } = false; } } diff --git a/Views/Vehicle/_Report.cshtml b/Views/Vehicle/_Report.cshtml index 47534f48..e3e23965 100644 --- a/Views/Vehicle/_Report.cshtml +++ b/Views/Vehicle/_Report.cshtml @@ -126,6 +126,12 @@
+ @if (Model.CustomWidgetsConfigured) + { +
+ +
+ } @@ -153,6 +159,15 @@ +@if (Model.CustomWidgetsConfigured) +{ + +}