moved electric vehicle flag to vehicle level.
This commit is contained in:
@@ -45,8 +45,7 @@ namespace CarCareTracker.Controllers
|
|||||||
UseDarkMode = bool.Parse(_config[nameof(UserConfig.UseDarkMode)]),
|
UseDarkMode = bool.Parse(_config[nameof(UserConfig.UseDarkMode)]),
|
||||||
UseMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]),
|
UseMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]),
|
||||||
UseDescending = bool.Parse(_config[nameof(UserConfig.UseDescending)]),
|
UseDescending = bool.Parse(_config[nameof(UserConfig.UseDescending)]),
|
||||||
EnableAuth = bool.Parse(_config[nameof(UserConfig.EnableAuth)]),
|
EnableAuth = bool.Parse(_config[nameof(UserConfig.EnableAuth)])
|
||||||
UsekWh = bool.Parse(_config[nameof(UserConfig.UsekWh)])
|
|
||||||
};
|
};
|
||||||
return PartialView("_Settings", userConfig);
|
return PartialView("_Settings", userConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,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();
|
||||||
}
|
}
|
||||||
return PartialView("_Gas", computedResults);
|
var vehicleIsElectric = _dataAccess.GetVehicleById(vehicleId).IsElectric;
|
||||||
|
var viewModel = new GasRecordViewModelContainer()
|
||||||
|
{
|
||||||
|
UseKwh = vehicleIsElectric,
|
||||||
|
GasRecords = computedResults
|
||||||
|
};
|
||||||
|
return PartialView("_Gas", viewModel);
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult SaveGasRecordToVehicleId(GasRecordInput gasRecord)
|
public IActionResult SaveGasRecordToVehicleId(GasRecordInput gasRecord)
|
||||||
@@ -332,7 +338,13 @@ namespace CarCareTracker.Controllers
|
|||||||
Gallons = result.Gallons,
|
Gallons = result.Gallons,
|
||||||
IsFillToFull = result.IsFillToFull
|
IsFillToFull = result.IsFillToFull
|
||||||
};
|
};
|
||||||
return PartialView("_GasModal", convertedResult);
|
var vehicleIsElectric = _dataAccess.GetVehicleById(convertedResult.VehicleId).IsElectric;
|
||||||
|
var viewModel = new GasRecordInputContainer()
|
||||||
|
{
|
||||||
|
UseKwh = vehicleIsElectric,
|
||||||
|
GasRecord = convertedResult
|
||||||
|
};
|
||||||
|
return PartialView("_GasModal", viewModel);
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult DeleteGasRecordById(int gasRecordId)
|
public IActionResult DeleteGasRecordById(int gasRecordId)
|
||||||
|
|||||||
8
Models/GasRecord/GasRecordInputContainer.cs
Normal file
8
Models/GasRecord/GasRecordInputContainer.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace CarCareTracker.Models
|
||||||
|
{
|
||||||
|
public class GasRecordInputContainer
|
||||||
|
{
|
||||||
|
public bool UseKwh { get; set; }
|
||||||
|
public GasRecordInput GasRecord { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Models/GasRecord/GasRecordViewModelContainer.cs
Normal file
8
Models/GasRecord/GasRecordViewModelContainer.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace CarCareTracker.Models
|
||||||
|
{
|
||||||
|
public class GasRecordViewModelContainer
|
||||||
|
{
|
||||||
|
public bool UseKwh { get; set; }
|
||||||
|
public List<GasRecordViewModel> GasRecords { get; set; } = new List<GasRecordViewModel>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
public class UserConfig
|
public class UserConfig
|
||||||
{
|
{
|
||||||
public bool UseDarkMode { get; set; }
|
public bool UseDarkMode { get; set; }
|
||||||
public bool UsekWh { get; set; }
|
|
||||||
public bool EnableCsvImports { get; set; }
|
public bool EnableCsvImports { get; set; }
|
||||||
public bool UseMPG { get; set; }
|
public bool UseMPG { get; set; }
|
||||||
public bool UseDescending { get; set; }
|
public bool UseDescending { get; set; }
|
||||||
|
|||||||
@@ -8,5 +8,6 @@
|
|||||||
public string Make { get; set; }
|
public string Make { get; set; }
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,6 @@
|
|||||||
<input class="form-check-input" onChange="updateSettings()" type="checkbox" role="switch" id="useMPG" checked="@Model.UseMPG">
|
<input class="form-check-input" onChange="updateSettings()" type="checkbox" role="switch" id="useMPG" checked="@Model.UseMPG">
|
||||||
<label class="form-check-label" for="useMPG">Use Imperial Calculation for Fuel Economy Calculations(MPG)<br /><small class="text-body-secondary">This Will Also Change Units to Miles and Gallons</small></label>
|
<label class="form-check-label" for="useMPG">Use Imperial Calculation for Fuel Economy Calculations(MPG)<br /><small class="text-body-secondary">This Will Also Change Units to Miles and Gallons</small></label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check form-switch">
|
|
||||||
<input class="form-check-input" onChange="updateSettings()" type="checkbox" role="switch" id="usekWh" checked="@Model.UsekWh">
|
|
||||||
<label class="form-check-label" for="usekWh">Electric Car(Gas Consumption Units will be replaced with kWh)</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-md-6">
|
<div class="col-12 col-md-6">
|
||||||
<div class="form-check form-switch">
|
<div class="form-check form-switch">
|
||||||
@@ -80,8 +76,7 @@
|
|||||||
useDarkMode: $("#enableDarkMode").is(':checked'),
|
useDarkMode: $("#enableDarkMode").is(':checked'),
|
||||||
enableCsvImports: $("#enableCsvImports").is(':checked'),
|
enableCsvImports: $("#enableCsvImports").is(':checked'),
|
||||||
useMPG: $("#useMPG").is(':checked'),
|
useMPG: $("#useMPG").is(':checked'),
|
||||||
useDescending: $("#useDescending").is(':checked'),
|
useDescending: $("#useDescending").is(':checked')
|
||||||
usekWh: $("#usekWh").is(':checked')
|
|
||||||
}
|
}
|
||||||
$.post('/Home/WriteToSettings', { userConfig: userConfigObject}, function(data){
|
$.post('/Home/WriteToSettings', { userConfig: userConfigObject}, function(data){
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
@inject IConfiguration Configuration
|
@inject IConfiguration Configuration
|
||||||
|
@model GasRecordViewModelContainer
|
||||||
@{
|
@{
|
||||||
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
|
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
|
||||||
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
||||||
var useKwh = bool.Parse(Configuration[nameof(UserConfig.UsekWh)]);
|
var useKwh = Model.UseKwh;
|
||||||
string consumptionUnit;
|
string consumptionUnit;
|
||||||
string fuelEconomyUnit;
|
string fuelEconomyUnit;
|
||||||
if (useKwh)
|
if (useKwh)
|
||||||
@@ -15,19 +16,18 @@
|
|||||||
fuelEconomyUnit = useMPG ? "mpg" : "l/100km";
|
fuelEconomyUnit = useMPG ? "mpg" : "l/100km";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@model List<GasRecordViewModel>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<div class="d-flex align-items-center flex-wrap">
|
<div class="d-flex align-items-center flex-wrap">
|
||||||
<span class="ms-2 badge bg-success">@($"# of Gas Records: {Model.Count()}")</span>
|
<span class="ms-2 badge bg-success">@($"# of Gas Records: {Model.GasRecords.Count()}")</span>
|
||||||
@if (Model.Where(x=>x.MilesPerGallon > 0).Any())
|
@if (Model.GasRecords.Where(x => x.MilesPerGallon > 0).Any())
|
||||||
{
|
{
|
||||||
<span class="ms-2 badge bg-primary">@($"Average Fuel Economy: {Model.Where(y => y.MilesPerGallon > 0)?.Average(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
<span class="ms-2 badge bg-primary">@($"Average Fuel Economy: {Model.GasRecords.Where(y => y.MilesPerGallon > 0)?.Average(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
||||||
<span class="ms-2 badge bg-primary">@($"Min Fuel Economy: {Model.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
<span class="ms-2 badge bg-primary">@($"Min Fuel Economy: {Model.GasRecords.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
||||||
<span class="ms-2 badge bg-primary">@($"Max Fuel Economy: {Model.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
<span class="ms-2 badge bg-primary">@($"Max Fuel Economy: {Model.GasRecords.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
||||||
}
|
}
|
||||||
<span class="ms-2 badge bg-success">@($"Total Fuel Consumed: {Model.Sum(x=>x.Gallons).ToString("F")}")</span>
|
<span class="ms-2 badge bg-success">@($"Total Fuel Consumed: {Model.GasRecords.Sum(x => x.Gallons).ToString("F")}")</span>
|
||||||
<span class="ms-2 badge bg-success">@($"Total Cost: {Model.Sum(x => x.Cost).ToString("C3")}")</span>
|
<span class="ms-2 badge bg-success">@($"Total Cost: {Model.GasRecords.Sum(x => x.Cost).ToString("C3")}")</span>
|
||||||
</div>
|
</div>
|
||||||
@if (enableCsvImports)
|
@if (enableCsvImports)
|
||||||
{
|
{
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (GasRecordViewModel gasRecord in Model)
|
@foreach (GasRecordViewModel gasRecord in Model.GasRecords)
|
||||||
{
|
{
|
||||||
<tr class="d-flex" style="cursor:pointer;" onclick="showEditGasRecordModal(@gasRecord.Id)">
|
<tr class="d-flex" style="cursor:pointer;" onclick="showEditGasRecordModal(@gasRecord.Id)">
|
||||||
<td class="col-2">@gasRecord.Date</td>
|
<td class="col-2">@gasRecord.Date</td>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
@inject IConfiguration Configuration
|
@inject IConfiguration Configuration
|
||||||
@model GasRecordInput
|
@model GasRecordInputContainer
|
||||||
@{
|
@{
|
||||||
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
|
||||||
var useKwh = bool.Parse(Configuration[nameof(UserConfig.UsekWh)]);
|
var useKwh = Model.UseKwh;
|
||||||
var isNew = Model.Id == 0;
|
var isNew = Model.GasRecord.Id == 0;
|
||||||
string consumptionUnit;
|
string consumptionUnit;
|
||||||
if (useKwh)
|
if (useKwh)
|
||||||
{
|
{
|
||||||
@@ -26,26 +26,26 @@
|
|||||||
<input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;">
|
<input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;">
|
||||||
<label for="gasRecordDate">Date</label>
|
<label for="gasRecordDate">Date</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" id="gasRecordDate" placeholder="Date refueled" class="form-control" value="@Model.Date">
|
<input type="text" id="gasRecordDate" placeholder="Date refueled" class="form-control" value="@Model.GasRecord.Date">
|
||||||
<span class="input-group-text"><i class="bi bi-calendar-event"></i></span>
|
<span class="input-group-text"><i class="bi bi-calendar-event"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<label for="gasRecordMileage">Odometer Reading(@(useMPG ? "miles" : "kilometers"))</label>
|
<label for="gasRecordMileage">Odometer Reading(@(useMPG ? "miles" : "kilometers"))</label>
|
||||||
<input type="number" id="gasRecordMileage" class="form-control" placeholder="Odometer reading when refueled" value="@(isNew ? "" : Model.Mileage)">
|
<input type="number" id="gasRecordMileage" class="form-control" placeholder="Odometer reading when refueled" value="@(isNew ? "" : Model.GasRecord.Mileage)">
|
||||||
<label for="gasRecordGallons">Fuel Consumption(@(consumptionUnit))</label>
|
<label for="gasRecordGallons">Fuel Consumption(@(consumptionUnit))</label>
|
||||||
<input type="text" id="gasRecordGallons" class="form-control" placeholder="Amount of gas refueled" value="@(isNew ? "" : Model.Gallons)">
|
<input type="text" id="gasRecordGallons" class="form-control" placeholder="Amount of gas refueled" value="@(isNew ? "" : Model.GasRecord.Gallons)">
|
||||||
<div class="form-check form-switch">
|
<div class="form-check form-switch">
|
||||||
<input class="form-check-input" type="checkbox" role="switch" id="gasIsFillToFull" checked="@Model.IsFillToFull">
|
<input class="form-check-input" type="checkbox" role="switch" id="gasIsFillToFull" checked="@Model.GasRecord.IsFillToFull">
|
||||||
<label class="form-check-label" for="gasIsFillToFull">Is Filled To Full</label>
|
<label class="form-check-label" for="gasIsFillToFull">Is Filled To Full</label>
|
||||||
</div>
|
</div>
|
||||||
<label for="GasRecordCost">Cost</label>
|
<label for="GasRecordCost">Cost</label>
|
||||||
<input type="number" id="gasRecordCost" class="form-control" placeholder="Cost of gas refueled" value="@(isNew ? "" : Model.Cost)">
|
<input type="number" id="gasRecordCost" class="form-control" placeholder="Cost of gas refueled" value="@(isNew ? "" : Model.GasRecord.Cost)">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 col-12">
|
<div class="col-md-6 col-12">
|
||||||
@if (Model.Files.Any())
|
@if (Model.GasRecord.Files.Any())
|
||||||
{
|
{
|
||||||
<div>
|
<div>
|
||||||
<label>Uploaded Documents</label>
|
<label>Uploaded Documents</label>
|
||||||
@foreach (UploadedFiles filesUploaded in Model.Files)
|
@foreach (UploadedFiles filesUploaded in Model.GasRecord.Files)
|
||||||
{
|
{
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
|
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
@if (!isNew)
|
@if (!isNew)
|
||||||
{
|
{
|
||||||
<button type="button" class="btn btn-danger" onclick="deleteGasRecord(@Model.Id)" style="margin-right:auto;">Delete</button>
|
<button type="button" class="btn btn-danger" onclick="deleteGasRecord(@Model.GasRecord.Id)" style="margin-right:auto;">Delete</button>
|
||||||
}
|
}
|
||||||
<button type="button" class="btn btn-secondary" onclick="hideAddGasRecordModal()">Cancel</button>
|
<button type="button" class="btn btn-secondary" onclick="hideAddGasRecordModal()">Cancel</button>
|
||||||
@if (isNew)
|
@if (isNew)
|
||||||
@@ -85,12 +85,12 @@
|
|||||||
var uploadedFiles = [];
|
var uploadedFiles = [];
|
||||||
getUploadedFilesFromModel();
|
getUploadedFilesFromModel();
|
||||||
function getUploadedFilesFromModel() {
|
function getUploadedFilesFromModel() {
|
||||||
@foreach (UploadedFiles filesUploaded in Model.Files)
|
@foreach (UploadedFiles filesUploaded in Model.GasRecord.Files)
|
||||||
{
|
{
|
||||||
@:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location" });
|
@:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getGasRecordModelData(){
|
function getGasRecordModelData(){
|
||||||
return {id: @Model.Id}
|
return { id: @Model.GasRecord.Id}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -20,6 +20,10 @@
|
|||||||
<input type="text" id="inputModel" class="form-control" placeholder="Model" value="@Model.Model">
|
<input type="text" id="inputModel" class="form-control" placeholder="Model" value="@Model.Model">
|
||||||
<label for="inputLicensePlate">License Plate</label>
|
<label for="inputLicensePlate">License Plate</label>
|
||||||
<input type="text" id="inputLicensePlate" class="form-control" placeholder="License Plate" value="@Model.LicensePlate">
|
<input type="text" id="inputLicensePlate" class="form-control" placeholder="License Plate" value="@Model.LicensePlate">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input class="form-check-input" type="checkbox" role="switch" id="inputIsElectric" checked="@Model.IsElectric">
|
||||||
|
<label class="form-check-label" for="inputIsElectric">Electric Vehicle</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>
|
||||||
|
|||||||
@@ -12,6 +12,5 @@
|
|||||||
"UseDescending": false,
|
"UseDescending": false,
|
||||||
"EnableAuth": false,
|
"EnableAuth": false,
|
||||||
"UserNameHash": "",
|
"UserNameHash": "",
|
||||||
"UserPasswordHash": "",
|
"UserPasswordHash": ""
|
||||||
"UsekWh": false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ function saveVehicle(isEdit) {
|
|||||||
var vehicleMake = $("#inputMake").val();
|
var vehicleMake = $("#inputMake").val();
|
||||||
var vehicleModel = $("#inputModel").val();
|
var vehicleModel = $("#inputModel").val();
|
||||||
var vehicleLicensePlate = $("#inputLicensePlate").val();
|
var vehicleLicensePlate = $("#inputLicensePlate").val();
|
||||||
|
var vehicleIsElectric = $("#inputIsElectric").is(":checked");
|
||||||
//validate
|
//validate
|
||||||
var hasError = false;
|
var hasError = false;
|
||||||
if (vehicleYear.trim() == '' || parseInt(vehicleYear) < 1900) {
|
if (vehicleYear.trim() == '' || parseInt(vehicleYear) < 1900) {
|
||||||
@@ -72,7 +73,8 @@ function saveVehicle(isEdit) {
|
|||||||
year: vehicleYear,
|
year: vehicleYear,
|
||||||
make: vehicleMake,
|
make: vehicleMake,
|
||||||
model: vehicleModel,
|
model: vehicleModel,
|
||||||
licensePlate: vehicleLicensePlate
|
licensePlate: vehicleLicensePlate,
|
||||||
|
isElectric: vehicleIsElectric
|
||||||
}, function (data) {
|
}, function (data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
if (!isEdit) {
|
if (!isEdit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user