-
Notifications
You must be signed in to change notification settings - Fork 0
/
GridFactory.php
99 lines (84 loc) · 2.66 KB
/
GridFactory.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
<?php
namespace Sallyx\RabbitMqLogger\Controls\Doctrine;
use Kdyby\Doctrine\EntityManager;
use Nette\Application\UI\Component;
use Ublaboo\DataGrid\DataGrid;
use Sallyx\RabbitMqLogger\Model\Doctrine\Entity\NetteExceptionsLog;
use Sallyx\RabbitMqLogger\Controls\GridFactory as IGridFactory;
class GridFactory implements IGridFactory {
use \Nette\SmartObject;
/** @var EntityManager */
private $em;
/** @var string */
private $exceptionRoute;
/** @var string */
private $exceptionSecret;
/**
* @param EntityManager $em
* @param array $exConfig
*/
public function __construct(EntityManager $em, array $exConfig) {
$this->em = $em;
$this->exceptionRoute = $exConfig['route'];
$this->exceptionSecret = $exConfig['secret'];
}
/**
* @return Component
*/
public function create() {
$ds = $this->em->createQueryBuilder()
->select('message')
->from('Sallyx\RabbitMqLogger\Model\Doctrine\Entity\NetteExceptionsLog', 'message');
$grid = new DataGrid(NULL, 'rabbit-mq-logger-grid');
$grid->setDataSource($ds);
$grid->setDefaultSort(['id' => 'DESC']);
$grid->setColumnsHideable();
$grid->addColumnText('id', 'Id')
->setSortable();
$grid->addColumnText('guid', 'Guid')
->setSortable()
->setFilterText();
$grid->addColumnText('location', 'Location')
->setSortable()
->setFilterText();
$grid->addColumnDateTime('timestamp', 'Thrown')
->setSortable()
->setFormat('y/m/d H:i:s');
$grid->addColumnDateTime('created', 'Logged')
->setSortable()
->setFormat('y/m/d H:i:s')
->setDefaultHide(TRUE);
$grid->addColumnText('priority', 'Priority')
->setSortable()
->setFilterText();
$ef = $grid->addColumnText('exceptionFile', 'Exception File');
$grid->addColumnText('errorText', 'Error');
if (!empty($this->exceptionSecret)) {
$efRenderer = function($item) {
if (empty($item->exceptionFile)) {
return '';
}
return "<a target='_blank' href='$item->location$this->exceptionRoute?secret=$this->exceptionSecret&file=$item->exceptionFile'>"
. $item->exceptionFile
. '</a>';
};
$ef->setRenderer($efRenderer)->setTemplateEscaping(FALSE);
}
$that = $this;
$grid->addActionCallback('delete', '')
->setIcon('trash')
->setTitle('Delete row')
->setClass('btn btn-xs btn-danger ajax')
->setConfirm('Do you really want to delete row %s?', 'id')
->onClick[] = function($id) use ($that, $grid) {
$that->handleDelete($id);
$grid->redrawControl();
};
return $grid;
}
public function handleDelete($id) {
$message = $this->em->find('Sallyx\RabbitMqLogger\Model\Doctrine\Entity\NetteExceptionsLog', $id);
$this->em->remove($message);
$this->em->flush();
}
}