Applied VSCode JS formatting settings

This commit is contained in:
Bernd Bestel
2020-08-30 12:18:16 +02:00
parent e0e3212f13
commit 9cea0c77cd
68 changed files with 408 additions and 371 deletions

View File

@@ -122,7 +122,8 @@ function RefreshStatistics()
var overdueCount = 0; var overdueCount = 0;
var now = moment(); var now = moment();
var nextXDaysThreshold = moment().add(nextXDays, "days"); var nextXDaysThreshold = moment().add(nextXDays, "days");
result.forEach(element => { result.forEach(element =>
{
var date = moment(element.next_estimated_charge_time); var date = moment(element.next_estimated_charge_time);
if (date.isBefore(now)) if (date.isBefore(now))
{ {

View File

@@ -17,7 +17,8 @@ var calendar = $("#calendar").fullCalendar({
"eventLimit": false, "eventLimit": false,
"height": "auto", "height": "auto",
"eventSources": fullcalendarEventSources, "eventSources": fullcalendarEventSources,
eventClick: function(info) { eventClick: function(info)
{
location.href = info.link; location.href = info.link;
} }
}); });

View File

@@ -182,7 +182,8 @@ function RefreshStatistics()
var assignedToMeCount = 0; var assignedToMeCount = 0;
var now = moment(); var now = moment();
var nextXDaysThreshold = moment().add(nextXDays, "days"); var nextXDaysThreshold = moment().add(nextXDays, "days");
result.forEach(element => { result.forEach(element =>
{
var date = moment(element.next_estimated_execution_time); var date = moment(element.next_estimated_execution_time);
if (date.isBefore(now)) if (date.isBefore(now))
{ {

View File

@@ -5,14 +5,16 @@ Grocy.Components.BarcodeScanner.CheckCapabilities = async function()
{ {
var track = Quagga.CameraAccess.getActiveTrack(); var track = Quagga.CameraAccess.getActiveTrack();
var capabilities = {}; var capabilities = {};
if (typeof track.getCapabilities === 'function') { if (typeof track.getCapabilities === 'function')
{
capabilities = track.getCapabilities(); capabilities = track.getCapabilities();
} }
// If there is more than 1 camera, show the camera selection // If there is more than 1 camera, show the camera selection
var cameras = await Quagga.CameraAccess.enumerateVideoDevices(); var cameras = await Quagga.CameraAccess.enumerateVideoDevices();
var cameraSelect = document.querySelector('.cameraSelect-wrapper'); var cameraSelect = document.querySelector('.cameraSelect-wrapper');
if (cameraSelect) { if (cameraSelect)
{
cameraSelect.style.display = cameras.length > 1 ? 'inline-block' : 'none'; cameraSelect.style.display = cameras.length > 1 ? 'inline-block' : 'none';
} }
@@ -20,11 +22,13 @@ Grocy.Components.BarcodeScanner.CheckCapabilities = async function()
var canTorch = typeof capabilities.torch === 'boolean' && capabilities.torch var canTorch = typeof capabilities.torch === 'boolean' && capabilities.torch
// Remove the torch button, if either the device can not torch or AutoTorchOn is set. // Remove the torch button, if either the device can not torch or AutoTorchOn is set.
var node = document.querySelector('.torch'); var node = document.querySelector('.torch');
if (node) { if (node)
{
node.style.display = canTorch && !Grocy.FeatureFlags.GROCY_FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA ? 'inline-block' : 'none'; node.style.display = canTorch && !Grocy.FeatureFlags.GROCY_FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA ? 'inline-block' : 'none';
} }
// If AutoTorchOn is set, turn on the torch. // If AutoTorchOn is set, turn on the torch.
if (canTorch && Grocy.FeatureFlags.GROCY_FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA) { if (canTorch && Grocy.FeatureFlags.GROCY_FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA)
{
Grocy.Components.BarcodeScanner.TorchOn(track); Grocy.Components.BarcodeScanner.TorchOn(track);
} }
@@ -142,7 +146,8 @@ Grocy.Components.BarcodeScanner.StopScanning = function()
Grocy.Components.BarcodeScanner.TorchOn = function(track) Grocy.Components.BarcodeScanner.TorchOn = function(track)
{ {
if (track) { if (track)
{
track.applyConstraints({ track.applyConstraints({
advanced: [ advanced: [
{ {
@@ -251,7 +256,8 @@ $(document).on("click", "#barcodescanner-start-button", async function(e)
var cameraSelect = document.querySelector('.cameraSelect'); var cameraSelect = document.querySelector('.cameraSelect');
var cameras = await Quagga.CameraAccess.enumerateVideoDevices(); var cameras = await Quagga.CameraAccess.enumerateVideoDevices();
cameras.forEach(camera => { cameras.forEach(camera =>
{
var option = document.createElement("option"); var option = document.createElement("option");
option.text = camera.label ? camera.label : camera.deviceId; // Use camera label if it exists, else show device id option.text = camera.label ? camera.label : camera.deviceId; // Use camera label if it exists, else show device id
option.value = camera.deviceId; option.value = camera.deviceId;
@@ -261,7 +267,8 @@ $(document).on("click", "#barcodescanner-start-button", async function(e)
// Set initial value to preferred camera if one exists - and if not, start out empty // Set initial value to preferred camera if one exists - and if not, start out empty
cameraSelect.value = window.localStorage.getItem('cameraId'); cameraSelect.value = window.localStorage.getItem('cameraId');
cameraSelect.onchange = function(){ cameraSelect.onchange = function()
{
window.localStorage.setItem('cameraId', cameraSelect.value); window.localStorage.setItem('cameraId', cameraSelect.value);
Quagga.stop(); Quagga.stop();
Grocy.Components.BarcodeScanner.StartScanning(); Grocy.Components.BarcodeScanner.StartScanning();

View File

@@ -157,14 +157,16 @@ Grocy.Components.ProductCard.Refresh = function(productId)
key = dataPoint.shopping_location.name key = dataPoint.shopping_location.name
} }
if (!datasets[key]) { if (!datasets[key])
{
datasets[key] = [] datasets[key] = []
} }
chart.labels.push(moment(dataPoint.date).toDate()); chart.labels.push(moment(dataPoint.date).toDate());
datasets[key].push(dataPoint.price); datasets[key].push(dataPoint.price);
}); });
Object.keys(datasets).forEach((key) => { Object.keys(datasets).forEach((key) =>
{
chart.datasets.push({ chart.datasets.push({
data: datasets[key], data: datasets[key],
fill: false, fill: false,

View File

@@ -17,7 +17,8 @@
var jsonData = {}; var jsonData = {};
jsonData.new_amount = jsonForm.new_amount; jsonData.new_amount = jsonForm.new_amount;
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue(); jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue();
} }
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
@@ -84,7 +85,8 @@
$('#price').val(''); $('#price').val('');
Grocy.Components.DateTimePicker.Clear(); Grocy.Components.DateTimePicker.Clear();
Grocy.Components.ProductPicker.SetValue(''); Grocy.Components.ProductPicker.SetValue('');
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
Grocy.Components.ShoppingLocationPicker.SetValue(''); Grocy.Components.ShoppingLocationPicker.SetValue('');
} }
Grocy.Components.ProductPicker.GetInputElement().focus(); Grocy.Components.ProductPicker.GetInputElement().focus();
@@ -153,7 +155,8 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
} }
$('#price').val(parseFloat(productDetails.last_price).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 })); $('#price').val(parseFloat(productDetails.last_price).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }));
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id); Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id);
} }
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)

View File

@@ -487,7 +487,8 @@ $('#qu_id_purchase').blur(function(e)
// Preset the stock quantity unit with the purchase quantity unit, if the stock quantity unit is unset. // Preset the stock quantity unit with the purchase quantity unit, if the stock quantity unit is unset.
var QuIdStock = $('#qu_id_stock'); var QuIdStock = $('#qu_id_stock');
var QuIdPurchase = $('#qu_id_purchase'); var QuIdPurchase = $('#qu_id_purchase');
if (QuIdStock[0].selectedIndex === 0 && QuIdPurchase[0].selectedIndex !== 0) { if (QuIdStock[0].selectedIndex === 0 && QuIdPurchase[0].selectedIndex !== 0)
{
QuIdStock[0].selectedIndex = QuIdPurchase[0].selectedIndex; QuIdStock[0].selectedIndex = QuIdPurchase[0].selectedIndex;
Grocy.FrontendHelpers.ValidateForm('product-form'); Grocy.FrontendHelpers.ValidateForm('product-form');
} }

View File

@@ -30,7 +30,8 @@
var jsonData = {}; var jsonData = {};
jsonData.amount = amount; jsonData.amount = amount;
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue(); jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue();
} }
jsonData.price = price; jsonData.price = price;
@@ -100,7 +101,8 @@
} }
Grocy.Components.DateTimePicker.Clear(); Grocy.Components.DateTimePicker.Clear();
Grocy.Components.ProductPicker.SetValue(''); Grocy.Components.ProductPicker.SetValue('');
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
Grocy.Components.ShoppingLocationPicker.SetValue(''); Grocy.Components.ShoppingLocationPicker.SetValue('');
} }
Grocy.Components.ProductPicker.GetInputElement().focus(); Grocy.Components.ProductPicker.GetInputElement().focus();
@@ -192,7 +194,8 @@ if (Grocy.Components.ProductPicker !== undefined)
} }
} }
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
if (barcode_shopping_location_id != null) if (barcode_shopping_location_id != null)
{ {
Grocy.Components.ShoppingLocationPicker.SetId(barcode_shopping_location_id); Grocy.Components.ShoppingLocationPicker.SetId(barcode_shopping_location_id);

View File

@@ -39,7 +39,8 @@ $('.save-recipe').on('click', function(e)
const location = $(e.currentTarget).attr('data-location') == 'return' ? '/recipes?recipe=' : '/recipe/'; const location = $(e.currentTarget).attr('data-location') == 'return' ? '/recipes?recipe=' : '/recipe/';
if(Grocy.EditMode == 'create') { if (Grocy.EditMode == 'create')
{
console.log(jsonData); console.log(jsonData);
Grocy.Api.Post('objects/recipes', jsonData, Grocy.Api.Post('objects/recipes', jsonData,
(result) => saveRecipePicture(result, location)); (result) => saveRecipePicture(result, location));
@@ -338,7 +339,8 @@ $('#save-recipe-include-button').on('click', function(e)
} }
}); });
$("#recipe-picture").on("change", function (e) { $("#recipe-picture").on("change", function(e)
{
$("#recipe-picture-label").removeClass("d-none"); $("#recipe-picture-label").removeClass("d-none");
$("#recipe-picture-label-none").addClass("d-none"); $("#recipe-picture-label-none").addClass("d-none");
$("#delete-current-recipe-picture-on-save-hint").addClass("d-none"); $("#delete-current-recipe-picture-on-save-hint").addClass("d-none");
@@ -347,7 +349,8 @@ $("#recipe-picture").on("change", function (e) {
}); });
Grocy.DeleteRecipePictureOnSave = false; Grocy.DeleteRecipePictureOnSave = false;
$("#delete-current-recipe-picture-button").on("click", function (e) { $("#delete-current-recipe-picture-button").on("click", function(e)
{
Grocy.DeleteRecipePictureOnSave = true; Grocy.DeleteRecipePictureOnSave = true;
$("#current-recipe-picture").addClass("d-none"); $("#current-recipe-picture").addClass("d-none");
$("#delete-current-recipe-picture-on-save-hint").removeClass("d-none"); $("#delete-current-recipe-picture-on-save-hint").removeClass("d-none");

View File

@@ -14,7 +14,8 @@
jsonData.amount = jsonForm.amount; jsonData.amount = jsonForm.amount;
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue(); jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
jsonData.purchased_date = Grocy.Components.DateTimePicker2.GetValue(); jsonData.purchased_date = Grocy.Components.DateTimePicker2.GetValue();
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue(); jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue();
} }
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)

View File

@@ -200,7 +200,8 @@ function RefreshStatistics()
function(result) function(result)
{ {
var amountSum = 0; var amountSum = 0;
result.forEach(element => { result.forEach(element =>
{
amountSum += parseInt(element.amount); amountSum += parseInt(element.amount);
}); });
$("#info-current-stock").text(__n(result.length, '%s Product', '%s Products')); $("#info-current-stock").text(__n(result.length, '%s Product', '%s Products'));

View File

@@ -185,7 +185,8 @@ function RefreshStatistics()
var overdueCount = 0; var overdueCount = 0;
var now = moment(); var now = moment();
var nextXDaysThreshold = moment().add(nextXDays, "days"); var nextXDaysThreshold = moment().add(nextXDays, "days");
result.forEach(element => { result.forEach(element =>
{
var date = moment(element.due_date); var date = moment(element.due_date);
if (date.isBefore(now)) if (date.isBefore(now))
{ {

View File

@@ -137,7 +137,8 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
Grocy.Api.Get('stock/products/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(productDetails) function(productDetails)
{ {
if (productDetails.product.enable_tare_weight_handling == 1) { if (productDetails.product.enable_tare_weight_handling == 1)
{
Grocy.Components.ProductPicker.GetPicker().parent().find(".invalid-feedback").text(__t('Products with Tare weight enabled are currently not supported for Transfer. Please select another product.')); Grocy.Components.ProductPicker.GetPicker().parent().find(".invalid-feedback").text(__t('Products with Tare weight enabled are currently not supported for Transfer. Please select another product.'));
Grocy.Components.ProductPicker.Clear(); Grocy.Components.ProductPicker.Clear();
return; return;

View File

@@ -1,10 +1,12 @@
$('input.permission-cb').click( $('input.permission-cb').click(
function () { function()
{
check_hierachy(this.checked, this.name); check_hierachy(this.checked, this.name);
} }
); );
function check_hierachy(checked, name) { function check_hierachy(checked, name)
{
var disabled = checked; var disabled = checked;
$('#permission-sub-' + name).find('input.permission-cb') $('#permission-sub-' + name).find('input.permission-cb')
.prop('checked', disabled) .prop('checked', disabled)
@@ -12,28 +14,37 @@ function check_hierachy(checked, name) {
} }
$('#permission-save').click( $('#permission-save').click(
function () { function()
{
var permission_list = $('input.permission-cb') var permission_list = $('input.permission-cb')
.filter(function () { .filter(function()
{
return $(this).prop('checked') && !$(this).attr('disabled'); return $(this).prop('checked') && !$(this).attr('disabled');
}).map(function () { }).map(function()
{
return $(this).data('perm-id'); return $(this).data('perm-id');
}).toArray(); }).toArray();
Grocy.Api.Put('users/' + Grocy.EditObjectId + '/permissions', { Grocy.Api.Put('users/' + Grocy.EditObjectId + '/permissions', {
'permissions': permission_list, 'permissions': permission_list,
}, function (result) { }, function(result)
{
toastr.success(__t("Permissions saved")); toastr.success(__t("Permissions saved"));
}, function (xhr) { }, function(xhr)
{
toastr.error(__t(JSON.parse(xhr.response).error_message)); toastr.error(__t(JSON.parse(xhr.response).error_message));
} }
); );
} }
); );
if (Grocy.EditObjectId == Grocy.UserId) { if (Grocy.EditObjectId == Grocy.UserId)
$('input.permission-cb[name=ADMIN]').click(function () { {
if (!this.checked) { $('input.permission-cb[name=ADMIN]').click(function()
if (!confirm(__t('Are you sure you want to remove full permissions for yourself?'))) { {
if (!this.checked)
{
if (!confirm(__t('Are you sure you want to remove full permissions for yourself?')))
{
this.checked = true; this.checked = true;
check_hierachy(this.checked, this.name); check_hierachy(this.checked, this.name);
} }