mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Show the value returned by the provider on part creation page.
This makes it easier to check or assign a element manually
This commit is contained in:
parent
b74ab18a6d
commit
c810b6772c
5 changed files with 61 additions and 2 deletions
|
@ -88,9 +88,12 @@ class InfoProviderController extends AbstractController
|
|||
{
|
||||
$this->denyAccessUnlessGranted('@info_providers.create_parts');
|
||||
|
||||
$new_part = $this->infoRetriever->createPart($providerKey, $providerId);
|
||||
$dto = $this->infoRetriever->getDetails($providerKey, $providerId);
|
||||
$new_part = $this->infoRetriever->dtoToPart($dto);
|
||||
|
||||
$form = $this->createForm(PartBaseType::class, $new_part);
|
||||
$form = $this->createForm(PartBaseType::class, $new_part, [
|
||||
'info_provider_dto' => $dto,
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
namespace App\Form\Part;
|
||||
|
||||
use App\Entity\Parts\ManufacturingStatus;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use App\Entity\Attachments\PartAttachment;
|
||||
use App\Entity\Parameters\PartParameter;
|
||||
|
@ -51,6 +52,7 @@ use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
|||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class PartBaseType extends AbstractType
|
||||
{
|
||||
|
@ -64,6 +66,8 @@ class PartBaseType extends AbstractType
|
|||
$part = $builder->getData();
|
||||
$new_part = null === $part->getID();
|
||||
|
||||
/** @var PartDetailDTO|null $dto */
|
||||
$dto = $options['info_provider_dto'];
|
||||
|
||||
//Common section
|
||||
$builder
|
||||
|
@ -95,6 +99,7 @@ class PartBaseType extends AbstractType
|
|||
->add('category', StructuralEntityType::class, [
|
||||
'class' => Category::class,
|
||||
'allow_add' => $this->security->isGranted('@categories.create'),
|
||||
'dto_value' => $dto?->category,
|
||||
'label' => 'part.edit.category',
|
||||
'disable_not_selectable' => true,
|
||||
])
|
||||
|
@ -102,6 +107,7 @@ class PartBaseType extends AbstractType
|
|||
'class' => Footprint::class,
|
||||
'required' => false,
|
||||
'label' => 'part.edit.footprint',
|
||||
'dto_value' => $dto?->footprint,
|
||||
'allow_add' => $this->security->isGranted('@footprints.create'),
|
||||
'disable_not_selectable' => true,
|
||||
])
|
||||
|
@ -122,6 +128,7 @@ class PartBaseType extends AbstractType
|
|||
'required' => false,
|
||||
'label' => 'part.edit.manufacturer.label',
|
||||
'allow_add' => $this->security->isGranted('@manufacturers.create'),
|
||||
'dto_value' => $dto?->manufacturer,
|
||||
'disable_not_selectable' => true,
|
||||
])
|
||||
->add('manufacturer_product_url', UrlType::class, [
|
||||
|
@ -268,10 +275,15 @@ class PartBaseType extends AbstractType
|
|||
->add('reset', ResetType::class, ['label' => 'part.edit.reset']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Part::class,
|
||||
'info_provider_dto' => null,
|
||||
]);
|
||||
|
||||
$resolver->setAllowedTypes('info_provider_dto', [PartDetailDTO::class, 'null']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,17 @@ class StructuralEntityType extends AbstractType
|
|||
|
||||
$resolver->setDefault('controller', 'elements--structural-entity-select');
|
||||
|
||||
//Options for DTO values
|
||||
$resolver->setDefault('dto_value', null);
|
||||
$resolver->setAllowedTypes('dto_value', ['null', 'string']);
|
||||
//If no help text is explicitly set, we use the dto value as help text and show it as html
|
||||
$resolver->setDefault('help', function (Options $options) {
|
||||
return $this->dtoText($options['dto_value']);
|
||||
});
|
||||
$resolver->setDefault('help_html', function (Options $options) {
|
||||
return $options['dto_value'] !== null;
|
||||
});
|
||||
|
||||
$resolver->setDefault('attr', function (Options $options) {
|
||||
$tmp = [
|
||||
'data-controller' => $options['controller'],
|
||||
|
@ -114,6 +125,16 @@ class StructuralEntityType extends AbstractType
|
|||
});
|
||||
}
|
||||
|
||||
private function dtoText(?string $text): ?string
|
||||
{
|
||||
if ($text === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = '<b>' . $this->translator->trans('info_providers.form.help_prefix') . ':</b> ';
|
||||
|
||||
return $result . htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') ;
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
|
|
|
@ -100,11 +100,28 @@ final class PartInfoRetriever
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the details for a part, based on the given search result.
|
||||
* @param SearchResultDTO $search_result
|
||||
* @return PartDetailDTO
|
||||
*/
|
||||
public function getDetailsForSearchResult(SearchResultDTO $search_result): PartDetailDTO
|
||||
{
|
||||
return $this->getDetails($search_result->provider_key, $search_result->provider_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given DTO to a part entity
|
||||
* @return Part
|
||||
*/
|
||||
public function dtoToPart(PartDetailDTO $search_result): Part
|
||||
{
|
||||
return $this->createPart($search_result->provider_key, $search_result->provider_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the given details to create a part entity
|
||||
*/
|
||||
public function createPart(string $provider_key, string $part_id): Part
|
||||
{
|
||||
$details = $this->getDetails($provider_key, $part_id);
|
||||
|
|
|
@ -11573,5 +11573,11 @@ Please note, that you can not impersonate a disabled user. If you try you will g
|
|||
<target>The alternative names given here, are used to find this element based on the results of the information providers.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="TRmIjDN" name="info_providers.form.help_prefix">
|
||||
<segment>
|
||||
<source>info_providers.form.help_prefix</source>
|
||||
<target>Provider</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue