149 lines
9.1 KiB
Plaintext
149 lines
9.1 KiB
Plaintext
@using CarCareTracker.Helper
|
|
@inject IConfigHelper config
|
|
@inject IGasHelper gasHelper
|
|
@inject ITranslationHelper translator
|
|
@model GasRecordViewModelContainer
|
|
@{
|
|
var userConfig = config.GetUserConfig(User);
|
|
var enableCsvImports = userConfig.EnableCsvImports;
|
|
var useMPG = userConfig.UseMPG;
|
|
var useUKMPG = userConfig.UseUKMPG;
|
|
var hideZero = userConfig.HideZero;
|
|
var useThreeDecimals = userConfig.UseThreeDecimalGasCost;
|
|
var gasCostFormat = useThreeDecimals ? "C3" : "C2";
|
|
var userLanguage = userConfig.UserLanguage;
|
|
var useKwh = Model.UseKwh;
|
|
var useHours = Model.UseHours;
|
|
var recordTags = Model.GasRecords.SelectMany(x => x.Tags).Distinct();
|
|
string preferredFuelEconomyUnit = userConfig.PreferredGasMileageUnit;
|
|
string preferredGasUnit = userConfig.PreferredGasUnit;
|
|
string consumptionUnit;
|
|
string fuelEconomyUnit;
|
|
string distanceUnit = useHours ? "h" : (useMPG ? "mi." : "km");
|
|
if (useKwh)
|
|
{
|
|
consumptionUnit = "kWh";
|
|
fuelEconomyUnit = useMPG ? $"{distanceUnit}/kWh" : $"kWh/100{distanceUnit}";
|
|
}
|
|
else if (useMPG && useUKMPG)
|
|
{
|
|
consumptionUnit = "imp gal";
|
|
fuelEconomyUnit = useHours ? "h/g" : "mpg";
|
|
} else if (useUKMPG)
|
|
{
|
|
fuelEconomyUnit = useHours ? "l/100h" : "l/100mi.";
|
|
consumptionUnit = "l";
|
|
distanceUnit = useHours ? "h" : "mi.";
|
|
}
|
|
else
|
|
{
|
|
consumptionUnit = useMPG ? "US gal" : "l";
|
|
fuelEconomyUnit = useHours ? (useMPG ? "h/g" : "l/100h") : (useMPG ? "mpg" : "l/100km");
|
|
}
|
|
}
|
|
<div class="row">
|
|
<div class="d-flex justify-content-between">
|
|
<div class="d-flex align-items-center flex-wrap">
|
|
<span class="ms-2 badge bg-success" data-aggregate-type="count">@($"{translator.Translate(userLanguage,"# of Gas Records")}: {Model.GasRecords.Count()}")</span>
|
|
@if (Model.GasRecords.Where(x => x.MilesPerGallon > 0).Any())
|
|
{
|
|
<span class="ms-2 badge bg-primary" id="averageFuelMileageLabel">@($"{translator.Translate(userLanguage,"Average Fuel Economy")}: {gasHelper.GetAverageGasMileage(Model.GasRecords, useMPG)}")</span>
|
|
if (useMPG)
|
|
{
|
|
<span class="ms-2 badge bg-primary" id="minFuelMileageLabel">@($"{translator.Translate(userLanguage,"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" id="maxFuelMileageLabel">@($"{translator.Translate(userLanguage,"Max Fuel Economy")}: {Model.GasRecords.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
|
} else
|
|
{
|
|
<span class="ms-2 badge bg-primary" id="minFuelMileageLabel">@($"{translator.Translate(userLanguage,"Min Fuel Economy")}: {Model.GasRecords.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
|
<span class="ms-2 badge bg-primary" id="maxFuelMileageLabel">@($"{translator.Translate(userLanguage,"Max Fuel Economy")}: {Model.GasRecords.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
|
}
|
|
}
|
|
<span class="ms-2 badge bg-success">@($"{translator.Translate(userLanguage,"Total Fuel Consumed")}: {Model.GasRecords.Sum(x => x.Gallons).ToString("F")}")</span>
|
|
<span class="ms-2 badge bg-success" data-aggregate-type="sum">@($"{translator.Translate(userLanguage,"Total Cost")}: {Model.GasRecords.Sum(x => x.Cost).ToString(gasCostFormat)}")</span>
|
|
@foreach (string recordTag in recordTags)
|
|
{
|
|
<span onclick="toggleGasFilter(this)" class="user-select-none ms-2 rounded-pill badge bg-secondary tagfilter" style="cursor:pointer;">@recordTag</span>
|
|
}
|
|
<datalist id="tagList">
|
|
@foreach (string recordTag in recordTags)
|
|
{
|
|
<!option value="@recordTag"></!option>
|
|
}
|
|
</datalist>
|
|
</div>
|
|
@if (enableCsvImports)
|
|
{
|
|
<div class="btn-group">
|
|
<button onclick="showAddGasRecordModal()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>@translator.Translate(userLanguage,"Add Gas Record")</button>
|
|
<button type="button" class="btn btn-md btn-primary btn-md mt-1 mb-1 dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<span class="visually-hidden">Toggle Dropdown</span>
|
|
</button>
|
|
<ul class="dropdown-menu">
|
|
<li><a class="dropdown-item" href="#" onclick="showBulkImportModal('GasRecord')">@translator.Translate(userLanguage,"Import via CSV")</a></li>
|
|
<li><a class="dropdown-item" href="#" onclick="exportVehicleData('GasRecord')">@translator.Translate(userLanguage,"Export to CSV")</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><a class="dropdown-item" href="#" onclick="printTab()">@translator.Translate(userLanguage,"Print")</a></li>
|
|
</ul>
|
|
</div>
|
|
} else {
|
|
<button onclick="showAddGasRecordModal()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>@translator.Translate(userLanguage,"Add Gas Record")</button>
|
|
}
|
|
</div>
|
|
</div>
|
|
<div class="row vehicleDetailTabContainer">
|
|
<div class="col-12">
|
|
<div class="row mt-2 showOnPrint">
|
|
<div class="d-flex">
|
|
<img src="/defaults/lubelogger_logo.png" />
|
|
</div>
|
|
</div>
|
|
<table class="table table-hover">
|
|
<thead class="sticky-top">
|
|
<tr class="d-flex">
|
|
<th scope="col" class="col-2">@translator.Translate(userLanguage,"Date Refueled")</th>
|
|
<th scope="col" class="col-2">@($"{translator.Translate(userLanguage, "Odometer")}({distanceUnit})")</th>
|
|
<th scope="col" class="col-1" style="cursor:pointer;" onclick="toggleSort('gas-tab-pane', this)">@($"Δ({distanceUnit})")</th>
|
|
<th scope="col" class="col-2" data-gas="consumption" data-unit="@consumptionUnit" onclick="toggleSort('gas-tab-pane', this)" oncontextmenu="toggleUnits(this)" style="cursor:pointer;">@($"{translator.Translate(userLanguage,"Consumption")}({consumptionUnit})")</th>
|
|
<th scope="col" class="col-3" data-gas="fueleconomy" data-unit="@fuelEconomyUnit" onclick="toggleSort('gas-tab-pane', this)" oncontextmenu="toggleUnits(this)" style="cursor:pointer;">@($"{@translator.Translate(userLanguage,"Fuel Economy")}({fuelEconomyUnit})")</th>
|
|
<th scope="col" class="col-1" onclick="toggleSort('gas-tab-pane', this)" style="cursor:pointer;">@translator.Translate(userLanguage,"Cost")</th>
|
|
<th scope="col" class="col-1" onclick="toggleSort('gas-tab-pane', this)" style="cursor:pointer;">@translator.Translate(userLanguage,"Unit Cost")</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (GasRecordViewModel gasRecord in Model.GasRecords)
|
|
{
|
|
<tr class="d-flex" style="cursor:pointer;" onclick="showEditGasRecordModal(@gasRecord.Id)" data-tags='@string.Join(" ", gasRecord.Tags)'>
|
|
<td class="col-2">@gasRecord.Date</td>
|
|
<td class="col-2" data-gas-type="mileage" data-gas-aggregate="@gasRecord.DeltaMileage" data-gas-original="@gasRecord.Mileage">@gasRecord.Mileage</td>
|
|
<td class="col-1">@(gasRecord.DeltaMileage == default ? "---" : gasRecord.DeltaMileage)</td>
|
|
<td class="col-2" data-gas-type="consumption" data-gas-aggregate="@gasRecord.Gallons">@gasRecord.Gallons.ToString("F")</td>
|
|
<td class="col-3" data-gas-type="fueleconomy" data-aggregated='@(gasRecord.IncludeInAverage.ToString().ToLower())'>@(gasRecord.MilesPerGallon == 0 ? "---" : gasRecord.MilesPerGallon.ToString("F"))</td>
|
|
<td class="col-1" data-record-type="cost">@((hideZero && gasRecord.Cost == default) ? "---" : gasRecord.Cost.ToString(gasCostFormat))</td>
|
|
<td class="col-1" data-gas-type="unitcost">@((hideZero && gasRecord.CostPerGallon == default) ? "---" : gasRecord.CostPerGallon.ToString(gasCostFormat))</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="modal fade" data-bs-focus="false" id="gasRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg" role="document">
|
|
<div class="modal-content" id="gasRecordModalContent">
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
@if (!string.IsNullOrWhiteSpace(preferredFuelEconomyUnit))
|
|
{
|
|
@:convertFuelMileageUnits(decodeHTMLEntities('@fuelEconomyUnit'), decodeHTMLEntities('@preferredFuelEconomyUnit'), false);
|
|
}
|
|
@if (!string.IsNullOrWhiteSpace(preferredGasUnit))
|
|
{
|
|
@:convertGasConsumptionUnits(decodeHTMLEntities('@consumptionUnit'), decodeHTMLEntities('@preferredGasUnit'), false);
|
|
}
|
|
|
|
</script> |