Compare commits

...

3 commits

Author SHA1 Message Date
Jan Böhmer
d70fe0fbaa Improved styling of help text in settings forms
Some checks failed
Build assets artifact / Build assets artifact (push) Has been cancelled
Docker Image Build / docker (push) Has been cancelled
Docker Image Build (FrankenPHP) / docker (push) Has been cancelled
Static analysis / Static analysis (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, mysql) (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, mysql) (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, mysql) (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, postgres) (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, postgres) (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, postgres) (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, sqlite) (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, sqlite) (push) Has been cancelled
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, sqlite) (push) Has been cancelled
2025-08-24 23:42:39 +02:00
Jan Böhmer
48ff2494f6 Add settings form for remaining info providers 2025-08-24 23:35:31 +02:00
Jan Böhmer
ee33d743e6 Allow to associate settings forms with info providers 2025-08-24 23:32:58 +02:00
16 changed files with 126 additions and 23 deletions

12
composer.lock generated
View file

@ -5090,16 +5090,16 @@
},
{
"name": "jbtronics/settings-bundle",
"version": "v3.0.0",
"version": "v3.0.1",
"source": {
"type": "git",
"url": "https://github.com/jbtronics/settings-bundle.git",
"reference": "34b9629af73c7ad8989d8284470e79f3f8d79712"
"reference": "9103bd7f78f0b223d1c7167feb824004fc2a9f07"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jbtronics/settings-bundle/zipball/34b9629af73c7ad8989d8284470e79f3f8d79712",
"reference": "34b9629af73c7ad8989d8284470e79f3f8d79712",
"url": "https://api.github.com/repos/jbtronics/settings-bundle/zipball/9103bd7f78f0b223d1c7167feb824004fc2a9f07",
"reference": "9103bd7f78f0b223d1c7167feb824004fc2a9f07",
"shasum": ""
},
"require": {
@ -5160,7 +5160,7 @@
],
"support": {
"issues": "https://github.com/jbtronics/settings-bundle/issues",
"source": "https://github.com/jbtronics/settings-bundle/tree/v3.0.0"
"source": "https://github.com/jbtronics/settings-bundle/tree/v3.0.1"
},
"funding": [
{
@ -5172,7 +5172,7 @@
"type": "github"
}
],
"time": "2025-08-24T17:17:43+00:00"
"time": "2025-08-24T21:20:15+00:00"
},
{
"name": "jfcherng/php-color-output",

View file

@ -29,10 +29,14 @@ use App\Form\InfoProviderSystem\PartSearchType;
use App\Services\InfoProviderSystem\ExistingPartFinder;
use App\Services\InfoProviderSystem\PartInfoRetriever;
use App\Services\InfoProviderSystem\ProviderRegistry;
use App\Settings\AppSettings;
use Doctrine\ORM\EntityManagerInterface;
use Jbtronics\SettingsBundle\Form\SettingsFormFactoryInterface;
use Jbtronics\SettingsBundle\Manager\SettingsManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpClient\Exception\ClientException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -46,7 +50,9 @@ class InfoProviderController extends AbstractController
public function __construct(private readonly ProviderRegistry $providerRegistry,
private readonly PartInfoRetriever $infoRetriever,
private readonly ExistingPartFinder $existingPartFinder
private readonly ExistingPartFinder $existingPartFinder,
private readonly SettingsManagerInterface $settingsManager,
private readonly SettingsFormFactoryInterface $settingsFormFactory
)
{
@ -63,6 +69,48 @@ class InfoProviderController extends AbstractController
]);
}
#[Route('/provider/{provider}/settings', name: 'info_providers_provider_settings')]
public function providerSettings(string $provider, Request $request): Response
{
$this->denyAccessUnlessGranted('@config.change_system_settings');
$this->denyAccessUnlessGranted('@info_providers.create_parts');
$providerInstance = $this->providerRegistry->getProviderByKey($provider);
$settingsClass = $providerInstance->getProviderInfo()['settings_class'] ?? throw new \LogicException('Provider ' . $provider . ' does not have a settings class defined');
//Create a clone of the settings object
$settings = $this->settingsManager->createTemporaryCopy($settingsClass);
//Create a form builder for the settings object
$builder = $this->settingsFormFactory->createSettingsFormBuilder($settings);
//Add a submit button to the form
$builder->add('submit', SubmitType::class, ['label' => 'save']);
//Create the form
$form = $builder->getForm();
$form->handleRequest($request);
//If the form was submitted and is valid, save the settings
if ($form->isSubmitted() && $form->isValid()) {
$this->settingsManager->mergeTemporaryCopy($settings);
$this->settingsManager->save($settings);
$this->addFlash('success', t('settings.flash.saved'));
}
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', t('settings.flash.invalid'));
}
//Render the form
return $this->render('info_providers/settings/provider_settings.html.twig', [
'form' => $form,
'info_provider_key' => $provider,
'info_provider_info' => $providerInstance->getProviderInfo(),
]);
}
#[Route('/search', name: 'info_providers_search')]
#[Route('/update/{target}', name: 'info_providers_update_part_search')]
public function search(Request $request, #[MapEntity(id: 'target')] ?Part $update_target, LoggerInterface $exceptionLogger): Response
@ -128,4 +176,4 @@ class InfoProviderController extends AbstractController
'update_target' => $update_target
]);
}
}
}

View file

@ -78,7 +78,8 @@ class DigikeyProvider implements InfoProviderInterface
'description' => 'This provider uses the DigiKey API to search for parts.',
'url' => 'https://www.digikey.com/',
'oauth_app_name' => self::OAUTH_APP_NAME,
'disabled_help' => 'Set the Client ID and Secret in provider settings and connect OAuth to enable.'
'disabled_help' => 'Set the Client ID and Secret in provider settings and connect OAuth to enable.',
'settings_class' => DigikeySettings::class,
];
}

View file

@ -66,7 +66,8 @@ class Element14Provider implements InfoProviderInterface
'name' => 'Farnell element14',
'description' => 'This provider uses the Farnell element14 API to search for parts.',
'url' => 'https://www.element14.com/',
'disabled_help' => 'Configure the API key in the provider settings to enable.'
'disabled_help' => 'Configure the API key in the provider settings to enable.',
'settings_class' => Element14Settings::class,
];
}

View file

@ -39,8 +39,9 @@ interface InfoProviderInterface
* - url?: The url of the provider (e.g. "https://www.digikey.com")
* - disabled_help?: A help text which is shown when the provider is disabled, explaining how to enable it
* - oauth_app_name?: The name of the OAuth app which is used for authentication (e.g. "ip_digikey_oauth"). If this is set a connect button will be shown
* - settings_class?: The class name of the settings class which contains the settings for this provider (e.g. "App\Settings\InfoProviderSettings\DigikeySettings"). If this is set a link to the settings will be shown
*
* @phpstan-return array{ name: string, description?: string, logo?: string, url?: string, disabled_help?: string, oauth_app_name?: string }
* @phpstan-return array{ name: string, description?: string, logo?: string, url?: string, disabled_help?: string, oauth_app_name?: string, settings_class?: class-string }
*/
public function getProviderInfo(): array;
@ -78,4 +79,4 @@ interface InfoProviderInterface
* @return ProviderCapabilities[]
*/
public function getCapabilities(): array;
}
}

View file

@ -51,7 +51,8 @@ class LCSCProvider implements InfoProviderInterface
'name' => 'LCSC',
'description' => 'This provider uses the (unofficial) LCSC API to search for parts.',
'url' => 'https://www.lcsc.com/',
'disabled_help' => 'Enable this provider in the provider settings.'
'disabled_help' => 'Enable this provider in the provider settings.',
'settings_class' => LCSCSettings::class,
];
}

View file

@ -61,7 +61,8 @@ class MouserProvider implements InfoProviderInterface
'name' => 'Mouser',
'description' => 'This provider uses the Mouser API to search for parts.',
'url' => 'https://www.mouser.com/',
'disabled_help' => 'Configure the API key in the provider settings to enable.'
'disabled_help' => 'Configure the API key in the provider settings to enable.',
'settings_class' => MouserSettings::class
];
}

View file

@ -246,7 +246,8 @@ class OEMSecretsProvider implements InfoProviderInterface
'name' => 'OEMSecrets',
'description' => 'This provider uses the OEMSecrets API to search for parts.',
'url' => 'https://www.oemsecrets.com/',
'disabled_help' => 'Configure the API key in the provider settings to enable.'
'disabled_help' => 'Configure the API key in the provider settings to enable.',
'settings_class' => OEMSecretsSettings::class
];
}
/**

View file

@ -170,7 +170,8 @@ class OctopartProvider implements InfoProviderInterface
'name' => 'Octopart',
'description' => 'This provider uses the Nexar/Octopart API to search for parts on Octopart.',
'url' => 'https://www.octopart.com/',
'disabled_help' => 'Set the Client ID and Secret in provider settings.'
'disabled_help' => 'Set the Client ID and Secret in provider settings.',
'settings_class' => OctopartSettings::class
];
}

View file

@ -51,7 +51,8 @@ class PollinProvider implements InfoProviderInterface
'name' => 'Pollin',
'description' => 'Webscraping from pollin.de to get part information',
'url' => 'https://www.pollin.de/',
'disabled_help' => 'Enable the provider in provider settings'
'disabled_help' => 'Enable the provider in provider settings',
'settings_class' => PollinSettings::class,
];
}

View file

@ -51,7 +51,8 @@ class ReicheltProvider implements InfoProviderInterface
'name' => 'Reichelt',
'description' => 'Webscraping from reichelt.com to get part information',
'url' => 'https://www.reichelt.com/',
'disabled_help' => 'Enable provider in provider settings.'
'disabled_help' => 'Enable provider in provider settings.',
'settings_class' => ReicheltSettings::class,
];
}

View file

@ -54,7 +54,8 @@ class TMEProvider implements InfoProviderInterface
'name' => 'TME',
'description' => 'This provider uses the API of TME (Transfer Multipart).',
'url' => 'https://tme.eu/',
'disabled_help' => 'Configure the API Token and secret in provider settings to use this provider.'
'disabled_help' => 'Configure the API Token and secret in provider settings to use this provider.',
'settings_class' => TMESettings::class
];
}

View file

@ -13,7 +13,6 @@
{% else %}
{{ provider.providerInfo.name | trans }}
{% endif %}
</h5>
<div>
{% if provider.providerInfo.description is defined and provider.providerInfo.description is not null %}
@ -23,6 +22,11 @@
</div>
<div class="col-6">
{% if provider.providerInfo.settings_class is defined %}
<a href="{{ path('info_providers_provider_settings', {'provider': provider.providerKey}) }}" class="btn btn-primary btn-sm"
title="{% trans %}info_providers.settings.title{% endtrans %}"
><i class="fa-solid fa-cog"></i></a>
{% endif %}
{% for capability in provider.capabilities %}
{# @var capability \App\Services\InfoProviderSystem\Providers\ProviderCapabilities #}
<span class="badge text-bg-secondary">
@ -52,4 +56,4 @@
{% endfor %}
</tbody>
</table>
{% endmacro %}
{% endmacro %}

View file

@ -0,0 +1,31 @@
{% extends "main_card.html.twig" %}
{% macro genId(widget) %}{{ widget.vars.full_name }}{% endmacro %}
{% form_theme form "form/settings_form.html.twig" %}
{% block title %}{% trans %}info_providers.settings.title{% endtrans %}: {{ info_provider_info.name }}{% endblock %}
{% block card_title %}<i class="fa-solid fa-gear fa-fw"></i> {% trans %}info_providers.settings.title{% endtrans %}: <b>{{ info_provider_info.name }}</b>{% endblock %}
{% block card_content %}
<div class="offset-sm-3">
<h3>
{% if info_provider_info.url %}
<a href="{{ info_provider_info.url }}" class="link-external" target="_blank" rel="nofollow">{{ info_provider_info.name }}</a>
{% else %}
{{ info_provider_info.name }}
{% endif %}
</h3>
{% if info_provider_info.description %}
<p class="text-muted">{{ info_provider_info.description }}</p>
{% endif %}
</div>
{{ form_start(form) }}
<div class="row">
<div class="offset-sm-3 col mb-3 ps-2">
<b>{{ form_help(form) }}</b>
</div>
</div>
{{ form_end(form) }}
{% endblock %}

View file

@ -42,8 +42,12 @@
<i class="fa-solid {{ settings_icon(settings_object)|default('fa-sliders') }} fa-fw"></i>
{{ (section_widget.vars.label ?? section_widget.vars.name|humanize)|trans }}
</legend>
{{ form_help(section_widget) }}
{{ form_errors(section_widget) }}
<div class="row">
<div class="offset-sm-3 col mb-3 ps-2">
<b>{{ form_help(section_widget) }}</b>
{{ form_errors(section_widget) }}
</div>
</div>
{{ form_widget(section_widget) }}
</fieldset>
{% if not loop.last %}

View file

@ -13045,5 +13045,11 @@ Please note, that you can not impersonate a disabled user. If you try you will g
<target>Settings are invalid. Please check your input!</target>
</segment>
</unit>
<unit id="yRXWSRN" name="info_providers.settings.title">
<segment>
<source>info_providers.settings.title</source>
<target>Info provider settings</target>
</segment>
</unit>
</file>
</xliff>