added default settings for new customer form (#358)
This commit is contained in:
@@ -154,3 +154,10 @@ kimai:
|
|||||||
activeUsersYear: { title: stats.userActiveYear, query: users, begin: '01 january this year 00:00:00', end: '31 december this year 23:59:59', icon: user, color: yellow }
|
activeUsersYear: { title: stats.userActiveYear, query: users, begin: '01 january this year 00:00:00', end: '31 december this year 23:59:59', icon: user, color: yellow }
|
||||||
activeUsersTotal: { title: stats.userActiveTotal, query: users, icon: user, color: red }
|
activeUsersTotal: { title: stats.userActiveTotal, query: users, icon: user, color: red }
|
||||||
activeRecordings: { title: stats.activeRecordings, query: active, icon: duration, color: red }
|
activeRecordings: { title: stats.activeRecordings, query: active, icon: duration, color: red }
|
||||||
|
|
||||||
|
# Default settings used to populate forms
|
||||||
|
#defaults:
|
||||||
|
# customer:
|
||||||
|
# timezone: Europe/Berlin
|
||||||
|
# country: DE
|
||||||
|
# currency: EUR
|
||||||
@@ -54,6 +54,10 @@ services:
|
|||||||
arguments:
|
arguments:
|
||||||
$timesheetAsMarkdown: "%kimai.timesheet.markdown%"
|
$timesheetAsMarkdown: "%kimai.timesheet.markdown%"
|
||||||
|
|
||||||
|
App\Controller\Admin\CustomerController:
|
||||||
|
arguments:
|
||||||
|
$defaults: "%kimai.defaults%"
|
||||||
|
|
||||||
# ================================================================================
|
# ================================================================================
|
||||||
# DATABASE
|
# DATABASE
|
||||||
# ================================================================================
|
# ================================================================================
|
||||||
|
|||||||
@@ -28,6 +28,19 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||||||
*/
|
*/
|
||||||
class CustomerController extends AbstractController
|
class CustomerController extends AbstractController
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $defaults;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $defaults
|
||||||
|
*/
|
||||||
|
public function __construct(array $defaults)
|
||||||
|
{
|
||||||
|
$this->defaults = $defaults;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \App\Repository\CustomerRepository
|
* @return \App\Repository\CustomerRepository
|
||||||
*/
|
*/
|
||||||
@@ -67,7 +80,12 @@ class CustomerController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function createAction(Request $request)
|
public function createAction(Request $request)
|
||||||
{
|
{
|
||||||
return $this->renderCustomerForm(new Customer(), $request);
|
$customer = new Customer();
|
||||||
|
$customer->setCountry($this->defaults['customer']['country']);
|
||||||
|
$customer->setCurrency($this->defaults['customer']['currency']);
|
||||||
|
$customer->setTimezone($this->defaults['customer']['timezone']);
|
||||||
|
|
||||||
|
return $this->renderCustomerForm($customer, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class AppExtension extends Extension implements PrependExtensionInterface
|
|||||||
$container->setParameter('kimai.dashboard', $config['dashboard']);
|
$container->setParameter('kimai.dashboard', $config['dashboard']);
|
||||||
$container->setParameter('kimai.widgets', $config['widgets']);
|
$container->setParameter('kimai.widgets', $config['widgets']);
|
||||||
$container->setParameter('kimai.invoice.documents', $config['invoice']['documents']);
|
$container->setParameter('kimai.invoice.documents', $config['invoice']['documents']);
|
||||||
|
$container->setParameter('kimai.defaults', $config['defaults']);
|
||||||
|
|
||||||
$this->createUserParameter($config, $container);
|
$this->createUserParameter($config, $container);
|
||||||
$this->createTimesheetParameter($config, $container);
|
$this->createTimesheetParameter($config, $container);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->append($this->getThemeNode())
|
->append($this->getThemeNode())
|
||||||
->append($this->getDashboardNode())
|
->append($this->getDashboardNode())
|
||||||
->append($this->getWidgetsNode())
|
->append($this->getWidgetsNode())
|
||||||
|
->append($this->getDefaultsNode())
|
||||||
->end()
|
->end()
|
||||||
->end();
|
->end();
|
||||||
|
|
||||||
@@ -303,4 +304,26 @@ class Configuration implements ConfigurationInterface
|
|||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getDefaultsNode()
|
||||||
|
{
|
||||||
|
$builder = new TreeBuilder();
|
||||||
|
$node = $builder->root('defaults');
|
||||||
|
|
||||||
|
$node
|
||||||
|
->addDefaultsIfNotSet()
|
||||||
|
->children()
|
||||||
|
->arrayNode('customer')
|
||||||
|
->addDefaultsIfNotSet()
|
||||||
|
->children()
|
||||||
|
->scalarNode('timezone')->defaultValue('Europe/Berlin')->end()
|
||||||
|
->scalarNode('country')->defaultValue('DE')->end()
|
||||||
|
->scalarNode('currency')->defaultValue('EUR')->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,16 @@ class CustomerControllerTest extends ControllerBaseTest
|
|||||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||||
$this->assertAccessIsGranted($client, '/admin/customer/create');
|
$this->assertAccessIsGranted($client, '/admin/customer/create');
|
||||||
$form = $client->getCrawler()->filter('form[name=customer_edit_form]')->form();
|
$form = $client->getCrawler()->filter('form[name=customer_edit_form]')->form();
|
||||||
|
|
||||||
|
$kernel = self::bootKernel();
|
||||||
|
$container = $kernel->getContainer();
|
||||||
|
$defaults = $container->getParameter('kimai.defaults')['customer'];
|
||||||
|
|
||||||
|
$editForm = $client->getCrawler()->filter('form[name=customer_edit_form]')->form();
|
||||||
|
$this->assertEquals($defaults['country'], $editForm->get('customer_edit_form[country]')->getValue());
|
||||||
|
$this->assertEquals($defaults['currency'], $editForm->get('customer_edit_form[currency]')->getValue());
|
||||||
|
$this->assertEquals($defaults['timezone'], $editForm->get('customer_edit_form[timezone]')->getValue());
|
||||||
|
|
||||||
$client->submit($form, [
|
$client->submit($form, [
|
||||||
'customer_edit_form' => [
|
'customer_edit_form' => [
|
||||||
'name' => 'Test Customer',
|
'name' => 'Test Customer',
|
||||||
|
|||||||
@@ -232,3 +232,19 @@ kimai:
|
|||||||
days: ['saturday','sunday']
|
days: ['saturday','sunday']
|
||||||
factor: 1.5
|
factor: 1.5
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Forms (kimai.yaml)
|
||||||
|
|
||||||
|
You can set some defaults for various forms within Kimai, to easify the creation process.
|
||||||
|
|
||||||
|
### Customer creation
|
||||||
|
|
||||||
|
Define the default values for a customer like this:
|
||||||
|
```yaml
|
||||||
|
kimai:
|
||||||
|
defaults:
|
||||||
|
customer:
|
||||||
|
timezone: Europe/London
|
||||||
|
country: GB
|
||||||
|
currency: GBP
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user