From 978a1651bac3faf5e91ddba327bf39aeb6a4cb63 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:28:59 +0200 Subject: Adding upstream version 0.10.0. Signed-off-by: Daniel Baumann --- application/controllers/ReportController.php.modal | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 application/controllers/ReportController.php.modal (limited to 'application/controllers/ReportController.php.modal') diff --git a/application/controllers/ReportController.php.modal b/application/controllers/ReportController.php.modal new file mode 100644 index 0000000..915bf2b --- /dev/null +++ b/application/controllers/ReportController.php.modal @@ -0,0 +1,126 @@ +report = Report::fromDb($this->params->getRequired('id')); + } + + public function indexAction() + { + $this->setTitle($this->report->getName()); + + $this->addControl($this->assembleActions()); + + $this->addContent($this->report->toHtml()); + } + + public function editAction() + { + $this->setTitle('Edit Report'); + + $values = [ + 'name' => $this->report->getName(), + 'timeframe' => $this->report->getTimeframe()->getId(), + ]; + + $reportlet = $this->report->getReportlets()[0]; + + $values['reportlet'] = $reportlet->getClass(); + + foreach ($reportlet->getConfig() as $name => $value) { + $values[$name] = $value; + } + + $form = new ReportForm(); + $form->setId($this->report->getId()); + $form->populate($values); + $form->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, 'reporting/reports'); + + $this->addContent($form); + } + + public function sendAction() + { + $this->setTitle('Send Report'); + + $form = new SendForm(); + $form + ->setReport($this->report) + ->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); + + $this->addContent(new Modal($form)); + } + + public function scheduleAction() + { + $this->setTitle('Schedule'); + + $form = new ScheduleForm(); + $form + ->setReport($this->report) + ->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); + + $this->addContent(new Modal($form)); + + $this->getResponse()->setHeader('X-Icinga-History', 'no', true); + } + + protected function assembleActions() + { + $reportId = $this->report->getId(); + + $download = (new DropdownLink('Download')) + ->addLink('PDF', Url::fromPath('reporting/report/download?type=pdf', ['id' => $reportId])); + + $send = (new DropdownLink('Send', 'forward')) + ->addLink('PDF', Url::fromPath('reporting/report/send?type=pdf', ['id' => $reportId])); + + if ($this->report->providesCsv()) { + $download->addLink('CSV', Url::fromPath('reporting/report/download?type=csv', ['id' => $reportId])); + $send->addLink('CSV', Url::fromPath('reporting/report/send?type=csv', ['id' => $reportId])); + } + + if ($this->report->providesJson()) { + $download->addLink('JSON', Url::fromPath('reporting/report/download?type=json', ['id' => $reportId])); + $send->addLink('JSON', Url::fromPath('reporting/report/send?type=json', ['id' => $reportId])); + } + + $actions = new ActionBar(); + + $actions + ->addLink('Modify', Url::fromPath('reporting/report/edit', ['id' => $reportId]), 'edit') + ->add(new ModalToggle('Schedule', Url::fromPath('reporting/report/schedule', ['id' => $reportId]), 'calendar-empty')) + ->add($download) + ->addLink('Send', Url::fromPath('reporting/report/send', ['id' => $reportId]), 'forward'); + + return $actions; + } +} -- cgit v1.2.3