From 48f0e16fdea323b2c59253ab921084e4df1af203 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Mon, 4 Nov 2024 08:37:38 -0700 Subject: [PATCH] additional enhancements to widget editor. --- Controllers/HomeController.cs | 21 +++++++++++++ Helper/FileHelper.cs | 32 +++++++++++++++++++ Views/Home/_Settings.cshtml | 6 ++++ Views/Home/_WidgetEditor.cshtml | 28 +++++++++++++++++ wwwroot/defaults/en_US.json | 2 +- wwwroot/js/settings.js | 55 +++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 Views/Home/_WidgetEditor.cshtml diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index b086110..a210d0f 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -523,6 +523,27 @@ namespace CarCareTracker.Controllers } return PartialView("_VehicleSelector", vehiclesStored); } + [Authorize(Roles = nameof(UserData.IsRootUser))] + [HttpGet] + public IActionResult GetCustomWidgetEditor() + { + var customWidgetData = _fileHelper.GetWidgets(); + return PartialView("_WidgetEditor", customWidgetData); + } + [Authorize(Roles = nameof(UserData.IsRootUser))] + [HttpPost] + public IActionResult SaveCustomWidgets(string widgetsData) + { + var saveResult = _fileHelper.SaveWidgets(widgetsData); + return Json(saveResult); + } + [Authorize(Roles = nameof(UserData.IsRootUser))] + [HttpPost] + public IActionResult DeleteCustomWidgets() + { + var deleteResult = _fileHelper.DeleteWidgets(); + return Json(deleteResult); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Helper/FileHelper.cs b/Helper/FileHelper.cs index 5e2a7f6..313074e 100644 --- a/Helper/FileHelper.cs +++ b/Helper/FileHelper.cs @@ -18,6 +18,8 @@ namespace CarCareTracker.Helper int ClearUnlinkedDocuments(List linkedDocuments); string GetWidgets(); bool WidgetsExist(); + bool SaveWidgets(string widgetsData); + bool DeleteWidgets(); } public class FileHelper : IFileHelper { @@ -392,5 +394,35 @@ namespace CarCareTracker.Helper { return File.Exists(StaticHelper.AdditionalWidgetsPath); } + public bool SaveWidgets(string widgetsData) + { + try + { + //Delete Widgets if exists + DeleteWidgets(); + File.WriteAllText(StaticHelper.AdditionalWidgetsPath, widgetsData); + return true; + } catch (Exception ex) + { + _logger.LogError(ex.Message); + return false; + } + } + public bool DeleteWidgets() + { + try + { + if (File.Exists(StaticHelper.AdditionalWidgetsPath)) + { + File.Delete(StaticHelper.AdditionalWidgetsPath); + } + return true; + } + catch (Exception ex) + { + _logger.LogError(ex.Message); + return false; + } + } } } diff --git a/Views/Home/_Settings.cshtml b/Views/Home/_Settings.cshtml index e648f54..b27733b 100644 --- a/Views/Home/_Settings.cshtml +++ b/Views/Home/_Settings.cshtml @@ -335,6 +335,12 @@ +