diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:46:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:46:47 +0000 |
commit | 4ada86876033fa171e2896d7e3d3c5645d8062db (patch) | |
tree | f0d1fee61877df200ccfb1c0af58a39cd551fb46 | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-reporting-upstream/0.10.0.tar.xz icingaweb2-module-reporting-upstream/0.10.0.zip |
Adding upstream version 0.10.0.upstream/0.10.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
77 files changed, 8937 insertions, 0 deletions
diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..d1d0ed7 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<ruleset name="PHP_CodeSniffer"> + <description>Sniff our code a while</description> + + <file>./</file> + + <exclude-pattern>vendor/*</exclude-pattern> + + <arg value="wps"/> + <arg name="report-width" value="auto"/> + <arg name="report-full"/> + <arg name="report-gitblame"/> + <arg name="report-summary"/> + <arg name="encoding" value="UTF-8"/> + <arg name="extensions" value="php"/> + + <rule ref="PSR2"/> + + <rule ref="Generic.Files.LineLength"> + <properties> + <property name="lineLimit" value="120"/> + <property name="absoluteLineLimit" value="0"/> + </properties> + </rule> +</ruleset> @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License.
\ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c2413f9 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# 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) + +![Icinga Logo](https://icinga.com/wp-content/uploads/2014/06/icinga_logo.png) + +Icinga Reporting is the central component for reporting related functionality in the monitoring web frontend and +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 +[idoreports](https://github.com/Icinga/icingaweb2-module-idoreports) module. + +## Documentation + +* [Installation](doc/02-Installation.md) diff --git a/application/clicommands/ScheduleCommand.php b/application/clicommands/ScheduleCommand.php new file mode 100644 index 0000000..e554138 --- /dev/null +++ b/application/clicommands/ScheduleCommand.php @@ -0,0 +1,24 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Clicommands; + +use Icinga\Module\Reporting\Cli\Command; +use Icinga\Module\Reporting\Scheduler; + +class ScheduleCommand extends Command +{ + /** + * Run all configured reports based on their schedule + * + * USAGE: + * + * icingacli reporting schedule run + */ + public function runAction() + { + $scheduler = new Scheduler($this->getDb()); + + $scheduler->run(); + } +} diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php new file mode 100644 index 0000000..30fcc67 --- /dev/null +++ b/application/controllers/ConfigController.php @@ -0,0 +1,41 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use Icinga\Application\Config; +use Icinga\Module\Reporting\Forms\ConfigureMailForm; +use Icinga\Module\Reporting\Forms\SelectBackendForm; +use Icinga\Web\Controller; + +class ConfigController extends Controller +{ + public function init() + { + $this->assertPermission('config/modules'); + + parent::init(); + } + + public function backendAction() + { + $form = (new SelectBackendForm()) + ->setIniConfig(Config::module('reporting')); + + $form->handleRequest(); + + $this->view->tabs = $this->Module()->getConfigTabs()->activate('backend'); + $this->view->form = $form; + } + + public function mailAction() + { + $form = (new ConfigureMailForm()) + ->setIniConfig(Config::module('reporting')); + + $form->handleRequest(); + + $this->view->tabs = $this->Module()->getConfigTabs()->activate('mail'); + $this->view->form = $form; + } +} diff --git a/application/controllers/PlugController.php.disabled b/application/controllers/PlugController.php.disabled new file mode 100644 index 0000000..a2c6453 --- /dev/null +++ b/application/controllers/PlugController.php.disabled @@ -0,0 +1,72 @@ +<?php + +namespace Icinga\Module\Reporting\Controllers; + +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Reporting\Hook\ReportHook; +use Icinga\Module\Reporting\Web\Forms\ReportForm; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Web\Hook; +use Icinga\Web\Url; +use ipl\Html\Html; + +class PlugController extends Controller +{ + public function indexAction() + { + $moduleToShow = strtolower($this->params->get('module', 'reporting')); + + $reportsByModule = []; + + foreach (ReportHook::getReports() as $class => $report) { + $moduleName = $report->getModuleName(); + + if (! isset($reportsByModule[$moduleName])) { + $reportsByModule[$moduleName] = []; + } + + $reportsByModule[$moduleName][$class] = $report; + } + + $editor = Html::tag('div', ['class' => 'editor']); + + $nav = []; + + $cards = []; + + foreach ($reportsByModule as $moduleName => $reports) { + $link = Html::tag('a', ['href' => Url::fromRequest(['module' => $moduleName])], $moduleName); + + $nav[] = $link; + + if ($moduleName !== $moduleToShow) { + continue; + } + + $link->getAttributes()->add('class', 'active'); + + foreach ($reports as $report) { + $cards[] = Html::tag( + 'div', + ['class' => 'card'], + [ + Html::tag('div', ['class' => 'card-top'], $report->getPreview()), + Html::tag( + 'div', + ['class' => 'card-content'], + Html::tag('h5', ['class' => 'card-title'], $report->getName()), + Html::tag('p', ['class' => 'card-text'], $report->getDescription()) + ) + ] + ); + } + } + + $editor->add(Html::tag('div', ['class' => 'editor-nav'], $nav)); + $editor->add(Html::tag('div', ['class' => 'editor-content'], $cards)); + + $this->addContent($editor); + + $this->addContent(Html::tag('a', ['href' => 'plug', 'class' => 'modal-toggle', 'data-base-target' => 'modal-container'], 'Modal')); + } +} diff --git a/application/controllers/ReportController.php b/application/controllers/ReportController.php new file mode 100644 index 0000000..090c759 --- /dev/null +++ b/application/controllers/ReportController.php @@ -0,0 +1,208 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Application\Hook; +use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Report; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Module\Reporting\Web\Forms\ReportForm; +use Icinga\Module\Reporting\Web\Forms\ScheduleForm; +use Icinga\Module\Reporting\Web\Forms\SendForm; +use Icinga\Module\Reporting\Web\Widget\CompatDropdown; +use ipl\Html\Error; +use ipl\Web\Url; +use ipl\Web\Widget\ActionBar; +use Icinga\Util\Environment; + +class ReportController extends Controller +{ + use Database; + + /** @var Report */ + protected $report; + + public function init() + { + $this->report = Report::fromDb($this->params->getRequired('id')); + } + + public function indexAction() + { + $this->addTitleTab($this->report->getName()); + + $this->addControl($this->assembleActions()); + + Environment::raiseExecutionTime(); + Environment::raiseMemoryLimit(); + + try { + $this->addContent($this->report->toHtml()); + } catch (\Exception $e) { + $this->addContent(Error::show($e)); + } + } + + public function editAction() + { + $this->assertPermission('reporting/reports'); + $this->addTitleTab('Edit Report'); + + $values = [ + 'name' => $this->report->getName(), + // TODO(el): Must cast to string here because ipl/html does not + // support integer return values for attribute callbacks + 'timeframe' => (string) $this->report->getTimeframe()->getId(), + ]; + + $reportlet = $this->report->getReportlets()[0]; + + $values['reportlet'] = $reportlet->getClass(); + + foreach ($reportlet->getConfig() as $name => $value) { + $values[$name] = $value; + } + + $form = new ReportForm(); + $form->setId($this->report->getId()); + $form->populate($values); + $form->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, 'reporting/reports'); + + $this->addContent($form); + } + + public function sendAction() + { + $this->addTitleTab('Send Report'); + + Environment::raiseExecutionTime(); + Environment::raiseMemoryLimit(); + + $form = new SendForm(); + $form + ->setReport($this->report) + ->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); + + $this->addContent($form); + } + + 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->addContent($form); + } + + public function downloadAction() + { + $type = $this->params->getRequired('type'); + + Environment::raiseExecutionTime(); + Environment::raiseMemoryLimit(); + + $name = sprintf( + '%s (%s) %s', + $this->report->getName(), + $this->report->getTimeframe()->getName(), + date('Y-m-d H:i') + ); + + switch ($type) { + case 'pdf': + /** @var Hook\PdfexportHook */ + Pdfexport::first()->streamPdfFromHtml($this->report->toPdf(), $name); + exit; + case 'csv': + $response = $this->getResponse(); + $response + ->setHeader('Content-Type', 'text/csv') + ->setHeader('Cache-Control', 'no-store') + ->setHeader( + 'Content-Disposition', + 'attachment; filename=' . $name . '.csv' + ) + ->appendBody($this->report->toCsv()) + ->sendResponse(); + exit; + case 'json': + $response = $this->getResponse(); + $response + ->setHeader('Content-Type', 'application/json') + ->setHeader('Cache-Control', 'no-store') + ->setHeader( + 'Content-Disposition', + 'inline; filename=' . $name . '.json' + ) + ->appendBody($this->report->toJson()) + ->sendResponse(); + exit; + } + } + + protected function assembleActions() + { + $reportId = $this->report->getId(); + + $download = (new CompatDropdown('Download')) + ->addLink( + 'PDF', + Url::fromPath('reporting/report/download?type=pdf', ['id' => $reportId]), + null, + ['target' => '_blank'] + ); + + if ($this->report->providesData()) { + $download->addLink( + 'CSV', + Url::fromPath('reporting/report/download?type=csv', ['id' => $reportId]), + null, + ['target' => '_blank'] + ); + $download->addLink( + 'JSON', + Url::fromPath('reporting/report/download?type=json', ['id' => $reportId]), + null, + ['target' => '_blank'] + ); + } + + $actions = new ActionBar(); + + if ($this->hasPermission('reporting/reports')) { + $actions->addLink( + 'Modify', + Url::fromPath('reporting/report/edit', ['id' => $reportId]), + 'edit' + ); + } + + if ($this->hasPermission('reporting/schedules')) { + $actions->addLink( + 'Schedule', + Url::fromPath('reporting/report/schedule', ['id' => $reportId]), + 'calendar-empty' + ); + } + + $actions + ->add($download) + ->addLink('Send', Url::fromPath('reporting/report/send', ['id' => $reportId]), 'forward'); + + return $actions; + } +} diff --git a/application/controllers/ReportController.php.modal b/application/controllers/ReportController.php.modal new file mode 100644 index 0000000..915bf2b --- /dev/null +++ b/application/controllers/ReportController.php.modal @@ -0,0 +1,126 @@ +<?php + +namespace Icinga\Module\Reporting\Controllers; + +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Report; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Module\Reporting\Web\Forms\ReportForm; +use Icinga\Module\Reporting\Web\Forms\ScheduleForm; +use Icinga\Module\Reporting\Web\Forms\SendForm; +use ipl\Web\Widget\ModalToggle; +use ipl\Web\Widget\Modal; +use reportingipl\Web\Url; +use reportingipl\Web\Widget\ActionBar; +use reportingipl\Web\Widget\DropdownLink; + +class ReportController extends Controller +{ + use Database; + + /** @var Report */ + protected $report; + + public function init() + { + $this->report = Report::fromDb($this->params->getRequired('id')); + } + + public function indexAction() + { + $this->setTitle($this->report->getName()); + + $this->addControl($this->assembleActions()); + + $this->addContent($this->report->toHtml()); + } + + public function editAction() + { + $this->setTitle('Edit Report'); + + $values = [ + 'name' => $this->report->getName(), + 'timeframe' => $this->report->getTimeframe()->getId(), + ]; + + $reportlet = $this->report->getReportlets()[0]; + + $values['reportlet'] = $reportlet->getClass(); + + foreach ($reportlet->getConfig() as $name => $value) { + $values[$name] = $value; + } + + $form = new ReportForm(); + $form->setId($this->report->getId()); + $form->populate($values); + $form->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, 'reporting/reports'); + + $this->addContent($form); + } + + public function sendAction() + { + $this->setTitle('Send Report'); + + $form = new SendForm(); + $form + ->setReport($this->report) + ->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); + + $this->addContent(new Modal($form)); + } + + public function scheduleAction() + { + $this->setTitle('Schedule'); + + $form = new ScheduleForm(); + $form + ->setReport($this->report) + ->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); + + $this->addContent(new Modal($form)); + + $this->getResponse()->setHeader('X-Icinga-History', 'no', true); + } + + protected function assembleActions() + { + $reportId = $this->report->getId(); + + $download = (new DropdownLink('Download')) + ->addLink('PDF', Url::fromPath('reporting/report/download?type=pdf', ['id' => $reportId])); + + $send = (new DropdownLink('Send', 'forward')) + ->addLink('PDF', Url::fromPath('reporting/report/send?type=pdf', ['id' => $reportId])); + + if ($this->report->providesCsv()) { + $download->addLink('CSV', Url::fromPath('reporting/report/download?type=csv', ['id' => $reportId])); + $send->addLink('CSV', Url::fromPath('reporting/report/send?type=csv', ['id' => $reportId])); + } + + if ($this->report->providesJson()) { + $download->addLink('JSON', Url::fromPath('reporting/report/download?type=json', ['id' => $reportId])); + $send->addLink('JSON', Url::fromPath('reporting/report/send?type=json', ['id' => $reportId])); + } + + $actions = new ActionBar(); + + $actions + ->addLink('Modify', Url::fromPath('reporting/report/edit', ['id' => $reportId]), 'edit') + ->add(new ModalToggle('Schedule', Url::fromPath('reporting/report/schedule', ['id' => $reportId]), 'calendar-empty')) + ->add($download) + ->addLink('Send', Url::fromPath('reporting/report/send', ['id' => $reportId]), 'forward'); + + return $actions; + } +} diff --git a/application/controllers/ReportsController.php b/application/controllers/ReportsController.php new file mode 100644 index 0000000..7971897 --- /dev/null +++ b/application/controllers/ReportsController.php @@ -0,0 +1,104 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Module\Reporting\Web\Forms\ReportForm; +use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs; +use ipl\Html\Html; +use ipl\Sql\Select; +use ipl\Web\Url; +use ipl\Web\Widget\ButtonLink; +use ipl\Web\Widget\Icon; +use ipl\Web\Widget\Link; + +class ReportsController extends Controller +{ + use Database; + use ReportsTimeframesAndTemplatesTabs; + + public function indexAction() + { + $this->createTabs()->activate('reports'); + + if ($this->hasPermission('reporting/reports')) { + $this->addControl(new ButtonLink( + $this->translate('New Report'), + Url::fromPath('reporting/reports/new'), + 'plus' + )); + } + + $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); + + foreach ($this->getDb()->select($select) 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]) + ) + ]) + ]); + } + + if (! empty($tableRows)) { + $table = Html::tag( + 'table', + ['class' => 'common-table table-row-selectable', 'data-base-target' => '_next'], + [ + Html::tag( + 'thead', + null, + Html::tag( + 'tr', + null, + [ + Html::tag('th', null, 'Name'), + Html::tag('th', null, 'Author'), + Html::tag('th', null, 'Timeframe'), + Html::tag('th', null, 'Date Created'), + Html::tag('th', null, 'Date Modified'), + Html::tag('th') + ] + ) + ), + Html::tag('tbody', null, $tableRows) + ] + ); + + $this->addContent($table); + } else { + $this->addContent(Html::tag('p', null, 'No reports created yet.')); + } + } + + public function newAction() + { + $this->assertPermission('reporting/reports'); + $this->addTitleTab($this->translate('New Report')); + + $form = new ReportForm(); + $form->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, 'reporting/reports'); + + $this->addContent($form); + } +} diff --git a/application/controllers/TemplateController.php b/application/controllers/TemplateController.php new file mode 100644 index 0000000..bb37b3c --- /dev/null +++ b/application/controllers/TemplateController.php @@ -0,0 +1,89 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use DateTime; +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Module\Reporting\Web\Forms\TemplateForm; +use Icinga\Module\Reporting\Web\Widget\Template; +use ipl\Sql\Select; + +class TemplateController extends Controller +{ + use Database; + + public function indexAction() + { + $this->createTabs()->activate('preview'); + + $template = Template::fromDb($this->params->getRequired('id')); + + if ($template === null) { + throw new \Exception('Template not found'); + } + + $template + ->setMacros([ + 'date' => (new DateTime())->format('jS M, Y'), + 'time_frame' => 'Time Frame', + 'time_frame_absolute' => 'Time Frame (absolute)', + 'title' => 'Icinga Report Preview' + ]) + ->setPreview(true); + + $this->addContent($template); + } + + 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->addContent($form); + } + + protected function createTabs() + { + $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; + } +} diff --git a/application/controllers/TemplatesController.php b/application/controllers/TemplatesController.php new file mode 100644 index 0000000..91a82b1 --- /dev/null +++ b/application/controllers/TemplatesController.php @@ -0,0 +1,106 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Module\Reporting\Web\Forms\TemplateForm; +use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs; +use ipl\Html\Html; +use ipl\Sql\Select; +use ipl\Web\Url; +use ipl\Web\Widget\ButtonLink; +use ipl\Web\Widget\Link; + +class TemplatesController extends Controller +{ + use Database; + use ReportsTimeframesAndTemplatesTabs; + + public function indexAction() + { + $this->createTabs()->activate('templates'); + + $canManage = $this->hasPermission('reporting/templates'); + + if ($canManage) { + $this->addControl(new ButtonLink( + $this->translate('New Template'), + Url::fromPath('reporting/templates/new'), + 'plus' + )); + } + + $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] + ); + } + + $tableRows[] = Html::tag('tr', null, [ + Html::tag('td', null, new Link($template->name, $subjectUrl)), + 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)) + ]); + } + + if (! empty($tableRows)) { + $table = Html::tag( + 'table', + ['class' => 'common-table table-row-selectable', 'data-base-target' => '_next'], + [ + Html::tag( + 'thead', + null, + Html::tag( + 'tr', + null, + [ + Html::tag('th', null, 'Name'), + Html::tag('th', null, 'Author'), + Html::tag('th', null, 'Date Created'), + Html::tag('th', null, 'Date Modified') + ] + ) + ), + Html::tag('tbody', null, $tableRows) + ] + ); + + $this->addContent($table); + } else { + $this->addContent(Html::tag('p', null, 'No templates created yet.')); + } + } + + public function newAction() + { + $this->assertPermission('reporting/templates'); + $this->addTitleTab('New Template'); + + $form = new TemplateForm(); + + $form->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, 'reporting/templates'); + + $this->addContent($form); + } +} diff --git a/application/controllers/TestController.php b/application/controllers/TestController.php new file mode 100644 index 0000000..f666085 --- /dev/null +++ b/application/controllers/TestController.php @@ -0,0 +1,47 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Timeframe; +use Icinga\Module\Reporting\Web\Controller; +use ipl\Html\Table; +use ipl\Sql\Select; + +class TestController extends Controller +{ + use Database; + + public function timeframesAction() + { + $select = (new Select()) + ->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 new file mode 100644 index 0000000..ca67b0b --- /dev/null +++ b/application/controllers/TimeframeController.php @@ -0,0 +1,47 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Timeframe; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Module\Reporting\Web\Forms\TimeframeForm; + +class TimeframeController extends Controller +{ + use Database; + + /** @var Timeframe */ + protected $timeframe; + + public function init() + { + $this->timeframe = Timeframe::fromDb($this->params->getRequired('id')); + } + + public function editAction() + { + $this->assertPermission('reporting/timeframes'); + $this->addTitleTab($this->translate('Edit Time Frame')); + + $values = [ + 'name' => $this->timeframe->getName(), + 'start' => $this->timeframe->getStart(), + 'end' => $this->timeframe->getEnd() + ]; + + + $form = (new TimeframeForm()) + ->setId($this->timeframe->getId()); + + $form->populate($values); + + $form->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, 'reporting/timeframes'); + + $this->addContent($form); + } +} diff --git a/application/controllers/TimeframesController.php b/application/controllers/TimeframesController.php new file mode 100644 index 0000000..505d8d9 --- /dev/null +++ b/application/controllers/TimeframesController.php @@ -0,0 +1,103 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Module\Reporting\Web\Forms\TimeframeForm; +use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs; +use ipl\Html\Html; +use ipl\Sql\Select; +use ipl\Web\Url; +use ipl\Web\Widget\ButtonLink; +use ipl\Web\Widget\Link; + +class TimeframesController extends Controller +{ + use Database; + use ReportsTimeframesAndTemplatesTabs; + + public function indexAction() + { + $this->createTabs()->activate('timeframes'); + + $canManage = $this->hasPermission('reporting/timeframes'); + + if ($canManage) { + $this->addControl(new ButtonLink( + $this->translate('New Timeframe'), + Url::fromPath('reporting/timeframes/new'), + 'plus' + )); + } + + $tableRows = []; + + $select = (new Select()) + ->from('timeframe t') + ->columns('*'); + + foreach ($this->getDb()->select($select) as $timeframe) { + $subject = $timeframe->name; + + if ($canManage) { + $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)) + ]); + } + + if (! empty($tableRows)) { + $table = Html::tag( + 'table', + ['class' => 'common-table table-row-selectable', 'data-base-target' => '_next'], + [ + Html::tag( + 'thead', + null, + Html::tag( + 'tr', + null, + [ + Html::tag('th', null, 'Name'), + Html::tag('th', null, 'Start'), + Html::tag('th', null, 'End'), + Html::tag('th', null, 'Date Created'), + Html::tag('th', null, 'Date Modified') + ] + ) + ), + Html::tag('tbody', null, $tableRows) + ] + ); + + $this->addContent($table); + } else { + $this->addContent(Html::tag('p', null, 'No timeframes created yet.')); + } + } + + public function newAction() + { + $this->assertPermission('reporting/timeframes'); + $this->addTitleTab($this->translate('New Timeframe')); + + $form = new TimeframeForm(); + $form->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, 'reporting/timeframes'); + + $this->addContent($form); + } +} diff --git a/application/forms/ConfigureMailForm.php b/application/forms/ConfigureMailForm.php new file mode 100644 index 0000000..c27c934 --- /dev/null +++ b/application/forms/ConfigureMailForm.php @@ -0,0 +1,23 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Forms; + +use Icinga\Forms\ConfigForm; + +class ConfigureMailForm extends ConfigForm +{ + public function init() + { + $this->setName('reporting_mail'); + $this->setSubmitLabel($this->translate('Save Changes')); + } + + public function createElements(array $formData) + { + $this->addElement('text', 'mail_from', [ + 'label' => $this->translate('From'), + 'placeholder' => 'reporting@icinga' + ]); + } +} diff --git a/application/forms/SelectBackendForm.php b/application/forms/SelectBackendForm.php new file mode 100644 index 0000000..4ba9610 --- /dev/null +++ b/application/forms/SelectBackendForm.php @@ -0,0 +1,35 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Forms; + +use Icinga\Data\ResourceFactory; +use Icinga\Forms\ConfigForm; + +class SelectBackendForm extends ConfigForm +{ + public function init() + { + $this->setName('reporting_backend'); + $this->setSubmitLabel($this->translate('Save Changes')); + } + + public function createElements(array $formData) + { + $dbResources = ResourceFactory::getResourceConfigs('db')->keys(); + $options = array_combine($dbResources, $dbResources); + + $default = null; + if (isset($options['reporting'])) { + $default = 'reporting'; + } + + $this->addElement('select', 'backend_resource', [ + 'label' => $this->translate('Database'), + 'description' => $this->translate('Database resource'), + 'multiOptions' => $options, + 'value' => $default, + 'required' => true + ]); + } +} diff --git a/application/views/scripts/config/backend.phtml b/application/views/scripts/config/backend.phtml new file mode 100644 index 0000000..2574402 --- /dev/null +++ b/application/views/scripts/config/backend.phtml @@ -0,0 +1,6 @@ +<div class="controls"> + <?= /** @var \Icinga\Web\Widget\Tabs $tabs */ $tabs ?> +</div> +<div class="content"> + <?= /** @var \Icinga\Module\Reporting\Forms\SelectBackendForm $form */ $form ?> +</div> diff --git a/application/views/scripts/config/mail.phtml b/application/views/scripts/config/mail.phtml new file mode 100644 index 0000000..d647a82 --- /dev/null +++ b/application/views/scripts/config/mail.phtml @@ -0,0 +1,6 @@ +<div class="controls"> + <?= /** @var \Icinga\Web\Widget\Tabs $tabs */ $tabs ?> +</div> +<div class="content"> + <?= /** @var \Icinga\Module\Reporting\Forms\ConfigureMailForm $form */ $form ?> +</div> diff --git a/config/systemd/icinga-reporting.service b/config/systemd/icinga-reporting.service new file mode 100644 index 0000000..51cc155 --- /dev/null +++ b/config/systemd/icinga-reporting.service @@ -0,0 +1,10 @@ +[Unit] +Description=Icinga Reporting Scheduler + +[Service] +Type=simple +ExecStart=/usr/bin/icingacli reporting schedule run +Restart=on-success + +[Install] +WantedBy=multi-user.target diff --git a/configuration.php b/configuration.php new file mode 100644 index 0000000..bb5b2e6 --- /dev/null +++ b/configuration.php @@ -0,0 +1,52 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting { + + use Icinga\Application\Version; + + /** @var \Icinga\Application\Modules\Module $this */ + + $this->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', + )); + + $this->provideConfigTab('backend', array( + 'title' => $this->translate('Configure the database backend'), + 'label' => $this->translate('Backend'), + 'url' => 'config/backend' + )); + + $this->provideConfigTab('mail', array( + 'title' => $this->translate('Configure mail'), + 'label' => $this->translate('Mail'), + 'url' => 'config/mail' + )); + + $this->providePermission( + 'reporting/reports', + $this->translate('Allow managing reports') + ); + + $this->providePermission( + 'reporting/schedules', + $this->translate('Allow managing schedules') + ); + + $this->providePermission( + 'reporting/templates', + $this->translate('Allow managing templates') + ); + + $this->providePermission( + 'reporting/timeframes', + $this->translate('Allow managing timeframes') + ); +} diff --git a/doc/02-Installation.md b/doc/02-Installation.md new file mode 100644 index 0000000..fe4b8e4 --- /dev/null +++ b/doc/02-Installation.md @@ -0,0 +1,83 @@ +# Installation + +## 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 + +## Database Setup + +### MySQL / MariaDB + +The module needs a MySQL/MariaDB database with the schema that's provided in the `etc/schema/mysql.sql` file. + +Example 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'; +``` + +After, you can import the schema using the following command: + +``` +mysql -p -u root reporting < schema/mysql.sql +``` + +## PostgreSQL + +The module needs a PostgreSQL database with the schema that's provided in the `etc/schema/postgresql.sql` file. + +Example command for creating the PostgreSQL database. Please change the password: + +```sql +CREATE USER reporting WITH PASSWORD 'secret'; +CREATE DATABASE reporting + WITH OWNER reporting + ENCODING 'UTF8' + LC_COLLATE = 'en_US.UTF-8' + LC_CTYPE = 'en_US.UTF-8'; +``` + +After, you can import the schema using the following command: + +``` +psql -U reporting reporting -a -f schema/postgresql.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 new file mode 100644 index 0000000..f06481c --- /dev/null +++ b/doc/03-Configuration.md @@ -0,0 +1,33 @@ +# Configuration + +1. [Backend](#backend) +2. [Mail](#mail) +3. [Permissions](#permissions) + +## Backend + +If not already done during the installation of Icinga Reporting, setup the reporting database backend now. + +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. + +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. + +## Mail + +At `Configuration -> Modules -> reporting -> Mail` you can configure the address +that is used as the sender's address (From) in E-mails. + +## Permissions + +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) diff --git a/doc/80-Upgrading.md b/doc/80-Upgrading.md new file mode 100644 index 0000000..8252e6f --- /dev/null +++ b/doc/80-Upgrading.md @@ -0,0 +1,18 @@ +# Upgrading Icinga Reporting <a id="upgrading"></a> + +Upgrading Icinga Reporting is straightforward. +Usually the only manual steps involved are schema updates for the database. + +## Upgrading to Version 0.9.1 <a id="upgrading-to-v0.9.1"></a> + +Icinga Reporting version 0.9.1 requires a schema update for the database. +The schema has been adjusted so that it is no longer necessary to adjust server settings +if you're using a version of MySQL < 5.7 or MariaDB < 10.2. +Further, the start dates for the provided time frames **Last Year** and **Current Year** have been fixed. +Please find the upgrade script in **schema/mysql-migrations**. + +You may use the following command to apply the database schema upgrade file: + +``` +# mysql -u root -p reporting <schema/mysql-migrations/v0.9.1.sql +``` diff --git a/library/Reporting/Actions/SendMail.php b/library/Reporting/Actions/SendMail.php new file mode 100644 index 0000000..7c70bf5 --- /dev/null +++ b/library/Reporting/Actions/SendMail.php @@ -0,0 +1,84 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Actions; + +use Icinga\Application\Config; +use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport; +use Icinga\Module\Reporting\Hook\ActionHook; +use Icinga\Module\Reporting\Mail; +use Icinga\Module\Reporting\Report; +use ipl\Html\Form; + +class SendMail extends ActionHook +{ + public function getName() + { + return 'Send Mail'; + } + + public function execute(Report $report, array $config) + { + $name = sprintf( + '%s (%s) %s', + $report->getName(), + $report->getTimeframe()->getName(), + date('Y-m-d H:i') + ); + + $mail = new Mail(); + + $mail->setFrom(Config::module('reporting')->get('mail', 'from', 'reporting@icinga')); + + if (isset($config['subject'])) { + $mail->setSubject($config['subject']); + } + + switch ($config['type']) { + case 'pdf': + $mail->attachPdf(Pdfexport::first()->htmlToPdf($report->toPdf()), $name); + + break; + case 'csv': + $mail->attachCsv($report->toCsv(), $name); + + break; + case 'json': + $mail->attachJson($report->toJson(), $name); + + break; + default: + throw new \InvalidArgumentException(); + } + + $recipients = array_filter(preg_split('/[\s,]+/', $config['recipients'])); + + $mail->send(null, $recipients); + } + + public function initConfigForm(Form $form, Report $report) + { + $types = ['pdf' => 'PDF']; + + if ($report->providesData()) { + $types['csv'] = 'CSV'; + $types['json'] = 'JSON'; + } + + $form->addElement('select', 'type', [ + 'required' => true, + 'label' => t('Type'), + 'options' => $types + ]); + + $form->addElement('text', 'subject', [ + 'label' => t('Subject'), + 'placeholder' => Mail::DEFAULT_SUBJECT + ]); + + $form->addElement('textarea', 'recipients', [ + 'required' => true, + 'label' => t('Recipients') + ]); + } +} diff --git a/library/Reporting/Cli/Command.php b/library/Reporting/Cli/Command.php new file mode 100644 index 0000000..a89f77b --- /dev/null +++ b/library/Reporting/Cli/Command.php @@ -0,0 +1,23 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Cli; + +use Icinga\Application\Icinga; +use Icinga\Application\Version; +use Icinga\Module\Reporting\Database; + +class Command extends \Icinga\Cli\Command +{ + use Database; + + // Fix Web 2 issue where $configs is not properly initialized + protected $configs = []; + + public function init() + { + if (version_compare(Version::VERSION, '2.7.0', '<')) { + Icinga::app()->getModuleManager()->loadEnabledModules(); + } + } +} diff --git a/library/Reporting/Common/Macros.php b/library/Reporting/Common/Macros.php new file mode 100644 index 0000000..052cdd2 --- /dev/null +++ b/library/Reporting/Common/Macros.php @@ -0,0 +1,49 @@ +<?php + +namespace Icinga\Module\Reporting\Common; + +trait Macros +{ + protected $macros; + + /** + * @param string $name + * + * @return mixed + */ + public function getMacro($name) + { + return $this->macros[$name] ?: null; + } + + /** + * @return mixed + */ + public function getMacros() + { + return $this->macros; + } + + /** + * @param mixed $macros + * + * @return $this + */ + public function setMacros($macros) + { + $this->macros = $macros; + + return $this; + } + + public function resolveMacros($subject) + { + $macros = []; + + foreach ((array) $this->macros as $key => $value) { + $macros['${' . $key . '}'] = $value; + } + + return str_replace(array_keys($macros), array_values($macros), $subject); + } +} diff --git a/library/Reporting/Database.php b/library/Reporting/Database.php new file mode 100644 index 0000000..3dabe17 --- /dev/null +++ b/library/Reporting/Database.php @@ -0,0 +1,58 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use Icinga\Application\Config; +use Icinga\Data\ResourceFactory; +use ipl\Sql; + +trait Database +{ + protected function getDb($resource = null) + { + $config = new Sql\Config(ResourceFactory::getResourceConfig( + $resource ?: Config::module('reporting')->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'"; + } + + $conn = new RetryConnection($config); + + return $conn; + } + + protected function listTimeframes() + { + $select = (new Sql\Select()) + ->from('timeframe') + ->columns(['id', 'name']); + + $timeframes = []; + + foreach ($this->getDb()->select($select) as $row) { + $timeframes[$row->id] = $row->name; + } + + return $timeframes; + } + + protected function listTemplates() + { + $select = (new Sql\Select()) + ->from('template') + ->columns(['id', 'name']); + + $templates = []; + + foreach ($this->getDb()->select($select) as $row) { + $templates[$row->id] = $row->name; + } + + return $templates; + } +} diff --git a/library/Reporting/Dimensions.php b/library/Reporting/Dimensions.php new file mode 100644 index 0000000..dfedbc8 --- /dev/null +++ b/library/Reporting/Dimensions.php @@ -0,0 +1,21 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +trait Dimensions +{ + protected $dimensions; + + public function getDimensions() + { + return $this->dimensions; + } + + public function setDimensions(array $dimensions) + { + $this->dimensions = $dimensions; + + return $this; + } +} diff --git a/library/Reporting/Hook/ActionHook.php b/library/Reporting/Hook/ActionHook.php new file mode 100644 index 0000000..ef550ee --- /dev/null +++ b/library/Reporting/Hook/ActionHook.php @@ -0,0 +1,37 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Hook; + +use Icinga\Application\Hook; +use Icinga\Module\Reporting\Report; +use ipl\Html\Form; + +abstract class ActionHook +{ + /** + * @return string + */ + abstract public function getName(); + + /** + * @param Report $report + * @param array $config + */ + abstract public function execute(Report $report, array $config); + + /** + * @param Form $form + */ + public function initConfigForm(Form $form, Report $report) + { + } + + /** + * @return ActionHook[] + */ + final public static function getActions() + { + return Hook::all('reporting/Action'); + } +} diff --git a/library/Reporting/Hook/ReportHook.php b/library/Reporting/Hook/ReportHook.php new file mode 100644 index 0000000..13cc01e --- /dev/null +++ b/library/Reporting/Hook/ReportHook.php @@ -0,0 +1,116 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Hook; + +use Icinga\Application\ClassLoader; +use Icinga\Application\Hook; +use Icinga\Module\Reporting\ReportData; +use Icinga\Module\Reporting\Timerange; +use ipl\Html\Form; +use ipl\Html\ValidHtml; + +abstract class ReportHook +{ + /** + * Get the name of the report + * + * @return string + */ + abstract public function getName(); + + /** + * @param Timerange $timerange + * @param array $config + * + * @return ReportData|null + */ + public function getData(Timerange $timerange, array $config = null) + { + return null; + } + + /** + * Get the HTML of the report + * + * @param Timerange $timerange + * @param array $config + * + * @return ValidHtml|null + */ + public function getHtml(Timerange $timerange, array $config = null) + { + return null; + } + + /** + * Initialize the report's configuration form + * + * @param Form $form + */ + public function initConfigForm(Form $form) + { + } + + /** + * Get the description of the report + * + * @return string + */ + public function getDescription() + { + return null; + } + + /** + * Get whether the report provides reporting data + * + * @return bool + */ + public function providesData() + { + try { + $method = new \ReflectionMethod($this, 'getData'); + } catch (\ReflectionException $e) { + return false; + } + + return $method->getDeclaringClass()->getName() !== self::class; + } + + /** + * Get whether the report provides HTML + * + * @return bool + */ + public function providesHtml() + { + try { + $method = new \ReflectionMethod($this, 'getHtml'); + } catch (\ReflectionException $e) { + return false; + } + + return $method->getDeclaringClass()->getName() !== self::class; + } + + /** + * Get the module name of the report + * + * @return string + */ + final public function getModuleName() + { + return ClassLoader::extractModuleName(get_class($this)); + } + + /** + * Get all provided reports + * + * @return ReportHook[] + */ + final public static function getReports() + { + return Hook::all('reporting/Report'); + } +} diff --git a/library/Reporting/Mail.php b/library/Reporting/Mail.php new file mode 100644 index 0000000..7581f45 --- /dev/null +++ b/library/Reporting/Mail.php @@ -0,0 +1,180 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use Zend_Mail; +use Zend_Mail_Transport_Sendmail; +use Zend_Mime; +use Zend_Mime_Part; + +class Mail +{ + /** @var string */ + const DEFAULT_SUBJECT = 'Icinga Reporting'; + + /** @var string */ + protected $from; + + /** @var string */ + protected $subject = self::DEFAULT_SUBJECT; + + /** @var Zend_Mail_Transport_Sendmail */ + protected $transport; + + /** @var array */ + protected $attachments = []; + + /** + * Get the from part + * + * @return string + */ + public function getFrom() + { + if (isset($this->from)) { + return $this->from; + } + + if (isset($_SERVER['SERVER_ADMIN'])) { + $this->from = $_SERVER['SERVER_ADMIN']; + + return $this->from; + } + + foreach (['HTTP_HOST', 'SERVER_NAME', 'HOSTNAME'] as $key) { + if (isset($_SEVER[$key])) { + $this->from = 'icinga-reporting@' . $_SERVER[$key]; + + return $this->from; + } + } + + $this->from = 'icinga-reporting@localhost'; + + return $this->from; + } + + /** + * Set the from part + * + * @param string $from + * + * @return $this + */ + public function setFrom($from) + { + $this->from = $from; + + return $this; + } + + /** + * Get the subject + * + * @return string + */ + public function getSubject() + { + return $this->subject; + } + + /** + * Set the subject + * + * @param string $subject + * + * @return $this + */ + public function setSubject($subject) + { + $this->subject = $subject; + + return $this; + } + + /** + * Get the mail transport + * + * @return Zend_Mail_Transport_Sendmail + */ + public function getTransport() + { + if (! isset($this->transport)) { + $this->transport = new Zend_Mail_Transport_Sendmail('-f ' . escapeshellarg($this->getFrom())); + } + + return $this->transport; + } + + public function attachCsv($csv, $filename) + { + if (is_array($csv)) { + $csv = Str::putcsv($csv); + } + + $attachment = new Zend_Mime_Part($csv); + + $attachment->type = 'text/csv'; + $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; + $attachment->encoding = Zend_Mime::ENCODING_BASE64; + $attachment->filename = basename($filename, '.csv') . '.csv'; + + $this->attachments[] = $attachment; + + return $this; + } + + public function attachJson($json, $filename) + { + if (is_array($json)) { + $json = json_encode($json); + } + + $attachment = new Zend_Mime_Part($json); + + $attachment->type = 'application/json'; + $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; + $attachment->encoding = Zend_Mime::ENCODING_BASE64; + $attachment->filename = basename($filename, '.json') . '.json'; + + $this->attachments[] = $attachment; + + return $this; + } + + public function attachPdf($pdf, $filename) + { + $attachment = new Zend_Mime_Part($pdf); + + $attachment->type = 'application/pdf'; + $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; + $attachment->encoding = Zend_Mime::ENCODING_BASE64; + $attachment->filename = basename($filename, '.pdf') . '.pdf'; + + $this->attachments[] = $attachment; + + return $this; + } + + public function send($body, $recipient) + { + $mail = new Zend_Mail('UTF-8'); + + $mail->setFrom($this->getFrom()); + $mail->addTo($recipient); + $mail->setSubject($this->getSubject()); + + if (strlen($body) !== strlen(strip_tags($body))) { + $mail->setBodyHtml($body); + } else { + $mail->setBodyText($body); + } + + foreach ($this->attachments as $attachment) { + $mail->addAttachment($attachment); + } + + $mail->send($this->getTransport()); + } +} diff --git a/library/Reporting/ProvidedActions.php b/library/Reporting/ProvidedActions.php new file mode 100644 index 0000000..2590d1f --- /dev/null +++ b/library/Reporting/ProvidedActions.php @@ -0,0 +1,20 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use Icinga\Module\Reporting\Hook\ActionHook; + +trait ProvidedActions +{ + public function listActions() + { + $actions = []; + + foreach (ActionHook::getActions() as $class => $action) { + $actions[$class] = $action->getName(); + } + + return $actions; + } +} diff --git a/library/Reporting/ProvidedReports.php b/library/Reporting/ProvidedReports.php new file mode 100644 index 0000000..edfc2ce --- /dev/null +++ b/library/Reporting/ProvidedReports.php @@ -0,0 +1,20 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use Icinga\Module\Reporting\Hook\ReportHook; + +trait ProvidedReports +{ + public function listReports() + { + $reports = []; + + foreach (ReportHook::getReports() as $class => $report) { + $reports[$class] = $report->getName(); + } + + return $reports; + } +} diff --git a/library/Reporting/Report.php b/library/Reporting/Report.php new file mode 100644 index 0000000..7f2eee3 --- /dev/null +++ b/library/Reporting/Report.php @@ -0,0 +1,382 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use DateTime; +use Exception; +use Icinga\Module\Pdfexport\PrintableHtmlDocument; +use Icinga\Module\Reporting\Web\Widget\Template; +use ipl\Html\HtmlDocument; +use ipl\Sql; + +class Report +{ + use Database; + + /** @var int */ + protected $id; + + /** @var string */ + protected $name; + + /** @var string */ + protected $author; + + /** @var Timeframe */ + protected $timeframe; + + /** @var Reportlet[] */ + protected $reportlets; + + /** @var Schedule */ + protected $schedule; + + /** @var Template */ + protected $template; + + /** + * @param int $id + * + * @return static + * + * @throws Exception + */ + public static function fromDb($id) + { + $report = new static(); + + $db = $report->getDb(); + + $select = (new Sql\Select()) + ->from('report') + ->columns('*') + ->where(['id = ?' => $id]); + + $row = $db->select($select)->fetch(); + + if ($row === false) { + throw new Exception('Report not found'); + } + + $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.'); + } + + $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; + } + + $reportlet->setConfig($config); + + $report->setReportlets([$reportlet]); + + $select = (new Sql\Select()) + ->from('schedule') + ->columns('*') + ->where(['report_id = ?' => $id]); + + $row = $db->select($select)->fetch(); + + 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); + } + + return $report; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * + * @return $this + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return string + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @param string $author + * + * @return $this + */ + public function setAuthor($author) + { + $this->author = $author; + + return $this; + } + + /** + * @return Timeframe + */ + public function getTimeframe() + { + return $this->timeframe; + } + + /** + * @param Timeframe $timeframe + * + * @return $this + */ + public function setTimeframe(Timeframe $timeframe) + { + $this->timeframe = $timeframe; + + return $this; + } + + /** + * @return Reportlet[] + */ + public function getReportlets() + { + return $this->reportlets; + } + + /** + * @param Reportlet[] $reportlets + * + * @return $this + */ + public function setReportlets(array $reportlets) + { + $this->reportlets = $reportlets; + + return $this; + } + + /** + * @return Schedule + */ + public function getSchedule() + { + return $this->schedule; + } + + /** + * @param Schedule $schedule + * + * @return $this + */ + public function setSchedule(Schedule $schedule) + { + $this->schedule = $schedule; + + return $this; + } + + /** + * @return Template + */ + public function getTemplate() + { + 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) { + $implementation = $reportlet->getImplementation(); + + if ($implementation->providesData()) { + return true; + } + } + + return false; + } + + /** + * @return HtmlDocument + */ + public function toHtml() + { + $timerange = $this->getTimeframe()->getTimerange(); + + $html = new HtmlDocument(); + + foreach ($this->getReportlets() as $reportlet) { + $implementation = $reportlet->getImplementation(); + + $html->add($implementation->getHtml($timerange, $reportlet->getConfig())); + } + + return $html; + } + + /** + * @return string + */ + public function toCsv() + { + $timerange = $this->getTimeframe()->getTimerange(); + + $csv = []; + + foreach ($this->getReportlets() as $reportlet) { + $implementation = $reportlet->getImplementation(); + + if ($implementation->providesData()) { + $data = $implementation->getData($timerange, $reportlet->getConfig()); + $csv[] = array_merge($data->getDimensions(), $data->getValues()); + foreach ($data->getRows() as $row) { + $csv[] = array_merge($row->getDimensions(), $row->getValues()); + } + + break; + } + } + + return Str::putcsv($csv); + } + + /** + * @return string + */ + public function toJson() + { + $timerange = $this->getTimeframe()->getTimerange(); + + $json = []; + + foreach ($this->getReportlets() as $reportlet) { + $implementation = $reportlet->getImplementation(); + + if ($implementation->providesData()) { + $data = $implementation->getData($timerange, $reportlet->getConfig()); + $dimensions = $data->getDimensions(); + $values = $data->getValues(); + foreach ($data->getRows() as $row) { + $json[] = \array_combine($dimensions, $row->getDimensions()) + + \array_combine($values, $row->getValues()); + } + + break; + } + } + + return json_encode($json); + } + + /** + * @return PrintableHtmlDocument + * + * @throws Exception + */ + public function toPdf() + { + $html = (new PrintableHtmlDocument()) + ->setTitle($this->getName()) + ->addAttributes(['class' => 'icinga-module module-reporting']) + ->addHtml($this->toHtml()); + + if ($this->template !== null) { + $this->template->setMacros([ + 'title' => $this->name, + 'date' => (new DateTime())->format('jS M, Y'), + 'time_frame' => $this->timeframe->getName(), + 'time_frame_absolute' => sprintf( + 'From %s to %s', + $this->timeframe->getTimerange()->getStart()->format('r'), + $this->timeframe->getTimerange()->getEnd()->format('r') + ) + ]); + + $html->setCoverPage($this->template->getCoverPage()->setMacros($this->template->getMacros())); + $html->setHeader($this->template->getHeader()->setMacros($this->template->getMacros())); + $html->setFooter($this->template->getFooter()->setMacros($this->template->getMacros())); + } + + return $html; + } +} diff --git a/library/Reporting/ReportData.php b/library/Reporting/ReportData.php new file mode 100644 index 0000000..787f4db --- /dev/null +++ b/library/Reporting/ReportData.php @@ -0,0 +1,71 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +class ReportData implements \Countable +{ + use Dimensions; + use Values; + + /** @var ReportRow[]|null */ + protected $rows; + + public function getRows() + { + return $this->rows; + } + + public function setRows(array $rows) + { + $this->rows = $rows; + + return $this; + } + + public function getAverages() + { + $totals = $this->getTotals(); + $averages = []; + $count = \count($this); + + foreach ($totals as $total) { + $averages[] = $total / $count; + } + + return $averages; + } + +// public function getMaximums() +// { +// } + +// public function getMinimums() +// { +// } + + public function getTotals() + { + $totals = []; + + foreach ((array) $this->getRows() as $row) { + $i = 0; + foreach ((array) $row->getValues() as $value) { + if (! isset($totals[$i])) { + $totals[$i] = $value; + } else { + $totals[$i] += $value; + } + + ++$i; + } + } + + return $totals; + } + + public function count(): int + { + return count((array) $this->getRows()); + } +} diff --git a/library/Reporting/ReportRow.php b/library/Reporting/ReportRow.php new file mode 100644 index 0000000..1536488 --- /dev/null +++ b/library/Reporting/ReportRow.php @@ -0,0 +1,10 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +class ReportRow +{ + use Dimensions; + use Values; +} diff --git a/library/Reporting/Reportlet.php b/library/Reporting/Reportlet.php new file mode 100644 index 0000000..2876a00 --- /dev/null +++ b/library/Reporting/Reportlet.php @@ -0,0 +1,86 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +class Reportlet +{ + /** @var int */ + protected $id; + + /** @var string */ + protected $class; + + /** @var array */ + protected $config; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * + * @return $this + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * @return string + */ + public function getClass() + { + return $this->class; + } + + /** + * @param string $class + * + * @return $this + */ + public function setClass($class) + { + $this->class = $class; + + return $this; + } + + /** + * @return array + */ + public function getConfig() + { + return $this->config; + } + + /** + * @param array $config + * + * @return $this + */ + public function setConfig($config) + { + $this->config = $config; + + return $this; + } + + /** + * @return \Icinga\Module\Reporting\Hook\ReportHook + */ + public function getImplementation() + { + $class = $this->getClass(); + + return new $class; + } +} diff --git a/library/Reporting/Reports/SystemReport.php b/library/Reporting/Reports/SystemReport.php new file mode 100644 index 0000000..8a3d8dd --- /dev/null +++ b/library/Reporting/Reports/SystemReport.php @@ -0,0 +1,39 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Reports; + +use Icinga\Module\Reporting\Hook\ReportHook; +use Icinga\Module\Reporting\Timerange; +use ipl\Html\HtmlString; + +class SystemReport extends ReportHook +{ + public function getName() + { + return 'System'; + } + + public function getHtml(Timerange $timerange, array $config = null) + { + ob_start(); + phpinfo(); + $html = ob_get_clean(); + + $doc = new \DOMDocument(); + @$doc->loadHTML($html); + + $style = $doc->getElementsByTagName('style')->item(0); + $style->parentNode->removeChild($style); + + $title = $doc->getElementsByTagName('title')->item(0); + $title->parentNode->removeChild($title); + + $meta = $doc->getElementsByTagName('meta')->item(0); + $meta->parentNode->removeChild($meta); + + $doc->getElementsByTagName('div')->item(0)->setAttribute('class', 'system-report'); + + return new HtmlString($doc->saveHTML()); + } +} diff --git a/library/Reporting/RetryConnection.php b/library/Reporting/RetryConnection.php new file mode 100644 index 0000000..ebadfd2 --- /dev/null +++ b/library/Reporting/RetryConnection.php @@ -0,0 +1,66 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use ipl\Sql\Connection; + +class RetryConnection extends Connection +{ + public function prepexec($stmt, $values = null) + { + try { + $sth = parent::prepexec($stmt, $values); + } catch (\Exception $e) { + $lostConnection = Str::contains($e->getMessage(), [ + 'server has gone away', + 'no connection to the server', + 'Lost connection', + 'Error while sending', + 'is dead or not enabled', + 'decryption failed or bad record mac', + 'server closed the connection unexpectedly', + 'SSL connection has been closed unexpectedly', + 'Error writing data to the connection', + 'Resource deadlock avoided', + 'Transaction() on null', + 'child connection forced to terminate due to client_idle_limit', + 'query_wait_timeout', + 'reset by peer', + 'Physical connection is not usable', + 'TCP Provider: Error code 0x68', + 'ORA-03114', + 'Packets out of order. Expected', + 'Adaptive Server connection failed', + 'Communication link failure', + ]); + + if (! $lostConnection) { + throw $e; + } + + $this->disconnect(); + + try { + $this->connect(); + } catch (\Exception $e) { + $noConnection = Str::contains($e->getMessage(), [ + 'No such file or directory', + 'Connection refused' + ]); + + if (! $noConnection) { + throw $e; + } + + \sleep(10); + + $this->connect(); + } + + $sth = parent::prepexec($stmt, $values); + } + + return $sth; + } +} diff --git a/library/Reporting/Schedule.php b/library/Reporting/Schedule.php new file mode 100644 index 0000000..e0ffa9f --- /dev/null +++ b/library/Reporting/Schedule.php @@ -0,0 +1,160 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +class Schedule +{ + /** @var int */ + protected $id; + + /** @var int */ + protected $reportId; + + /** @var \DateTime */ + protected $start; + + /** @var string */ + protected $frequency; + + /** @var string */ + protected $action; + + /** @var array */ + protected $config; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * + * @return $this + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * @return int + */ + public function getReportId() + { + return $this->reportId; + } + + /** + * @param int $id + * + * @return $this + */ + public function setReportId($id) + { + $this->reportId = $id; + + return $this; + } + + /** + * @return \DateTime + */ + public function getStart() + { + return $this->start; + } + + /** + * @param \DateTime $start + * + * @return $this + */ + public function setStart(\DateTime $start) + { + $this->start = $start; + + return $this; + } + + /** + * @return string + */ + public function getFrequency() + { + return $this->frequency; + } + + /** + * @param string $frequency + * + * @return $this + */ + public function setFrequency($frequency) + { + $this->frequency = $frequency; + + return $this; + } + + /** + * @return string + */ + public function getAction() + { + return $this->action; + } + + /** + * @param string $action + * + * @return $this + */ + public function setAction($action) + { + $this->action = $action; + + return $this; + } + + /** + * @return array + */ + public function getConfig() + { + return $this->config; + } + + /** + * @param array $config + * + * @return $this + */ + public function setConfig(array $config) + { + $this->config = $config; + + return $this; + } + + /** + * @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()) + ); + } +} diff --git a/library/Reporting/Scheduler.php b/library/Reporting/Scheduler.php new file mode 100644 index 0000000..1b8d9f6 --- /dev/null +++ b/library/Reporting/Scheduler.php @@ -0,0 +1,176 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use Cron\CronExpression; +use ipl\Sql\Connection; +use ipl\Sql\Select; +use React\EventLoop\Factory as Loop; + +function datetime_get_time_of_day(\DateTime $dateTime) +{ + $midnight = clone $dateTime; + $midnight->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 new file mode 100644 index 0000000..d4c7355 --- /dev/null +++ b/library/Reporting/Str.php @@ -0,0 +1,37 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +class Str +{ + public static function putcsv(array $data, $delimiter = ',', $enclosure = '"', $escape = '\\') + { + $fp = fopen('php://temp', 'r+b'); + + foreach ($data as $row) { + fputcsv($fp, $row, $delimiter, $enclosure, $escape); + } + + rewind($fp); + + $csv = stream_get_contents($fp); + + fclose($fp); + + $csv = rtrim($csv, "\n"); // fputcsv adds a newline + + return $csv; + } + + public static function contains($haystack, $needle) + { + foreach ((array) $needle as $n) { + if (\strpos($haystack, $n) !== false) { + return true; + } + } + + return false; + } +} diff --git a/library/Reporting/Timeframe.php b/library/Reporting/Timeframe.php new file mode 100644 index 0000000..f295779 --- /dev/null +++ b/library/Reporting/Timeframe.php @@ -0,0 +1,168 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use ipl\Sql\Select; + +class Timeframe +{ + use Database; + + /** @var int */ + protected $id; + + /** @var string */ + protected $name; + + /** @var string */ + protected $title; + + /** @var string */ + protected $start; + + /** @var string */ + protected $end; + + /** + * @param int $id + * + * @return static + * + * @throws \Exception + */ + public static function fromDb($id) + { + $timeframe = new static(); + + $db = $timeframe->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); + + return $timeframe; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * + * @return $this + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return string + */ + public function getStart() + { + return $this->start; + } + + /** + * @param string $start + * + * @return $this + */ + public function setStart($start) + { + $this->start = $start; + + return $this; + } + + /** + * @return string + */ + public function getEnd() + { + 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()); + $end = new \DateTime($this->getEnd()); + + return new Timerange($start, $end); + } +} diff --git a/library/Reporting/Timerange.php b/library/Reporting/Timerange.php new file mode 100644 index 0000000..086bfb8 --- /dev/null +++ b/library/Reporting/Timerange.php @@ -0,0 +1,35 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +class Timerange +{ + /** @var \DateTime */ + protected $start; + + /** @var \DateTime */ + protected $end; + + public function __construct(\DateTime $start, \DateTime $end) + { + $this->start = $start; + $this->end = $end; + } + + /** + * @return \DateTime + */ + public function getStart() + { + return $this->start; + } + + /** + * @return \DateTime + */ + public function getEnd() + { + return $this->end; + } +} diff --git a/library/Reporting/Values.php b/library/Reporting/Values.php new file mode 100644 index 0000000..3aa9b24 --- /dev/null +++ b/library/Reporting/Values.php @@ -0,0 +1,21 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +trait Values +{ + protected $values; + + public function getValues() + { + return $this->values; + } + + public function setValues(array $values) + { + $this->values = $values; + + return $this; + } +} diff --git a/library/Reporting/Web/Controller.php b/library/Reporting/Web/Controller.php new file mode 100644 index 0000000..5040183 --- /dev/null +++ b/library/Reporting/Web/Controller.php @@ -0,0 +1,20 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web; + +use ipl\Html\Form; +use ipl\Web\Compat\CompatController; + +class Controller extends CompatController +{ + protected function redirectForm(Form $form, $url) + { + if ($form->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 new file mode 100644 index 0000000..5f6605d --- /dev/null +++ b/library/Reporting/Web/Flatpickr.php @@ -0,0 +1,77 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web; + +use Icinga\Application\Version; +use ipl\Html\Html; +use ipl\Web\Compat\CompatDecorator; + +class Flatpickr extends CompatDecorator +{ + protected $allowInput = true; + + /** + * Set whether to allow manual input + * + * @param bool $state + * + * @return $this + */ + public function setAllowInput(bool $state): self + { + $this->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 new file mode 100644 index 0000000..2578681 --- /dev/null +++ b/library/Reporting/Web/Forms/DecoratedElement.php @@ -0,0 +1,17 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Forms; + +use ipl\Html\Contract\FormElementDecorator; + +trait DecoratedElement +{ + protected function addDecoratedElement(FormElementDecorator $decorator, $type, $name, array $attributes) + { + $element = $this->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 new file mode 100644 index 0000000..b2eb536 --- /dev/null +++ b/library/Reporting/Web/Forms/Decorator/CompatDecorator.php @@ -0,0 +1,63 @@ +<?php +// Icinga Reporting | (c) 2021 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Forms\Decorator; + +use Icinga\Application\Version; +use ipl\Html\Attributes; +use ipl\Html\FormElement\CheckboxElement; +use ipl\Html\HtmlElement; + +class CompatDecorator extends \ipl\Web\Compat\CompatDecorator +{ + protected function createCheckboxCompat(CheckboxElement $checkbox) + { + if (! $checkbox->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 new file mode 100644 index 0000000..6b1e692 --- /dev/null +++ b/library/Reporting/Web/Forms/ReportForm.php @@ -0,0 +1,168 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Forms; + +use Icinga\Authentication\Auth; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\ProvidedReports; +use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator; +use ipl\Html\Contract\FormSubmitElement; +use ipl\Html\Form; +use ipl\Web\Compat\CompatForm; + +class ReportForm extends CompatForm +{ + use Database; + use ProvidedReports; + + /** @var bool Hack to disable the {@link onSuccess()} code upon deletion of the report */ + protected $callOnSuccess; + + protected $id; + + public function setId($id) + { + $this->id = $id; + + return $this; + } + + protected function assemble() + { + $this->setDefaultElementDecorator(new CompatDecorator()); + + $this->addElement('text', 'name', [ + 'required' => true, + 'label' => 'Name' + ]); + + $this->addElement('select', 'timeframe', [ + 'required' => true, + 'label' => 'Timeframe', + 'options' => [null => 'Please choose'] + $this->listTimeframes(), + 'class' => 'autosubmit' + ]); + + $this->addElement('select', 'template', [ + 'label' => 'Template', + 'options' => [null => 'Please choose'] + $this->listTemplates() + ]); + + $this->addElement('select', 'reportlet', [ + 'required' => true, + 'label' => 'Report', + 'options' => [null => 'Please choose'] + $this->listReports(), + 'class' => 'autosubmit' + ]); + + $values = $this->getValues(); + + if (isset($values['reportlet'])) { + $config = new Form(); +// $config->populate($this->getValues()); + + /** @var \Icinga\Module\Reporting\Hook\ReportHook $reportlet */ + $reportlet = new $values['reportlet']; + + $reportlet->initConfigForm($config); + + foreach ($config->getElements() as $element) { + $this->addElement($element); + } + } + + $this->addElement('submit', 'submit', [ + 'label' => $this->id === null ? 'Create Report' : 'Update Report' + ]); + + if ($this->id !== null) { + /** @var FormSubmitElement $removeButton */ + $removeButton = $this->createElement('submit', 'remove', [ + 'label' => '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; + + return; + } + } + } + + public function onSuccess() + { + if ($this->callOnSuccess === false) { + return; + } + + $db = $this->getDb(); + + $values = $this->getValues(); + + $now = time() * 1000; + + $db->beginTransaction(); + + if ($this->id === null) { + $db->insert('report', [ + 'name' => $values['name'], + 'author' => Auth::getInstance()->getUser()->getUsername(), + 'timeframe_id' => $values['timeframe'], + 'template_id' => $values['template'], + 'ctime' => $now, + 'mtime' => $now + ]); + + $reportId = $db->lastInsertId(); + } else { + $db->update('report', [ + 'name' => $values['name'], + 'timeframe_id' => $values['timeframe'], + 'template_id' => $values['template'], + 'mtime' => $now + ], ['id = ?' => $this->id]); + + $reportId = $this->id; + } + + unset($values['name']); + unset($values['timeframe']); + + if ($this->id !== null) { + $db->delete('reportlet', ['report_id = ?' => $reportId]); + } + + $db->insert('reportlet', [ + 'report_id' => $reportId, + 'class' => $values['reportlet'], + 'ctime' => $now, + 'mtime' => $now + ]); + + $reportletId = $db->lastInsertId(); + + unset($values['reportlet']); + + foreach ($values as $name => $value) { + $db->insert('config', [ + 'reportlet_id' => $reportletId, + 'name' => $name, + 'value' => $value, + 'ctime' => $now, + 'mtime' => $now + ]); + } + + $db->commitTransaction(); + } +} diff --git a/library/Reporting/Web/Forms/ScheduleForm.php b/library/Reporting/Web/Forms/ScheduleForm.php new file mode 100644 index 0000000..47f3ee3 --- /dev/null +++ b/library/Reporting/Web/Forms/ScheduleForm.php @@ -0,0 +1,177 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Forms; + +use DateTime; +use Icinga\Application\Version; +use Icinga\Authentication\Auth; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\ProvidedActions; +use Icinga\Module\Reporting\Report; +use Icinga\Module\Reporting\Web\Flatpickr; +use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator; +use ipl\Html\Contract\FormSubmitElement; +use ipl\Html\Form; +use ipl\Web\Compat\CompatForm; + +class ScheduleForm extends CompatForm +{ + use Database; + use DecoratedElement; + use ProvidedActions; + + /** @var Report */ + protected $report; + + protected $id; + + public function setReport(Report $report) + { + $this->report = $report; + + $schedule = $report->getSchedule(); + + if ($schedule !== null) { + $this->setId($schedule->getId()); + + $values = [ + 'start' => $schedule->getStart()->format('Y-m-d\\TH:i:s'), + 'frequency' => $schedule->getFrequency(), + 'action' => $schedule->getAction() + ] + $schedule->getConfig(); + + $this->populate($values); + } + + return $this; + } + + public function setId($id) + { + $this->id = $id; + + return $this; + } + + 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' + ]); + + $values = $this->getValues(); + + if (isset($values['action'])) { + $config = new Form(); +// $config->populate($this->getValues()); + + /** @var \Icinga\Module\Reporting\Hook\ActionHook $action */ + $action = new $values['action']; + + $action->initConfigForm($config, $this->report); + + foreach ($config->getElements() as $element) { + $this->addElement($element); + } + } + + $this->addElement('submit', 'submit', [ + 'label' => $this->id === null ? 'Create Schedule' : 'Update Schedule' + ]); + + if ($this->id !== null) { + /** @var FormSubmitElement $removeButton */ + $removeButton = $this->createElement('submit', 'remove', [ + 'label' => '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; + } + } + } + + public function onSuccess() + { + $db = $this->getDb(); + + $values = $this->getValues(); + + $now = time() * 1000; + + if (! $values['start'] instanceof DateTime) { + $values['start'] = DateTime::createFromFormat('Y-m-d H:i:s', $values['start']); + } + + $data = [ + 'start' => $values['start']->getTimestamp() * 1000, + 'frequency' => $values['frequency'], + 'action' => $values['action'], + 'mtime' => $now + ]; + + unset($values['start']); + unset($values['frequency']); + unset($values['action']); + + $data['config'] = json_encode($values); + + $db->beginTransaction(); + + if ($this->id === null) { + $db->insert('schedule', $data + [ + 'author' => Auth::getInstance()->getUser()->getUsername(), + 'report_id' => $this->report->getId(), + 'ctime' => $now + ]); + } else { + $db->update('schedule', $data, ['id = ?' => $this->id]); + } + + $db->commitTransaction(); + } +} diff --git a/library/Reporting/Web/Forms/SendForm.php b/library/Reporting/Web/Forms/SendForm.php new file mode 100644 index 0000000..03b691c --- /dev/null +++ b/library/Reporting/Web/Forms/SendForm.php @@ -0,0 +1,47 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Forms; + +use Icinga\Module\Reporting\Actions\SendMail; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\ProvidedReports; +use Icinga\Module\Reporting\Report; +use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator; +use ipl\Web\Compat\CompatForm; + +class SendForm extends CompatForm +{ + use Database; + use ProvidedReports; + + /** @var Report */ + protected $report; + + public function setReport(Report $report) + { + $this->report = $report; + + return $this; + } + + protected function assemble() + { + $this->setDefaultElementDecorator(new CompatDecorator()); + + (new SendMail())->initConfigForm($this, $this->report); + + $this->addElement('submit', 'submit', [ + 'label' => 'Send Report' + ]); + } + + public function onSuccess() + { + $values = $this->getValues(); + + $sendMail = new SendMail(); + + $sendMail->execute($this->report, $values); + } +} diff --git a/library/Reporting/Web/Forms/TemplateForm.php b/library/Reporting/Web/Forms/TemplateForm.php new file mode 100644 index 0000000..bb062bb --- /dev/null +++ b/library/Reporting/Web/Forms/TemplateForm.php @@ -0,0 +1,284 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Forms; + +use Icinga\Authentication\Auth; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator; +use ipl\Html\Contract\FormSubmitElement; +use ipl\Html\Html; +use ipl\Web\Compat\CompatForm; +use reportingipl\Html\FormElement\FileElement; + +class TemplateForm extends CompatForm +{ + use Database; + + /** @var bool Hack to disable the {@link onSuccess()} code upon deletion of the template */ + protected $callOnSuccess; + + protected $template; + + public function getTemplate() + { + return $this->template; + } + + public function setTemplate($template) + { + $this->template = $template; + + if ($template->settings) { + $this->populate(array_filter($template->settings, function ($value) { + // Don't populate files + return ! is_array($value); + })); + } + + return $this; + } + + protected function assemble() + { + $this->setDefaultElementDecorator(new CompatDecorator()); + + $this->setAttribute('enctype', 'multipart/form-data'); + + $this->add(Html::tag('h2', 'Template Settings')); + + $this->addElement('text', 'name', [ + 'label' => 'Name', + 'placeholder' => 'Template name', + 'required' => true + ]); + + $this->add(Html::tag('h2', 'Cover Page Settings')); + + $this->addElement(new FileElement('cover_page_background_image', [ + 'label' => 'Background Image', + 'accept' => 'image/png, image/jpeg' + ])); + + 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' + )); + + $this->addElement('checkbox', 'remove_cover_page_background_image', [ + 'label' => 'Remove background image' + ]); + } + + $this->addElement(new FileElement('cover_page_logo', [ + 'label' => 'Logo', + 'accept' => 'image/png, image/jpeg' + ])); + + 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' + )); + + $this->addElement('checkbox', 'remove_cover_page_logo', [ + 'label' => 'Remove Logo' + ]); + } + + $this->addElement('textarea', 'title', [ + 'label' => 'Title', + 'placeholder' => 'Report title' + ]); + + $this->addElement('text', 'color', [ + 'label' => 'Color', + 'placeholder' => 'CSS color code' + ]); + + $this->add(Html::tag('h2', 'Header Settings')); + + $this->addColumnSettings('header_column1', 'Column 1'); + $this->addColumnSettings('header_column2', 'Column 2'); + $this->addColumnSettings('header_column3', 'Column 3'); + + $this->add(Html::tag('h2', 'Footer Settings')); + + $this->addColumnSettings('footer_column1', 'Column 1'); + $this->addColumnSettings('footer_column2', 'Column 2'); + $this->addColumnSettings('footer_column3', 'Column 3'); + + $this->addElement('submit', 'submit', [ + 'label' => $this->template === null ? 'Create Template' : 'Update Template' + ]); + + if ($this->template !== null) { + /** @var FormSubmitElement $removeButton */ + $removeButton = $this->createElement('submit', 'remove', [ + 'label' => '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; + } + } + } + + public function onSuccess() + { + if ($this->callOnSuccess === false) { + return; + } + + ini_set('upload_max_filesize', '10M'); + + $settings = $this->getValues(); + + try { + /** @var $uploadedFile \GuzzleHttp\Psr7\UploadedFile */ + foreach ($this->getRequest()->getUploadedFiles() as $name => $uploadedFile) { + if ($uploadedFile->getError() === UPLOAD_ERR_NO_FILE) { + continue; + } + + $settings[$name] = [ + 'mime_type' => $uploadedFile->getClientMediaType(), + 'size' => $uploadedFile->getSize(), + 'content' => base64_encode((string) $uploadedFile->getStream()) + ]; + } + + $db = $this->getDb(); + + $now = time() * 1000; + + if ($this->template === null) { + $db->insert('template', [ + 'name' => $settings['name'], + 'author' => Auth::getInstance()->getUser()->getUsername(), + 'settings' => json_encode($settings), + 'ctime' => $now, + 'mtime' => $now + ]); + } else { + if (isset($settings['remove_cover_page_background_image'])) { + unset($settings['cover_page_background_image']); + unset($settings['remove_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'])) { + unset($settings['cover_page_logo']); + unset($settings['remove_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']; + } + + foreach (['header', 'footer'] as $headerOrFooter) { + for ($i = 1; $i <= 3; ++$i) { + $type = "{$headerOrFooter}_column{$i}_type"; + + if ($settings[$type] === 'image') { + $value = "{$headerOrFooter}_column{$i}_value"; + + if (! isset($settings[$value]) + && isset($this->template->settings[$value]) + ) { + $settings[$value] = $this->template->settings[$value]; + } + } + } + } + + $db->update('template', [ + 'name' => $settings['name'], + 'settings' => json_encode($settings), + 'mtime' => $now + ], ['id = ?' => $this->template->id]); + } + } catch (\Exception $e) { + die($e->getMessage()); + } + } + + protected function addColumnSettings($name, $label) + { + $type = "{$name}_type"; + $value = "{$name}_value"; + + $this->addElement('select', $type, [ + 'class' => 'autosubmit', + 'label' => $label, + 'options' => [ + null => 'None', + 'text' => 'Text', + 'image' => 'Image', + 'variable' => 'Variable' + ] + ]); + + switch ($this->getValue($type, 'none')) { + case 'image': + $this->addElement(new FileElement($value, [ + 'label' => 'Image', + 'accept' => 'image/png, image/jpeg' + ])); + + if ($this->template !== null + && $this->template->settings[$type] === 'image' + && isset($this->template->settings[$value]) + ) { + $this->add(Html::tag( + 'p', + ['style' => ['margin-left: 14em;']], + 'Upload a new image to override the existing one' + )); + } + break; + case 'variable': + $this->addElement('select', $value, [ + 'label' => 'Variable', + 'options' => [ + 'report_title' => 'Report Title', + 'time_frame' => 'Time Frame', + 'time_frame_absolute' => 'Time Frame (absolute)', + 'page_number' => 'Page Number', + 'total_number_of_pages' => 'Total Number of Pages', + 'page_of' => 'Page Number + Total Number of Pages', + 'date' => 'Date' + ], + 'value' => 'report_title' + ]); + break; + case 'text': + $this->addElement('text', $value, [ + 'label' => 'Text', + 'placeholder' => 'Column text' + ]); + break; + } + } +} diff --git a/library/Reporting/Web/Forms/TimeframeForm.php b/library/Reporting/Web/Forms/TimeframeForm.php new file mode 100644 index 0000000..3d78709 --- /dev/null +++ b/library/Reporting/Web/Forms/TimeframeForm.php @@ -0,0 +1,106 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Forms; + +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Web\Flatpickr; +use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator; +use ipl\Html\Contract\FormSubmitElement; +use ipl\Web\Compat\CompatForm; + +class TimeframeForm extends CompatForm +{ + use Database; + use DecoratedElement; + + protected $id; + + public function setId($id) + { + $this->id = $id; + + return $this; + } + + protected function assemble() + { + $this->setDefaultElementDecorator(new CompatDecorator()); + + $this->addElement('text', 'name', [ + 'required' => true, + 'label' => 'Name' + ]); + + $flatpickr = new Flatpickr(); + + $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' + ]); + + $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' + ]); + + $this->addElement('submit', 'submit', [ + 'label' => $this->id === null ? 'Create Time Frame' : 'Update Time Frame' + ]); + + if ($this->id !== null) { + /** @var FormSubmitElement $removeButton */ + $removeButton = $this->createElement('submit', 'remove', [ + 'label' => '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; + } + } + } + + public function onSuccess() + { + $db = $this->getDb(); + + $values = $this->getValues(); + + $now = time() * 1000; + + $end = $db->quoteIdentifier('end'); + + if ($this->id === null) { + $db->insert('timeframe', [ + 'name' => $values['name'], + 'start' => $values['start'], + $end => $values['end'], + 'ctime' => $now, + 'mtime' => $now + ]); + } else { + $db->update('timeframe', [ + 'name' => $values['name'], + 'start' => $values['start'], + $end => $values['end'], + 'mtime' => $now + ], ['id = ?' => $this->id]); + } + } +} diff --git a/library/Reporting/Web/ReportsTimeframesAndTemplatesTabs.php b/library/Reporting/Web/ReportsTimeframesAndTemplatesTabs.php new file mode 100644 index 0000000..afb8b14 --- /dev/null +++ b/library/Reporting/Web/ReportsTimeframesAndTemplatesTabs.php @@ -0,0 +1,37 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web; + +trait ReportsTimeframesAndTemplatesTabs +{ + /** + * Create tabs + * + * @return \Icinga\Web\Widget\Tabs + */ + protected function createTabs() + { + $tabs = $this->getTabs(); + + $tabs->add('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' + ]); + + $tabs->add('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 new file mode 100644 index 0000000..cdd7b40 --- /dev/null +++ b/library/Reporting/Web/Widget/CompatDropdown.php @@ -0,0 +1,22 @@ +<?php +// Icinga Reporting | (c) 2021 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Widget; + +use ipl\Web\Widget\ActionLink; +use ipl\Web\Widget\Dropdown; + +class CompatDropdown extends Dropdown +{ + public function addLink($content, $url, $icon = null, array $attributes = null) + { + $link = new ActionLink($content, $url, $icon, ['class' => 'dropdown-item']); + if (! empty($attributes)) { + $link->addAttributes($attributes); + } + + $this->links[] = $link; + + return $this; + } +} diff --git a/library/Reporting/Web/Widget/CoverPage.php b/library/Reporting/Web/Widget/CoverPage.php new file mode 100644 index 0000000..545ef6a --- /dev/null +++ b/library/Reporting/Web/Widget/CoverPage.php @@ -0,0 +1,181 @@ +<?php + +namespace Icinga\Module\Reporting\Web\Widget; + +use Icinga\Module\Reporting\Common\Macros; +use ipl\Html\BaseHtmlElement; +use ipl\Html\Html; + +class CoverPage extends BaseHtmlElement +{ + use Macros; + + /** @var array */ + protected $backgroundImage; + + /** @var string */ + protected $color; + + /** @var array */ + protected $logo; + + /** @var string */ + protected $title; + + protected $tag = 'div'; + + protected $defaultAttributes = ['class' => 'cover-page page']; + + /** + * @return bool + */ + public function hasBackgroundImage() + { + return $this->backgroundImage !== null; + } + + /** + * @return array + */ + public function getBackgroundImage() + { + return $this->backgroundImage; + } + + /** + * @param array $backgroundImage + * + * @return $this + */ + public function setBackgroundImage($backgroundImage) + { + $this->backgroundImage = $backgroundImage; + + return $this; + } + + /** + * @return bool + */ + public function hasColor() + { + return $this->color !== null; + } + + /** + * @return string + */ + public function getColor() + { + return $this->color; + } + + /** + * @param string $color + * + * @return $this + */ + public function setColor($color) + { + $this->color = $color; + + return $this; + } + + /** + * @return bool + */ + public function hasLogo() + { + return $this->logo !== null; + } + + /** + * @return array + */ + public function getLogo() + { + return $this->logo; + } + + /** + * @param array $logo + * + * @return $this + */ + public function setLogo($logo) + { + $this->logo = $logo; + + return $this; + } + + public function hasTitle() + { + return $this->title !== null; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + protected function assemble() + { + if ($this->hasBackgroundImage()) { + $this + ->getAttributes() + ->add('style', "background-image: url('" . Template::getDataUrl($this->getBackgroundImage()) . "');"); + } + + $content = Html::tag('div', ['class' => 'cover-page-content']); + + if ($this->hasColor()) { + $content->getAttributes()->add('style', "color: {$this->getColor()};"); + } + + if ($this->hasLogo()) { + $content->add(Html::tag( + 'img', + [ + 'class' => 'logo', + 'src' => Template::getDataUrl($this->getLogo()) + ] + )); + } + + if ($this->hasTitle()) { + $title = array_map(function ($part) { + $part = trim($part); + + if (! $part) { + return Html::tag('br'); + } else { + return Html::tag('div', null, $part); + } + }, explode("\n", $this->resolveMacros($this->getTitle()))); + + $content->add(Html::tag( + 'h2', + $title + )); + } + + $this->add($content); + } +} diff --git a/library/Reporting/Web/Widget/HeaderOrFooter.php b/library/Reporting/Web/Widget/HeaderOrFooter.php new file mode 100644 index 0000000..dcb37e7 --- /dev/null +++ b/library/Reporting/Web/Widget/HeaderOrFooter.php @@ -0,0 +1,95 @@ +<?php + +namespace Icinga\Module\Reporting\Web\Widget; + +use Icinga\Module\Reporting\Common\Macros; +use ipl\Html\Html; +use ipl\Html\HtmlDocument; + +class HeaderOrFooter extends HtmlDocument +{ + use Macros; + + const HEADER = 'header'; + + const FOOTER = 'footer'; + + protected $type; + + protected $data; + + protected $tag = 'div'; + + public function __construct($type, array $data) + { + $this->type = $type; + $this->data = $data; + } + + protected function resolveVariable($variable) + { + switch ($variable) { + case 'report_title': + $resolved = Html::tag('span', ['class' => 'title']); + break; + case 'time_frame': + $resolved = Html::tag('p', $this->getMacro('time_frame')); + break; + case 'time_frame_absolute': + $resolved = Html::tag('p', $this->getMacro('time_frame_absolute')); + break; + case 'page_number': + $resolved = Html::tag('span', ['class' => 'pageNumber']); + break; + case 'total_number_of_pages': + $resolved = Html::tag('span', ['class' => 'totalPages']); + break; + case 'page_of': + $resolved = Html::tag('p', Html::sprintf( + '%s / %s', + Html::tag('span', ['class' => 'pageNumber']), + Html::tag('span', ['class' => 'totalPages']) + )); + break; + case 'date': + $resolved = Html::tag('span', ['class' => 'date']); + break; + default: + $resolved = $variable; + break; + } + + return $resolved; + } + + protected function createColumn(array $data, $key) + { + $typeKey = "${key}_type"; + $valueKey = "${key}_value"; + $type = isset($data[$typeKey]) ? $data[$typeKey] : null; + + switch ($type) { + case 'text': + $column = Html::tag('p', $data[$valueKey]); + break; + case 'image': + $column = Html::tag('img', ['height' => 13, 'src' => Template::getDataUrl($data[$valueKey])]); + break; + case 'variable': + $column = $this->resolveVariable($data[$valueKey]); + break; + default: + $column = Html::tag('div'); + break; + } + + return $column; + } + + protected function assemble() + { + for ($i = 1; $i <= 3; ++$i) { + $this->add($this->createColumn($this->data, "{$this->type}_column{$i}")); + } + } +} diff --git a/library/Reporting/Web/Widget/Template.php b/library/Reporting/Web/Widget/Template.php new file mode 100644 index 0000000..e780a3d --- /dev/null +++ b/library/Reporting/Web/Widget/Template.php @@ -0,0 +1,183 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Web\Widget; + +use Icinga\Module\Reporting\Common\Macros; +use Icinga\Module\Reporting\Database; +use ipl\Html\BaseHtmlElement; +use ipl\Html\Html; +use ipl\Sql\Select; + +class Template extends BaseHtmlElement +{ + use Database; + use Macros; + + protected $tag = 'div'; + + protected $defaultAttributes = ['class' => 'template']; + + /** @var CoverPage */ + protected $coverPage; + + /** @var HeaderOrFooter */ + protected $header; + + /** @var HeaderOrFooter */ + protected $footer; + + protected $preview; + + public static function getDataUrl(array $image = null) + { + if (empty($image)) { + return 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; + } + + return sprintf('data:%s;base64,%s', $image['mime_type'], $image['content']); + } + + public static function fromDb($id) + { + $template = new static(); + + $select = (new Select()) + ->from('template') + ->columns('*') + ->where(['id = ?' => $id]); + + $row = $template->getDb()->select($select)->fetch(); + + if ($row === false) { + return null; + } + + $row->settings = json_decode($row->settings, true); + + $coverPage = (new CoverPage()) + ->setColor($row->settings['color']) + ->setTitle($row->settings['title']); + + if (isset($row->settings['cover_page_background_image'])) { + $coverPage->setBackgroundImage($row->settings['cover_page_background_image']); + } + + if (isset($row->settings['cover_page_logo'])) { + $coverPage->setLogo($row->settings['cover_page_logo']); + } + + $template + ->setCoverPage($coverPage) + ->setHeader(new HeaderOrFooter(HeaderOrFooter::HEADER, $row->settings)) + ->setFooter(new HeaderOrFooter(HeaderOrFooter::FOOTER, $row->settings)); + + return $template; + } + + /** + * @return CoverPage + */ + public function getCoverPage() + { + return $this->coverPage; + } + + /** + * @param CoverPage $coverPage + * + * @return $this + */ + public function setCoverPage(CoverPage $coverPage) + { + $this->coverPage = $coverPage; + + return $this; + } + + /** + * @return HeaderOrFooter + */ + public function getHeader() + { + return $this->header; + } + + /** + * @param HeaderOrFooter $header + * + * @return $this + */ + public function setHeader($header) + { + $this->header = $header; + + return $this; + } + + /** + * @return HeaderOrFooter + */ + public function getFooter() + { + return $this->footer; + } + + /** + * @param HeaderOrFooter $footer + * + * @return $this + */ + public function setFooter($footer) + { + $this->footer = $footer; + + return $this; + } + + /** + * @return mixed + */ + public function getPreview() + { + return $this->preview; + } + + /** + * @param mixed $preview + * + * @return $this + */ + public function setPreview($preview) + { + $this->preview = $preview; + + return $this; + } + + protected function assemble() + { + if ($this->preview) { + $this->getAttributes()->add('class', 'preview'); + } + + $this->add($this->getCoverPage()->setMacros($this->macros)); + +// $page = Html::tag( +// 'div', +// ['class' => 'main'], +// Html::tag('div', ['class' => 'page-content'], [ +// $this->header->setMacros($this->macros), +// Html::tag( +// 'div', +// [ +// 'class' => 'main' +// ] +// ), +// $this->footer->setMacros($this->macros) +// ]) +// ); +// +// $this->add($page); + } +} diff --git a/library/vendor/ipl/Html/src/FormElement/FileElement.php b/library/vendor/ipl/Html/src/FormElement/FileElement.php new file mode 100644 index 0000000..88aeb8c --- /dev/null +++ b/library/vendor/ipl/Html/src/FormElement/FileElement.php @@ -0,0 +1,15 @@ +<?php + +namespace reportingipl\Html\FormElement; + +use ipl\Html\FormElement\InputElement; + +class FileElement extends InputElement +{ + protected $type = 'file'; + + public function setValue($value) + { + return $this; + } +} diff --git a/module.info b/module.info new file mode 100644 index 0000000..5f27c61 --- /dev/null +++ b/module.info @@ -0,0 +1,6 @@ +Module: Reporting +Version: 0.10.0 +Requires: + Libraries: icinga-php-library (>=0.8.0), icinga-php-thirdparty (>=0.10.0) + Modules: pdfexport (>=0.10.0) +Description: Reporting diff --git a/public/css/module.less b/public/css/module.less new file mode 100644 index 0000000..49cc4e5 --- /dev/null +++ b/public/css/module.less @@ -0,0 +1,215 @@ +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +.flatpickr-calendar { + position: fixed; +} + +.flatpickr-day { + &.selected, + &.selected:hover { + border-color: @icinga-blue; + background: @icinga-blue; + } +} + +.sla-column { + border-radius: 0.5em; + color: @text-color-on-icinga-blue; + text-align: center; + width: 10em; + + &.ok { + background-color: @color-ok; + } + + &.nok { + background-color: @color-critical; + } +} + +.sla-table { + td:nth-child(1), + td:nth-child(2) { + word-break: break-word; + } + + td:nth-child(3) { + white-space: nowrap; + } +} + +.sla-table > tbody::before { + content: "\200C"; + display: block; + line-height: 0.5em; +} + +/* Stuff that's missing in ipl <= 0.8 START */ + +.dropdown { + display: inline-block; + position: relative; + + .dropdown-toggle::after { + content: ""; + display: inline-block; + width: 0; + height: 0; + margin-left: .255em; + vertical-align: .255em; + border-top: .3em solid; + border-right: .3em solid transparent; + border-bottom: 0; + border-left: .3em solid transparent; + } + + .dropdown-menu { + display: none; + min-width: 10em; + border: 1px solid @gray-light; + background: @body-bg-color; + margin: -.25em; + border-radius: .25em; + padding: .25em; + position: absolute; + } + + &:hover > .dropdown-menu { + display: block; + box-shadow: 0 0 2em 0 rgba(0,0,0,.2); + } + + .dropdown-item { + display: block; + padding: .5em; + margin: -.25em; + + &.action-link:hover { + padding: .5em; + background: @tr-hover-color; + .rounded-corners(0) + } + } +} + +.action-bar .dropdown:first-child:hover .dropdown-menu { + left: .25em; +} + +.action-bar .dropdown:last-child:hover .dropdown-menu { + right: .25em; +} + +.action-bar > *:not(:last-child) { + margin-right: .5em; +} + +/* Stuff that's missing in ipl <= 0.8 END */ + +@font-family-print: "Helvetica Neue", "Helvetica", "Arial", sans-serif; + +.page-size-a4 { + background-color: white; + box-shadow: 0 0 0.25cm rgba(0,0,0,0.5); + display: block; + margin: 0 auto 0.5cm; + font-family: @font-family-print; + page-break-after: always; + height: 29.7cm; + width: 21cm; +} + +.page-content { + display: flex; + flex-direction: column; +} + +.cover-page { + background-repeat: no-repeat; + background-position: center; +} + +.cover-page-content { + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + + height: 100%; + width: 100%; + + h2 { + text-align: center; + } +} + +@gutter: 0.5em; + +.grid { + display: flex; + justify-content: space-between; + + &.with-gutters { + margin-left: -0.5 * @gutter; + margin-right: -0.5 * @gutter; + + > * { + margin-left: 0.5 * @gutter; + margin-right: 0.5 * @gutter; + } + } +} + +.main { + flex: 1; + + display: flex; + align-items: center; + flex-direction: column; + justify-content: space-around; +} + +.preview .main { + background-image: url(../static/img?file=graph-dummy.svg&module_name=reporting);; + background-position: center center; + background-repeat: no-repeat; + background-size: contain; +} + +.header, +.footer { + .grid(); +} + +@media print { + font-family: @font-family-print; +} + +.preview .page { + .page-size-a4(); +} + +/* Form fallback styles, remove once <=2.9.5 support is dropped */ + +.icinga-controls { + input[type="file"] { + background-color: @low-sat-blue; + } + + button[type="button"] { + background-color: @low-sat-blue; + } +} + +form.icinga-form { + input[type="file"] { + flex: 1 1 auto; + width: 0; + } + + button[type="button"] { + line-height: normal; + } +} + +/* Form fallback styles end */ diff --git a/public/css/system-report.css b/public/css/system-report.css new file mode 100644 index 0000000..cf42ae6 --- /dev/null +++ b/public/css/system-report.css @@ -0,0 +1,81 @@ +/* Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 */ + +.system-report { + background-color: #fff; + color: #222; + font-family: sans-serif; + + width: 100%; +} +.system-report pre { + margin: 0; + font-family: monospace; +} +.system-report a:link { + color: #009; + text-decoration: none; + background-color: #fff; +} +.system-report a:hover { + text-decoration: underline; +} +.system-report table { + border-collapse: collapse; + border: 0; + width: 934px; + box-shadow: 1px 2px 3px #ccc; +} +.system-report .center { + text-align: center; +} +.system-report .center table { + margin: 1em auto; + text-align: left; +} +.system-report .center th { + text-align: center !important; +} +.system-report td, +.system-report th { + border: 1px solid #666; + font-size: 75%; + vertical-align: baseline; + padding: 4px 5px; +} +.system-report h1 { + font-size: 150%; +} +.system-report h2 { + font-size: 125%; +} +.system-report .p { + text-align: left; +} +.system-report .e { + background-color: #ccf; + width: 300px; + font-weight: bold; +} +.system-report .h { + background-color: #99c; + font-weight: bold; +} +.system-report .v { + background-color: #ddd; + max-width: 300px; + overflow-x: auto; + word-wrap: break-word; +} +.system-report .v i { + color: #999; +} +.system-report img { + float: right; + border: 0; +} +.system-report hr { + width: 934px; + background-color: #ccc; + border: 0; + height: 1px; +} diff --git a/public/css/vendor/flatpickr.css b/public/css/vendor/flatpickr.css new file mode 100644 index 0000000..64eb467 --- /dev/null +++ b/public/css/vendor/flatpickr.css @@ -0,0 +1,784 @@ +.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 new file mode 100644 index 0000000..46c57b7 --- /dev/null +++ b/public/css/vendor/flatpickr.min.css @@ -0,0 +1,13 @@ +.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/img/select-icon-2x.png b/public/img/select-icon-2x.png Binary files differnew file mode 100644 index 0000000..8d24b10 --- /dev/null +++ b/public/img/select-icon-2x.png diff --git a/public/img/select-icon.png b/public/img/select-icon.png Binary files differnew file mode 100644 index 0000000..0cf5132 --- /dev/null +++ b/public/img/select-icon.png diff --git a/public/img/textarea-corner-2x.png b/public/img/textarea-corner-2x.png Binary files differnew file mode 100644 index 0000000..ee9cb50 --- /dev/null +++ b/public/img/textarea-corner-2x.png diff --git a/public/img/textarea-corner.png b/public/img/textarea-corner.png Binary files differnew file mode 100644 index 0000000..3a2242c --- /dev/null +++ b/public/img/textarea-corner.png diff --git a/public/js/module.js b/public/js/module.js new file mode 100644 index 0000000..f65a2d9 --- /dev/null +++ b/public/js/module.js @@ -0,0 +1,50 @@ +// 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 = $('<div>'); + 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 new file mode 100644 index 0000000..15d7397 --- /dev/null +++ b/public/js/vendor/flatpickr.js @@ -0,0 +1,2605 @@ +/* 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: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M13.207 8.472l-7.854 7.854-0.707-0.707 7.146-7.146-7.146-7.148 0.707-0.707 7.854 7.854z' /></svg>", + noCalendar: false, + now: new Date(), + onChange: [], + onClose: [], + onDayCreate: [], + onDestroy: [], + onKeyDown: [], + onMonthChange: [], + onOpen: [], + onParseConfig: [], + onReady: [], + onValueUpdate: [], + onYearChange: [], + onPreCalendarPosition: [], + plugins: [], + position: "auto", + positionElement: undefined, + prevArrow: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M5.207 8.471l7.146 7.147-0.707 0.707-7.853-7.854 7.854-7.853 0.707 0.707-7.147 7.146z' /></svg>", + 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", "<span class='flatpickr-day'>" + self.config.getWeek(date) + "</span>"); + } + 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 <span class='flatpickr-weekday'>\n " + weekdays.join("</span><span class='flatpickr-weekday'>") + "\n </span>\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 new file mode 100644 index 0000000..c850b7c --- /dev/null +++ b/public/js/vendor/flatpickr.min.js @@ -0,0 +1,2 @@ +/* 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<a;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},t=["onChange","onClose","onDayCreate","onDestroy","onKeyDown","onMonthChange","onOpen","onParseConfig","onReady","onValueUpdate","onYearChange","onPreCalendarPosition"],n={_disable:[],_enable:[],allowInput:!1,altFormat:"F j, Y",altInput:!1,altInputClass:"form-control input",animate:"object"==typeof window&&-1===window.navigator.userAgent.indexOf("MSIE"),ariaDateFormat:"F j, Y",clickOpens:!0,closeOnSelect:!0,conjunction:", ",dateFormat:"Y-m-d",defaultHour:12,defaultMinute:0,defaultSeconds:0,disable:[],disableMobile:!1,enable:[],enableSeconds:!1,enableTime:!1,errorHandler:function(e){return"undefined"!=typeof console&&console.warn(e)},getWeek:function(e){var t=new Date(e.getTime());t.setHours(0,0,0,0),t.setDate(t.getDate()+3-(t.getDay()+6)%7);var n=new Date(t.getFullYear(),0,4);return 1+Math.round(((t.getTime()-n.getTime())/864e5-3+(n.getDay()+6)%7)/7)},hourIncrement:1,ignoredFocusElements:[],inline:!1,locale:"default",minuteIncrement:5,mode:"single",monthSelectorType:"dropdown",nextArrow:"<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M13.207 8.472l-7.854 7.854-0.707-0.707 7.146-7.146-7.146-7.148 0.707-0.707 7.854 7.854z' /></svg>",noCalendar:!1,now:new Date,onChange:[],onClose:[],onDayCreate:[],onDestroy:[],onKeyDown:[],onMonthChange:[],onOpen:[],onParseConfig:[],onReady:[],onValueUpdate:[],onYearChange:[],onPreCalendarPosition:[],plugins:[],position:"auto",positionElement:void 0,prevArrow:"<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M5.207 8.471l7.146 7.147-0.707 0.707-7.853-7.854 7.854-7.853 0.707 0.707-7.147 7.146z' /></svg>",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="";h<s.length;h++){var w=s[h],b="\\"===w,C="\\"===s[h-1]||b;if(p[w]&&!C){D+=p[w];var M=new RegExp(D).exec(e);M&&(f=!0)&&m["Y"!==w?"push":"unshift"]({fn:g[w],val:M[++v]})}else b||(D+=".");m.forEach(function(e){var t=e.fn,n=e.val;return l=t(l,n,c)||l})}l=f?l:void 0}}if(l instanceof Date&&!isNaN(l.getTime()))return!0===a&&l.setHours(0,0,0,0),l;i.errorHandler(new Error("Invalid date provided: "+d))}}};function w(e,t,n){return void 0===n&&(n=!0),!1!==n?new Date(e.getTime()).setHours(0,0,0,0)-new Date(t.getTime()).setHours(0,0,0,0):e.getTime()-t.getTime()}var b=function(e,t,n){return e>Math.min(t,n)&&e<Math.max(t,n)},C={DAY:864e5};"function"!=typeof Object.assign&&(Object.assign=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(!e)throw TypeError("Cannot convert undefined or null to object");for(var a=function(t){t&&Object.keys(t).forEach(function(n){return e[n]=t[n]})},i=0,o=t;i<o.length;i++){a(o[i])}return e});var M=300;function y(f,g){var h={config:e({},n,E.defaultConfig),l10n:a};function y(e){return e.bind(h)}function x(){var e=h.config;!1===e.weekNumbers&&1===e.showMonths||!0!==e.noCalendar&&window.requestAnimationFrame(function(){if(void 0!==h.calendarContainer&&(h.calendarContainer.style.visibility="hidden",h.calendarContainer.style.display="block"),void 0!==h.daysContainer){var t=(h.days.offsetWidth+1)*e.showMonths;h.daysContainer.style.width=t+"px",h.calendarContainer.style.width=t+(void 0!==h.weekWrapper?h.weekWrapper.offsetWidth:0)+"px",h.calendarContainer.style.removeProperty("visibility"),h.calendarContainer.style.removeProperty("display")}})}function T(e){0===h.selectedDates.length&&ie(),void 0!==e&&"blur"!==e.type&&function(e){e.preventDefault();var t="keydown"===e.type,n=e.target;void 0!==h.amPM&&e.target===h.amPM&&(h.amPM.textContent=h.l10n.amPM[o(h.amPM.textContent===h.l10n.amPM[0])]);var a=parseFloat(n.getAttribute("min")),r=parseFloat(n.getAttribute("max")),l=parseFloat(n.getAttribute("step")),c=parseInt(n.value,10),d=e.delta||(t?38===e.which?1:-1:0),s=c+l*d;if(void 0!==n.value&&2===n.value.length){var u=n===h.hourElement,f=n===h.minuteElement;s<a?(s=r+s+o(!u)+(o(u)&&o(!h.amPM)),f&&j(void 0,-1,h.hourElement)):s>r&&(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<h.now?h.config.maxDate:h.now),a=h.currentYear,i=h.currentMonth;try{void 0!==n&&(h.currentYear=n.getFullYear(),h.currentMonth=n.getMonth())}catch(e){e.message="Invalid date supplied: "+n,h.config.errorHandler(e)}t&&h.currentYear!==a&&(ge("onYearChange"),K()),!t||h.currentYear===a&&h.currentMonth===i||ge("onMonthChange"),h.redraw()}function P(e){~e.target.className.indexOf("arrow")&&j(e,e.target.classList.contains("arrowUp")?1:-1)}function j(e,t,n){var a=e&&e.target,i=n||a&&a.parentNode&&a.parentNode.firstChild,o=pe("increment");o.delta=t,i&&i.dispatchEvent(o)}function H(e,t,n,a){var i=X(t,!0),o=d("span","flatpickr-day "+e,t.getDate().toString());return o.dateObj=t,o.$i=a,o.setAttribute("aria-label",h.formatDate(t,h.config.ariaDateFormat)),-1===e.indexOf("hidden")&&0===w(t,h.now)&&(h.todayDateElem=o,o.classList.add("today"),o.setAttribute("aria-current","date")),i?(o.tabIndex=-1,he(t)&&(o.classList.add("selected"),h.selectedDateElem=o,"range"===h.config.mode&&(c(o,"startRange",h.selectedDates[0]&&0===w(t,h.selectedDates[0],!0)),c(o,"endRange",h.selectedDates[1]&&0===w(t,h.selectedDates[1],!0)),"nextMonthDay"===e&&o.classList.add("inRange")))):o.classList.add("flatpickr-disabled"),"range"===h.config.mode&&function(e){return!("range"!==h.config.mode||h.selectedDates.length<2)&&w(e,h.selectedDates[0])>=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","<span class='flatpickr-day'>"+h.config.getWeek(t)+"</span>"),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&&d<c&&d!=(t>0?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;t<h.config.showMonths;t++){var n=new Date(h.currentYear,h.currentMonth,1);n.setMonth(h.currentMonth+t),e.appendChild(B(n.getFullYear(),n.getMonth()))}h.daysContainer.appendChild(e),h.days=h.daysContainer.firstChild,"range"===h.config.mode&&1===h.selectedDates.length&&ne()}}function K(){if(!(h.config.showMonths>1||"dropdown"!==h.config.monthSelectorType)){var e=function(e){return!(void 0!==h.config.minDate&&h.currentYear===h.config.minDate.getFullYear()&&e<h.config.minDate.getMonth())&&!(void 0!==h.config.maxDate&&h.currentYear===h.config.maxDate.getFullYear()&&e>h.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<t.length&&(t=t.splice(e,t.length).concat(t.splice(0,e)));for(var n=h.config.showMonths;n--;)h.weekdayContainer.children[n].innerHTML="\n <span class='flatpickr-weekday'>\n "+t.join("</span><span class='flatpickr-weekday'>")+"\n </span>\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&&e<h.config.minDate.getFullYear()||h.config.maxDate&&e>h.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<i.length;o++){if("function"==typeof(r=i[o])&&r(n))return a;if(r instanceof Date&&void 0!==n&&r.getTime()===n.getTime())return a;if("string"==typeof r&&void 0!==n){var l=h.parseDate(r,void 0,!0);return l&&l.getTime()===n.getTime()?a:!a}if("object"==typeof r&&void 0!==n&&r.from&&r.to&&n.getTime()>=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;c<i;c+=C.DAY)X(new Date(c),!0)||(o=o||c>a&&c<i,c<n&&(!r||c>r)?r=c:c>n&&(!l||c<l)&&(l=c));for(var d=0;d<h.config.showMonths;d++)for(var s=h.daysContainer.children[d],u=function(a,i){var c=s.children[a],d=c.dateObj.getTime(),u=r>0&&d<r||l>0&&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"),n<t&&d===n?c.classList.add("startRange"):n>t&&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;f<m;f++)u(f)}}function ae(){!h.isOpen||h.config.static||h.config.inline||le()}function ie(){h.setDate(void 0!==h.config.minDate?new Date(h.config.minDate.getTime()):new Date,!0),S(),we()}function oe(e){return function(t){var n=h.config["_"+e+"Date"]=h.parseDate(t,h.config.dateFormat),a=h.config["_"+("min"===e?"max":"min")+"Date"];void 0!==n&&(h["min"===e?"minDateHasTime":"maxDateHasTime"]=n.getHours()>0||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&&d<n&&l.top>n,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||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]&&a<n.length;a++)n[a](h.selectedDates,h.input.value,h,t);"onChange"===e&&(h.input.dispatchEvent(pe("change")),h.input.dispatchEvent(pe("input")))}}function pe(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!0),t}function he(e){for(var t=0;t<h.selectedDates.length;t++)if(0===w(h.selectedDates[t],e))return""+t;return!1}function ve(){h.config.noCalendar||h.isMobile||!h.monthNav||(h.yearElements.forEach(function(e,t){var n=new Date(h.currentYear,h.currentMonth,1);n.setMonth(h.currentMonth+t),h.config.showMonths>1||"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.currentYear<h.config.minDate.getFullYear()),h._hideNextMonthArrow=void 0!==h.config.maxDate&&(h.currentYear===h.config.maxDate.getFullYear()?h.currentMonth+1>h.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<a.length;u++)h.config[a[u]]=!0===h.config[a[u]]||"true"===h.config[a[u]];t.filter(function(e){return void 0!==h.config[e]}).forEach(function(e){h.config[e]=l(h.config[e]||[]).map(y)}),h.isMobile=!h.config.disableMobile&&!h.config.inline&&"single"===h.config.mode&&!h.config.disable.length&&!h.config.enable.length&&!h.config.weekNumbers&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);for(var u=0;u<h.config.plugins.length;u++){var m=h.config.plugins[u](h)||{};for(var p in m)t.indexOf(p)>-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()<h.now.getTime()?h.config.maxDate:h.now,h.currentYear=h._initialDate.getFullYear(),h.currentMonth=h._initialDate.getMonth(),h.selectedDates.length>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;i<n.length;i++){var o=n[i];try{if(null!==o.getAttribute("data-fp-omit"))continue;void 0!==o._flatpickr&&(o._flatpickr.destroy(),o._flatpickr=void 0),o._flatpickr=y(o,t||{}),a.push(o._flatpickr)}catch(e){console.error(e)}}return 1===a.length?a[0]:a}"undefined"!=typeof HTMLElement&&"undefined"!=typeof HTMLCollection&&"undefined"!=typeof NodeList&&(HTMLCollection.prototype.flatpickr=NodeList.prototype.flatpickr=function(e){return x(this,e)},HTMLElement.prototype.flatpickr=function(e){return x([this],e)});var E=function(e,t){return"string"==typeof e?x(window.document.querySelectorAll(e),t):e instanceof Node?x([e],t):x(e,t)};return E.defaultConfig={},E.l10ns={en:e({},a),default:e({},a)},E.localize=function(t){E.l10ns.default=e({},E.l10ns.default,t)},E.setDefaults=function(t){E.defaultConfig=e({},E.defaultConfig,t)},E.parseDate=D({}),E.formatDate=v({}),E.compareDates=w,"undefined"!=typeof jQuery&&void 0!==jQuery.fn&&(jQuery.fn.flatpickr=function(e){return x(this,e)}),Date.prototype.fp_incr=function(e){return new Date(this.getFullYear(),this.getMonth(),this.getDate()+("string"==typeof e?parseInt(e,10):e))},"undefined"!=typeof window&&(window.flatpickr=E),E});
\ No newline at end of file @@ -0,0 +1,15 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting { + + use Icinga\Application\Icinga; + + /** @var \Icinga\Application\Modules\Module $this */ + + $this->provideHook('reporting/Report', '\\Icinga\\Module\\Reporting\\Reports\\SystemReport'); + + $this->provideHook('reporting/Action', '\\Icinga\\Module\\Reporting\\Actions\\SendMail'); + + Icinga::app()->getLoader()->registerNamespace('reportingipl\Html', __DIR__ . '/library/vendor/ipl/Html/src'); +} diff --git a/schema/mysql-migrations/v0.10.0.sql b/schema/mysql-migrations/v0.10.0.sql new file mode 100644 index 0000000..638135b --- /dev/null +++ b/schema/mysql-migrations/v0.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-migrations/v0.9.1.sql b/schema/mysql-migrations/v0.9.1.sql new file mode 100644 index 0000000..bd71b37 --- /dev/null +++ b/schema/mysql-migrations/v0.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.sql b/schema/mysql.sql new file mode 100644 index 0000000..5f70481 --- /dev/null +++ b/schema/mysql.sql @@ -0,0 +1,96 @@ +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/postgresql.sql b/schema/postgresql.sql new file mode 100644 index 0000000..329a65f --- /dev/null +++ b/schema/postgresql.sql @@ -0,0 +1,83 @@ +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 +); |