Skip to content

Commit

Permalink
make odometer optional
Browse files Browse the repository at this point in the history
  • Loading branch information
hargata committed Sep 25, 2024
1 parent e056aaa commit a653f3a
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Helper/GasHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public List<GasRecordViewModel> GetGasRecordViewModels(List<GasRecord> result, b
if (i > 0)
{
var deltaMileage = currentObject.Mileage - previousMileage;
if (deltaMileage < 0)
{
deltaMileage = 0;
}
var gasRecordViewModel = new GasRecordViewModel()
{
Id = currentObject.Id,
Expand Down
4 changes: 4 additions & 0 deletions Logic/OdometerLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public int GetLastOdometerRecordMileage(int vehicleId, List<OdometerRecord> odom
}
public bool AutoInsertOdometerRecord(OdometerRecord odometer)
{
if (odometer.Mileage == default)
{
return false;
}
var lastReportedMileage = GetLastOdometerRecordMileage(odometer.VehicleId, new List<OdometerRecord>());
odometer.InitialMileage = lastReportedMileage != default ? lastReportedMileage : odometer.Mileage;

Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_CollisionRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>
<label for="collisionRecordMileage">@translator.Translate(userLanguage, "Odometer")</label>
<div class="input-group">
<input type="number" inputmode="numeric" id="collisionRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when repaired")" value="@(isNew ? "" : Model.Mileage)">
<input type="number" inputmode="numeric" id="collisionRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when repaired")" value="@(isNew || Model.Mileage == default ? "" : Model.Mileage)">
@if (isNew)
{
<div class="input-group-text">
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_CollisionRecords.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
{
<tr class="d-flex user-select-none" style="cursor:pointer;" onmouseup="stopEvent()" ontouchstart="detectRowLongTouch(this)" ontouchend="detectRowTouchEndPremature(this)" data-rowId="@collisionRecord.Id" oncontextmenu="showTableContextMenu(this)" onmousemove="rangeMouseMove(this)" onclick="handleTableRowClick(this, showEditCollisionRecordModal,@collisionRecord.Id)" data-tags='@string.Join(" ", collisionRecord.Tags)'>
<td class="col-2 col-xl-1 flex-grow-1" data-column="date" data-date="@StaticHelper.GetEpochFromDateTime(collisionRecord.Date)">@collisionRecord.Date.ToShortDateString()</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="odometer">@collisionRecord.Mileage</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="odometer">@(collisionRecord.Mileage == default ? "---" : collisionRecord.Mileage.ToString())</td>
<td class="col-3 col-xl-4 flex-grow-1 flex-shrink-1" data-column="description">@collisionRecord.Description</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="cost" data-record-type="cost">@((hideZero && collisionRecord.Cost == default) ? "---" : collisionRecord.Cost.ToString("C"))</td>
<td class="col-3 flex-grow-1 flex-shrink-1 text-truncate" data-column="notes">@CarCareTracker.Helper.StaticHelper.TruncateStrings(collisionRecord.Notes)</td>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_Gas.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
{
<tr class="d-flex user-select-none" style="cursor:pointer;" onmouseup="stopEvent()" ontouchstart="detectRowLongTouch(this)" ontouchend="detectRowTouchEndPremature(this)" data-rowId="@gasRecord.Id" oncontextmenu="showTableContextMenu(this)" onmousemove="rangeMouseMove(this)" onclick="handleTableRowClick(this, showEditGasRecordModal,@gasRecord.Id)" data-tags='@string.Join(" ", gasRecord.Tags)'>
<td class="col-2 flex-grow-1" data-column="daterefueled">@gasRecord.Date</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="odometer" data-gas-type="mileage" data-gas-aggregate="@gasRecord.DeltaMileage" data-gas-original="@gasRecord.Mileage">@gasRecord.Mileage</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="odometer" data-gas-type="mileage" data-gas-aggregate="@gasRecord.DeltaMileage" data-gas-original="@gasRecord.Mileage">@(gasRecord.Mileage == default ? "---" : gasRecord.Mileage.ToString())</td>
<td class="col-1 flex-grow-1 flex-shrink-1" data-column="delta">@(gasRecord.DeltaMileage == default ? "---" : gasRecord.DeltaMileage)</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="consumption" data-gas-type="consumption" data-gas-aggregate="@gasRecord.Gallons">@gasRecord.Gallons.ToString("F")</td>
<td class="col-3 flex-grow-1 flex-shrink-1" data-column="fueleconomy" data-gas-type="fueleconomy" data-aggregated='@(gasRecord.IncludeInAverage.ToString().ToLower())'>@(gasRecord.MilesPerGallon == 0 ? "---" : gasRecord.MilesPerGallon.ToString("F"))</td>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_GasModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>
<label for="gasRecordMileage">@($"{translator.Translate(userLanguage,"Odometer Reading")}({distanceUnit})")</label>
<div class="input-group">
<input type="number" inputmode="numeric" id="gasRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when refueled")" value="@(isNew ? "" : Model.GasRecord.Mileage)">
<input type="number" inputmode="numeric" id="gasRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when refueled")" value="@(isNew || Model.GasRecord.Mileage == default ? "" : Model.GasRecord.Mileage)">
@if (isNew)
{
<div class="input-group-text">
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_ServiceRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>
<label for="serviceRecordMileage">@translator.Translate(userLanguage, "Odometer")</label>
<div class="input-group">
<input type="number" inputmode="numeric" id="serviceRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when serviced")" value="@(isNew ? "" : Model.Mileage)">
<input type="number" inputmode="numeric" id="serviceRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when serviced")" value="@(isNew || Model.Mileage == default ? "" : Model.Mileage)">
@if (isNew)
{
<div class="input-group-text">
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_ServiceRecords.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
{
<tr class="d-flex user-select-none" style="cursor:pointer;" onmouseup="stopEvent()" ontouchstart="detectRowLongTouch(this)" ontouchend="detectRowTouchEndPremature(this)" data-rowId="@serviceRecord.Id" oncontextmenu="showTableContextMenu(this)" onmousemove="rangeMouseMove(this)" onclick="handleTableRowClick(this, showEditServiceRecordModal,@serviceRecord.Id)" data-tags='@string.Join(" ", serviceRecord.Tags)'>
<td class="col-2 col-xl-1 flex-grow-1" data-column="date" data-date="@StaticHelper.GetEpochFromDateTime(serviceRecord.Date)">@serviceRecord.Date.ToShortDateString()</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="odometer">@serviceRecord.Mileage</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="odometer">@(serviceRecord.Mileage == default ? "---" : serviceRecord.Mileage.ToString())</td>
<td class="col-3 col-xl-4 flex-grow-1 flex-shrink-1" data-column="description">@serviceRecord.Description</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="cost" data-record-type="cost">@((hideZero && serviceRecord.Cost == default) ? "---" : serviceRecord.Cost.ToString("C"))</td>
<td class="col-3 text-truncate flex-grow-1 flex-shrink-1" data-column="notes">@CarCareTracker.Helper.StaticHelper.TruncateStrings(serviceRecord.Notes)</td>
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_UpgradeRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>
<label for="upgradeRecordMileage">@translator.Translate(userLanguage, "Odometer")</label>
<div class="input-group">
<input type="number" inputmode="numeric" id="upgradeRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when upgraded/modded")" value="@(isNew ? "" : Model.Mileage)">
<input type="number" inputmode="numeric" id="upgradeRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when upgraded/modded")" value="@(isNew || Model.Mileage == default ? "" : Model.Mileage)">
@if (isNew)
{
<div class="input-group-text">
Expand Down
2 changes: 1 addition & 1 deletion Views/Vehicle/_UpgradeRecords.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
{
<tr class="d-flex user-select-none" style="cursor:pointer;" onmouseup="stopEvent()" ontouchstart="detectRowLongTouch(this)" ontouchend="detectRowTouchEndPremature(this)" data-rowId="@upgradeRecord.Id" oncontextmenu="showTableContextMenu(this)" onmousemove="rangeMouseMove(this)" onclick="handleTableRowClick(this, showEditUpgradeRecordModal,@upgradeRecord.Id)" data-tags='@string.Join(" ", upgradeRecord.Tags)'>
<td class="col-2 flex-grow-1 col-xl-1" data-column="date" data-date="@StaticHelper.GetEpochFromDateTime(upgradeRecord.Date)">@upgradeRecord.Date.ToShortDateString()</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="odometer">@upgradeRecord.Mileage</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="odometer">@(upgradeRecord.Mileage == default ? "---" : upgradeRecord.Mileage.ToString())</td>
<td class="col-3 flex-grow-1 flex-shrink-1 col-xl-4" data-column="description">@upgradeRecord.Description</td>
<td class="col-2 flex-grow-1 flex-shrink-1" data-column="cost" data-record-type="cost">@((hideZero && upgradeRecord.Cost == default) ? "---" : upgradeRecord.Cost.ToString("C"))</td>
<td class="col-3 flex-grow-1 flex-shrink-1 text-truncate" data-column="notes">@CarCareTracker.Helper.StaticHelper.TruncateStrings(upgradeRecord.Notes)</td>
Expand Down
3 changes: 3 additions & 0 deletions wwwroot/js/collisionrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ function getAndValidateCollisionRecordValues() {
var collisionRecordId = getCollisionRecordModelData().id;
var addReminderRecord = $("#addReminderCheck").is(":checked");
//Odometer Adjustments
if (isNaN(collisionMileage)) {
collisionMileage = '0';
}
collisionMileage = GetAdjustedOdometer(collisionRecordId, collisionMileage);
//validation
var hasError = false;
Expand Down
3 changes: 3 additions & 0 deletions wwwroot/js/gasrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ function getAndValidateGasRecordValues() {
var vehicleId = GetVehicleId().vehicleId;
var gasRecordId = getGasRecordModelData().id;
//Odometer Adjustments
if (isNaN(gasMileage)) {
gasMileage = '0';
}
gasMileage = GetAdjustedOdometer(gasRecordId, gasMileage);
//validation
var hasError = false;
Expand Down
5 changes: 4 additions & 1 deletion wwwroot/js/planrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ function updatePlanRecordProgress(newProgress) {
showCancelButton: true,
focusConfirm: false,
preConfirm: () => {
const odometer = $("#inputOdometer").val();
var odometer = $("#inputOdometer").val();
if (odometer.trim() == '') {
odometer = '0';
}
if (!odometer || isNaN(odometer)) {
Swal.showValidationMessage(`Please enter an odometer reading`)
}
Expand Down
3 changes: 3 additions & 0 deletions wwwroot/js/servicerecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ function getAndValidateServiceRecordValues() {
var serviceRecordId = getServiceRecordModelData().id;
var addReminderRecord = $("#addReminderCheck").is(":checked");
//Odometer Adjustments
if (isNaN(serviceMileage)) {
serviceMileage = '0';
}
serviceMileage = GetAdjustedOdometer(serviceRecordId, serviceMileage);
//validation
var hasError = false;
Expand Down
3 changes: 3 additions & 0 deletions wwwroot/js/upgraderecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ function getAndValidateUpgradeRecordValues() {
var upgradeRecordId = getUpgradeRecordModelData().id;
var addReminderRecord = $("#addReminderCheck").is(":checked");
//Odometer Adjustments
if (isNaN(upgradeMileage)) {
upgradeMileage = '0';
}
upgradeMileage = GetAdjustedOdometer(upgradeRecordId, upgradeMileage);
//validation
var hasError = false;
Expand Down

0 comments on commit a653f3a

Please sign in to comment.