Skip to content

Commit

Permalink
Updated proximity to unlock field
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Dec 18, 2024
1 parent bbd552b commit 7f975fc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
2 changes: 2 additions & 0 deletions public/api-spec-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
"type": "string"
},
"proximityToUnlock": {
"description": "Proximity to unlock in meters.",
"type": [
"integer",
"null"
Expand Down Expand Up @@ -542,6 +543,7 @@
"type": "string"
},
"proximityToUnlock": {
"description": "Proximity to unlock in meters.",
"type": [
"integer",
"null"
Expand Down
2 changes: 2 additions & 0 deletions public/api-spec-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ components:
longitude:
type: string
proximityToUnlock:
description: 'Proximity to unlock in meters.'
type:
- integer
- 'null'
Expand Down Expand Up @@ -278,6 +279,7 @@ components:
longitude:
type: string
proximityToUnlock:
description: 'Proximity to unlock in meters.'
type:
- integer
- 'null'
Expand Down
13 changes: 11 additions & 2 deletions src/Controller/Admin/PointOfInterestCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace App\Controller\Admin;

use App\Admin\Field\LocationField;
use App\Admin\Field\ValueWithUnitField;
use App\Entity\PointOfInterest;
use App\Entity\Role;
use App\Entity\Route;
use App\Field\VichImageField;
use App\Form\ValueWithUnitType;
use App\Service\EasyAdminHelper;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
Expand Down Expand Up @@ -91,8 +93,15 @@ public function configureFields(string $pageName): iterable
->setRequired(true)
->setVirtual(true)->setColumns(12);

yield NumberField::new('proximityToUnlock', new TranslatableMessage('Proximity to unlock', [], 'admin'))
->setHelp(new TranslatableMessage('The proximity that allows unlocking this point of interest (in m).', [], 'admin'))->setColumns(12);
yield ValueWithUnitField::new('proximityToUnlock', new TranslatableMessage('Proximity to unlock', [], 'admin'))
->setFormTypeOption('units', [
'm' => [
ValueWithUnitType::OPTION_LABEL => new TranslatableMessage('meter', [], 'admin'),
ValueWithUnitType::OPTION_SCALE => 1,
ValueWithUnitType::OPTION_LOCALIZED_UNIT => new TranslatableMessage('unit.m', [], 'admin'),
],
])
->setHelp(new TranslatableMessage('The proximity that allows unlocking this point of interest.', [], 'admin'))->setColumns(12);

yield DateField::new('createdAt', new TranslatableMessage('Created at', [], 'admin'))->hideOnForm();
yield DateField::new('updatedAt', new TranslatableMessage('Updated at', [], 'admin'))->hideOnForm();
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/PointOfInterest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class PointOfInterest implements BlameableInterface, \JsonSerializable
#[Groups(['read'])]
private ?string $longitude = null;

/**
* Proximity to unlock in meters.
*/
#[ORM\Column(length: 255, nullable: true)]
#[Assert\NotBlank]
#[Groups(['read'])]
Expand Down
6 changes: 3 additions & 3 deletions src/Form/ValueWithUnitType.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
;
}

public function transform(int $value, array $options): array
public function transform(?int $value, array $options): array
{
try {
return $this->getMatchingUnit($value, $options);
Expand Down Expand Up @@ -118,14 +118,14 @@ private function getUnits(array $options): array
return $units;
}

public function getMatchingUnit(int $value, array $options): array
public function getMatchingUnit(?int $value, array $options): array
{
$units = $this->getUnits($options);
foreach ($units as $unit => $info) {
$scale = $info[self::OPTION_SCALE];
if ($value >= $scale || array_key_last($units) === $unit) {
return [
self::FIELD_VALUE => $scale > 1 ? $value / $scale : $value,
self::FIELD_VALUE => null === $value ? null : ($scale > 1 ? $value / $scale : $value),
self::FIELD_UNIT => $unit,
self::OPTION_LOCALIZED_UNIT => $info[self::OPTION_LOCALIZED_UNIT],
];
Expand Down
12 changes: 6 additions & 6 deletions translations/admin+intl-icu.da.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
<source>A text version of the podcast, for people with hearing disabilities.</source>
<target state="translated">En tekstuel udgave af podcasten til mennesker med hørenedsættelse.</target>
</trans-unit>
<trans-unit id="bbzr4x2" resname="The proximity that allows unlocking this point of interest (in m).">
<source>The proximity that allows unlocking this point of interest (in m).</source>
<target state="translated">Nærheden for at afspille seværdigheden (i meter).</target>
</trans-unit>
<trans-unit id="IquzO6S" resname="Users mail address, which is also used as login name">
<source>Users mail address, which is also used as login name</source>
<target state="translated">E-mailadresse som også bruges som brugernavn</target>
Expand Down Expand Up @@ -89,7 +85,7 @@
<source>This link will expire in {expire_info}.</source>
<target state="translated">Linket udløber om {expire_info}.</target>
</trans-unit>
<trans-unit id="zyE0yOM" resname="If you don't receive an email please check your spam folder or &lt;a href=&quot;{forgot_password_url}&quot;&gt;try again&lt;/a&gt;.">
<trans-unit id="zyE0yOM" resname="If you don't receive an email please check your spam folder or &lt;a href=&quot;{forgot_password_url}&quot;>try again&lt;/a>.">
<source>If you don't receive an email please check your spam folder or &lt;a href="{forgot_password_url}"&gt;try again&lt;/a&gt;.</source>
<target state="translated"><![CDATA[Hvis du ikke modtager en e-mail, så tjek din “Uønsket mail”-mappe eller <a href="{forgot_password_url}">prøv igen</a>.]]></target>
</trans-unit>
Expand Down Expand Up @@ -205,7 +201,7 @@
<source>Email</source>
<target state="translated">E-mail</target>
</trans-unit>
<trans-unit id="XkthfIE" resname="Enter a location on the form &lt;code&gt;lat, lng&lt;/code&gt;, e.g. &lt;code&gt;56.153244272970866, 10.213798100000005&lt;/code&gt;. &lt;strong&gt;Notice&lt;/strong&gt;: the two numbers must always be separated by a comma and use dot as decimal separator.&lt;br&gt;Hint: Open &lt;a href=&quot;https://www.google.com/maps&quot; target=&quot;_blank&quot;&gt;Google Maps&lt;/a&gt; and “right” click on the map to get the coordinates.">
<trans-unit id="XkthfIE" resname="Enter a location on the form &lt;code>lat, lng&lt;/code>, e.g. &lt;code>56.153244272970866, 10.213798100000005&lt;/code>. &lt;strong>Notice&lt;/strong>: the two numbers must always be separated by a comma and use dot as decimal separator.&lt;br>Hint: Open &lt;a href=&quot;https://www.google.com/maps&quot; target=&quot;_blank&quot;>Google Maps&lt;/a> and “right” click on the map to get the coordinates.">
<source>Enter a location on the form &lt;code&gt;lat, lng&lt;/code&gt;, e.g. &lt;code&gt;56.153244272970866, 10.213798100000005&lt;/code&gt;. &lt;strong&gt;Notice&lt;/strong&gt;: the two numbers must always be separated by a comma and use dot as decimal separator.&lt;br&gt;Hint: Open &lt;a href="https://www.google.com/maps" target="_blank"&gt;Google Maps&lt;/a&gt; and “right” click on the map to get the coordinates.</source>
<target state="translated"><![CDATA[Indtast en lokation på formen <code>breddegrad, længdegrad</code>, fx. <code>56.153244272970866, 10.213798100000005</code>. <strong>Bemærk</strong>: de to tal skal altid adskilles af et komma og skal bruge punktum som decimalseparator.<br>Tip: Åbn <a href="https://www.google.com/maps" target="_blank">Google Maps</a> og højreklik på kortet for at få koordinaterne.]]></target>
</trans-unit>
Expand Down Expand Up @@ -341,6 +337,10 @@
<source>minutes</source>
<target state="translated">minutter</target>
</trans-unit>
<trans-unit id="BOdcynp" resname="The proximity that allows unlocking this point of interest.">
<source>The proximity that allows unlocking this point of interest.</source>
<target state="translated">Nærheden for at afspille seværdigheden.</target>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 4 additions & 4 deletions translations/admin+intl-icu.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
<source>A text version of the podcast, for people with hearing disabilities.</source>
<target>A text version of the podcast, for people with hearing disabilities.</target>
</trans-unit>
<trans-unit id="bbzr4x2" resname="The proximity that allows unlocking this point of interest (in m).">
<source>The proximity that allows unlocking this point of interest (in m).</source>
<target>The proximity that allows unlocking this point of interest (in m).</target>
</trans-unit>
<trans-unit id="IquzO6S" resname="Users mail address, which is also used as login name">
<source>Users mail address, which is also used as login name</source>
<target>Users mail address, which is also used as login name</target>
Expand Down Expand Up @@ -341,6 +337,10 @@
<source>minutes</source>
<target>minutes</target>
</trans-unit>
<trans-unit id="BOdcynp" resname="The proximity that allows unlocking this point of interest.">
<source>The proximity that allows unlocking this point of interest.</source>
<target>The proximity that allows unlocking this point of interest.</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 7f975fc

Please sign in to comment.