Add multi-object detail views
Add the controller to handle requests to the multi-detail view and fix some bugs in the multiselection of the mainDetailGrid component refs #3788
This commit is contained in:
parent
a96331b4d6
commit
b911e8c56b
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
// {{{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}}}
|
||||
|
||||
use \Icinga\Web\Controller\ActionController;
|
||||
|
||||
/**
|
||||
* Displays aggregations collections of multiple objects.
|
||||
*/
|
||||
class Monitoring_MultiController extends ActionController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->view->objects = $this->getDetailQueries();
|
||||
}
|
||||
|
||||
public function hostAction()
|
||||
{
|
||||
$this->view->hosts = $this->_getAllParams();
|
||||
}
|
||||
|
||||
public function servicesAction()
|
||||
{
|
||||
}
|
||||
|
||||
public function notificationsAction()
|
||||
{
|
||||
}
|
||||
|
||||
public function historyAction()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all queries from the 'detail' parameter and prepare
|
||||
* them for further processing.
|
||||
*
|
||||
* @return array An array containing all requests and their filter values.
|
||||
*/
|
||||
private function getDetailQueries()
|
||||
{
|
||||
$details = $this->_getAllParams();
|
||||
$objects = array();
|
||||
foreach ($details as $property => $values) {
|
||||
if (!is_array($values)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($values as $index => $value) {
|
||||
if (!array_key_exists($index, $objects)) {
|
||||
$objects[$index] = array();
|
||||
}
|
||||
$objects[$index][$property] = $value;
|
||||
}
|
||||
}
|
||||
return $objects;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<span>Summary for <?= count($objects) ?> object(s) </span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
<?= $this->render('multi/components/summary.phtml'); ?>
|
|
@ -121,27 +121,19 @@ function($, URI, Selectable) {
|
|||
* Fetch the selections from a query containing multiple selections
|
||||
*/
|
||||
var selectionFromMultiQuery = function(query) {
|
||||
var i = 0;
|
||||
var selections = [];
|
||||
alert('query ' + JSON.stringify(query));
|
||||
$.each(query, function(key, value) {
|
||||
// Fetch the index from the key
|
||||
var id = key.match(/\[([0-9]+)\]/);
|
||||
alert(id);
|
||||
if (id) {
|
||||
alert('extracted id ' + id[1]);
|
||||
// Remove the index from the key
|
||||
key = key.replace(/\[[0-9]+\]/,'');
|
||||
key = encodeURIComponent(key);
|
||||
value = encodeURIComponent(value);
|
||||
// Add it to the array representing this index
|
||||
if (id[1] !== i) {
|
||||
// begin a new index
|
||||
selections[i] = [ key + '=' + value ];
|
||||
i = id[1];
|
||||
} else {
|
||||
selections[i].push(key + '=' + value);
|
||||
// Create an object that contains the queries for each index.
|
||||
var i = id[1];
|
||||
if (!selections[i]) {
|
||||
selections[i] = [];
|
||||
}
|
||||
selections[i] = [ encodeURIComponent(key) + '=' + encodeURIComponent(value) ];
|
||||
}
|
||||
});
|
||||
return selections;
|
||||
|
@ -176,8 +168,8 @@ function($, URI, Selectable) {
|
|||
}
|
||||
var segments = url.segment();
|
||||
var parts;
|
||||
if (segments.length > 2 && segments[1] === 'Multi') {
|
||||
alert('from multiselection');
|
||||
// TODO: Handle it for cases when there is no /icinga-web2/ in the path
|
||||
if (segments.length > 2 && segments[2].toLowerCase() === 'multi') {
|
||||
parts = selectionFromMultiQuery(url.query(true));
|
||||
} else {
|
||||
parts = selectionFromQuery(url.query(true));
|
||||
|
@ -212,8 +204,10 @@ function($, URI, Selectable) {
|
|||
var selected = restoreSelectionStateUrl(detailUrl);
|
||||
var selection = {};
|
||||
$.each(selected, function(i, selectionId) {
|
||||
if (selectables[selectionId]) {
|
||||
selection[selectionId] = selectables[selectionId];
|
||||
var restored = selectables[selectionId];
|
||||
if (restored) {
|
||||
selection[selectionId] = restored;
|
||||
restored.setActive(true);
|
||||
}
|
||||
});
|
||||
return selection;
|
||||
|
|
Loading…
Reference in New Issue