-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathReportsController.php
150 lines (128 loc) · 4.94 KB
/
ReportsController.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2
namespace Icinga\Module\Reporting\Controllers;
use Icinga\Module\Icingadb\ProvidedHook\Reporting\HostSlaReport;
use Icinga\Module\Icingadb\ProvidedHook\Reporting\ServiceSlaReport;
use Icinga\Module\Reporting\Database;
use Icinga\Module\Reporting\Model\Report;
use Icinga\Module\Reporting\Web\Controller;
use Icinga\Module\Reporting\Web\Forms\ReportForm;
use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs;
use ipl\Html\Html;
use ipl\Web\Url;
use ipl\Web\Widget\ButtonLink;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
class ReportsController extends Controller
{
use Database;
use ReportsTimeframesAndTemplatesTabs;
public function indexAction()
{
$this->createTabs()->activate('reports');
if ($this->hasPermission('reporting/reports/modify')) {
$this->addControl(new ButtonLink(
$this->translate('New Report'),
Url::fromPath('reporting/reports/new'),
'plus',
[
'data-icinga-modal' => true,
'data-no-icinga-ajax' => true
]
));
}
$tableRows = [];
$reports = Report::on($this->getDb())
->withColumns(['report.timeframe.name']);
$this->applyRestriction($reports, 'name');
$sortControl = $this->createSortControl(
$reports,
[
'name' => $this->translate('Name'),
'author' => $this->translate('Author'),
'ctime' => $this->translate('Created At'),
'mtime' => $this->translate('Modified At')
]
);
$this->addControl($sortControl);
foreach ($reports as $report) {
$url = Url::fromPath('reporting/report', ['id' => $report->id])->getAbsoluteUrl('&');
$content = [
Html::tag('td', null, $report->name),
Html::tag('td', null, $report->author),
Html::tag('td', null, $report->timeframe->name),
Html::tag('td', null, $report->ctime->format('Y-m-d H:i')),
Html::tag('td', null, $report->mtime->format('Y-m-d H:i')),
];
if ($this->hasPermission('reporting/reports/modify')) {
$content[] = Html::tag('td', ['class' => 'icon-col'], [
new Link(
new Icon('edit'),
Url::fromPath('reporting/report/edit', ['id' => $report->id]),
[
'data-icinga-modal' => true,
'data-no-icinga-ajax' => true
]
)
]);
}
$tableRows[] = Html::tag('tr', ['href' => $url], $content);
}
if (! empty($tableRows)) {
$table = Html::tag(
'table',
['class' => 'common-table table-row-selectable', 'data-base-target' => '_next'],
[
Html::tag(
'thead',
null,
Html::tag(
'tr',
null,
[
Html::tag('th', null, 'Name'),
Html::tag('th', null, 'Author'),
Html::tag('th', null, 'Timeframe'),
Html::tag('th', null, 'Date Created'),
Html::tag('th', null, 'Date Modified'),
Html::tag('th')
]
)
),
Html::tag('tbody', null, $tableRows)
]
);
$this->addContent($table);
} else {
$this->addContent(Html::tag('p', null, 'No reports created yet.'));
}
}
public function newAction()
{
$this->assertPermission('reporting/reports/modify');
$this->addTitleTab($this->translate('New Report'));
switch ($this->params->shift('report')) {
case 'host':
$class = HostSlaReport::class;
break;
case 'service':
$class = ServiceSlaReport::class;
break;
default:
$class = null;
break;
}
$form = (new ReportForm())
->setAction((string) Url::fromRequest())
->populate([
'filter' => $this->params->shift('filter'),
'reportlet' => $class
])
->on(ReportForm::ON_SUCCESS, function () {
$this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true);
$this->redirectNow('__CLOSE__');
})
->handleRequest($this->getServerRequest());
$this->addContent($form);
}
}