forked from j-guyon/CommandSchedulerBundle
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ScheduledCommandCrudController.php
executable file
·102 lines (91 loc) · 3.57 KB
/
ScheduledCommandCrudController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php /** @noinspection ALL */
namespace App\Controller\Admin;
use Dukecity\CommandSchedulerBundle\Entity\ScheduledCommand;
use Dukecity\CommandSchedulerBundle\Form\Type\CommandChoiceType;
use Dukecity\CommandSchedulerBundle\Service\CommandParser;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Symfony\Component\Security\Http\Attribute\IsGranted;
/**
* @link https://symfony.com/doc/current/bundles/EasyAdminBundle/actions.html
* @link https://github.com/Dukecity/CommandSchedulerBundle/wiki/Integrations
*/
#[IsGranted('ROLE_ADMIN')]
class ScheduledCommandCrudController extends AbstractCrudController
{
public function __construct(private CommandParser $commandParser)
{
}
public static function getEntityFqcn(): string
{
return ScheduledCommand::class;
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setEntityLabelInSingular('ScheduledCommand')
->setEntityLabelInPlural('ScheduledCommands')
->setSearchFields(['name', 'command']);
}
public function configureFields(string $pageName): iterable
{
# translation_domain: 'DukecityCommandScheduler'
#$translationDomain = $context->getI18n()->setTranslationDomain();
$id = IdField::new('id', 'ID')->hideOnForm()->setSortable(false)->hideOnIndex();
$name = TextField::new('name');
# EasyAdmin3 could not handle multidimensional Arrays ;(
$command = ChoiceField::new('command')
#->setChoices($this->commandParser->getCommands())
->setChoices($this->commandParser->reduceNamespacedCommands($this->commandParser->getCommands()))
->setFormType(CommandChoiceType::class)
;
$arguments = TextField::new('arguments');
$cronExpression = TextField::new('cronExpression');
$logFile = TextField::new('logFile');
$priority = IntegerField::new('priority');
$lastExecution = DateTimeField::new('lastExecution');
$lastReturnCode = IntegerField::new('lastReturnCode');
$disabled = BooleanField::new('disabled');
$locked = BooleanField::new('locked');
$executeImmediately = BooleanField::new('executeImmediately');
#$description = TextareaField::new('description');
#$createdAt = DateTimeField::new('createdAt');
# LISTING
if (Crud::PAGE_INDEX === $pageName) {
return [
$id,
$name,
$disabled,
$command,
$arguments,
$cronExpression,
$priority,
$lastExecution->setFormat('short', 'short'),
$lastReturnCode,
$locked
];
}
# CREATE/EDIT
return [
FormField::addPanel('Basic information'),
$id,
$name,
$command,
$arguments,
$cronExpression,
$priority,
$logFile,
$disabled,
$executeImmediately
];
}
}