Skip to content

Commit

Permalink
Merge pull request #105 from hargata/Hargata/qol
Browse files Browse the repository at this point in the history
Quality of Life Improvements.
  • Loading branch information
hargata authored Jan 15, 2024
2 parents 4ccfcd6 + d268694 commit b03460d
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 25 deletions.
11 changes: 10 additions & 1 deletion Controllers/APIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ public IActionResult TaxRecords(int vehicleId)
public IActionResult GasRecords(int vehicleId, bool useMPG, bool useUKMPG)
{
var vehicleRecords = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicleId);
var result = _gasHelper.GetGasRecordViewModels(vehicleRecords, useMPG, useUKMPG).Select(x => new GasRecordExportModel { Date = x.Date, Odometer = x.Mileage.ToString(), Cost = x.Cost.ToString(), FuelConsumed = x.Gallons.ToString(), FuelEconomy = x.MilesPerGallon.ToString()});
var result = _gasHelper.GetGasRecordViewModels(vehicleRecords, useMPG, useUKMPG)
.Select(x => new GasRecordExportModel {
Date = x.Date,
Odometer = x.Mileage.ToString(),
Cost = x.Cost.ToString(),
FuelConsumed = x.Gallons.ToString(),
FuelEconomy = x.MilesPerGallon.ToString(),
IsFillToFull = x.IsFillToFull.ToString(),
MissedFuelUp = x.MissedFuelUp.ToString()
});
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
Expand Down
17 changes: 13 additions & 4 deletions Controllers/VehicleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,15 @@ public IActionResult ExportFromVehicleToCsv(int vehicleId, ImportMode mode)
bool useUKMPG = _config.GetUserConfig(User).UseUKMPG;
vehicleRecords = vehicleRecords.OrderBy(x => x.Date).ThenBy(x => x.Mileage).ToList();
var convertedRecords = _gasHelper.GetGasRecordViewModels(vehicleRecords, useMPG, useUKMPG);
var exportData = convertedRecords.Select(x => new GasRecordExportModel { Date = x.Date.ToString(), Cost = x.Cost.ToString(), FuelConsumed = x.Gallons.ToString(), FuelEconomy = x.MilesPerGallon.ToString(), Odometer = x.Mileage.ToString() });
var exportData = convertedRecords.Select(x => new GasRecordExportModel {
Date = x.Date.ToString(),
Cost = x.Cost.ToString(),
FuelConsumed = x.Gallons.ToString(),
FuelEconomy = x.MilesPerGallon.ToString(),
Odometer = x.Mileage.ToString(),
IsFillToFull = x.IsFillToFull.ToString(),
MissedFuelUp = x.MissedFuelUp.ToString()
});
using (var writer = new StreamWriter(fullExportFilePath))
{
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
Expand Down Expand Up @@ -302,12 +310,14 @@ public IActionResult ImportToVehicleIdFromCsv(int vehicleId, ImportMode mode, st
convertedRecord.IsFillToFull = !parsedBool;
} else if (!string.IsNullOrWhiteSpace(importModel.IsFillToFull))
{
var parsedBool = importModel.IsFillToFull.Trim() == "1" || importModel.IsFillToFull.Trim() == "Full";
var possibleFillToFullValues = new List<string> { "1", "true", "full" };
var parsedBool = possibleFillToFullValues.Contains(importModel.IsFillToFull.Trim().ToLower());
convertedRecord.IsFillToFull = parsedBool;
}
if (!string.IsNullOrWhiteSpace(importModel.MissedFuelUp))
{
var parsedBool = importModel.MissedFuelUp.Trim() == "1";
var possibleMissedFuelUpValues = new List<string> { "1", "true" };
var parsedBool = possibleMissedFuelUpValues.Contains(importModel.MissedFuelUp.Trim().ToLower());
convertedRecord.MissedFuelUp = parsedBool;
}
//insert record into db, check to make sure fuelconsumed is not zero so we don't get a divide by zero error.
Expand Down Expand Up @@ -634,7 +644,6 @@ public IActionResult GetReportPartialView(int vehicleId)
allCosts.AddRange(_reportHelper.GetServiceRecordSum(serviceRecords, 0));
allCosts.AddRange(_reportHelper.GetRepairRecordSum(collisionRecords, 0));
allCosts.AddRange(_reportHelper.GetUpgradeRecordSum(upgradeRecords, 0));
allCosts.AddRange(_reportHelper.GetUpgradeRecordSum(upgradeRecords, 0));
allCosts.AddRange(_reportHelper.GetGasRecordSum(gasRecords, 0));
allCosts.AddRange(_reportHelper.GetTaxRecordSum(taxRecords, 0));
viewModel.CostForVehicleByMonth = allCosts.GroupBy(x => new { x.MonthName, x.MonthId }).OrderBy(x => x.Key.MonthId).Select(x => new CostForVehicleByMonth
Expand Down
8 changes: 6 additions & 2 deletions Helper/GasHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public List<GasRecordViewModel> GetGasRecordViewModels(List<GasRecord> result, b
Gallons = convertedConsumption,
Cost = currentObject.Cost,
DeltaMileage = deltaMileage,
CostPerGallon = currentObject.Cost / convertedConsumption
CostPerGallon = currentObject.Cost / convertedConsumption,
IsFillToFull = currentObject.IsFillToFull,
MissedFuelUp = currentObject.MissedFuelUp
};
if (currentObject.MissedFuelUp)
{
Expand Down Expand Up @@ -81,7 +83,9 @@ public List<GasRecordViewModel> GetGasRecordViewModels(List<GasRecord> result, b
Cost = currentObject.Cost,
DeltaMileage = 0,
MilesPerGallon = 0,
CostPerGallon = currentObject.Cost / convertedConsumption
CostPerGallon = currentObject.Cost / convertedConsumption,
IsFillToFull = currentObject.IsFillToFull,
MissedFuelUp = currentObject.MissedFuelUp
});
}
previousMileage = currentObject.Mileage;
Expand Down
2 changes: 1 addition & 1 deletion MapProfile/FuellyMappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public FuellyMapper()
Map(m => m.PartialFuelUp).Name(["partial_fuelup"]);
Map(m => m.IsFillToFull).Name(["isfilltofull", "filled up"]);
Map(m => m.Description).Name(["description"]);
Map(m => m.MissedFuelUp).Name(["missed_fuelup"]);
Map(m => m.MissedFuelUp).Name(["missed_fuelup", "missedfuelup"]);
}
}
}
2 changes: 1 addition & 1 deletion Models/Collision/CollisionRecordInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class CollisionRecordInput
{
public int Id { get; set; }
public int VehicleId { get; set; }
public string Date { get; set; }
public string Date { get; set; } = DateTime.Now.ToShortDateString();
public int Mileage { get; set; }
public string Description { get; set; }
public decimal Cost { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Models/GasRecord/GasRecordInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class GasRecordInput
{
public int Id { get; set; }
public int VehicleId { get; set; }
public string Date { get; set; }
public string Date { get; set; } = DateTime.Now.ToShortDateString();
/// <summary>
/// American moment
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Models/GasRecord/GasRecordViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public class GasRecordViewModel
public int DeltaMileage { get; set; }
public decimal MilesPerGallon { get; set; }
public decimal CostPerGallon { get; set; }
public bool IsFillToFull { get; set; }
public bool MissedFuelUp { get; set; }
}
}
2 changes: 2 additions & 0 deletions Models/ImportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class GasRecordExportModel
public string FuelConsumed { get; set; }
public string Cost { get; set; }
public string FuelEconomy { get; set; }
public string IsFillToFull { get; set; }
public string MissedFuelUp { get; set; }
}
public class ReminderExportModel
{
Expand Down
2 changes: 1 addition & 1 deletion Models/ServiceRecord/ServiceRecordInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class ServiceRecordInput
{
public int Id { get; set; }
public int VehicleId { get; set; }
public string Date { get; set; }
public string Date { get; set; } = DateTime.Now.ToShortDateString();
public int Mileage { get; set; }
public string Description { get; set; }
public decimal Cost { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Models/TaxRecord/TaxRecordInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class TaxRecordInput
{
public int Id { get; set; }
public int VehicleId { get; set; }
public string Date { get; set; }
public string Date { get; set; } = DateTime.Now.ToShortDateString();
public string Description { get; set; }
public decimal Cost { get; set; }
public string Notes { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Models/Upgrades/UpgradeReportInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class UpgradeRecordInput
{
public int Id { get; set; }
public int VehicleId { get; set; }
public string Date { get; set; }
public string Date { get; set; } = DateTime.Now.ToShortDateString();
public int Mileage { get; set; }
public string Description { get; set; }
public decimal Cost { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Views/Admin/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</div>
</div>
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-4">Token</th>
<th scope="col" class="col-6">Issued To</th>
Expand All @@ -62,7 +62,7 @@
<span class="lead">Users</span>
<hr />
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-4">Username</th>
<th scope="col" class="col-4">Email</th>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_CollisionRecords.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</div>
</div>
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-1">Date</th>
<th scope="col" class="col-2">Odometer</th>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_Gas.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</div>
</div>
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-2">Date Refueled</th>
<th scope="col" class="col-2">Odometer(@(distanceUnit))</th>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_Notes.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
</div>
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-3">Description</th>
<th scope="col" class="col-9">Note</th>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_ReminderRecords.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
</div>
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-1">Urgency</th>
<th scope="col" class="col-2">Metric</th>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_ServiceRecords.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</div>
</div>
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-1">Date</th>
<th scope="col" class="col-2">Odometer</th>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_TaxRecords.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</div>
</div>
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-1">Date</th>
<th scope="col" class="col-6">Description</th>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_UpgradeRecords.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</div>
</div>
<table class="table table-hover">
<thead>
<thead class="sticky-top">
<tr class="d-flex">
<th scope="col" class="col-1">Date</th>
<th scope="col" class="col-2">Odometer</th>
Expand Down
4 changes: 4 additions & 0 deletions wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,7 @@ html {
display: none;
}
}

.dropdown-menu.show{
z-index: 1030;
}
6 changes: 3 additions & 3 deletions wwwroot/defaults/gassample.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Date,Odometer,FuelConsumed,Cost
5/8/2020,204836,8.331,16.24
5/30/2020,205056,11.913,25.72
Date,Odometer,FuelConsumed,Cost,IsFillToFull,MissedFuelUp
5/8/2020,204836,8.331,16.24,True,False
5/30/2020,205056,11.913,25.72,True,False

0 comments on commit b03460d

Please sign in to comment.