Merge pull request #180 from hargata/Hargata/hr-mpg

Hargata/hr mpg
This commit is contained in:
Hargata Softworks
2024-01-28 07:39:42 -07:00
committed by GitHub
10 changed files with 47 additions and 21 deletions

View File

@@ -538,10 +538,13 @@ namespace CarCareTracker.Controllers
{ {
computedResults = computedResults.OrderByDescending(x => DateTime.Parse(x.Date)).ThenByDescending(x => x.Mileage).ToList(); computedResults = computedResults.OrderByDescending(x => DateTime.Parse(x.Date)).ThenByDescending(x => x.Mileage).ToList();
} }
var vehicleIsElectric = _dataAccess.GetVehicleById(vehicleId).IsElectric; var vehicleData = _dataAccess.GetVehicleById(vehicleId);
var vehicleIsElectric = vehicleData.IsElectric;
var vehicleUseHours = vehicleData.UseHours;
var viewModel = new GasRecordViewModelContainer() var viewModel = new GasRecordViewModelContainer()
{ {
UseKwh = vehicleIsElectric, UseKwh = vehicleIsElectric,
UseHours = vehicleUseHours,
GasRecords = computedResults GasRecords = computedResults
}; };
return PartialView("_Gas", viewModel); return PartialView("_Gas", viewModel);
@@ -564,9 +567,12 @@ namespace CarCareTracker.Controllers
return Json(result); return Json(result);
} }
[HttpGet] [HttpGet]
public IActionResult GetAddGasRecordPartialView() public IActionResult GetAddGasRecordPartialView(int vehicleId)
{ {
return PartialView("_GasModal", new GasRecordInputContainer() { GasRecord = new GasRecordInput() }); var vehicleData = _dataAccess.GetVehicleById(vehicleId);
var vehicleIsElectric = vehicleData.IsElectric;
var vehicleUseHours = vehicleData.UseHours;
return PartialView("_GasModal", new GasRecordInputContainer() { UseKwh = vehicleIsElectric, UseHours = vehicleUseHours, GasRecord = new GasRecordInput() });
} }
[HttpGet] [HttpGet]
public IActionResult GetGasRecordForEditById(int gasRecordId) public IActionResult GetGasRecordForEditById(int gasRecordId)
@@ -585,10 +591,13 @@ namespace CarCareTracker.Controllers
MissedFuelUp = result.MissedFuelUp, MissedFuelUp = result.MissedFuelUp,
Notes = result.Notes Notes = result.Notes
}; };
var vehicleIsElectric = _dataAccess.GetVehicleById(convertedResult.VehicleId).IsElectric; var vehicleData = _dataAccess.GetVehicleById(convertedResult.VehicleId);
var vehicleIsElectric = vehicleData.IsElectric;
var vehicleUseHours = vehicleData.UseHours;
var viewModel = new GasRecordInputContainer() var viewModel = new GasRecordInputContainer()
{ {
UseKwh = vehicleIsElectric, UseKwh = vehicleIsElectric,
UseHours = vehicleUseHours,
GasRecord = convertedResult GasRecord = convertedResult
}; };
return PartialView("_GasModal", viewModel); return PartialView("_GasModal", viewModel);

View File

@@ -2,7 +2,8 @@
{ {
public class GasRecordInputContainer public class GasRecordInputContainer
{ {
public bool UseKwh { get; set; } public bool UseKwh { get; set; }
public GasRecordInput GasRecord { get; set; } public bool UseHours { get; set; }
public GasRecordInput GasRecord { get; set; }
} }
} }

View File

@@ -2,7 +2,8 @@
{ {
public class GasRecordViewModelContainer public class GasRecordViewModelContainer
{ {
public bool UseKwh { get; set; } public bool UseKwh { get; set; }
public List<GasRecordViewModel> GasRecords { get; set; } = new List<GasRecordViewModel>(); public bool UseHours { get; set; }
public List<GasRecordViewModel> GasRecords { get; set; } = new List<GasRecordViewModel>();
} }
} }

View File

@@ -9,5 +9,6 @@
public string Model { get; set; } public string Model { get; set; }
public string LicensePlate { get; set; } public string LicensePlate { get; set; }
public bool IsElectric { get; set; } = false; public bool IsElectric { get; set; } = false;
public bool UseHours { get; set; } = false;
} }
} }

View File

@@ -11,28 +11,29 @@
var useThreeDecimals = userConfig.UseThreeDecimalGasCost; var useThreeDecimals = userConfig.UseThreeDecimalGasCost;
var gasCostFormat = useThreeDecimals ? "C3" : "C2"; var gasCostFormat = useThreeDecimals ? "C3" : "C2";
var useKwh = Model.UseKwh; var useKwh = Model.UseKwh;
var useHours = Model.UseHours;
string consumptionUnit; string consumptionUnit;
string fuelEconomyUnit; string fuelEconomyUnit;
string distanceUnit = useMPG ? "mi." : "km"; string distanceUnit = useHours ? "h" : (useMPG ? "mi." : "km");
if (useKwh) if (useKwh)
{ {
consumptionUnit = "kWh"; consumptionUnit = "kWh";
fuelEconomyUnit = useMPG ? "mi./kWh" : "kWh/100km"; fuelEconomyUnit = useMPG ? $"{distanceUnit}/kWh" : $"kWh/100{distanceUnit}";
} }
else if (useMPG && useUKMPG) else if (useMPG && useUKMPG)
{ {
consumptionUnit = "imp gal"; consumptionUnit = "imp gal";
fuelEconomyUnit = "mpg"; fuelEconomyUnit = useHours ? "h/g" : "mpg";
} else if (useUKMPG) } else if (useUKMPG)
{ {
fuelEconomyUnit = "l/100mi."; fuelEconomyUnit = useHours ? "l/100h" : "l/100mi.";
consumptionUnit = "l"; consumptionUnit = "l";
distanceUnit = "mi."; distanceUnit = useHours ? "h" : "mi.";
} }
else else
{ {
consumptionUnit = useMPG ? "US gal" : "l"; consumptionUnit = useMPG ? "US gal" : "l";
fuelEconomyUnit = useMPG ? "mpg" : "l/100km"; fuelEconomyUnit = useHours ? (useMPG ? "h/g" : "l/100h") : (useMPG ? "mpg" : "l/100km");
} }
} }
<div class="row"> <div class="row">

View File

@@ -5,6 +5,7 @@
var useMPG = config.GetUserConfig(User).UseMPG; var useMPG = config.GetUserConfig(User).UseMPG;
var useUKMPG = config.GetUserConfig(User).UseUKMPG; var useUKMPG = config.GetUserConfig(User).UseUKMPG;
var useKwh = Model.UseKwh; var useKwh = Model.UseKwh;
var useHours = Model.UseHours;
var isNew = Model.GasRecord.Id == 0; var isNew = Model.GasRecord.Id == 0;
string consumptionUnit; string consumptionUnit;
string distanceUnit; string distanceUnit;
@@ -19,7 +20,11 @@
{ {
consumptionUnit = useMPG ? "gallons" : "liters"; consumptionUnit = useMPG ? "gallons" : "liters";
} }
if (useUKMPG) if (useHours)
{
distanceUnit = "hours";
}
else if (useUKMPG)
{ {
distanceUnit = "miles"; distanceUnit = "miles";
} }

View File

@@ -5,22 +5,24 @@
var useMPG = config.GetUserConfig(User).UseMPG; var useMPG = config.GetUserConfig(User).UseMPG;
var useUKMPG = config.GetUserConfig(User).UseUKMPG; var useUKMPG = config.GetUserConfig(User).UseUKMPG;
var useKwh = Model.VehicleData.IsElectric; var useKwh = Model.VehicleData.IsElectric;
var useHours = Model.VehicleData.UseHours;
string fuelEconomyUnit; string fuelEconomyUnit;
if (useKwh) if (useKwh)
{ {
fuelEconomyUnit = useMPG ? "mi./kWh" : "kWh/100km"; var distanceUnit = useHours ? "h" : (useMPG ? "mi." : "km");
fuelEconomyUnit = useMPG ? $"{distanceUnit}/kWh" : $"kWh/100{distanceUnit}";
} }
else if (useMPG && useUKMPG) else if (useMPG && useUKMPG)
{ {
fuelEconomyUnit = "mpg"; fuelEconomyUnit = useHours ? "h/g" : "mpg";
} }
else if (useUKMPG) else if (useUKMPG)
{ {
fuelEconomyUnit = "l/100mi."; fuelEconomyUnit = useHours ? "l/100h" : "l/100mi.";
} }
else else
{ {
fuelEconomyUnit = useMPG ? "mpg" : "l/100km"; fuelEconomyUnit = useHours ? (useMPG ? "h/g" : "l/100h") : (useMPG ? "mpg" : "l/100km");
} }
} }
@model VehicleHistoryViewModel @model VehicleHistoryViewModel

View File

@@ -33,6 +33,10 @@
<input class="form-check-input" type="checkbox" role="switch" id="inputIsElectric" checked="@Model.IsElectric"> <input class="form-check-input" type="checkbox" role="switch" id="inputIsElectric" checked="@Model.IsElectric">
<label class="form-check-label" for="inputIsElectric">Electric Vehicle</label> <label class="form-check-label" for="inputIsElectric">Electric Vehicle</label>
</div> </div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="inputUseHours" checked="@Model.UseHours">
<label class="form-check-label" for="inputUseHours">Use Engine Hours</label>
</div>
@if (!string.IsNullOrWhiteSpace(Model.ImageLocation)) @if (!string.IsNullOrWhiteSpace(Model.ImageLocation))
{ {
<label for="inputImage">Replace picture(optional)</label> <label for="inputImage">Replace picture(optional)</label>

View File

@@ -1,5 +1,5 @@
function showAddGasRecordModal() { function showAddGasRecordModal() {
$.get('/Vehicle/GetAddGasRecordPartialView', function (data) { $.get(`/Vehicle/GetAddGasRecordPartialView?vehicleId=${GetVehicleId().vehicleId}`, function (data) {
if (data) { if (data) {
$("#gasRecordModalContent").html(data); $("#gasRecordModalContent").html(data);
//initiate datepicker //initiate datepicker

View File

@@ -38,6 +38,7 @@ function saveVehicle(isEdit) {
var vehicleModel = $("#inputModel").val(); var vehicleModel = $("#inputModel").val();
var vehicleLicensePlate = $("#inputLicensePlate").val(); var vehicleLicensePlate = $("#inputLicensePlate").val();
var vehicleIsElectric = $("#inputIsElectric").is(":checked"); var vehicleIsElectric = $("#inputIsElectric").is(":checked");
var vehicleUseHours = $("#inputUseHours").is(":checked");
//validate //validate
var hasError = false; var hasError = false;
if (vehicleYear.trim() == '' || parseInt(vehicleYear) < 1900) { if (vehicleYear.trim() == '' || parseInt(vehicleYear) < 1900) {
@@ -74,7 +75,8 @@ function saveVehicle(isEdit) {
make: vehicleMake, make: vehicleMake,
model: vehicleModel, model: vehicleModel,
licensePlate: vehicleLicensePlate, licensePlate: vehicleLicensePlate,
isElectric: vehicleIsElectric isElectric: vehicleIsElectric,
useHours: vehicleUseHours
}, function (data) { }, function (data) {
if (data) { if (data) {
if (!isEdit) { if (!isEdit) {