Add journal and undo UI for stock bookings, chore executions and battery charge cycles (closes #63, closes #97)

This commit is contained in:
Bernd Bestel
2018-10-27 17:26:00 +02:00
parent fe83e2fa6f
commit 364f6b2051
28 changed files with 541 additions and 92 deletions

View File

@@ -0,0 +1,70 @@
var batteriesJournalTable = $('#batteries-journal-table').DataTable({
'paginate': true,
'order': [[1, 'desc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true,
'stateSaveParams': function(settings, data)
{
data.search.search = "";
data.columns.forEach(column =>
{
column.search.search = "";
});
}
});
$("#battery-filter").on("change", function()
{
var value = $(this).val();
var text = $("#battery-filter option:selected").text();
if (value === "all")
{
text = "";
}
batteriesJournalTable.column(1).search(text).draw();
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
batteriesJournalTable.search(value).draw();
});
if (typeof GetUriParam("battery") !== "undefined")
{
$("#battery-filter").val(GetUriParam("battery"));
$("#battery-filter").trigger("change");
}
$(document).on('click', '.undo-battery-execution-button', function(e)
{
e.preventDefault();
var element = $(e.currentTarget);
var chargeCycleId = $(e.currentTarget).attr('data-charge-cycle-id');
Grocy.Api.Get('batteries/undo-charge-cycle/' + chargeCycleId.toString(),
function(result)
{
element.closest("tr").addClass("text-muted");
element.closest(".undo-battery-execution-button").addClass("disabled");
toastr.success(L("Charge cycle successfully undone"));
},
function(xhr)
{
console.error(xhr);
}
);
});

View File

@@ -10,7 +10,7 @@
Grocy.Api.Get('batteries/track-charge-cycle/' + jsonForm.battery_id + '?tracked_time=' + $('#tracked_time').find('input').val(),
function(result)
{
toastr.success(L('Tracked charge cylce of battery #1 on #2', batteryDetails.battery.name, $('#tracked_time').find('input').val()));
toastr.success(L('Tracked charge cycle of battery #1 on #2', batteryDetails.battery.name, $('#tracked_time').find('input').val()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoChargeCycle(' + result.charge_cycle_id + ')"><i class="fas fa-undo"></i> ' + L("Undo") + '</a>');
$('#battery_id').val('');
$('#battery_id_text_input').focus();
@@ -86,3 +86,16 @@ $('#tracked_time').find('input').on('keypress', function (e)
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
});
function UndoChargeCycle(chargeCycleId)
{
Grocy.Api.Get('batteries/undo-charge-cycle/' + chargeCycleId.toString(),
function(result)
{
toastr.success(L("Charge cycle successfully undone"));
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -1,46 +0,0 @@
var choresAnalysisTable = $('#chores-analysis-table').DataTable({
'paginate': false,
'order': [[1, 'desc']],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true,
'stateSaveParams': function(settings, data)
{
data.search.search = "";
data.columns.forEach(column =>
{
column.search.search = "";
});
}
});
$("#chore-filter").on("change", function()
{
var value = $(this).val();
var text = $("#chore-filter option:selected").text();
if (value === "all")
{
text = "";
}
choresAnalysisTable.column(0).search(text).draw();
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
choresAnalysisTable.search(value).draw();
});
if (typeof GetUriParam("chore") !== "undefined")
{
$("#chore-filter").val(GetUriParam("chore"));
$("#chore-filter").trigger("change");
}

View File

@@ -0,0 +1,70 @@
var choresJournalTable = $('#chores-journal-table').DataTable({
'paginate': true,
'order': [[1, 'desc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true,
'stateSaveParams': function(settings, data)
{
data.search.search = "";
data.columns.forEach(column =>
{
column.search.search = "";
});
}
});
$("#chore-filter").on("change", function()
{
var value = $(this).val();
var text = $("#chore-filter option:selected").text();
if (value === "all")
{
text = "";
}
choresJournalTable.column(1).search(text).draw();
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
choresJournalTable.search(value).draw();
});
if (typeof GetUriParam("chore") !== "undefined")
{
$("#chore-filter").val(GetUriParam("chore"));
$("#chore-filter").trigger("change");
}
$(document).on('click', '.undo-chore-execution-button', function(e)
{
e.preventDefault();
var element = $(e.currentTarget);
var executionId = $(e.currentTarget).attr('data-execution-id');
Grocy.Api.Get('chores/undo-chore-execution/' + executionId.toString(),
function(result)
{
element.closest("tr").addClass("text-muted");
element.closest(".undo-chore-execution-button").addClass("disabled");
toastr.success(L("Chore execution successfully undone"));
},
function(xhr)
{
console.error(xhr);
}
);
});

View File

@@ -10,7 +10,7 @@
Grocy.Api.Get('chores/track-chore-execution/' + jsonForm.chore_id + '?tracked_time=' + Grocy.Components.DateTimePicker.GetValue() + "&done_by=" + Grocy.Components.UserPicker.GetValue(),
function(result)
{
toastr.success(L('Tracked execution of chore #1 on #2', choreDetails.chore.name, Grocy.Components.DateTimePicker.GetValue()));
toastr.success(L('Tracked execution of chore #1 on #2', choreDetails.chore.name, Grocy.Components.DateTimePicker.GetValue()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoChoreExecution(' + result.chore_execution_id + ')"><i class="fas fa-undo"></i> ' + L("Undo") + '</a>');
$('#chore_id').val('');
$('#chore_id_text_input').focus();
@@ -82,3 +82,17 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
{
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
});
function UndoChoreExecution(executionId)
{
Grocy.Api.Get('chores/undo-chore-execution/' + executionId.toString(),
function(result)
{
toastr.success(L("Chore execution successfully undone"));
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -16,7 +16,7 @@
Grocy.Api.Get('stock/consume-product/' + jsonForm.product_id + '/' + jsonForm.amount + '?spoiled=' + spoiled,
function(result)
{
toastr.success(L('Removed #1 #2 of #3 from stock', jsonForm.amount, Pluralize(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name));
toastr.success(L('Removed #1 #2 of #3 from stock', jsonForm.amount, Pluralize(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBooking(' + result.booking_id + ')"><i class="fas fa-undo"></i> ' + L("Undo") + '</a>');
$('#amount').val(1);
Grocy.Components.ProductPicker.SetValue('');
@@ -102,3 +102,17 @@ $('#consume-form input').keydown(function(event)
}
}
});
function UndoStockBooking(bookingId)
{
Grocy.Api.Get('stock/undo-booking/' + bookingId.toString(),
function(result)
{
toastr.success(L("Booking successfully undone"));
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -32,7 +32,7 @@
);
}
toastr.success(L('Stock amount of #1 is now #2 #3', productDetails.product.name, jsonForm.new_amount, Pluralize(jsonForm.new_amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)));
toastr.success(L('Stock amount of #1 is now #2 #3', productDetails.product.name, jsonForm.new_amount, Pluralize(jsonForm.new_amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBooking(' + result.booking_id + ')"><i class="fas fa-undo"></i> ' + L("Undo") + '</a>');
if (addBarcode !== undefined)
{
@@ -186,3 +186,17 @@ $('#new_amount').on('keyup', function(e)
);
}
});
function UndoStockBooking(bookingId)
{
Grocy.Api.Get('stock/undo-booking/' + bookingId.toString(),
function(result)
{
toastr.success(L("Booking successfully undone"));
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -5,7 +5,7 @@
var jsonForm = $('#purchase-form').serializeJSON();
Grocy.Api.Get('stock/get-product-details/' + jsonForm.product_id,
function (productDetails)
function(productDetails)
{
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
@@ -40,7 +40,7 @@
);
}
toastr.success(L('Added #1 #2 of #3 to stock', amount, Pluralize(amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name));
toastr.success(L('Added #1 #2 of #3 to stock', amount, Pluralize(amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBooking(' + result.booking_id + ')"><i class="fas fa-undo"></i> ' + L("Undo") + '</a>');
if (addBarcode !== undefined)
{
@@ -171,3 +171,17 @@ $('#amount').on('change', function (e)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
function UndoStockBooking(bookingId)
{
Grocy.Api.Get('stock/undo-booking/' + bookingId.toString(),
function(result)
{
toastr.success(L("Booking successfully undone"));
},
function(xhr)
{
console.error(xhr);
}
);
};

View File

@@ -0,0 +1,70 @@
var stockJournalTable = $('#stock-journal-table').DataTable({
'paginate': true,
'order': [[3, 'desc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true,
'stateSaveParams': function(settings, data)
{
data.search.search = "";
data.columns.forEach(column =>
{
column.search.search = "";
});
}
});
$("#product-filter").on("change", function()
{
var value = $(this).val();
var text = $("#product-filter option:selected").text();
if (value === "all")
{
text = "";
}
stockJournalTable.column(1).search(text).draw();
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
stockJournalTable.search(value).draw();
});
if (typeof GetUriParam("product") !== "undefined")
{
$("#product-filter").val(GetUriParam("product"));
$("#product-filter").trigger("change");
}
$(document).on('click', '.undo-stock-booking-button', function(e)
{
e.preventDefault();
var element = $(e.currentTarget);
var bookingId = $(e.currentTarget).attr('data-booking-id');
Grocy.Api.Get('stock/undo-booking/' + bookingId.toString(),
function(result)
{
element.closest("tr").addClass("text-muted");
element.closest(".undo-stock-booking-button").addClass("disabled");
toastr.success(L("Booking successfully undone"));
},
function(xhr)
{
console.error(xhr);
}
);
});