Fix/Reimplement dashboard

refs #4532
This commit is contained in:
Jannis Moßhammer 2013-10-22 12:08:44 +02:00
parent 7b3646e9fd
commit f7c0eaa7c4
21 changed files with 1158 additions and 133 deletions

View File

@ -56,7 +56,8 @@ class AddUrlForm extends Form
array(
'label' => 'Dashboard',
'required' => true,
'style' => 'display:inline-block',
'style' => 'display:inline-block;',
'multiOptions' => $dashboard->getPaneKeyTitleArray()
)
);
@ -64,8 +65,9 @@ class AddUrlForm extends Form
$newDashboardBtn = new Zend_Form_Element_Submit(
'create_new_pane',
array(
'label' => '+',
'label' => 'Create A New Pane',
'required' => false,
'class' => 'btn btn-default',
'style' => 'display:inline-block'
)
);
@ -83,7 +85,7 @@ class AddUrlForm extends Form
* Add a textfield for creating a new pane to this form
*
*/
private function addNewPaneTextField()
private function addNewPaneTextField($showExistingButton = true)
{
$txtCreatePane = new Zend_Form_Element_Text(
'pane',
@ -106,18 +108,22 @@ class AddUrlForm extends Form
$cancelDashboardBtn = new Zend_Form_Element_Submit(
'use_existing_dashboard',
array(
'label' => '{{REMOVE_ICON}}',
'required' => false,
'style' => 'display:inline-block'
'class' => 'btn',
'escape' => false,
'label' => 'Use An Existing Dashboard',
'required' => false
)
);
$cancelDashboardBtn->removeDecorator('DtDdWrapper');
$txtCreatePane->removeDecorator('DtDdWrapper');
$txtCreatePane->removeDecorator('htmlTag');
$this->addElement($txtCreatePane);
$this->addElement($cancelDashboardBtn);
if ($showExistingButton) {
$this->addElement($cancelDashboardBtn);
}
$this->addElement($markAsNewPane);
}
@ -146,7 +152,7 @@ class AddUrlForm extends Form
!$this->getRequest()->getPost('use_existing_dashboard', '0')) // and the user didn't click the 'use
// existing' button
) {
$this->addNewPaneTextField();
$this->addNewPaneTextField(!empty($elems));
} else {
$this->addPaneSelectionBox($dashboard);
}
@ -159,7 +165,7 @@ class AddUrlForm extends Form
'required' => true,
)
);
$this->setSubmitLabel("{{CREATE_ICON}} Add To Dashboard");
$this->setSubmitLabel("Add To Dashboard");
}
}

View File

@ -1,3 +1,5 @@
<h3>Add Dashboard URL</h3>
<h1>Hosts Status</h1>
<?= $this->form->render($this); ?>
<div style="max-width:600px" >
<?= $this->form->render($this); ?>
</div>

View File

@ -1,3 +1,5 @@
<?= $this->tabs->render($this); ?>
<?= $this->dashboard->render($this); ?>
<div class="dashboard" data-columns>
<?= $this->dashboard->render($this); ?>
</div>

View File

@ -59,10 +59,10 @@ class Palette
* @var array
*/
public $colorSets = array(
self::OK => array('#00FF00','#00C90D', '#008209', '#238C47', '#00BB3F', '#37DD6F'),
self::PROBLEM => array('#FF0000','#FF1300', '#FF4E40', '#A60C00', '#FF4500', '#A62D00'),
self::WARNING => array('#FFFF00', 'B4B400' , '#A6A600', '#F5FF73', '#FFB300', '#BFA730'),
self::NEUTRAL => array('#232323', '#009999', '#1D7373', '#ACACFF', '#8F9ABF', '#356AA6')
self::OK => array('#00FF00'),
self::PROBLEM => array('#FF0000'),
self::WARNING => array('#FFFF00'),
self::NEUTRAL => array('#f3f3f3')
);
/**
@ -79,8 +79,10 @@ class Palette
}
$color = current($this->colorSets[$type]);
echo $type;
if ($color === false) {
reset($this->colorSets[$type]);
$color = current($this->colorSets[$type]);
}
next($this->colorSets[$type]);

View File

@ -112,6 +112,9 @@ class PieChart extends Chart
if ($total === 100) {
return;
}
if ($total == 0) {
return;
}
foreach ($pie['data'] as &$slice) {
$slice = $slice/$total * 100;
}
@ -181,7 +184,7 @@ class PieChart extends Chart
private function getColorForPieSlice(array $pie, $dataIdx)
{
if (isset($pie['colors']) && is_array($pie['colors']) && isset($pie['colors'][$dataIdx])) {
return $pie['colors']['dataIdx'];
return $pie['colors'][$dataIdx];
}
$type = Palette::NEUTRAL;
if (isset($pie['palette']) && is_array($pie['palette']) && isset($pie['palette'][$dataIdx])) {
@ -203,6 +206,7 @@ class PieChart extends Chart
foreach ($this->pies as $pie) {
$labelPos = 0;
$lastRadius = 0;
foreach ($pie['data'] as $idx => $dataset) {
$slice = new PieSlice($radius, $dataset, $lastRadius);
$slice->setX($x)
@ -244,13 +248,21 @@ class PieChart extends Chart
$offset = isset($this->pies[$i+1]) ? $radius - $shrinkStep : 0;
$labelPos = 0;
$lastRadius = 0;
foreach ($pie['data'] as $idx => $dataset) {
foreach ($pie['data'] as $idx => $dataset) {
$color = $this->getColorForPieSlice($pie, $idx);
if ($dataset === 100) {
$dataset = 99.9;
}
if ($dataset == 0) {
$labelPos++;
continue;
}
$slice = new PieSlice($radius, $dataset, $lastRadius);
$slice->setY(50)
->setX($x)
->setStrokeColor('#000')
->setStrokeWidth(1)
->setFill($this->getColorForPieSlice($pie, $idx))
->setFill($color)
->setLabelGroup($labelBox);
if (!$this->noCaption && isset($pie['labels'])) {

View File

@ -178,13 +178,13 @@ class PieSlice extends Animatable implements Drawable
$midX += ($addOffset + $r/1.8) * ($midRadius > M_PI ? -1 : 1);
$path->append(array($midX, $midY))->toAbsolute();
$midX += intval($r/2 * sin(M_PI/7)) * ($midRadius > M_PI ? -1 : 1);
$midX += intval($r/2 * sin(M_PI/9)) * ($midRadius > M_PI ? -1 : 1);
$midY -= intval($r/2 * cos(M_PI/7)) * ($midRadius < M_PI*1.5 && $midRadius > M_PI/2 ? -1 : 1);
if ($ctx->ytoRelative($midY) > 100) {
$midY = $ctx->yToAbsolute(100);
} elseif ($ctx->ytoRelative($midY) < 0) {
$midY = $ctx->yToAbsolute(0);
$midY = $ctx->yToAbsolute($ctx->ytoRelative(100+$midY));
}
$path->append(array($midX , $midY));

View File

@ -74,13 +74,13 @@ class LinearUnit implements AxisUnit
*
* @var int
*/
private $currentTick = 0;
protected $currentTick = 0;
/**
* The currently displayed value
* @var int
*/
private $currentValue = 0;
protected $currentValue = 0;
/**
* Create and initialize this AxisUnit

View File

@ -250,6 +250,7 @@ class Tree
*/
public static function normalizeTree($node)
{
if ($node->type === Node::TYPE_OPERATOR) {
return $node;
}

View File

@ -201,6 +201,9 @@ class ActionController extends Zend_Controller_Action
if ($this->_request->isXmlHttpRequest()) {
$target = ($this->getParam('render') === 'detail') ? 'inline' : 'body';
if ($target !== 'inline') {
$target = ($this->getParam('view') === 'compact') ? 'inline' : 'body';
}
$this->_helper->layout()->setLayout($target);
}
}

View File

@ -612,7 +612,9 @@ class Form extends Zend_Form
$el->removeDecorator('Label');
$el->removeDecorator('DtDdWrapper');
$el->addDecorator(new BootstrapForm());
$el->setAttrib('class', $el->getAttrib('class') . ' form-control input-sm');
if ($el->getId() === 'btn_submit' || stripos($el->getAttrib('class'), 'btn') === false) {
$el->setAttrib('class', $el->getAttrib('class') . ' form-control input-sm');
}
}
return $this;

View File

@ -29,9 +29,13 @@
namespace Icinga\Web\Widget\Dashboard;
use Icinga\Util\Dimension;
use Icinga\Web\Form;
use Icinga\Web\Url;
use Icinga\Web\Widget\Widget;
use Zend_View_Abstract;
use Zend_Config;
use Zend_Form_Element_Submit;
use Zend_Form_Element_Button;
/**
* A dashboard pane component
@ -81,18 +85,16 @@ class Component implements Widget
*/
private $template =<<<'EOD'
<div class="panel panel-default" style="{DIMENSION}">
<div class="panel-heading panel-title">
<a href="{URL}"> {TITLE}</a>
<button class="btn btn-danger btn-sm pull-right">
<a href="{REMOVE_URL}" style="color:black">{{REMOVE_ICON}}</a>
</button>
</div>
<div class="panel-body">
<noscript>
<iframe src="{URL}" style="height:100%; width:99%" frameborder="no"></iframe>
</noscript>
<div data-icinga-component="app/dashboard" class="dashboard-component" data-icinga-url="{URL}">
<h1 class="pull-left"><a data-icinga-target="self" href="{FULL_URL}"> {TITLE}</a></h1>
{REMOVE_BTN}
<div class="container">
</div>
<noscript>
<iframe src="{URL}" style="height:100%; width:99%" frameborder="no"></iframe>
</noscript>
</div>
EOD;
@ -194,11 +196,27 @@ EOD;
/**
* @see Widget::render()
*/
public function render(\Zend_View_Abstract $view)
public function render(Zend_View_Abstract $view)
{
$url = clone($this->url);
$url->addParams(array('view' => 'compact'));
$html = str_replace('{URL}', $url->getAbsoluteUrl(), $this->template);
$html = str_replace('{FULL_URL}', $url->getUrlWithout('view')->getAbsoluteUrl(), $html);
$html = str_replace('{REMOVE_BTN}', $this->getRemoveForm($view), $html);
$html = str_replace('{DIMENSION}', $this->getBoxSizeAsCSS(), $html);
$html = str_replace('{TITLE}', htmlentities($this->getTitle()), $html);
return $html;
}
/**
* Render the form for removing a dashboard elemetn
*
* @param Zend_View_Abstract $view The view to use for rendering
* @return string The html representation of the form
*/
public function getRemoveForm(Zend_View_Abstract $view)
{
$removeUrl = Url::fromPath(
'/dashboard/removecomponent',
array(
@ -206,12 +224,18 @@ EOD;
'component' => $this->getTitle()
)
);
$html = str_replace('{URL}', $url->getAbsoluteUrl(), $this->template);
$html = str_replace('{REMOVE_URL}', $removeUrl, $html);
$html = str_replace('{DIMENSION}', $this->getBoxSizeAsCSS(), $html);
$html = str_replace('{TITLE}', htmlentities($this->getTitle()), $html);
return $html;
$form = new Form();
$form->setMethod('POST');
$form->setAction($removeUrl);
$form->addElement(new Zend_Form_Element_Button(
'remove_pane_btn',
array(
'class'=> 'btn btn-danger pull-right',
'type' => 'submit',
'label' => 'Remove'
)
));
return $form->render($view);
}
/**

View File

@ -33,8 +33,11 @@ use Icinga\Web\Form;
use Icinga\Web\Controller\ActionController;
use Icinga\Chart\SVGRenderer;
use Icinga\Chart\GridChart;
use Icinga\Module\Monitoring\DataView\Groupsummary as GroupsummaryView;
use Icinga\Module\Monitoring\Backend;
use Icinga\Chart\Palette;
use Icinga\Chart\Axis;
use Icinga\Chart\PieChart;
/**
* Class Monitoring_CommandController
@ -65,7 +68,7 @@ class Monitoring_ChartController extends ActionController
*/
public function init()
{
$this->backend = Backend::getInstance($this->_getParam('backend'));
}
public function testAction() {
@ -100,7 +103,7 @@ class Monitoring_ChartController extends ActionController
$this->chart->drawBars(
array(
'label' => 'Some other line',
'color' => 'black',
'color' => 'green',
'data' => $data3,
'showPoints' => true
)
@ -111,11 +114,72 @@ class Monitoring_ChartController extends ActionController
'label' => 'Nr of outtakes',
'color' => 'yellow',
'width' => '5',
'data' => $data2
)
);
$this->view->svg = $this->chart;
}
public function hostgroupAction()
{
$query = GroupsummaryView::fromRequest(
$this->_request,
array(
'hostgroup_name',
'cnt_hosts_up',
'cnt_hosts_unreachable',
'cnt_hosts_unreachable_unhandled',
'cnt_hosts_down',
'cnt_hosts_down_unhandled',
'cnt_hosts_pending',
'cnt_services_ok',
'cnt_services_unknown',
'cnt_services_unknown_unhandled',
'cnt_services_critical',
'cnt_services_critical_unhandled',
'cnt_services_warning',
'cnt_services_warning_unhandled',
'cnt_services_pending'
)
)->getQuery()->fetchRow();
$this->view->chart = new PieChart();
$this->view->chart->drawPie(
array(
'data' => array(
(int) $query->cnt_hosts_up,
(int) $query->cnt_hosts_down,
(int) $query->cnt_hosts_unreachable,
(int) $query->cnt_hosts_pending
),
'colors' => array('00ff00', 'ff0000', 'ffff00', 'fefefe'),
'labels'=> array(
(int) $query->cnt_hosts_up . ' Up Hosts',
(int) $query->cnt_hosts_down . ' Down Hosts',
(int) $query->cnt_hosts_unreachable . ' Unreachable Hosts',
(int) $query->cnt_hosts_pending . ' Pending Hosts'
)
),
array(
'data' => array(
(int) $query->cnt_services_ok,
(int) $query->cnt_services_warning,
(int) $query->cnt_services_critical,
(int) $query->cnt_services_unknown,
(int) $query->cnt_services_pending
),
'colors' => array('00ff00', 'ffff00','ff0000', 'efef00', 'fefefe'),
'labels'=> array(
$query->cnt_services_ok . ' Up Services',
$query->cnt_services_warning . ' Warning Services',
$query->cnt_services_critical . ' Down Services',
$query->cnt_services_unknown . ' Unreachable Services',
$query->cnt_services_pending . ' Pending Services'
)
)
);
}
}

View File

@ -0,0 +1,6 @@
<div style="width:500px; height:300px;margin:auto">
<?=
$chart->render();
?>
</div>

View File

@ -1,94 +1,87 @@
<?php
$viewHelper = $this->getHelper('MonitoringState');
?>
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="multi">
<table class="table table-condensed" style="font-size:9pt" >
<tbody>
<?php foreach($hosts as $host): ?>
<?php $hostStateName = strtolower($this->util()->getHostStateName($host->host_state)); ?>
<?php $hostLink = $this->href('monitoring/show/host', array('host' => $host->host_name)); ?>
<tr <?= ($this->activeRowHref === $hostLink) ? 'class="active"' : ''; ?> >
<!-- Color column -->
<td class="tacheader-status-<?= $hostStateName; ?>">
<a style="visibility:hidden" href="<?= $hostLink; ?>"></a>
</td>
<!-- Icons -->
<td>
<?php if (!$host->host_handled && $host->host_state > 0): ?>
<a href="#" title="Unhandled">
<i class="icon-table icinga-icon-unhandled"></i>
</a>
<?php endif; ?>
<?php if ($host->host_acknowledged && !$host->host_in_downtime): ?>
<a href="#" title="Acknowledged">
<i class="icon-table icinga-icon-acknowledgement"></i>
</a>
<?php endif; ?>
<?php if ($host->host_is_flapping): ?>
<a href="#" title="Flapping">
<i class="icon-table icinga-icon-flapping"></i>
</a>
<?php endif; ?>
<?php if (!$host->host_notifications_enabled): ?>
<a href="#" title="Notifications Disabled">
<i class="icon-table icinga-icon-notification-disabled"></i>
</a>
<?php endif; ?>
<?php if ($host->host_in_downtime): ?>
<a href="#" title="In Downtime">
<i class="icon-table icinga-icon-in-downtime"></i>
</a>
<?php endif; ?>
<?php if (!$host->host_active_checks_enabled): ?>
<?php if (!$host->host_passive_checks_enabled): ?>
<a href="#" title="Active And Passive Checks Disabled">
<i class="icinga-icon-active-passive-checks-disabled"></i>
</a>
<?php else: ?>
<a href="#" title="Active Checks Disabled">
<i class="icon-table icinga-icon-active-checks-disabled"></i>
</a>
<?php endif; ?>
<?php endif; ?>
<?php if ($host->host_last_comment !== null): ?>
<a href="#" title="Comments">
<i class="icon-table icinga-icon-comment"></i>
</a>
<?php endif; ?>
</td>
<!-- State -->
<td title="<?= $viewHelper->getStateTitle($host, 'host'); ?>">
<a href="<?= $this->href('monitoring/list/services', array('host' => $host->host_name)) ?>">
<strong><?= $host->host_name ?></strong>
</a>
</td>
<td>
<div class="output-text">
<?= $this->escape(substr(strip_tags($host->host_output), 0, 10000)); ?>
</div>
</td>
<?= $this->paginationControl($hosts, null, null, array('preserve' => $this->preserve)) ?>
<table class="table table-condensed">
<thead>
<tr>
<th colspan="2">Status</th>
<th>Host</th>
<th>Output</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($hosts as $host): ?>
<tr>
<td>
<div>
<?php if ($host->host_icon_image) : ?>
<img src="<?= $host->host_icon_image; ?>"/>
<?php endif; ?>
</div>
</td>
<td>
<div>
<?php if (!$host->host_handled && $host->host_state > 0): ?>
<a href="#" title="<?= 'Unhandled host' ?>">
<i>{{UNHANDLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($host->host_acknowledged && !$host->host_in_downtime): ?>
<a href="#" title="<?= 'Acknowledged' ?>">
<i>{{ACKNOWLEDGED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($host->host_is_flapping): ?>
<a href="#" title="<?= 'Flapping' ?>">
<i>{{FLAPPING_ICON}}</i>
</a>
<?php endif; ?>
<?php if (!$host->host_notifications_enabled): ?>
<a href="#" title="<?= 'Notifications disabled' ?>">
<i>{{NOTIFICATIONS_DISABLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($host->host_in_downtime): ?>
<a href="#" title="<?= 'In downtime' ?>">
<i>{{IN_DOWNTIME_ICON}}</i>
</a>
<?php endif; ?>
</div>
</td>
<td title="<?= $viewHelper->getStateTitle($host, 'host'); ?>">
<div>
<a href="<?= $this->href('monitoring/show/history', array('host' => $host->host_name)); ?>">
<b> <?= ucfirst($viewHelper->monitoringState($host, 'host')); ?> </b>
<div> Since&nbsp;
<?= $this->timeSince($host->host_last_state_change); ?>
<?php if ($host->host_state_type == 0): ?>
<a href="#" title="<?= 'Soft state' ?>">
<i>{{SOFTSTATE_ICON}}</i>
</a>
<?php endif; ?>
</div>
</a>
</div>
</td>
<td>
<?php if ($host->host_last_comment !== null): ?>
<a href="#" title="<?= 'Comments' ?>">
<i>{{COMMENT_ICON}}</i>
</a>
<?php endif; ?>
<a href="<?= $this->href('monitoring/show/host', array('host' => $host->host_name)); ?>">
<b><?= $host->host_name; ?></b>
<br/>
<i><?= $host->host_address; ?></i>
</a>
<?php if ($host->host_action_url != ''): ?>
<a href="<?= $host->host_action_url; ?>">Action</a>
<?php endif; ?>
<?php if ($host->host_notes_url != ''): ?>
<a href="<?= $host->host_notes_url; ?>">Notes</a>
<?php endif; ?>
</td>
<td>
<?= $this->escape(substr(strip_tags($host->host_output), 0, 500)); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</tbody>
</table>
</div>

View File

@ -107,6 +107,9 @@ class UrlViewFilter
public function normalizeTreeNode($node, Tree $subTree = null)
{
$subTree = $subTree ? $subTree : new Tree();
if (!$node) {
return $subTree;
}
if ($node->type === Node::TYPE_OPERATOR) {
$this->insertNormalizedOperatorNode($node, $subTree);
} else {

View File

@ -457,5 +457,12 @@ select.input-sm {
}
.panel-body {
}
.dashboard-component {
border: 1px solid @lightgrey;
float:left;
width:45%;
padding:1%;
margin:1%;
}

View File

@ -401,6 +401,7 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
mainDom.addClass('col-xs-pull-12 col-sm-pull-12 col-md-pull-12 col-lg-7');
detailDom.addClass('col-xs-push-12 col-sm-push-12 col-md-push-12 col-lg-5');
$(window).trigger('layoutchange');
};
/**
@ -426,6 +427,7 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
mainDom.addClass('col-sm-12');
detailDom.addClass('hidden-sm');
detailDom.removeAttr('data-icinga-href');
$(window).trigger('layoutchange');
};
/**
* Injects the icinga object into the Container class

View File

@ -0,0 +1,70 @@
/*global Icinga:false, document: false, define:false require:false base_url:false console:false */
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* 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.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Dashboard container, uses freetile for layout
*
*/
define(['jquery', 'logging', 'URIjs/URI', 'icinga/componentLoader'], function($, log, URI, components) {
'use strict';
return function(parent) {
this.dom = $(parent);
var dashboardContainer = this.dom.parent('div');
dashboardContainer.freetile();
this.container = this.dom.children('.container');
this.dashboardUrl = this.dom.attr('data-icinga-url');
var reloadTimeout = null;
/**
* Refresh the container content and layout
*/
this.refresh = function() {
$.ajax({
url: this.dashboardUrl
}).done((function(response) {
this.container.html(response);
dashboardContainer.freetile('layout');
$(window).on('layoutchange', function() {
dashboardContainer.freetile('layout');
});
this.triggerRefresh();
components.load();
}).bind(this)).fail((function(response, reason) {
this.container.html(response);
}).bind(this));
};
this.triggerRefresh = function() {
if (reloadTimeout) {
clearTimeout(reloadTimeout);
}
setTimeout(this.refresh.bind(this), 10000);
};
this.refresh();
};
});

View File

@ -4,6 +4,7 @@ requirejs.config({
'paths': {
'jquery': 'vendor/jquery-1.8.3',
'jquery_scrollto': 'vendor/jquery.scrollto',
'freetile': 'vendor/freetile',
'bootstrap': 'vendor/bootstrap/bootstrap.min',
'logging': 'icinga/util/logging',
'URIjs': 'vendor/uri',
@ -13,9 +14,13 @@ requirejs.config({
'datetimepicker': {
'exports': 'datetimepicker'
},
'jquery_scrollto': {
exports: 'jquery_scrollto'
},
'freetile': {
exports: 'freetile'
},
'jquery' : {
exports: 'jquery'
}
@ -26,7 +31,7 @@ define(['jquery'], function ($, history) {
window.$ = $;
window.jQuery = $;
requirejs(['bootstrap','jquery_scrollto'], function() {
requirejs(['bootstrap','vendor/imagesLoaded','jquery_scrollto', 'freetile'], function() {
requirejs(['datetimepicker']);
});
requirejs(['icinga/icinga'], function (Icinga) {

5
public/js/vendor/freetile.js vendored Normal file

File diff suppressed because one or more lines are too long

816
public/js/vendor/imagesLoaded.js vendored Normal file
View File

@ -0,0 +1,816 @@
/*!
* imagesLoaded PACKAGED v3.0.4
* JavaScript is all like "You images are done yet or what?"
* MIT License
*/
/*!
* EventEmitter v4.2.4 - git.io/ee
* Oliver Caldwell
* MIT license
* @preserve
*/
(function () {
'use strict';
/**
* Class for managing events.
* Can be extended to provide event functionality in other classes.
*
* @class EventEmitter Manages event registering and emitting.
*/
function EventEmitter() {}
// Shortcuts to improve speed and size
// Easy access to the prototype
var proto = EventEmitter.prototype;
/**
* Finds the index of the listener for the event in it's storage array.
*
* @param {Function[]} listeners Array of listeners to search through.
* @param {Function} listener Method to look for.
* @return {Number} Index of the specified listener, -1 if not found
* @api private
*/
function indexOfListener(listeners, listener) {
var i = listeners.length;
while (i--) {
if (listeners[i].listener === listener) {
return i;
}
}
return -1;
}
/**
* Alias a method while keeping the context correct, to allow for overwriting of target method.
*
* @param {String} name The name of the target method.
* @return {Function} The aliased method
* @api private
*/
function alias(name) {
return function aliasClosure() {
return this[name].apply(this, arguments);
};
}
/**
* Returns the listener array for the specified event.
* Will initialise the event object and listener arrays if required.
* Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
* Each property in the object response is an array of listener functions.
*
* @param {String|RegExp} evt Name of the event to return the listeners from.
* @return {Function[]|Object} All listener functions for the event.
*/
proto.getListeners = function getListeners(evt) {
var events = this._getEvents();
var response;
var key;
// Return a concatenated array of all matching events if
// the selector is a regular expression.
if (typeof evt === 'object') {
response = {};
for (key in events) {
if (events.hasOwnProperty(key) && evt.test(key)) {
response[key] = events[key];
}
}
}
else {
response = events[evt] || (events[evt] = []);
}
return response;
};
/**
* Takes a list of listener objects and flattens it into a list of listener functions.
*
* @param {Object[]} listeners Raw listener objects.
* @return {Function[]} Just the listener functions.
*/
proto.flattenListeners = function flattenListeners(listeners) {
var flatListeners = [];
var i;
for (i = 0; i < listeners.length; i += 1) {
flatListeners.push(listeners[i].listener);
}
return flatListeners;
};
/**
* Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
*
* @param {String|RegExp} evt Name of the event to return the listeners from.
* @return {Object} All listener functions for an event in an object.
*/
proto.getListenersAsObject = function getListenersAsObject(evt) {
var listeners = this.getListeners(evt);
var response;
if (listeners instanceof Array) {
response = {};
response[evt] = listeners;
}
return response || listeners;
};
/**
* Adds a listener function to the specified event.
* The listener will not be added if it is a duplicate.
* If the listener returns true then it will be removed after it is called.
* If you pass a regular expression as the event name then the listener will be added to all events that match it.
*
* @param {String|RegExp} evt Name of the event to attach the listener to.
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addListener = function addListener(evt, listener) {
var listeners = this.getListenersAsObject(evt);
var listenerIsWrapped = typeof listener === 'object';
var key;
for (key in listeners) {
if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
listeners[key].push(listenerIsWrapped ? listener : {
listener: listener,
once: false
});
}
}
return this;
};
/**
* Alias of addListener
*/
proto.on = alias('addListener');
/**
* Semi-alias of addListener. It will add a listener that will be
* automatically removed after it's first execution.
*
* @param {String|RegExp} evt Name of the event to attach the listener to.
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addOnceListener = function addOnceListener(evt, listener) {
return this.addListener(evt, {
listener: listener,
once: true
});
};
/**
* Alias of addOnceListener.
*/
proto.once = alias('addOnceListener');
/**
* Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
* You need to tell it what event names should be matched by a regex.
*
* @param {String} evt Name of the event to create.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.defineEvent = function defineEvent(evt) {
this.getListeners(evt);
return this;
};
/**
* Uses defineEvent to define multiple events.
*
* @param {String[]} evts An array of event names to define.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.defineEvents = function defineEvents(evts) {
for (var i = 0; i < evts.length; i += 1) {
this.defineEvent(evts[i]);
}
return this;
};
/**
* Removes a listener function from the specified event.
* When passed a regular expression as the event name, it will remove the listener from all events that match it.
*
* @param {String|RegExp} evt Name of the event to remove the listener from.
* @param {Function} listener Method to remove from the event.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeListener = function removeListener(evt, listener) {
var listeners = this.getListenersAsObject(evt);
var index;
var key;
for (key in listeners) {
if (listeners.hasOwnProperty(key)) {
index = indexOfListener(listeners[key], listener);
if (index !== -1) {
listeners[key].splice(index, 1);
}
}
}
return this;
};
/**
* Alias of removeListener
*/
proto.off = alias('removeListener');
/**
* Adds listeners in bulk using the manipulateListeners method.
* If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
* You can also pass it a regular expression to add the array of listeners to all events that match it.
* Yeah, this function does quite a bit. That's probably a bad thing.
*
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to add.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addListeners = function addListeners(evt, listeners) {
// Pass through to manipulateListeners
return this.manipulateListeners(false, evt, listeners);
};
/**
* Removes listeners in bulk using the manipulateListeners method.
* If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
* You can also pass it an event name and an array of listeners to be removed.
* You can also pass it a regular expression to remove the listeners from all events that match it.
*
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to remove.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeListeners = function removeListeners(evt, listeners) {
// Pass through to manipulateListeners
return this.manipulateListeners(true, evt, listeners);
};
/**
* Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
* The first argument will determine if the listeners are removed (true) or added (false).
* If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
* You can also pass it an event name and an array of listeners to be added/removed.
* You can also pass it a regular expression to manipulate the listeners of all events that match it.
*
* @param {Boolean} remove True if you want to remove listeners, false if you want to add.
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to add/remove.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
var i;
var value;
var single = remove ? this.removeListener : this.addListener;
var multiple = remove ? this.removeListeners : this.addListeners;
// If evt is an object then pass each of it's properties to this method
if (typeof evt === 'object' && !(evt instanceof RegExp)) {
for (i in evt) {
if (evt.hasOwnProperty(i) && (value = evt[i])) {
// Pass the single listener straight through to the singular method
if (typeof value === 'function') {
single.call(this, i, value);
}
else {
// Otherwise pass back to the multiple function
multiple.call(this, i, value);
}
}
}
}
else {
// So evt must be a string
// And listeners must be an array of listeners
// Loop over it and pass each one to the multiple method
i = listeners.length;
while (i--) {
single.call(this, evt, listeners[i]);
}
}
return this;
};
/**
* Removes all listeners from a specified event.
* If you do not specify an event then all listeners will be removed.
* That means every event will be emptied.
* You can also pass a regex to remove all events that match it.
*
* @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeEvent = function removeEvent(evt) {
var type = typeof evt;
var events = this._getEvents();
var key;
// Remove different things depending on the state of evt
if (type === 'string') {
// Remove all listeners for the specified event
delete events[evt];
}
else if (type === 'object') {
// Remove all events matching the regex.
for (key in events) {
if (events.hasOwnProperty(key) && evt.test(key)) {
delete events[key];
}
}
}
else {
// Remove all listeners in all events
delete this._events;
}
return this;
};
/**
* Alias of removeEvent.
*
* Added to mirror the node API.
*/
proto.removeAllListeners = alias('removeEvent');
/**
* Emits an event of your choice.
* When emitted, every listener attached to that event will be executed.
* If you pass the optional argument array then those arguments will be passed to every listener upon execution.
* Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
* So they will not arrive within the array on the other side, they will be separate.
* You can also pass a regular expression to emit to all events that match it.
*
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
* @param {Array} [args] Optional array of arguments to be passed to each listener.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.emitEvent = function emitEvent(evt, args) {
var listeners = this.getListenersAsObject(evt);
var listener;
var i;
var key;
var response;
for (key in listeners) {
if (listeners.hasOwnProperty(key)) {
i = listeners[key].length;
while (i--) {
// If the listener returns true then it shall be removed from the event
// The function is executed either with a basic call or an apply if there is an args array
listener = listeners[key][i];
if (listener.once === true) {
this.removeListener(evt, listener.listener);
}
response = listener.listener.apply(this, args || []);
if (response === this._getOnceReturnValue()) {
this.removeListener(evt, listener.listener);
}
}
}
}
return this;
};
/**
* Alias of emitEvent
*/
proto.trigger = alias('emitEvent');
/**
* Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
* As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
*
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
* @param {...*} Optional additional arguments to be passed to each listener.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.emit = function emit(evt) {
var args = Array.prototype.slice.call(arguments, 1);
return this.emitEvent(evt, args);
};
/**
* Sets the current value to check against when executing listeners. If a
* listeners return value matches the one set here then it will be removed
* after execution. This value defaults to true.
*
* @param {*} value The new value to check for when executing listeners.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.setOnceReturnValue = function setOnceReturnValue(value) {
this._onceReturnValue = value;
return this;
};
/**
* Fetches the current value to check against when executing listeners. If
* the listeners return value matches this one then it should be removed
* automatically. It will return true by default.
*
* @return {*|Boolean} The current value to check for or the default, true.
* @api private
*/
proto._getOnceReturnValue = function _getOnceReturnValue() {
if (this.hasOwnProperty('_onceReturnValue')) {
return this._onceReturnValue;
}
else {
return true;
}
};
/**
* Fetches the events object and creates one if required.
*
* @return {Object} The events storage object.
* @api private
*/
proto._getEvents = function _getEvents() {
return this._events || (this._events = {});
};
// Expose the class either via AMD, CommonJS or the global object
this.EventEmitter = EventEmitter;
}.call(this));
/*!
* eventie v1.0.3
* event binding helper
* eventie.bind( elem, 'click', myFn )
* eventie.unbind( elem, 'click', myFn )
*/
/*jshint browser: true, undef: true, unused: true */
/*global define: false */
( function( window ) {
'use strict';
var docElem = document.documentElement;
var bind = function() {};
if ( docElem.addEventListener ) {
bind = function( obj, type, fn ) {
obj.addEventListener( type, fn, false );
};
} else if ( docElem.attachEvent ) {
bind = function( obj, type, fn ) {
obj[ type + fn ] = fn.handleEvent ?
function() {
var event = window.event;
// add event.target
event.target = event.target || event.srcElement;
fn.handleEvent.call( fn, event );
} :
function() {
var event = window.event;
// add event.target
event.target = event.target || event.srcElement;
fn.call( obj, event );
};
obj.attachEvent( "on" + type, obj[ type + fn ] );
};
}
var unbind = function() {};
if ( docElem.removeEventListener ) {
unbind = function( obj, type, fn ) {
obj.removeEventListener( type, fn, false );
};
} else if ( docElem.detachEvent ) {
unbind = function( obj, type, fn ) {
obj.detachEvent( "on" + type, obj[ type + fn ] );
try {
delete obj[ type + fn ];
} catch ( err ) {
// can't delete window object properties
obj[ type + fn ] = undefined;
}
};
}
var eventie = {
bind: bind,
unbind: unbind
};
// transport
// browser global
window.eventie = eventie;
})( this );
/*!
* imagesLoaded v3.0.4
* JavaScript is all like "You images are done yet or what?"
* MIT License
*/
( function( window ) {
'use strict';
var $ = window.jQuery;
var console = window.console;
var hasConsole = typeof console !== 'undefined';
// -------------------------- helpers -------------------------- //
// extend objects
function extend( a, b ) {
for ( var prop in b ) {
a[ prop ] = b[ prop ];
}
return a;
}
var objToString = Object.prototype.toString;
function isArray( obj ) {
return objToString.call( obj ) === '[object Array]';
}
// turn element or nodeList into an array
function makeArray( obj ) {
var ary = [];
if ( isArray( obj ) ) {
// use object if already an array
ary = obj;
} else if ( typeof obj.length === 'number' ) {
// convert nodeList to array
for ( var i=0, len = obj.length; i < len; i++ ) {
ary.push( obj[i] );
}
} else {
// array of single index
ary.push( obj );
}
return ary;
}
// -------------------------- -------------------------- //
function defineImagesLoaded( EventEmitter, eventie ) {
/**
* @param {Array, Element, NodeList, String} elem
* @param {Object or Function} options - if function, use as callback
* @param {Function} onAlways - callback function
*/
function ImagesLoaded( elem, options, onAlways ) {
// coerce ImagesLoaded() without new, to be new ImagesLoaded()
if ( !( this instanceof ImagesLoaded ) ) {
return new ImagesLoaded( elem, options );
}
// use elem as selector string
if ( typeof elem === 'string' ) {
elem = document.querySelectorAll( elem );
}
this.elements = makeArray( elem );
this.options = extend( {}, this.options );
if ( typeof options === 'function' ) {
onAlways = options;
} else {
extend( this.options, options );
}
if ( onAlways ) {
this.on( 'always', onAlways );
}
this.getImages();
if ( $ ) {
// add jQuery Deferred object
this.jqDeferred = new $.Deferred();
}
// HACK check async to allow time to bind listeners
var _this = this;
setTimeout( function() {
_this.check();
});
}
ImagesLoaded.prototype = new EventEmitter();
ImagesLoaded.prototype.options = {};
ImagesLoaded.prototype.getImages = function() {
this.images = [];
// filter & find items if we have an item selector
for ( var i=0, len = this.elements.length; i < len; i++ ) {
var elem = this.elements[i];
// filter siblings
if ( elem.nodeName === 'IMG' ) {
this.addImage( elem );
}
// find children
var childElems = elem.querySelectorAll('img');
// concat childElems to filterFound array
for ( var j=0, jLen = childElems.length; j < jLen; j++ ) {
var img = childElems[j];
this.addImage( img );
}
}
};
/**
* @param {Image} img
*/
ImagesLoaded.prototype.addImage = function( img ) {
var loadingImage = new LoadingImage( img );
this.images.push( loadingImage );
};
ImagesLoaded.prototype.check = function() {
var _this = this;
var checkedCount = 0;
var length = this.images.length;
this.hasAnyBroken = false;
// complete if no images
if ( !length ) {
this.complete();
return;
}
function onConfirm( image, message ) {
if ( _this.options.debug && hasConsole ) {
console.log( 'confirm', image, message );
}
_this.progress( image );
checkedCount++;
if ( checkedCount === length ) {
_this.complete();
}
return true; // bind once
}
for ( var i=0; i < length; i++ ) {
var loadingImage = this.images[i];
loadingImage.on( 'confirm', onConfirm );
loadingImage.check();
}
};
ImagesLoaded.prototype.progress = function( image ) {
this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded;
// HACK - Chrome triggers event before object properties have changed. #83
var _this = this;
setTimeout( function() {
_this.emit( 'progress', _this, image );
if ( _this.jqDeferred ) {
_this.jqDeferred.notify( _this, image );
}
});
};
ImagesLoaded.prototype.complete = function() {
var eventName = this.hasAnyBroken ? 'fail' : 'done';
this.isComplete = true;
var _this = this;
// HACK - another setTimeout so that confirm happens after progress
setTimeout( function() {
_this.emit( eventName, _this );
_this.emit( 'always', _this );
if ( _this.jqDeferred ) {
var jqMethod = _this.hasAnyBroken ? 'reject' : 'resolve';
_this.jqDeferred[ jqMethod ]( _this );
}
});
};
// -------------------------- jquery -------------------------- //
if ( $ ) {
$.fn.imagesLoaded = function( options, callback ) {
var instance = new ImagesLoaded( this, options, callback );
return instance.jqDeferred.promise( $(this) );
};
}
// -------------------------- -------------------------- //
var cache = {};
function LoadingImage( img ) {
this.img = img;
}
LoadingImage.prototype = new EventEmitter();
LoadingImage.prototype.check = function() {
// first check cached any previous images that have same src
var cached = cache[ this.img.src ];
if ( cached ) {
this.useCached( cached );
return;
}
// add this to cache
cache[ this.img.src ] = this;
// If complete is true and browser supports natural sizes,
// try to check for image status manually.
if ( this.img.complete && this.img.naturalWidth !== undefined ) {
// report based on naturalWidth
this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
return;
}
// If none of the checks above matched, simulate loading on detached element.
var proxyImage = this.proxyImage = new Image();
eventie.bind( proxyImage, 'load', this );
eventie.bind( proxyImage, 'error', this );
proxyImage.src = this.img.src;
};
LoadingImage.prototype.useCached = function( cached ) {
if ( cached.isConfirmed ) {
this.confirm( cached.isLoaded, 'cached was confirmed' );
} else {
var _this = this;
cached.on( 'confirm', function( image ) {
_this.confirm( image.isLoaded, 'cache emitted confirmed' );
return true; // bind once
});
}
};
LoadingImage.prototype.confirm = function( isLoaded, message ) {
this.isConfirmed = true;
this.isLoaded = isLoaded;
this.emit( 'confirm', this, message );
};
// trigger specified handler for event type
LoadingImage.prototype.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
LoadingImage.prototype.onload = function() {
this.confirm( true, 'onload' );
this.unbindProxyEvents();
};
LoadingImage.prototype.onerror = function() {
this.confirm( false, 'onerror' );
this.unbindProxyEvents();
};
LoadingImage.prototype.unbindProxyEvents = function() {
eventie.unbind( this.proxyImage, 'load', this );
eventie.unbind( this.proxyImage, 'error', this );
};
// ----- ----- //
return ImagesLoaded;
}
// -------------------------- transport -------------------------- //
// browser global
window.imagesLoaded = defineImagesLoaded(
window.EventEmitter,
window.eventie
);
})( window );