Skip to content

Commit

Permalink
Merge pull request #683 from hargata/Hargata/kiosk
Browse files Browse the repository at this point in the history
Added kiosk view.
  • Loading branch information
hargata authored Nov 1, 2024
2 parents 7f6265b + 85542cb commit aea8709
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 66 deletions.
68 changes: 13 additions & 55 deletions Controllers/APIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,55 +125,7 @@ public IActionResult VehicleInfo(int vehicleId)
vehicles.AddRange(result);
}

List<VehicleInfo> apiResult = new List<VehicleInfo>();

foreach(Vehicle vehicle in vehicles)
{
var currentMileage = _vehicleLogic.GetMaxMileage(vehicle.Id);
var reminders = _reminderRecordDataAccess.GetReminderRecordsByVehicleId(vehicle.Id);
var results = _reminderHelper.GetReminderRecordViewModels(reminders, currentMileage, DateTime.Now);

var serviceRecords = _serviceRecordDataAccess.GetServiceRecordsByVehicleId(vehicle.Id);
var repairRecords = _collisionRecordDataAccess.GetCollisionRecordsByVehicleId(vehicle.Id);
var upgradeRecords = _upgradeRecordDataAccess.GetUpgradeRecordsByVehicleId(vehicle.Id);
var gasRecords = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicle.Id);
var taxRecords = _taxRecordDataAccess.GetTaxRecordsByVehicleId(vehicle.Id);
var planRecords = _planRecordDataAccess.GetPlanRecordsByVehicleId(vehicle.Id);

var resultToAdd = new VehicleInfo()
{
VehicleData = vehicle,
LastReportedOdometer = currentMileage,
ServiceRecordCount = serviceRecords.Count(),
ServiceRecordCost = serviceRecords.Sum(x=>x.Cost),
RepairRecordCount = repairRecords.Count(),
RepairRecordCost = repairRecords.Sum(x=>x.Cost),
UpgradeRecordCount = upgradeRecords.Count(),
UpgradeRecordCost = upgradeRecords.Sum(x=>x.Cost),
GasRecordCount = gasRecords.Count(),
GasRecordCost = gasRecords.Sum(x=>x.Cost),
TaxRecordCount = taxRecords.Count(),
TaxRecordCost = taxRecords.Sum(x=> x.Cost),
VeryUrgentReminderCount = results.Count(x => x.Urgency == ReminderUrgency.VeryUrgent),
PastDueReminderCount = results.Count(x => x.Urgency == ReminderUrgency.PastDue),
UrgentReminderCount = results.Count(x => x.Urgency == ReminderUrgency.Urgent),
NotUrgentReminderCount = results.Count(x => x.Urgency == ReminderUrgency.NotUrgent),
PlanRecordBackLogCount = planRecords.Count(x=>x.Progress == PlanProgress.Backlog),
PlanRecordInProgressCount = planRecords.Count(x=>x.Progress == PlanProgress.InProgress),
PlanRecordTestingCount = planRecords.Count(x=>x.Progress == PlanProgress.Testing),
PlanRecordDoneCount = planRecords.Count(x=>x.Progress == PlanProgress.Done)
};
//set next reminder
if (results.Any(x => (x.Metric == ReminderMetric.Date || x.Metric == ReminderMetric.Both) && x.Date >= DateTime.Now.Date))
{
resultToAdd.NextReminder = results.Where(x => x.Date >= DateTime.Now.Date).OrderBy(x => x.Date).Select(x => new ReminderExportModel { Description = x.Description, Urgency = x.Urgency.ToString(), Metric = x.Metric.ToString(), Notes = x.Notes, DueDate = x.Date.ToShortDateString(), DueOdometer = x.Mileage.ToString() }).First();
}
else if (results.Any(x => (x.Metric == ReminderMetric.Odometer || x.Metric == ReminderMetric.Both) && x.Mileage >= currentMileage))
{
resultToAdd.NextReminder = results.Where(x => x.Mileage >= currentMileage).OrderBy(x => x.Mileage).Select(x => new ReminderExportModel { Description = x.Description, Urgency = x.Urgency.ToString(), Metric = x.Metric.ToString(), Notes = x.Notes, DueDate = x.Date.ToShortDateString(), DueOdometer = x.Mileage.ToString() }).First();
}
apiResult.Add(resultToAdd);
}
var apiResult = _vehicleLogic.GetVehicleInfo(vehicles);
return Json(apiResult);
}
[TypeFilter(typeof(CollaboratorFilter))]
Expand Down Expand Up @@ -241,7 +193,8 @@ public IActionResult AddServiceRecord(int vehicleId, GenericRecordExportModel in
Description = input.Description,
Notes = string.IsNullOrWhiteSpace(input.Notes) ? "" : input.Notes,
Cost = decimal.Parse(input.Cost),
ExtraFields = input.ExtraFields
ExtraFields = input.ExtraFields,
Tags = string.IsNullOrWhiteSpace(input.Tags) ? new List<string>() : input.Tags.Split(' ').Distinct().ToList()
};
_serviceRecordDataAccess.SaveServiceRecordToVehicle(serviceRecord);
if (_config.GetUserConfig(User).EnableAutoOdometerInsert)
Expand Down Expand Up @@ -318,7 +271,8 @@ public IActionResult AddRepairRecord(int vehicleId, GenericRecordExportModel inp
Description = input.Description,
Notes = string.IsNullOrWhiteSpace(input.Notes) ? "" : input.Notes,
Cost = decimal.Parse(input.Cost),
ExtraFields = input.ExtraFields
ExtraFields = input.ExtraFields,
Tags = string.IsNullOrWhiteSpace(input.Tags) ? new List<string>() : input.Tags.Split(' ').Distinct().ToList()
};
_collisionRecordDataAccess.SaveCollisionRecordToVehicle(repairRecord);
if (_config.GetUserConfig(User).EnableAutoOdometerInsert)
Expand Down Expand Up @@ -395,7 +349,8 @@ public IActionResult AddUpgradeRecord(int vehicleId, GenericRecordExportModel in
Description = input.Description,
Notes = string.IsNullOrWhiteSpace(input.Notes) ? "" : input.Notes,
Cost = decimal.Parse(input.Cost),
ExtraFields = input.ExtraFields
ExtraFields = input.ExtraFields,
Tags = string.IsNullOrWhiteSpace(input.Tags) ? new List<string>() : input.Tags.Split(' ').Distinct().ToList()
};
_upgradeRecordDataAccess.SaveUpgradeRecordToVehicle(upgradeRecord);
if (_config.GetUserConfig(User).EnableAutoOdometerInsert)
Expand Down Expand Up @@ -469,7 +424,8 @@ public IActionResult AddTaxRecord(int vehicleId, TaxRecordExportModel input)
Description = input.Description,
Notes = string.IsNullOrWhiteSpace(input.Notes) ? "" : input.Notes,
Cost = decimal.Parse(input.Cost),
ExtraFields = input.ExtraFields
ExtraFields = input.ExtraFields,
Tags = string.IsNullOrWhiteSpace(input.Tags) ? new List<string>() : input.Tags.Split(' ').Distinct().ToList()
};
_taxRecordDataAccess.SaveTaxRecordToVehicle(taxRecord);
StaticHelper.NotifyAsync(_config.GetWebHookUrl(), vehicleId, User.Identity.Name, $"Added Tax Record via API - Description: {taxRecord.Description}");
Expand Down Expand Up @@ -553,7 +509,8 @@ public IActionResult AddOdometerRecord(int vehicleId, OdometerRecordExportModel
Notes = string.IsNullOrWhiteSpace(input.Notes) ? "" : input.Notes,
InitialMileage = (string.IsNullOrWhiteSpace(input.InitialOdometer) || int.Parse(input.InitialOdometer) == default) ? _odometerLogic.GetLastOdometerRecordMileage(vehicleId, new List<OdometerRecord>()) : int.Parse(input.InitialOdometer),
Mileage = int.Parse(input.Odometer),
ExtraFields = input.ExtraFields
ExtraFields = input.ExtraFields,
Tags = string.IsNullOrWhiteSpace(input.Tags) ? new List<string>() : input.Tags.Split(' ').Distinct().ToList()
};
_odometerRecordDataAccess.SaveOdometerRecordToVehicle(odometerRecord);
StaticHelper.NotifyAsync(_config.GetWebHookUrl(), vehicleId, User.Identity.Name, $"Added Odometer Record via API - Mileage: {odometerRecord.Mileage.ToString()}");
Expand Down Expand Up @@ -634,7 +591,8 @@ public IActionResult AddGasRecord(int vehicleId, GasRecordExportModel input)
MissedFuelUp = bool.Parse(input.MissedFuelUp),
Notes = string.IsNullOrWhiteSpace(input.Notes) ? "" : input.Notes,
Cost = decimal.Parse(input.Cost),
ExtraFields = input.ExtraFields
ExtraFields = input.ExtraFields,
Tags = string.IsNullOrWhiteSpace(input.Tags) ? new List<string>() : input.Tags.Split(' ').Distinct().ToList()
};
_gasRecordDataAccess.SaveGasRecordToVehicle(gasRecord);
if (_config.GetUserConfig(User).EnableAutoOdometerInsert)
Expand Down
26 changes: 22 additions & 4 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ public IActionResult Index(string tab = "garage")
{
return View(model: tab);
}
public IActionResult Kiosk(string exceptions)
{
try {
var exceptionList = string.IsNullOrWhiteSpace(exceptions) ? new List<int>() : exceptions.Split(',').Select(x => int.Parse(x)).ToList();
return View(exceptionList);
}
catch (Exception ex)
{
return View(new List<int>());
}
}
public IActionResult KioskContent(List<int> exceptionList)
{
var vehiclesStored = _dataAccess.GetVehicles();
if (!User.IsInRole(nameof(UserData.IsRootUser)))
{
vehiclesStored = _userLogic.FilterUserVehicles(vehiclesStored, GetUserID());
}
vehiclesStored.RemoveAll(x => exceptionList.Contains(x.Id));
var result = _vehicleLogic.GetVehicleInfo(vehiclesStored);
return PartialView("_Kiosk", result);
}
public IActionResult Garage()
{
var vehiclesStored = _dataAccess.GetVehicles();
Expand Down Expand Up @@ -184,10 +206,6 @@ public IActionResult SaveReminderUrgencyThreshold(ReminderUrgencyConfig reminder
var result = _config.SaveUserConfig(User, existingConfig);
return Json(result);
}
public IActionResult Privacy()
{
return View();
}
[Authorize(Roles = nameof(UserData.IsRootUser))]
public IActionResult GetExtraFieldsModal(int importMode = 0)
{
Expand Down
14 changes: 14 additions & 0 deletions Helper/StaticHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public static string GetTitleCaseReminderUrgency(ReminderUrgency input)
return input.ToString();
}
}
public static string GetTitleCaseReminderUrgency(string input)
{
switch (input)
{
case "NotUrgent":
return "Not Urgent";
case "VeryUrgent":
return "Very Urgent";
case "PastDue":
return "Past Due";
default:
return input;
}
}

public static string TruncateStrings(string input, int maxLength = 25)
{
Expand Down
58 changes: 58 additions & 0 deletions Logic/VehicleLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IVehicleLogic
int GetMinMileage(VehicleRecords vehicleRecords);
int GetOwnershipDays(string purchaseDate, string soldDate, List<ServiceRecord> serviceRecords, List<CollisionRecord> repairRecords, List<GasRecord> gasRecords, List<UpgradeRecord> upgradeRecords, List<OdometerRecord> odometerRecords, List<TaxRecord> taxRecords);
bool GetVehicleHasUrgentOrPastDueReminders(int vehicleId, int currentMileage);
List<VehicleInfo> GetVehicleInfo(List<Vehicle> vehicles);
}
public class VehicleLogic: IVehicleLogic
{
Expand All @@ -24,6 +25,7 @@ public class VehicleLogic: IVehicleLogic
private readonly ITaxRecordDataAccess _taxRecordDataAccess;
private readonly IOdometerRecordDataAccess _odometerRecordDataAccess;
private readonly IReminderRecordDataAccess _reminderRecordDataAccess;
private readonly IPlanRecordDataAccess _planRecordDataAccess;
private readonly IReminderHelper _reminderHelper;
public VehicleLogic(
IServiceRecordDataAccess serviceRecordDataAccess,
Expand All @@ -33,6 +35,7 @@ public VehicleLogic(
ITaxRecordDataAccess taxRecordDataAccess,
IOdometerRecordDataAccess odometerRecordDataAccess,
IReminderRecordDataAccess reminderRecordDataAccess,
IPlanRecordDataAccess planRecordDataAccess,
IReminderHelper reminderHelper
) {
_serviceRecordDataAccess = serviceRecordDataAccess;
Expand All @@ -41,6 +44,7 @@ IReminderHelper reminderHelper
_upgradeRecordDataAccess = upgradeRecordDataAccess;
_taxRecordDataAccess = taxRecordDataAccess;
_odometerRecordDataAccess = odometerRecordDataAccess;
_planRecordDataAccess = planRecordDataAccess;
_reminderRecordDataAccess = reminderRecordDataAccess;
_reminderHelper = reminderHelper;
}
Expand Down Expand Up @@ -218,5 +222,59 @@ public bool GetVehicleHasUrgentOrPastDueReminders(int vehicleId, int currentMile
var results = _reminderHelper.GetReminderRecordViewModels(reminders, currentMileage, DateTime.Now);
return results.Any(x => x.Urgency == ReminderUrgency.VeryUrgent || x.Urgency == ReminderUrgency.PastDue);
}

public List<VehicleInfo> GetVehicleInfo(List<Vehicle> vehicles)
{
List<VehicleInfo> apiResult = new List<VehicleInfo>();

foreach (Vehicle vehicle in vehicles)
{
var currentMileage = GetMaxMileage(vehicle.Id);
var reminders = _reminderRecordDataAccess.GetReminderRecordsByVehicleId(vehicle.Id);
var results = _reminderHelper.GetReminderRecordViewModels(reminders, currentMileage, DateTime.Now);

var serviceRecords = _serviceRecordDataAccess.GetServiceRecordsByVehicleId(vehicle.Id);
var repairRecords = _collisionRecordDataAccess.GetCollisionRecordsByVehicleId(vehicle.Id);
var upgradeRecords = _upgradeRecordDataAccess.GetUpgradeRecordsByVehicleId(vehicle.Id);
var gasRecords = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicle.Id);
var taxRecords = _taxRecordDataAccess.GetTaxRecordsByVehicleId(vehicle.Id);
var planRecords = _planRecordDataAccess.GetPlanRecordsByVehicleId(vehicle.Id);

var resultToAdd = new VehicleInfo()
{
VehicleData = vehicle,
LastReportedOdometer = currentMileage,
ServiceRecordCount = serviceRecords.Count(),
ServiceRecordCost = serviceRecords.Sum(x => x.Cost),
RepairRecordCount = repairRecords.Count(),
RepairRecordCost = repairRecords.Sum(x => x.Cost),
UpgradeRecordCount = upgradeRecords.Count(),
UpgradeRecordCost = upgradeRecords.Sum(x => x.Cost),
GasRecordCount = gasRecords.Count(),
GasRecordCost = gasRecords.Sum(x => x.Cost),
TaxRecordCount = taxRecords.Count(),
TaxRecordCost = taxRecords.Sum(x => x.Cost),
VeryUrgentReminderCount = results.Count(x => x.Urgency == ReminderUrgency.VeryUrgent),
PastDueReminderCount = results.Count(x => x.Urgency == ReminderUrgency.PastDue),
UrgentReminderCount = results.Count(x => x.Urgency == ReminderUrgency.Urgent),
NotUrgentReminderCount = results.Count(x => x.Urgency == ReminderUrgency.NotUrgent),
PlanRecordBackLogCount = planRecords.Count(x => x.Progress == PlanProgress.Backlog),
PlanRecordInProgressCount = planRecords.Count(x => x.Progress == PlanProgress.InProgress),
PlanRecordTestingCount = planRecords.Count(x => x.Progress == PlanProgress.Testing),
PlanRecordDoneCount = planRecords.Count(x => x.Progress == PlanProgress.Done)
};
//set next reminder
if (results.Any(x => (x.Metric == ReminderMetric.Date || x.Metric == ReminderMetric.Both) && x.Date >= DateTime.Now.Date))
{
resultToAdd.NextReminder = results.Where(x => x.Date >= DateTime.Now.Date).OrderBy(x => x.Date).Select(x => new ReminderExportModel { Description = x.Description, Urgency = x.Urgency.ToString(), Metric = x.Metric.ToString(), Notes = x.Notes, DueDate = x.Date.ToShortDateString(), DueOdometer = x.Mileage.ToString() }).First();
}
else if (results.Any(x => (x.Metric == ReminderMetric.Odometer || x.Metric == ReminderMetric.Both) && x.Mileage >= currentMileage))
{
resultToAdd.NextReminder = results.Where(x => x.Mileage >= currentMileage).OrderBy(x => x.Mileage).Select(x => new ReminderExportModel { Description = x.Description, Urgency = x.Urgency.ToString(), Metric = x.Metric.ToString(), Notes = x.Notes, DueDate = x.Date.ToShortDateString(), DueOdometer = x.Mileage.ToString() }).First();
}
apiResult.Add(resultToAdd);
}
return apiResult;
}
}
}
62 changes: 62 additions & 0 deletions Views/Home/Kiosk.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@{
ViewData["Title"] = "Kiosk";
}
@model List<int>
<div class="progress" role="progressbar" aria-label="Refresh Progress" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="height: 1px">
<div class="progress-bar" style="width: 0%"></div>
</div>
<div id="kioskContainer" class="container-fluid">
</div>
<script>
let refreshTimer;
let exceptionList = [];
let subtractAmount = 0;
@foreach(int exception in Model)
{
@:exceptionList.push(@exception);
}
function initKiosk() {
$("body > div").removeClass("container");
$("body > div").css('height', '100vh');
subtractAmount = parseInt($("#kioskContainer").width() * 0.0016); //remove 0.0016% of width every 100 ms which will approximate to one minute.
if (subtractAmount < 2) {
subtractAmount = 2;
}
retrieveKioskContent();
}
function retrieveKioskContent(){
clearInterval(refreshTimer);
$.post('/Home/KioskContent', {exceptionList: exceptionList}, function (data) {
$("#kioskContainer").html(data);
$(".progress-bar").width($("#kioskContainer").width());
setTimeout(function () { startTimer() }, 500);
});
}
function startTimer() {
refreshTimer = setInterval(function () {
var currentWidth = $(".progress-bar").width();
if (currentWidth > 0) {
$(".progress-bar").width(currentWidth - subtractAmount);
} else {
retrieveKioskContent();
}
}, 100);
}
function addVehicleToExceptionList(vehicleId) {
Swal.fire({
title: "Remove Vehicle from Dashboard?",
text: "Removed vehicles can be restored by refreshing the page",
showCancelButton: true,
confirmButtonText: "Remove",
confirmButtonColor: "#dc3545"
}).then((result) => {
if (result.isConfirmed) {
exceptionList.push(vehicleId);
retrieveKioskContent();
}
});
}
initKiosk();
</script>
6 changes: 0 additions & 6 deletions Views/Home/Privacy.cshtml

This file was deleted.

Loading

0 comments on commit aea8709

Please sign in to comment.