From 4a909e5c44e8655b80c43393f54f999aadce390d Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Thu, 29 Feb 2024 11:36:54 -0700 Subject: [PATCH] Added extra fields functionality to fuel tab. --- Helper/GasHelper.cs | 6 +- Models/GasRecord/GasRecordViewModel.cs | 1 + Views/Vehicle/_Gas.cshtml | 136 +++++++++++++++++++------ 3 files changed, 108 insertions(+), 35 deletions(-) diff --git a/Helper/GasHelper.cs b/Helper/GasHelper.cs index a71b5d5..d564cf2 100644 --- a/Helper/GasHelper.cs +++ b/Helper/GasHelper.cs @@ -71,7 +71,8 @@ namespace CarCareTracker.Helper IsFillToFull = currentObject.IsFillToFull, MissedFuelUp = currentObject.MissedFuelUp, Notes = currentObject.Notes, - Tags = currentObject.Tags + Tags = currentObject.Tags, + ExtraFields = currentObject.ExtraFields }; if (currentObject.MissedFuelUp) { @@ -124,7 +125,8 @@ namespace CarCareTracker.Helper IsFillToFull = currentObject.IsFillToFull, MissedFuelUp = currentObject.MissedFuelUp, Notes = currentObject.Notes, - Tags = currentObject.Tags + Tags = currentObject.Tags, + ExtraFields = currentObject.ExtraFields }); } previousMileage = currentObject.Mileage; diff --git a/Models/GasRecord/GasRecordViewModel.cs b/Models/GasRecord/GasRecordViewModel.cs index 6086114..a4b3f30 100644 --- a/Models/GasRecord/GasRecordViewModel.cs +++ b/Models/GasRecord/GasRecordViewModel.cs @@ -22,6 +22,7 @@ public bool MissedFuelUp { get; set; } public string Notes { get; set; } public List Tags { get; set; } = new List(); + public List ExtraFields { get; set; } = new List(); public bool IncludeInAverage { get { return MilesPerGallon > 0 || (!IsFillToFull && !MissedFuelUp); } } } } diff --git a/Views/Vehicle/_Gas.cshtml b/Views/Vehicle/_Gas.cshtml index 3f8abd3..8c3bd00 100644 --- a/Views/Vehicle/_Gas.cshtml +++ b/Views/Vehicle/_Gas.cshtml @@ -29,7 +29,8 @@ { consumptionUnit = "imp gal"; fuelEconomyUnit = useHours ? "h/g" : "mpg"; - } else if (useUKMPG) + } + else if (useUKMPG) { fuelEconomyUnit = useHours ? "l/100h" : "l/100mi."; consumptionUnit = "l"; @@ -40,26 +41,32 @@ consumptionUnit = useMPG ? "US gal" : "l"; fuelEconomyUnit = useHours ? (useMPG ? "h/g" : "l/100h") : (useMPG ? "mpg" : "l/100km"); } + var extraFields = new List(); + if (userConfig.EnableExtraFieldColumns) + { + extraFields = Model.GasRecords.SelectMany(x => x.ExtraFields).Select(y => y.Name).Distinct().ToList(); + } }
- @($"{translator.Translate(userLanguage,"# of Gas Records")}: {Model.GasRecords.Count()}") + @($"{translator.Translate(userLanguage, "# of Gas Records")}: {Model.GasRecords.Count()}") @if (Model.GasRecords.Where(x => x.MilesPerGallon > 0).Any()) { - @($"{translator.Translate(userLanguage,"Average Fuel Economy")}: {gasHelper.GetAverageGasMileage(Model.GasRecords, useMPG)}") + @($"{translator.Translate(userLanguage, "Average Fuel Economy")}: {gasHelper.GetAverageGasMileage(Model.GasRecords, useMPG)}") if (useMPG) { - @($"{translator.Translate(userLanguage,"Min Fuel Economy")}: {Model.GasRecords.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}") - @($"{translator.Translate(userLanguage,"Max Fuel Economy")}: {Model.GasRecords.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}") - } else + @($"{translator.Translate(userLanguage, "Min Fuel Economy")}: {Model.GasRecords.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}") + @($"{translator.Translate(userLanguage, "Max Fuel Economy")}: {Model.GasRecords.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}") + } + else { - @($"{translator.Translate(userLanguage,"Min Fuel Economy")}: {Model.GasRecords.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}") - @($"{translator.Translate(userLanguage,"Max Fuel Economy")}: {Model.GasRecords.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}") + @($"{translator.Translate(userLanguage, "Min Fuel Economy")}: {Model.GasRecords.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}") + @($"{translator.Translate(userLanguage, "Max Fuel Economy")}: {Model.GasRecords.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}") } } - @($"{translator.Translate(userLanguage,"Total Fuel Consumed")}: {Model.GasRecords.Sum(x => x.Gallons).ToString("F")}") - @($"{translator.Translate(userLanguage,"Total Cost")}: {Model.GasRecords.Sum(x => x.Cost).ToString(gasCostFormat)}") + @($"{translator.Translate(userLanguage, "Total Fuel Consumed")}: {Model.GasRecords.Sum(x => x.Gallons).ToString("F")}") + @($"{translator.Translate(userLanguage, "Total Cost")}: {Model.GasRecords.Sum(x => x.Cost).ToString(gasCostFormat)}") @foreach (string recordTag in recordTags) { @recordTag @@ -74,19 +81,75 @@ @if (enableCsvImports) {
- +
- } else { - + } + else + { + }
@@ -100,26 +163,34 @@ - - - - - - - + + + + + + + + @foreach (string extraFieldColumn in extraFields) + { + + } @foreach (GasRecordViewModel gasRecord in Model.GasRecords) { - - - - - - - + + + + + + + + @foreach (string extraFieldColumn in extraFields) + { + + } } @@ -131,7 +202,6 @@ @@ -149,8 +219,8 @@ { @:convertFuelMileageUnits(decodeHTMLEntities('@fuelEconomyUnit'), decodeHTMLEntities('@preferredFuelEconomyUnit'), false); } - @if (!string.IsNullOrWhiteSpace(preferredGasUnit)) - { + @if (!string.IsNullOrWhiteSpace(preferredGasUnit)) + { @:convertGasConsumptionUnits(decodeHTMLEntities('@consumptionUnit'), decodeHTMLEntities('@preferredGasUnit'), false); }
@translator.Translate(userLanguage,"Date Refueled")@($"{translator.Translate(userLanguage, "Odometer")}({distanceUnit})")@($"Δ({distanceUnit})")@($"{translator.Translate(userLanguage,"Consumption")}({consumptionUnit})")@($"{@translator.Translate(userLanguage,"Fuel Economy")}({fuelEconomyUnit})")@translator.Translate(userLanguage,"Cost")@translator.Translate(userLanguage,"Unit Cost")@translator.Translate(userLanguage, "Date Refueled")@($"{translator.Translate(userLanguage, "Odometer")}({distanceUnit})")@($"Δ({distanceUnit})")@($"{translator.Translate(userLanguage, "Consumption")}({consumptionUnit})")@($"{@translator.Translate(userLanguage, "Fuel Economy")}({fuelEconomyUnit})")@translator.Translate(userLanguage, "Cost")@translator.Translate(userLanguage, "Unit Cost")
@gasRecord.Date@gasRecord.Mileage@(gasRecord.DeltaMileage == default ? "---" : gasRecord.DeltaMileage)@gasRecord.Gallons.ToString("F")@(gasRecord.MilesPerGallon == 0 ? "---" : gasRecord.MilesPerGallon.ToString("F"))@((hideZero && gasRecord.Cost == default) ? "---" : gasRecord.Cost.ToString(gasCostFormat))@((hideZero && gasRecord.CostPerGallon == default) ? "---" : gasRecord.CostPerGallon.ToString(gasCostFormat))@gasRecord.Date@gasRecord.Mileage@(gasRecord.DeltaMileage == default ? "---" : gasRecord.DeltaMileage)@gasRecord.Gallons.ToString("F")@(gasRecord.MilesPerGallon == 0 ? "---" : gasRecord.MilesPerGallon.ToString("F"))@((hideZero && gasRecord.Cost == default) ? "---" : gasRecord.Cost.ToString(gasCostFormat))@((hideZero && gasRecord.CostPerGallon == default) ? "---" : gasRecord.CostPerGallon.ToString(gasCostFormat))