configs: overwrite via prepend, mode instead of duration_only (#715)

This commit is contained in:
Kevin Papst
2019-04-26 16:14:28 +02:00
committed by GitHub
parent f0f757cf75
commit 32f0d80729
24 changed files with 253 additions and 45 deletions

View File

@@ -11,6 +11,9 @@ namespace App\Configuration;
class TimesheetConfiguration implements SystemBundleConfiguration
{
public const MODE_DURATION_ONLY = 'duration_only';
public const MODE_DEFAULT = 'default';
use StringAccessibleConfigTrait;
public function getPrefix(): string
@@ -25,7 +28,7 @@ class TimesheetConfiguration implements SystemBundleConfiguration
public function isDurationOnly(): bool
{
return (bool) $this->find('duration_only');
return $this->find('mode') === self::MODE_DURATION_ONLY;
}
public function isMarkdownEnabled(): bool

View File

@@ -9,13 +9,15 @@
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as BaseAbstractController;
use Symfony\Component\Translation\DataCollectorTranslator;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* The abstract base controller.
*/
abstract class AbstractController extends Controller
abstract class AbstractController extends BaseAbstractController implements ServiceSubscriberInterface
{
public const FLASH_SUCCESS = 'success';
public const FLASH_WARNING = 'warning';
@@ -89,4 +91,11 @@ abstract class AbstractController extends Controller
$this->addFlash($type, $message);
}
public static function getSubscribedServices()
{
return array_merge(parent::getSubscribedServices(), [
'translator' => TranslatorInterface::class
]);
}
}

View File

@@ -14,6 +14,7 @@ use App\Event\SystemConfigurationEvent;
use App\Form\Model\Configuration;
use App\Form\Model\SystemConfiguration as SystemConfigurationModel;
use App\Form\SystemConfigurationForm;
use App\Form\Type\TimesheetModeType;
use App\Repository\ConfigurationRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -199,11 +200,11 @@ class SystemConfigurationController extends AbstractController
->setSection(SystemConfigurationModel::SECTION_TIMESHEET)
->setConfiguration([
(new Configuration())
->setName('timesheet.markdown_content')
->setType(CheckboxType::class)
->setName('timesheet.mode')
->setType(TimesheetModeType::class)
->setTranslationDomain('system-configuration'),
(new Configuration())
->setName('timesheet.duration_only')
->setName('timesheet.markdown_content')
->setType(CheckboxType::class)
->setTranslationDomain('system-configuration'),
(new Configuration())

View File

@@ -69,7 +69,6 @@ class TimesheetController extends AbstractController
'showFilter' => $form->isSubmitted(),
'toolbarForm' => $form->createView(),
'showSummary' => $this->getUser()->getPreferenceValue('timesheet.daily_stats', false),
'duration_only' => $this->configuration->isDurationOnly(),
]);
}

View File

@@ -65,7 +65,6 @@ class TimesheetTeamController extends AbstractController
'query' => $query,
'showFilter' => $form->isSubmitted(),
'toolbarForm' => $form->createView(),
'duration_only' => $this->configuration->isDurationOnly(),
]);
}

View File

@@ -33,7 +33,7 @@ class CustomerFixtures extends Fixture
public const MIN_BUDGET = 0;
public const MAX_BUDGET = 100000;
public const MIN_GLOBAL_ACTIVITIES = 5;
public const MAX_GLOBAL_ACTIVITIES = 50;
public const MAX_GLOBAL_ACTIVITIES = 30;
public const MIN_PROJECTS_PER_CUSTOMER = 2;
public const MAX_PROJECTS_PER_CUSTOMER = 25;
public const MIN_ACTIVITIES_PER_PROJECT = 0;
@@ -72,7 +72,7 @@ class CustomerFixtures extends Fixture
$amountGlobalActivities = rand(self::MIN_GLOBAL_ACTIVITIES, self::MAX_GLOBAL_ACTIVITIES);
for ($c = 1; $c <= $amountGlobalActivities; $c++) {
$visibleActivity = 0 != $a % 3;
$visibleActivity = 0 != $c % 4;
$activity = $this->createActivity($faker, null, $visibleActivity);
$manager->persist($activity);
}

View File

@@ -32,6 +32,14 @@ class AppExtension extends Extension
$config = [];
}
// @deprecated since 0.9, duration_only will be removed with 1.0
if (isset($config['timesheet']['duration_only'])) {
trigger_error('Configuration "kimai.timesheet.duration_only" is deprecated, please remove it', E_USER_DEPRECATED);
if (true === $config['timesheet']['duration_only'] && 'duration_only' !== $config['timesheet']['mode']) {
trigger_error('Found ambiguous configuration. Please remove "kimai.timesheet.duration_only" and set "kimai.timesheet.mode" instead.');
}
}
// safe alternatives to %kernel.project_dir%
$container->setParameter('kimai.data_dir', $config['data_dir']);
$container->setParameter('kimai.plugin_dir', $config['plugin_dir']);

View File

@@ -75,6 +75,16 @@ class Configuration implements ConfigurationInterface
->children()
->booleanNode('duration_only')
->defaultValue(false)
->setDeprecated()
->end()
->scalarNode('mode')
->defaultValue('default')
->validate()
->ifTrue(function ($value) {
return !in_array($value, ['default', 'duration_only']);
})
->thenInvalid('Chosen timesheet mode is invalid, allowed values: default, duration_only')
->end()
->end()
->booleanNode('markdown_content')
->defaultValue(false)

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use App\Configuration\TimesheetConfiguration;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select the timesheet mode.
*/
class TimesheetModeType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => 'label.timesheet.mode',
'choices' => [
'label.timesheet.mode_default' => TimesheetConfiguration::MODE_DEFAULT,
'label.timesheet.mode_duration_only' => TimesheetConfiguration::MODE_DURATION_ONLY,
],
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}

View File

@@ -17,7 +17,7 @@ class AssetExtension extends BaseAssetExtension
* Overwritten to support subdirectories and subdomains at the same time.
*
* @param string $path
* @param null $packageName
* @param null|string $packageName
* @return mixed|string
*/
public function getAssetUrl($path, $packageName = null)

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Twig;
use App\Configuration\TimesheetConfiguration;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class TimesheetConfigExtension extends AbstractExtension
{
/**
* @var TimesheetConfiguration
*/
protected $configuration;
public function __construct(TimesheetConfiguration $configuration)
{
$this->configuration = $configuration;
}
/**
* @return TwigFunction[]
*/
public function getFunctions()
{
return [
new TwigFunction('is_duration_only', [$this, 'isDurationOnly']),
];
}
public function isDurationOnly(): bool
{
return $this->configuration->isDurationOnly();
}
}