Add possibility to filter products by location (references #10)

This commit is contained in:
Bernd Bestel 2018-07-08 15:16:24 +02:00
parent 92e648490a
commit ecf96252b9
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
5 changed files with 47 additions and 5 deletions

View File

@ -24,6 +24,7 @@ class StockController extends BaseController
return $this->AppContainer->view->render($response, 'stockoverview', [
'products' => $this->Database->products()->orderBy('name'),
'quantityunits' => $this->Database->quantity_units()->orderBy('name'),
'locations' => $this->Database->locations()->orderBy('name'),
'currentStock' => $currentStock,
'missingProducts' => $this->StockService->GetMissingProducts(),
'nextXDays' => $nextXDays,

View File

@ -129,6 +129,7 @@ return array(
'All' => 'Alle',
'Track charge cycle of battery #1' => 'Erfasse einen Ladezyklus für Batterie #1',
'Track execution of habit #1' => 'Erfasse eine Ausführung von #1',
'Filter by location' => 'Nach Standort filtern',
//Constants
'manually' => 'Manuell',

View File

@ -1,10 +1,46 @@
$('#stock-overview-table').DataTable({
var stockOverviewTable = $('#stock-overview-table').DataTable({
'bPaginate': false,
'order': [[3, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
{ 'orderable': false, 'targets': 0 },
{ 'visible': false, 'targets': 4 }
],
'language': JSON.parse(L('datatables_localization'))
'language': JSON.parse(L('datatables_localization')),
"dom": '<"filter-by-location">f'
});
$("div.filter-by-location").html('<div class="dataTables_filter"><label>' + L('Filter by location') + ':<select id="location-filter" class="form-control input-sm" style="margin-left: 0.5em;"></label></div>');
$('#stock-overview-table_wrapper').on("DOMSubtreeModified", function()
{
$('#stock-overview-table_wrapper').off("DOMSubtreeModified");
Grocy.Api.Get('get-objects/locations',
function(locations)
{
$('#location-filter').append($('<option></option>').val("all").html(L("All")));
$.each(locations, function(index)
{
var locationName = locations[index].name;
$('#location-filter').append($('<option></option>').val(locationName).html(locationName));
});
},
function(xhr)
{
console.error(xhr);
}
);
$("#location-filter").on("change", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
stockOverviewTable.column(4).search(value).draw();
});
});
$(document).on('click', '.product-consume-button', function(e)

View File

@ -1,4 +1,4 @@
{
"Version": "1.11.0",
"ReleaseDate": "2018-06-15"
"Version": "1.12.0",
"ReleaseDate": "2018-07-08"
}

View File

@ -29,6 +29,7 @@
<th>{{ $L('Product') }}</th>
<th>{{ $L('Amount') }}</th>
<th>{{ $L('Next best before date') }}</th>
<th class="hidden">Hidden location</th>
</tr>
</thead>
<tbody>
@ -60,6 +61,9 @@
{{ $currentStockEntry->best_before_date }}
<time class="timeago timeago-contextual" datetime="{{ $currentStockEntry->best_before_date }}"></time>
</td>
<td class="hidden">
{{ FindObjectInArrayByPropertyValue($locations, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->location_id)->name }}
</td>
</tr>
@endforeach
</tbody>