mirror of
https://github.com/hargata/lubelog.git
synced 2025-12-10 00:46:08 -06:00
Merge pull request #206 from hargata/Hargata/persist.fuel.settings
persist gas tab settings.
This commit is contained in:
commit
c747889f85
@ -608,6 +608,15 @@ namespace CarCareTracker.Controllers
|
|||||||
var result = _gasRecordDataAccess.DeleteGasRecordById(gasRecordId);
|
var result = _gasRecordDataAccess.DeleteGasRecordById(gasRecordId);
|
||||||
return Json(result);
|
return Json(result);
|
||||||
}
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult SaveUserGasTabPreferences(string gasUnit, string fuelMileageUnit)
|
||||||
|
{
|
||||||
|
var currentConfig = _config.GetUserConfig(User);
|
||||||
|
currentConfig.PreferredGasUnit = gasUnit;
|
||||||
|
currentConfig.PreferredGasMileageUnit = fuelMileageUnit;
|
||||||
|
var result = _config.SaveUserConfig(User, currentConfig);
|
||||||
|
return Json(result);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#region "Service Records"
|
#region "Service Records"
|
||||||
[TypeFilter(typeof(CollaboratorFilter))]
|
[TypeFilter(typeof(CollaboratorFilter))]
|
||||||
|
|||||||
@ -108,6 +108,8 @@ namespace CarCareTracker.Helper
|
|||||||
UseThreeDecimalGasCost = bool.Parse(_config[nameof(UserConfig.UseThreeDecimalGasCost)]),
|
UseThreeDecimalGasCost = bool.Parse(_config[nameof(UserConfig.UseThreeDecimalGasCost)]),
|
||||||
EnableAutoReminderRefresh = bool.Parse(_config[nameof(UserConfig.EnableAutoReminderRefresh)]),
|
EnableAutoReminderRefresh = bool.Parse(_config[nameof(UserConfig.EnableAutoReminderRefresh)]),
|
||||||
EnableAutoOdometerInsert = bool.Parse(_config[nameof(UserConfig.EnableAutoOdometerInsert)]),
|
EnableAutoOdometerInsert = bool.Parse(_config[nameof(UserConfig.EnableAutoOdometerInsert)]),
|
||||||
|
PreferredGasMileageUnit = _config[nameof(UserConfig.PreferredGasMileageUnit)],
|
||||||
|
PreferredGasUnit = _config[nameof(UserConfig.PreferredGasUnit)],
|
||||||
VisibleTabs = _config.GetSection("VisibleTabs").Get<List<ImportMode>>(),
|
VisibleTabs = _config.GetSection("VisibleTabs").Get<List<ImportMode>>(),
|
||||||
DefaultTab = (ImportMode)int.Parse(_config[nameof(UserConfig.DefaultTab)])
|
DefaultTab = (ImportMode)int.Parse(_config[nameof(UserConfig.DefaultTab)])
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
public bool UseMarkDownOnSavedNotes { get; set; }
|
public bool UseMarkDownOnSavedNotes { get; set; }
|
||||||
public bool EnableAutoReminderRefresh { get; set; }
|
public bool EnableAutoReminderRefresh { get; set; }
|
||||||
public bool EnableAutoOdometerInsert { get; set; }
|
public bool EnableAutoOdometerInsert { get; set; }
|
||||||
|
public string PreferredGasUnit { get; set; } = string.Empty;
|
||||||
|
public string PreferredGasMileageUnit { get; set; } = string.Empty;
|
||||||
public string UserNameHash { get; set; }
|
public string UserNameHash { get; set; }
|
||||||
public string UserPasswordHash { get; set;}
|
public string UserPasswordHash { get; set;}
|
||||||
public List<ImportMode> VisibleTabs { get; set; } = new List<ImportMode>() {
|
public List<ImportMode> VisibleTabs { get; set; } = new List<ImportMode>() {
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
var gasCostFormat = useThreeDecimals ? "C3" : "C2";
|
var gasCostFormat = useThreeDecimals ? "C3" : "C2";
|
||||||
var useKwh = Model.UseKwh;
|
var useKwh = Model.UseKwh;
|
||||||
var useHours = Model.UseHours;
|
var useHours = Model.UseHours;
|
||||||
|
string preferredFuelEconomyUnit = userConfig.PreferredGasMileageUnit;
|
||||||
|
string preferredGasUnit = userConfig.PreferredGasUnit;
|
||||||
string consumptionUnit;
|
string consumptionUnit;
|
||||||
string fuelEconomyUnit;
|
string fuelEconomyUnit;
|
||||||
string distanceUnit = useHours ? "h" : (useMPG ? "mi." : "km");
|
string distanceUnit = useHours ? "h" : (useMPG ? "mi." : "km");
|
||||||
@ -118,3 +120,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
@if (!string.IsNullOrWhiteSpace(preferredFuelEconomyUnit))
|
||||||
|
{
|
||||||
|
@:convertFuelMileageUnits(decodeHTMLEntities('@fuelEconomyUnit'), decodeHTMLEntities('@preferredFuelEconomyUnit'));
|
||||||
|
}
|
||||||
|
@if (!string.IsNullOrWhiteSpace(preferredGasUnit))
|
||||||
|
{
|
||||||
|
@:convertGasConsumptionUnits(decodeHTMLEntities('@consumptionUnit'), decodeHTMLEntities('@preferredGasUnit'));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@ -17,6 +17,8 @@
|
|||||||
"UseUKMPG": false,
|
"UseUKMPG": false,
|
||||||
"UseThreeDecimalGasCost": true,
|
"UseThreeDecimalGasCost": true,
|
||||||
"UseMarkDownOnSavedNotes": false,
|
"UseMarkDownOnSavedNotes": false,
|
||||||
|
"PreferredGasMileageUnit": "",
|
||||||
|
"PreferredGasUnit": "",
|
||||||
"VisibleTabs": [ 0, 1, 4, 2, 3, 6, 5, 8 ],
|
"VisibleTabs": [ 0, 1, 4, 2, 3, 6, 5, 8 ],
|
||||||
"DefaultTab": 8,
|
"DefaultTab": 8,
|
||||||
"UserNameHash": "",
|
"UserNameHash": "",
|
||||||
|
|||||||
@ -134,13 +134,21 @@ function getAndValidateGasRecordValues() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleUnits(sender) {
|
function saveUserGasTabPreferences() {
|
||||||
event.preventDefault();
|
var gasUnit = $("[data-gas='consumption']").attr("data-unit");
|
||||||
//check which column to convert.
|
var fuelMileageUnit = $("[data-gas='fueleconomy']").attr("data-unit");
|
||||||
sender = $(sender);
|
$.post('/Vehicle/SaveUserGasTabPreferences', { gasUnit: gasUnit, fuelMileageUnit: fuelMileageUnit }, function (data) {
|
||||||
if (sender.attr("data-gas") == "consumption") {
|
if (!data) {
|
||||||
switch (sender.attr("data-unit")) {
|
errorToast("Error Saving User Preferences");
|
||||||
case "US gal":
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertGasConsumptionUnits(currentUnit, destinationUnit) {
|
||||||
|
var sender = $("[data-gas='consumption']");
|
||||||
|
if (currentUnit == "US gal") {
|
||||||
|
switch (destinationUnit) {
|
||||||
|
case "l":
|
||||||
$("[data-gas-type='consumption']").map((index, elem) => {
|
$("[data-gas-type='consumption']").map((index, elem) => {
|
||||||
var convertedAmount = globalParseFloat(elem.innerText) * 3.785;
|
var convertedAmount = globalParseFloat(elem.innerText) * 3.785;
|
||||||
elem.innerText = convertedAmount.toFixed(2);
|
elem.innerText = convertedAmount.toFixed(2);
|
||||||
@ -152,8 +160,40 @@ function toggleUnits(sender) {
|
|||||||
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
||||||
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
||||||
});
|
});
|
||||||
|
setDebounce(saveUserGasTabPreferences);
|
||||||
break;
|
break;
|
||||||
case "l":
|
case "imp gal":
|
||||||
|
$("[data-gas-type='consumption']").map((index, elem) => {
|
||||||
|
var convertedAmount = globalParseFloat(elem.innerText) / 1.201;
|
||||||
|
elem.innerText = convertedAmount.toFixed(2);
|
||||||
|
sender.text(sender.text().replace(sender.attr("data-unit"), "imp gal"));
|
||||||
|
sender.attr("data-unit", "imp gal");
|
||||||
|
});
|
||||||
|
$("[data-gas-type='unitcost']").map((index, elem) => {
|
||||||
|
var convertedAmount = globalParseFloat(elem.innerText) * 1.201;
|
||||||
|
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
||||||
|
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
||||||
|
});
|
||||||
|
setDebounce(saveUserGasTabPreferences);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (currentUnit == "l") {
|
||||||
|
switch (destinationUnit) {
|
||||||
|
case "US gal":
|
||||||
|
$("[data-gas-type='consumption']").map((index, elem) => {
|
||||||
|
var convertedAmount = globalParseFloat(elem.innerText) / 3.785;
|
||||||
|
elem.innerText = convertedAmount.toFixed(2);
|
||||||
|
sender.text(sender.text().replace(sender.attr("data-unit"), "US gal"));
|
||||||
|
sender.attr("data-unit", "US gal");
|
||||||
|
});
|
||||||
|
$("[data-gas-type='unitcost']").map((index, elem) => {
|
||||||
|
var convertedAmount = globalParseFloat(elem.innerText) * 3.785;
|
||||||
|
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
||||||
|
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
||||||
|
});
|
||||||
|
setDebounce(saveUserGasTabPreferences);
|
||||||
|
break;
|
||||||
|
case "imp gal":
|
||||||
$("[data-gas-type='consumption']").map((index, elem) => {
|
$("[data-gas-type='consumption']").map((index, elem) => {
|
||||||
var convertedAmount = globalParseFloat(elem.innerText) / 4.546;
|
var convertedAmount = globalParseFloat(elem.innerText) / 4.546;
|
||||||
elem.innerText = convertedAmount.toFixed(2);
|
elem.innerText = convertedAmount.toFixed(2);
|
||||||
@ -165,8 +205,12 @@ function toggleUnits(sender) {
|
|||||||
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
||||||
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
||||||
});
|
});
|
||||||
|
setDebounce(saveUserGasTabPreferences);
|
||||||
break;
|
break;
|
||||||
case "imp gal":
|
}
|
||||||
|
} else if (currentUnit == "imp gal") {
|
||||||
|
switch (destinationUnit) {
|
||||||
|
case "US gal":
|
||||||
$("[data-gas-type='consumption']").map((index, elem) => {
|
$("[data-gas-type='consumption']").map((index, elem) => {
|
||||||
var convertedAmount = globalParseFloat(elem.innerText) * 1.201;
|
var convertedAmount = globalParseFloat(elem.innerText) * 1.201;
|
||||||
elem.innerText = convertedAmount.toFixed(2);
|
elem.innerText = convertedAmount.toFixed(2);
|
||||||
@ -178,11 +222,31 @@ function toggleUnits(sender) {
|
|||||||
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
||||||
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
||||||
});
|
});
|
||||||
|
setDebounce(saveUserGasTabPreferences);
|
||||||
|
break;
|
||||||
|
case "l":
|
||||||
|
$("[data-gas-type='consumption']").map((index, elem) => {
|
||||||
|
var convertedAmount = globalParseFloat(elem.innerText) * 4.546;
|
||||||
|
elem.innerText = convertedAmount.toFixed(2);
|
||||||
|
sender.text(sender.text().replace(sender.attr("data-unit"), "l"));
|
||||||
|
sender.attr("data-unit", "l");
|
||||||
|
});
|
||||||
|
$("[data-gas-type='unitcost']").map((index, elem) => {
|
||||||
|
var convertedAmount = globalParseFloat(elem.innerText) / 4.546;
|
||||||
|
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
||||||
|
elem.innerText = `${getGlobalConfig().currencySymbol}${convertedAmount.toFixed(decimalPoints)}`;
|
||||||
|
});
|
||||||
|
setDebounce(saveUserGasTabPreferences);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (sender.attr("data-gas") == "fueleconomy") {
|
}
|
||||||
switch (sender.attr("data-unit")) {
|
}
|
||||||
case "l/100km":
|
|
||||||
|
function convertFuelMileageUnits(currentUnit, destinationUnit) {
|
||||||
|
var sender = $("[data-gas='fueleconomy']");
|
||||||
|
if (currentUnit == "l/100km") {
|
||||||
|
switch (destinationUnit) {
|
||||||
|
case "km/l":
|
||||||
$("[data-gas-type='fueleconomy']").map((index, elem) => {
|
$("[data-gas-type='fueleconomy']").map((index, elem) => {
|
||||||
var convertedAmount = globalParseFloat(elem.innerText);
|
var convertedAmount = globalParseFloat(elem.innerText);
|
||||||
if (convertedAmount > 0) {
|
if (convertedAmount > 0) {
|
||||||
@ -208,8 +272,12 @@ function toggleUnits(sender) {
|
|||||||
sender.text(sender.text().replace(sender.attr("data-unit"), "km/l"));
|
sender.text(sender.text().replace(sender.attr("data-unit"), "km/l"));
|
||||||
sender.attr("data-unit", "km/l");
|
sender.attr("data-unit", "km/l");
|
||||||
});
|
});
|
||||||
|
setDebounce(saveUserGasTabPreferences);
|
||||||
break;
|
break;
|
||||||
case "km/l":
|
}
|
||||||
|
} else if (currentUnit == "km/l") {
|
||||||
|
switch (destinationUnit) {
|
||||||
|
case "l/100km":
|
||||||
$("[data-gas-type='fueleconomy']").map((index, elem) => {
|
$("[data-gas-type='fueleconomy']").map((index, elem) => {
|
||||||
var convertedAmount = globalParseFloat(elem.innerText);
|
var convertedAmount = globalParseFloat(elem.innerText);
|
||||||
if (convertedAmount > 0) {
|
if (convertedAmount > 0) {
|
||||||
@ -234,6 +302,35 @@ function toggleUnits(sender) {
|
|||||||
sender.text(sender.text().replace(sender.attr("data-unit"), "l/100km"));
|
sender.text(sender.text().replace(sender.attr("data-unit"), "l/100km"));
|
||||||
sender.attr("data-unit", "l/100km");
|
sender.attr("data-unit", "l/100km");
|
||||||
});
|
});
|
||||||
|
setDebounce(saveUserGasTabPreferences);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleUnits(sender) {
|
||||||
|
event.preventDefault();
|
||||||
|
//check which column to convert.
|
||||||
|
sender = $(sender);
|
||||||
|
if (sender.attr("data-gas") == "consumption") {
|
||||||
|
switch (sender.attr("data-unit")) {
|
||||||
|
case "US gal":
|
||||||
|
convertGasConsumptionUnits("US gal", "l");
|
||||||
|
break;
|
||||||
|
case "l":
|
||||||
|
convertGasConsumptionUnits("l", "imp gal");
|
||||||
|
break;
|
||||||
|
case "imp gal":
|
||||||
|
convertGasConsumptionUnits("imp gal", "US gal");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (sender.attr("data-gas") == "fueleconomy") {
|
||||||
|
switch (sender.attr("data-unit")) {
|
||||||
|
case "l/100km":
|
||||||
|
convertFuelMileageUnits("l/100km", "km/l");
|
||||||
|
break;
|
||||||
|
case "km/l":
|
||||||
|
convertFuelMileageUnits("km/l", "l/100km");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user