edit single system config section in modal (#1490)
This commit is contained in:
@@ -29,6 +29,7 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
|
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\Validator\Constraints\DateTime;
|
use Symfony\Component\Validator\Constraints\DateTime;
|
||||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||||
@@ -41,26 +42,21 @@ use Symfony\Component\Validator\Constraints\Regex;
|
|||||||
* @Route(path="/admin/system-config")
|
* @Route(path="/admin/system-config")
|
||||||
* @Security("is_granted('system_configuration')")
|
* @Security("is_granted('system_configuration')")
|
||||||
*/
|
*/
|
||||||
class SystemConfigurationController extends AbstractController
|
final class SystemConfigurationController extends AbstractController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var EventDispatcherInterface
|
* @var EventDispatcherInterface
|
||||||
*/
|
*/
|
||||||
protected $eventDispatcher;
|
private $eventDispatcher;
|
||||||
/**
|
/**
|
||||||
* @var SystemConfiguration
|
* @var SystemConfiguration
|
||||||
*/
|
*/
|
||||||
protected $configurations;
|
private $configurations;
|
||||||
/**
|
/**
|
||||||
* @var ConfigurationRepository
|
* @var ConfigurationRepository
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param EventDispatcherInterface $dispatcher
|
|
||||||
* @param ConfigurationRepository $repository
|
|
||||||
* @param SystemConfiguration $config
|
|
||||||
*/
|
|
||||||
public function __construct(EventDispatcherInterface $dispatcher, ConfigurationRepository $repository, SystemConfiguration $config)
|
public function __construct(EventDispatcherInterface $dispatcher, ConfigurationRepository $repository, SystemConfiguration $config)
|
||||||
{
|
{
|
||||||
$this->eventDispatcher = $dispatcher;
|
$this->eventDispatcher = $dispatcher;
|
||||||
@@ -70,10 +66,8 @@ class SystemConfigurationController extends AbstractController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route(path="/", name="system_configuration", methods={"GET"})
|
* @Route(path="/", name="system_configuration", methods={"GET"})
|
||||||
*
|
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
|
||||||
*/
|
*/
|
||||||
public function indexAction()
|
public function indexAction(): Response
|
||||||
{
|
{
|
||||||
$configSettings = $this->getInitializedConfigurations();
|
$configSettings = $this->getInitializedConfigurations();
|
||||||
|
|
||||||
@@ -90,6 +84,30 @@ class SystemConfigurationController extends AbstractController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(path="/edit/{section}", name="system_configuration_section", methods={"GET"})
|
||||||
|
*/
|
||||||
|
public function sectionAction(string $section): Response
|
||||||
|
{
|
||||||
|
$configSettings = $this->getInitializedConfigurations();
|
||||||
|
|
||||||
|
$configurations = [];
|
||||||
|
foreach ($configSettings as $configModel) {
|
||||||
|
if ($configModel->getSection() !== $section) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$configurations[] = [
|
||||||
|
'model' => $configModel,
|
||||||
|
'form' => $this->createConfigurationsForm($configModel)->createView(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('system-configuration/index.html.twig', [
|
||||||
|
'sections' => $configurations,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route(path="/update/{section}", name="system_configuration_update", methods={"POST"})
|
* @Route(path="/update/{section}", name="system_configuration_update", methods={"POST"})
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% extends 'base.html.twig' %}
|
{% extends app.request.xmlHttpRequest ? 'form.html.twig' : 'base.html.twig' %}
|
||||||
{% import "system-configuration/actions.html.twig" as actions %}
|
{% import "system-configuration/actions.html.twig" as actions %}
|
||||||
|
|
||||||
{% block page_title %}{{ 'title'|trans({}, 'system-configuration') }}{% endblock %}
|
{% block page_title %}{{ 'title'|trans({}, 'system-configuration') }}{% endblock %}
|
||||||
@@ -7,8 +7,10 @@
|
|||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
|
{% set formEditTemplate = app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig' %}
|
||||||
|
|
||||||
{% for section in sections %}
|
{% for section in sections %}
|
||||||
{{ include('default/_form.html.twig', {
|
{{ include(formEditTemplate, {
|
||||||
'title': section.model.section|trans({}, 'system-configuration'),
|
'title': section.model.section|trans({}, 'system-configuration'),
|
||||||
'form': section.form,
|
'form': section.form,
|
||||||
}) }}
|
}) }}
|
||||||
|
|||||||
@@ -45,6 +45,25 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSectionAction()
|
||||||
|
{
|
||||||
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||||
|
$this->assertAccessIsGranted($client, '/admin/system-config/edit/timesheet');
|
||||||
|
|
||||||
|
$expectedForms = $this->getTestDataForms();
|
||||||
|
|
||||||
|
$result = $client->getCrawler()->filter('section.content div.box.box-primary');
|
||||||
|
$this->assertEquals(1, count($result));
|
||||||
|
|
||||||
|
$result = $client->getCrawler()->filter('section.content div.box.box-primary form');
|
||||||
|
$this->assertEquals(1, count($result));
|
||||||
|
|
||||||
|
$result = $client->getCrawler()->filter('form[name=system_configuration_form_timesheet]');
|
||||||
|
$this->assertEquals(1, count($result));
|
||||||
|
$form = $result->form();
|
||||||
|
$this->assertEquals('POST', $form->getMethod());
|
||||||
|
}
|
||||||
|
|
||||||
public function getTestDataForms()
|
public function getTestDataForms()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user