Custom Widgets

This commit is contained in:
DESKTOP-T0O5CDB\DESK-555BD 2024-11-03 13:22:48 -07:00
parent 82634e9e1b
commit d6b6600ce9
9 changed files with 62 additions and 1 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ config/userConfig.json
CarCareTracker.csproj.user
Properties/launchSettings.json
data/cartracker-log.db
data/widgets.html

View File

@ -22,6 +22,8 @@ namespace CarCareTracker.Controllers
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 @@ namespace CarCareTracker.Controllers
}).ToList();
return PartialView("_GasCostByMonthReport", groupedRecord);
}
[HttpGet]
public IActionResult GetAdditionalWidgets()
{
var widgets = _fileHelper.GetWidgets();
return PartialView("_ReportWidgets", widgets);
}
}
}

View File

@ -16,6 +16,8 @@ namespace CarCareTracker.Helper
int ClearTempFolder();
int ClearUnlinkedThumbnails(List<string> linkedImages);
int ClearUnlinkedDocuments(List<string> linkedDocuments);
string GetWidgets();
bool WidgetsExist();
}
public class FileHelper : IFileHelper
{
@ -368,5 +370,27 @@ namespace CarCareTracker.Helper
}
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);
}
}
}

View File

@ -12,6 +12,7 @@ namespace CarCareTracker.Helper
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";

View File

@ -8,5 +8,6 @@
public ReminderMakeUpForVehicle ReminderMakeUpForVehicle { get; set; } = new ReminderMakeUpForVehicle();
public List<int> Years { get; set; } = new List<int>();
public List<UserCollaborator> Collaborators { get; set; } = new List<UserCollaborator>();
public bool CustomWidgetsConfigured { get; set; } = false;
}
}

View File

@ -126,6 +126,12 @@
<div class="d-grid">
<button onclick="exportAttachments()" class="btn btn-secondary btn-md mt-1 mb-1">@translator.Translate(userLanguage, "Export Attachments")<i class="bi ms-2 bi-box-arrow-in-up-right"></i></button>
</div>
@if (Model.CustomWidgetsConfigured)
{
<div class="d-grid">
<button onclick="loadCustomWidgets()" class="btn btn-secondary btn-md mt-1 mb-1">@translator.Translate(userLanguage, "Additional Widgets")<i class="bi ms-2 bi-box-arrow-in-up-right"></i></button>
</div>
}
</div>
</div>
</div>
@ -153,6 +159,15 @@
</div>
</div>
</div>
@if (Model.CustomWidgetsConfigured)
{
<div class="modal fade" data-bs-focus="false" id="vehicleCustomWidgetsModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="vehicleCustomWidgetsModalContent">
</div>
</div>
</div>
}
<div id="vehicleHistoryReport" class="showOnPrint"></div>
<script>

View File

@ -0,0 +1,2 @@
@model string
@Html.Raw(Model)

File diff suppressed because one or more lines are too long

View File

@ -265,3 +265,12 @@ function loadGlobalSearchResult(recordId, recordType) {
break;
}
}
function loadCustomWidgets() {
$.get('/Vehicle/GetAdditionalWidgets', function (data) {
$("#vehicleCustomWidgetsModalContent").html(data);
$("#vehicleCustomWidgetsModal").modal('show');
})
}
function hideCustomWidgetsModal() {
$("#vehicleCustomWidgetsModal").modal('hide');
}