From c22a2c3ebc334fd7a891370e43a841d914893d47 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:29:17 +0200 Subject: Merging upstream version 1.0.1. Signed-off-by: Daniel Baumann --- .mailmap | 15 + .phpcs.xml | 25 - AUTHORS | 16 + README.md | 12 +- application/clicommands/DownloadCommand.php | 98 + application/clicommands/ListCommand.php | 133 + application/clicommands/ScheduleCommand.php | 120 +- application/controllers/ConfigController.php | 1 + application/controllers/ReportController.php | 216 +- application/controllers/ReportsController.php | 95 +- application/controllers/TemplateController.php | 107 +- application/controllers/TemplatesController.php | 75 +- application/controllers/TestController.php | 47 - application/controllers/TimeframeController.php | 41 +- application/controllers/TimeframesController.php | 61 +- application/forms/ConfigureMailForm.php | 1 + application/forms/SelectBackendForm.php | 11 +- configuration.php | 8 +- doc/02-Installation.md | 69 +- doc/03-Configuration.md | 51 +- doc/80-Upgrading.md | 40 +- library/Reporting/Actions/SendMail.php | 40 +- library/Reporting/Cli/Command.php | 4 +- library/Reporting/Database.php | 103 +- library/Reporting/Dimensions.php | 1 + library/Reporting/Hook/ActionHook.php | 8 +- library/Reporting/Hook/ReportHook.php | 13 +- library/Reporting/Mail.php | 19 +- library/Reporting/Model/Config.php | 47 + library/Reporting/Model/Report.php | 71 + library/Reporting/Model/Reportlet.php | 48 + library/Reporting/Model/Schedule.php | 48 + library/Reporting/Model/Schema.php | 49 + library/Reporting/Model/Template.php | 53 + library/Reporting/Model/Timeframe.php | 53 + library/Reporting/ProvidedActions.php | 1 + library/Reporting/ProvidedHook/DbMigration.php | 79 + library/Reporting/ProvidedReports.php | 1 + library/Reporting/Report.php | 249 +- library/Reporting/ReportData.php | 1 + library/Reporting/ReportRow.php | 1 + library/Reporting/Reportlet.php | 62 +- library/Reporting/Reports/SystemReport.php | 29 +- library/Reporting/RetryConnection.php | 1 + library/Reporting/Schedule.php | 177 +- library/Reporting/Scheduler.php | 176 -- library/Reporting/Str.php | 3 + library/Reporting/Timeframe.php | 97 +- library/Reporting/Timerange.php | 1 + library/Reporting/Values.php | 1 + library/Reporting/Web/Controller.php | 11 +- library/Reporting/Web/Flatpickr.php | 77 - library/Reporting/Web/Forms/DecoratedElement.php | 17 - .../Web/Forms/Decorator/CompatDecorator.php | 63 - library/Reporting/Web/Forms/ReportForm.php | 179 +- library/Reporting/Web/Forms/ScheduleForm.php | 195 +- library/Reporting/Web/Forms/SendForm.php | 8 +- library/Reporting/Web/Forms/TemplateForm.php | 190 +- library/Reporting/Web/Forms/TimeframeForm.php | 195 +- .../Web/ReportsTimeframesAndTemplatesTabs.php | 22 +- library/Reporting/Web/Widget/CompatDropdown.php | 1 + library/Reporting/Web/Widget/CoverPage.php | 18 +- library/Reporting/Web/Widget/HeaderOrFooter.php | 10 +- library/Reporting/Web/Widget/Template.php | 44 +- .../ipl/Html/src/FormElement/FileElement.php | 15 - module.info | 4 +- phpcs.xml | 22 + phpstan-baseline.neon | 1126 +++++++++ phpstan.neon | 35 + public/css/module.less | 44 +- public/css/vendor/flatpickr.css | 784 ------ public/css/vendor/flatpickr.min.css | 13 - public/js/module.js | 50 - public/js/vendor/flatpickr.js | 2605 -------------------- public/js/vendor/flatpickr.min.js | 2 - run.php | 3 + schema/mysql-migrations/v0.10.0.sql | 12 - schema/mysql-migrations/v0.9.1.sql | 9 - schema/mysql-upgrades/0.10.0.sql | 12 + schema/mysql-upgrades/0.9.1.sql | 9 + schema/mysql-upgrades/1.0.0.sql | 64 + schema/mysql.schema.sql | 108 + schema/mysql.sql | 96 - schema/pgsql-upgrades/1.0.0.sql | 44 + schema/pgsql.schema.sql | 95 + schema/postgresql.sql | 83 - 86 files changed, 3821 insertions(+), 5122 deletions(-) create mode 100644 .mailmap delete mode 100644 .phpcs.xml create mode 100644 AUTHORS create mode 100644 application/clicommands/DownloadCommand.php create mode 100644 application/clicommands/ListCommand.php delete mode 100644 application/controllers/TestController.php create mode 100644 library/Reporting/Model/Config.php create mode 100644 library/Reporting/Model/Report.php create mode 100644 library/Reporting/Model/Reportlet.php create mode 100644 library/Reporting/Model/Schedule.php create mode 100644 library/Reporting/Model/Schema.php create mode 100644 library/Reporting/Model/Template.php create mode 100644 library/Reporting/Model/Timeframe.php create mode 100644 library/Reporting/ProvidedHook/DbMigration.php delete mode 100644 library/Reporting/Scheduler.php delete mode 100644 library/Reporting/Web/Flatpickr.php delete mode 100644 library/Reporting/Web/Forms/DecoratedElement.php delete mode 100644 library/Reporting/Web/Forms/Decorator/CompatDecorator.php delete mode 100644 library/vendor/ipl/Html/src/FormElement/FileElement.php create mode 100644 phpcs.xml create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon delete mode 100644 public/css/vendor/flatpickr.css delete mode 100644 public/css/vendor/flatpickr.min.css delete mode 100644 public/js/module.js delete mode 100644 public/js/vendor/flatpickr.js delete mode 100644 public/js/vendor/flatpickr.min.js delete mode 100644 schema/mysql-migrations/v0.10.0.sql delete mode 100644 schema/mysql-migrations/v0.9.1.sql create mode 100644 schema/mysql-upgrades/0.10.0.sql create mode 100644 schema/mysql-upgrades/0.9.1.sql create mode 100644 schema/mysql-upgrades/1.0.0.sql create mode 100644 schema/mysql.schema.sql delete mode 100644 schema/mysql.sql create mode 100644 schema/pgsql-upgrades/1.0.0.sql create mode 100644 schema/pgsql.schema.sql delete mode 100644 schema/postgresql.sql diff --git a/.mailmap b/.mailmap new file mode 100644 index 0000000..ff29528 --- /dev/null +++ b/.mailmap @@ -0,0 +1,15 @@ +Damiano Chini +Dirk Götz +Eric Lippmann +Florian Rosenegger +J. Nathanael Philipp +Johannes Meyer +Jonada Hoxha +Mathieu Lu +Michael Friedrich +Nicolai Buchwitz +Ravi Kumar Kempapura Srinivasa +Sukhwinder Dhillon +Timm Ortloff +Valentina Da Rold +Yonas Habteab diff --git a/.phpcs.xml b/.phpcs.xml deleted file mode 100644 index d1d0ed7..0000000 --- a/.phpcs.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - Sniff our code a while - - ./ - - vendor/* - - - - - - - - - - - - - - - - - - diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..a91ae29 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,16 @@ +Damiano Chini +Dirk Götz +Eric Lippmann +Florian Rosenegger +J. Nathanael Philipp +Johannes Meyer +Jonada Hoxha +MAJ +Mathieu Lu +Michael Friedrich +Nicolai Buchwitz +Ravi Kumar Kempapura Srinivasa +Sukhwinder Dhillon +Timm Ortloff +Valentina Da Rold +Yonas Habteab diff --git a/README.md b/README.md index c2413f9..5e477d8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Icinga Reporting -[![PHP Support](https://img.shields.io/badge/php-%3E%3D%207.0-777BB4?logo=PHP)](https://php.net/) -![Build Status](https://github.com/icinga/icingaweb2-module-reporting/workflows/PHP%20Tests/badge.svg?branch=master) -[![Github Tag](https://img.shields.io/github/tag/Icinga/icingaweb2-module-reporting.svg)](https://github.com/Icinga/icingaweb2-module-reporting) +[![PHP Support](https://img.shields.io/badge/php-%3E%3D%207.2-777BB4?logo=PHP)](https://php.net/) +[![PHP Tests](https://github.com/Icinga/icingaweb2-module-reporting/actions/workflows/php.yml/badge.svg)](https://github.com/Icinga/icingaweb2-module-reporting/actions/workflows/php.yml) +[![Github Tag](https://img.shields.io/github/tag/Icinga/icingaweb2-module-reporting.svg)](https://github.com/Icinga/icingaweb2-module-reporting/releases/latest) ![Icinga Logo](https://icinga.com/wp-content/uploads/2014/06/icinga_logo.png) @@ -10,7 +10,11 @@ Icinga Reporting is the central component for reporting related functionality in framework Icinga Web 2. The engine allows you to create reports over a specified time period for ad-hoc and scheduled generation of reports. Other modules use the provided functionality in order to provide concrete reports. -If you are looking for SLA reports for your hosts and services, please also install the +## Host/Service SLA Reports + +With Icinga DB Web there is no additional module required. + +If you are still using the monitoring module, please also install the [idoreports](https://github.com/Icinga/icingaweb2-module-idoreports) module. ## Documentation diff --git a/application/clicommands/DownloadCommand.php b/application/clicommands/DownloadCommand.php new file mode 100644 index 0000000..9b7c99d --- /dev/null +++ b/application/clicommands/DownloadCommand.php @@ -0,0 +1,98 @@ + [--format=] + * + * OPTIONS + * + * --format= + * Download report as PDF, CSV or JSON. Defaults to pdf. + * + * --output= + * Save report to the specified . + * + * EXAMPLES + * + * Download report with ID 1: + * icingacli reporting download 1 + * + * Download report with ID 1 as CSV: + * icingacli reporting download 1 --format=csv + * + * Download report with ID 1 as JSON to the specified file: + * icingacli reporting download 1 --format=json --output=sla.json + */ + public function defaultAction() + { + $id = $this->params->getStandalone(); + if ($id === null) { + $this->fail($this->translate('Argument id is mandatory')); + } + + /** @var Model\Report $report */ + $report = Model\Report::on(Database::get()) + ->with('timeframe') + ->filter(Filter::equal('id', $id)) + ->first(); + + if ($report === null) { + throw new NotFoundError('Report not found'); + } + + $report = Report::fromModel($report); + + /** @var string $format */ + $format = $this->params->get('format', 'pdf'); + $format = strtolower($format); + switch ($format) { + case 'pdf': + $content = Pdfexport::first()->htmlToPdf($report->toPdf()); + break; + case 'csv': + $content = $report->toCsv(); + break; + case 'json': + $content = $report->toJson(); + break; + default: + throw new InvalidArgumentException(sprintf('Format %s is not supported', $format)); + } + + /** @var string $output */ + $output = $this->params->get('output'); + if ($output === null) { + $name = sprintf( + '%s (%s) %s', + $report->getName(), + $report->getTimeframe()->getName(), + date('Y-m-d H:i') + ); + + $output = "$name.$format"; + } elseif (is_dir($output)) { + $this->fail($this->translate(sprintf('%s is a directory', $output))); + } + + file_put_contents($output, $content); + echo "$output\n"; + } +} diff --git a/application/clicommands/ListCommand.php b/application/clicommands/ListCommand.php new file mode 100644 index 0000000..2486ae0 --- /dev/null +++ b/application/clicommands/ListCommand.php @@ -0,0 +1,133 @@ + + * Sort the reports by the given column. Defaults to id. + * + * --direction= + * Sort the reports by the specified sort column in ascending or descending order. Defaults to asc. + * + * --filter= + * Filter the reports by the specified report name. Performs a wildcard search by default. + * + * EXAMPLES + * + * Sort the reports by name: + * icingacli reporting list --sort=name + * + * Sort the reports by author in descending order: + * icingacli reporting list --sort=author --direction=DESC + * + * Filter the reports that contain "Host" in the report name: + * icingacli reporting list --filter=Host + * + * Filter the reports that begin with "Service": + * icingacli reporting list --filter=Service* + * + * Filter the reports that end with "SLA": + * icingacli reporting list --filter=*SLA + */ + public function indexAction() + { + /** @var string $sort */ + $sort = $this->params->get('sort', 'id'); + $sort = strtolower($sort); + + if ($sort !== 'id' && $sort !== 'name' && $sort !== 'author') { + throw new InvalidArgumentException(sprintf('Sorting by %s is not supported', $sort)); + } + + $direction = $this->params->get('direction', 'ASC'); + + $reports = Model\Report::on(Database::get()); + $reports + ->with(['reportlets']) + ->orderBy($sort, $direction); + + $filter = $this->params->get('filter'); + if ($filter !== null) { + if (strpos($filter, '*') === false) { + $filter = '*' . $filter . '*'; + } + $reports->filter(Filter::like('name', $filter)); + } + + if ($reports->count() === 0) { + print $this->translate("No reports found\n"); + exit; + } + + $dataCallbacks = [ + 'ID' => function ($report) { + return $report->id; + }, + 'Name' => function ($report) { + return $report->name; + }, + 'Author' => function ($report) { + return $report->author; + }, + 'Type' => function ($report) { + return (new $report->reportlets->class())->getName(); + } + ]; + + $this->outputTable($reports, $dataCallbacks); + } + + protected function outputTable($reports, array $dataCallbacks) + { + $columnsAndLengths = []; + foreach ($dataCallbacks as $key => $_) { + $columnsAndLengths[$key] = strlen($key); + } + + $rows = []; + foreach ($reports as $report) { + $row = []; + foreach ($dataCallbacks as $key => $callback) { + $row[] = $callback($report); + $columnsAndLengths[$key] = max($columnsAndLengths[$key], mb_strlen($callback($report))); + } + + $rows[] = $row; + } + + $format = '|'; + $beautifier = '|'; + foreach ($columnsAndLengths as $length) { + $headerFormat = " %-" . sprintf('%ss |', $length); + $format .= $headerFormat; + $beautifier .= sprintf($headerFormat, str_repeat('-', $length)); + } + $format .= "\n"; + $beautifier .= "\n"; + + printf($format, ...array_keys($columnsAndLengths)); + print $beautifier; + + foreach ($rows as $row) { + printf($format, ...$row); + } + } +} diff --git a/application/clicommands/ScheduleCommand.php b/application/clicommands/ScheduleCommand.php index e554138..f50d046 100644 --- a/application/clicommands/ScheduleCommand.php +++ b/application/clicommands/ScheduleCommand.php @@ -1,10 +1,25 @@ getDb()); + $scheduler = new Scheduler(); + $this->attachJobsLogging($scheduler); + + /** @var Schedule[] $runningSchedules */ + $runningSchedules = []; + // Check for configuration changes every 5 minutes to make sure new jobs are scheduled, updated and deleted + // jobs are cancelled. + $watchdog = function () use (&$watchdog, $scheduler, &$runningSchedules) { + $schedules = []; + try { + // Since this is a long-running daemon, the resources or module config may change meanwhile. + // Therefore, reload the resources and module config from disk each time (at 5m intervals) + // before reconnecting to the database. + ResourceFactory::setConfig(Config::app('resources', true)); + Config::module('reporting', 'config', true); + + $schedules = $this->fetchSchedules(); + } catch (Throwable $err) { + Logger::error('Failed to fetch report schedules from the database: %s', $err); + Logger::debug($err->getTraceAsString()); + } + + $outdated = array_diff_key($runningSchedules, $schedules); + foreach ($outdated as $schedule) { + Logger::info( + 'Removing %s as it either no longer exists in the database or its config has been changed', + $schedule->getName() + ); + + $scheduler->remove($schedule); + + unset($runningSchedules[$schedule->getUuid()->toString()]); + } + + $newSchedules = array_diff_key($schedules, $runningSchedules); + foreach ($newSchedules as $key => $schedule) { + $config = $schedule->getConfig(); + $frequency = $config['frequency']; + + try { + /** @var Frequency $type */ + $type = $config['frequencyType']; + $frequency = $type::fromJson($frequency); + } catch (Exception $err) { + Logger::error( + '%s has invalid schedule expression %s: %s', + $schedule->getName(), + $frequency, + $err->getMessage() + ); + + continue; + } + + $scheduler->schedule($schedule, $frequency); + + $runningSchedules[$key] = $schedule; + } + + Loop::addTimer(5 * 60, $watchdog); + }; + Loop::futureTick($watchdog); + } + + /** + * Fetch schedules from the database + * + * @return Schedule[] + */ + protected function fetchSchedules(): array + { + $schedules = []; + $query = Model\Schedule::on(Database::get())->with(['report.timeframe', 'report']); + + foreach ($query as $schedule) { + $schedule = Schedule::fromModel($schedule, Report::fromModel($schedule->report)); + $schedules[$schedule->getUuid()->toString()] = $schedule; + } + + return $schedules; + } + + protected function attachJobsLogging(Scheduler $scheduler) + { + $scheduler->on(Scheduler::ON_TASK_FAILED, function (Task $job, Throwable $e) { + Logger::error('Failed to run job %s: %s', $job->getName(), $e->getMessage()); + Logger::debug($e->getTraceAsString()); + }); + + $scheduler->on(Scheduler::ON_TASK_RUN, function (Task $job, ExtendedPromiseInterface $_) { + Logger::info('Running job %s', $job->getName()); + }); + + $scheduler->on(Scheduler::ON_TASK_SCHEDULED, function (Task $job, DateTime $dateTime) { + Logger::info('Scheduling job %s to run at %s', $job->getName(), $dateTime->format('Y-m-d H:i:s')); + }); - $scheduler->run(); + $scheduler->on(Scheduler::ON_TASK_EXPIRED, function (Task $task, DateTime $dateTime) { + Logger::info( + sprintf('Detaching expired job %s at %s', $task->getName(), $dateTime->format('Y-m-d H:i:s')) + ); + }); } } diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 30fcc67..7e73c3c 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -1,4 +1,5 @@ report = Report::fromDb($this->params->getRequired('id')); + $reportId = $this->params->getRequired('id'); + + /** @var Model\Report $report */ + $report = Model\Report::on(Database::get()) + ->with(['timeframe']) + ->filter(Filter::equal('id', $reportId)) + ->first(); + + if ($report === null) { + $this->httpNotFound($this->translate('Report not found')); + } + + $this->report = Report::fromModel($report); } public function indexAction() { $this->addTitleTab($this->report->getName()); + $this->controls->getAttributes()->add('class', 'default-layout'); $this->addControl($this->assembleActions()); + if ($this->isXhr()) { + /** @var string $contentId */ + $contentId = $this->content->getAttributes()->get('id')->getValue(); + $this->sendExtraUpdates([ + $contentId => Url::fromPath('reporting/report/content', ['id' => $this->report->getId()]) + ]); + + // Will be replaced once the report content is rendered + $this->addContent(new HtmlElement('div')); + } else { + Environment::raiseExecutionTime(); + Environment::raiseMemoryLimit(); + + try { + $this->addContent($this->report->toHtml()); + } catch (Exception $e) { + $this->addContent(Error::show($e)); + } + } + } + + public function contentAction(): void + { Environment::raiseExecutionTime(); Environment::raiseMemoryLimit(); + $this->view->compact = true; + $this->_helper->layout()->disableLayout(); + try { - $this->addContent($this->report->toHtml()); - } catch (\Exception $e) { - $this->addContent(Error::show($e)); + $this->getDocument()->addHtml($this->report->toHtml()); + } catch (Exception $e) { + $this->getDocument()->addHtml(Error::show($e)); + } + } + + public function cloneAction() + { + $this->assertPermission('reporting/reports'); + $this->addTitleTab($this->translate('Clone Report')); + + $values = ['timeframe' => (string) $this->report->getTimeframe()->getId()]; + + $reportlet = $this->report->getReportlets()[0]; + + $values['reportlet'] = $reportlet->getClass(); + + foreach ($reportlet->getConfig() as $name => $value) { + if ($name === 'name') { + if (preg_match('/(?:Clone )(\d+)$/', $value, $m)) { + $value = preg_replace('/\d+$/', (string) ((int) $m[1] + 1), $value); + } else { + $value .= ' Clone 1'; + } + } + + $values[$name] = $value; } + + $form = (new ReportForm()) + ->setSubmitButtonLabel($this->translate('Clone Report')) + ->setAction((string) Url::fromRequest()) + ->populate($values) + ->on(ReportForm::ON_SUCCESS, function (ReportForm $form) { + Notification::success($this->translate('Cloned report successfully')); + + $this->sendExtraUpdates(['#col1']); + + $this->redirectNow(Url::fromPath('reporting/report', ['id' => $form->getId()])); + }) + ->handleRequest($this->getServerRequest()); + + $this->addContent($form); } public function editAction() { $this->assertPermission('reporting/reports'); - $this->addTitleTab('Edit Report'); + $this->addTitleTab($this->translate('Edit Report')); $values = [ 'name' => $this->report->getName(), @@ -66,29 +148,44 @@ class ReportController extends Controller $values[$name] = $value; } - $form = new ReportForm(); - $form->setId($this->report->getId()); - $form->populate($values); - $form->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, 'reporting/reports'); + $form = ReportForm::fromId($this->report->getId()) + ->setAction((string) Url::fromRequest()) + ->populate($values) + ->on(ReportForm::ON_SUCCESS, function (ReportForm $form) { + $pressedButton = $form->getPressedSubmitElement(); + if ($pressedButton && $pressedButton->getName() === 'remove') { + Notification::success($this->translate('Removed report successfully')); + + $this->switchToSingleColumnLayout(); + } else { + Notification::success($this->translate('Updated report successfully')); + + $this->closeModalAndRefreshRemainingViews( + Url::fromPath('reporting/report', ['id' => $this->report->getId()]) + ); + } + }) + ->handleRequest($this->getServerRequest()); $this->addContent($form); } public function sendAction() { - $this->addTitleTab('Send Report'); + $this->addTitleTab($this->translate('Send Report')); Environment::raiseExecutionTime(); Environment::raiseMemoryLimit(); - $form = new SendForm(); - $form + $form = (new SendForm()) ->setReport($this->report) - ->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); + ->setAction((string) Url::fromRequest()) + ->on(SendForm::ON_SUCCESS, function () { + $this->closeModalAndRefreshRelatedView( + Url::fromPath('reporting/report', ['id' => $this->report->getId()]) + ); + }) + ->handleRequest($this->getServerRequest()); $this->addContent($form); } @@ -96,16 +193,38 @@ class ReportController extends Controller public function scheduleAction() { $this->assertPermission('reporting/schedules'); - $this->addTitleTab('Schedule'); - - $form = new ScheduleForm(); - $form - ->setReport($this->report) - ->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); + $this->addTitleTab($this->translate('Schedule')); + + $form = ScheduleForm::fromReport($this->report); + $form->setAction((string) Url::fromRequest()) + ->on(ScheduleForm::ON_SUCCESS, function () use ($form) { + $pressedButton = $form->getPressedSubmitElement(); + if ($pressedButton) { + $pressedButton = $pressedButton->getName(); + } + + if ($pressedButton === 'remove') { + Notification::success($this->translate('Removed schedule successfully')); + } elseif ($pressedButton === 'send') { + Notification::success($this->translate('Report sent successfully')); + } elseif ($this->report->getSchedule() !== null) { + Notification::success($this->translate('Updated schedule successfully')); + } else { + Notification::success($this->translate('Created schedule successfully')); + } + + $this->closeModalAndRefreshRelatedView( + Url::fromPath('reporting/report', ['id' => $this->report->getId()]) + ); + }) + ->handleRequest($this->getServerRequest()); $this->addContent($form); + + $parts = $form->getPartUpdates(); + if (! empty($parts)) { + $this->sendMultipartUpdate(...$parts); + } } public function downloadAction() @@ -124,8 +243,9 @@ class ReportController extends Controller switch ($type) { case 'pdf': - /** @var Hook\PdfexportHook */ - Pdfexport::first()->streamPdfFromHtml($this->report->toPdf(), $name); + /** @var Hook\PdfexportHook $exports */ + $exports = Pdfexport::first(); + $exports->streamPdfFromHtml($this->report->toPdf(), $name); exit; case 'csv': $response = $this->getResponse(); @@ -184,24 +304,42 @@ class ReportController extends Controller $actions = new ActionBar(); if ($this->hasPermission('reporting/reports')) { - $actions->addLink( - 'Modify', - Url::fromPath('reporting/report/edit', ['id' => $reportId]), - 'edit' + $actions->addHtml( + (new ActionLink( + $this->translate('Modify'), + Url::fromPath('reporting/report/edit', ['id' => $reportId]), + 'edit' + ))->openInModal() + ); + + $actions->addHtml( + (new ActionLink( + $this->translate('Clone'), + Url::fromPath('reporting/report/clone', ['id' => $reportId]), + 'clone' + ))->openInModal() ); } if ($this->hasPermission('reporting/schedules')) { - $actions->addLink( - 'Schedule', - Url::fromPath('reporting/report/schedule', ['id' => $reportId]), - 'calendar-empty' + $actions->addHtml( + (new ActionLink( + $this->translate('Schedule'), + Url::fromPath('reporting/report/schedule', ['id' => $reportId]), + 'calendar-empty' + ))->openInModal() ); } $actions ->add($download) - ->addLink('Send', Url::fromPath('reporting/report/send', ['id' => $reportId]), 'forward'); + ->addHtml( + (new ActionLink( + $this->translate('Send'), + Url::fromPath('reporting/report/send', ['id' => $reportId]), + 'forward' + ))->openInModal() + ); return $actions; } diff --git a/application/controllers/ReportsController.php b/application/controllers/ReportsController.php index 7971897..f6aeedd 100644 --- a/application/controllers/ReportsController.php +++ b/application/controllers/ReportsController.php @@ -1,23 +1,23 @@ createTabs()->activate('reports'); if ($this->hasPermission('reporting/reports')) { - $this->addControl(new ButtonLink( - $this->translate('New Report'), - Url::fromPath('reporting/reports/new'), - 'plus' - )); + $this->addControl( + (new ButtonLink( + $this->translate('New Report'), + Url::fromPath('reporting/reports/new'), + 'plus' + ))->openInModal() + ); } $tableRows = []; - $select = (new Select()) - ->from('report r') - ->columns(['r.*', 'timeframe' => 't.name']) - ->join('timeframe t', 'r.timeframe_id = t.id') - ->orderBy('r.mtime', SORT_DESC); + $reports = Report::on(Database::get()) + ->withColumns(['report.timeframe.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 ($this->getDb()->select($select) as $report) { + /** @var Report $report */ + foreach ($reports as $report) { $url = Url::fromPath('reporting/report', ['id' => $report->id])->getAbsoluteUrl('&'); $tableRows[] = Html::tag('tr', ['href' => $url], [ Html::tag('td', null, $report->name), Html::tag('td', null, $report->author), - Html::tag('td', null, $report->timeframe), - Html::tag('td', null, date('Y-m-d H:i', $report->ctime / 1000)), - Html::tag('td', null, date('Y-m-d H:i', $report->mtime / 1000)), - Html::tag('td', ['class' => 'icon-col'], [ - new Link( - new Icon('edit'), - Url::fromPath('reporting/report/edit', ['id' => $report->id]) - ) - ]) + 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')), ]); } @@ -94,10 +100,43 @@ class ReportsController extends Controller $this->assertPermission('reporting/reports'); $this->addTitleTab($this->translate('New Report')); - $form = new ReportForm(); - $form->handleRequest(ServerRequest::fromGlobals()); + 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()) + ->setRenderCreateAndShowButton($class !== null) + ->populate([ + 'filter' => $this->params->shift('filter'), + 'reportlet' => $class + ]) + ->on(ReportForm::ON_SUCCESS, function (ReportForm $form) { + Notification::success($this->translate('Created report successfully')); - $this->redirectForm($form, 'reporting/reports'); + $pressedButton = $form->getPressedSubmitElement(); + if ($pressedButton && $pressedButton->getName() !== 'create_show') { + $this->closeModalAndRefreshRelatedView(Url::fromPath('reporting/reports')); + } else { + $this->redirectNow( + Url::fromPath( + sprintf( + 'reporting/reports#!%s', + Url::fromPath('reporting/report', ['id' => $form->getId()])->getAbsoluteUrl() + ) + ) + ); + } + }) + ->handleRequest($this->getServerRequest()); $this->addContent($form); } diff --git a/application/controllers/TemplateController.php b/application/controllers/TemplateController.php index bb37b3c..70cf9f0 100644 --- a/application/controllers/TemplateController.php +++ b/application/controllers/TemplateController.php @@ -1,31 +1,54 @@ createTabs()->activate('preview'); + parent::init(); - $template = Template::fromDb($this->params->getRequired('id')); + /** @var Model\Template $template */ + $template = Model\Template::on(Database::get()) + ->filter(Filter::equal('id', $this->params->getRequired('id'))) + ->first(); if ($template === null) { - throw new \Exception('Template not found'); + throw new Exception('Template not found'); } - $template + $this->template = $template; + } + + public function indexAction() + { + $this->addTitleTab($this->translate('Preview')); + + $this->controls->getAttributes()->add('class', 'default-layout'); + $this->addControl($this->createActionBars()); + + $template = Template::fromModel($this->template) ->setMacros([ 'date' => (new DateTime())->format('jS M, Y'), 'time_frame' => 'Time Frame', @@ -40,50 +63,40 @@ class TemplateController extends Controller public function editAction() { $this->assertPermission('reporting/templates'); - - $this->createTabs()->activate('edit'); - - $select = (new Select()) - ->from('template') - ->columns(['id', 'settings']) - ->where(['id = ?' => $this->params->getRequired('id')]); - - $template = $this->getDb()->select($select)->fetch(); - - if ($template === false) { - throw new \Exception('Template not found'); - } - - $template->settings = json_decode($template->settings, true); - - $form = (new TemplateForm()) - ->setTemplate($template); - - $form->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, 'reporting/templates'); + $this->addTitleTab($this->translate('Edit Template')); + + $form = TemplateForm::fromTemplate($this->template) + ->setAction((string) Url::fromRequest()) + ->on(TemplateForm::ON_SUCCESS, function (Form $form) { + $pressedButton = $form->getPressedSubmitElement(); + if ($pressedButton && $pressedButton->getName() === 'remove') { + Notification::success($this->translate('Removed template successfully')); + + $this->switchToSingleColumnLayout(); + } else { + Notification::success($this->translate('Updated template successfully')); + + $this->closeModalAndRefreshRemainingViews( + Url::fromPath('reporting/template', ['id' => $this->template->id]) + ); + } + }) + ->handleRequest(ServerRequest::fromGlobals()); $this->addContent($form); } - protected function createTabs() + protected function createActionBars(): ValidHtml { - $tabs = $this->getTabs(); - - if ($this->hasPermission('reporting/templates')) { - $tabs->add('edit', [ - 'title' => $this->translate('Edit template'), - 'label' => $this->translate('Edit Template'), - 'url' => 'reporting/template/edit?id=' . $this->params->getRequired('id') - ]); - } - - $tabs->add('preview', [ - 'title' => $this->translate('Preview template'), - 'label' => $this->translate('Preview'), - 'url' => 'reporting/template?id=' . $this->params->getRequired('id') - ]); - - return $tabs; + $actions = new ActionBar(); + $actions->addHtml( + (new ActionLink( + $this->translate('Modify'), + Url::fromPath('reporting/template/edit', ['id' => $this->template->id]), + 'edit' + ))->openInModal() + ); + + return $actions; } } diff --git a/application/controllers/TemplatesController.php b/application/controllers/TemplatesController.php index 91a82b1..99a5dcb 100644 --- a/application/controllers/TemplatesController.php +++ b/application/controllers/TemplatesController.php @@ -1,22 +1,22 @@ hasPermission('reporting/templates'); if ($canManage) { - $this->addControl(new ButtonLink( - $this->translate('New Template'), - Url::fromPath('reporting/templates/new'), - 'plus' - )); + $this->addControl( + (new ButtonLink( + $this->translate('New Template'), + Url::fromPath('reporting/templates/new'), + 'plus' + ))->openInModal() + ); } - $select = (new Select()) - ->from('template') - ->columns(['id', 'name', 'author', 'ctime', 'mtime']) - ->orderBy('mtime', SORT_DESC); - - foreach ($this->getDb()->select($select) as $template) { - if ($canManage) { - // Edit URL - $subjectUrl = Url::fromPath( - 'reporting/template/edit', - ['id' => $template->id] - ); - } else { - // Preview URL - $subjectUrl = Url::fromPath( - 'reporting/template', - ['id' => $template->id] - ); - } + $templates = Model\Template::on(Database::get()); + + $sortControl = $this->createSortControl( + $templates, + [ + 'name' => $this->translate('Name'), + 'author' => $this->translate('Author'), + 'ctime' => $this->translate('Created At'), + 'mtime' => $this->translate('Modified At') + ] + ); + $this->addControl($sortControl); + + $tableRows = []; + + /** @var Model\Template $template */ + foreach ($templates as $template) { + // Preview URL + $subjectLink = new Link($template->name, Url::fromPath('reporting/template', ['id' => $template->id])); $tableRows[] = Html::tag('tr', null, [ - Html::tag('td', null, new Link($template->name, $subjectUrl)), + Html::tag('td', null, $subjectLink), Html::tag('td', null, $template->author), - Html::tag('td', null, date('Y-m-d H:i', $template->ctime / 1000)), - Html::tag('td', null, date('Y-m-d H:i', $template->mtime / 1000)) + Html::tag('td', null, $template->ctime->format('Y-m-d H:i')), + Html::tag('td', null, $template->mtime->format('Y-m-d H:i')) ]); } @@ -93,13 +95,16 @@ class TemplatesController extends Controller public function newAction() { $this->assertPermission('reporting/templates'); - $this->addTitleTab('New Template'); - - $form = new TemplateForm(); + $this->addTitleTab($this->translate('New Template')); - $form->handleRequest(ServerRequest::fromGlobals()); + $form = (new TemplateForm()) + ->setAction((string) Url::fromRequest()) + ->on(TemplateForm::ON_SUCCESS, function () { + Notification::success($this->translate('Created template successfully')); - $this->redirectForm($form, 'reporting/templates'); + $this->closeModalAndRefreshRelatedView(Url::fromPath('reporting/templates')); + }) + ->handleRequest($this->getServerRequest()); $this->addContent($form); } diff --git a/application/controllers/TestController.php b/application/controllers/TestController.php deleted file mode 100644 index f666085..0000000 --- a/application/controllers/TestController.php +++ /dev/null @@ -1,47 +0,0 @@ -from('timeframe') - ->columns('*'); - - $table = new Table(); - - $table->getAttributes()->add('class', 'common-table'); - - $table->getHeader()->add(Table::row(['Name', 'Title', 'Start', 'End'], null, 'th')); - - foreach ($this->getDb()->select($select) as $row) { - $timeframe = (new Timeframe()) - ->setName($row->name) - ->setTitle($row->title) - ->setStart($row->start) - ->setEnd($row->end); - - $table->getBody()->add(Table::row([ - $timeframe->getName(), - $timeframe->getTitle(), - $timeframe->getTimerange()->getStart()->format('Y-m-d H:i:s'), - $timeframe->getTimerange()->getEnd()->format('Y-m-d H:i:s') - ])); - } - - $this->addTitleTab('Timeframes'); - - $this->addContent($table); - } -} diff --git a/application/controllers/TimeframeController.php b/application/controllers/TimeframeController.php index ca67b0b..01395c2 100644 --- a/application/controllers/TimeframeController.php +++ b/application/controllers/TimeframeController.php @@ -1,24 +1,37 @@ timeframe = Timeframe::fromDb($this->params->getRequired('id')); + /** @var Model\Timeframe $timeframe */ + $timeframe = Model\Timeframe::on(Database::get()) + ->filter(Filter::equal('id', $this->params->getRequired('id'))) + ->first(); + + if ($timeframe === null) { + throw new Exception('Timeframe not found'); + } + + $this->timeframe = Timeframe::fromModel($timeframe); } public function editAction() @@ -32,15 +45,19 @@ class TimeframeController extends Controller 'end' => $this->timeframe->getEnd() ]; + $form = TimeframeForm::fromId($this->timeframe->getId()) + ->setAction((string) Url::fromRequest()) + ->populate($values) + ->on(TimeframeForm::ON_SUCCESS, function (Form $form) { + $pressedButton = $form->getPressedSubmitElement(); + if ($pressedButton && $pressedButton->getName() === 'remove') { + Notification::success($this->translate('Removed timeframe successfully')); + } else { + Notification::success($this->translate('Update timeframe successfully')); + } - $form = (new TimeframeForm()) - ->setId($this->timeframe->getId()); - - $form->populate($values); - - $form->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, 'reporting/timeframes'); + $this->switchToSingleColumnLayout(); + })->handleRequest($this->getServerRequest()); $this->addContent($form); } diff --git a/application/controllers/TimeframesController.php b/application/controllers/TimeframesController.php index 505d8d9..f38c661 100644 --- a/application/controllers/TimeframesController.php +++ b/application/controllers/TimeframesController.php @@ -1,22 +1,22 @@ hasPermission('reporting/timeframes'); if ($canManage) { - $this->addControl(new ButtonLink( - $this->translate('New Timeframe'), - Url::fromPath('reporting/timeframes/new'), - 'plus' - )); + $this->addControl( + (new ButtonLink( + $this->translate('New Timeframe'), + Url::fromPath('reporting/timeframes/new'), + 'plus' + ))->openInModal() + ); } $tableRows = []; - $select = (new Select()) - ->from('timeframe t') - ->columns('*'); + $timeframes = Model\Timeframe::on(Database::get()); + + $sortControl = $this->createSortControl( + $timeframes, + [ + 'name' => $this->translate('Name'), + 'ctime' => $this->translate('Created At'), + 'mtime' => $this->translate('Modified At') + ] + ); - foreach ($this->getDb()->select($select) as $timeframe) { + $this->addControl($sortControl); + + foreach ($timeframes as $timeframe) { $subject = $timeframe->name; if ($canManage) { - $subject = new Link($timeframe->name, Url::fromPath( - 'reporting/timeframe/edit', - ['id' => $timeframe->id] - )); + $subject = new Link( + $timeframe->name, + Url::fromPath('reporting/timeframe/edit', ['id' => $timeframe->id]) + ); } $tableRows[] = Html::tag('tr', null, [ Html::tag('td', null, $subject), Html::tag('td', null, $timeframe->start), Html::tag('td', null, $timeframe->end), - Html::tag('td', null, date('Y-m-d H:i', $timeframe->ctime / 1000)), - Html::tag('td', null, date('Y-m-d H:i', $timeframe->mtime / 1000)) + Html::tag('td', null, $timeframe->ctime->format('Y-m-d H:i')), + Html::tag('td', null, $timeframe->mtime->format('Y-m-d H:i')) ]); } if (! empty($tableRows)) { $table = Html::tag( 'table', - ['class' => 'common-table table-row-selectable', 'data-base-target' => '_next'], + [ + 'class' => 'common-table table-row-selectable', + 'data-base-target' => '_next' + ], [ Html::tag( 'thead', @@ -93,10 +107,13 @@ class TimeframesController extends Controller $this->assertPermission('reporting/timeframes'); $this->addTitleTab($this->translate('New Timeframe')); - $form = new TimeframeForm(); - $form->handleRequest(ServerRequest::fromGlobals()); + $form = (new TimeframeForm()) + ->setAction((string) Url::fromRequest()) + ->on(TimeframeForm::ON_SUCCESS, function () { + Notification::success($this->translate('Created timeframe successfully')); - $this->redirectForm($form, 'reporting/timeframes'); + $this->closeModalAndRefreshRelatedView(Url::fromPath('reporting/timeframes')); + })->handleRequest($this->getServerRequest()); $this->addContent($form); } diff --git a/application/forms/ConfigureMailForm.php b/application/forms/ConfigureMailForm.php index c27c934..b0a52ae 100644 --- a/application/forms/ConfigureMailForm.php +++ b/application/forms/ConfigureMailForm.php @@ -1,4 +1,5 @@ addElement('select', 'backend_resource', [ - 'label' => $this->translate('Database'), - 'description' => $this->translate('Database resource'), - 'multiOptions' => $options, - 'value' => $default, - 'required' => true + 'label' => $this->translate('Database'), + 'description' => $this->translate('Database resource'), + 'multiOptions' => $options, + 'value' => $default, + 'required' => true ]); } } diff --git a/configuration.php b/configuration.php index bb5b2e6..49c2f45 100644 --- a/configuration.php +++ b/configuration.php @@ -1,19 +1,13 @@ provideCssFile('system-report.css'); - if (version_compare(Version::VERSION, '2.9.0', '<')) { - $this->provideJsFile('vendor/flatpickr.min.js'); - $this->provideCssFile('vendor/flatpickr.min.css'); - } - $this->menuSection(N_('Reporting'))->add(N_('Reports'), array( 'url' => 'reporting/reports', )); diff --git a/doc/02-Installation.md b/doc/02-Installation.md index fe4b8e4..8b04fff 100644 --- a/doc/02-Installation.md +++ b/doc/02-Installation.md @@ -1,40 +1,42 @@ -# Installation +# Installing Icinga Reporting + +Please see the Icinga Web documentation on +[how to install modules](https://icinga.com/docs/icinga-web-2/latest/doc/08-Modules/#installation) from source. +Make sure you use `reporting` as the module name. The following requirements must also be met. ## Requirements -* PHP (>= 7.0) -* Icinga Web 2 (>= 2.9) -* Icinga Web 2 libraries: - * [Icinga PHP Library (ipl)](https://github.com/Icinga/icinga-php-library) (>= 0.8) - * [Icinga PHP Thirdparty](https://github.com/Icinga/icinga-php-thirdparty) (>= 0.10) -* Icinga Web 2 modules: - * [Icinga PDF Export](https://github.com/Icinga/icingaweb2-module-pdfexport) (>= 0.10) -* MySQL / MariaDB or PostgreSQL +* PHP (≥7.2) +* MySQL or PostgreSQL PDO PHP libraries +* The following PHP modules must be installed: `mbstring` +* [Icinga Web](https://github.com/Icinga/icingaweb2) (≥2.9) +* [Icinga PHP Library (ipl)](https://github.com/Icinga/icinga-php-library) (≥0.13.0) +* [Icinga PHP Thirdparty](https://github.com/Icinga/icinga-php-thirdparty) (≥0.12.0) -## Database Setup +## Setting up the Database -### MySQL / MariaDB +### Setting up a MySQL or MariaDB Database -The module needs a MySQL/MariaDB database with the schema that's provided in the `etc/schema/mysql.sql` file. +The module needs a MySQL/MariaDB database with the schema that's provided in the `schema/mysql.schema.sql` file. -Example command for creating the MySQL/MariaDB database. Please change the password: +You can use the following sample command for creating the MySQL/MariaDB database. Please change the password: ``` CREATE DATABASE reporting; -GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON reporting.* TO reporting@localhost IDENTIFIED BY 'secret'; +GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, CREATE VIEW, INDEX, EXECUTE ON reporting.* TO reporting@localhost IDENTIFIED BY 'secret'; ``` After, you can import the schema using the following command: ``` -mysql -p -u root reporting < schema/mysql.sql +mysql -p -u root reporting < /usr/share/icingaweb2/modules/reporting/schema/mysql.schema.sql ``` -## PostgreSQL +## Setting up a PostgreSQL Database -The module needs a PostgreSQL database with the schema that's provided in the `etc/schema/postgresql.sql` file. +The module needs a PostgreSQL database with the schema that's provided in the `schema/pgsql.schema.sql` file. -Example command for creating the PostgreSQL database. Please change the password: +You can use the following sample command for creating the PostgreSQL database. Please change the password: ```sql CREATE USER reporting WITH PASSWORD 'secret'; @@ -48,36 +50,7 @@ CREATE DATABASE reporting After, you can import the schema using the following command: ``` -psql -U reporting reporting -a -f schema/postgresql.sql +psql -U reporting reporting -a -f /usr/share/icingaweb2/modules/reporting/schema/pgsql.schema.sql ``` -## Module Installation - -1. Install it [like any other module](https://icinga.com/docs/icinga-web-2/latest/doc/08-Modules/#installation). -Use `reporting` as name. - -2. Once you've set up the database, create a new Icinga Web 2 resource for it using the -`Configuration -> Application -> Resources` menu. Make sure that you set the character set to `utf8mb4`. - -3. The next step involves telling the Reporting module which database resource to use. This can be done in -`Configuration -> Modules -> reporting -> Backend`. If you've used `reporting` as name for the resource, -you can skip this step. - This concludes the installation. Now continue with the [configuration](03-Configuration.md). - -## Scheduler Daemon - -There is a daemon for generating and distributing reports on a schedule if configured: - -``` -icingacli reporting schedule run -``` - -This command schedules the execution of all applicable reports. - -You may configure this command as `systemd` service. Just copy the example service definition from -`config/systemd/icinga-reporting.service` to `/etc/systemd/system/icinga-reporting.service` and enable it afterwards: - -``` -systemctl enable icinga-reporting.service -``` diff --git a/doc/03-Configuration.md b/doc/03-Configuration.md index f06481c..e789aef 100644 --- a/doc/03-Configuration.md +++ b/doc/03-Configuration.md @@ -1,20 +1,17 @@ # Configuration -1. [Backend](#backend) -2. [Mail](#mail) -3. [Permissions](#permissions) +Icinga Reporting is configured via the web interface. Below you will find an overview of the necessary settings. ## Backend -If not already done during the installation of Icinga Reporting, setup the reporting database backend now. +Icinga Reporting stores all its configuration in the database, therefore you need to create and configure a database +resource for it. -Create a new [Icinga Web 2 resource](https://icinga.com/docs/icingaweb2/latest/doc/04-Resources/#database) -for [Icinga Reporting's database](https://icinga.com/docs/icinga-reporting/latest/doc/02-Installation/#database-setup) -using the `Configuration -> Application -> Resources` menu. +1. Create a new resource for Icinga Reporting via the `Configuration -> Application -> Resources` menu. -Then tell Icinga Reporting which database resource to use. This can be done in -`Configuration -> Modules -> reporting -> Backend`. If you've used `reporting` -as name for the resource, this is optional. +2. Configure the resource you just created as the database connection for Icinga Reporting using the + `Configuration → Modules → reporting → Backend` menu. If you've used `reporting` + as name for the resource, this is optional. ## Mail @@ -25,9 +22,31 @@ that is used as the sender's address (From) in E-mails. There are four permissions that can be used to control what can be managed by whom. -Permission | Applies to ----------------------|---------------- -reporting/reports | Reports (create, edit, delete) -reporting/schedules | Schedules (create, edit, delete) -reporting/templates | Templates (create, edit, delete) -reporting/timeframes | Timeframes (create, edit, delete) +| Permission | Applies to | +|----------------------|-----------------------------------| +| reporting/reports | Reports (create, edit, delete) | +| reporting/schedules | Schedules (create, edit, delete) | +| reporting/templates | Templates (create, edit, delete) | +| reporting/timeframes | Timeframes (create, edit, delete) | + +## Icinga Reporting Daemon + +There is a daemon for generating and distributing reports on a schedule if configured: + +``` +icingacli reporting schedule run +``` + +This command schedules the execution of all applicable reports. + +The `systemd` service of this module uses this command as well. + +To configure this as a `systemd` service, copy the example service definition from +`/usr/share/icingaweb2/modules/reporting/config/systemd/icinga-reporting.service` +to `/etc/systemd/system/icinga-reporting.service`. + +You can run the following command to enable and start the daemon. + +``` +systemctl enable --now icinga-reporting.service +``` diff --git a/doc/80-Upgrading.md b/doc/80-Upgrading.md index 8252e6f..41b665c 100644 --- a/doc/80-Upgrading.md +++ b/doc/80-Upgrading.md @@ -3,7 +3,43 @@ Upgrading Icinga Reporting is straightforward. Usually the only manual steps involved are schema updates for the database. -## Upgrading to Version 0.9.1 +## Upgrading to Version 1.0.0 + +Icinga Reporting version 1.0.0 requires a schema update for the database. +If you're already using Icinga Web version `>= 2.12`, then you don't need to perform any of these steps manually. +Icinga Web provides you the ability to perform such migrations in a simple way. You may be familiar with such an +automation if you're an Icinga Director user. For those who are not using the latest version of Icinga Web, please +follow the instructions below. + +> **Note** +> +> If you're not using Icinga Web migration automation, you may need to [populate](https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html#time-zone-installation) +> all the system named time zone information into your MSQL/MariaDB server. Otherwise, the migration may not succeed. + +You may use the following command to apply the database schema upgrade file: + + +**Note:** If you haven't installed this module from packages, then please adapt the schema path to the correct installation path. + + + +``` +# mysql -u root -p reporting /usr/share/icingaweb2/modules/reporting/schema/mysql-upgrades/1.0.0.sql +``` + +## Upgrading to Version 0.10.0 + +Icinga Reporting version 0.10.0 requires a schema update for the database. +A new table `template`, linked to table `report`, has been introduced. +Please find the upgrade script in **schema/mysql-upgrades**. + +You may use the following command to apply the database schema upgrade file: + +``` +# mysql -u root -p reporting setFrom(Config::module('reporting')->get('mail', 'from', 'reporting@icinga')); + $mail->setFrom( + Config::module('reporting', 'config', true)->get('mail', 'from', 'reporting@icinga') + ); if (isset($config['subject'])) { $mail->setSubject($config['subject']); @@ -51,9 +57,10 @@ class SendMail extends ActionHook throw new \InvalidArgumentException(); } - $recipients = array_filter(preg_split('/[\s,]+/', $config['recipients'])); + /** @var array $recipients */ + $recipients = preg_split('/[\s,]+/', $config['recipients']); - $mail->send(null, $recipients); + $mail->send(null, array_filter($recipients)); } public function initConfigForm(Form $form, Report $report) @@ -66,19 +73,34 @@ class SendMail extends ActionHook } $form->addElement('select', 'type', [ - 'required' => true, - 'label' => t('Type'), - 'options' => $types + 'required' => true, + 'label' => t('Type'), + 'options' => $types ]); $form->addElement('text', 'subject', [ - 'label' => t('Subject'), - 'placeholder' => Mail::DEFAULT_SUBJECT + 'label' => t('Subject'), + 'placeholder' => Mail::DEFAULT_SUBJECT ]); $form->addElement('textarea', 'recipients', [ 'required' => true, - 'label' => t('Recipients') + 'label' => t('Recipients'), + 'validators' => [ + new CallbackValidator(function ($value, CallbackValidator $validator): bool { + $mailValidator = new EmailAddressValidator(); + $mails = Str::trimSplit($value); + foreach ($mails as $mail) { + if (! $mailValidator->isValid($mail)) { + $validator->addMessage(...$mailValidator->getMessages()); + + return false; + } + } + + return true; + }) + ] ]); } } diff --git a/library/Reporting/Cli/Command.php b/library/Reporting/Cli/Command.php index a89f77b..16ce8fa 100644 --- a/library/Reporting/Cli/Command.php +++ b/library/Reporting/Cli/Command.php @@ -1,16 +1,14 @@ get('backend', 'resource', 'reporting') - )); + } - $config->options = [\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ]; - if ($config->db === 'mysql') { - $config->options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES" - . ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"; + /** + * Get the database connection + * + * @return RetryConnection + */ + public static function get(): RetryConnection + { + if (self::$instance === null) { + self::$instance = self::getDb(); } - $conn = new RetryConnection($config); - - return $conn; + return self::$instance; } - protected function listTimeframes() + private static function getDb(): RetryConnection { - $select = (new Sql\Select()) - ->from('timeframe') - ->columns(['id', 'name']); - - $timeframes = []; + $config = new Sql\Config( + ResourceFactory::getResourceConfig( + Config::module('reporting')->get('backend', 'resource', 'reporting') + ) + ); - foreach ($this->getDb()->select($select) as $row) { - $timeframes[$row->id] = $row->name; + $config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ]; + if ($config->db === 'mysql') { + $config->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES" + . ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"; } - return $timeframes; + return new RetryConnection($config); } - protected function listTemplates() + /** + * List all reporting timeframes + * + * @return array + */ + public static function listTimeframes(): array { - $select = (new Sql\Select()) - ->from('template') - ->columns(['id', 'name']); + return self::list( + (new Sql\Select()) + ->from('timeframe') + ->columns(['id', 'name']) + ); + } - $templates = []; + /** + * List all reporting templates + * + * @return array + */ + public static function listTemplates(): array + { + return self::list( + (new Sql\Select()) + ->from('template') + ->columns(['id', 'name']) + ); + } + + /** + * Helper method for list templates and timeframes + * + * @param Sql\Select $select + * + * @return array + */ + private static function list(Sql\Select $select): array + { + $result = []; + /** @var stdClass $row */ + foreach (self::get()->select($select) as $row) { + /** @var int $id */ + $id = $row->id; + /** @var string $name */ + $name = $row->name; - foreach ($this->getDb()->select($select) as $row) { - $templates[$row->id] = $row->name; + $result[$id] = $name; } - return $templates; + return $result; } } diff --git a/library/Reporting/Dimensions.php b/library/Reporting/Dimensions.php index dfedbc8..09b23c9 100644 --- a/library/Reporting/Dimensions.php +++ b/library/Reporting/Dimensions.php @@ -1,4 +1,5 @@ from = 'icinga-reporting@' . $_SERVER[$key]; return $this->from; @@ -58,7 +59,7 @@ class Mail /** * Set the from part * - * @param string $from + * @param string $from * * @return $this */ @@ -82,7 +83,7 @@ class Mail /** * Set the subject * - * @param string $subject + * @param string $subject * * @return $this */ @@ -161,14 +162,14 @@ class Mail { $mail = new Zend_Mail('UTF-8'); - $mail->setFrom($this->getFrom()); + $mail->setFrom($this->getFrom(), ''); $mail->addTo($recipient); $mail->setSubject($this->getSubject()); - if (strlen($body) !== strlen(strip_tags($body))) { + if ($body && (strlen($body) !== strlen(strip_tags($body)))) { $mail->setBodyHtml($body); } else { - $mail->setBodyText($body); + $mail->setBodyText($body ?? ''); } foreach ($this->attachments as $attachment) { diff --git a/library/Reporting/Model/Config.php b/library/Reporting/Model/Config.php new file mode 100644 index 0000000..791a76d --- /dev/null +++ b/library/Reporting/Model/Config.php @@ -0,0 +1,47 @@ +add(new MillisecondTimestamp([ + 'ctime', + 'mtime' + ])); + } + + public function createRelations(Relations $relations) + { + $relations->belongsTo('reportlet', Reportlet::class); + } +} diff --git a/library/Reporting/Model/Report.php b/library/Reporting/Model/Report.php new file mode 100644 index 0000000..b466a60 --- /dev/null +++ b/library/Reporting/Model/Report.php @@ -0,0 +1,71 @@ +add(new MillisecondTimestamp([ + 'ctime', + 'mtime' + ])); + } + + public function createRelations(Relations $relations) + { + $relations->belongsTo('timeframe', Timeframe::class); + $relations->belongsTo('template', Template::class) + ->setJoinType('LEFT'); + + $relations->hasOne('schedule', Schedule::class) + ->setJoinType('LEFT'); + $relations->hasMany('reportlets', Reportlet::class); + } +} diff --git a/library/Reporting/Model/Reportlet.php b/library/Reporting/Model/Reportlet.php new file mode 100644 index 0000000..3552cf5 --- /dev/null +++ b/library/Reporting/Model/Reportlet.php @@ -0,0 +1,48 @@ +add(new MillisecondTimestamp([ + 'ctime', + 'mtime' + ])); + } + + public function createRelations(Relations $relations) + { + $relations->belongsTo('report', Report::class); + + $relations->hasMany('config', Config::class); + } +} diff --git a/library/Reporting/Model/Schedule.php b/library/Reporting/Model/Schedule.php new file mode 100644 index 0000000..6100d2a --- /dev/null +++ b/library/Reporting/Model/Schedule.php @@ -0,0 +1,48 @@ +add(new MillisecondTimestamp([ + 'ctime', + 'mtime' + ])); + } + + public function createRelations(Relations $relations) + { + $relations->belongsTo('report', Report::class); + } +} diff --git a/library/Reporting/Model/Schema.php b/library/Reporting/Model/Schema.php new file mode 100644 index 0000000..102a6eb --- /dev/null +++ b/library/Reporting/Model/Schema.php @@ -0,0 +1,49 @@ +add(new BoolCast(['success'])); + $behaviors->add(new MillisecondTimestamp(['timestamp'])); + } +} diff --git a/library/Reporting/Model/Template.php b/library/Reporting/Model/Template.php new file mode 100644 index 0000000..6695f37 --- /dev/null +++ b/library/Reporting/Model/Template.php @@ -0,0 +1,53 @@ +add(new MillisecondTimestamp([ + 'ctime', + 'mtime' + ])); + } + + public function createRelations(Relations $relations) + { + $relations->hasMany('report', Report::class) + ->setJoinType('LEFT'); + } +} diff --git a/library/Reporting/Model/Timeframe.php b/library/Reporting/Model/Timeframe.php new file mode 100644 index 0000000..9936a58 --- /dev/null +++ b/library/Reporting/Model/Timeframe.php @@ -0,0 +1,53 @@ +add(new MillisecondTimestamp([ + 'ctime', + 'mtime' + ])); + } + + public function createRelations(Relations $relations) + { + $relations->hasMany('report', Report::class); + } +} diff --git a/library/Reporting/ProvidedActions.php b/library/Reporting/ProvidedActions.php index 2590d1f..b3187c7 100644 --- a/library/Reporting/ProvidedActions.php +++ b/library/Reporting/ProvidedActions.php @@ -1,4 +1,5 @@ translate('Icinga Reporting'); + } + + public function providedDescriptions(): array + { + return [ + '0.9.1' => $this->translate( + 'Modifies all columns that uses current_timestamp to unix_timestamp and alters the database' + . ' engine of some tables.' + ), + '0.10.0' => $this->translate('Creates the template table and adjusts some column types'), + '1.0.0' => $this->translate('Migrates all your configured report schedules to the new config.') + ]; + } + + protected function getSchemaQuery(): Query + { + return Schema::on($this->getDb()); + } + + public function getDb(): Connection + { + return Database::get(); + } + + public function getVersion(): string + { + if ($this->version === null) { + $conn = $this->getDb(); + $schema = $this->getSchemaQuery() + ->columns(['version', 'success']) + ->orderBy('id', SORT_DESC) + ->limit(2); + + if (static::tableExists($conn, $schema->getModel()->getTableName())) { + /** @var Schema $version */ + foreach ($schema as $version) { + if ($version->success) { + $this->version = $version->version; + } + } + + if (! $this->version) { + // Schema version table exist, but the user has probably deleted the entry! + $this->version = '1.0.0'; + } + } elseif (static::tableExists($conn, 'template')) { + // We have added Postgres support and the template table with 0.10.0. + // So, use this as the last (migrated) version. + $this->version = '0.10.0'; + } elseif (static::getColumnType($conn, 'timeframe', 'name') === 'varchar(128)') { + // Upgrade script 0.9.1 alters the timeframe.name column from `varchar(255)` -> `varchar(128)`. + // Therefore, we can safely use this as the last migrated version. + $this->version = '0.9.1'; + } else { + // Use the initial version as the last migrated schema version! + $this->version = '0.9.0'; + } + } + + return $this->version; + } +} diff --git a/library/Reporting/ProvidedReports.php b/library/Reporting/ProvidedReports.php index edfc2ce..b672478 100644 --- a/library/Reporting/ProvidedReports.php +++ b/library/Reporting/ProvidedReports.php @@ -1,4 +1,5 @@ getDb(); + $report->id = $reportModel->id; + $report->name = $reportModel->name; + $report->author = $reportModel->author; + $report->timeframe = Timeframe::fromModel($reportModel->timeframe); - $select = (new Sql\Select()) - ->from('report') - ->columns('*') - ->where(['id = ?' => $id]); - - $row = $db->select($select)->fetch(); - - if ($row === false) { - throw new Exception('Report not found'); + $template = $reportModel->template->first(); + if ($template !== null) { + $report->template = Template::fromModel($template); } - $report - ->setId($row->id) - ->setName($row->name) - ->setAuthor($row->author) - ->setTimeframe(Timeframe::fromDb($row->timeframe_id)) - ->setTemplate(Template::fromDb($row->template_id)); - - $select = (new Sql\Select()) - ->from('reportlet') - ->columns('*') - ->where(['report_id = ?' => $id]); - - $row = $db->select($select)->fetch(); - - if ($row === false) { - throw new Exception('No reportlets configured.'); + $reportlets = []; + foreach ($reportModel->reportlets as $reportlet) { + $reportlet->report_name = $reportModel->name; + $reportlet->report_id = $reportModel->id; + $reportlets[] = Reportlet::fromModel($reportlet); } - $reportlet = new Reportlet(); - - $reportlet - ->setId($row->id) - ->setClass($row->class); - - $select = (new Sql\Select()) - ->from('config') - ->columns('*') - ->where(['reportlet_id = ?' => $row->id]); - - $rows = $db->select($select)->fetchAll(); - - $config = []; - - foreach ($rows as $row) { - $config[$row->name] = $row->value; + if (empty($reportlets)) { + throw new Exception('No reportlets configured'); } - $reportlet->setConfig($config); - - $report->setReportlets([$reportlet]); - - $select = (new Sql\Select()) - ->from('schedule') - ->columns('*') - ->where(['report_id = ?' => $id]); - - $row = $db->select($select)->fetch(); + $report->reportlets = $reportlets; - if ($row !== false) { - $schedule = new Schedule(); - - $schedule - ->setId($row->id) - ->setStart((new \DateTime())->setTimestamp((int) $row->start / 1000)) - ->setFrequency($row->frequency) - ->setAction($row->action) - ->setConfig(json_decode($row->config, true)); - - $report->setSchedule($schedule); + $schedule = $reportModel->schedule->first(); + if ($schedule !== null) { + $report->schedule = Schedule::fromModel($schedule, $report); } return $report; @@ -131,18 +89,6 @@ class Report return $this->id; } - /** - * @param int $id - * - * @return $this - */ - public function setId($id) - { - $this->id = $id; - - return $this; - } - /** * @return string */ @@ -151,18 +97,6 @@ class Report return $this->name; } - /** - * @param string $name - * - * @return $this - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - /** * @return string */ @@ -171,18 +105,6 @@ class Report return $this->author; } - /** - * @param string $author - * - * @return $this - */ - public function setAuthor($author) - { - $this->author = $author; - - return $this; - } - /** * @return Timeframe */ @@ -191,18 +113,6 @@ class Report return $this->timeframe; } - /** - * @param Timeframe $timeframe - * - * @return $this - */ - public function setTimeframe(Timeframe $timeframe) - { - $this->timeframe = $timeframe; - - return $this; - } - /** * @return Reportlet[] */ @@ -211,18 +121,6 @@ class Report return $this->reportlets; } - /** - * @param Reportlet[] $reportlets - * - * @return $this - */ - public function setReportlets(array $reportlets) - { - $this->reportlets = $reportlets; - - return $this; - } - /** * @return Schedule */ @@ -231,18 +129,6 @@ class Report return $this->schedule; } - /** - * @param Schedule $schedule - * - * @return $this - */ - public function setSchedule(Schedule $schedule) - { - $this->schedule = $schedule; - - return $this; - } - /** * @return Template */ @@ -251,18 +137,6 @@ class Report return $this->template; } - /** - * @param Template $template - * - * @return $this - */ - public function setTemplate($template) - { - $this->template = $template; - - return $this; - } - public function providesData() { foreach ($this->getReportlets() as $reportlet) { @@ -300,6 +174,7 @@ class Report public function toCsv() { $timerange = $this->getTimeframe()->getTimerange(); + $convertFloats = version_compare(PHP_VERSION, '8.0.0', '<'); $csv = []; @@ -309,8 +184,41 @@ class Report if ($implementation->providesData()) { $data = $implementation->getData($timerange, $reportlet->getConfig()); $csv[] = array_merge($data->getDimensions(), $data->getValues()); + + $hosts = []; + $isServiceExport = false; + $config = $reportlet->getConfig(); + $exportTotalEnabled = isset($config['export_total']) && $config['export_total']; + if ($exportTotalEnabled) { + $isServiceExport = $reportlet->getClass() === ServiceSlaReport::class; + } + foreach ($data->getRows() as $row) { - $csv[] = array_merge($row->getDimensions(), $row->getValues()); + $values = $row->getValues(); + if ($convertFloats) { + foreach ($values as &$value) { + if (is_float($value)) { + $value = sprintf('%.4F', $value); + } + } + } + + if ($isServiceExport) { + $hosts[$row->getDimensions()[0]] = true; + } + + $csv[] = array_merge($row->getDimensions(), $values); + } + + if ($exportTotalEnabled) { + $precision = $config['sla_precision'] ?? SlaReport::DEFAULT_REPORT_PRECISION; + $total = [$isServiceExport ? count($hosts) : $data->count()]; + if ($isServiceExport) { + $total[] = $data->count(); + } + $total[] = round($data->getAverages()[0], $precision); + + $csv[] = $total; } break; @@ -336,9 +244,34 @@ class Report $data = $implementation->getData($timerange, $reportlet->getConfig()); $dimensions = $data->getDimensions(); $values = $data->getValues(); + + $hosts = []; + $isServiceExport = false; + $config = $reportlet->getConfig(); + $exportTotalEnabled = isset($config['export_total']) && $config['export_total']; + if ($exportTotalEnabled) { + $isServiceExport = $reportlet->getClass() === ServiceSlaReport::class; + } + foreach ($data->getRows() as $row) { - $json[] = \array_combine($dimensions, $row->getDimensions()) - + \array_combine($values, $row->getValues()); + $json[] = array_combine($dimensions, $row->getDimensions()) + + array_combine($values, $row->getValues()); + + if ($isServiceExport) { + $hosts[$row->getDimensions()[0]] = true; + } + } + + if ($exportTotalEnabled) { + $total = [t('Total Hosts') => $isServiceExport ? count($hosts) : $data->count()]; + if ($isServiceExport) { + $total[t('Total Services')] = $data->count(); + } + + $precision = $config['sla_precision'] ?? SlaReport::DEFAULT_REPORT_PRECISION; + $total[t('Total SLA Averages')] = round($data->getAverages()[0], $precision); + + $json[] = $total; } break; diff --git a/library/Reporting/ReportData.php b/library/Reporting/ReportData.php index 787f4db..addd6db 100644 --- a/library/Reporting/ReportData.php +++ b/library/Reporting/ReportData.php @@ -1,4 +1,5 @@ id; - } - - /** - * @param int $id + * Create reportlet from the given model * - * @return $this + * @param Model\Reportlet $reportletModel + * + * @return static */ - public function setId($id) + public static function fromModel(Model\Reportlet $reportletModel): self { - $this->id = $id; + $reportlet = new static(); + $reportlet->class = $reportletModel->class; + + $reportletConfig = [ + 'name' => $reportletModel->report_name, + 'id' => $reportletModel->report_id + ]; + + foreach ($reportletModel->config as $config) { + $reportletConfig[$config->name] = $config->value; + } - return $this; + $reportlet->config = $reportletConfig; + + return $reportlet; } /** @@ -42,18 +46,6 @@ class Reportlet return $this->class; } - /** - * @param string $class - * - * @return $this - */ - public function setClass($class) - { - $this->class = $class; - - return $this; - } - /** * @return array */ @@ -62,18 +54,6 @@ class Reportlet return $this->config; } - /** - * @param array $config - * - * @return $this - */ - public function setConfig($config) - { - $this->config = $config; - - return $this; - } - /** * @return \Icinga\Module\Reporting\Hook\ReportHook */ @@ -81,6 +61,6 @@ class Reportlet { $class = $this->getClass(); - return new $class; + return new $class(); } } diff --git a/library/Reporting/Reports/SystemReport.php b/library/Reporting/Reports/SystemReport.php index 8a3d8dd..5c9a544 100644 --- a/library/Reporting/Reports/SystemReport.php +++ b/library/Reporting/Reports/SystemReport.php @@ -1,8 +1,10 @@ loadHTML($html); + if (! Icinga::app()->isCli()) { + $doc = new \DOMDocument(); + @$doc->loadHTML($html); + + $style = $doc->getElementsByTagName('style')->item(0); + $style->parentNode->removeChild($style); - $style = $doc->getElementsByTagName('style')->item(0); - $style->parentNode->removeChild($style); + $title = $doc->getElementsByTagName('title')->item(0); + $title->parentNode->removeChild($title); - $title = $doc->getElementsByTagName('title')->item(0); - $title->parentNode->removeChild($title); + $meta = $doc->getElementsByTagName('meta')->item(0); + $meta->parentNode->removeChild($meta); - $meta = $doc->getElementsByTagName('meta')->item(0); - $meta->parentNode->removeChild($meta); + $doc->getElementsByTagName('div')->item(0)->setAttribute('class', 'system-report'); - $doc->getElementsByTagName('div')->item(0)->setAttribute('class', 'system-report'); + $html = $doc->saveHTML(); + } else { + $html = nl2br($html); + } - return new HtmlString($doc->saveHTML()); + return new HtmlString($html); } } diff --git a/library/Reporting/RetryConnection.php b/library/Reporting/RetryConnection.php index ebadfd2..5f7e125 100644 --- a/library/Reporting/RetryConnection.php +++ b/library/Reporting/RetryConnection.php @@ -1,4 +1,5 @@ id; + $this->action = $action; + $this->config = $config; + ksort($this->config); + + $this + ->setName($name) + ->setReport($report) + ->setUuid(Uuid::fromBytes($this->getChecksum())); } /** - * @param int $id + * Create schedule from the given model + * + * @param Model\Schedule $scheduleModel * - * @return $this + * @return static */ - public function setId($id) + + public static function fromModel(Model\Schedule $scheduleModel, Report $report): self { - $this->id = $id; + $config = Json::decode($scheduleModel->config ?? [], true); + $schedule = new static("Schedule{$scheduleModel->id}", $scheduleModel->action, $config, $report); + $schedule->id = $scheduleModel->id; - return $this; + return $schedule; } /** + * Get the id of this schedule + * * @return int */ - public function getReportId() + public function getId(): int { - return $this->reportId; + return $this->id; } /** - * @param int $id + * Get the action hook class of this schedule * - * @return $this - */ - public function setReportId($id) - { - $this->reportId = $id; - - return $this; - } - - /** - * @return \DateTime + * @return string */ - public function getStart() + public function getAction(): string { - return $this->start; + return $this->action; } /** - * @param \DateTime $start + * Get the config of this schedule * - * @return $this + * @return array */ - public function setStart(\DateTime $start) + public function getConfig(): array { - $this->start = $start; - - return $this; + return $this->config; } /** - * @return string + * Get the report this schedule belongs to + * + * @return Report */ - public function getFrequency() + public function getReport(): Report { - return $this->frequency; + return $this->report; } /** - * @param string $frequency + * Set the report this schedule belongs to * - * @return $this + * @param Report $report + * + * @return $this */ - public function setFrequency($frequency) + public function setReport(Report $report): self { - $this->frequency = $frequency; + $this->report = $report; return $this; } /** + * Get the checksum of this schedule + * * @return string */ - public function getAction() + public function getChecksum(): string { - return $this->action; + return md5( + $this->getName() . $this->getReport()->getName() . $this->getAction() . Json::encode($this->getConfig()), + true + ); } - /** - * @param string $action - * - * @return $this - */ - public function setAction($action) + public function run(): ExtendedPromiseInterface { - $this->action = $action; + $deferred = new Promise\Deferred(); + Loop::futureTick(function () use ($deferred) { + $action = $this->getAction(); + /** @var ActionHook $actionHook */ + $actionHook = new $action(); - return $this; - } + try { + $actionHook->execute($this->getReport(), $this->getConfig()); + } catch (Exception $err) { + $deferred->reject($err); - /** - * @return array - */ - public function getConfig() - { - return $this->config; - } + return; + } - /** - * @param array $config - * - * @return $this - */ - public function setConfig(array $config) - { - $this->config = $config; + $deferred->resolve(); + }); - return $this; - } + /** @var ExtendedPromiseInterface $promise */ + $promise = $deferred->promise(); - /** - * @return string - */ - public function getChecksum() - { - return \md5( - $this->getId() - . $this->getReportId() - . $this->getStart()->format('Y-m-d H:i:s') - . $this->getAction() - . $this->getFrequency() - . \json_encode($this->getConfig()) - ); + return $promise; } } diff --git a/library/Reporting/Scheduler.php b/library/Reporting/Scheduler.php deleted file mode 100644 index 1b8d9f6..0000000 --- a/library/Reporting/Scheduler.php +++ /dev/null @@ -1,176 +0,0 @@ -modify('midnight'); - - $diff = $midnight->diff($dateTime); - - return $diff->h * 60 * 60 + $diff->i * 60 + $diff->s; -} - -class Scheduler -{ - protected $db; - - protected $loop; - - /** @var array */ - protected $schedules = []; - - /** @var array */ - protected $timers = []; - - public function __construct(Connection $db) - { - $this->db = $db; - $this->loop = Loop::create(); - } - - public function run() - { - $updateTimers = function () use (&$updateTimers) { - $this->updateTimers(); - - $this->loop->addTimer(60, $updateTimers); - }; - - $this->loop->futureTick($updateTimers); - - $this->loop->run(); - } - - protected function fetchSchedules() - { - $schedules = []; - - $select = (new Select()) - ->from('schedule') - ->columns('*'); - - foreach ($this->db->select($select) as $row) { - $schedule = (new Schedule()) - ->setId((int) $row->id) - ->setReportId((int) $row->report_id) - ->setAction($row->action) - ->setConfig(\json_decode($row->config, true)) - ->setStart((new \DateTime())->setTimestamp((int) $row->start / 1000)) - ->setFrequency($row->frequency); - - $schedules[$schedule->getChecksum()] = $schedule; - } - - return $schedules; - } - - protected function updateTimers() - { - $schedules = $this->fetchSchedules(); - - $remove = \array_diff_key($this->schedules, $schedules); - - foreach ($remove as $schedule) { - printf("Removing job %s.\n", "Schedule {$schedule->getId()}"); - - $checksum = $schedule->getChecksum(); - - if (isset($this->timers[$checksum])) { - $this->loop->cancelTimer($this->timers[$checksum]); - unset($this->timers[$checksum]); - } else { - printf("Can't find timer for job %s.\n", $checksum); - } - } - - $add = \array_diff_key($schedules, $this->schedules); - - foreach ($add as $schedule) { - $this->add($schedule); - } - - $this->schedules = $schedules; - } - - - protected function add(Schedule $schedule) - { - $name = "Schedule {$schedule->getId()}"; - $frequency = $schedule->getFrequency(); - $start = clone $schedule->getStart(); - $callback = function () use ($schedule) { - $actionClass = $schedule->getAction(); - /** @var ActionHook $action */ - $action = new $actionClass; - - $action->execute( - Report::fromDb($schedule->getReportId()), - $schedule->getConfig() - ); - }; - - switch ($frequency) { - case 'minutely': - $modify = '+1 minute'; - break; - case 'hourly': - $modify = '+1 hour'; - break; - case 'daily': - $modify = '+1 day'; - break; - case 'weekly': - $modify = '+1 week'; - break; - case 'monthly': - $modify = '+1 month'; - break; - default: - throw new \InvalidArgumentException('Invalid frequency.'); - } - - $now = new \DateTime(); - - if ($start < $now) { -// printf("Scheduling job %s to run immediately.\n", $name); -// $this->loop->futureTick($callback); - - while ($start < $now) { - $start->modify($modify); - } - } - - $next = clone $start; - $next->modify($modify); - $interval = $next->getTimestamp() - $start->getTimestamp(); - - $current = $start->getTimestamp() - $now->getTimestamp(); - - printf("Scheduling job %s to run at %s.\n", $name, $start->format('Y-m-d H:i:s')); - - $loop = function () use (&$loop, $name, $callback, $interval, $schedule) { - $callback(); - - $nextRun = (new \DateTime()) - ->add(new \DateInterval("PT{$interval}S")); - - printf("Scheduling job %s to run at %s.\n", $name, $nextRun->format('Y-m-d H:i:s')); - - $timer = $this->loop->addTimer($interval, $loop); - - $this->timers[$schedule->getChecksum()] = $timer; - }; - - $timer = $this->loop->addTimer($current, $loop); - - $this->timers[$schedule->getChecksum()] = $timer; - } -} diff --git a/library/Reporting/Str.php b/library/Reporting/Str.php index d4c7355..77eb65e 100644 --- a/library/Reporting/Str.php +++ b/library/Reporting/Str.php @@ -1,4 +1,5 @@ getDb(); - - $select = (new Select()) - ->from('timeframe') - ->columns('*') - ->where(['id = ?' => $id]); - - $row = $db->select($select)->fetch(); - - if ($row === false) { - throw new \Exception('Timeframe not found'); - } - - $timeframe - ->setId($row->id) - ->setName($row->name) - ->setTitle($row->title) - ->setStart($row->start) - ->setEnd($row->end); + $timeframe->id = $timeframeModel->id; + $timeframe->name = $timeframeModel->name; + $timeframe->title = $timeframeModel->title; + $timeframe->start = $timeframeModel->start; + $timeframe->end = $timeframeModel->end; return $timeframe; } @@ -66,18 +51,6 @@ class Timeframe return $this->id; } - /** - * @param int $id - * - * @return $this - */ - public function setId($id) - { - $this->id = $id; - - return $this; - } - /** * @return string */ @@ -86,18 +59,6 @@ class Timeframe return $this->name; } - /** - * @param string $name - * - * @return $this - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - /** * @return string */ @@ -106,18 +67,6 @@ class Timeframe return $this->title; } - /** - * @param string $title - * - * @return $this - */ - public function setTitle($title) - { - $this->title = $title; - - return $this; - } - /** * @return string */ @@ -126,18 +75,6 @@ class Timeframe return $this->start; } - /** - * @param string $start - * - * @return $this - */ - public function setStart($start) - { - $this->start = $start; - - return $this; - } - /** * @return string */ @@ -146,18 +83,6 @@ class Timeframe return $this->end; } - /** - * @param string $end - * - * @return $this - */ - public function setEnd($end) - { - $this->end = $end; - - return $this; - } - public function getTimerange() { $start = new \DateTime($this->getStart()); diff --git a/library/Reporting/Timerange.php b/library/Reporting/Timerange.php index 086bfb8..0ca0a2d 100644 --- a/library/Reporting/Timerange.php +++ b/library/Reporting/Timerange.php @@ -1,4 +1,5 @@ hasBeenSubmitted() - && ((isset($form->valid) && $form->valid === true) - || $form->isValid()) - ) { - $this->redirectNow($url); - } - } } diff --git a/library/Reporting/Web/Flatpickr.php b/library/Reporting/Web/Flatpickr.php deleted file mode 100644 index 5f6605d..0000000 --- a/library/Reporting/Web/Flatpickr.php +++ /dev/null @@ -1,77 +0,0 @@ -allowInput = $state; - - return $this; - } - - protected function assembleElement() - { - if (version_compare(Version::VERSION, '2.9.0', '>=')) { - $element = parent::assembleElement(); - } else { - $element = $this->formElement; - } - - if (version_compare(Version::VERSION, '2.10.0', '<')) { - $element->getAttributes()->set('data-use-flatpickr-fallback', true); - } else { - $element->getAttributes()->set('data-use-datetime-picker', true); - } - - if (! $this->allowInput) { - return $element; - } - - $element->getAttributes() - ->set('data-input', true) - ->set('data-flatpickr-wrap', true) - ->set('data-flatpickr-allow-input', true) - ->set('data-flatpickr-click-opens', 'false'); - - return [ - $element, - Html::tag('button', ['type' => 'button', 'class' => 'icon-calendar', 'data-toggle' => true]), - Html::tag('button', ['type' => 'button', 'class' => 'icon-cancel', 'data-clear' => true]) - ]; - } - - protected function assemble() - { - if (version_compare(Version::VERSION, '2.9.0', '>=')) { - parent::assemble(); - return; - } - - if ($this->formElement->hasBeenValidated() && ! $this->formElement->isValid()) { - $this->getAttributes()->add('class', 'has-error'); - } - - $this->add(array_filter([ - $this->assembleLabel(), - $this->assembleElement(), - $this->assembleDescription(), - $this->assembleErrors() - ])); - } -} diff --git a/library/Reporting/Web/Forms/DecoratedElement.php b/library/Reporting/Web/Forms/DecoratedElement.php deleted file mode 100644 index 2578681..0000000 --- a/library/Reporting/Web/Forms/DecoratedElement.php +++ /dev/null @@ -1,17 +0,0 @@ -createElement($type, $name, $attributes); - $decorator->decorate($element); - $this->registerElement($element); - $this->add($element); - } -} diff --git a/library/Reporting/Web/Forms/Decorator/CompatDecorator.php b/library/Reporting/Web/Forms/Decorator/CompatDecorator.php deleted file mode 100644 index b2eb536..0000000 --- a/library/Reporting/Web/Forms/Decorator/CompatDecorator.php +++ /dev/null @@ -1,63 +0,0 @@ -getAttributes()->has('id')) { - $checkbox->setAttribute('id', base64_encode(random_bytes(8))); - } - - $checkbox->getAttributes()->add('class', 'sr-only'); - - $classes = ['toggle-switch']; - if ($checkbox->getAttributes()->get('disabled')->getValue()) { - $classes[] = 'disabled'; - } - - return [ - $checkbox, - new HtmlElement('label', Attributes::create([ - 'class' => $classes, - 'aria-hidden' => 'true', - 'for' => $checkbox->getAttributes()->get('id')->getValue() - ]), new HtmlElement('span', Attributes::create(['class' => 'toggle-slider']))) - ]; - } - - protected function assembleElementCompat() - { - if ($this->formElement instanceof CheckboxElement) { - return $this->createCheckboxCompat($this->formElement); - } - - return $this->formElement; - } - - protected function assemble() - { - if (version_compare(Version::VERSION, '2.9.0', '>=')) { - parent::assemble(); - return; - } - - if ($this->formElement->hasBeenValidated() && ! $this->formElement->isValid()) { - $this->getAttributes()->add('class', 'has-error'); - } - - $this->add(array_filter([ - $this->assembleLabel(), - $this->assembleElementCompat(), - $this->assembleDescription(), - $this->assembleErrors() - ])); - } -} diff --git a/library/Reporting/Web/Forms/ReportForm.php b/library/Reporting/Web/Forms/ReportForm.php index 6b1e692..40e376e 100644 --- a/library/Reporting/Web/Forms/ReportForm.php +++ b/library/Reporting/Web/Forms/ReportForm.php @@ -1,4 +1,5 @@ id = $id; + $form = new static(); + $form->id = $id; + + return $form; + } + + public function getId(): ?int + { + return $this->id; + } + + /** + * Set the label of the submit button + * + * @param string $label + * + * @return $this + */ + public function setSubmitButtonLabel(string $label): self + { + $this->submitButtonLabel = $label; return $this; } - protected function assemble() + /** + * Get the label of the submit button + * + * @return string + */ + public function getSubmitButtonLabel(): string + { + if ($this->submitButtonLabel !== null) { + return $this->submitButtonLabel; + } + + return $this->id === null ? $this->translate('Create Report') : $this->translate('Update Report'); + } + + /** + * Set whether the create and show submit button should be rendered + * + * @param bool $renderCreateAndShowButton + * + * @return $this + */ + public function setRenderCreateAndShowButton(bool $renderCreateAndShowButton): self { - $this->setDefaultElementDecorator(new CompatDecorator()); + $this->renderCreateAndShowButton = $renderCreateAndShowButton; + return $this; + } + + public function hasBeenSubmitted(): bool + { + return $this->hasBeenSent() && ( + $this->getPopulatedValue('submit') + || $this->getPopulatedValue('create_show') + || $this->getPopulatedValue('remove') + ); + } + + protected function assemble() + { $this->addElement('text', 'name', [ - 'required' => true, - 'label' => 'Name' + 'required' => true, + 'label' => $this->translate('Name'), + 'description' => $this->translate( + 'A unique name of this report. It is used when exporting to pdf, json or csv format' + . ' and also when listing the reports in the cli' + ), + 'validators' => [ + 'Callback' => function ($value, CallbackValidator $validator) { + if ($value !== null && strpos($value, '..') !== false) { + $validator->addMessage( + $this->translate('Double dots are not allowed in the report name') + ); + + return false; + } + + return true; + } + ] ]); $this->addElement('select', 'timeframe', [ - 'required' => true, - 'label' => 'Timeframe', - 'options' => [null => 'Please choose'] + $this->listTimeframes(), - 'class' => 'autosubmit' + 'required' => true, + 'class' => 'autosubmit', + 'label' => $this->translate('Timeframe'), + 'options' => [null => $this->translate('Please choose')] + Database::listTimeframes(), + 'description' => $this->translate( + 'Specifies the time frame in which this report is to be generated' + ) ]); $this->addElement('select', 'template', [ - 'label' => 'Template', - 'options' => [null => 'Please choose'] + $this->listTemplates() + 'label' => $this->translate('Template'), + 'options' => [null => $this->translate('Please choose')] + Database::listTemplates(), + 'description' => $this->translate( + 'Specifies the template to use when exporting this report to pdf. (Default Icinga template)' + ) ]); $this->addElement('select', 'reportlet', [ - 'required' => true, - 'label' => 'Report', - 'options' => [null => 'Please choose'] + $this->listReports(), - 'class' => 'autosubmit' + 'required' => true, + 'class' => 'autosubmit', + 'label' => $this->translate('Report'), + 'options' => [null => $this->translate('Please choose')] + $this->listReports(), + 'description' => $this->translate('Specifies the type of the reportlet to be generated') ]); $values = $this->getValues(); @@ -63,7 +153,7 @@ class ReportForm extends CompatForm // $config->populate($this->getValues()); /** @var \Icinga\Module\Reporting\Hook\ReportHook $reportlet */ - $reportlet = new $values['reportlet']; + $reportlet = new $values['reportlet'](); $reportlet->initConfigForm($config); @@ -73,40 +163,43 @@ class ReportForm extends CompatForm } $this->addElement('submit', 'submit', [ - 'label' => $this->id === null ? 'Create Report' : 'Update Report' + 'label' => $this->getSubmitButtonLabel() ]); if ($this->id !== null) { /** @var FormSubmitElement $removeButton */ $removeButton = $this->createElement('submit', 'remove', [ - 'label' => 'Remove Report', + 'label' => $this->translate('Remove Report'), 'class' => 'btn-remove', 'formnovalidate' => true ]); $this->registerElement($removeButton); - $this->getElement('submit')->getWrapper()->prepend($removeButton); - - if ($removeButton->hasBeenPressed()) { - $this->getDb()->delete('report', ['id = ?' => $this->id]); - // Stupid cheat because ipl/html is not capable of multiple submit buttons - $this->getSubmitButton()->setValue($this->getSubmitButton()->getButtonLabel()); - $this->callOnSuccess = false; - $this->valid = true; + /** @var HtmlDocument $wrapper */ + $wrapper = $this->getElement('submit')->getWrapper(); + $wrapper->prepend($removeButton); + } elseif ($this->renderCreateAndShowButton) { + $createAndShow = $this->createElement('submit', 'create_show', [ + 'label' => $this->translate('Create and Show'), + ]); + $this->registerElement($createAndShow); - return; - } + /** @var HtmlDocument $wrapper */ + $wrapper = $this->getElement('submit')->getWrapper(); + $wrapper->prepend($createAndShow); } } public function onSuccess() { - if ($this->callOnSuccess === false) { + $db = Database::get(); + + if ($this->getPopulatedValue('remove')) { + $db->delete('report', ['id = ?' => $this->id]); + return; } - $db = $this->getDb(); - $values = $this->getValues(); $now = time() * 1000; @@ -155,14 +248,16 @@ class ReportForm extends CompatForm foreach ($values as $name => $value) { $db->insert('config', [ - 'reportlet_id' => $reportletId, - 'name' => $name, - 'value' => $value, - 'ctime' => $now, - 'mtime' => $now + 'reportlet_id' => $reportletId, + 'name' => $name, + 'value' => $value, + 'ctime' => $now, + 'mtime' => $now ]); } $db->commitTransaction(); + + $this->id = $reportId; } } diff --git a/library/Reporting/Web/Forms/ScheduleForm.php b/library/Reporting/Web/Forms/ScheduleForm.php index 47f3ee3..72c4767 100644 --- a/library/Reporting/Web/Forms/ScheduleForm.php +++ b/library/Reporting/Web/Forms/ScheduleForm.php @@ -1,96 +1,98 @@ report = $report; + $this->scheduleElement = new ScheduleElement('schedule_element'); + /** @var Web $app */ + $app = Icinga::app(); + $this->scheduleElement->setIdProtector([$app->getRequest(), 'protectId']); + } - $schedule = $report->getSchedule(); + public function getPartUpdates(): array + { + return $this->scheduleElement->prepareMultipartUpdate($this->getRequest()); + } + + /** + * Create a new form instance with the given report + * + * @param Report $report + * + * @return static + */ + public static function fromReport(Report $report): self + { + $form = new static(); + $form->report = $report; + $schedule = $report->getSchedule(); if ($schedule !== null) { - $this->setId($schedule->getId()); + $config = $schedule->getConfig(); + $config['action'] = $schedule->getAction(); + + /** @var Frequency $type */ + $type = $config['frequencyType']; + $config['schedule_element'] = $type::fromJson($config['frequency']); - $values = [ - 'start' => $schedule->getStart()->format('Y-m-d\\TH:i:s'), - 'frequency' => $schedule->getFrequency(), - 'action' => $schedule->getAction() - ] + $schedule->getConfig(); + unset($config['frequency']); + unset($config['frequencyType']); - $this->populate($values); + $form->populate($config); } - return $this; + return $form; } - public function setId($id) + public function hasBeenSubmitted(): bool { - $this->id = $id; - - return $this; + return $this->hasBeenSent() && ( + $this->getPopulatedValue('submit') + || $this->getPopulatedValue('remove') + || $this->getPopulatedValue('send') + ); } protected function assemble() { - $this->setDefaultElementDecorator(new CompatDecorator()); - - $frequency = [ - 'minutely' => 'Minutely', - 'hourly' => 'Hourly', - 'daily' => 'Daily', - 'weekly' => 'Weekly', - 'monthly' => 'Monthly' - ]; - - if (version_compare(Version::VERSION, '2.9.0', '>=')) { - $this->addElement('localDateTime', 'start', [ - 'required' => true, - 'label' => t('Start'), - 'placeholder' => t('Choose date and time') - ]); - } else { - $this->addDecoratedElement((new Flatpickr())->setAllowInput(false), 'text', 'start', [ - 'required' => true, - 'label' => t('Start'), - 'placeholder' => t('Choose date and time') - ]); - } - - $this->addElement('select', 'frequency', [ - 'required' => true, - 'label' => 'Frequency', - 'options' => [null => 'Please choose'] + $frequency, - ]); - $this->addElement('select', 'action', [ - 'required' => true, - 'label' => 'Action', - 'options' => [null => 'Please choose'] + $this->listActions(), - 'class' => 'autosubmit' + 'required' => true, + 'class' => 'autosubmit', + 'options' => array_merge([null => $this->translate('Please choose')], $this->listActions()), + 'label' => $this->translate('Action'), + 'description' => $this->translate('Specifies an action to be triggered by the scheduler') ]); $values = $this->getValues(); @@ -99,8 +101,8 @@ class ScheduleForm extends CompatForm $config = new Form(); // $config->populate($this->getValues()); - /** @var \Icinga\Module\Reporting\Hook\ActionHook $action */ - $action = new $values['action']; + /** @var ActionHook $action */ + $action = new $values['action'](); $action->initConfigForm($config, $this->report); @@ -109,67 +111,80 @@ class ScheduleForm extends CompatForm } } + $this->addHtml(HtmlElement::create('div', ['class' => 'schedule-element-separator'])); + $this->addElement($this->scheduleElement); + + $schedule = $this->report->getSchedule(); $this->addElement('submit', 'submit', [ - 'label' => $this->id === null ? 'Create Schedule' : 'Update Schedule' + 'label' => $schedule === null ? $this->translate('Create Schedule') : $this->translate('Update Schedule') ]); - if ($this->id !== null) { + if ($schedule !== null) { + $sendButton = $this->createElement('submit', 'send', [ + 'label' => $this->translate('Send Report Now'), + 'formnovalidate' => true + ]); + $this->registerElement($sendButton); + + /** @var HtmlDocument $wrapper */ + $wrapper = $this->getElement('submit')->getWrapper(); + $wrapper->prepend($sendButton); + /** @var FormSubmitElement $removeButton */ $removeButton = $this->createElement('submit', 'remove', [ - 'label' => 'Remove Schedule', + 'label' => $this->translate('Remove Schedule'), 'class' => 'btn-remove', 'formnovalidate' => true ]); $this->registerElement($removeButton); - $this->getElement('submit')->getWrapper()->prepend($removeButton); - - if ($removeButton->hasBeenPressed()) { - $this->getDb()->delete('schedule', ['id = ?' => $this->id]); - - // Stupid cheat because ipl/html is not capable of multiple submit buttons - $this->getSubmitButton()->setValue($this->getSubmitButton()->getButtonLabel()); - $this->valid = true; - - return; - } + $wrapper->prepend($removeButton); } } public function onSuccess() { - $db = $this->getDb(); + $db = Database::get(); + $schedule = $this->report->getSchedule(); + if ($this->getPopulatedValue('remove')) { + $db->delete('schedule', ['id = ?' => $schedule->getId()]); - $values = $this->getValues(); + return; + } - $now = time() * 1000; + $values = $this->getValues(); + if ($this->getPopulatedValue('send')) { + $action = new $values['action'](); + $action->execute($this->report, $values); - if (! $values['start'] instanceof DateTime) { - $values['start'] = DateTime::createFromFormat('Y-m-d H:i:s', $values['start']); + return; } - $data = [ - 'start' => $values['start']->getTimestamp() * 1000, - 'frequency' => $values['frequency'], - 'action' => $values['action'], - 'mtime' => $now - ]; - - unset($values['start']); - unset($values['frequency']); + $action = $values['action']; unset($values['action']); + unset($values['schedule_element']); - $data['config'] = json_encode($values); + $frequency = $this->scheduleElement->getValue(); + $values['frequency'] = Json::encode($frequency); + $values['frequencyType'] = get_php_type($frequency); + $config = Json::encode($values); $db->beginTransaction(); - if ($this->id === null) { - $db->insert('schedule', $data + [ + if ($schedule === null) { + $now = (new DateTime())->getTimestamp() * 1000; + $db->insert('schedule', [ 'author' => Auth::getInstance()->getUser()->getUsername(), 'report_id' => $this->report->getId(), - 'ctime' => $now + 'ctime' => $now, + 'mtime' => $now, + 'action' => $action, + 'config' => $config ]); } else { - $db->update('schedule', $data, ['id = ?' => $this->id]); + $db->update('schedule', [ + 'action' => $action, + 'config' => $config + ], ['id = ?' => $schedule->getId()]); } $db->commitTransaction(); diff --git a/library/Reporting/Web/Forms/SendForm.php b/library/Reporting/Web/Forms/SendForm.php index 03b691c..e3cf3ec 100644 --- a/library/Reporting/Web/Forms/SendForm.php +++ b/library/Reporting/Web/Forms/SendForm.php @@ -1,18 +1,16 @@ setDefaultElementDecorator(new CompatDecorator()); - (new SendMail())->initConfigForm($this, $this->report); $this->addElement('submit', 'submit', [ - 'label' => 'Send Report' + 'label' => $this->translate('Send Report') ]); } diff --git a/library/Reporting/Web/Forms/TemplateForm.php b/library/Reporting/Web/Forms/TemplateForm.php index bb062bb..4cd44a9 100644 --- a/library/Reporting/Web/Forms/TemplateForm.php +++ b/library/Reporting/Web/Forms/TemplateForm.php @@ -1,23 +1,21 @@ template; } - public function setTemplate($template) + /** + * Create a new form instance with the given report + * + * @param $template + * + * @return static + */ + public static function fromTemplate($template): self { - $this->template = $template; + $form = new static(); + + $template->settings = Json::decode($template->settings, true); + $form->template = $template; if ($template->settings) { - $this->populate(array_filter($template->settings, function ($value) { + /** @var array $settings */ + $settings = $template->settings; + $form->populate(array_filter($settings, function ($value) { // Don't populate files return ! is_array($value); })); } - return $this; + return $form; } - protected function assemble() + public function hasBeenSubmitted(): bool { - $this->setDefaultElementDecorator(new CompatDecorator()); + return $this->hasBeenSent() && ($this->getPopulatedValue('submit') || $this->getPopulatedValue('remove')); + } + protected function assemble() + { $this->setAttribute('enctype', 'multipart/form-data'); $this->add(Html::tag('h2', 'Template Settings')); $this->addElement('text', 'name', [ - 'label' => 'Name', - 'placeholder' => 'Template name', + 'label' => $this->translate('Name'), + 'placeholder' => $this->translate('Template name'), 'required' => true ]); - $this->add(Html::tag('h2', 'Cover Page Settings')); + $this->add(Html::tag('h2', $this->translate('Cover Page Settings'))); - $this->addElement(new FileElement('cover_page_background_image', [ - 'label' => 'Background Image', - 'accept' => 'image/png, image/jpeg' - ])); + $this->addElement('file', 'cover_page_background_image', [ + 'label' => $this->translate('Background Image'), + 'accept' => ['image/png', 'image/jpeg', 'image/jpg'], + 'destination' => sys_get_temp_dir() + ]); - if ($this->template !== null - && isset($this->template->settings['cover_page_background_image']) + if ( + $this->template !== null + && isset($this->template->settings['cover_page_background_image']) ) { $this->add(Html::tag( 'p', - ['style' => ['margin-left: 14em;']], - 'Upload a new background image to override the existing one' + ['class' => 'override-uploaded-file-hint'], + $this->translate('Upload a new background image to override the existing one') )); $this->addElement('checkbox', 'remove_cover_page_background_image', [ - 'label' => 'Remove background image' + 'label' => $this->translate('Remove background image') ]); } - $this->addElement(new FileElement('cover_page_logo', [ - 'label' => 'Logo', - 'accept' => 'image/png, image/jpeg' - ])); + $this->addElement('file', 'cover_page_logo', [ + 'label' => $this->translate('Logo'), + 'accept' => ['image/png', 'image/jpeg', 'image/jpg'], + 'destination' => sys_get_temp_dir() + ]); - if ($this->template !== null + if ( + $this->template !== null && isset($this->template->settings['cover_page_logo']) ) { $this->add(Html::tag( 'p', - ['style' => ['margin-left: 14em;']], - 'Upload a new logo to override the existing one' + ['class' => 'override-uploaded-file-hint'], + $this->translate('Upload a new logo to override the existing one') )); $this->addElement('checkbox', 'remove_cover_page_logo', [ - 'label' => 'Remove Logo' + 'label' => $this->translate('Remove Logo') ]); } $this->addElement('textarea', 'title', [ - 'label' => 'Title', - 'placeholder' => 'Report title' + 'label' => $this->translate('Title'), + 'placeholder' => $this->translate('Report title') ]); $this->addElement('text', 'color', [ - 'label' => 'Color', - 'placeholder' => 'CSS color code' + 'label' => $this->translate('Color'), + 'placeholder' => $this->translate('CSS color code') ]); - $this->add(Html::tag('h2', 'Header Settings')); + $this->add(Html::tag('h2', $this->translate('Header Settings'))); - $this->addColumnSettings('header_column1', 'Column 1'); - $this->addColumnSettings('header_column2', 'Column 2'); - $this->addColumnSettings('header_column3', 'Column 3'); + $this->addColumnSettings('header_column1', $this->translate('Column 1')); + $this->addColumnSettings('header_column2', $this->translate('Column 2')); + $this->addColumnSettings('header_column3', $this->translate('Column 3')); - $this->add(Html::tag('h2', 'Footer Settings')); + $this->add(Html::tag('h2', $this->translate('Footer Settings'))); - $this->addColumnSettings('footer_column1', 'Column 1'); - $this->addColumnSettings('footer_column2', 'Column 2'); - $this->addColumnSettings('footer_column3', 'Column 3'); + $this->addColumnSettings('footer_column1', $this->translate('Column 1')); + $this->addColumnSettings('footer_column2', $this->translate('Column 2')); + $this->addColumnSettings('footer_column3', $this->translate('Column 3')); $this->addElement('submit', 'submit', [ - 'label' => $this->template === null ? 'Create Template' : 'Update Template' + 'label' => $this->template === null + ? $this->translate('Create Template') + : $this->translate('Update Template') ]); if ($this->template !== null) { /** @var FormSubmitElement $removeButton */ $removeButton = $this->createElement('submit', 'remove', [ - 'label' => 'Remove Template', + 'label' => $this->translate('Remove Template'), 'class' => 'btn-remove', 'formnovalidate' => true ]); $this->registerElement($removeButton); - $this->getElement('submit')->getWrapper()->prepend($removeButton); - if ($removeButton->hasBeenPressed()) { - $this->getDb()->delete('template', ['id = ?' => $this->template->id]); - - // Stupid cheat because ipl/html is not capable of multiple submit buttons - $this->getSubmitButton()->setValue($this->getSubmitButton()->getButtonLabel()); - $this->callOnSuccess = false; - $this->valid = true; - - return; - } + /** @var HtmlDocument $wrapper */ + $wrapper = $this->getElement('submit')->getWrapper(); + $wrapper->prepend($removeButton); } } public function onSuccess() { - if ($this->callOnSuccess === false) { + if ($this->getPopulatedValue('remove')) { + Database::get()->delete('template', ['id = ?' => $this->template->id]); + return; } @@ -153,20 +166,17 @@ class TemplateForm extends CompatForm $settings = $this->getValues(); try { - /** @var $uploadedFile \GuzzleHttp\Psr7\UploadedFile */ - foreach ($this->getRequest()->getUploadedFiles() as $name => $uploadedFile) { - if ($uploadedFile->getError() === UPLOAD_ERR_NO_FILE) { - continue; + foreach ($settings as $name => $setting) { + if ($setting instanceof UploadedFile) { + $settings[$name] = [ + 'mime_type' => $setting->getClientMediaType(), + 'size' => $setting->getSize(), + 'content' => base64_encode((string) $setting->getStream()) + ]; } - - $settings[$name] = [ - 'mime_type' => $uploadedFile->getClientMediaType(), - 'size' => $uploadedFile->getSize(), - 'content' => base64_encode((string) $uploadedFile->getStream()) - ]; } - $db = $this->getDb(); + $db = Database::get(); $now = time() * 1000; @@ -179,19 +189,21 @@ class TemplateForm extends CompatForm 'mtime' => $now ]); } else { - if (isset($settings['remove_cover_page_background_image'])) { + if ($this->getValue('remove_cover_page_background_image', 'n') === 'y') { unset($settings['cover_page_background_image']); unset($settings['remove_cover_page_background_image']); - } elseif (! isset($settings['cover_page_background_image']) + } elseif ( + ! isset($settings['cover_page_background_image']) && isset($this->template->settings['cover_page_background_image']) ) { $settings['cover_page_background_image'] = $this->template->settings['cover_page_background_image']; } - if (isset($settings['remove_cover_page_logo'])) { + if ($this->getValue('remove_cover_page_logo', 'n') === 'y') { unset($settings['cover_page_logo']); unset($settings['remove_cover_page_logo']); - } elseif (! isset($settings['cover_page_logo']) + } elseif ( + ! isset($settings['cover_page_logo']) && isset($this->template->settings['cover_page_logo']) ) { $settings['cover_page_logo'] = $this->template->settings['cover_page_logo']; @@ -204,7 +216,8 @@ class TemplateForm extends CompatForm if ($settings[$type] === 'image') { $value = "{$headerOrFooter}_column{$i}_value"; - if (! isset($settings[$value]) + if ( + ! isset($settings[$value]) && isset($this->template->settings[$value]) ) { $settings[$value] = $this->template->settings[$value]; @@ -219,7 +232,7 @@ class TemplateForm extends CompatForm 'mtime' => $now ], ['id = ?' => $this->template->id]); } - } catch (\Exception $e) { + } catch (Exception $e) { die($e->getMessage()); } } @@ -240,20 +253,31 @@ class TemplateForm extends CompatForm ] ]); + $valueType = $this->getValue($type, 'none'); + $populated = $this->getPopulatedValue($value); + if ( + ($valueType === 'image' && ! $populated instanceof UploadedFile) + || ($valueType !== 'image' && $populated instanceof UploadedFile) + ) { + $this->clearPopulatedValue($value); + } + switch ($this->getValue($type, 'none')) { case 'image': - $this->addElement(new FileElement($value, [ - 'label' => 'Image', - 'accept' => 'image/png, image/jpeg' - ])); + $this->addElement('file', $value, [ + 'label' => 'Image', + 'accept' => ['image/png', 'image/jpeg', 'image/jpg'], + 'destination' => sys_get_temp_dir() + ]); - if ($this->template !== null + if ( + $this->template !== null && $this->template->settings[$type] === 'image' && isset($this->template->settings[$value]) ) { $this->add(Html::tag( 'p', - ['style' => ['margin-left: 14em;']], + ['class' => 'override-uploaded-file-hint'], 'Upload a new image to override the existing one' )); } @@ -270,7 +294,7 @@ class TemplateForm extends CompatForm 'page_of' => 'Page Number + Total Number of Pages', 'date' => 'Date' ], - 'value' => 'report_title' + 'value' => 'report_title' ]); break; case 'text': diff --git a/library/Reporting/Web/Forms/TimeframeForm.php b/library/Reporting/Web/Forms/TimeframeForm.php index 3d78709..37ea34f 100644 --- a/library/Reporting/Web/Forms/TimeframeForm.php +++ b/library/Reporting/Web/Forms/TimeframeForm.php @@ -1,86 +1,203 @@ id = $id; + $form = new static(); + + $form->id = $id; - return $this; + return $form; } - protected function assemble() + public function hasBeenSubmitted(): bool { - $this->setDefaultElementDecorator(new CompatDecorator()); + return $this->hasBeenSent() && ($this->getPopulatedValue('submit') || $this->getPopulatedValue('remove')); + } + protected function assemble() + { $this->addElement('text', 'name', [ - 'required' => true, - 'label' => 'Name' + 'required' => true, + 'label' => $this->translate('Name'), + 'description' => $this->translate('A unique name of this timeframe') ]); - $flatpickr = new Flatpickr(); + $default = new DateTime('00:00:00'); + $start = $this->getPopulatedValue('start', $default); + if (! $start instanceof DateTime) { + $datetime = DateTime::createFromFormat(LocalDateTimeElement::FORMAT, $start); + if ($datetime) { + $start = $datetime; + } + } - $this->addDecoratedElement($flatpickr, 'text', 'start', [ - 'required' => true, - 'label' => 'Start', - 'placeholder' => 'Select a start date or provide a textual datetime description', - 'data-flatpickr-default-hour' => '00' + $relativeStart = $this->getPopulatedValue('relative-start', $start instanceof DateTime ? 'n' : 'y'); + $this->addElement('checkbox', 'relative-start', [ + 'required' => false, + 'class' => 'autosubmit', + 'value' => $relativeStart, + 'label' => $this->translate('Relative Start') ]); - $this->addDecoratedElement($flatpickr, 'text', 'end', [ - 'required' => true, - 'label' => 'End', - 'placeholder' => 'Select a end date or provide a textual datetime description', - 'data-flatpickrDefaultHour' => '23', - 'data-flatpickrDefaultMinute' => '59', - 'data-flatpickrDefaultSeconds' => '59' - ]); + if ($relativeStart === 'n') { + if (! $start instanceof DateTime) { + $start = $default; + $this->clearPopulatedValue('start'); + } + + $this->addElement( + new LocalDateTimeElement('start', [ + 'required' => true, + 'value' => $start, + 'label' => $this->translate('Start'), + 'description' => $this->translate('Specifies the start time of this timeframe') + ]) + ); + } else { + $this->addElement('text', 'start', [ + 'required' => true, + 'label' => $this->translate('Start'), + 'placeholder' => $this->translate('First day of this month'), + 'description' => $this->translate('Specifies the start time of this timeframe'), + 'validators' => [ + new CallbackValidator(function ($value, CallbackValidator $validator) { + if ($value !== null) { + try { + new DateTime($value); + } catch (Exception $_) { + $validator->addMessage($this->translate('Invalid textual date time')); + + return false; + } + } + + return true; + }) + ] + ]); + } + + $default = new DateTime('23:59:59'); + $end = $this->getPopulatedValue('end', $default); + if (! $end instanceof DateTime) { + $datetime = DateTime::createFromFormat(LocalDateTimeElement::FORMAT, $end); + if ($datetime) { + $end = $datetime; + } + } + + $relativeEnd = $this->getPopulatedValue('relative-end', $end instanceof DateTime ? 'n' : 'y'); + if ($relativeStart === 'y') { + $this->addElement('checkbox', 'relative-end', [ + 'required' => false, + 'class' => 'autosubmit', + 'value' => $relativeEnd, + 'label' => $this->translate('Relative End') + ]); + } + + if ($relativeEnd === 'n' || $relativeStart === 'n') { + if (! $end instanceof DateTime) { + $end = $default; + $this->clearPopulatedValue('end'); + } + + $this->addElement( + new LocalDateTimeElement('end', [ + 'required' => true, + 'value' => $end, + 'label' => $this->translate('End'), + 'description' => $this->translate('Specifies the end time of this timeframe') + ]) + ); + } else { + $this->addElement('text', 'end', [ + 'required' => true, + 'label' => $this->translate('End'), + 'placeholder' => $this->translate('Last day of this month'), + 'description' => $this->translate('Specifies the end time of this timeframe'), + 'validators' => [ + new CallbackValidator(function ($value, CallbackValidator $validator) { + if ($value !== null) { + try { + new DateTime($value); + } catch (Exception $_) { + $validator->addMessage($this->translate('Invalid textual date time')); + + return false; + } + } + + return true; + }) + ] + ]); + } $this->addElement('submit', 'submit', [ - 'label' => $this->id === null ? 'Create Time Frame' : 'Update Time Frame' + 'label' => $this->id === null + ? $this->translate('Create Time Frame') + : $this->translate('Update Time Frame') ]); if ($this->id !== null) { /** @var FormSubmitElement $removeButton */ $removeButton = $this->createElement('submit', 'remove', [ - 'label' => 'Remove Time Frame', + 'label' => $this->translate('Remove Time Frame'), 'class' => 'btn-remove', 'formnovalidate' => true ]); $this->registerElement($removeButton); - $this->getElement('submit')->getWrapper()->prepend($removeButton); - if ($removeButton->hasBeenPressed()) { - $this->getDb()->delete('timeframe', ['id = ?' => $this->id]); - - // Stupid cheat because ipl/html is not capable of multiple submit buttons - $this->getSubmitButton()->setValue($this->getSubmitButton()->getButtonLabel()); - $this->valid = true; - - return; - } + /** @var HtmlDocument $wrapper */ + $wrapper = $this->getElement('submit')->getWrapper(); + $wrapper->prepend($removeButton); } } public function onSuccess() { - $db = $this->getDb(); + $db = Database::get(); + + if ($this->getPopulatedValue('remove')) { + $db->delete('timeframe', ['id = ?' => $this->id]); + + return; + } $values = $this->getValues(); + if ($values['start'] instanceof DateTime) { + $values['start'] = $values['start']->format(LocalDateTimeElement::FORMAT); + } + + if ($values['end'] instanceof DateTime) { + $values['end'] = $values['end']->format(LocalDateTimeElement::FORMAT); + } $now = time() * 1000; diff --git a/library/Reporting/Web/ReportsTimeframesAndTemplatesTabs.php b/library/Reporting/Web/ReportsTimeframesAndTemplatesTabs.php index afb8b14..fee6770 100644 --- a/library/Reporting/Web/ReportsTimeframesAndTemplatesTabs.php +++ b/library/Reporting/Web/ReportsTimeframesAndTemplatesTabs.php @@ -1,4 +1,5 @@ getTabs(); + $tabs->getAttributes()->set('data-base-target', '_main'); $tabs->add('reports', [ - 'title' => $this->translate('Show reports'), - 'label' => $this->translate('Reports'), - 'url' => 'reporting/reports' + 'title' => $this->translate('Show reports'), + 'label' => $this->translate('Reports'), + 'url' => 'reporting/reports' ]); $tabs->add('timeframes', [ - 'title' => $this->translate('Show time frames'), - 'label' => $this->translate('Time Frames'), - 'url' => 'reporting/timeframes' + 'title' => $this->translate('Show time frames'), + 'label' => $this->translate('Time Frames'), + 'url' => 'reporting/timeframes' ]); $tabs->add('templates', [ - 'title' => $this->translate('Show templates'), - 'label' => $this->translate('Templates'), - 'url' => 'reporting/templates' + 'title' => $this->translate('Show templates'), + 'label' => $this->translate('Templates'), + 'url' => 'reporting/templates' ]); return $tabs; diff --git a/library/Reporting/Web/Widget/CompatDropdown.php b/library/Reporting/Web/Widget/CompatDropdown.php index cdd7b40..f5d4b03 100644 --- a/library/Reporting/Web/Widget/CompatDropdown.php +++ b/library/Reporting/Web/Widget/CompatDropdown.php @@ -1,4 +1,5 @@ hasBackgroundImage()) { - $this - ->getAttributes() - ->add('style', "background-image: url('" . Template::getDataUrl($this->getBackgroundImage()) . "');"); + $coverPageBackground = (new StyleWithNonce()) + ->setModule('reporting') + ->addFor($this, [ + 'background-image' => sprintf("url('%s')", Template::getDataUrl($this->getBackgroundImage())) + ]); + + $this->addHtml($coverPageBackground); } $content = Html::tag('div', ['class' => 'cover-page-content']); - if ($this->hasColor()) { - $content->getAttributes()->add('style', "color: {$this->getColor()};"); + $coverPageLogo = (new StyleWithNonce()) + ->setModule('reporting') + ->addFor($content, ['color' => $this->getColor()]); + + $content->addHtml($coverPageLogo); } if ($this->hasLogo()) { diff --git a/library/Reporting/Web/Widget/HeaderOrFooter.php b/library/Reporting/Web/Widget/HeaderOrFooter.php index dcb37e7..3ec9a7f 100644 --- a/library/Reporting/Web/Widget/HeaderOrFooter.php +++ b/library/Reporting/Web/Widget/HeaderOrFooter.php @@ -10,9 +10,9 @@ class HeaderOrFooter extends HtmlDocument { use Macros; - const HEADER = 'header'; + public const HEADER = 'header'; - const FOOTER = 'footer'; + public const FOOTER = 'footer'; protected $type; @@ -64,9 +64,9 @@ class HeaderOrFooter extends HtmlDocument protected function createColumn(array $data, $key) { - $typeKey = "${key}_type"; - $valueKey = "${key}_value"; - $type = isset($data[$typeKey]) ? $data[$typeKey] : null; + $typeKey = "{$key}_type"; + $valueKey = "{$key}_value"; + $type = $data[$typeKey] ?? null; switch ($type) { case 'text': diff --git a/library/Reporting/Web/Widget/Template.php b/library/Reporting/Web/Widget/Template.php index e780a3d..0f07703 100644 --- a/library/Reporting/Web/Widget/Template.php +++ b/library/Reporting/Web/Widget/Template.php @@ -1,17 +1,15 @@ from('template') - ->columns('*') - ->where(['id = ?' => $id]); - - $row = $template->getDb()->select($select)->fetch(); - - if ($row === false) { - return null; - } - - $row->settings = json_decode($row->settings, true); + $templateModel->settings = json_decode($templateModel->settings, true); $coverPage = (new CoverPage()) - ->setColor($row->settings['color']) - ->setTitle($row->settings['title']); + ->setColor($templateModel->settings['color']) + ->setTitle($templateModel->settings['title']); - if (isset($row->settings['cover_page_background_image'])) { - $coverPage->setBackgroundImage($row->settings['cover_page_background_image']); + if (isset($templateModel->settings['cover_page_background_image'])) { + $coverPage->setBackgroundImage($templateModel->settings['cover_page_background_image']); } - if (isset($row->settings['cover_page_logo'])) { - $coverPage->setLogo($row->settings['cover_page_logo']); + if (isset($templateModel->settings['cover_page_logo'])) { + $coverPage->setLogo($templateModel->settings['cover_page_logo']); } $template ->setCoverPage($coverPage) - ->setHeader(new HeaderOrFooter(HeaderOrFooter::HEADER, $row->settings)) - ->setFooter(new HeaderOrFooter(HeaderOrFooter::FOOTER, $row->settings)); + ->setHeader(new HeaderOrFooter(HeaderOrFooter::HEADER, $templateModel->settings)) + ->setFooter(new HeaderOrFooter(HeaderOrFooter::FOOTER, $templateModel->settings)); return $template; } diff --git a/library/vendor/ipl/Html/src/FormElement/FileElement.php b/library/vendor/ipl/Html/src/FormElement/FileElement.php deleted file mode 100644 index 88aeb8c..0000000 --- a/library/vendor/ipl/Html/src/FormElement/FileElement.php +++ /dev/null @@ -1,15 +0,0 @@ -=0.8.0), icinga-php-thirdparty (>=0.10.0) + Libraries: icinga-php-library (>=0.13.0), icinga-php-thirdparty (>=0.12.0) Modules: pdfexport (>=0.10.0) Description: Reporting diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..e92acdd --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,22 @@ + + + + ./ + + vendor/* + + + + + + + + + + + + + + + + diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..4799ad3 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,1126 @@ +parameters: + ignoreErrors: + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Clicommands\\\\DownloadCommand\\:\\:defaultAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/clicommands/DownloadCommand.php + + - + message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#" + count: 1 + path: application/clicommands/DownloadCommand.php + + - + message: "#^Call to an undefined method object\\:\\:getName\\(\\)\\.$#" + count: 1 + path: application/clicommands/ListCommand.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Clicommands\\\\ListCommand\\:\\:indexAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/clicommands/ListCommand.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Clicommands\\\\ListCommand\\:\\:outputTable\\(\\) has no return type specified\\.$#" + count: 1 + path: application/clicommands/ListCommand.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Clicommands\\\\ListCommand\\:\\:outputTable\\(\\) has parameter \\$dataCallbacks with no value type specified in iterable type array\\.$#" + count: 1 + path: application/clicommands/ListCommand.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Clicommands\\\\ListCommand\\:\\:outputTable\\(\\) has parameter \\$reports with no type specified\\.$#" + count: 1 + path: application/clicommands/ListCommand.php + + - + message: "#^Parameter \\#1 \\$haystack of function strpos expects string, mixed given\\.$#" + count: 1 + path: application/clicommands/ListCommand.php + + - + message: "#^Parameter \\#2 \\$direction of method ipl\\\\Orm\\\\Query\\:\\:orderBy\\(\\) expects int\\|string\\|null, mixed given\\.$#" + count: 1 + path: application/clicommands/ListCommand.php + + - + message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:like\\(\\) expects array\\\\|string, mixed given\\.$#" + count: 1 + path: application/clicommands/ListCommand.php + + - + message: "#^Cannot access property \\$report on mixed\\.$#" + count: 1 + path: application/clicommands/ScheduleCommand.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Clicommands\\\\ScheduleCommand\\:\\:attachJobsLogging\\(\\) has no return type specified\\.$#" + count: 1 + path: application/clicommands/ScheduleCommand.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Clicommands\\\\ScheduleCommand\\:\\:runAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/clicommands/ScheduleCommand.php + + - + message: "#^Parameter \\#1 \\$scheduleModel of static method Icinga\\\\Module\\\\Reporting\\\\Schedule\\:\\:fromModel\\(\\) expects Icinga\\\\Module\\\\Reporting\\\\Model\\\\Schedule, mixed given\\.$#" + count: 1 + path: application/clicommands/ScheduleCommand.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ConfigController\\:\\:backendAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ConfigController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ConfigController\\:\\:mailAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ConfigController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:assembleActions\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:cloneAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:downloadAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:editAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:indexAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:scheduleAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:sendAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportController.php + + - + message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#" + count: 1 + path: application/controllers/ReportController.php + + - + message: "#^Cannot access property \\$name on mixed\\.$#" + count: 1 + path: application/controllers/ReportsController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportsController\\:\\:indexAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportsController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportsController\\:\\:newAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/ReportsController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplateController\\:\\:editAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/TemplateController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplateController\\:\\:indexAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/TemplateController.php + + - + message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#" + count: 1 + path: application/controllers/TemplateController.php + + - + message: "#^Cannot call method format\\(\\) on mixed\\.$#" + count: 2 + path: application/controllers/TemplatesController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplatesController\\:\\:indexAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/TemplatesController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplatesController\\:\\:newAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/TemplatesController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframeController\\:\\:editAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/TimeframeController.php + + - + message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#" + count: 1 + path: application/controllers/TimeframeController.php + + - + message: "#^Cannot access property \\$ctime on mixed\\.$#" + count: 1 + path: application/controllers/TimeframesController.php + + - + message: "#^Cannot access property \\$end on mixed\\.$#" + count: 1 + path: application/controllers/TimeframesController.php + + - + message: "#^Cannot access property \\$id on mixed\\.$#" + count: 1 + path: application/controllers/TimeframesController.php + + - + message: "#^Cannot access property \\$mtime on mixed\\.$#" + count: 1 + path: application/controllers/TimeframesController.php + + - + message: "#^Cannot access property \\$name on mixed\\.$#" + count: 2 + path: application/controllers/TimeframesController.php + + - + message: "#^Cannot access property \\$start on mixed\\.$#" + count: 1 + path: application/controllers/TimeframesController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframesController\\:\\:indexAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/TimeframesController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframesController\\:\\:newAction\\(\\) has no return type specified\\.$#" + count: 1 + path: application/controllers/TimeframesController.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Forms\\\\ConfigureMailForm\\:\\:createElements\\(\\) has no return type specified\\.$#" + count: 1 + path: application/forms/ConfigureMailForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Forms\\\\ConfigureMailForm\\:\\:createElements\\(\\) has parameter \\$formData with no value type specified in iterable type array\\.$#" + count: 1 + path: application/forms/ConfigureMailForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Forms\\\\SelectBackendForm\\:\\:createElements\\(\\) has no return type specified\\.$#" + count: 1 + path: application/forms/SelectBackendForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Forms\\\\SelectBackendForm\\:\\:createElements\\(\\) has parameter \\$formData with no value type specified in iterable type array\\.$#" + count: 1 + path: application/forms/SelectBackendForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Actions\\\\SendMail\\:\\:execute\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Actions/SendMail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Actions\\\\SendMail\\:\\:execute\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Actions/SendMail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Actions\\\\SendMail\\:\\:initConfigForm\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Actions/SendMail.php + + - + message: "#^Parameter \\#1 \\$from of method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:setFrom\\(\\) expects string, mixed given\\.$#" + count: 1 + path: library/Reporting/Actions/SendMail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Cli\\\\Command\\:\\:init\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Cli/Command.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Cli\\\\Command\\:\\:\\$configs has no type specified\\.$#" + count: 1 + path: library/Reporting/Cli/Command.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Hook\\\\ActionHook\\:\\:execute\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Hook/ActionHook.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Hook\\\\ActionHook\\:\\:execute\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Hook/ActionHook.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Hook\\\\ActionHook\\:\\:initConfigForm\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Hook/ActionHook.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Hook\\\\ReportHook\\:\\:getData\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Hook/ReportHook.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Hook\\\\ReportHook\\:\\:getHtml\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Hook/ReportHook.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Hook\\\\ReportHook\\:\\:initConfigForm\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Hook/ReportHook.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachCsv\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachCsv\\(\\) has parameter \\$csv with no type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachCsv\\(\\) has parameter \\$filename with no type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachJson\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachJson\\(\\) has parameter \\$filename with no type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachJson\\(\\) has parameter \\$json with no type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachPdf\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachPdf\\(\\) has parameter \\$filename with no type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:attachPdf\\(\\) has parameter \\$pdf with no type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:send\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:send\\(\\) has parameter \\$body with no type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:send\\(\\) has parameter \\$recipient with no type specified\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:\\$attachments type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Mail.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Config\\:\\:createBehaviors\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Config.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Config\\:\\:createRelations\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Config.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Report\\:\\:createBehaviors\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Report.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Report\\:\\:createRelations\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Report.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Report\\:\\:getDefaultSort\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Model/Report.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Reportlet\\:\\:createBehaviors\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Reportlet.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Reportlet\\:\\:createRelations\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Reportlet.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Schedule\\:\\:createBehaviors\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Schedule.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Schedule\\:\\:createRelations\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Schedule.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Template\\:\\:createBehaviors\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Template.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Template\\:\\:createRelations\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Template.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Template\\:\\:getDefaultSort\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Model/Template.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Timeframe\\:\\:createBehaviors\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Timeframe.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Model\\\\Timeframe\\:\\:createRelations\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Model/Timeframe.php + + - + message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" + count: 1 + path: library/Reporting/Report.php + + - + message: "#^Cannot access property \\$report_id on mixed\\.$#" + count: 1 + path: library/Reporting/Report.php + + - + message: "#^Cannot access property \\$report_name on mixed\\.$#" + count: 1 + path: library/Reporting/Report.php + + - + message: "#^Cannot call method count\\(\\) on Icinga\\\\Module\\\\Reporting\\\\ReportData\\|null\\.$#" + count: 4 + path: library/Reporting/Report.php + + - + message: "#^Cannot call method first\\(\\) on mixed\\.$#" + count: 2 + path: library/Reporting/Report.php + + - + message: "#^Cannot call method getAverages\\(\\) on Icinga\\\\Module\\\\Reporting\\\\ReportData\\|null\\.$#" + count: 2 + path: library/Reporting/Report.php + + - + message: "#^Cannot call method getDimensions\\(\\) on Icinga\\\\Module\\\\Reporting\\\\ReportData\\|null\\.$#" + count: 2 + path: library/Reporting/Report.php + + - + message: "#^Cannot call method getRows\\(\\) on Icinga\\\\Module\\\\Reporting\\\\ReportData\\|null\\.$#" + count: 2 + path: library/Reporting/Report.php + + - + message: "#^Cannot call method getValues\\(\\) on Icinga\\\\Module\\\\Reporting\\\\ReportData\\|null\\.$#" + count: 2 + path: library/Reporting/Report.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Report\\:\\:providesData\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Report.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Report\\:\\:toJson\\(\\) should return string but returns string\\|false\\.$#" + count: 1 + path: library/Reporting/Report.php + + - + message: "#^Parameter \\#1 \\$reportletModel of static method Icinga\\\\Module\\\\Reporting\\\\Reportlet\\:\\:fromModel\\(\\) expects Icinga\\\\Module\\\\Reporting\\\\Model\\\\Reportlet, mixed given\\.$#" + count: 1 + path: library/Reporting/Report.php + + - + message: "#^Parameter \\#1 \\$timeframeModel of static method Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:fromModel\\(\\) expects Icinga\\\\Module\\\\Reporting\\\\Model\\\\Timeframe, mixed given\\.$#" + count: 1 + path: library/Reporting/Report.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:getAverages\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:getDimensions\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:getRows\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:getTotals\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:getValues\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:setDimensions\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:setDimensions\\(\\) has parameter \\$dimensions with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:setRows\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:setRows\\(\\) has parameter \\$rows with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:setValues\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:setValues\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:\\$dimensions has no type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\ReportData\\:\\:\\$values has no type specified\\.$#" + count: 1 + path: library/Reporting/ReportData.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportRow\\:\\:getDimensions\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportRow.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportRow\\:\\:getValues\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportRow.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportRow\\:\\:setDimensions\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportRow.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportRow\\:\\:setDimensions\\(\\) has parameter \\$dimensions with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/ReportRow.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportRow\\:\\:setValues\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/ReportRow.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\ReportRow\\:\\:setValues\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/ReportRow.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\ReportRow\\:\\:\\$dimensions has no type specified\\.$#" + count: 1 + path: library/Reporting/ReportRow.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\ReportRow\\:\\:\\$values has no type specified\\.$#" + count: 1 + path: library/Reporting/ReportRow.php + + - + message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" + count: 1 + path: library/Reporting/Reportlet.php + + - + message: "#^Cannot access property \\$name on mixed\\.$#" + count: 1 + path: library/Reporting/Reportlet.php + + - + message: "#^Cannot access property \\$value on mixed\\.$#" + count: 1 + path: library/Reporting/Reportlet.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Reportlet\\:\\:getConfig\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Reportlet.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Reportlet\\:\\:getImplementation\\(\\) should return Icinga\\\\Module\\\\Reporting\\\\Hook\\\\ReportHook but returns object\\.$#" + count: 1 + path: library/Reporting/Reportlet.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Reportlet\\:\\:\\$class \\(string\\) does not accept mixed\\.$#" + count: 1 + path: library/Reporting/Reportlet.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Reportlet\\:\\:\\$config type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Reportlet.php + + - + message: "#^Cannot access property \\$parentNode on DOMElement\\|null\\.$#" + count: 3 + path: library/Reporting/Reports/SystemReport.php + + - + message: "#^Cannot call method removeChild\\(\\) on DOMNode\\|null\\.$#" + count: 3 + path: library/Reporting/Reports/SystemReport.php + + - + message: "#^Cannot call method setAttribute\\(\\) on DOMElement\\|null\\.$#" + count: 1 + path: library/Reporting/Reports/SystemReport.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Reports\\\\SystemReport\\:\\:getHtml\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Reports/SystemReport.php + + - + message: "#^Parameter \\#1 \\$content of class ipl\\\\Html\\\\HtmlString constructor expects string, string\\|false given\\.$#" + count: 1 + path: library/Reporting/Reports/SystemReport.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\RetryConnection\\:\\:prepexec\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/RetryConnection.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Schedule\\:\\:__construct\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Schedule.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Schedule\\:\\:getConfig\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Schedule.php + + - + message: "#^Parameter \\#1 \\$json of static method Icinga\\\\Util\\\\Json\\:\\:decode\\(\\) expects string, mixed given\\.$#" + count: 1 + path: library/Reporting/Schedule.php + + - + message: "#^Part \\$scheduleModel\\-\\>id \\(mixed\\) of encapsed string cannot be cast to string\\.$#" + count: 1 + path: library/Reporting/Schedule.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Schedule\\:\\:\\$config type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Schedule.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Schedule\\:\\:\\$id \\(int\\) does not accept mixed\\.$#" + count: 1 + path: library/Reporting/Schedule.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Str\\:\\:contains\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Str.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Str\\:\\:contains\\(\\) has parameter \\$haystack with no type specified\\.$#" + count: 1 + path: library/Reporting/Str.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Str\\:\\:contains\\(\\) has parameter \\$needle with no type specified\\.$#" + count: 1 + path: library/Reporting/Str.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Str\\:\\:putcsv\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Str.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Str\\:\\:putcsv\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Str.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Str\\:\\:putcsv\\(\\) has parameter \\$delimiter with no type specified\\.$#" + count: 1 + path: library/Reporting/Str.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Str\\:\\:putcsv\\(\\) has parameter \\$enclosure with no type specified\\.$#" + count: 1 + path: library/Reporting/Str.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Str\\:\\:putcsv\\(\\) has parameter \\$escape with no type specified\\.$#" + count: 1 + path: library/Reporting/Str.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:getTimerange\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Timeframe.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:\\$end \\(string\\) does not accept mixed\\.$#" + count: 1 + path: library/Reporting/Timeframe.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:\\$id \\(int\\) does not accept mixed\\.$#" + count: 1 + path: library/Reporting/Timeframe.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:\\$name \\(string\\) does not accept mixed\\.$#" + count: 1 + path: library/Reporting/Timeframe.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:\\$start \\(string\\) does not accept mixed\\.$#" + count: 1 + path: library/Reporting/Timeframe.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:\\$title \\(string\\) does not accept mixed\\.$#" + count: 1 + path: library/Reporting/Timeframe.php + + - + message: "#^Cannot call method getUsername\\(\\) on Icinga\\\\User\\|null\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ReportForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ReportForm\\:\\:assemble\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ReportForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ReportForm\\:\\:fromId\\(\\) has parameter \\$id with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ReportForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ReportForm\\:\\:listReports\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ReportForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ReportForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ReportForm.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ReportForm\\:\\:\\$id has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ReportForm.php + + - + message: "#^Call to an undefined method object\\:\\:execute\\(\\)\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ScheduleForm.php + + - + message: "#^Cannot call method getUsername\\(\\) on Icinga\\\\User\\|null\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ScheduleForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ScheduleForm\\:\\:assemble\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ScheduleForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ScheduleForm\\:\\:getPartUpdates\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ScheduleForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ScheduleForm\\:\\:listActions\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ScheduleForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ScheduleForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ScheduleForm.php + + - + message: "#^Parameter \\#1 \\$request of method ipl\\\\Web\\\\FormElement\\\\ScheduleElement\\:\\:prepareMultipartUpdate\\(\\) expects Psr\\\\Http\\\\Message\\\\RequestInterface, Psr\\\\Http\\\\Message\\\\ServerRequestInterface\\|null given\\.$#" + count: 1 + path: library/Reporting/Web/Forms/ScheduleForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\SendForm\\:\\:assemble\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/SendForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\SendForm\\:\\:listReports\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/SendForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\SendForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/SendForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\SendForm\\:\\:setReport\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/SendForm.php + + - + message: "#^Cannot call method getUsername\\(\\) on Icinga\\\\User\\|null\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:addColumnSettings\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:addColumnSettings\\(\\) has parameter \\$label with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:addColumnSettings\\(\\) has parameter \\$name with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:assemble\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:fromTemplate\\(\\) has parameter \\$template with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:getTemplate\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:\\$template has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TemplateForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TimeframeForm\\:\\:assemble\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TimeframeForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TimeframeForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Forms/TimeframeForm.php + + - + message: "#^Parameter \\#2 \\$datetime of static method DateTime\\:\\:createFromFormat\\(\\) expects string, mixed given\\.$#" + count: 2 + path: library/Reporting/Web/Forms/TimeframeForm.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CompatDropdown\\:\\:addLink\\(\\) has parameter \\$attributes with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CompatDropdown.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:assemble\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:getBackgroundImage\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:getLogo\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:hasTitle\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:resolveMacros\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:resolveMacros\\(\\) has parameter \\$subject with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:setBackgroundImage\\(\\) has parameter \\$backgroundImage with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:setLogo\\(\\) has parameter \\$logo with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:\\$backgroundImage type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:\\$logo type has no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:\\$macros has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/CoverPage.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:__construct\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:__construct\\(\\) has parameter \\$type with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:assemble\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:createColumn\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:createColumn\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:createColumn\\(\\) has parameter \\$key with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:resolveMacros\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:resolveMacros\\(\\) has parameter \\$subject with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:resolveVariable\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:resolveVariable\\(\\) has parameter \\$variable with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:\\$data has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:\\$macros has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:\\$tag has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter\\:\\:\\$type has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/HeaderOrFooter.php + + - + message: "#^Cannot access offset 'color' on mixed\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Cannot access offset 'cover_page_logo' on mixed\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Cannot access offset 'cover_page…' on mixed\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Cannot access offset 'title' on mixed\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:assemble\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:getDataUrl\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:getDataUrl\\(\\) has parameter \\$image with no value type specified in iterable type array\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:resolveMacros\\(\\) has no return type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:resolveMacros\\(\\) has parameter \\$subject with no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Parameter \\#1 \\$backgroundImage of method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:setBackgroundImage\\(\\) expects array, mixed given\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Parameter \\#1 \\$color of method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:setColor\\(\\) expects string, mixed given\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Parameter \\#1 \\$json of function json_decode expects string, mixed given\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Parameter \\#1 \\$logo of method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:setLogo\\(\\) expects array, mixed given\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Parameter \\#1 \\$title of method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\CoverPage\\:\\:setTitle\\(\\) expects string, mixed given\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Parameter \\#2 \\$data of class Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\HeaderOrFooter constructor expects array, mixed given\\.$#" + count: 2 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:\\$macros has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php + + - + message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:\\$preview has no type specified\\.$#" + count: 1 + path: library/Reporting/Web/Widget/Template.php diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b540b89 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,35 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: max + + checkFunctionNameCase: true + checkInternalClassCaseSensitivity: true + treatPhpDocTypesAsCertain: false + + paths: + - application + - library + + scanDirectories: + - /icingaweb2 + - /usr/share/icinga-php/ipl + - /usr/share/icinga-php/vendor + - /usr/share/icingaweb2-modules/icingadb + - /usr/share/icingaweb2-modules/pdfexport + + ignoreErrors: + - + messages: + - '#Unsafe usage of new static\(\)#' + - '#. but return statement is missing#' + reportUnmatched: false + + - '#Call to an undefined method Icinga\\Module\\Reporting\\RetryConnection::lastInsertId\(\)#' + + - '#Call to an undefined method Zend_Controller_Action_HelperBroker::layout\(\)#' + + universalObjectCratesClasses: + - Icinga\Web\View + - ipl\Orm\Model diff --git a/public/css/module.less b/public/css/module.less index 49cc4e5..c4ad1bd 100644 --- a/public/css/module.less +++ b/public/css/module.less @@ -1,15 +1,7 @@ // Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 -.flatpickr-calendar { - position: fixed; -} - -.flatpickr-day { - &.selected, - &.selected:hover { - border-color: @icinga-blue; - background: @icinga-blue; - } +.content:focus { + outline: none; } .sla-column { @@ -25,6 +17,10 @@ &.nok { background-color: @color-critical; } + + &.unknown { + background-color: @state-unknown; + } } .sla-table { @@ -92,16 +88,20 @@ } } -.action-bar .dropdown:first-child:hover .dropdown-menu { - left: .25em; -} +.action-bar { + line-height: 2em; -.action-bar .dropdown:last-child:hover .dropdown-menu { - right: .25em; -} + .dropdown:first-child:hover .dropdown-menu { + left: .25em; + } -.action-bar > *:not(:last-child) { - margin-right: .5em; + .dropdown:last-child:hover .dropdown-menu { + right: .25em; + } + + > *:not(:last-child) { + margin-right: .5em; + } } /* Stuff that's missing in ipl <= 0.8 END */ @@ -189,6 +189,14 @@ .page-size-a4(); } +.schedule-element-separator { + border-top: 1px solid @gray-lighter; +} + +.icinga-controls .override-uploaded-file-hint { + margin-left: 14em; +} + /* Form fallback styles, remove once <=2.9.5 support is dropped */ .icinga-controls { diff --git a/public/css/vendor/flatpickr.css b/public/css/vendor/flatpickr.css deleted file mode 100644 index 64eb467..0000000 --- a/public/css/vendor/flatpickr.css +++ /dev/null @@ -1,784 +0,0 @@ -.flatpickr-calendar { - background: transparent; - opacity: 0; - display: none; - text-align: center; - visibility: hidden; - padding: 0; - -webkit-animation: none; - animation: none; - direction: ltr; - border: 0; - font-size: 14px; - line-height: 24px; - border-radius: 5px; - position: absolute; - width: 307.875px; - -webkit-box-sizing: border-box; - box-sizing: border-box; - -ms-touch-action: manipulation; - touch-action: manipulation; - background: #fff; - -webkit-box-shadow: 1px 0 0 #e6e6e6, -1px 0 0 #e6e6e6, 0 1px 0 #e6e6e6, 0 -1px 0 #e6e6e6, 0 3px 13px rgba(0,0,0,0.08); - box-shadow: 1px 0 0 #e6e6e6, -1px 0 0 #e6e6e6, 0 1px 0 #e6e6e6, 0 -1px 0 #e6e6e6, 0 3px 13px rgba(0,0,0,0.08); -} -.flatpickr-calendar.open, -.flatpickr-calendar.inline { - opacity: 1; - max-height: 640px; - visibility: visible; -} -.flatpickr-calendar.open { - display: inline-block; - z-index: 99999; -} -.flatpickr-calendar.animate.open { - -webkit-animation: fpFadeInDown 300ms cubic-bezier(0.23, 1, 0.32, 1); - animation: fpFadeInDown 300ms cubic-bezier(0.23, 1, 0.32, 1); -} -.flatpickr-calendar.inline { - display: block; - position: relative; - top: 2px; -} -.flatpickr-calendar.static { - position: absolute; - top: calc(100% + 2px); -} -.flatpickr-calendar.static.open { - z-index: 999; - display: block; -} -.flatpickr-calendar.multiMonth .flatpickr-days .dayContainer:nth-child(n+1) .flatpickr-day.inRange:nth-child(7n+7) { - -webkit-box-shadow: none !important; - box-shadow: none !important; -} -.flatpickr-calendar.multiMonth .flatpickr-days .dayContainer:nth-child(n+2) .flatpickr-day.inRange:nth-child(7n+1) { - -webkit-box-shadow: -2px 0 0 #e6e6e6, 5px 0 0 #e6e6e6; - box-shadow: -2px 0 0 #e6e6e6, 5px 0 0 #e6e6e6; -} -.flatpickr-calendar .hasWeeks .dayContainer, -.flatpickr-calendar .hasTime .dayContainer { - border-bottom: 0; - border-bottom-right-radius: 0; - border-bottom-left-radius: 0; -} -.flatpickr-calendar .hasWeeks .dayContainer { - border-left: 0; -} -.flatpickr-calendar.showTimeInput.hasTime .flatpickr-time { - height: 40px; - border-top: 1px solid #e6e6e6; -} -.flatpickr-calendar.noCalendar.hasTime .flatpickr-time { - height: auto; -} -.flatpickr-calendar:before, -.flatpickr-calendar:after { - position: absolute; - display: block; - pointer-events: none; - border: solid transparent; - content: ''; - height: 0; - width: 0; - left: 22px; -} -.flatpickr-calendar.rightMost:before, -.flatpickr-calendar.rightMost:after { - left: auto; - right: 22px; -} -.flatpickr-calendar:before { - border-width: 5px; - margin: 0 -5px; -} -.flatpickr-calendar:after { - border-width: 4px; - margin: 0 -4px; -} -.flatpickr-calendar.arrowTop:before, -.flatpickr-calendar.arrowTop:after { - bottom: 100%; -} -.flatpickr-calendar.arrowTop:before { - border-bottom-color: #e6e6e6; -} -.flatpickr-calendar.arrowTop:after { - border-bottom-color: #fff; -} -.flatpickr-calendar.arrowBottom:before, -.flatpickr-calendar.arrowBottom:after { - top: 100%; -} -.flatpickr-calendar.arrowBottom:before { - border-top-color: #e6e6e6; -} -.flatpickr-calendar.arrowBottom:after { - border-top-color: #fff; -} -.flatpickr-calendar:focus { - outline: 0; -} -.flatpickr-wrapper { - position: relative; - display: inline-block; -} -.flatpickr-months { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; -} -.flatpickr-months .flatpickr-month { - background: transparent; - color: rgba(0,0,0,0.9); - fill: rgba(0,0,0,0.9); - height: 34px; - line-height: 1; - text-align: center; - position: relative; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; - overflow: hidden; - -webkit-box-flex: 1; - -webkit-flex: 1; - -ms-flex: 1; - flex: 1; -} -.flatpickr-months .flatpickr-prev-month, -.flatpickr-months .flatpickr-next-month { - text-decoration: none; - cursor: pointer; - position: absolute; - top: 0; - height: 34px; - padding: 10px; - z-index: 3; - color: rgba(0,0,0,0.9); - fill: rgba(0,0,0,0.9); -} -.flatpickr-months .flatpickr-prev-month.flatpickr-disabled, -.flatpickr-months .flatpickr-next-month.flatpickr-disabled { - display: none; -} -.flatpickr-months .flatpickr-prev-month i, -.flatpickr-months .flatpickr-next-month i { - position: relative; -} -.flatpickr-months .flatpickr-prev-month.flatpickr-prev-month, -.flatpickr-months .flatpickr-next-month.flatpickr-prev-month { -/* - /*rtl:begin:ignore*/ -/* - */ - left: 0; -/* - /*rtl:end:ignore*/ -/* - */ -} -/* - /*rtl:begin:ignore*/ -/* - /*rtl:end:ignore*/ -.flatpickr-months .flatpickr-prev-month.flatpickr-next-month, -.flatpickr-months .flatpickr-next-month.flatpickr-next-month { -/* - /*rtl:begin:ignore*/ -/* - */ - right: 0; -/* - /*rtl:end:ignore*/ -/* - */ -} -/* - /*rtl:begin:ignore*/ -/* - /*rtl:end:ignore*/ -.flatpickr-months .flatpickr-prev-month:hover, -.flatpickr-months .flatpickr-next-month:hover { - color: #959ea9; -} -.flatpickr-months .flatpickr-prev-month:hover svg, -.flatpickr-months .flatpickr-next-month:hover svg { - fill: #f64747; -} -.flatpickr-months .flatpickr-prev-month svg, -.flatpickr-months .flatpickr-next-month svg { - width: 14px; - height: 14px; -} -.flatpickr-months .flatpickr-prev-month svg path, -.flatpickr-months .flatpickr-next-month svg path { - -webkit-transition: fill 0.1s; - transition: fill 0.1s; - fill: inherit; -} -.numInputWrapper { - position: relative; - height: auto; -} -.numInputWrapper input, -.numInputWrapper span { - display: inline-block; -} -.numInputWrapper input { - width: 100%; -} -.numInputWrapper input::-ms-clear { - display: none; -} -.numInputWrapper input::-webkit-outer-spin-button, -.numInputWrapper input::-webkit-inner-spin-button { - margin: 0; - -webkit-appearance: none; -} -.numInputWrapper span { - position: absolute; - right: 0; - width: 14px; - padding: 0 4px 0 2px; - height: 50%; - line-height: 50%; - opacity: 0; - cursor: pointer; - border: 1px solid rgba(57,57,57,0.15); - -webkit-box-sizing: border-box; - box-sizing: border-box; -} -.numInputWrapper span:hover { - background: rgba(0,0,0,0.1); -} -.numInputWrapper span:active { - background: rgba(0,0,0,0.2); -} -.numInputWrapper span:after { - display: block; - content: ""; - position: absolute; -} -.numInputWrapper span.arrowUp { - top: 0; - border-bottom: 0; -} -.numInputWrapper span.arrowUp:after { - border-left: 4px solid transparent; - border-right: 4px solid transparent; - border-bottom: 4px solid rgba(57,57,57,0.6); - top: 26%; -} -.numInputWrapper span.arrowDown { - top: 50%; -} -.numInputWrapper span.arrowDown:after { - border-left: 4px solid transparent; - border-right: 4px solid transparent; - border-top: 4px solid rgba(57,57,57,0.6); - top: 40%; -} -.numInputWrapper span svg { - width: inherit; - height: auto; -} -.numInputWrapper span svg path { - fill: rgba(0,0,0,0.5); -} -.numInputWrapper:hover { - background: rgba(0,0,0,0.05); -} -.numInputWrapper:hover span { - opacity: 1; -} -.flatpickr-current-month { - font-size: 135%; - line-height: inherit; - font-weight: 300; - color: inherit; - position: absolute; - width: 75%; - left: 12.5%; - padding: 7.48px 0 0 0; - line-height: 1; - height: 34px; - display: inline-block; - text-align: center; - -webkit-transform: translate3d(0px, 0px, 0px); - transform: translate3d(0px, 0px, 0px); -} -.flatpickr-current-month span.cur-month { - font-family: inherit; - font-weight: 700; - color: inherit; - display: inline-block; - margin-left: 0.5ch; - padding: 0; -} -.flatpickr-current-month span.cur-month:hover { - background: rgba(0,0,0,0.05); -} -.flatpickr-current-month .numInputWrapper { - width: 6ch; - width: 7ch\0; - display: inline-block; -} -.flatpickr-current-month .numInputWrapper span.arrowUp:after { - border-bottom-color: rgba(0,0,0,0.9); -} -.flatpickr-current-month .numInputWrapper span.arrowDown:after { - border-top-color: rgba(0,0,0,0.9); -} -.flatpickr-current-month input.cur-year { - background: transparent; - -webkit-box-sizing: border-box; - box-sizing: border-box; - color: inherit; - cursor: text; - padding: 0 0 0 0.5ch; - margin: 0; - display: inline-block; - font-size: inherit; - font-family: inherit; - font-weight: 300; - line-height: inherit; - height: auto; - border: 0; - border-radius: 0; - vertical-align: initial; - -webkit-appearance: textfield; - -moz-appearance: textfield; - appearance: textfield; -} -.flatpickr-current-month input.cur-year:focus { - outline: 0; -} -.flatpickr-current-month input.cur-year[disabled], -.flatpickr-current-month input.cur-year[disabled]:hover { - font-size: 100%; - color: rgba(0,0,0,0.5); - background: transparent; - pointer-events: none; -} -.flatpickr-current-month .flatpickr-monthDropdown-months { - appearance: menulist; - background: transparent; - border: none; - border-radius: 0; - box-sizing: border-box; - color: inherit; - cursor: pointer; - font-size: inherit; - font-family: inherit; - font-weight: 300; - height: auto; - line-height: inherit; - margin: -1px 0 0 0; - outline: none; - padding: 0 0 0 0.5ch; - position: relative; - vertical-align: initial; - -webkit-box-sizing: border-box; - -webkit-appearance: menulist; - -moz-appearance: menulist; - width: auto; -} -.flatpickr-current-month .flatpickr-monthDropdown-months:focus, -.flatpickr-current-month .flatpickr-monthDropdown-months:active { - outline: none; -} -.flatpickr-current-month .flatpickr-monthDropdown-months:hover { - background: rgba(0,0,0,0.05); -} -.flatpickr-current-month .flatpickr-monthDropdown-months .flatpickr-monthDropdown-month { - background-color: transparent; - outline: none; - padding: 0; -} -.flatpickr-weekdays { - background: transparent; - text-align: center; - overflow: hidden; - width: 100%; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-box-align: center; - -webkit-align-items: center; - -ms-flex-align: center; - align-items: center; - height: 28px; -} -.flatpickr-weekdays .flatpickr-weekdaycontainer { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-box-flex: 1; - -webkit-flex: 1; - -ms-flex: 1; - flex: 1; -} -span.flatpickr-weekday { - cursor: default; - font-size: 90%; - background: transparent; - color: rgba(0,0,0,0.54); - line-height: 1; - margin: 0; - text-align: center; - display: block; - -webkit-box-flex: 1; - -webkit-flex: 1; - -ms-flex: 1; - flex: 1; - font-weight: bolder; -} -.dayContainer, -.flatpickr-weeks { - padding: 1px 0 0 0; -} -.flatpickr-days { - position: relative; - overflow: hidden; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-box-align: start; - -webkit-align-items: flex-start; - -ms-flex-align: start; - align-items: flex-start; - width: 307.875px; -} -.flatpickr-days:focus { - outline: 0; -} -.dayContainer { - padding: 0; - outline: 0; - text-align: left; - width: 307.875px; - min-width: 307.875px; - max-width: 307.875px; - -webkit-box-sizing: border-box; - box-sizing: border-box; - display: inline-block; - display: -ms-flexbox; - display: -webkit-box; - display: -webkit-flex; - display: flex; - -webkit-flex-wrap: wrap; - flex-wrap: wrap; - -ms-flex-wrap: wrap; - -ms-flex-pack: justify; - -webkit-justify-content: space-around; - justify-content: space-around; - -webkit-transform: translate3d(0px, 0px, 0px); - transform: translate3d(0px, 0px, 0px); - opacity: 1; -} -.dayContainer + .dayContainer { - -webkit-box-shadow: -1px 0 0 #e6e6e6; - box-shadow: -1px 0 0 #e6e6e6; -} -.flatpickr-day { - background: none; - border: 1px solid transparent; - border-radius: 150px; - -webkit-box-sizing: border-box; - box-sizing: border-box; - color: #393939; - cursor: pointer; - font-weight: 400; - width: 14.2857143%; - -webkit-flex-basis: 14.2857143%; - -ms-flex-preferred-size: 14.2857143%; - flex-basis: 14.2857143%; - max-width: 39px; - height: 39px; - line-height: 39px; - margin: 0; - display: inline-block; - position: relative; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; - justify-content: center; - text-align: center; -} -.flatpickr-day.inRange, -.flatpickr-day.prevMonthDay.inRange, -.flatpickr-day.nextMonthDay.inRange, -.flatpickr-day.today.inRange, -.flatpickr-day.prevMonthDay.today.inRange, -.flatpickr-day.nextMonthDay.today.inRange, -.flatpickr-day:hover, -.flatpickr-day.prevMonthDay:hover, -.flatpickr-day.nextMonthDay:hover, -.flatpickr-day:focus, -.flatpickr-day.prevMonthDay:focus, -.flatpickr-day.nextMonthDay:focus { - cursor: pointer; - outline: 0; - background: #e6e6e6; - border-color: #e6e6e6; -} -.flatpickr-day.today { - border-color: #959ea9; -} -.flatpickr-day.today:hover, -.flatpickr-day.today:focus { - border-color: #959ea9; - background: #959ea9; - color: #fff; -} -.flatpickr-day.selected, -.flatpickr-day.startRange, -.flatpickr-day.endRange, -.flatpickr-day.selected.inRange, -.flatpickr-day.startRange.inRange, -.flatpickr-day.endRange.inRange, -.flatpickr-day.selected:focus, -.flatpickr-day.startRange:focus, -.flatpickr-day.endRange:focus, -.flatpickr-day.selected:hover, -.flatpickr-day.startRange:hover, -.flatpickr-day.endRange:hover, -.flatpickr-day.selected.prevMonthDay, -.flatpickr-day.startRange.prevMonthDay, -.flatpickr-day.endRange.prevMonthDay, -.flatpickr-day.selected.nextMonthDay, -.flatpickr-day.startRange.nextMonthDay, -.flatpickr-day.endRange.nextMonthDay { - background: #569ff7; - -webkit-box-shadow: none; - box-shadow: none; - color: #fff; - border-color: #569ff7; -} -.flatpickr-day.selected.startRange, -.flatpickr-day.startRange.startRange, -.flatpickr-day.endRange.startRange { - border-radius: 50px 0 0 50px; -} -.flatpickr-day.selected.endRange, -.flatpickr-day.startRange.endRange, -.flatpickr-day.endRange.endRange { - border-radius: 0 50px 50px 0; -} -.flatpickr-day.selected.startRange + .endRange:not(:nth-child(7n+1)), -.flatpickr-day.startRange.startRange + .endRange:not(:nth-child(7n+1)), -.flatpickr-day.endRange.startRange + .endRange:not(:nth-child(7n+1)) { - -webkit-box-shadow: -10px 0 0 #569ff7; - box-shadow: -10px 0 0 #569ff7; -} -.flatpickr-day.selected.startRange.endRange, -.flatpickr-day.startRange.startRange.endRange, -.flatpickr-day.endRange.startRange.endRange { - border-radius: 50px; -} -.flatpickr-day.inRange { - border-radius: 0; - -webkit-box-shadow: -5px 0 0 #e6e6e6, 5px 0 0 #e6e6e6; - box-shadow: -5px 0 0 #e6e6e6, 5px 0 0 #e6e6e6; -} -.flatpickr-day.flatpickr-disabled, -.flatpickr-day.flatpickr-disabled:hover, -.flatpickr-day.prevMonthDay, -.flatpickr-day.nextMonthDay, -.flatpickr-day.notAllowed, -.flatpickr-day.notAllowed.prevMonthDay, -.flatpickr-day.notAllowed.nextMonthDay { - color: rgba(57,57,57,0.3); - background: transparent; - border-color: transparent; - cursor: default; -} -.flatpickr-day.flatpickr-disabled, -.flatpickr-day.flatpickr-disabled:hover { - cursor: not-allowed; - color: rgba(57,57,57,0.1); -} -.flatpickr-day.week.selected { - border-radius: 0; - -webkit-box-shadow: -5px 0 0 #569ff7, 5px 0 0 #569ff7; - box-shadow: -5px 0 0 #569ff7, 5px 0 0 #569ff7; -} -.flatpickr-day.hidden { - visibility: hidden; -} -.rangeMode .flatpickr-day { - margin-top: 1px; -} -.flatpickr-weekwrapper { - float: left; -} -.flatpickr-weekwrapper .flatpickr-weeks { - padding: 0 12px; - -webkit-box-shadow: 1px 0 0 #e6e6e6; - box-shadow: 1px 0 0 #e6e6e6; -} -.flatpickr-weekwrapper .flatpickr-weekday { - float: none; - width: 100%; - line-height: 28px; -} -.flatpickr-weekwrapper span.flatpickr-day, -.flatpickr-weekwrapper span.flatpickr-day:hover { - display: block; - width: 100%; - max-width: none; - color: rgba(57,57,57,0.3); - background: transparent; - cursor: default; - border: none; -} -.flatpickr-innerContainer { - display: block; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-box-sizing: border-box; - box-sizing: border-box; - overflow: hidden; -} -.flatpickr-rContainer { - display: inline-block; - padding: 0; - -webkit-box-sizing: border-box; - box-sizing: border-box; -} -.flatpickr-time { - text-align: center; - outline: 0; - display: block; - height: 0; - line-height: 40px; - max-height: 40px; - -webkit-box-sizing: border-box; - box-sizing: border-box; - overflow: hidden; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; -} -.flatpickr-time:after { - content: ""; - display: table; - clear: both; -} -.flatpickr-time .numInputWrapper { - -webkit-box-flex: 1; - -webkit-flex: 1; - -ms-flex: 1; - flex: 1; - width: 40%; - height: 40px; - float: left; -} -.flatpickr-time .numInputWrapper span.arrowUp:after { - border-bottom-color: #393939; -} -.flatpickr-time .numInputWrapper span.arrowDown:after { - border-top-color: #393939; -} -.flatpickr-time.hasSeconds .numInputWrapper { - width: 26%; -} -.flatpickr-time.time24hr .numInputWrapper { - width: 49%; -} -.flatpickr-time input { - background: transparent; - -webkit-box-shadow: none; - box-shadow: none; - border: 0; - border-radius: 0; - text-align: center; - margin: 0; - padding: 0; - height: inherit; - line-height: inherit; - color: #393939; - font-size: 14px; - position: relative; - -webkit-box-sizing: border-box; - box-sizing: border-box; - -webkit-appearance: textfield; - -moz-appearance: textfield; - appearance: textfield; -} -.flatpickr-time input.flatpickr-hour { - font-weight: bold; -} -.flatpickr-time input.flatpickr-minute, -.flatpickr-time input.flatpickr-second { - font-weight: 400; -} -.flatpickr-time input:focus { - outline: 0; - border: 0; -} -.flatpickr-time .flatpickr-time-separator, -.flatpickr-time .flatpickr-am-pm { - height: inherit; - float: left; - line-height: inherit; - color: #393939; - font-weight: bold; - width: 2%; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; - -webkit-align-self: center; - -ms-flex-item-align: center; - align-self: center; -} -.flatpickr-time .flatpickr-am-pm { - outline: 0; - width: 18%; - cursor: pointer; - text-align: center; - font-weight: 400; -} -.flatpickr-time input:hover, -.flatpickr-time .flatpickr-am-pm:hover, -.flatpickr-time input:focus, -.flatpickr-time .flatpickr-am-pm:focus { - background: #eee; -} -.flatpickr-input[readonly] { - cursor: pointer; -} -@-webkit-keyframes fpFadeInDown { - from { - opacity: 0; - -webkit-transform: translate3d(0, -20px, 0); - transform: translate3d(0, -20px, 0); - } - to { - opacity: 1; - -webkit-transform: translate3d(0, 0, 0); - transform: translate3d(0, 0, 0); - } -} -@keyframes fpFadeInDown { - from { - opacity: 0; - -webkit-transform: translate3d(0, -20px, 0); - transform: translate3d(0, -20px, 0); - } - to { - opacity: 1; - -webkit-transform: translate3d(0, 0, 0); - transform: translate3d(0, 0, 0); - } -} diff --git a/public/css/vendor/flatpickr.min.css b/public/css/vendor/flatpickr.min.css deleted file mode 100644 index 46c57b7..0000000 --- a/public/css/vendor/flatpickr.min.css +++ /dev/null @@ -1,13 +0,0 @@ -.flatpickr-calendar{background:transparent;opacity:0;display:none;text-align:center;visibility:hidden;padding:0;-webkit-animation:none;animation:none;direction:ltr;border:0;font-size:14px;line-height:24px;border-radius:5px;position:absolute;width:307.875px;-webkit-box-sizing:border-box;box-sizing:border-box;-ms-touch-action:manipulation;touch-action:manipulation;background:#fff;-webkit-box-shadow:1px 0 0 #e6e6e6,-1px 0 0 #e6e6e6,0 1px 0 #e6e6e6,0 -1px 0 #e6e6e6,0 3px 13px rgba(0,0,0,0.08);box-shadow:1px 0 0 #e6e6e6,-1px 0 0 #e6e6e6,0 1px 0 #e6e6e6,0 -1px 0 #e6e6e6,0 3px 13px rgba(0,0,0,0.08);}.flatpickr-calendar.open,.flatpickr-calendar.inline{opacity:1;max-height:640px;visibility:visible}.flatpickr-calendar.open{display:inline-block;z-index:99999}.flatpickr-calendar.animate.open{-webkit-animation:fpFadeInDown 300ms cubic-bezier(.23,1,.32,1);animation:fpFadeInDown 300ms cubic-bezier(.23,1,.32,1)}.flatpickr-calendar.inline{display:block;position:relative;top:2px}.flatpickr-calendar.static{position:absolute;top:calc(100% + 2px);}.flatpickr-calendar.static.open{z-index:999;display:block}.flatpickr-calendar.multiMonth .flatpickr-days .dayContainer:nth-child(n+1) .flatpickr-day.inRange:nth-child(7n+7){-webkit-box-shadow:none !important;box-shadow:none !important}.flatpickr-calendar.multiMonth .flatpickr-days .dayContainer:nth-child(n+2) .flatpickr-day.inRange:nth-child(7n+1){-webkit-box-shadow:-2px 0 0 #e6e6e6,5px 0 0 #e6e6e6;box-shadow:-2px 0 0 #e6e6e6,5px 0 0 #e6e6e6}.flatpickr-calendar .hasWeeks .dayContainer,.flatpickr-calendar .hasTime .dayContainer{border-bottom:0;border-bottom-right-radius:0;border-bottom-left-radius:0}.flatpickr-calendar .hasWeeks .dayContainer{border-left:0}.flatpickr-calendar.showTimeInput.hasTime .flatpickr-time{height:40px;border-top:1px solid #e6e6e6}.flatpickr-calendar.noCalendar.hasTime .flatpickr-time{height:auto}.flatpickr-calendar:before,.flatpickr-calendar:after{position:absolute;display:block;pointer-events:none;border:solid transparent;content:'';height:0;width:0;left:22px}.flatpickr-calendar.rightMost:before,.flatpickr-calendar.rightMost:after{left:auto;right:22px}.flatpickr-calendar:before{border-width:5px;margin:0 -5px}.flatpickr-calendar:after{border-width:4px;margin:0 -4px}.flatpickr-calendar.arrowTop:before,.flatpickr-calendar.arrowTop:after{bottom:100%}.flatpickr-calendar.arrowTop:before{border-bottom-color:#e6e6e6}.flatpickr-calendar.arrowTop:after{border-bottom-color:#fff}.flatpickr-calendar.arrowBottom:before,.flatpickr-calendar.arrowBottom:after{top:100%}.flatpickr-calendar.arrowBottom:before{border-top-color:#e6e6e6}.flatpickr-calendar.arrowBottom:after{border-top-color:#fff}.flatpickr-calendar:focus{outline:0}.flatpickr-wrapper{position:relative;display:inline-block}.flatpickr-months{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}.flatpickr-months .flatpickr-month{background:transparent;color:rgba(0,0,0,0.9);fill:rgba(0,0,0,0.9);height:34px;line-height:1;text-align:center;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;overflow:hidden;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1}.flatpickr-months .flatpickr-prev-month,.flatpickr-months .flatpickr-next-month{text-decoration:none;cursor:pointer;position:absolute;top:0;height:34px;padding:10px;z-index:3;color:rgba(0,0,0,0.9);fill:rgba(0,0,0,0.9);}.flatpickr-months .flatpickr-prev-month.flatpickr-disabled,.flatpickr-months .flatpickr-next-month.flatpickr-disabled{display:none}.flatpickr-months .flatpickr-prev-month i,.flatpickr-months .flatpickr-next-month i{position:relative}.flatpickr-months .flatpickr-prev-month.flatpickr-prev-month,.flatpickr-months .flatpickr-next-month.flatpickr-prev-month{/* - /*rtl:begin:ignore*/left:0;/* - /*rtl:end:ignore*/}/* - /*rtl:begin:ignore*/ -/* - /*rtl:end:ignore*/ -.flatpickr-months .flatpickr-prev-month.flatpickr-next-month,.flatpickr-months .flatpickr-next-month.flatpickr-next-month{/* - /*rtl:begin:ignore*/right:0;/* - /*rtl:end:ignore*/}/* - /*rtl:begin:ignore*/ -/* - /*rtl:end:ignore*/ -.flatpickr-months .flatpickr-prev-month:hover,.flatpickr-months .flatpickr-next-month:hover{color:#959ea9;}.flatpickr-months .flatpickr-prev-month:hover svg,.flatpickr-months .flatpickr-next-month:hover svg{fill:#f64747}.flatpickr-months .flatpickr-prev-month svg,.flatpickr-months .flatpickr-next-month svg{width:14px;height:14px;}.flatpickr-months .flatpickr-prev-month svg path,.flatpickr-months .flatpickr-next-month svg path{-webkit-transition:fill .1s;transition:fill .1s;fill:inherit}.numInputWrapper{position:relative;height:auto;}.numInputWrapper input,.numInputWrapper span{display:inline-block}.numInputWrapper input{width:100%;}.numInputWrapper input::-ms-clear{display:none}.numInputWrapper input::-webkit-outer-spin-button,.numInputWrapper input::-webkit-inner-spin-button{margin:0;-webkit-appearance:none}.numInputWrapper span{position:absolute;right:0;width:14px;padding:0 4px 0 2px;height:50%;line-height:50%;opacity:0;cursor:pointer;border:1px solid rgba(57,57,57,0.15);-webkit-box-sizing:border-box;box-sizing:border-box;}.numInputWrapper span:hover{background:rgba(0,0,0,0.1)}.numInputWrapper span:active{background:rgba(0,0,0,0.2)}.numInputWrapper span:after{display:block;content:"";position:absolute}.numInputWrapper span.arrowUp{top:0;border-bottom:0;}.numInputWrapper span.arrowUp:after{border-left:4px solid transparent;border-right:4px solid transparent;border-bottom:4px solid rgba(57,57,57,0.6);top:26%}.numInputWrapper span.arrowDown{top:50%;}.numInputWrapper span.arrowDown:after{border-left:4px solid transparent;border-right:4px solid transparent;border-top:4px solid rgba(57,57,57,0.6);top:40%}.numInputWrapper span svg{width:inherit;height:auto;}.numInputWrapper span svg path{fill:rgba(0,0,0,0.5)}.numInputWrapper:hover{background:rgba(0,0,0,0.05);}.numInputWrapper:hover span{opacity:1}.flatpickr-current-month{font-size:135%;line-height:inherit;font-weight:300;color:inherit;position:absolute;width:75%;left:12.5%;padding:7.48px 0 0 0;line-height:1;height:34px;display:inline-block;text-align:center;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);}.flatpickr-current-month span.cur-month{font-family:inherit;font-weight:700;color:inherit;display:inline-block;margin-left:.5ch;padding:0;}.flatpickr-current-month span.cur-month:hover{background:rgba(0,0,0,0.05)}.flatpickr-current-month .numInputWrapper{width:6ch;width:7ch\0;display:inline-block;}.flatpickr-current-month .numInputWrapper span.arrowUp:after{border-bottom-color:rgba(0,0,0,0.9)}.flatpickr-current-month .numInputWrapper span.arrowDown:after{border-top-color:rgba(0,0,0,0.9)}.flatpickr-current-month input.cur-year{background:transparent;-webkit-box-sizing:border-box;box-sizing:border-box;color:inherit;cursor:text;padding:0 0 0 .5ch;margin:0;display:inline-block;font-size:inherit;font-family:inherit;font-weight:300;line-height:inherit;height:auto;border:0;border-radius:0;vertical-align:initial;-webkit-appearance:textfield;-moz-appearance:textfield;appearance:textfield;}.flatpickr-current-month input.cur-year:focus{outline:0}.flatpickr-current-month input.cur-year[disabled],.flatpickr-current-month input.cur-year[disabled]:hover{font-size:100%;color:rgba(0,0,0,0.5);background:transparent;pointer-events:none}.flatpickr-current-month .flatpickr-monthDropdown-months{appearance:menulist;background:transparent;border:none;border-radius:0;box-sizing:border-box;color:inherit;cursor:pointer;font-size:inherit;font-family:inherit;font-weight:300;height:auto;line-height:inherit;margin:-1px 0 0 0;outline:none;padding:0 0 0 .5ch;position:relative;vertical-align:initial;-webkit-box-sizing:border-box;-webkit-appearance:menulist;-moz-appearance:menulist;width:auto;}.flatpickr-current-month .flatpickr-monthDropdown-months:focus,.flatpickr-current-month .flatpickr-monthDropdown-months:active{outline:none}.flatpickr-current-month .flatpickr-monthDropdown-months:hover{background:rgba(0,0,0,0.05)}.flatpickr-current-month .flatpickr-monthDropdown-months .flatpickr-monthDropdown-month{background-color:transparent;outline:none;padding:0}.flatpickr-weekdays{background:transparent;text-align:center;overflow:hidden;width:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;height:28px;}.flatpickr-weekdays .flatpickr-weekdaycontainer{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1}span.flatpickr-weekday{cursor:default;font-size:90%;background:transparent;color:rgba(0,0,0,0.54);line-height:1;margin:0;text-align:center;display:block;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;font-weight:bolder}.dayContainer,.flatpickr-weeks{padding:1px 0 0 0}.flatpickr-days{position:relative;overflow:hidden;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-align:start;-webkit-align-items:flex-start;-ms-flex-align:start;align-items:flex-start;width:307.875px;}.flatpickr-days:focus{outline:0}.dayContainer{padding:0;outline:0;text-align:left;width:307.875px;min-width:307.875px;max-width:307.875px;-webkit-box-sizing:border-box;box-sizing:border-box;display:inline-block;display:-ms-flexbox;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-wrap:wrap;-ms-flex-pack:justify;-webkit-justify-content:space-around;justify-content:space-around;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);opacity:1;}.dayContainer + .dayContainer{-webkit-box-shadow:-1px 0 0 #e6e6e6;box-shadow:-1px 0 0 #e6e6e6}.flatpickr-day{background:none;border:1px solid transparent;border-radius:150px;-webkit-box-sizing:border-box;box-sizing:border-box;color:#393939;cursor:pointer;font-weight:400;width:14.2857143%;-webkit-flex-basis:14.2857143%;-ms-flex-preferred-size:14.2857143%;flex-basis:14.2857143%;max-width:39px;height:39px;line-height:39px;margin:0;display:inline-block;position:relative;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;text-align:center;}.flatpickr-day.inRange,.flatpickr-day.prevMonthDay.inRange,.flatpickr-day.nextMonthDay.inRange,.flatpickr-day.today.inRange,.flatpickr-day.prevMonthDay.today.inRange,.flatpickr-day.nextMonthDay.today.inRange,.flatpickr-day:hover,.flatpickr-day.prevMonthDay:hover,.flatpickr-day.nextMonthDay:hover,.flatpickr-day:focus,.flatpickr-day.prevMonthDay:focus,.flatpickr-day.nextMonthDay:focus{cursor:pointer;outline:0;background:#e6e6e6;border-color:#e6e6e6}.flatpickr-day.today{border-color:#959ea9;}.flatpickr-day.today:hover,.flatpickr-day.today:focus{border-color:#959ea9;background:#959ea9;color:#fff}.flatpickr-day.selected,.flatpickr-day.startRange,.flatpickr-day.endRange,.flatpickr-day.selected.inRange,.flatpickr-day.startRange.inRange,.flatpickr-day.endRange.inRange,.flatpickr-day.selected:focus,.flatpickr-day.startRange:focus,.flatpickr-day.endRange:focus,.flatpickr-day.selected:hover,.flatpickr-day.startRange:hover,.flatpickr-day.endRange:hover,.flatpickr-day.selected.prevMonthDay,.flatpickr-day.startRange.prevMonthDay,.flatpickr-day.endRange.prevMonthDay,.flatpickr-day.selected.nextMonthDay,.flatpickr-day.startRange.nextMonthDay,.flatpickr-day.endRange.nextMonthDay{background:#569ff7;-webkit-box-shadow:none;box-shadow:none;color:#fff;border-color:#569ff7}.flatpickr-day.selected.startRange,.flatpickr-day.startRange.startRange,.flatpickr-day.endRange.startRange{border-radius:50px 0 0 50px}.flatpickr-day.selected.endRange,.flatpickr-day.startRange.endRange,.flatpickr-day.endRange.endRange{border-radius:0 50px 50px 0}.flatpickr-day.selected.startRange + .endRange:not(:nth-child(7n+1)),.flatpickr-day.startRange.startRange + .endRange:not(:nth-child(7n+1)),.flatpickr-day.endRange.startRange + .endRange:not(:nth-child(7n+1)){-webkit-box-shadow:-10px 0 0 #569ff7;box-shadow:-10px 0 0 #569ff7}.flatpickr-day.selected.startRange.endRange,.flatpickr-day.startRange.startRange.endRange,.flatpickr-day.endRange.startRange.endRange{border-radius:50px}.flatpickr-day.inRange{border-radius:0;-webkit-box-shadow:-5px 0 0 #e6e6e6,5px 0 0 #e6e6e6;box-shadow:-5px 0 0 #e6e6e6,5px 0 0 #e6e6e6}.flatpickr-day.flatpickr-disabled,.flatpickr-day.flatpickr-disabled:hover,.flatpickr-day.prevMonthDay,.flatpickr-day.nextMonthDay,.flatpickr-day.notAllowed,.flatpickr-day.notAllowed.prevMonthDay,.flatpickr-day.notAllowed.nextMonthDay{color:rgba(57,57,57,0.3);background:transparent;border-color:transparent;cursor:default}.flatpickr-day.flatpickr-disabled,.flatpickr-day.flatpickr-disabled:hover{cursor:not-allowed;color:rgba(57,57,57,0.1)}.flatpickr-day.week.selected{border-radius:0;-webkit-box-shadow:-5px 0 0 #569ff7,5px 0 0 #569ff7;box-shadow:-5px 0 0 #569ff7,5px 0 0 #569ff7}.flatpickr-day.hidden{visibility:hidden}.rangeMode .flatpickr-day{margin-top:1px}.flatpickr-weekwrapper{float:left;}.flatpickr-weekwrapper .flatpickr-weeks{padding:0 12px;-webkit-box-shadow:1px 0 0 #e6e6e6;box-shadow:1px 0 0 #e6e6e6}.flatpickr-weekwrapper .flatpickr-weekday{float:none;width:100%;line-height:28px}.flatpickr-weekwrapper span.flatpickr-day,.flatpickr-weekwrapper span.flatpickr-day:hover{display:block;width:100%;max-width:none;color:rgba(57,57,57,0.3);background:transparent;cursor:default;border:none}.flatpickr-innerContainer{display:block;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-sizing:border-box;box-sizing:border-box;overflow:hidden;}.flatpickr-rContainer{display:inline-block;padding:0;-webkit-box-sizing:border-box;box-sizing:border-box}.flatpickr-time{text-align:center;outline:0;display:block;height:0;line-height:40px;max-height:40px;-webkit-box-sizing:border-box;box-sizing:border-box;overflow:hidden;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}.flatpickr-time:after{content:"";display:table;clear:both}.flatpickr-time .numInputWrapper{-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;width:40%;height:40px;float:left;}.flatpickr-time .numInputWrapper span.arrowUp:after{border-bottom-color:#393939}.flatpickr-time .numInputWrapper span.arrowDown:after{border-top-color:#393939}.flatpickr-time.hasSeconds .numInputWrapper{width:26%}.flatpickr-time.time24hr .numInputWrapper{width:49%}.flatpickr-time input{background:transparent;-webkit-box-shadow:none;box-shadow:none;border:0;border-radius:0;text-align:center;margin:0;padding:0;height:inherit;line-height:inherit;color:#393939;font-size:14px;position:relative;-webkit-box-sizing:border-box;box-sizing:border-box;-webkit-appearance:textfield;-moz-appearance:textfield;appearance:textfield;}.flatpickr-time input.flatpickr-hour{font-weight:bold}.flatpickr-time input.flatpickr-minute,.flatpickr-time input.flatpickr-second{font-weight:400}.flatpickr-time input:focus{outline:0;border:0}.flatpickr-time .flatpickr-time-separator,.flatpickr-time .flatpickr-am-pm{height:inherit;float:left;line-height:inherit;color:#393939;font-weight:bold;width:2%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-align-self:center;-ms-flex-item-align:center;align-self:center}.flatpickr-time .flatpickr-am-pm{outline:0;width:18%;cursor:pointer;text-align:center;font-weight:400}.flatpickr-time input:hover,.flatpickr-time .flatpickr-am-pm:hover,.flatpickr-time input:focus,.flatpickr-time .flatpickr-am-pm:focus{background:#eee}.flatpickr-input[readonly]{cursor:pointer}@-webkit-keyframes fpFadeInDown{from{opacity:0;-webkit-transform:translate3d(0,-20px,0);transform:translate3d(0,-20px,0)}to{opacity:1;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}}@keyframes fpFadeInDown{from{opacity:0;-webkit-transform:translate3d(0,-20px,0);transform:translate3d(0,-20px,0)}to{opacity:1;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}} \ No newline at end of file diff --git a/public/js/module.js b/public/js/module.js deleted file mode 100644 index f65a2d9..0000000 --- a/public/js/module.js +++ /dev/null @@ -1,50 +0,0 @@ -// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 - -;(function (Icinga) { - - 'use strict'; - - var Reporting = function(module) { - this.module = module; - - this.initialize(); - }; - - Reporting.prototype.initialize = function () { - if (typeof $().flatpickr === 'function') { - this.module.on('rendered', function (event) { - var $container = $('
'); - event.target.insertAdjacentElement('beforeend', $container[0]); - $('[data-use-flatpickr-fallback]').each(function() { - var options = { - appendTo: $container[0], - dateFormat: 'Y-m-d H:i:S', - enableTime: true, - enableSeconds: true - }; - - for (name in this.dataset) { - if (name.length > 9 && name.substr(0, 9) === 'flatpickr') { - var value = this.dataset[name]; - if (value === '') { - value = true; - } - - options[name.charAt(9).toLowerCase() + name.substr(10)] = value; - } - } - - var element = this; - if (!! options.wrap) { - element = this.parentNode; - } - - $(element).flatpickr(options); - }); - }); - } - }; - - Icinga.availableModules.reporting = Reporting; - -}(Icinga)); diff --git a/public/js/vendor/flatpickr.js b/public/js/vendor/flatpickr.js deleted file mode 100644 index 15d7397..0000000 --- a/public/js/vendor/flatpickr.js +++ /dev/null @@ -1,2605 +0,0 @@ -/* flatpickr v4.6.3, @license MIT */ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global = global || self, global.flatpickr = factory()); -}(this, function () { 'use strict'; - - /*! ***************************************************************************** - Copyright (c) Microsoft Corporation. All rights reserved. - Licensed under the Apache License, Version 2.0 (the "License"); you may not use - this file except in compliance with the License. You may obtain a copy of the - License at http://www.apache.org/licenses/LICENSE-2.0 - - THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED - WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, - MERCHANTABLITY OR NON-INFRINGEMENT. - - See the Apache Version 2.0 License for specific language governing permissions - and limitations under the License. - ***************************************************************************** */ - - var __assign = function() { - __assign = Object.assign || function __assign(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); - }; - - var HOOKS = [ - "onChange", - "onClose", - "onDayCreate", - "onDestroy", - "onKeyDown", - "onMonthChange", - "onOpen", - "onParseConfig", - "onReady", - "onValueUpdate", - "onYearChange", - "onPreCalendarPosition", - ]; - var defaults = { - _disable: [], - _enable: [], - allowInput: false, - altFormat: "F j, Y", - altInput: false, - altInputClass: "form-control input", - animate: typeof window === "object" && - window.navigator.userAgent.indexOf("MSIE") === -1, - ariaDateFormat: "F j, Y", - clickOpens: true, - closeOnSelect: true, - conjunction: ", ", - dateFormat: "Y-m-d", - defaultHour: 12, - defaultMinute: 0, - defaultSeconds: 0, - disable: [], - disableMobile: false, - enable: [], - enableSeconds: false, - enableTime: false, - errorHandler: function (err) { - return typeof console !== "undefined" && console.warn(err); - }, - getWeek: function (givenDate) { - var date = new Date(givenDate.getTime()); - date.setHours(0, 0, 0, 0); - // Thursday in current week decides the year. - date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7)); - // January 4 is always in week 1. - var week1 = new Date(date.getFullYear(), 0, 4); - // Adjust to Thursday in week 1 and count number of weeks from date to week1. - return (1 + - Math.round(((date.getTime() - week1.getTime()) / 86400000 - - 3 + - ((week1.getDay() + 6) % 7)) / - 7)); - }, - hourIncrement: 1, - ignoredFocusElements: [], - inline: false, - locale: "default", - minuteIncrement: 5, - mode: "single", - monthSelectorType: "dropdown", - nextArrow: "", - noCalendar: false, - now: new Date(), - onChange: [], - onClose: [], - onDayCreate: [], - onDestroy: [], - onKeyDown: [], - onMonthChange: [], - onOpen: [], - onParseConfig: [], - onReady: [], - onValueUpdate: [], - onYearChange: [], - onPreCalendarPosition: [], - plugins: [], - position: "auto", - positionElement: undefined, - prevArrow: "", - shorthandCurrentMonth: false, - showMonths: 1, - static: false, - time_24hr: false, - weekNumbers: false, - wrap: false - }; - - var english = { - weekdays: { - shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], - longhand: [ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - ] - }, - months: { - shorthand: [ - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", - ], - longhand: [ - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", - ] - }, - daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], - firstDayOfWeek: 0, - ordinal: function (nth) { - var s = nth % 100; - if (s > 3 && s < 21) - return "th"; - switch (s % 10) { - case 1: - return "st"; - case 2: - return "nd"; - case 3: - return "rd"; - default: - return "th"; - } - }, - rangeSeparator: " to ", - weekAbbreviation: "Wk", - scrollTitle: "Scroll to increment", - toggleTitle: "Click to toggle", - amPM: ["AM", "PM"], - yearAriaLabel: "Year", - hourAriaLabel: "Hour", - minuteAriaLabel: "Minute", - time_24hr: false - }; - - var pad = function (number) { return ("0" + number).slice(-2); }; - var int = function (bool) { return (bool === true ? 1 : 0); }; - /* istanbul ignore next */ - function debounce(func, wait, immediate) { - if (immediate === void 0) { immediate = false; } - var timeout; - return function () { - var context = this, args = arguments; - timeout !== null && clearTimeout(timeout); - timeout = window.setTimeout(function () { - timeout = null; - if (!immediate) - func.apply(context, args); - }, wait); - if (immediate && !timeout) - func.apply(context, args); - }; - } - var arrayify = function (obj) { - return obj instanceof Array ? obj : [obj]; - }; - - function toggleClass(elem, className, bool) { - if (bool === true) - return elem.classList.add(className); - elem.classList.remove(className); - } - function createElement(tag, className, content) { - var e = window.document.createElement(tag); - className = className || ""; - content = content || ""; - e.className = className; - if (content !== undefined) - e.textContent = content; - return e; - } - function clearNode(node) { - while (node.firstChild) - node.removeChild(node.firstChild); - } - function findParent(node, condition) { - if (condition(node)) - return node; - else if (node.parentNode) - return findParent(node.parentNode, condition); - return undefined; // nothing found - } - function createNumberInput(inputClassName, opts) { - var wrapper = createElement("div", "numInputWrapper"), numInput = createElement("input", "numInput " + inputClassName), arrowUp = createElement("span", "arrowUp"), arrowDown = createElement("span", "arrowDown"); - if (navigator.userAgent.indexOf("MSIE 9.0") === -1) { - numInput.type = "number"; - } - else { - numInput.type = "text"; - numInput.pattern = "\\d*"; - } - if (opts !== undefined) - for (var key in opts) - numInput.setAttribute(key, opts[key]); - wrapper.appendChild(numInput); - wrapper.appendChild(arrowUp); - wrapper.appendChild(arrowDown); - return wrapper; - } - function getEventTarget(event) { - if (typeof event.composedPath === "function") { - var path = event.composedPath(); - return path[0]; - } - return event.target; - } - - var doNothing = function () { return undefined; }; - var monthToStr = function (monthNumber, shorthand, locale) { return locale.months[shorthand ? "shorthand" : "longhand"][monthNumber]; }; - var revFormat = { - D: doNothing, - F: function (dateObj, monthName, locale) { - dateObj.setMonth(locale.months.longhand.indexOf(monthName)); - }, - G: function (dateObj, hour) { - dateObj.setHours(parseFloat(hour)); - }, - H: function (dateObj, hour) { - dateObj.setHours(parseFloat(hour)); - }, - J: function (dateObj, day) { - dateObj.setDate(parseFloat(day)); - }, - K: function (dateObj, amPM, locale) { - dateObj.setHours((dateObj.getHours() % 12) + - 12 * int(new RegExp(locale.amPM[1], "i").test(amPM))); - }, - M: function (dateObj, shortMonth, locale) { - dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth)); - }, - S: function (dateObj, seconds) { - dateObj.setSeconds(parseFloat(seconds)); - }, - U: function (_, unixSeconds) { return new Date(parseFloat(unixSeconds) * 1000); }, - W: function (dateObj, weekNum, locale) { - var weekNumber = parseInt(weekNum); - var date = new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0); - date.setDate(date.getDate() - date.getDay() + locale.firstDayOfWeek); - return date; - }, - Y: function (dateObj, year) { - dateObj.setFullYear(parseFloat(year)); - }, - Z: function (_, ISODate) { return new Date(ISODate); }, - d: function (dateObj, day) { - dateObj.setDate(parseFloat(day)); - }, - h: function (dateObj, hour) { - dateObj.setHours(parseFloat(hour)); - }, - i: function (dateObj, minutes) { - dateObj.setMinutes(parseFloat(minutes)); - }, - j: function (dateObj, day) { - dateObj.setDate(parseFloat(day)); - }, - l: doNothing, - m: function (dateObj, month) { - dateObj.setMonth(parseFloat(month) - 1); - }, - n: function (dateObj, month) { - dateObj.setMonth(parseFloat(month) - 1); - }, - s: function (dateObj, seconds) { - dateObj.setSeconds(parseFloat(seconds)); - }, - u: function (_, unixMillSeconds) { - return new Date(parseFloat(unixMillSeconds)); - }, - w: doNothing, - y: function (dateObj, year) { - dateObj.setFullYear(2000 + parseFloat(year)); - } - }; - var tokenRegex = { - D: "(\\w+)", - F: "(\\w+)", - G: "(\\d\\d|\\d)", - H: "(\\d\\d|\\d)", - J: "(\\d\\d|\\d)\\w+", - K: "", - M: "(\\w+)", - S: "(\\d\\d|\\d)", - U: "(.+)", - W: "(\\d\\d|\\d)", - Y: "(\\d{4})", - Z: "(.+)", - d: "(\\d\\d|\\d)", - h: "(\\d\\d|\\d)", - i: "(\\d\\d|\\d)", - j: "(\\d\\d|\\d)", - l: "(\\w+)", - m: "(\\d\\d|\\d)", - n: "(\\d\\d|\\d)", - s: "(\\d\\d|\\d)", - u: "(.+)", - w: "(\\d\\d|\\d)", - y: "(\\d{2})" - }; - var formats = { - // get the date in UTC - Z: function (date) { return date.toISOString(); }, - // weekday name, short, e.g. Thu - D: function (date, locale, options) { - return locale.weekdays.shorthand[formats.w(date, locale, options)]; - }, - // full month name e.g. January - F: function (date, locale, options) { - return monthToStr(formats.n(date, locale, options) - 1, false, locale); - }, - // padded hour 1-12 - G: function (date, locale, options) { - return pad(formats.h(date, locale, options)); - }, - // hours with leading zero e.g. 03 - H: function (date) { return pad(date.getHours()); }, - // day (1-30) with ordinal suffix e.g. 1st, 2nd - J: function (date, locale) { - return locale.ordinal !== undefined - ? date.getDate() + locale.ordinal(date.getDate()) - : date.getDate(); - }, - // AM/PM - K: function (date, locale) { return locale.amPM[int(date.getHours() > 11)]; }, - // shorthand month e.g. Jan, Sep, Oct, etc - M: function (date, locale) { - return monthToStr(date.getMonth(), true, locale); - }, - // seconds 00-59 - S: function (date) { return pad(date.getSeconds()); }, - // unix timestamp - U: function (date) { return date.getTime() / 1000; }, - W: function (date, _, options) { - return options.getWeek(date); - }, - // full year e.g. 2016 - Y: function (date) { return date.getFullYear(); }, - // day in month, padded (01-30) - d: function (date) { return pad(date.getDate()); }, - // hour from 1-12 (am/pm) - h: function (date) { return (date.getHours() % 12 ? date.getHours() % 12 : 12); }, - // minutes, padded with leading zero e.g. 09 - i: function (date) { return pad(date.getMinutes()); }, - // day in month (1-30) - j: function (date) { return date.getDate(); }, - // weekday name, full, e.g. Thursday - l: function (date, locale) { - return locale.weekdays.longhand[date.getDay()]; - }, - // padded month number (01-12) - m: function (date) { return pad(date.getMonth() + 1); }, - // the month number (1-12) - n: function (date) { return date.getMonth() + 1; }, - // seconds 0-59 - s: function (date) { return date.getSeconds(); }, - // Unix Milliseconds - u: function (date) { return date.getTime(); }, - // number of the day of the week - w: function (date) { return date.getDay(); }, - // last two digits of year e.g. 16 for 2016 - y: function (date) { return String(date.getFullYear()).substring(2); } - }; - - var createDateFormatter = function (_a) { - var _b = _a.config, config = _b === void 0 ? defaults : _b, _c = _a.l10n, l10n = _c === void 0 ? english : _c; - return function (dateObj, frmt, overrideLocale) { - var locale = overrideLocale || l10n; - if (config.formatDate !== undefined) { - return config.formatDate(dateObj, frmt, locale); - } - return frmt - .split("") - .map(function (c, i, arr) { - return formats[c] && arr[i - 1] !== "\\" - ? formats[c](dateObj, locale, config) - : c !== "\\" - ? c - : ""; - }) - .join(""); - }; - }; - var createDateParser = function (_a) { - var _b = _a.config, config = _b === void 0 ? defaults : _b, _c = _a.l10n, l10n = _c === void 0 ? english : _c; - return function (date, givenFormat, timeless, customLocale) { - if (date !== 0 && !date) - return undefined; - var locale = customLocale || l10n; - var parsedDate; - var dateOrig = date; - if (date instanceof Date) - parsedDate = new Date(date.getTime()); - else if (typeof date !== "string" && - date.toFixed !== undefined // timestamp - ) - // create a copy - parsedDate = new Date(date); - else if (typeof date === "string") { - // date string - var format = givenFormat || (config || defaults).dateFormat; - var datestr = String(date).trim(); - if (datestr === "today") { - parsedDate = new Date(); - timeless = true; - } - else if (/Z$/.test(datestr) || - /GMT$/.test(datestr) // datestrings w/ timezone - ) - parsedDate = new Date(date); - else if (config && config.parseDate) - parsedDate = config.parseDate(date, format); - else { - parsedDate = - !config || !config.noCalendar - ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0) - : new Date(new Date().setHours(0, 0, 0, 0)); - var matched = void 0, ops = []; - for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) { - var token_1 = format[i]; - var isBackSlash = token_1 === "\\"; - var escaped = format[i - 1] === "\\" || isBackSlash; - if (tokenRegex[token_1] && !escaped) { - regexStr += tokenRegex[token_1]; - var match = new RegExp(regexStr).exec(date); - if (match && (matched = true)) { - ops[token_1 !== "Y" ? "push" : "unshift"]({ - fn: revFormat[token_1], - val: match[++matchIndex] - }); - } - } - else if (!isBackSlash) - regexStr += "."; // don't really care - ops.forEach(function (_a) { - var fn = _a.fn, val = _a.val; - return (parsedDate = fn(parsedDate, val, locale) || parsedDate); - }); - } - parsedDate = matched ? parsedDate : undefined; - } - } - /* istanbul ignore next */ - if (!(parsedDate instanceof Date && !isNaN(parsedDate.getTime()))) { - config.errorHandler(new Error("Invalid date provided: " + dateOrig)); - return undefined; - } - if (timeless === true) - parsedDate.setHours(0, 0, 0, 0); - return parsedDate; - }; - }; - /** - * Compute the difference in dates, measured in ms - */ - function compareDates(date1, date2, timeless) { - if (timeless === void 0) { timeless = true; } - if (timeless !== false) { - return (new Date(date1.getTime()).setHours(0, 0, 0, 0) - - new Date(date2.getTime()).setHours(0, 0, 0, 0)); - } - return date1.getTime() - date2.getTime(); - } - var isBetween = function (ts, ts1, ts2) { - return ts > Math.min(ts1, ts2) && ts < Math.max(ts1, ts2); - }; - var duration = { - DAY: 86400000 - }; - - if (typeof Object.assign !== "function") { - Object.assign = function (target) { - var args = []; - for (var _i = 1; _i < arguments.length; _i++) { - args[_i - 1] = arguments[_i]; - } - if (!target) { - throw TypeError("Cannot convert undefined or null to object"); - } - var _loop_1 = function (source) { - if (source) { - Object.keys(source).forEach(function (key) { return (target[key] = source[key]); }); - } - }; - for (var _a = 0, args_1 = args; _a < args_1.length; _a++) { - var source = args_1[_a]; - _loop_1(source); - } - return target; - }; - } - - var DEBOUNCED_CHANGE_MS = 300; - function FlatpickrInstance(element, instanceConfig) { - var self = { - config: __assign({}, defaults, flatpickr.defaultConfig), - l10n: english - }; - self.parseDate = createDateParser({ config: self.config, l10n: self.l10n }); - self._handlers = []; - self.pluginElements = []; - self.loadedPlugins = []; - self._bind = bind; - self._setHoursFromDate = setHoursFromDate; - self._positionCalendar = positionCalendar; - self.changeMonth = changeMonth; - self.changeYear = changeYear; - self.clear = clear; - self.close = close; - self._createElement = createElement; - self.destroy = destroy; - self.isEnabled = isEnabled; - self.jumpToDate = jumpToDate; - self.open = open; - self.redraw = redraw; - self.set = set; - self.setDate = setDate; - self.toggle = toggle; - function setupHelperFunctions() { - self.utils = { - getDaysInMonth: function (month, yr) { - if (month === void 0) { month = self.currentMonth; } - if (yr === void 0) { yr = self.currentYear; } - if (month === 1 && ((yr % 4 === 0 && yr % 100 !== 0) || yr % 400 === 0)) - return 29; - return self.l10n.daysInMonth[month]; - } - }; - } - function init() { - self.element = self.input = element; - self.isOpen = false; - parseConfig(); - setupLocale(); - setupInputs(); - setupDates(); - setupHelperFunctions(); - if (!self.isMobile) - build(); - bindEvents(); - if (self.selectedDates.length || self.config.noCalendar) { - if (self.config.enableTime) { - setHoursFromDate(self.config.noCalendar - ? self.latestSelectedDateObj || self.config.minDate - : undefined); - } - updateValue(false); - } - setCalendarWidth(); - self.showTimeInput = - self.selectedDates.length > 0 || self.config.noCalendar; - var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); - /* TODO: investigate this further - - Currently, there is weird positioning behavior in safari causing pages - to scroll up. https://github.com/chmln/flatpickr/issues/563 - - However, most browsers are not Safari and positioning is expensive when used - in scale. https://github.com/chmln/flatpickr/issues/1096 - */ - if (!self.isMobile && isSafari) { - positionCalendar(); - } - triggerEvent("onReady"); - } - function bindToInstance(fn) { - return fn.bind(self); - } - function setCalendarWidth() { - var config = self.config; - if (config.weekNumbers === false && config.showMonths === 1) - return; - else if (config.noCalendar !== true) { - window.requestAnimationFrame(function () { - if (self.calendarContainer !== undefined) { - self.calendarContainer.style.visibility = "hidden"; - self.calendarContainer.style.display = "block"; - } - if (self.daysContainer !== undefined) { - var daysWidth = (self.days.offsetWidth + 1) * config.showMonths; - self.daysContainer.style.width = daysWidth + "px"; - self.calendarContainer.style.width = - daysWidth + - (self.weekWrapper !== undefined - ? self.weekWrapper.offsetWidth - : 0) + - "px"; - self.calendarContainer.style.removeProperty("visibility"); - self.calendarContainer.style.removeProperty("display"); - } - }); - } - } - /** - * The handler for all events targeting the time inputs - */ - function updateTime(e) { - if (self.selectedDates.length === 0) { - setDefaultTime(); - } - if (e !== undefined && e.type !== "blur") { - timeWrapper(e); - } - var prevValue = self._input.value; - setHoursFromInputs(); - updateValue(); - if (self._input.value !== prevValue) { - self._debouncedChange(); - } - } - function ampm2military(hour, amPM) { - return (hour % 12) + 12 * int(amPM === self.l10n.amPM[1]); - } - function military2ampm(hour) { - switch (hour % 24) { - case 0: - case 12: - return 12; - default: - return hour % 12; - } - } - /** - * Syncs the selected date object time with user's time input - */ - function setHoursFromInputs() { - if (self.hourElement === undefined || self.minuteElement === undefined) - return; - var hours = (parseInt(self.hourElement.value.slice(-2), 10) || 0) % 24, minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60, seconds = self.secondElement !== undefined - ? (parseInt(self.secondElement.value, 10) || 0) % 60 - : 0; - if (self.amPM !== undefined) { - hours = ampm2military(hours, self.amPM.textContent); - } - var limitMinHours = self.config.minTime !== undefined || - (self.config.minDate && - self.minDateHasTime && - self.latestSelectedDateObj && - compareDates(self.latestSelectedDateObj, self.config.minDate, true) === - 0); - var limitMaxHours = self.config.maxTime !== undefined || - (self.config.maxDate && - self.maxDateHasTime && - self.latestSelectedDateObj && - compareDates(self.latestSelectedDateObj, self.config.maxDate, true) === - 0); - if (limitMaxHours) { - var maxTime = self.config.maxTime !== undefined - ? self.config.maxTime - : self.config.maxDate; - hours = Math.min(hours, maxTime.getHours()); - if (hours === maxTime.getHours()) - minutes = Math.min(minutes, maxTime.getMinutes()); - if (minutes === maxTime.getMinutes()) - seconds = Math.min(seconds, maxTime.getSeconds()); - } - if (limitMinHours) { - var minTime = self.config.minTime !== undefined - ? self.config.minTime - : self.config.minDate; - hours = Math.max(hours, minTime.getHours()); - if (hours === minTime.getHours()) - minutes = Math.max(minutes, minTime.getMinutes()); - if (minutes === minTime.getMinutes()) - seconds = Math.max(seconds, minTime.getSeconds()); - } - setHours(hours, minutes, seconds); - } - /** - * Syncs time input values with a date - */ - function setHoursFromDate(dateObj) { - var date = dateObj || self.latestSelectedDateObj; - if (date) - setHours(date.getHours(), date.getMinutes(), date.getSeconds()); - } - function setDefaultHours() { - var hours = self.config.defaultHour; - var minutes = self.config.defaultMinute; - var seconds = self.config.defaultSeconds; - if (self.config.minDate !== undefined) { - var minHr = self.config.minDate.getHours(); - var minMinutes = self.config.minDate.getMinutes(); - hours = Math.max(hours, minHr); - if (hours === minHr) - minutes = Math.max(minMinutes, minutes); - if (hours === minHr && minutes === minMinutes) - seconds = self.config.minDate.getSeconds(); - } - if (self.config.maxDate !== undefined) { - var maxHr = self.config.maxDate.getHours(); - var maxMinutes = self.config.maxDate.getMinutes(); - hours = Math.min(hours, maxHr); - if (hours === maxHr) - minutes = Math.min(maxMinutes, minutes); - if (hours === maxHr && minutes === maxMinutes) - seconds = self.config.maxDate.getSeconds(); - } - setHours(hours, minutes, seconds); - } - /** - * Sets the hours, minutes, and optionally seconds - * of the latest selected date object and the - * corresponding time inputs - * @param {Number} hours the hour. whether its military - * or am-pm gets inferred from config - * @param {Number} minutes the minutes - * @param {Number} seconds the seconds (optional) - */ - function setHours(hours, minutes, seconds) { - if (self.latestSelectedDateObj !== undefined) { - self.latestSelectedDateObj.setHours(hours % 24, minutes, seconds || 0, 0); - } - if (!self.hourElement || !self.minuteElement || self.isMobile) - return; - self.hourElement.value = pad(!self.config.time_24hr - ? ((12 + hours) % 12) + 12 * int(hours % 12 === 0) - : hours); - self.minuteElement.value = pad(minutes); - if (self.amPM !== undefined) - self.amPM.textContent = self.l10n.amPM[int(hours >= 12)]; - if (self.secondElement !== undefined) - self.secondElement.value = pad(seconds); - } - /** - * Handles the year input and incrementing events - * @param {Event} event the keyup or increment event - */ - function onYearInput(event) { - var year = parseInt(event.target.value) + (event.delta || 0); - if (year / 1000 > 1 || - (event.key === "Enter" && !/[^\d]/.test(year.toString()))) { - changeYear(year); - } - } - /** - * Essentially addEventListener + tracking - * @param {Element} element the element to addEventListener to - * @param {String} event the event name - * @param {Function} handler the event handler - */ - function bind(element, event, handler, options) { - if (event instanceof Array) - return event.forEach(function (ev) { return bind(element, ev, handler, options); }); - if (element instanceof Array) - return element.forEach(function (el) { return bind(el, event, handler, options); }); - element.addEventListener(event, handler, options); - self._handlers.push({ - element: element, - event: event, - handler: handler, - options: options - }); - } - /** - * A mousedown handler which mimics click. - * Minimizes latency, since we don't need to wait for mouseup in most cases. - * Also, avoids handling right clicks. - * - * @param {Function} handler the event handler - */ - function onClick(handler) { - return function (evt) { - evt.which === 1 && handler(evt); - }; - } - function triggerChange() { - triggerEvent("onChange"); - } - /** - * Adds all the necessary event listeners - */ - function bindEvents() { - if (self.config.wrap) { - ["open", "close", "toggle", "clear"].forEach(function (evt) { - Array.prototype.forEach.call(self.element.querySelectorAll("[data-" + evt + "]"), function (el) { - return bind(el, "click", self[evt]); - }); - }); - } - if (self.isMobile) { - setupMobile(); - return; - } - var debouncedResize = debounce(onResize, 50); - self._debouncedChange = debounce(triggerChange, DEBOUNCED_CHANGE_MS); - if (self.daysContainer && !/iPhone|iPad|iPod/i.test(navigator.userAgent)) - bind(self.daysContainer, "mouseover", function (e) { - if (self.config.mode === "range") - onMouseOver(e.target); - }); - bind(window.document.body, "keydown", onKeyDown); - if (!self.config.inline && !self.config.static) - bind(window, "resize", debouncedResize); - if (window.ontouchstart !== undefined) - bind(window.document, "touchstart", documentClick); - else - bind(window.document, "mousedown", onClick(documentClick)); - bind(window.document, "focus", documentClick, { capture: true }); - if (self.config.clickOpens === true) { - bind(self._input, "focus", self.open); - bind(self._input, "mousedown", onClick(self.open)); - } - if (self.daysContainer !== undefined) { - bind(self.monthNav, "mousedown", onClick(onMonthNavClick)); - bind(self.monthNav, ["keyup", "increment"], onYearInput); - bind(self.daysContainer, "mousedown", onClick(selectDate)); - } - if (self.timeContainer !== undefined && - self.minuteElement !== undefined && - self.hourElement !== undefined) { - var selText = function (e) { - return e.target.select(); - }; - bind(self.timeContainer, ["increment"], updateTime); - bind(self.timeContainer, "blur", updateTime, { capture: true }); - bind(self.timeContainer, "mousedown", onClick(timeIncrement)); - bind([self.hourElement, self.minuteElement], ["focus", "click"], selText); - if (self.secondElement !== undefined) - bind(self.secondElement, "focus", function () { return self.secondElement && self.secondElement.select(); }); - if (self.amPM !== undefined) { - bind(self.amPM, "mousedown", onClick(function (e) { - updateTime(e); - triggerChange(); - })); - } - } - } - /** - * Set the calendar view to a particular date. - * @param {Date} jumpDate the date to set the view to - * @param {boolean} triggerChange if change events should be triggered - */ - function jumpToDate(jumpDate, triggerChange) { - var jumpTo = jumpDate !== undefined - ? self.parseDate(jumpDate) - : self.latestSelectedDateObj || - (self.config.minDate && self.config.minDate > self.now - ? self.config.minDate - : self.config.maxDate && self.config.maxDate < self.now - ? self.config.maxDate - : self.now); - var oldYear = self.currentYear; - var oldMonth = self.currentMonth; - try { - if (jumpTo !== undefined) { - self.currentYear = jumpTo.getFullYear(); - self.currentMonth = jumpTo.getMonth(); - } - } - catch (e) { - /* istanbul ignore next */ - e.message = "Invalid date supplied: " + jumpTo; - self.config.errorHandler(e); - } - if (triggerChange && self.currentYear !== oldYear) { - triggerEvent("onYearChange"); - buildMonthSwitch(); - } - if (triggerChange && - (self.currentYear !== oldYear || self.currentMonth !== oldMonth)) { - triggerEvent("onMonthChange"); - } - self.redraw(); - } - /** - * The up/down arrow handler for time inputs - * @param {Event} e the click event - */ - function timeIncrement(e) { - if (~e.target.className.indexOf("arrow")) - incrementNumInput(e, e.target.classList.contains("arrowUp") ? 1 : -1); - } - /** - * Increments/decrements the value of input associ- - * ated with the up/down arrow by dispatching an - * "increment" event on the input. - * - * @param {Event} e the click event - * @param {Number} delta the diff (usually 1 or -1) - * @param {Element} inputElem the input element - */ - function incrementNumInput(e, delta, inputElem) { - var target = e && e.target; - var input = inputElem || - (target && target.parentNode && target.parentNode.firstChild); - var event = createEvent("increment"); - event.delta = delta; - input && input.dispatchEvent(event); - } - function build() { - var fragment = window.document.createDocumentFragment(); - self.calendarContainer = createElement("div", "flatpickr-calendar"); - self.calendarContainer.tabIndex = -1; - if (!self.config.noCalendar) { - fragment.appendChild(buildMonthNav()); - self.innerContainer = createElement("div", "flatpickr-innerContainer"); - if (self.config.weekNumbers) { - var _a = buildWeeks(), weekWrapper = _a.weekWrapper, weekNumbers = _a.weekNumbers; - self.innerContainer.appendChild(weekWrapper); - self.weekNumbers = weekNumbers; - self.weekWrapper = weekWrapper; - } - self.rContainer = createElement("div", "flatpickr-rContainer"); - self.rContainer.appendChild(buildWeekdays()); - if (!self.daysContainer) { - self.daysContainer = createElement("div", "flatpickr-days"); - self.daysContainer.tabIndex = -1; - } - buildDays(); - self.rContainer.appendChild(self.daysContainer); - self.innerContainer.appendChild(self.rContainer); - fragment.appendChild(self.innerContainer); - } - if (self.config.enableTime) { - fragment.appendChild(buildTime()); - } - toggleClass(self.calendarContainer, "rangeMode", self.config.mode === "range"); - toggleClass(self.calendarContainer, "animate", self.config.animate === true); - toggleClass(self.calendarContainer, "multiMonth", self.config.showMonths > 1); - self.calendarContainer.appendChild(fragment); - var customAppend = self.config.appendTo !== undefined && - self.config.appendTo.nodeType !== undefined; - if (self.config.inline || self.config.static) { - self.calendarContainer.classList.add(self.config.inline ? "inline" : "static"); - if (self.config.inline) { - if (!customAppend && self.element.parentNode) - self.element.parentNode.insertBefore(self.calendarContainer, self._input.nextSibling); - else if (self.config.appendTo !== undefined) - self.config.appendTo.appendChild(self.calendarContainer); - } - if (self.config.static) { - var wrapper = createElement("div", "flatpickr-wrapper"); - if (self.element.parentNode) - self.element.parentNode.insertBefore(wrapper, self.element); - wrapper.appendChild(self.element); - if (self.altInput) - wrapper.appendChild(self.altInput); - wrapper.appendChild(self.calendarContainer); - } - } - if (!self.config.static && !self.config.inline) - (self.config.appendTo !== undefined - ? self.config.appendTo - : window.document.body).appendChild(self.calendarContainer); - } - function createDay(className, date, dayNumber, i) { - var dateIsEnabled = isEnabled(date, true), dayElement = createElement("span", "flatpickr-day " + className, date.getDate().toString()); - dayElement.dateObj = date; - dayElement.$i = i; - dayElement.setAttribute("aria-label", self.formatDate(date, self.config.ariaDateFormat)); - if (className.indexOf("hidden") === -1 && - compareDates(date, self.now) === 0) { - self.todayDateElem = dayElement; - dayElement.classList.add("today"); - dayElement.setAttribute("aria-current", "date"); - } - if (dateIsEnabled) { - dayElement.tabIndex = -1; - if (isDateSelected(date)) { - dayElement.classList.add("selected"); - self.selectedDateElem = dayElement; - if (self.config.mode === "range") { - toggleClass(dayElement, "startRange", self.selectedDates[0] && - compareDates(date, self.selectedDates[0], true) === 0); - toggleClass(dayElement, "endRange", self.selectedDates[1] && - compareDates(date, self.selectedDates[1], true) === 0); - if (className === "nextMonthDay") - dayElement.classList.add("inRange"); - } - } - } - else { - dayElement.classList.add("flatpickr-disabled"); - } - if (self.config.mode === "range") { - if (isDateInRange(date) && !isDateSelected(date)) - dayElement.classList.add("inRange"); - } - if (self.weekNumbers && - self.config.showMonths === 1 && - className !== "prevMonthDay" && - dayNumber % 7 === 1) { - self.weekNumbers.insertAdjacentHTML("beforeend", "" + self.config.getWeek(date) + ""); - } - triggerEvent("onDayCreate", dayElement); - return dayElement; - } - function focusOnDayElem(targetNode) { - targetNode.focus(); - if (self.config.mode === "range") - onMouseOver(targetNode); - } - function getFirstAvailableDay(delta) { - var startMonth = delta > 0 ? 0 : self.config.showMonths - 1; - var endMonth = delta > 0 ? self.config.showMonths : -1; - for (var m = startMonth; m != endMonth; m += delta) { - var month = self.daysContainer.children[m]; - var startIndex = delta > 0 ? 0 : month.children.length - 1; - var endIndex = delta > 0 ? month.children.length : -1; - for (var i = startIndex; i != endIndex; i += delta) { - var c = month.children[i]; - if (c.className.indexOf("hidden") === -1 && isEnabled(c.dateObj)) - return c; - } - } - return undefined; - } - function getNextAvailableDay(current, delta) { - var givenMonth = current.className.indexOf("Month") === -1 - ? current.dateObj.getMonth() - : self.currentMonth; - var endMonth = delta > 0 ? self.config.showMonths : -1; - var loopDelta = delta > 0 ? 1 : -1; - for (var m = givenMonth - self.currentMonth; m != endMonth; m += loopDelta) { - var month = self.daysContainer.children[m]; - var startIndex = givenMonth - self.currentMonth === m - ? current.$i + delta - : delta < 0 - ? month.children.length - 1 - : 0; - var numMonthDays = month.children.length; - for (var i = startIndex; i >= 0 && i < numMonthDays && i != (delta > 0 ? numMonthDays : -1); i += loopDelta) { - var c = month.children[i]; - if (c.className.indexOf("hidden") === -1 && - isEnabled(c.dateObj) && - Math.abs(current.$i - i) >= Math.abs(delta)) - return focusOnDayElem(c); - } - } - self.changeMonth(loopDelta); - focusOnDay(getFirstAvailableDay(loopDelta), 0); - return undefined; - } - function focusOnDay(current, offset) { - var dayFocused = isInView(document.activeElement || document.body); - var startElem = current !== undefined - ? current - : dayFocused - ? document.activeElement - : self.selectedDateElem !== undefined && isInView(self.selectedDateElem) - ? self.selectedDateElem - : self.todayDateElem !== undefined && isInView(self.todayDateElem) - ? self.todayDateElem - : getFirstAvailableDay(offset > 0 ? 1 : -1); - if (startElem === undefined) - return self._input.focus(); - if (!dayFocused) - return focusOnDayElem(startElem); - getNextAvailableDay(startElem, offset); - } - function buildMonthDays(year, month) { - var firstOfMonth = (new Date(year, month, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7; - var prevMonthDays = self.utils.getDaysInMonth((month - 1 + 12) % 12); - var daysInMonth = self.utils.getDaysInMonth(month), days = window.document.createDocumentFragment(), isMultiMonth = self.config.showMonths > 1, prevMonthDayClass = isMultiMonth ? "prevMonthDay hidden" : "prevMonthDay", nextMonthDayClass = isMultiMonth ? "nextMonthDay hidden" : "nextMonthDay"; - var dayNumber = prevMonthDays + 1 - firstOfMonth, dayIndex = 0; - // prepend days from the ending of previous month - for (; dayNumber <= prevMonthDays; dayNumber++, dayIndex++) { - days.appendChild(createDay(prevMonthDayClass, new Date(year, month - 1, dayNumber), dayNumber, dayIndex)); - } - // Start at 1 since there is no 0th day - for (dayNumber = 1; dayNumber <= daysInMonth; dayNumber++, dayIndex++) { - days.appendChild(createDay("", new Date(year, month, dayNumber), dayNumber, dayIndex)); - } - // append days from the next month - for (var dayNum = daysInMonth + 1; dayNum <= 42 - firstOfMonth && - (self.config.showMonths === 1 || dayIndex % 7 !== 0); dayNum++, dayIndex++) { - days.appendChild(createDay(nextMonthDayClass, new Date(year, month + 1, dayNum % daysInMonth), dayNum, dayIndex)); - } - //updateNavigationCurrentMonth(); - var dayContainer = createElement("div", "dayContainer"); - dayContainer.appendChild(days); - return dayContainer; - } - function buildDays() { - if (self.daysContainer === undefined) { - return; - } - clearNode(self.daysContainer); - // TODO: week numbers for each month - if (self.weekNumbers) - clearNode(self.weekNumbers); - var frag = document.createDocumentFragment(); - for (var i = 0; i < self.config.showMonths; i++) { - var d = new Date(self.currentYear, self.currentMonth, 1); - d.setMonth(self.currentMonth + i); - frag.appendChild(buildMonthDays(d.getFullYear(), d.getMonth())); - } - self.daysContainer.appendChild(frag); - self.days = self.daysContainer.firstChild; - if (self.config.mode === "range" && self.selectedDates.length === 1) { - onMouseOver(); - } - } - function buildMonthSwitch() { - if (self.config.showMonths > 1 || - self.config.monthSelectorType !== "dropdown") - return; - var shouldBuildMonth = function (month) { - if (self.config.minDate !== undefined && - self.currentYear === self.config.minDate.getFullYear() && - month < self.config.minDate.getMonth()) { - return false; - } - return !(self.config.maxDate !== undefined && - self.currentYear === self.config.maxDate.getFullYear() && - month > self.config.maxDate.getMonth()); - }; - self.monthsDropdownContainer.tabIndex = -1; - self.monthsDropdownContainer.innerHTML = ""; - for (var i = 0; i < 12; i++) { - if (!shouldBuildMonth(i)) - continue; - var month = createElement("option", "flatpickr-monthDropdown-month"); - month.value = new Date(self.currentYear, i).getMonth().toString(); - month.textContent = monthToStr(i, self.config.shorthandCurrentMonth, self.l10n); - month.tabIndex = -1; - if (self.currentMonth === i) { - month.selected = true; - } - self.monthsDropdownContainer.appendChild(month); - } - } - function buildMonth() { - var container = createElement("div", "flatpickr-month"); - var monthNavFragment = window.document.createDocumentFragment(); - var monthElement; - if (self.config.showMonths > 1 || - self.config.monthSelectorType === "static") { - monthElement = createElement("span", "cur-month"); - } - else { - self.monthsDropdownContainer = createElement("select", "flatpickr-monthDropdown-months"); - bind(self.monthsDropdownContainer, "change", function (e) { - var target = e.target; - var selectedMonth = parseInt(target.value, 10); - self.changeMonth(selectedMonth - self.currentMonth); - triggerEvent("onMonthChange"); - }); - buildMonthSwitch(); - monthElement = self.monthsDropdownContainer; - } - var yearInput = createNumberInput("cur-year", { tabindex: "-1" }); - var yearElement = yearInput.getElementsByTagName("input")[0]; - yearElement.setAttribute("aria-label", self.l10n.yearAriaLabel); - if (self.config.minDate) { - yearElement.setAttribute("min", self.config.minDate.getFullYear().toString()); - } - if (self.config.maxDate) { - yearElement.setAttribute("max", self.config.maxDate.getFullYear().toString()); - yearElement.disabled = - !!self.config.minDate && - self.config.minDate.getFullYear() === self.config.maxDate.getFullYear(); - } - var currentMonth = createElement("div", "flatpickr-current-month"); - currentMonth.appendChild(monthElement); - currentMonth.appendChild(yearInput); - monthNavFragment.appendChild(currentMonth); - container.appendChild(monthNavFragment); - return { - container: container, - yearElement: yearElement, - monthElement: monthElement - }; - } - function buildMonths() { - clearNode(self.monthNav); - self.monthNav.appendChild(self.prevMonthNav); - if (self.config.showMonths) { - self.yearElements = []; - self.monthElements = []; - } - for (var m = self.config.showMonths; m--;) { - var month = buildMonth(); - self.yearElements.push(month.yearElement); - self.monthElements.push(month.monthElement); - self.monthNav.appendChild(month.container); - } - self.monthNav.appendChild(self.nextMonthNav); - } - function buildMonthNav() { - self.monthNav = createElement("div", "flatpickr-months"); - self.yearElements = []; - self.monthElements = []; - self.prevMonthNav = createElement("span", "flatpickr-prev-month"); - self.prevMonthNav.innerHTML = self.config.prevArrow; - self.nextMonthNav = createElement("span", "flatpickr-next-month"); - self.nextMonthNav.innerHTML = self.config.nextArrow; - buildMonths(); - Object.defineProperty(self, "_hidePrevMonthArrow", { - get: function () { return self.__hidePrevMonthArrow; }, - set: function (bool) { - if (self.__hidePrevMonthArrow !== bool) { - toggleClass(self.prevMonthNav, "flatpickr-disabled", bool); - self.__hidePrevMonthArrow = bool; - } - } - }); - Object.defineProperty(self, "_hideNextMonthArrow", { - get: function () { return self.__hideNextMonthArrow; }, - set: function (bool) { - if (self.__hideNextMonthArrow !== bool) { - toggleClass(self.nextMonthNav, "flatpickr-disabled", bool); - self.__hideNextMonthArrow = bool; - } - } - }); - self.currentYearElement = self.yearElements[0]; - updateNavigationCurrentMonth(); - return self.monthNav; - } - function buildTime() { - self.calendarContainer.classList.add("hasTime"); - if (self.config.noCalendar) - self.calendarContainer.classList.add("noCalendar"); - self.timeContainer = createElement("div", "flatpickr-time"); - self.timeContainer.tabIndex = -1; - var separator = createElement("span", "flatpickr-time-separator", ":"); - var hourInput = createNumberInput("flatpickr-hour", { - "aria-label": self.l10n.hourAriaLabel - }); - self.hourElement = hourInput.getElementsByTagName("input")[0]; - var minuteInput = createNumberInput("flatpickr-minute", { - "aria-label": self.l10n.minuteAriaLabel - }); - self.minuteElement = minuteInput.getElementsByTagName("input")[0]; - self.hourElement.tabIndex = self.minuteElement.tabIndex = -1; - self.hourElement.value = pad(self.latestSelectedDateObj - ? self.latestSelectedDateObj.getHours() - : self.config.time_24hr - ? self.config.defaultHour - : military2ampm(self.config.defaultHour)); - self.minuteElement.value = pad(self.latestSelectedDateObj - ? self.latestSelectedDateObj.getMinutes() - : self.config.defaultMinute); - self.hourElement.setAttribute("step", self.config.hourIncrement.toString()); - self.minuteElement.setAttribute("step", self.config.minuteIncrement.toString()); - self.hourElement.setAttribute("min", self.config.time_24hr ? "0" : "1"); - self.hourElement.setAttribute("max", self.config.time_24hr ? "23" : "12"); - self.minuteElement.setAttribute("min", "0"); - self.minuteElement.setAttribute("max", "59"); - self.timeContainer.appendChild(hourInput); - self.timeContainer.appendChild(separator); - self.timeContainer.appendChild(minuteInput); - if (self.config.time_24hr) - self.timeContainer.classList.add("time24hr"); - if (self.config.enableSeconds) { - self.timeContainer.classList.add("hasSeconds"); - var secondInput = createNumberInput("flatpickr-second"); - self.secondElement = secondInput.getElementsByTagName("input")[0]; - self.secondElement.value = pad(self.latestSelectedDateObj - ? self.latestSelectedDateObj.getSeconds() - : self.config.defaultSeconds); - self.secondElement.setAttribute("step", self.minuteElement.getAttribute("step")); - self.secondElement.setAttribute("min", "0"); - self.secondElement.setAttribute("max", "59"); - self.timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":")); - self.timeContainer.appendChild(secondInput); - } - if (!self.config.time_24hr) { - // add self.amPM if appropriate - self.amPM = createElement("span", "flatpickr-am-pm", self.l10n.amPM[int((self.latestSelectedDateObj - ? self.hourElement.value - : self.config.defaultHour) > 11)]); - self.amPM.title = self.l10n.toggleTitle; - self.amPM.tabIndex = -1; - self.timeContainer.appendChild(self.amPM); - } - return self.timeContainer; - } - function buildWeekdays() { - if (!self.weekdayContainer) - self.weekdayContainer = createElement("div", "flatpickr-weekdays"); - else - clearNode(self.weekdayContainer); - for (var i = self.config.showMonths; i--;) { - var container = createElement("div", "flatpickr-weekdaycontainer"); - self.weekdayContainer.appendChild(container); - } - updateWeekdays(); - return self.weekdayContainer; - } - function updateWeekdays() { - if (!self.weekdayContainer) { - return; - } - var firstDayOfWeek = self.l10n.firstDayOfWeek; - var weekdays = self.l10n.weekdays.shorthand.slice(); - if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) { - weekdays = weekdays.splice(firstDayOfWeek, weekdays.length).concat(weekdays.splice(0, firstDayOfWeek)); - } - for (var i = self.config.showMonths; i--;) { - self.weekdayContainer.children[i].innerHTML = "\n \n " + weekdays.join("") + "\n \n "; - } - } - /* istanbul ignore next */ - function buildWeeks() { - self.calendarContainer.classList.add("hasWeeks"); - var weekWrapper = createElement("div", "flatpickr-weekwrapper"); - weekWrapper.appendChild(createElement("span", "flatpickr-weekday", self.l10n.weekAbbreviation)); - var weekNumbers = createElement("div", "flatpickr-weeks"); - weekWrapper.appendChild(weekNumbers); - return { - weekWrapper: weekWrapper, - weekNumbers: weekNumbers - }; - } - function changeMonth(value, isOffset) { - if (isOffset === void 0) { isOffset = true; } - var delta = isOffset ? value : value - self.currentMonth; - if ((delta < 0 && self._hidePrevMonthArrow === true) || - (delta > 0 && self._hideNextMonthArrow === true)) - return; - self.currentMonth += delta; - if (self.currentMonth < 0 || self.currentMonth > 11) { - self.currentYear += self.currentMonth > 11 ? 1 : -1; - self.currentMonth = (self.currentMonth + 12) % 12; - triggerEvent("onYearChange"); - buildMonthSwitch(); - } - buildDays(); - triggerEvent("onMonthChange"); - updateNavigationCurrentMonth(); - } - function clear(triggerChangeEvent, toInitial) { - if (triggerChangeEvent === void 0) { triggerChangeEvent = true; } - if (toInitial === void 0) { toInitial = true; } - self.input.value = ""; - if (self.altInput !== undefined) - self.altInput.value = ""; - if (self.mobileInput !== undefined) - self.mobileInput.value = ""; - self.selectedDates = []; - self.latestSelectedDateObj = undefined; - if (toInitial === true) { - self.currentYear = self._initialDate.getFullYear(); - self.currentMonth = self._initialDate.getMonth(); - } - self.showTimeInput = false; - if (self.config.enableTime === true) { - setDefaultHours(); - } - self.redraw(); - if (triggerChangeEvent) - // triggerChangeEvent is true (default) or an Event - triggerEvent("onChange"); - } - function close() { - self.isOpen = false; - if (!self.isMobile) { - if (self.calendarContainer !== undefined) { - self.calendarContainer.classList.remove("open"); - } - if (self._input !== undefined) { - self._input.classList.remove("active"); - } - } - triggerEvent("onClose"); - } - function destroy() { - if (self.config !== undefined) - triggerEvent("onDestroy"); - for (var i = self._handlers.length; i--;) { - var h = self._handlers[i]; - h.element.removeEventListener(h.event, h.handler, h.options); - } - self._handlers = []; - if (self.mobileInput) { - if (self.mobileInput.parentNode) - self.mobileInput.parentNode.removeChild(self.mobileInput); - self.mobileInput = undefined; - } - else if (self.calendarContainer && self.calendarContainer.parentNode) { - if (self.config.static && self.calendarContainer.parentNode) { - var wrapper = self.calendarContainer.parentNode; - wrapper.lastChild && wrapper.removeChild(wrapper.lastChild); - if (wrapper.parentNode) { - while (wrapper.firstChild) - wrapper.parentNode.insertBefore(wrapper.firstChild, wrapper); - wrapper.parentNode.removeChild(wrapper); - } - } - else - self.calendarContainer.parentNode.removeChild(self.calendarContainer); - } - if (self.altInput) { - self.input.type = "text"; - if (self.altInput.parentNode) - self.altInput.parentNode.removeChild(self.altInput); - delete self.altInput; - } - if (self.input) { - self.input.type = self.input._type; - self.input.classList.remove("flatpickr-input"); - self.input.removeAttribute("readonly"); - self.input.value = ""; - } - [ - "_showTimeInput", - "latestSelectedDateObj", - "_hideNextMonthArrow", - "_hidePrevMonthArrow", - "__hideNextMonthArrow", - "__hidePrevMonthArrow", - "isMobile", - "isOpen", - "selectedDateElem", - "minDateHasTime", - "maxDateHasTime", - "days", - "daysContainer", - "_input", - "_positionElement", - "innerContainer", - "rContainer", - "monthNav", - "todayDateElem", - "calendarContainer", - "weekdayContainer", - "prevMonthNav", - "nextMonthNav", - "monthsDropdownContainer", - "currentMonthElement", - "currentYearElement", - "navigationCurrentMonth", - "selectedDateElem", - "config", - ].forEach(function (k) { - try { - delete self[k]; - } - catch (_) { } - }); - } - function isCalendarElem(elem) { - if (self.config.appendTo && self.config.appendTo.contains(elem)) - return true; - return self.calendarContainer.contains(elem); - } - function documentClick(e) { - if (self.isOpen && !self.config.inline) { - var eventTarget_1 = getEventTarget(e); - var isCalendarElement = isCalendarElem(eventTarget_1); - var isInput = eventTarget_1 === self.input || - eventTarget_1 === self.altInput || - self.element.contains(eventTarget_1) || - // web components - // e.path is not present in all browsers. circumventing typechecks - (e.path && - e.path.indexOf && - (~e.path.indexOf(self.input) || - ~e.path.indexOf(self.altInput))); - var lostFocus = e.type === "blur" - ? isInput && - e.relatedTarget && - !isCalendarElem(e.relatedTarget) - : !isInput && - !isCalendarElement && - !isCalendarElem(e.relatedTarget); - var isIgnored = !self.config.ignoredFocusElements.some(function (elem) { - return elem.contains(eventTarget_1); - }); - if (lostFocus && isIgnored) { - if (self.timeContainer !== undefined && - self.minuteElement !== undefined && - self.hourElement !== undefined) { - updateTime(); - } - self.close(); - if (self.config.mode === "range" && self.selectedDates.length === 1) { - self.clear(false); - self.redraw(); - } - } - } - } - function changeYear(newYear) { - if (!newYear || - (self.config.minDate && newYear < self.config.minDate.getFullYear()) || - (self.config.maxDate && newYear > self.config.maxDate.getFullYear())) - return; - var newYearNum = newYear, isNewYear = self.currentYear !== newYearNum; - self.currentYear = newYearNum || self.currentYear; - if (self.config.maxDate && - self.currentYear === self.config.maxDate.getFullYear()) { - self.currentMonth = Math.min(self.config.maxDate.getMonth(), self.currentMonth); - } - else if (self.config.minDate && - self.currentYear === self.config.minDate.getFullYear()) { - self.currentMonth = Math.max(self.config.minDate.getMonth(), self.currentMonth); - } - if (isNewYear) { - self.redraw(); - triggerEvent("onYearChange"); - buildMonthSwitch(); - } - } - function isEnabled(date, timeless) { - if (timeless === void 0) { timeless = true; } - var dateToCheck = self.parseDate(date, undefined, timeless); // timeless - if ((self.config.minDate && - dateToCheck && - compareDates(dateToCheck, self.config.minDate, timeless !== undefined ? timeless : !self.minDateHasTime) < 0) || - (self.config.maxDate && - dateToCheck && - compareDates(dateToCheck, self.config.maxDate, timeless !== undefined ? timeless : !self.maxDateHasTime) > 0)) - return false; - if (self.config.enable.length === 0 && self.config.disable.length === 0) - return true; - if (dateToCheck === undefined) - return false; - var bool = self.config.enable.length > 0, array = bool ? self.config.enable : self.config.disable; - for (var i = 0, d = void 0; i < array.length; i++) { - d = array[i]; - if (typeof d === "function" && - d(dateToCheck) // disabled by function - ) - return bool; - else if (d instanceof Date && - dateToCheck !== undefined && - d.getTime() === dateToCheck.getTime()) - // disabled by date - return bool; - else if (typeof d === "string" && dateToCheck !== undefined) { - // disabled by date string - var parsed = self.parseDate(d, undefined, true); - return parsed && parsed.getTime() === dateToCheck.getTime() - ? bool - : !bool; - } - else if ( - // disabled by range - typeof d === "object" && - dateToCheck !== undefined && - d.from && - d.to && - dateToCheck.getTime() >= d.from.getTime() && - dateToCheck.getTime() <= d.to.getTime()) - return bool; - } - return !bool; - } - function isInView(elem) { - if (self.daysContainer !== undefined) - return (elem.className.indexOf("hidden") === -1 && - self.daysContainer.contains(elem)); - return false; - } - function onKeyDown(e) { - // e.key e.keyCode - // "Backspace" 8 - // "Tab" 9 - // "Enter" 13 - // "Escape" (IE "Esc") 27 - // "ArrowLeft" (IE "Left") 37 - // "ArrowUp" (IE "Up") 38 - // "ArrowRight" (IE "Right") 39 - // "ArrowDown" (IE "Down") 40 - // "Delete" (IE "Del") 46 - var isInput = e.target === self._input; - var allowInput = self.config.allowInput; - var allowKeydown = self.isOpen && (!allowInput || !isInput); - var allowInlineKeydown = self.config.inline && isInput && !allowInput; - if (e.keyCode === 13 && isInput) { - if (allowInput) { - self.setDate(self._input.value, true, e.target === self.altInput - ? self.config.altFormat - : self.config.dateFormat); - return e.target.blur(); - } - else { - self.open(); - } - } - else if (isCalendarElem(e.target) || - allowKeydown || - allowInlineKeydown) { - var isTimeObj = !!self.timeContainer && - self.timeContainer.contains(e.target); - switch (e.keyCode) { - case 13: - if (isTimeObj) { - e.preventDefault(); - updateTime(); - focusAndClose(); - } - else - selectDate(e); - break; - case 27: // escape - e.preventDefault(); - focusAndClose(); - break; - case 8: - case 46: - if (isInput && !self.config.allowInput) { - e.preventDefault(); - self.clear(); - } - break; - case 37: - case 39: - if (!isTimeObj && !isInput) { - e.preventDefault(); - if (self.daysContainer !== undefined && - (allowInput === false || - (document.activeElement && isInView(document.activeElement)))) { - var delta_1 = e.keyCode === 39 ? 1 : -1; - if (!e.ctrlKey) - focusOnDay(undefined, delta_1); - else { - e.stopPropagation(); - changeMonth(delta_1); - focusOnDay(getFirstAvailableDay(1), 0); - } - } - } - else if (self.hourElement) - self.hourElement.focus(); - break; - case 38: - case 40: - e.preventDefault(); - var delta = e.keyCode === 40 ? 1 : -1; - if ((self.daysContainer && e.target.$i !== undefined) || - e.target === self.input || - e.target === self.altInput) { - if (e.ctrlKey) { - e.stopPropagation(); - changeYear(self.currentYear - delta); - focusOnDay(getFirstAvailableDay(1), 0); - } - else if (!isTimeObj) - focusOnDay(undefined, delta * 7); - } - else if (e.target === self.currentYearElement) { - changeYear(self.currentYear - delta); - } - else if (self.config.enableTime) { - if (!isTimeObj && self.hourElement) - self.hourElement.focus(); - updateTime(e); - self._debouncedChange(); - } - break; - case 9: - if (isTimeObj) { - var elems = [ - self.hourElement, - self.minuteElement, - self.secondElement, - self.amPM, - ] - .concat(self.pluginElements) - .filter(function (x) { return x; }); - var i = elems.indexOf(e.target); - if (i !== -1) { - var target = elems[i + (e.shiftKey ? -1 : 1)]; - e.preventDefault(); - (target || self._input).focus(); - } - } - else if (!self.config.noCalendar && - self.daysContainer && - self.daysContainer.contains(e.target) && - e.shiftKey) { - e.preventDefault(); - self._input.focus(); - } - break; - default: - break; - } - } - if (self.amPM !== undefined && e.target === self.amPM) { - switch (e.key) { - case self.l10n.amPM[0].charAt(0): - case self.l10n.amPM[0].charAt(0).toLowerCase(): - self.amPM.textContent = self.l10n.amPM[0]; - setHoursFromInputs(); - updateValue(); - break; - case self.l10n.amPM[1].charAt(0): - case self.l10n.amPM[1].charAt(0).toLowerCase(): - self.amPM.textContent = self.l10n.amPM[1]; - setHoursFromInputs(); - updateValue(); - break; - } - } - if (isInput || isCalendarElem(e.target)) { - triggerEvent("onKeyDown", e); - } - } - function onMouseOver(elem) { - if (self.selectedDates.length !== 1 || - (elem && - (!elem.classList.contains("flatpickr-day") || - elem.classList.contains("flatpickr-disabled")))) - return; - var hoverDate = elem - ? elem.dateObj.getTime() - : self.days.firstElementChild.dateObj.getTime(), initialDate = self.parseDate(self.selectedDates[0], undefined, true).getTime(), rangeStartDate = Math.min(hoverDate, self.selectedDates[0].getTime()), rangeEndDate = Math.max(hoverDate, self.selectedDates[0].getTime()); - var containsDisabled = false; - var minRange = 0, maxRange = 0; - for (var t = rangeStartDate; t < rangeEndDate; t += duration.DAY) { - if (!isEnabled(new Date(t), true)) { - containsDisabled = - containsDisabled || (t > rangeStartDate && t < rangeEndDate); - if (t < initialDate && (!minRange || t > minRange)) - minRange = t; - else if (t > initialDate && (!maxRange || t < maxRange)) - maxRange = t; - } - } - for (var m = 0; m < self.config.showMonths; m++) { - var month = self.daysContainer.children[m]; - var _loop_1 = function (i, l) { - var dayElem = month.children[i], date = dayElem.dateObj; - var timestamp = date.getTime(); - var outOfRange = (minRange > 0 && timestamp < minRange) || - (maxRange > 0 && timestamp > maxRange); - if (outOfRange) { - dayElem.classList.add("notAllowed"); - ["inRange", "startRange", "endRange"].forEach(function (c) { - dayElem.classList.remove(c); - }); - return "continue"; - } - else if (containsDisabled && !outOfRange) - return "continue"; - ["startRange", "inRange", "endRange", "notAllowed"].forEach(function (c) { - dayElem.classList.remove(c); - }); - if (elem !== undefined) { - elem.classList.add(hoverDate <= self.selectedDates[0].getTime() - ? "startRange" - : "endRange"); - if (initialDate < hoverDate && timestamp === initialDate) - dayElem.classList.add("startRange"); - else if (initialDate > hoverDate && timestamp === initialDate) - dayElem.classList.add("endRange"); - if (timestamp >= minRange && - (maxRange === 0 || timestamp <= maxRange) && - isBetween(timestamp, initialDate, hoverDate)) - dayElem.classList.add("inRange"); - } - }; - for (var i = 0, l = month.children.length; i < l; i++) { - _loop_1(i, l); - } - } - } - function onResize() { - if (self.isOpen && !self.config.static && !self.config.inline) - positionCalendar(); - } - function setDefaultTime() { - self.setDate(self.config.minDate !== undefined - ? new Date(self.config.minDate.getTime()) - : new Date(), true); - setDefaultHours(); - updateValue(); - } - function open(e, positionElement) { - if (positionElement === void 0) { positionElement = self._positionElement; } - if (self.isMobile === true) { - if (e) { - e.preventDefault(); - e.target && e.target.blur(); - } - if (self.mobileInput !== undefined) { - self.mobileInput.focus(); - self.mobileInput.click(); - } - triggerEvent("onOpen"); - return; - } - if (self._input.disabled || self.config.inline) - return; - var wasOpen = self.isOpen; - self.isOpen = true; - if (!wasOpen) { - self.calendarContainer.classList.add("open"); - self._input.classList.add("active"); - triggerEvent("onOpen"); - positionCalendar(positionElement); - } - if (self.config.enableTime === true && self.config.noCalendar === true) { - if (self.selectedDates.length === 0) { - setDefaultTime(); - } - if (self.config.allowInput === false && - (e === undefined || - !self.timeContainer.contains(e.relatedTarget))) { - setTimeout(function () { return self.hourElement.select(); }, 50); - } - } - } - function minMaxDateSetter(type) { - return function (date) { - var dateObj = (self.config["_" + type + "Date"] = self.parseDate(date, self.config.dateFormat)); - var inverseDateObj = self.config["_" + (type === "min" ? "max" : "min") + "Date"]; - if (dateObj !== undefined) { - self[type === "min" ? "minDateHasTime" : "maxDateHasTime"] = - dateObj.getHours() > 0 || - dateObj.getMinutes() > 0 || - dateObj.getSeconds() > 0; - } - if (self.selectedDates) { - self.selectedDates = self.selectedDates.filter(function (d) { return isEnabled(d); }); - if (!self.selectedDates.length && type === "min") - setHoursFromDate(dateObj); - updateValue(); - } - if (self.daysContainer) { - redraw(); - if (dateObj !== undefined) - self.currentYearElement[type] = dateObj.getFullYear().toString(); - else - self.currentYearElement.removeAttribute(type); - self.currentYearElement.disabled = - !!inverseDateObj && - dateObj !== undefined && - inverseDateObj.getFullYear() === dateObj.getFullYear(); - } - }; - } - function parseConfig() { - var boolOpts = [ - "wrap", - "weekNumbers", - "allowInput", - "clickOpens", - "time_24hr", - "enableTime", - "noCalendar", - "altInput", - "shorthandCurrentMonth", - "inline", - "static", - "enableSeconds", - "disableMobile", - ]; - var userConfig = __assign({}, instanceConfig, JSON.parse(JSON.stringify(element.dataset || {}))); - var formats = {}; - self.config.parseDate = userConfig.parseDate; - self.config.formatDate = userConfig.formatDate; - Object.defineProperty(self.config, "enable", { - get: function () { return self.config._enable; }, - set: function (dates) { - self.config._enable = parseDateRules(dates); - } - }); - Object.defineProperty(self.config, "disable", { - get: function () { return self.config._disable; }, - set: function (dates) { - self.config._disable = parseDateRules(dates); - } - }); - var timeMode = userConfig.mode === "time"; - if (!userConfig.dateFormat && (userConfig.enableTime || timeMode)) { - var defaultDateFormat = flatpickr.defaultConfig.dateFormat || defaults.dateFormat; - formats.dateFormat = - userConfig.noCalendar || timeMode - ? "H:i" + (userConfig.enableSeconds ? ":S" : "") - : defaultDateFormat + " H:i" + (userConfig.enableSeconds ? ":S" : ""); - } - if (userConfig.altInput && - (userConfig.enableTime || timeMode) && - !userConfig.altFormat) { - var defaultAltFormat = flatpickr.defaultConfig.altFormat || defaults.altFormat; - formats.altFormat = - userConfig.noCalendar || timeMode - ? "h:i" + (userConfig.enableSeconds ? ":S K" : " K") - : defaultAltFormat + (" h:i" + (userConfig.enableSeconds ? ":S" : "") + " K"); - } - if (!userConfig.altInputClass) { - self.config.altInputClass = - self.input.className + " " + self.config.altInputClass; - } - Object.defineProperty(self.config, "minDate", { - get: function () { return self.config._minDate; }, - set: minMaxDateSetter("min") - }); - Object.defineProperty(self.config, "maxDate", { - get: function () { return self.config._maxDate; }, - set: minMaxDateSetter("max") - }); - var minMaxTimeSetter = function (type) { return function (val) { - self.config[type === "min" ? "_minTime" : "_maxTime"] = self.parseDate(val, "H:i:S"); - }; }; - Object.defineProperty(self.config, "minTime", { - get: function () { return self.config._minTime; }, - set: minMaxTimeSetter("min") - }); - Object.defineProperty(self.config, "maxTime", { - get: function () { return self.config._maxTime; }, - set: minMaxTimeSetter("max") - }); - if (userConfig.mode === "time") { - self.config.noCalendar = true; - self.config.enableTime = true; - } - Object.assign(self.config, formats, userConfig); - for (var i = 0; i < boolOpts.length; i++) - self.config[boolOpts[i]] = - self.config[boolOpts[i]] === true || - self.config[boolOpts[i]] === "true"; - HOOKS.filter(function (hook) { return self.config[hook] !== undefined; }).forEach(function (hook) { - self.config[hook] = arrayify(self.config[hook] || []).map(bindToInstance); - }); - self.isMobile = - !self.config.disableMobile && - !self.config.inline && - self.config.mode === "single" && - !self.config.disable.length && - !self.config.enable.length && - !self.config.weekNumbers && - /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); - for (var i = 0; i < self.config.plugins.length; i++) { - var pluginConf = self.config.plugins[i](self) || {}; - for (var key in pluginConf) { - if (HOOKS.indexOf(key) > -1) { - self.config[key] = arrayify(pluginConf[key]) - .map(bindToInstance) - .concat(self.config[key]); - } - else if (typeof userConfig[key] === "undefined") - self.config[key] = pluginConf[key]; - } - } - triggerEvent("onParseConfig"); - } - function setupLocale() { - if (typeof self.config.locale !== "object" && - typeof flatpickr.l10ns[self.config.locale] === "undefined") - self.config.errorHandler(new Error("flatpickr: invalid locale " + self.config.locale)); - self.l10n = __assign({}, flatpickr.l10ns["default"], (typeof self.config.locale === "object" - ? self.config.locale - : self.config.locale !== "default" - ? flatpickr.l10ns[self.config.locale] - : undefined)); - tokenRegex.K = "(" + self.l10n.amPM[0] + "|" + self.l10n.amPM[1] + "|" + self.l10n.amPM[0].toLowerCase() + "|" + self.l10n.amPM[1].toLowerCase() + ")"; - var userConfig = __assign({}, instanceConfig, JSON.parse(JSON.stringify(element.dataset || {}))); - if (userConfig.time_24hr === undefined && - flatpickr.defaultConfig.time_24hr === undefined) { - self.config.time_24hr = self.l10n.time_24hr; - } - self.formatDate = createDateFormatter(self); - self.parseDate = createDateParser({ config: self.config, l10n: self.l10n }); - } - function positionCalendar(customPositionElement) { - if (self.calendarContainer === undefined) - return; - triggerEvent("onPreCalendarPosition"); - var positionElement = customPositionElement || self._positionElement; - var calendarHeight = Array.prototype.reduce.call(self.calendarContainer.children, (function (acc, child) { return acc + child.offsetHeight; }), 0), calendarWidth = self.calendarContainer.offsetWidth, configPos = self.config.position.split(" "), configPosVertical = configPos[0], configPosHorizontal = configPos.length > 1 ? configPos[1] : null, inputBounds = positionElement.getBoundingClientRect(), distanceFromBottom = window.innerHeight - inputBounds.bottom, showOnTop = configPosVertical === "above" || - (configPosVertical !== "below" && - distanceFromBottom < calendarHeight && - inputBounds.top > calendarHeight); - var top = window.pageYOffset + - inputBounds.top + - (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2); - toggleClass(self.calendarContainer, "arrowTop", !showOnTop); - toggleClass(self.calendarContainer, "arrowBottom", showOnTop); - if (self.config.inline) - return; - var left = window.pageXOffset + - inputBounds.left - - (configPosHorizontal != null && configPosHorizontal === "center" - ? (calendarWidth - inputBounds.width) / 2 - : 0); - var right = window.document.body.offsetWidth - (window.pageXOffset + inputBounds.right); - var rightMost = left + calendarWidth > window.document.body.offsetWidth; - var centerMost = right + calendarWidth > window.document.body.offsetWidth; - toggleClass(self.calendarContainer, "rightMost", rightMost); - if (self.config.static) - return; - self.calendarContainer.style.top = top + "px"; - if (!rightMost) { - self.calendarContainer.style.left = left + "px"; - self.calendarContainer.style.right = "auto"; - } - else if (!centerMost) { - self.calendarContainer.style.left = "auto"; - self.calendarContainer.style.right = right + "px"; - } - else { - var doc = document.styleSheets[0]; - // some testing environments don't have css support - if (doc === undefined) - return; - var bodyWidth = window.document.body.offsetWidth; - var centerLeft = Math.max(0, bodyWidth / 2 - calendarWidth / 2); - var centerBefore = ".flatpickr-calendar.centerMost:before"; - var centerAfter = ".flatpickr-calendar.centerMost:after"; - var centerIndex = doc.cssRules.length; - var centerStyle = "{left:" + inputBounds.left + "px;right:auto;}"; - toggleClass(self.calendarContainer, "rightMost", false); - toggleClass(self.calendarContainer, "centerMost", true); - doc.insertRule(centerBefore + "," + centerAfter + centerStyle, centerIndex); - self.calendarContainer.style.left = centerLeft + "px"; - self.calendarContainer.style.right = "auto"; - } - } - function redraw() { - if (self.config.noCalendar || self.isMobile) - return; - updateNavigationCurrentMonth(); - buildDays(); - } - function focusAndClose() { - self._input.focus(); - if (window.navigator.userAgent.indexOf("MSIE") !== -1 || - navigator.msMaxTouchPoints !== undefined) { - // hack - bugs in the way IE handles focus keeps the calendar open - setTimeout(self.close, 0); - } - else { - self.close(); - } - } - function selectDate(e) { - e.preventDefault(); - e.stopPropagation(); - var isSelectable = function (day) { - return day.classList && - day.classList.contains("flatpickr-day") && - !day.classList.contains("flatpickr-disabled") && - !day.classList.contains("notAllowed"); - }; - var t = findParent(e.target, isSelectable); - if (t === undefined) - return; - var target = t; - var selectedDate = (self.latestSelectedDateObj = new Date(target.dateObj.getTime())); - var shouldChangeMonth = (selectedDate.getMonth() < self.currentMonth || - selectedDate.getMonth() > - self.currentMonth + self.config.showMonths - 1) && - self.config.mode !== "range"; - self.selectedDateElem = target; - if (self.config.mode === "single") - self.selectedDates = [selectedDate]; - else if (self.config.mode === "multiple") { - var selectedIndex = isDateSelected(selectedDate); - if (selectedIndex) - self.selectedDates.splice(parseInt(selectedIndex), 1); - else - self.selectedDates.push(selectedDate); - } - else if (self.config.mode === "range") { - if (self.selectedDates.length === 2) { - self.clear(false, false); - } - self.latestSelectedDateObj = selectedDate; - self.selectedDates.push(selectedDate); - // unless selecting same date twice, sort ascendingly - if (compareDates(selectedDate, self.selectedDates[0], true) !== 0) - self.selectedDates.sort(function (a, b) { return a.getTime() - b.getTime(); }); - } - setHoursFromInputs(); - if (shouldChangeMonth) { - var isNewYear = self.currentYear !== selectedDate.getFullYear(); - self.currentYear = selectedDate.getFullYear(); - self.currentMonth = selectedDate.getMonth(); - if (isNewYear) { - triggerEvent("onYearChange"); - buildMonthSwitch(); - } - triggerEvent("onMonthChange"); - } - updateNavigationCurrentMonth(); - buildDays(); - updateValue(); - if (self.config.enableTime) - setTimeout(function () { return (self.showTimeInput = true); }, 50); - // maintain focus - if (!shouldChangeMonth && - self.config.mode !== "range" && - self.config.showMonths === 1) - focusOnDayElem(target); - else if (self.selectedDateElem !== undefined && - self.hourElement === undefined) { - self.selectedDateElem && self.selectedDateElem.focus(); - } - if (self.hourElement !== undefined) - self.hourElement !== undefined && self.hourElement.focus(); - if (self.config.closeOnSelect) { - var single = self.config.mode === "single" && !self.config.enableTime; - var range = self.config.mode === "range" && - self.selectedDates.length === 2 && - !self.config.enableTime; - if (single || range) { - focusAndClose(); - } - } - triggerChange(); - } - var CALLBACKS = { - locale: [setupLocale, updateWeekdays], - showMonths: [buildMonths, setCalendarWidth, buildWeekdays], - minDate: [jumpToDate], - maxDate: [jumpToDate] - }; - function set(option, value) { - if (option !== null && typeof option === "object") { - Object.assign(self.config, option); - for (var key in option) { - if (CALLBACKS[key] !== undefined) - CALLBACKS[key].forEach(function (x) { return x(); }); - } - } - else { - self.config[option] = value; - if (CALLBACKS[option] !== undefined) - CALLBACKS[option].forEach(function (x) { return x(); }); - else if (HOOKS.indexOf(option) > -1) - self.config[option] = arrayify(value); - } - self.redraw(); - updateValue(false); - } - function setSelectedDate(inputDate, format) { - var dates = []; - if (inputDate instanceof Array) - dates = inputDate.map(function (d) { return self.parseDate(d, format); }); - else if (inputDate instanceof Date || typeof inputDate === "number") - dates = [self.parseDate(inputDate, format)]; - else if (typeof inputDate === "string") { - switch (self.config.mode) { - case "single": - case "time": - dates = [self.parseDate(inputDate, format)]; - break; - case "multiple": - dates = inputDate - .split(self.config.conjunction) - .map(function (date) { return self.parseDate(date, format); }); - break; - case "range": - dates = inputDate - .split(self.l10n.rangeSeparator) - .map(function (date) { return self.parseDate(date, format); }); - break; - default: - break; - } - } - else - self.config.errorHandler(new Error("Invalid date supplied: " + JSON.stringify(inputDate))); - self.selectedDates = dates.filter(function (d) { return d instanceof Date && isEnabled(d, false); }); - if (self.config.mode === "range") - self.selectedDates.sort(function (a, b) { return a.getTime() - b.getTime(); }); - } - function setDate(date, triggerChange, format) { - if (triggerChange === void 0) { triggerChange = false; } - if (format === void 0) { format = self.config.dateFormat; } - if ((date !== 0 && !date) || (date instanceof Array && date.length === 0)) - return self.clear(triggerChange); - setSelectedDate(date, format); - self.showTimeInput = self.selectedDates.length > 0; - self.latestSelectedDateObj = - self.selectedDates[self.selectedDates.length - 1]; - self.redraw(); - jumpToDate(); - setHoursFromDate(); - if (self.selectedDates.length === 0) { - self.clear(false); - } - updateValue(triggerChange); - if (triggerChange) - triggerEvent("onChange"); - } - function parseDateRules(arr) { - return arr - .slice() - .map(function (rule) { - if (typeof rule === "string" || - typeof rule === "number" || - rule instanceof Date) { - return self.parseDate(rule, undefined, true); - } - else if (rule && - typeof rule === "object" && - rule.from && - rule.to) - return { - from: self.parseDate(rule.from, undefined), - to: self.parseDate(rule.to, undefined) - }; - return rule; - }) - .filter(function (x) { return x; }); // remove falsy values - } - function setupDates() { - self.selectedDates = []; - self.now = self.parseDate(self.config.now) || new Date(); - // Workaround IE11 setting placeholder as the input's value - var preloadedDate = self.config.defaultDate || - ((self.input.nodeName === "INPUT" || - self.input.nodeName === "TEXTAREA") && - self.input.placeholder && - self.input.value === self.input.placeholder - ? null - : self.input.value); - if (preloadedDate) - setSelectedDate(preloadedDate, self.config.dateFormat); - self._initialDate = - self.selectedDates.length > 0 - ? self.selectedDates[0] - : self.config.minDate && - self.config.minDate.getTime() > self.now.getTime() - ? self.config.minDate - : self.config.maxDate && - self.config.maxDate.getTime() < self.now.getTime() - ? self.config.maxDate - : self.now; - self.currentYear = self._initialDate.getFullYear(); - self.currentMonth = self._initialDate.getMonth(); - if (self.selectedDates.length > 0) - self.latestSelectedDateObj = self.selectedDates[0]; - if (self.config.minTime !== undefined) - self.config.minTime = self.parseDate(self.config.minTime, "H:i"); - if (self.config.maxTime !== undefined) - self.config.maxTime = self.parseDate(self.config.maxTime, "H:i"); - self.minDateHasTime = - !!self.config.minDate && - (self.config.minDate.getHours() > 0 || - self.config.minDate.getMinutes() > 0 || - self.config.minDate.getSeconds() > 0); - self.maxDateHasTime = - !!self.config.maxDate && - (self.config.maxDate.getHours() > 0 || - self.config.maxDate.getMinutes() > 0 || - self.config.maxDate.getSeconds() > 0); - Object.defineProperty(self, "showTimeInput", { - get: function () { return self._showTimeInput; }, - set: function (bool) { - self._showTimeInput = bool; - if (self.calendarContainer) - toggleClass(self.calendarContainer, "showTimeInput", bool); - self.isOpen && positionCalendar(); - } - }); - } - function setupInputs() { - self.input = self.config.wrap - ? element.querySelector("[data-input]") - : element; - /* istanbul ignore next */ - if (!self.input) { - self.config.errorHandler(new Error("Invalid input element specified")); - return; - } - // hack: store previous type to restore it after destroy() - self.input._type = self.input.type; - self.input.type = "text"; - self.input.classList.add("flatpickr-input"); - self._input = self.input; - if (self.config.altInput) { - // replicate self.element - self.altInput = createElement(self.input.nodeName, self.config.altInputClass); - self._input = self.altInput; - self.altInput.placeholder = self.input.placeholder; - self.altInput.disabled = self.input.disabled; - self.altInput.required = self.input.required; - self.altInput.tabIndex = self.input.tabIndex; - self.altInput.type = "text"; - self.input.setAttribute("type", "hidden"); - if (!self.config.static && self.input.parentNode) - self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling); - } - if (!self.config.allowInput) - self._input.setAttribute("readonly", "readonly"); - self._positionElement = self.config.positionElement || self._input; - } - function setupMobile() { - var inputType = self.config.enableTime - ? self.config.noCalendar - ? "time" - : "datetime-local" - : "date"; - self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile"); - self.mobileInput.step = self.input.getAttribute("step") || "any"; - self.mobileInput.tabIndex = 1; - self.mobileInput.type = inputType; - self.mobileInput.disabled = self.input.disabled; - self.mobileInput.required = self.input.required; - self.mobileInput.placeholder = self.input.placeholder; - self.mobileFormatStr = - inputType === "datetime-local" - ? "Y-m-d\\TH:i:S" - : inputType === "date" - ? "Y-m-d" - : "H:i:S"; - if (self.selectedDates.length > 0) { - self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr); - } - if (self.config.minDate) - self.mobileInput.min = self.formatDate(self.config.minDate, "Y-m-d"); - if (self.config.maxDate) - self.mobileInput.max = self.formatDate(self.config.maxDate, "Y-m-d"); - self.input.type = "hidden"; - if (self.altInput !== undefined) - self.altInput.type = "hidden"; - try { - if (self.input.parentNode) - self.input.parentNode.insertBefore(self.mobileInput, self.input.nextSibling); - } - catch (_a) { } - bind(self.mobileInput, "change", function (e) { - self.setDate(e.target.value, false, self.mobileFormatStr); - triggerEvent("onChange"); - triggerEvent("onClose"); - }); - } - function toggle(e) { - if (self.isOpen === true) - return self.close(); - self.open(e); - } - function triggerEvent(event, data) { - // If the instance has been destroyed already, all hooks have been removed - if (self.config === undefined) - return; - var hooks = self.config[event]; - if (hooks !== undefined && hooks.length > 0) { - for (var i = 0; hooks[i] && i < hooks.length; i++) - hooks[i](self.selectedDates, self.input.value, self, data); - } - if (event === "onChange") { - self.input.dispatchEvent(createEvent("change")); - // many front-end frameworks bind to the input event - self.input.dispatchEvent(createEvent("input")); - } - } - function createEvent(name) { - var e = document.createEvent("Event"); - e.initEvent(name, true, true); - return e; - } - function isDateSelected(date) { - for (var i = 0; i < self.selectedDates.length; i++) { - if (compareDates(self.selectedDates[i], date) === 0) - return "" + i; - } - return false; - } - function isDateInRange(date) { - if (self.config.mode !== "range" || self.selectedDates.length < 2) - return false; - return (compareDates(date, self.selectedDates[0]) >= 0 && - compareDates(date, self.selectedDates[1]) <= 0); - } - function updateNavigationCurrentMonth() { - if (self.config.noCalendar || self.isMobile || !self.monthNav) - return; - self.yearElements.forEach(function (yearElement, i) { - var d = new Date(self.currentYear, self.currentMonth, 1); - d.setMonth(self.currentMonth + i); - if (self.config.showMonths > 1 || - self.config.monthSelectorType === "static") { - self.monthElements[i].textContent = - monthToStr(d.getMonth(), self.config.shorthandCurrentMonth, self.l10n) + " "; - } - else { - self.monthsDropdownContainer.value = d.getMonth().toString(); - } - yearElement.value = d.getFullYear().toString(); - }); - self._hidePrevMonthArrow = - self.config.minDate !== undefined && - (self.currentYear === self.config.minDate.getFullYear() - ? self.currentMonth <= self.config.minDate.getMonth() - : self.currentYear < self.config.minDate.getFullYear()); - self._hideNextMonthArrow = - self.config.maxDate !== undefined && - (self.currentYear === self.config.maxDate.getFullYear() - ? self.currentMonth + 1 > self.config.maxDate.getMonth() - : self.currentYear > self.config.maxDate.getFullYear()); - } - function getDateStr(format) { - return self.selectedDates - .map(function (dObj) { return self.formatDate(dObj, format); }) - .filter(function (d, i, arr) { - return self.config.mode !== "range" || - self.config.enableTime || - arr.indexOf(d) === i; - }) - .join(self.config.mode !== "range" - ? self.config.conjunction - : self.l10n.rangeSeparator); - } - /** - * Updates the values of inputs associated with the calendar - */ - function updateValue(triggerChange) { - if (triggerChange === void 0) { triggerChange = true; } - if (self.mobileInput !== undefined && self.mobileFormatStr) { - self.mobileInput.value = - self.latestSelectedDateObj !== undefined - ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr) - : ""; - } - self.input.value = getDateStr(self.config.dateFormat); - if (self.altInput !== undefined) { - self.altInput.value = getDateStr(self.config.altFormat); - } - if (triggerChange !== false) - triggerEvent("onValueUpdate"); - } - function onMonthNavClick(e) { - var isPrevMonth = self.prevMonthNav.contains(e.target); - var isNextMonth = self.nextMonthNav.contains(e.target); - if (isPrevMonth || isNextMonth) { - changeMonth(isPrevMonth ? -1 : 1); - } - else if (self.yearElements.indexOf(e.target) >= 0) { - e.target.select(); - } - else if (e.target.classList.contains("arrowUp")) { - self.changeYear(self.currentYear + 1); - } - else if (e.target.classList.contains("arrowDown")) { - self.changeYear(self.currentYear - 1); - } - } - function timeWrapper(e) { - e.preventDefault(); - var isKeyDown = e.type === "keydown", input = e.target; - if (self.amPM !== undefined && e.target === self.amPM) { - self.amPM.textContent = - self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])]; - } - var min = parseFloat(input.getAttribute("min")), max = parseFloat(input.getAttribute("max")), step = parseFloat(input.getAttribute("step")), curValue = parseInt(input.value, 10), delta = e.delta || - (isKeyDown ? (e.which === 38 ? 1 : -1) : 0); - var newValue = curValue + step * delta; - if (typeof input.value !== "undefined" && input.value.length === 2) { - var isHourElem = input === self.hourElement, isMinuteElem = input === self.minuteElement; - if (newValue < min) { - newValue = - max + - newValue + - int(!isHourElem) + - (int(isHourElem) && int(!self.amPM)); - if (isMinuteElem) - incrementNumInput(undefined, -1, self.hourElement); - } - else if (newValue > max) { - newValue = - input === self.hourElement ? newValue - max - int(!self.amPM) : min; - if (isMinuteElem) - incrementNumInput(undefined, 1, self.hourElement); - } - if (self.amPM && - isHourElem && - (step === 1 - ? newValue + curValue === 23 - : Math.abs(newValue - curValue) > step)) { - self.amPM.textContent = - self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])]; - } - input.value = pad(newValue); - } - } - init(); - return self; - } - /* istanbul ignore next */ - function _flatpickr(nodeList, config) { - // static list - var nodes = Array.prototype.slice - .call(nodeList) - .filter(function (x) { return x instanceof HTMLElement; }); - var instances = []; - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; - try { - if (node.getAttribute("data-fp-omit") !== null) - continue; - if (node._flatpickr !== undefined) { - node._flatpickr.destroy(); - node._flatpickr = undefined; - } - node._flatpickr = FlatpickrInstance(node, config || {}); - instances.push(node._flatpickr); - } - catch (e) { - console.error(e); - } - } - return instances.length === 1 ? instances[0] : instances; - } - /* istanbul ignore next */ - if (typeof HTMLElement !== "undefined" && - typeof HTMLCollection !== "undefined" && - typeof NodeList !== "undefined") { - // browser env - HTMLCollection.prototype.flatpickr = NodeList.prototype.flatpickr = function (config) { - return _flatpickr(this, config); - }; - HTMLElement.prototype.flatpickr = function (config) { - return _flatpickr([this], config); - }; - } - /* istanbul ignore next */ - var flatpickr = function (selector, config) { - if (typeof selector === "string") { - return _flatpickr(window.document.querySelectorAll(selector), config); - } - else if (selector instanceof Node) { - return _flatpickr([selector], config); - } - else { - return _flatpickr(selector, config); - } - }; - /* istanbul ignore next */ - flatpickr.defaultConfig = {}; - flatpickr.l10ns = { - en: __assign({}, english), - "default": __assign({}, english) - }; - flatpickr.localize = function (l10n) { - flatpickr.l10ns["default"] = __assign({}, flatpickr.l10ns["default"], l10n); - }; - flatpickr.setDefaults = function (config) { - flatpickr.defaultConfig = __assign({}, flatpickr.defaultConfig, config); - }; - flatpickr.parseDate = createDateParser({}); - flatpickr.formatDate = createDateFormatter({}); - flatpickr.compareDates = compareDates; - /* istanbul ignore next */ - if (typeof jQuery !== "undefined" && typeof jQuery.fn !== "undefined") { - jQuery.fn.flatpickr = function (config) { - return _flatpickr(this, config); - }; - } - // eslint-disable-next-line @typescript-eslint/camelcase - Date.prototype.fp_incr = function (days) { - return new Date(this.getFullYear(), this.getMonth(), this.getDate() + (typeof days === "string" ? parseInt(days, 10) : days)); - }; - if (typeof window !== "undefined") { - window.flatpickr = flatpickr; - } - - return flatpickr; - -})); diff --git a/public/js/vendor/flatpickr.min.js b/public/js/vendor/flatpickr.min.js deleted file mode 100644 index c850b7c..0000000 --- a/public/js/vendor/flatpickr.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/* flatpickr v4.6.3,, @license MIT */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).flatpickr=t()}(this,function(){"use strict";var e=function(){return(e=Object.assign||function(e){for(var t,n=1,a=arguments.length;n",noCalendar:!1,now:new Date,onChange:[],onClose:[],onDayCreate:[],onDestroy:[],onKeyDown:[],onMonthChange:[],onOpen:[],onParseConfig:[],onReady:[],onValueUpdate:[],onYearChange:[],onPreCalendarPosition:[],plugins:[],position:"auto",positionElement:void 0,prevArrow:"",shorthandCurrentMonth:!1,showMonths:1,static:!1,time_24hr:!1,weekNumbers:!1,wrap:!1},a={weekdays:{shorthand:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longhand:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},months:{shorthand:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longhand:["January","February","March","April","May","June","July","August","September","October","November","December"]},daysInMonth:[31,28,31,30,31,30,31,31,30,31,30,31],firstDayOfWeek:0,ordinal:function(e){var t=e%100;if(t>3&&t<21)return"th";switch(t%10){case 1:return"st";case 2:return"nd";case 3:return"rd";default:return"th"}},rangeSeparator:" to ",weekAbbreviation:"Wk",scrollTitle:"Scroll to increment",toggleTitle:"Click to toggle",amPM:["AM","PM"],yearAriaLabel:"Year",hourAriaLabel:"Hour",minuteAriaLabel:"Minute",time_24hr:!1},i=function(e){return("0"+e).slice(-2)},o=function(e){return!0===e?1:0};function r(e,t,n){var a;return void 0===n&&(n=!1),function(){var i=this,o=arguments;null!==a&&clearTimeout(a),a=window.setTimeout(function(){a=null,n||e.apply(i,o)},t),n&&!a&&e.apply(i,o)}}var l=function(e){return e instanceof Array?e:[e]};function c(e,t,n){if(!0===n)return e.classList.add(t);e.classList.remove(t)}function d(e,t,n){var a=window.document.createElement(e);return t=t||"",n=n||"",a.className=t,void 0!==n&&(a.textContent=n),a}function s(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function u(e,t){var n=d("div","numInputWrapper"),a=d("input","numInput "+e),i=d("span","arrowUp"),o=d("span","arrowDown");if(-1===navigator.userAgent.indexOf("MSIE 9.0")?a.type="number":(a.type="text",a.pattern="\\d*"),void 0!==t)for(var r in t)a.setAttribute(r,t[r]);return n.appendChild(a),n.appendChild(i),n.appendChild(o),n}var f=function(){},m=function(e,t,n){return n.months[t?"shorthand":"longhand"][e]},g={D:f,F:function(e,t,n){e.setMonth(n.months.longhand.indexOf(t))},G:function(e,t){e.setHours(parseFloat(t))},H:function(e,t){e.setHours(parseFloat(t))},J:function(e,t){e.setDate(parseFloat(t))},K:function(e,t,n){e.setHours(e.getHours()%12+12*o(new RegExp(n.amPM[1],"i").test(t)))},M:function(e,t,n){e.setMonth(n.months.shorthand.indexOf(t))},S:function(e,t){e.setSeconds(parseFloat(t))},U:function(e,t){return new Date(1e3*parseFloat(t))},W:function(e,t,n){var a=parseInt(t),i=new Date(e.getFullYear(),0,2+7*(a-1),0,0,0,0);return i.setDate(i.getDate()-i.getDay()+n.firstDayOfWeek),i},Y:function(e,t){e.setFullYear(parseFloat(t))},Z:function(e,t){return new Date(t)},d:function(e,t){e.setDate(parseFloat(t))},h:function(e,t){e.setHours(parseFloat(t))},i:function(e,t){e.setMinutes(parseFloat(t))},j:function(e,t){e.setDate(parseFloat(t))},l:f,m:function(e,t){e.setMonth(parseFloat(t)-1)},n:function(e,t){e.setMonth(parseFloat(t)-1)},s:function(e,t){e.setSeconds(parseFloat(t))},u:function(e,t){return new Date(parseFloat(t))},w:f,y:function(e,t){e.setFullYear(2e3+parseFloat(t))}},p={D:"(\\w+)",F:"(\\w+)",G:"(\\d\\d|\\d)",H:"(\\d\\d|\\d)",J:"(\\d\\d|\\d)\\w+",K:"",M:"(\\w+)",S:"(\\d\\d|\\d)",U:"(.+)",W:"(\\d\\d|\\d)",Y:"(\\d{4})",Z:"(.+)",d:"(\\d\\d|\\d)",h:"(\\d\\d|\\d)",i:"(\\d\\d|\\d)",j:"(\\d\\d|\\d)",l:"(\\w+)",m:"(\\d\\d|\\d)",n:"(\\d\\d|\\d)",s:"(\\d\\d|\\d)",u:"(.+)",w:"(\\d\\d|\\d)",y:"(\\d{2})"},h={Z:function(e){return e.toISOString()},D:function(e,t,n){return t.weekdays.shorthand[h.w(e,t,n)]},F:function(e,t,n){return m(h.n(e,t,n)-1,!1,t)},G:function(e,t,n){return i(h.h(e,t,n))},H:function(e){return i(e.getHours())},J:function(e,t){return void 0!==t.ordinal?e.getDate()+t.ordinal(e.getDate()):e.getDate()},K:function(e,t){return t.amPM[o(e.getHours()>11)]},M:function(e,t){return m(e.getMonth(),!0,t)},S:function(e){return i(e.getSeconds())},U:function(e){return e.getTime()/1e3},W:function(e,t,n){return n.getWeek(e)},Y:function(e){return e.getFullYear()},d:function(e){return i(e.getDate())},h:function(e){return e.getHours()%12?e.getHours()%12:12},i:function(e){return i(e.getMinutes())},j:function(e){return e.getDate()},l:function(e,t){return t.weekdays.longhand[e.getDay()]},m:function(e){return i(e.getMonth()+1)},n:function(e){return e.getMonth()+1},s:function(e){return e.getSeconds()},u:function(e){return e.getTime()},w:function(e){return e.getDay()},y:function(e){return String(e.getFullYear()).substring(2)}},v=function(e){var t=e.config,i=void 0===t?n:t,o=e.l10n,r=void 0===o?a:o;return function(e,t,n){var a=n||r;return void 0!==i.formatDate?i.formatDate(e,t,a):t.split("").map(function(t,n,o){return h[t]&&"\\"!==o[n-1]?h[t](e,a,i):"\\"!==t?t:""}).join("")}},D=function(e){var t=e.config,i=void 0===t?n:t,o=e.l10n,r=void 0===o?a:o;return function(e,t,a,o){if(0===e||e){var l,c=o||r,d=e;if(e instanceof Date)l=new Date(e.getTime());else if("string"!=typeof e&&void 0!==e.toFixed)l=new Date(e);else if("string"==typeof e){var s=t||(i||n).dateFormat,u=String(e).trim();if("today"===u)l=new Date,a=!0;else if(/Z$/.test(u)||/GMT$/.test(u))l=new Date(e);else if(i&&i.parseDate)l=i.parseDate(e,s);else{l=i&&i.noCalendar?new Date((new Date).setHours(0,0,0,0)):new Date((new Date).getFullYear(),0,1,0,0,0,0);for(var f=void 0,m=[],h=0,v=0,D="";hMath.min(t,n)&&er&&(s=n===h.hourElement?s-r-o(!h.amPM):a,f&&j(void 0,1,h.hourElement)),h.amPM&&u&&(1===l?s+c===23:Math.abs(s-c)>l)&&(h.amPM.textContent=h.l10n.amPM[o(h.amPM.textContent===h.l10n.amPM[0])]),n.value=i(s)}}(e);var t=h._input.value;k(),we(),h._input.value!==t&&h._debouncedChange()}function k(){if(void 0!==h.hourElement&&void 0!==h.minuteElement){var e,t,n=(parseInt(h.hourElement.value.slice(-2),10)||0)%24,a=(parseInt(h.minuteElement.value,10)||0)%60,i=void 0!==h.secondElement?(parseInt(h.secondElement.value,10)||0)%60:0;void 0!==h.amPM&&(e=n,t=h.amPM.textContent,n=e%12+12*o(t===h.l10n.amPM[1]));var r=void 0!==h.config.minTime||h.config.minDate&&h.minDateHasTime&&h.latestSelectedDateObj&&0===w(h.latestSelectedDateObj,h.config.minDate,!0);if(void 0!==h.config.maxTime||h.config.maxDate&&h.maxDateHasTime&&h.latestSelectedDateObj&&0===w(h.latestSelectedDateObj,h.config.maxDate,!0)){var l=void 0!==h.config.maxTime?h.config.maxTime:h.config.maxDate;(n=Math.min(n,l.getHours()))===l.getHours()&&(a=Math.min(a,l.getMinutes())),a===l.getMinutes()&&(i=Math.min(i,l.getSeconds()))}if(r){var c=void 0!==h.config.minTime?h.config.minTime:h.config.minDate;(n=Math.max(n,c.getHours()))===c.getHours()&&(a=Math.max(a,c.getMinutes())),a===c.getMinutes()&&(i=Math.max(i,c.getSeconds()))}O(n,a,i)}}function I(e){var t=e||h.latestSelectedDateObj;t&&O(t.getHours(),t.getMinutes(),t.getSeconds())}function S(){var e=h.config.defaultHour,t=h.config.defaultMinute,n=h.config.defaultSeconds;if(void 0!==h.config.minDate){var a=h.config.minDate.getHours(),i=h.config.minDate.getMinutes();(e=Math.max(e,a))===a&&(t=Math.max(i,t)),e===a&&t===i&&(n=h.config.minDate.getSeconds())}if(void 0!==h.config.maxDate){var o=h.config.maxDate.getHours(),r=h.config.maxDate.getMinutes();(e=Math.min(e,o))===o&&(t=Math.min(r,t)),e===o&&t===r&&(n=h.config.maxDate.getSeconds())}O(e,t,n)}function O(e,t,n){void 0!==h.latestSelectedDateObj&&h.latestSelectedDateObj.setHours(e%24,t,n||0,0),h.hourElement&&h.minuteElement&&!h.isMobile&&(h.hourElement.value=i(h.config.time_24hr?e:(12+e)%12+12*o(e%12==0)),h.minuteElement.value=i(t),void 0!==h.amPM&&(h.amPM.textContent=h.l10n.amPM[o(e>=12)]),void 0!==h.secondElement&&(h.secondElement.value=i(n)))}function _(e){var t=parseInt(e.target.value)+(e.delta||0);(t/1e3>1||"Enter"===e.key&&!/[^\d]/.test(t.toString()))&&Q(t)}function F(e,t,n,a){return t instanceof Array?t.forEach(function(t){return F(e,t,n,a)}):e instanceof Array?e.forEach(function(e){return F(e,t,n,a)}):(e.addEventListener(t,n,a),void h._handlers.push({element:e,event:t,handler:n,options:a}))}function N(e){return function(t){1===t.which&&e(t)}}function Y(){ge("onChange")}function A(e,t){var n=void 0!==e?h.parseDate(e):h.latestSelectedDateObj||(h.config.minDate&&h.config.minDate>h.now?h.config.minDate:h.config.maxDate&&h.config.maxDate=0&&w(e,h.selectedDates[1])<=0}(t)&&!he(t)&&o.classList.add("inRange"),h.weekNumbers&&1===h.config.showMonths&&"prevMonthDay"!==e&&n%7==1&&h.weekNumbers.insertAdjacentHTML("beforeend",""+h.config.getWeek(t)+""),ge("onDayCreate",o),o}function L(e){e.focus(),"range"===h.config.mode&&ne(e)}function W(e){for(var t=e>0?0:h.config.showMonths-1,n=e>0?h.config.showMonths:-1,a=t;a!=n;a+=e)for(var i=h.daysContainer.children[a],o=e>0?0:i.children.length-1,r=e>0?i.children.length:-1,l=o;l!=r;l+=e){var c=i.children[l];if(-1===c.className.indexOf("hidden")&&X(c.dateObj))return c}}function R(e,t){var n=ee(document.activeElement||document.body),a=void 0!==e?e:n?document.activeElement:void 0!==h.selectedDateElem&&ee(h.selectedDateElem)?h.selectedDateElem:void 0!==h.todayDateElem&&ee(h.todayDateElem)?h.todayDateElem:W(t>0?1:-1);return void 0===a?h._input.focus():n?void function(e,t){for(var n=-1===e.className.indexOf("Month")?e.dateObj.getMonth():h.currentMonth,a=t>0?h.config.showMonths:-1,i=t>0?1:-1,o=n-h.currentMonth;o!=a;o+=i)for(var r=h.daysContainer.children[o],l=n-h.currentMonth===o?e.$i+t:t<0?r.children.length-1:0,c=r.children.length,d=l;d>=0&&d0?c:-1);d+=i){var s=r.children[d];if(-1===s.className.indexOf("hidden")&&X(s.dateObj)&&Math.abs(e.$i-d)>=Math.abs(t))return L(s)}h.changeMonth(i),R(W(i),0)}(a,t):L(a)}function B(e,t){for(var n=(new Date(e,t,1).getDay()-h.l10n.firstDayOfWeek+7)%7,a=h.utils.getDaysInMonth((t-1+12)%12),i=h.utils.getDaysInMonth(t),o=window.document.createDocumentFragment(),r=h.config.showMonths>1,l=r?"prevMonthDay hidden":"prevMonthDay",c=r?"nextMonthDay hidden":"nextMonthDay",s=a+1-n,u=0;s<=a;s++,u++)o.appendChild(H(l,new Date(e,t-1,s),s,u));for(s=1;s<=i;s++,u++)o.appendChild(H("",new Date(e,t,s),s,u));for(var f=i+1;f<=42-n&&(1===h.config.showMonths||u%7!=0);f++,u++)o.appendChild(H(c,new Date(e,t+1,f%i),f,u));var m=d("div","dayContainer");return m.appendChild(o),m}function J(){if(void 0!==h.daysContainer){s(h.daysContainer),h.weekNumbers&&s(h.weekNumbers);for(var e=document.createDocumentFragment(),t=0;t1||"dropdown"!==h.config.monthSelectorType)){var e=function(e){return!(void 0!==h.config.minDate&&h.currentYear===h.config.minDate.getFullYear()&&eh.config.maxDate.getMonth())};h.monthsDropdownContainer.tabIndex=-1,h.monthsDropdownContainer.innerHTML="";for(var t=0;t<12;t++)if(e(t)){var n=d("option","flatpickr-monthDropdown-month");n.value=new Date(h.currentYear,t).getMonth().toString(),n.textContent=m(t,h.config.shorthandCurrentMonth,h.l10n),n.tabIndex=-1,h.currentMonth===t&&(n.selected=!0),h.monthsDropdownContainer.appendChild(n)}}}function U(){var e,t=d("div","flatpickr-month"),n=window.document.createDocumentFragment();h.config.showMonths>1||"static"===h.config.monthSelectorType?e=d("span","cur-month"):(h.monthsDropdownContainer=d("select","flatpickr-monthDropdown-months"),F(h.monthsDropdownContainer,"change",function(e){var t=e.target,n=parseInt(t.value,10);h.changeMonth(n-h.currentMonth),ge("onMonthChange")}),K(),e=h.monthsDropdownContainer);var a=u("cur-year",{tabindex:"-1"}),i=a.getElementsByTagName("input")[0];i.setAttribute("aria-label",h.l10n.yearAriaLabel),h.config.minDate&&i.setAttribute("min",h.config.minDate.getFullYear().toString()),h.config.maxDate&&(i.setAttribute("max",h.config.maxDate.getFullYear().toString()),i.disabled=!!h.config.minDate&&h.config.minDate.getFullYear()===h.config.maxDate.getFullYear());var o=d("div","flatpickr-current-month");return o.appendChild(e),o.appendChild(a),n.appendChild(o),t.appendChild(n),{container:t,yearElement:i,monthElement:e}}function q(){s(h.monthNav),h.monthNav.appendChild(h.prevMonthNav),h.config.showMonths&&(h.yearElements=[],h.monthElements=[]);for(var e=h.config.showMonths;e--;){var t=U();h.yearElements.push(t.yearElement),h.monthElements.push(t.monthElement),h.monthNav.appendChild(t.container)}h.monthNav.appendChild(h.nextMonthNav)}function $(){h.weekdayContainer?s(h.weekdayContainer):h.weekdayContainer=d("div","flatpickr-weekdays");for(var e=h.config.showMonths;e--;){var t=d("div","flatpickr-weekdaycontainer");h.weekdayContainer.appendChild(t)}return z(),h.weekdayContainer}function z(){if(h.weekdayContainer){var e=h.l10n.firstDayOfWeek,t=h.l10n.weekdays.shorthand.slice();e>0&&e\n "+t.join("")+"\n \n "}}function G(e,t){void 0===t&&(t=!0);var n=t?e:e-h.currentMonth;n<0&&!0===h._hidePrevMonthArrow||n>0&&!0===h._hideNextMonthArrow||(h.currentMonth+=n,(h.currentMonth<0||h.currentMonth>11)&&(h.currentYear+=h.currentMonth>11?1:-1,h.currentMonth=(h.currentMonth+12)%12,ge("onYearChange"),K()),J(),ge("onMonthChange"),ve())}function V(e){return!(!h.config.appendTo||!h.config.appendTo.contains(e))||h.calendarContainer.contains(e)}function Z(e){if(h.isOpen&&!h.config.inline){var t="function"==typeof(r=e).composedPath?r.composedPath()[0]:r.target,n=V(t),a=t===h.input||t===h.altInput||h.element.contains(t)||e.path&&e.path.indexOf&&(~e.path.indexOf(h.input)||~e.path.indexOf(h.altInput)),i="blur"===e.type?a&&e.relatedTarget&&!V(e.relatedTarget):!a&&!n&&!V(e.relatedTarget),o=!h.config.ignoredFocusElements.some(function(e){return e.contains(t)});i&&o&&(void 0!==h.timeContainer&&void 0!==h.minuteElement&&void 0!==h.hourElement&&T(),h.close(),"range"===h.config.mode&&1===h.selectedDates.length&&(h.clear(!1),h.redraw()))}var r}function Q(e){if(!(!e||h.config.minDate&&eh.config.maxDate.getFullYear())){var t=e,n=h.currentYear!==t;h.currentYear=t||h.currentYear,h.config.maxDate&&h.currentYear===h.config.maxDate.getFullYear()?h.currentMonth=Math.min(h.config.maxDate.getMonth(),h.currentMonth):h.config.minDate&&h.currentYear===h.config.minDate.getFullYear()&&(h.currentMonth=Math.max(h.config.minDate.getMonth(),h.currentMonth)),n&&(h.redraw(),ge("onYearChange"),K())}}function X(e,t){void 0===t&&(t=!0);var n=h.parseDate(e,void 0,t);if(h.config.minDate&&n&&w(n,h.config.minDate,void 0!==t?t:!h.minDateHasTime)<0||h.config.maxDate&&n&&w(n,h.config.maxDate,void 0!==t?t:!h.maxDateHasTime)>0)return!1;if(0===h.config.enable.length&&0===h.config.disable.length)return!0;if(void 0===n)return!1;for(var a=h.config.enable.length>0,i=a?h.config.enable:h.config.disable,o=0,r=void 0;o=r.from.getTime()&&n.getTime()<=r.to.getTime())return a}return!a}function ee(e){return void 0!==h.daysContainer&&(-1===e.className.indexOf("hidden")&&h.daysContainer.contains(e))}function te(e){var t=e.target===h._input,n=h.config.allowInput,a=h.isOpen&&(!n||!t),i=h.config.inline&&t&&!n;if(13===e.keyCode&&t){if(n)return h.setDate(h._input.value,!0,e.target===h.altInput?h.config.altFormat:h.config.dateFormat),e.target.blur();h.open()}else if(V(e.target)||a||i){var o=!!h.timeContainer&&h.timeContainer.contains(e.target);switch(e.keyCode){case 13:o?(e.preventDefault(),T(),de()):se(e);break;case 27:e.preventDefault(),de();break;case 8:case 46:t&&!h.config.allowInput&&(e.preventDefault(),h.clear());break;case 37:case 39:if(o||t)h.hourElement&&h.hourElement.focus();else if(e.preventDefault(),void 0!==h.daysContainer&&(!1===n||document.activeElement&&ee(document.activeElement))){var r=39===e.keyCode?1:-1;e.ctrlKey?(e.stopPropagation(),G(r),R(W(1),0)):R(void 0,r)}break;case 38:case 40:e.preventDefault();var l=40===e.keyCode?1:-1;h.daysContainer&&void 0!==e.target.$i||e.target===h.input||e.target===h.altInput?e.ctrlKey?(e.stopPropagation(),Q(h.currentYear-l),R(W(1),0)):o||R(void 0,7*l):e.target===h.currentYearElement?Q(h.currentYear-l):h.config.enableTime&&(!o&&h.hourElement&&h.hourElement.focus(),T(e),h._debouncedChange());break;case 9:if(o){var c=[h.hourElement,h.minuteElement,h.secondElement,h.amPM].concat(h.pluginElements).filter(function(e){return e}),d=c.indexOf(e.target);if(-1!==d){var s=c[d+(e.shiftKey?-1:1)];e.preventDefault(),(s||h._input).focus()}}else!h.config.noCalendar&&h.daysContainer&&h.daysContainer.contains(e.target)&&e.shiftKey&&(e.preventDefault(),h._input.focus())}}if(void 0!==h.amPM&&e.target===h.amPM)switch(e.key){case h.l10n.amPM[0].charAt(0):case h.l10n.amPM[0].charAt(0).toLowerCase():h.amPM.textContent=h.l10n.amPM[0],k(),we();break;case h.l10n.amPM[1].charAt(0):case h.l10n.amPM[1].charAt(0).toLowerCase():h.amPM.textContent=h.l10n.amPM[1],k(),we()}(t||V(e.target))&&ge("onKeyDown",e)}function ne(e){if(1===h.selectedDates.length&&(!e||e.classList.contains("flatpickr-day")&&!e.classList.contains("flatpickr-disabled"))){for(var t=e?e.dateObj.getTime():h.days.firstElementChild.dateObj.getTime(),n=h.parseDate(h.selectedDates[0],void 0,!0).getTime(),a=Math.min(t,h.selectedDates[0].getTime()),i=Math.max(t,h.selectedDates[0].getTime()),o=!1,r=0,l=0,c=a;ca&&cr)?r=c:c>n&&(!l||c0&&d0&&d>l;return u?(c.classList.add("notAllowed"),["inRange","startRange","endRange"].forEach(function(e){c.classList.remove(e)}),"continue"):o&&!u?"continue":(["startRange","inRange","endRange","notAllowed"].forEach(function(e){c.classList.remove(e)}),void(void 0!==e&&(e.classList.add(t<=h.selectedDates[0].getTime()?"startRange":"endRange"),nt&&d===n&&c.classList.add("endRange"),d>=r&&(0===l||d<=l)&&b(d,n,t)&&c.classList.add("inRange"))))},f=0,m=s.children.length;f0||n.getMinutes()>0||n.getSeconds()>0),h.selectedDates&&(h.selectedDates=h.selectedDates.filter(function(e){return X(e)}),h.selectedDates.length||"min"!==e||I(n),we()),h.daysContainer&&(ce(),void 0!==n?h.currentYearElement[e]=n.getFullYear().toString():h.currentYearElement.removeAttribute(e),h.currentYearElement.disabled=!!a&&void 0!==n&&a.getFullYear()===n.getFullYear())}}function re(){"object"!=typeof h.config.locale&&void 0===E.l10ns[h.config.locale]&&h.config.errorHandler(new Error("flatpickr: invalid locale "+h.config.locale)),h.l10n=e({},E.l10ns.default,"object"==typeof h.config.locale?h.config.locale:"default"!==h.config.locale?E.l10ns[h.config.locale]:void 0),p.K="("+h.l10n.amPM[0]+"|"+h.l10n.amPM[1]+"|"+h.l10n.amPM[0].toLowerCase()+"|"+h.l10n.amPM[1].toLowerCase()+")",void 0===e({},g,JSON.parse(JSON.stringify(f.dataset||{}))).time_24hr&&void 0===E.defaultConfig.time_24hr&&(h.config.time_24hr=h.l10n.time_24hr),h.formatDate=v(h),h.parseDate=D({config:h.config,l10n:h.l10n})}function le(e){if(void 0!==h.calendarContainer){ge("onPreCalendarPosition");var t=e||h._positionElement,n=Array.prototype.reduce.call(h.calendarContainer.children,function(e,t){return e+t.offsetHeight},0),a=h.calendarContainer.offsetWidth,i=h.config.position.split(" "),o=i[0],r=i.length>1?i[1]:null,l=t.getBoundingClientRect(),d=window.innerHeight-l.bottom,s="above"===o||"below"!==o&&dn,u=window.pageYOffset+l.top+(s?-n-2:t.offsetHeight+2);if(c(h.calendarContainer,"arrowTop",!s),c(h.calendarContainer,"arrowBottom",s),!h.config.inline){var f=window.pageXOffset+l.left-(null!=r&&"center"===r?(a-l.width)/2:0),m=window.document.body.offsetWidth-(window.pageXOffset+l.right),g=f+a>window.document.body.offsetWidth,p=m+a>window.document.body.offsetWidth;if(c(h.calendarContainer,"rightMost",g),!h.config.static)if(h.calendarContainer.style.top=u+"px",g)if(p){var v=document.styleSheets[0];if(void 0===v)return;var D=window.document.body.offsetWidth,w=Math.max(0,D/2-a/2),b=v.cssRules.length,C="{left:"+l.left+"px;right:auto;}";c(h.calendarContainer,"rightMost",!1),c(h.calendarContainer,"centerMost",!0),v.insertRule(".flatpickr-calendar.centerMost:before,.flatpickr-calendar.centerMost:after"+C,b),h.calendarContainer.style.left=w+"px",h.calendarContainer.style.right="auto"}else h.calendarContainer.style.left="auto",h.calendarContainer.style.right=m+"px";else h.calendarContainer.style.left=f+"px",h.calendarContainer.style.right="auto"}}}function ce(){h.config.noCalendar||h.isMobile||(ve(),J())}function de(){h._input.focus(),-1!==window.navigator.userAgent.indexOf("MSIE")||void 0!==navigator.msMaxTouchPoints?setTimeout(h.close,0):h.close()}function se(e){e.preventDefault(),e.stopPropagation();var t=function e(t,n){return n(t)?t:t.parentNode?e(t.parentNode,n):void 0}(e.target,function(e){return e.classList&&e.classList.contains("flatpickr-day")&&!e.classList.contains("flatpickr-disabled")&&!e.classList.contains("notAllowed")});if(void 0!==t){var n=t,a=h.latestSelectedDateObj=new Date(n.dateObj.getTime()),i=(a.getMonth()h.currentMonth+h.config.showMonths-1)&&"range"!==h.config.mode;if(h.selectedDateElem=n,"single"===h.config.mode)h.selectedDates=[a];else if("multiple"===h.config.mode){var o=he(a);o?h.selectedDates.splice(parseInt(o),1):h.selectedDates.push(a)}else"range"===h.config.mode&&(2===h.selectedDates.length&&h.clear(!1,!1),h.latestSelectedDateObj=a,h.selectedDates.push(a),0!==w(a,h.selectedDates[0],!0)&&h.selectedDates.sort(function(e,t){return e.getTime()-t.getTime()}));if(k(),i){var r=h.currentYear!==a.getFullYear();h.currentYear=a.getFullYear(),h.currentMonth=a.getMonth(),r&&(ge("onYearChange"),K()),ge("onMonthChange")}if(ve(),J(),we(),h.config.enableTime&&setTimeout(function(){return h.showTimeInput=!0},50),i||"range"===h.config.mode||1!==h.config.showMonths?void 0!==h.selectedDateElem&&void 0===h.hourElement&&h.selectedDateElem&&h.selectedDateElem.focus():L(n),void 0!==h.hourElement&&void 0!==h.hourElement&&h.hourElement.focus(),h.config.closeOnSelect){var l="single"===h.config.mode&&!h.config.enableTime,c="range"===h.config.mode&&2===h.selectedDates.length&&!h.config.enableTime;(l||c)&&de()}Y()}}h.parseDate=D({config:h.config,l10n:h.l10n}),h._handlers=[],h.pluginElements=[],h.loadedPlugins=[],h._bind=F,h._setHoursFromDate=I,h._positionCalendar=le,h.changeMonth=G,h.changeYear=Q,h.clear=function(e,t){void 0===e&&(e=!0);void 0===t&&(t=!0);h.input.value="",void 0!==h.altInput&&(h.altInput.value="");void 0!==h.mobileInput&&(h.mobileInput.value="");h.selectedDates=[],h.latestSelectedDateObj=void 0,!0===t&&(h.currentYear=h._initialDate.getFullYear(),h.currentMonth=h._initialDate.getMonth());h.showTimeInput=!1,!0===h.config.enableTime&&S();h.redraw(),e&&ge("onChange")},h.close=function(){h.isOpen=!1,h.isMobile||(void 0!==h.calendarContainer&&h.calendarContainer.classList.remove("open"),void 0!==h._input&&h._input.classList.remove("active"));ge("onClose")},h._createElement=d,h.destroy=function(){void 0!==h.config&&ge("onDestroy");for(var e=h._handlers.length;e--;){var t=h._handlers[e];t.element.removeEventListener(t.event,t.handler,t.options)}if(h._handlers=[],h.mobileInput)h.mobileInput.parentNode&&h.mobileInput.parentNode.removeChild(h.mobileInput),h.mobileInput=void 0;else if(h.calendarContainer&&h.calendarContainer.parentNode)if(h.config.static&&h.calendarContainer.parentNode){var n=h.calendarContainer.parentNode;if(n.lastChild&&n.removeChild(n.lastChild),n.parentNode){for(;n.firstChild;)n.parentNode.insertBefore(n.firstChild,n);n.parentNode.removeChild(n)}}else h.calendarContainer.parentNode.removeChild(h.calendarContainer);h.altInput&&(h.input.type="text",h.altInput.parentNode&&h.altInput.parentNode.removeChild(h.altInput),delete h.altInput);h.input&&(h.input.type=h.input._type,h.input.classList.remove("flatpickr-input"),h.input.removeAttribute("readonly"),h.input.value="");["_showTimeInput","latestSelectedDateObj","_hideNextMonthArrow","_hidePrevMonthArrow","__hideNextMonthArrow","__hidePrevMonthArrow","isMobile","isOpen","selectedDateElem","minDateHasTime","maxDateHasTime","days","daysContainer","_input","_positionElement","innerContainer","rContainer","monthNav","todayDateElem","calendarContainer","weekdayContainer","prevMonthNav","nextMonthNav","monthsDropdownContainer","currentMonthElement","currentYearElement","navigationCurrentMonth","selectedDateElem","config"].forEach(function(e){try{delete h[e]}catch(e){}})},h.isEnabled=X,h.jumpToDate=A,h.open=function(e,t){void 0===t&&(t=h._positionElement);if(!0===h.isMobile)return e&&(e.preventDefault(),e.target&&e.target.blur()),void 0!==h.mobileInput&&(h.mobileInput.focus(),h.mobileInput.click()),void ge("onOpen");if(h._input.disabled||h.config.inline)return;var n=h.isOpen;h.isOpen=!0,n||(h.calendarContainer.classList.add("open"),h._input.classList.add("active"),ge("onOpen"),le(t));!0===h.config.enableTime&&!0===h.config.noCalendar&&(0===h.selectedDates.length&&ie(),!1!==h.config.allowInput||void 0!==e&&h.timeContainer.contains(e.relatedTarget)||setTimeout(function(){return h.hourElement.select()},50))},h.redraw=ce,h.set=function(e,n){if(null!==e&&"object"==typeof e)for(var a in Object.assign(h.config,e),e)void 0!==ue[a]&&ue[a].forEach(function(e){return e()});else h.config[e]=n,void 0!==ue[e]?ue[e].forEach(function(e){return e()}):t.indexOf(e)>-1&&(h.config[e]=l(n));h.redraw(),we(!1)},h.setDate=function(e,t,n){void 0===t&&(t=!1);void 0===n&&(n=h.config.dateFormat);if(0!==e&&!e||e instanceof Array&&0===e.length)return h.clear(t);fe(e,n),h.showTimeInput=h.selectedDates.length>0,h.latestSelectedDateObj=h.selectedDates[h.selectedDates.length-1],h.redraw(),A(),I(),0===h.selectedDates.length&&h.clear(!1);we(t),t&&ge("onChange")},h.toggle=function(e){if(!0===h.isOpen)return h.close();h.open(e)};var ue={locale:[re,z],showMonths:[q,x,$],minDate:[A],maxDate:[A]};function fe(e,t){var n=[];if(e instanceof Array)n=e.map(function(e){return h.parseDate(e,t)});else if(e instanceof Date||"number"==typeof e)n=[h.parseDate(e,t)];else if("string"==typeof e)switch(h.config.mode){case"single":case"time":n=[h.parseDate(e,t)];break;case"multiple":n=e.split(h.config.conjunction).map(function(e){return h.parseDate(e,t)});break;case"range":n=e.split(h.l10n.rangeSeparator).map(function(e){return h.parseDate(e,t)})}else h.config.errorHandler(new Error("Invalid date supplied: "+JSON.stringify(e)));h.selectedDates=n.filter(function(e){return e instanceof Date&&X(e,!1)}),"range"===h.config.mode&&h.selectedDates.sort(function(e,t){return e.getTime()-t.getTime()})}function me(e){return e.slice().map(function(e){return"string"==typeof e||"number"==typeof e||e instanceof Date?h.parseDate(e,void 0,!0):e&&"object"==typeof e&&e.from&&e.to?{from:h.parseDate(e.from,void 0),to:h.parseDate(e.to,void 0)}:e}).filter(function(e){return e})}function ge(e,t){if(void 0!==h.config){var n=h.config[e];if(void 0!==n&&n.length>0)for(var a=0;n[a]&&a1||"static"===h.config.monthSelectorType?h.monthElements[t].textContent=m(n.getMonth(),h.config.shorthandCurrentMonth,h.l10n)+" ":h.monthsDropdownContainer.value=n.getMonth().toString(),e.value=n.getFullYear().toString()}),h._hidePrevMonthArrow=void 0!==h.config.minDate&&(h.currentYear===h.config.minDate.getFullYear()?h.currentMonth<=h.config.minDate.getMonth():h.currentYearh.config.maxDate.getMonth():h.currentYear>h.config.maxDate.getFullYear()))}function De(e){return h.selectedDates.map(function(t){return h.formatDate(t,e)}).filter(function(e,t,n){return"range"!==h.config.mode||h.config.enableTime||n.indexOf(e)===t}).join("range"!==h.config.mode?h.config.conjunction:h.l10n.rangeSeparator)}function we(e){void 0===e&&(e=!0),void 0!==h.mobileInput&&h.mobileFormatStr&&(h.mobileInput.value=void 0!==h.latestSelectedDateObj?h.formatDate(h.latestSelectedDateObj,h.mobileFormatStr):""),h.input.value=De(h.config.dateFormat),void 0!==h.altInput&&(h.altInput.value=De(h.config.altFormat)),!1!==e&&ge("onValueUpdate")}function be(e){var t=h.prevMonthNav.contains(e.target),n=h.nextMonthNav.contains(e.target);t||n?G(t?-1:1):h.yearElements.indexOf(e.target)>=0?e.target.select():e.target.classList.contains("arrowUp")?h.changeYear(h.currentYear+1):e.target.classList.contains("arrowDown")&&h.changeYear(h.currentYear-1)}return function(){h.element=h.input=f,h.isOpen=!1,function(){var a=["wrap","weekNumbers","allowInput","clickOpens","time_24hr","enableTime","noCalendar","altInput","shorthandCurrentMonth","inline","static","enableSeconds","disableMobile"],i=e({},g,JSON.parse(JSON.stringify(f.dataset||{}))),o={};h.config.parseDate=i.parseDate,h.config.formatDate=i.formatDate,Object.defineProperty(h.config,"enable",{get:function(){return h.config._enable},set:function(e){h.config._enable=me(e)}}),Object.defineProperty(h.config,"disable",{get:function(){return h.config._disable},set:function(e){h.config._disable=me(e)}});var r="time"===i.mode;if(!i.dateFormat&&(i.enableTime||r)){var c=E.defaultConfig.dateFormat||n.dateFormat;o.dateFormat=i.noCalendar||r?"H:i"+(i.enableSeconds?":S":""):c+" H:i"+(i.enableSeconds?":S":"")}if(i.altInput&&(i.enableTime||r)&&!i.altFormat){var d=E.defaultConfig.altFormat||n.altFormat;o.altFormat=i.noCalendar||r?"h:i"+(i.enableSeconds?":S K":" K"):d+" h:i"+(i.enableSeconds?":S":"")+" K"}i.altInputClass||(h.config.altInputClass=h.input.className+" "+h.config.altInputClass),Object.defineProperty(h.config,"minDate",{get:function(){return h.config._minDate},set:oe("min")}),Object.defineProperty(h.config,"maxDate",{get:function(){return h.config._maxDate},set:oe("max")});var s=function(e){return function(t){h.config["min"===e?"_minTime":"_maxTime"]=h.parseDate(t,"H:i:S")}};Object.defineProperty(h.config,"minTime",{get:function(){return h.config._minTime},set:s("min")}),Object.defineProperty(h.config,"maxTime",{get:function(){return h.config._maxTime},set:s("max")}),"time"===i.mode&&(h.config.noCalendar=!0,h.config.enableTime=!0),Object.assign(h.config,o,i);for(var u=0;u-1?h.config[p]=l(m[p]).map(y).concat(h.config[p]):void 0===i[p]&&(h.config[p]=m[p])}ge("onParseConfig")}(),re(),h.input=h.config.wrap?f.querySelector("[data-input]"):f,h.input?(h.input._type=h.input.type,h.input.type="text",h.input.classList.add("flatpickr-input"),h._input=h.input,h.config.altInput&&(h.altInput=d(h.input.nodeName,h.config.altInputClass),h._input=h.altInput,h.altInput.placeholder=h.input.placeholder,h.altInput.disabled=h.input.disabled,h.altInput.required=h.input.required,h.altInput.tabIndex=h.input.tabIndex,h.altInput.type="text",h.input.setAttribute("type","hidden"),!h.config.static&&h.input.parentNode&&h.input.parentNode.insertBefore(h.altInput,h.input.nextSibling)),h.config.allowInput||h._input.setAttribute("readonly","readonly"),h._positionElement=h.config.positionElement||h._input):h.config.errorHandler(new Error("Invalid input element specified")),function(){h.selectedDates=[],h.now=h.parseDate(h.config.now)||new Date;var e=h.config.defaultDate||("INPUT"!==h.input.nodeName&&"TEXTAREA"!==h.input.nodeName||!h.input.placeholder||h.input.value!==h.input.placeholder?h.input.value:null);e&&fe(e,h.config.dateFormat),h._initialDate=h.selectedDates.length>0?h.selectedDates[0]:h.config.minDate&&h.config.minDate.getTime()>h.now.getTime()?h.config.minDate:h.config.maxDate&&h.config.maxDate.getTime()0&&(h.latestSelectedDateObj=h.selectedDates[0]),void 0!==h.config.minTime&&(h.config.minTime=h.parseDate(h.config.minTime,"H:i")),void 0!==h.config.maxTime&&(h.config.maxTime=h.parseDate(h.config.maxTime,"H:i")),h.minDateHasTime=!!h.config.minDate&&(h.config.minDate.getHours()>0||h.config.minDate.getMinutes()>0||h.config.minDate.getSeconds()>0),h.maxDateHasTime=!!h.config.maxDate&&(h.config.maxDate.getHours()>0||h.config.maxDate.getMinutes()>0||h.config.maxDate.getSeconds()>0),Object.defineProperty(h,"showTimeInput",{get:function(){return h._showTimeInput},set:function(e){h._showTimeInput=e,h.calendarContainer&&c(h.calendarContainer,"showTimeInput",e),h.isOpen&&le()}})}(),h.utils={getDaysInMonth:function(e,t){return void 0===e&&(e=h.currentMonth),void 0===t&&(t=h.currentYear),1===e&&(t%4==0&&t%100!=0||t%400==0)?29:h.l10n.daysInMonth[e]}},h.isMobile||function(){var e=window.document.createDocumentFragment();if(h.calendarContainer=d("div","flatpickr-calendar"),h.calendarContainer.tabIndex=-1,!h.config.noCalendar){if(e.appendChild((h.monthNav=d("div","flatpickr-months"),h.yearElements=[],h.monthElements=[],h.prevMonthNav=d("span","flatpickr-prev-month"),h.prevMonthNav.innerHTML=h.config.prevArrow,h.nextMonthNav=d("span","flatpickr-next-month"),h.nextMonthNav.innerHTML=h.config.nextArrow,q(),Object.defineProperty(h,"_hidePrevMonthArrow",{get:function(){return h.__hidePrevMonthArrow},set:function(e){h.__hidePrevMonthArrow!==e&&(c(h.prevMonthNav,"flatpickr-disabled",e),h.__hidePrevMonthArrow=e)}}),Object.defineProperty(h,"_hideNextMonthArrow",{get:function(){return h.__hideNextMonthArrow},set:function(e){h.__hideNextMonthArrow!==e&&(c(h.nextMonthNav,"flatpickr-disabled",e),h.__hideNextMonthArrow=e)}}),h.currentYearElement=h.yearElements[0],ve(),h.monthNav)),h.innerContainer=d("div","flatpickr-innerContainer"),h.config.weekNumbers){var t=function(){h.calendarContainer.classList.add("hasWeeks");var e=d("div","flatpickr-weekwrapper");e.appendChild(d("span","flatpickr-weekday",h.l10n.weekAbbreviation));var t=d("div","flatpickr-weeks");return e.appendChild(t),{weekWrapper:e,weekNumbers:t}}(),n=t.weekWrapper,a=t.weekNumbers;h.innerContainer.appendChild(n),h.weekNumbers=a,h.weekWrapper=n}h.rContainer=d("div","flatpickr-rContainer"),h.rContainer.appendChild($()),h.daysContainer||(h.daysContainer=d("div","flatpickr-days"),h.daysContainer.tabIndex=-1),J(),h.rContainer.appendChild(h.daysContainer),h.innerContainer.appendChild(h.rContainer),e.appendChild(h.innerContainer)}h.config.enableTime&&e.appendChild(function(){h.calendarContainer.classList.add("hasTime"),h.config.noCalendar&&h.calendarContainer.classList.add("noCalendar"),h.timeContainer=d("div","flatpickr-time"),h.timeContainer.tabIndex=-1;var e=d("span","flatpickr-time-separator",":"),t=u("flatpickr-hour",{"aria-label":h.l10n.hourAriaLabel});h.hourElement=t.getElementsByTagName("input")[0];var n=u("flatpickr-minute",{"aria-label":h.l10n.minuteAriaLabel});if(h.minuteElement=n.getElementsByTagName("input")[0],h.hourElement.tabIndex=h.minuteElement.tabIndex=-1,h.hourElement.value=i(h.latestSelectedDateObj?h.latestSelectedDateObj.getHours():h.config.time_24hr?h.config.defaultHour:function(e){switch(e%24){case 0:case 12:return 12;default:return e%12}}(h.config.defaultHour)),h.minuteElement.value=i(h.latestSelectedDateObj?h.latestSelectedDateObj.getMinutes():h.config.defaultMinute),h.hourElement.setAttribute("step",h.config.hourIncrement.toString()),h.minuteElement.setAttribute("step",h.config.minuteIncrement.toString()),h.hourElement.setAttribute("min",h.config.time_24hr?"0":"1"),h.hourElement.setAttribute("max",h.config.time_24hr?"23":"12"),h.minuteElement.setAttribute("min","0"),h.minuteElement.setAttribute("max","59"),h.timeContainer.appendChild(t),h.timeContainer.appendChild(e),h.timeContainer.appendChild(n),h.config.time_24hr&&h.timeContainer.classList.add("time24hr"),h.config.enableSeconds){h.timeContainer.classList.add("hasSeconds");var a=u("flatpickr-second");h.secondElement=a.getElementsByTagName("input")[0],h.secondElement.value=i(h.latestSelectedDateObj?h.latestSelectedDateObj.getSeconds():h.config.defaultSeconds),h.secondElement.setAttribute("step",h.minuteElement.getAttribute("step")),h.secondElement.setAttribute("min","0"),h.secondElement.setAttribute("max","59"),h.timeContainer.appendChild(d("span","flatpickr-time-separator",":")),h.timeContainer.appendChild(a)}return h.config.time_24hr||(h.amPM=d("span","flatpickr-am-pm",h.l10n.amPM[o((h.latestSelectedDateObj?h.hourElement.value:h.config.defaultHour)>11)]),h.amPM.title=h.l10n.toggleTitle,h.amPM.tabIndex=-1,h.timeContainer.appendChild(h.amPM)),h.timeContainer}()),c(h.calendarContainer,"rangeMode","range"===h.config.mode),c(h.calendarContainer,"animate",!0===h.config.animate),c(h.calendarContainer,"multiMonth",h.config.showMonths>1),h.calendarContainer.appendChild(e);var r=void 0!==h.config.appendTo&&void 0!==h.config.appendTo.nodeType;if((h.config.inline||h.config.static)&&(h.calendarContainer.classList.add(h.config.inline?"inline":"static"),h.config.inline&&(!r&&h.element.parentNode?h.element.parentNode.insertBefore(h.calendarContainer,h._input.nextSibling):void 0!==h.config.appendTo&&h.config.appendTo.appendChild(h.calendarContainer)),h.config.static)){var l=d("div","flatpickr-wrapper");h.element.parentNode&&h.element.parentNode.insertBefore(l,h.element),l.appendChild(h.element),h.altInput&&l.appendChild(h.altInput),l.appendChild(h.calendarContainer)}h.config.static||h.config.inline||(void 0!==h.config.appendTo?h.config.appendTo:window.document.body).appendChild(h.calendarContainer)}(),function(){if(h.config.wrap&&["open","close","toggle","clear"].forEach(function(e){Array.prototype.forEach.call(h.element.querySelectorAll("[data-"+e+"]"),function(t){return F(t,"click",h[e])})}),h.isMobile)!function(){var e=h.config.enableTime?h.config.noCalendar?"time":"datetime-local":"date";h.mobileInput=d("input",h.input.className+" flatpickr-mobile"),h.mobileInput.step=h.input.getAttribute("step")||"any",h.mobileInput.tabIndex=1,h.mobileInput.type=e,h.mobileInput.disabled=h.input.disabled,h.mobileInput.required=h.input.required,h.mobileInput.placeholder=h.input.placeholder,h.mobileFormatStr="datetime-local"===e?"Y-m-d\\TH:i:S":"date"===e?"Y-m-d":"H:i:S",h.selectedDates.length>0&&(h.mobileInput.defaultValue=h.mobileInput.value=h.formatDate(h.selectedDates[0],h.mobileFormatStr)),h.config.minDate&&(h.mobileInput.min=h.formatDate(h.config.minDate,"Y-m-d")),h.config.maxDate&&(h.mobileInput.max=h.formatDate(h.config.maxDate,"Y-m-d")),h.input.type="hidden",void 0!==h.altInput&&(h.altInput.type="hidden");try{h.input.parentNode&&h.input.parentNode.insertBefore(h.mobileInput,h.input.nextSibling)}catch(e){}F(h.mobileInput,"change",function(e){h.setDate(e.target.value,!1,h.mobileFormatStr),ge("onChange"),ge("onClose")})}();else{var e=r(ae,50);h._debouncedChange=r(Y,M),h.daysContainer&&!/iPhone|iPad|iPod/i.test(navigator.userAgent)&&F(h.daysContainer,"mouseover",function(e){"range"===h.config.mode&&ne(e.target)}),F(window.document.body,"keydown",te),h.config.inline||h.config.static||F(window,"resize",e),void 0!==window.ontouchstart?F(window.document,"touchstart",Z):F(window.document,"mousedown",N(Z)),F(window.document,"focus",Z,{capture:!0}),!0===h.config.clickOpens&&(F(h._input,"focus",h.open),F(h._input,"mousedown",N(h.open))),void 0!==h.daysContainer&&(F(h.monthNav,"mousedown",N(be)),F(h.monthNav,["keyup","increment"],_),F(h.daysContainer,"mousedown",N(se))),void 0!==h.timeContainer&&void 0!==h.minuteElement&&void 0!==h.hourElement&&(F(h.timeContainer,["increment"],T),F(h.timeContainer,"blur",T,{capture:!0}),F(h.timeContainer,"mousedown",N(P)),F([h.hourElement,h.minuteElement],["focus","click"],function(e){return e.target.select()}),void 0!==h.secondElement&&F(h.secondElement,"focus",function(){return h.secondElement&&h.secondElement.select()}),void 0!==h.amPM&&F(h.amPM,"mousedown",N(function(e){T(e),Y()})))}}(),(h.selectedDates.length||h.config.noCalendar)&&(h.config.enableTime&&I(h.config.noCalendar?h.latestSelectedDateObj||h.config.minDate:void 0),we(!1)),x(),h.showTimeInput=h.selectedDates.length>0||h.config.noCalendar;var a=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);!h.isMobile&&a&&le(),ge("onReady")}(),h}function x(e,t){for(var n=Array.prototype.slice.call(e).filter(function(e){return e instanceof HTMLElement}),a=[],i=0;iprovideHook('DbMigration', '\\Icinga\\Module\\Reporting\\ProvidedHook\\DbMigration'); + $this->provideHook('reporting/Report', '\\Icinga\\Module\\Reporting\\Reports\\SystemReport'); $this->provideHook('reporting/Action', '\\Icinga\\Module\\Reporting\\Actions\\SendMail'); diff --git a/schema/mysql-migrations/v0.10.0.sql b/schema/mysql-migrations/v0.10.0.sql deleted file mode 100644 index 638135b..0000000 --- a/schema/mysql-migrations/v0.10.0.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE template ( - id int(10) unsigned NOT NULL AUTO_INCREMENT, - author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, - name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci, - settings longblob NOT NULL, - ctime bigint(20) unsigned NOT NULL, - mtime bigint(20) unsigned NOT NULL, - PRIMARY KEY(id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; - -ALTER TABLE report ADD COLUMN template_id int(10) unsigned NULL DEFAULT NULL AFTER timeframe_id; -ALTER TABLE report ADD CONSTRAINT report_template FOREIGN KEY (template_id) REFERENCES template (id); diff --git a/schema/mysql-migrations/v0.9.1.sql b/schema/mysql-migrations/v0.9.1.sql deleted file mode 100644 index bd71b37..0000000 --- a/schema/mysql-migrations/v0.9.1.sql +++ /dev/null @@ -1,9 +0,0 @@ -UPDATE timeframe SET start = 'first day of January this year midnight' WHERE name = 'Current Year'; -UPDATE timeframe SET start = 'first day of January last year midnight' WHERE name = 'Last Year'; -UPDATE timeframe SET ctime = UNIX_TIMESTAMP() * 1000, mtime = UNIX_TIMESTAMP() * 1000; - -ALTER TABLE timeframe MODIFY COLUMN name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci; -ALTER TABLE timeframe ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=default; - -ALTER TABLE report MODIFY COLUMN name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci; -ALTER TABLE report ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=default; diff --git a/schema/mysql-upgrades/0.10.0.sql b/schema/mysql-upgrades/0.10.0.sql new file mode 100644 index 0000000..638135b --- /dev/null +++ b/schema/mysql-upgrades/0.10.0.sql @@ -0,0 +1,12 @@ +CREATE TABLE template ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, + name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci, + settings longblob NOT NULL, + ctime bigint(20) unsigned NOT NULL, + mtime bigint(20) unsigned NOT NULL, + PRIMARY KEY(id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +ALTER TABLE report ADD COLUMN template_id int(10) unsigned NULL DEFAULT NULL AFTER timeframe_id; +ALTER TABLE report ADD CONSTRAINT report_template FOREIGN KEY (template_id) REFERENCES template (id); diff --git a/schema/mysql-upgrades/0.9.1.sql b/schema/mysql-upgrades/0.9.1.sql new file mode 100644 index 0000000..bd71b37 --- /dev/null +++ b/schema/mysql-upgrades/0.9.1.sql @@ -0,0 +1,9 @@ +UPDATE timeframe SET start = 'first day of January this year midnight' WHERE name = 'Current Year'; +UPDATE timeframe SET start = 'first day of January last year midnight' WHERE name = 'Last Year'; +UPDATE timeframe SET ctime = UNIX_TIMESTAMP() * 1000, mtime = UNIX_TIMESTAMP() * 1000; + +ALTER TABLE timeframe MODIFY COLUMN name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci; +ALTER TABLE timeframe ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=default; + +ALTER TABLE report MODIFY COLUMN name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci; +ALTER TABLE report ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=default; diff --git a/schema/mysql-upgrades/1.0.0.sql b/schema/mysql-upgrades/1.0.0.sql new file mode 100644 index 0000000..5b1d2b5 --- /dev/null +++ b/schema/mysql-upgrades/1.0.0.sql @@ -0,0 +1,64 @@ +DROP PROCEDURE IF EXISTS migrate_schedule_config; +DELIMITER // +CREATE PROCEDURE migrate_schedule_config() +BEGIN + DECLARE session_time_zone text; + + DECLARE schedule_id int; + DECLARE schedule_start bigint; + DECLARE schedule_frequency enum('minutely', 'hourly', 'daily', 'weekly', 'monthly'); + DECLARE schedule_config text; + + DECLARE frequency_json text; + + DECLARE done int DEFAULT 0; + DECLARE schedule CURSOR FOR SELECT id, start, frequency, config FROM schedule; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + -- Determine the current session time zone name + SELECT IF(@@session.TIME_ZONE = 'SYSTEM', @@system_time_zone, @@session.TIME_ZONE) INTO session_time_zone; + + IF session_time_zone NOT LIKE '+%:%' AND session_time_zone NOT LIKE '-%:%' AND CONVERT_TZ(FROM_UNIXTIME(1699903042), session_time_zone, '+00:00') IS NULL THEN + SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'required named time zone information are not populated into mysql/mariadb'; + END IF; + + OPEN schedule; + read_loop: LOOP + FETCH schedule INTO schedule_id, schedule_start, schedule_frequency, schedule_config; + IF done THEN + LEAVE read_loop; + END IF; + IF NOT INSTR(schedule_config, 'frequencyType') THEN + SET frequency_json = CONCAT( + ',"frequencyType":"\\\\ipl\\\\Scheduler\\\\Cron","frequency":"{', + '\\"expression\\":\\"@', schedule_frequency, + '\\",\\"start\\":\\"', DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(schedule_start / 1000), session_time_zone, '+00:00'), '%Y-%m-%dT%H:%i:%s.%f UTC'), + '\\"}"' + ); + UPDATE schedule SET config = INSERT(schedule_config, LENGTH(schedule_config), 0, frequency_json) WHERE id = schedule_id; + END IF; + END LOOP; + CLOSE schedule; +END // +DELIMITER ; + +CALL migrate_schedule_config(); +DROP PROCEDURE migrate_schedule_config; + +ALTER TABLE schedule + DROP COLUMN start, + DROP COLUMN frequency; + +CREATE TABLE reporting_schema ( + id int unsigned NOT NULL AUTO_INCREMENT, + version varchar(64) NOT NULL, + timestamp bigint unsigned NOT NULL, + success enum ('n', 'y') DEFAULT NULL, + reason text DEFAULT NULL, + + PRIMARY KEY (id), + CONSTRAINT idx_reporting_schema_version UNIQUE (version) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC; + +INSERT INTO reporting_schema (version, timestamp, success, reason) + VALUES ('1.0.0', UNIX_TIMESTAMP() * 1000, 'y', NULL); diff --git a/schema/mysql.schema.sql b/schema/mysql.schema.sql new file mode 100644 index 0000000..bd231bc --- /dev/null +++ b/schema/mysql.schema.sql @@ -0,0 +1,108 @@ +CREATE TABLE template ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, + name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci, + settings longblob NOT NULL, + ctime bigint(20) unsigned NOT NULL, + mtime bigint(20) unsigned NOT NULL, + PRIMARY KEY(id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE timeframe ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci, + title varchar(255) NULL DEFAULT NULL COLLATE utf8mb4_unicode_ci, + start varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, + end varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, + ctime bigint(20) unsigned NOT NULL, + mtime bigint(20) unsigned NOT NULL, + PRIMARY KEY(id), + UNIQUE KEY timeframe (name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +INSERT INTO timeframe (name, title, start, end, ctime, mtime) VALUES + ('4 Hours', null, '-4 hours', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('25 Hours', null, '-25 hours', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('One Week', null, '-1 week', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('One Month', null, '-1 month', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('One Year', null, '-1 year', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Current Day', null, 'midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Last Day', null, 'yesterday midnight', 'yesterday 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Current Week', null, 'monday this week midnight', 'sunday this week 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Last Week', null, 'monday last week midnight', 'sunday last week 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Current Month', null, 'first day of this month midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Last Month', null, 'first day of last month midnight', 'last day of last month 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Current Year', null, 'first day of January this year midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('Last Year', null, 'first day of January last year midnight', 'last day of December last year 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000); + +CREATE TABLE report ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + timeframe_id int(10) unsigned NOT NULL, + template_id int(10) unsigned NULL DEFAULT NULL, + author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, + name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci, + ctime bigint(20) unsigned NOT NULL, + mtime bigint(20) unsigned NOT NULL, + PRIMARY KEY(id), + UNIQUE KEY report (name), + CONSTRAINT report_timeframe FOREIGN KEY (timeframe_id) REFERENCES timeframe (id), + CONSTRAINT report_template FOREIGN KEY (template_id) REFERENCES template (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE reportlet ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + report_id int(10) unsigned NOT NULL, + class varchar(255) NOT NULL, + ctime bigint(20) unsigned NOT NULL, + mtime bigint(20) unsigned NOT NULL, + PRIMARY KEY(id), + CONSTRAINT reportlet_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE config ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + reportlet_id int(10) unsigned NOT NULL, + name varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, + value text NULL DEFAULT NULL, + ctime bigint(20) unsigned NOT NULL, + mtime bigint(20) unsigned NOT NULL, + PRIMARY KEY(id), + CONSTRAINT config_reportlet FOREIGN KEY (reportlet_id) REFERENCES reportlet (id) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE schedule ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + report_id int(10) unsigned NOT NULL, + author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, + action varchar(255) NOT NULL, + config text NULL DEFAULT NULL, + ctime bigint(20) unsigned NOT NULL, + mtime bigint(20) unsigned NOT NULL, + PRIMARY KEY(id), + CONSTRAINT schedule_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE reporting_schema ( + id int unsigned NOT NULL AUTO_INCREMENT, + version varchar(64) NOT NULL, + timestamp bigint unsigned NOT NULL, + success enum ('n', 'y') DEFAULT NULL, + reason text DEFAULT NULL, + + PRIMARY KEY (id), + CONSTRAINT idx_reporting_schema_version UNIQUE (version) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC; + +INSERT INTO reporting_schema (version, timestamp, success) + VALUES ('1.0.0', UNIX_TIMESTAMP() * 1000, 'y'); + +-- CREATE TABLE share ( +-- id int(10) unsigned NOT NULL AUTO_INCREMENT, +-- report_id int(10) unsigned NOT NULL, +-- username varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, +-- restriction enum('none', 'owner', 'consumer'), +-- ctime bigint(20) unsigned NOT NULL, +-- mtime bigint(20) unsigned NOT NULL, +-- PRIMARY KEY(id), +-- CONSTRAINT share_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE +-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/schema/mysql.sql b/schema/mysql.sql deleted file mode 100644 index 5f70481..0000000 --- a/schema/mysql.sql +++ /dev/null @@ -1,96 +0,0 @@ -CREATE TABLE template ( - id int(10) unsigned NOT NULL AUTO_INCREMENT, - author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, - name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci, - settings longblob NOT NULL, - ctime bigint(20) unsigned NOT NULL, - mtime bigint(20) unsigned NOT NULL, - PRIMARY KEY(id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; - -CREATE TABLE timeframe ( - id int(10) unsigned NOT NULL AUTO_INCREMENT, - name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci, - title varchar(255) NULL DEFAULT NULL COLLATE utf8mb4_unicode_ci, - start varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, - end varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, - ctime bigint(20) unsigned NOT NULL, - mtime bigint(20) unsigned NOT NULL, - PRIMARY KEY(id), - UNIQUE KEY timeframe (name) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; - -INSERT INTO timeframe (name, title, start, end, ctime, mtime) VALUES - ('4 Hours', null, '-4 hours', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('25 Hours', null, '-25 hours', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('One Week', null, '-1 week', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('One Month', null, '-1 month', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('One Year', null, '-1 year', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('Current Day', null, 'midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('Last Day', null, 'yesterday midnight', 'yesterday 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('Current Week', null, 'monday this week midnight', 'sunday this week 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('Last Week', null, 'monday last week midnight', 'sunday last week 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('Current Month', null, 'first day of this month midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('Last Month', null, 'first day of last month midnight', 'last day of last month 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('Current Year', null, 'first day of January this year midnight', 'now', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('Last Year', null, 'first day of January last year midnight', 'last day of December last year 23:59:59', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000); - -CREATE TABLE report ( - id int(10) unsigned NOT NULL AUTO_INCREMENT, - timeframe_id int(10) unsigned NOT NULL, - template_id int(10) unsigned NULL DEFAULT NULL, - author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, - name varchar(128) NOT NULL COLLATE utf8mb4_unicode_ci, - ctime bigint(20) unsigned NOT NULL, - mtime bigint(20) unsigned NOT NULL, - PRIMARY KEY(id), - UNIQUE KEY report (name), - CONSTRAINT report_timeframe FOREIGN KEY (timeframe_id) REFERENCES timeframe (id), - CONSTRAINT report_template FOREIGN KEY (template_id) REFERENCES template (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; - -CREATE TABLE reportlet ( - id int(10) unsigned NOT NULL AUTO_INCREMENT, - report_id int(10) unsigned NOT NULL, - class varchar(255) NOT NULL, - ctime bigint(20) unsigned NOT NULL, - mtime bigint(20) unsigned NOT NULL, - PRIMARY KEY(id), - CONSTRAINT reportlet_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; - -CREATE TABLE config ( - id int(10) unsigned NOT NULL AUTO_INCREMENT, - reportlet_id int(10) unsigned NOT NULL, - name varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, - value text NULL DEFAULT NULL, - ctime bigint(20) unsigned NOT NULL, - mtime bigint(20) unsigned NOT NULL, - PRIMARY KEY(id), - CONSTRAINT config_reportlet FOREIGN KEY (reportlet_id) REFERENCES reportlet (id) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; - -CREATE TABLE schedule ( - id int(10) unsigned NOT NULL AUTO_INCREMENT, - report_id int(10) unsigned NOT NULL, - author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, - start bigint(20) unsigned NOT NULL, - frequency enum('minutely', 'hourly', 'daily', 'weekly', 'monthly'), - action varchar(255) NOT NULL, - config text NULL DEFAULT NULL, - ctime bigint(20) unsigned NOT NULL, - mtime bigint(20) unsigned NOT NULL, - PRIMARY KEY(id), - CONSTRAINT schedule_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; - --- CREATE TABLE share ( --- id int(10) unsigned NOT NULL AUTO_INCREMENT, --- report_id int(10) unsigned NOT NULL, --- username varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci, --- restriction enum('none', 'owner', 'consumer'), --- ctime bigint(20) unsigned NOT NULL, --- mtime bigint(20) unsigned NOT NULL, --- PRIMARY KEY(id), --- CONSTRAINT share_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE --- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/schema/pgsql-upgrades/1.0.0.sql b/schema/pgsql-upgrades/1.0.0.sql new file mode 100644 index 0000000..0bf3c35 --- /dev/null +++ b/schema/pgsql-upgrades/1.0.0.sql @@ -0,0 +1,44 @@ +CREATE OR REPLACE PROCEDURE migrate_schedule_config() + LANGUAGE plpgsql + AS $$ + DECLARE + row record; + frequency_json text; + BEGIN + FOR row IN (SELECT id, start, frequency, config FROM schedule) + LOOP + IF NOT CAST(POSITION('frequencyType' IN row.config) AS bool) THEN + frequency_json = CONCAT( + ',"frequencyType":"\\ipl\\Scheduler\\Cron","frequency":"{', + '\"expression\":\"@', row.frequency, + '\",\"start\":\"', TO_CHAR(TO_TIMESTAMP(row.start / 1000) AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US UTC'), + '\"}"' + ); + UPDATE schedule SET config = OVERLAY(row.config PLACING frequency_json FROM LENGTH(row.config) FOR 0) WHERE id = row.id; + END IF; + END LOOP; + END; + $$; + +CALL migrate_schedule_config(); +DROP PROCEDURE migrate_schedule_config; + +ALTER TABLE schedule + DROP COLUMN start, + DROP COLUMN frequency; + +CREATE TYPE boolenum AS ENUM ('n', 'y'); + +CREATE TABLE reporting_schema ( + id serial, + version varchar(64) NOT NULL, + timestamp bigint NOT NULL, + success boolenum DEFAULT NULL, + reason text DEFAULT NULL, + + CONSTRAINT pk_reporting_schema PRIMARY KEY (id), + CONSTRAINT idx_reporting_schema_version UNIQUE (version) +); + +INSERT INTO reporting_schema (version, timestamp, success, reason) + VALUES ('1.0.0', unix_timestamp() * 1000, 'y', NULL); diff --git a/schema/pgsql.schema.sql b/schema/pgsql.schema.sql new file mode 100644 index 0000000..d20289c --- /dev/null +++ b/schema/pgsql.schema.sql @@ -0,0 +1,95 @@ +CREATE TYPE boolenum AS ENUM ('n', 'y'); + +CREATE OR REPLACE FUNCTION unix_timestamp(timestamp with time zone DEFAULT NOW()) RETURNS bigint + AS 'SELECT EXTRACT(EPOCH FROM $1)::bigint' + LANGUAGE SQL; + +CREATE TABLE template ( + id serial PRIMARY KEY, + author varchar(255) NOT NULL, + name varchar(128) NOT NULL, + settings text NOT NULL, + ctime bigint NOT NULL, + mtime bigint NOT NULL +); + +CREATE TABLE timeframe ( + id serial PRIMARY KEY, + name varchar(128) NOT NULL UNIQUE, + title varchar(255) DEFAULT NULL, + start varchar(255) NOT NULL, + "end" varchar(255) NOT NULL, + ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000 +); + +INSERT INTO timeframe (name, title, start, "end") VALUES + ('4 Hours', null, '-4 hours', 'now'), + ('25 Hours', null, '-25 hours', 'now'), + ('One Week', null, '-1 week', 'now'), + ('One Month', null, '-1 month', 'now'), + ('One Year', null, '-1 year', 'now'), + ('Current Day', null, 'midnight', 'now'), + ('Last Day', null, 'yesterday midnight', 'yesterday 23:59:59'), + ('Current Week', null, 'monday this week midnight', 'sunday this week 23:59:59'), + ('Last Week', null, 'monday last week midnight', 'sunday last week 23:59:59'), + ('Current Month', null, 'first day of this month midnight', 'now'), + ('Last Month', null, 'first day of last month midnight', 'last day of last month 23:59:59'), + ('Current Year', null, 'first day of January this year midnight', 'now'), + ('Last Year', null, 'first day of January last year midnight', 'last day of December last year 23:59:59'); + +CREATE TABLE report ( + id serial PRIMARY KEY, + timeframe_id int NOT NULL, + template_id int NULL DEFAULT NULL, + author varchar(255) NOT NULL, + name varchar(128) NOT NULL UNIQUE, + ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + CONSTRAINT report_timeframe FOREIGN KEY (timeframe_id) REFERENCES timeframe (id), + CONSTRAINT report_template FOREIGN KEY (template_id) REFERENCES template (id) +); + +CREATE TABLE reportlet ( + id serial PRIMARY KEY, + report_id int NOT NULL, + class varchar(255) NOT NULL, + ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + CONSTRAINT reportlet_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE config ( + id serial PRIMARY KEY, + reportlet_id int NOT NULL, + name varchar(255) NOT NULL, + value text DEFAULT NULL, + ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + CONSTRAINT config_reportlet FOREIGN KEY (reportlet_id) REFERENCES reportlet (id) ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE schedule ( + id serial PRIMARY KEY, + report_id int NOT NULL, + author varchar(255) NOT NULL, + action varchar(255) NOT NULL, + config text DEFAULT NULL, + ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000, + CONSTRAINT schedule_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE reporting_schema ( + id serial, + version varchar(64) NOT NULL, + timestamp bigint NOT NULL, + success boolenum DEFAULT NULL, + reason text DEFAULT NULL, + + CONSTRAINT pk_reporting_schema PRIMARY KEY (id), + CONSTRAINT idx_reporting_schema_version UNIQUE (version) +); + +INSERT INTO reporting_schema (version, timestamp, success) + VALUES ('1.0.0', UNIX_TIMESTAMP() * 1000, 'y'); diff --git a/schema/postgresql.sql b/schema/postgresql.sql deleted file mode 100644 index 329a65f..0000000 --- a/schema/postgresql.sql +++ /dev/null @@ -1,83 +0,0 @@ -CREATE OR REPLACE FUNCTION unix_timestamp(timestamp with time zone DEFAULT NOW()) RETURNS bigint - AS 'SELECT EXTRACT(EPOCH FROM $1)::bigint' - LANGUAGE SQL; - -CREATE TYPE frequency AS ENUM ('minutely', 'hourly', 'daily', 'weekly', 'monthly'); - -CREATE TABLE template ( - id serial PRIMARY KEY, - author varchar(255) NOT NULL, - name varchar(128) NOT NULL, - settings text NOT NULL, - ctime bigint NOT NULL, - mtime bigint NOT NULL -); - -CREATE TABLE timeframe ( - id serial PRIMARY KEY, - name varchar(128) NOT NULL UNIQUE, - title varchar(255) DEFAULT NULL, - start varchar(255) NOT NULL, - "end" varchar(255) NOT NULL, - ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000 -); - -INSERT INTO timeframe (name, title, start, "end") VALUES - ('4 Hours', null, '-4 hours', 'now'), - ('25 Hours', null, '-25 hours', 'now'), - ('One Week', null, '-1 week', 'now'), - ('One Month', null, '-1 month', 'now'), - ('One Year', null, '-1 year', 'now'), - ('Current Day', null, 'midnight', 'now'), - ('Last Day', null, 'yesterday midnight', 'yesterday 23:59:59'), - ('Current Week', null, 'monday this week midnight', 'sunday this week 23:59:59'), - ('Last Week', null, 'monday last week midnight', 'sunday last week 23:59:59'), - ('Current Month', null, 'first day of this month midnight', 'now'), - ('Last Month', null, 'first day of last month midnight', 'last day of last month 23:59:59'), - ('Current Year', null, 'first day of January this year midnight', 'now'), - ('Last Year', null, 'first day of January last year midnight', 'last day of December last year 23:59:59'); - -CREATE TABLE report ( - id serial PRIMARY KEY, - timeframe_id int NOT NULL, - template_id int NULL DEFAULT NULL, - author varchar(255) NOT NULL, - name varchar(128) NOT NULL UNIQUE, - ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - CONSTRAINT report_timeframe FOREIGN KEY (timeframe_id) REFERENCES timeframe (id), - CONSTRAINT report_template FOREIGN KEY (template_id) REFERENCES template (id) -); - -CREATE TABLE reportlet ( - id serial PRIMARY KEY, - report_id int NOT NULL, - class varchar(255) NOT NULL, - ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - CONSTRAINT reportlet_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE -); - -CREATE TABLE config ( - id serial PRIMARY KEY, - reportlet_id int NOT NULL, - name varchar(255) NOT NULL, - value text DEFAULT NULL, - ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - CONSTRAINT config_reportlet FOREIGN KEY (reportlet_id) REFERENCES reportlet (id) ON DELETE CASCADE ON UPDATE CASCADE -); - -CREATE TABLE schedule ( - id serial PRIMARY KEY, - report_id int NOT NULL, - author varchar(255) NOT NULL, - start bigint NOT NULL, - frequency frequency, - action varchar(255) NOT NULL, - config text DEFAULT NULL, - ctime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - mtime bigint NOT NULL DEFAULT unix_timestamp() * 1000, - CONSTRAINT schedule_report FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE ON UPDATE CASCADE -); -- cgit v1.2.3