|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oliverde8\PhpEtlBundle\Controller\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Action; |
|
6
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; |
|
7
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; |
|
8
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters; |
|
9
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\CodeEditorField; |
|
10
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\Field; |
|
11
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
|
12
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Filter\ChoiceFilter; |
|
13
|
|
|
use Oliverde8\PhpEtlBundle\Entity\EtlExecution; |
|
14
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; |
|
15
|
|
|
use Oliverde8\PhpEtlBundle\Services\ChainWorkDirManager; |
|
16
|
|
|
|
|
17
|
|
|
class EtlExecutionCrudController extends AbstractCrudController |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var ChainWorkDirManager */ |
|
20
|
|
|
protected $chainWorkDirManager; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* EtlExecutionCrudController constructor. |
|
24
|
|
|
* @param ChainWorkDirManager $chainWorkDirManager |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(ChainWorkDirManager $chainWorkDirManager) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->chainWorkDirManager = $chainWorkDirManager; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public static function getEntityFqcn(): string |
|
33
|
|
|
{ |
|
34
|
|
|
return EtlExecution::class; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function configureActions(Actions $actions): Actions |
|
38
|
|
|
{ |
|
39
|
|
|
return $actions |
|
40
|
|
|
->remove(Crud::PAGE_INDEX, Action::NEW) |
|
41
|
|
|
->remove(Crud::PAGE_INDEX, Action::EDIT) |
|
42
|
|
|
->remove(Crud::PAGE_INDEX, Action::DELETE) |
|
43
|
|
|
|
|
44
|
|
|
->add(Crud::PAGE_INDEX, Action::DETAIL) |
|
45
|
|
|
->remove(Crud::PAGE_DETAIL, Action::EDIT) |
|
46
|
|
|
->remove(Crud::PAGE_DETAIL, Action::DELETE); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function configureCrud(Crud $crud): Crud |
|
50
|
|
|
{ |
|
51
|
|
|
return $crud |
|
52
|
|
|
->setPageTitle("index", "Etl Executions") |
|
53
|
|
|
->setDateTimeFormat('dd/MM/y - HH:mm:ss') |
|
54
|
|
|
->setSearchFields(["name", "id"]) |
|
55
|
|
|
->setDefaultSort(['startTime' => 'DESC']); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function configureFields(string $pageName): iterable |
|
59
|
|
|
{ |
|
60
|
|
|
if (Crud::PAGE_DETAIL === $pageName) { |
|
61
|
|
|
return [ |
|
62
|
|
|
Field::new('name'), |
|
63
|
|
|
Field::new('status'), |
|
64
|
|
|
Field::new('startTime'), |
|
65
|
|
|
Field::new('endTime'), |
|
66
|
|
|
Field::new('failTime'), |
|
67
|
|
|
TextField::new('Files')->formatValue(function ($value, EtlExecution $entity) { |
|
68
|
|
|
// TODO create url's. |
|
69
|
|
|
return $this->chainWorkDirManager->listFiles($entity); |
|
70
|
|
|
})->setTemplatePath('@Oliverde8PhpEtl/fields/files.html.twig'), |
|
71
|
|
|
CodeEditorField::new('inputData')->setTemplatePath('@Oliverde8PhpEtl/fields/code_editor.html.twig'), |
|
72
|
|
|
CodeEditorField::new('inputOptions')->setTemplatePath('@Oliverde8PhpEtl/fields/code_editor.html.twig'), |
|
73
|
|
|
CodeEditorField::new('definition')->setTemplatePath('@Oliverde8PhpEtl/fields/code_editor.html.twig'), |
|
74
|
|
|
CodeEditorField::new('errorMessage')->setTemplatePath('@Oliverde8PhpEtl/fields/code_editor.html.twig'), |
|
75
|
|
|
]; |
|
76
|
|
|
} |
|
77
|
|
|
if (Crud::PAGE_INDEX === $pageName) { |
|
78
|
|
|
return [ |
|
79
|
|
|
Field::new('id'), |
|
80
|
|
|
Field::new('name'), |
|
81
|
|
|
TextField::new('status')->setTemplatePath('@Oliverde8PhpEtl/fields/status.html.twig'), |
|
82
|
|
|
Field::new('startTime'), |
|
83
|
|
|
Field::new('endTime'), |
|
84
|
|
|
]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return parent::configureFields($pageName); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
public function configureFilters(Filters $filters): Filters |
|
92
|
|
|
{ |
|
93
|
|
|
return $filters |
|
94
|
|
|
->add('name') |
|
95
|
|
|
->add( |
|
96
|
|
|
ChoiceFilter::new('status')->setChoices([ |
|
97
|
|
|
EtlExecution::STATUS_WAITING => EtlExecution::STATUS_WAITING, |
|
98
|
|
|
EtlExecution::STATUS_RUNNING => EtlExecution::STATUS_RUNNING, |
|
99
|
|
|
EtlExecution::STATUS_SUCCESS => EtlExecution::STATUS_SUCCESS, |
|
100
|
|
|
EtlExecution::STATUS_FAILURE => EtlExecution::STATUS_FAILURE, |
|
101
|
|
|
])->canSelectMultiple() |
|
102
|
|
|
) |
|
103
|
|
|
->add('startTime') |
|
104
|
|
|
->add('endTime'); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|