Make it possible to test quantity unit plural forms (closes #261)

This commit is contained in:
Bernd Bestel
2019-09-18 20:21:09 +02:00
parent 8f798a94d1
commit 346b589534
8 changed files with 127 additions and 1 deletions

View File

@@ -37,12 +37,13 @@
- Product Userfields are now also rendered on the shopping list (for items which have a product referenced) - Product Userfields are now also rendered on the shopping list (for items which have a product referenced)
- Fixed that the Userfield type "Preset list" had always the caption "Product group" instead of the configured one (thanks @oncleben31) - Fixed that the Userfield type "Preset list" had always the caption "Product group" instead of the configured one (thanks @oncleben31)
### General improvements/fixes ### General & other improvements/fixes
- Added a new `config.php` setting `CALENDAR_SHOW_WEEK_OF_YEAR` to configure if calendars should show week numbers (defaults to `true`) - Added a new `config.php` setting `CALENDAR_SHOW_WEEK_OF_YEAR` to configure if calendars should show week numbers (defaults to `true`)
- Fixed that datetimepickers not considered the `config.php` setting `CALENDAR_FIRST_DAY_OF_WEEK` - Fixed that datetimepickers not considered the `config.php` setting `CALENDAR_FIRST_DAY_OF_WEEK`
- Improved the handling which entry page to use with disabled feature flags (thanks @nielstholenaar) - Improved the handling which entry page to use with disabled feature flags (thanks @nielstholenaar)
- Boolean settings provided via environment variables (so the strings `true` and `false`) are now parsed correctly (thanks @mduret) - Boolean settings provided via environment variables (so the strings `true` and `false`) are now parsed correctly (thanks @mduret)
- All uploaded pictures (currently for products and recipes) are now automatically downscaled to the appropriate size when serving them to improve page load times - All uploaded pictures (currently for products and recipes) are now automatically downscaled to the appropriate size when serving them to improve page load times
- It's now possible to test plural forms of quantity units (button on the quantity unit edit page)
### API improvements & non-breaking changes ### API improvements & non-breaking changes
- New endpoint `/stock/shoppinglist/add-product` to add a product to a shopping list (thanks @Forceu) - New endpoint `/stock/shoppinglist/add-product` to add a product to a shopping list (thanks @Forceu)

View File

@@ -322,4 +322,11 @@ class StockController extends BaseController
]); ]);
} }
} }
public function QuantityUnitPluralFormTesting(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'quantityunitpluraltesting', [
'quantityUnits' => $this->Database->quantity_units()->orderBy('name')
]);
}
} }

View File

@@ -1453,3 +1453,12 @@ msgstr ""
msgid "Configure fields" msgid "Configure fields"
msgstr "" msgstr ""
msgid "Quantity unit plural form testing"
msgstr ""
msgid "Result"
msgstr ""
msgid "Test plural forms"
msgstr ""

View File

@@ -26,6 +26,10 @@
{ {
window.location.reload(); window.location.reload();
} }
else if (redirectDestination == "stay")
{
// Do nothing
}
else else
{ {
window.location.href = redirectDestination.replace("editobjectid", Grocy.EditObjectId); window.location.href = redirectDestination.replace("editobjectid", Grocy.EditObjectId);
@@ -50,6 +54,10 @@
{ {
window.location.reload(); window.location.reload();
} }
else if (redirectDestination == "stay")
{
// Do nothing
}
else else
{ {
window.location.href = redirectDestination.replace("editobjectid", Grocy.EditObjectId); window.location.href = redirectDestination.replace("editobjectid", Grocy.EditObjectId);
@@ -181,3 +189,22 @@ $("#qu-conversion-add-button").on("click", function(e)
Grocy.QuantityUnitEditFormRedirectUri = U("/quantityunitconversion/new?qu-unit=editobjectid"); Grocy.QuantityUnitEditFormRedirectUri = U("/quantityunitconversion/new?qu-unit=editobjectid");
$('#save-quantityunit-button').click(); $('#save-quantityunit-button').click();
}); });
$("#test-quantityunit-plural-forms-button").on("click", function(e)
{
e.preventDefault();
Grocy.QuantityUnitEditFormRedirectUri = "stay";
$("#save-quantityunit-button").click();
bootbox.alert({
message: '<iframe height="400px" class="embed-responsive" src="' + U("/quantityunitpluraltesting?embedded&qu=") + Grocy.EditObjectId.toString() + '"></iframe>',
closeButton: false,
size: "large",
callback: function(result)
{
Grocy.QuantityUnitEditFormRedirectUri = undefined;
Grocy.FrontendHelpers.EndUiBusy("quantityunit-form");
}
});
});

View File

@@ -0,0 +1,38 @@
$("#qu_id").change(function(event)
{
RefreshQuPluralTestingResult();
});
$("#amount").keyup(function (event)
{
RefreshQuPluralTestingResult();
});
$("#amount").change(function (event)
{
RefreshQuPluralTestingResult();
});
function RefreshQuPluralTestingResult()
{
var singularForm = $("#qu_id option:selected").data("singular-form");
var pluralForm = $("#qu_id option:selected").data("plural-form");
var amount = $("#amount").val();
if (singularForm.toString().isEmpty() || amount.toString().isEmpty())
{
return;
}
$("#result").parent().effect("highlight", {}, 100);
$("#result").fadeOut(100, function ()
{
$(this).text(__n(amount, singularForm, pluralForm)).fadeIn(100);
});
}
if (GetUriParam("qu") !== undefined)
{
$("#qu_id").val(GetUriParam("qu"));
$("#qu_id").trigger("change");
}

View File

@@ -47,6 +47,7 @@ $app->group('', function()
$this->get('/productgroup/{productGroupId}', '\Grocy\Controllers\StockController:ProductGroupEditForm'); $this->get('/productgroup/{productGroupId}', '\Grocy\Controllers\StockController:ProductGroupEditForm');
$this->get('/stockjournal', '\Grocy\Controllers\StockController:Journal'); $this->get('/stockjournal', '\Grocy\Controllers\StockController:Journal');
$this->get('/locationcontentsheet', '\Grocy\Controllers\StockController:LocationContentSheet'); $this->get('/locationcontentsheet', '\Grocy\Controllers\StockController:LocationContentSheet');
$this->get('/quantityunitpluraltesting', '\Grocy\Controllers\StockController:QuantityUnitPluralFormTesting');
} }
// Shopping list routes // Shopping list routes

View File

@@ -57,6 +57,7 @@
)) ))
<button id="save-quantityunit-button" class="btn btn-success">{{ $__t('Save') }}</button> <button id="save-quantityunit-button" class="btn btn-success">{{ $__t('Save') }}</button>
<button id="test-quantityunit-plural-forms-button" class="btn btn-secondary">{{ $__t('Test plural forms') }}</button>
</form> </form>
</div> </div>

View File

@@ -0,0 +1,42 @@
@extends('layout.default')
@section('title', $__t('Quantity unit plural form testing'))
@section('viewJsName', 'quantityunitpluraltesting')
@push('pageScripts')
<script src="{{ $U('/node_modules/jquery-ui-dist/jquery-ui.min.js?v=', true) }}{{ $version }}"></script>
@endpush
@section('content')
<div class="row">
<div class="col-lg-6 col-xs-12">
<h1>@yield('title')</h1>
<form id="quantityunitpluraltesting-form" novalidate>
<div class="form-group">
<label for="qu_id">{{ $__t('Quantity unit') }}</label>
<select class="form-control" id="qu_id" name="qu_id">
<option></option>
@foreach($quantityUnits as $quantityUnit)
<option value="{{ $quantityUnit->id }}" data-singular-form="{{ $quantityUnit->name }}" data-plural-form="{{ $quantityUnit->name_plural }}">{{ $quantityUnit->name }}</option>
@endforeach
</select>
</div>
@include('components.numberpicker', array(
'id' => 'amount',
'label' => 'Amount',
'min' => 0.0001,
'step' => 1,
'isRequired' => false,
'value' => 1
))
</form>
<h2><strong>{{ $__t('Result') }}:</strong> <span id="result"></span></h2>
</div>
</div>
@stop