mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
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
|
* Fetch the selections from a query containing multiple selections
|
||||||
*/
|
*/
|
||||||
var selectionFromMultiQuery = function(query) {
|
var selectionFromMultiQuery = function(query) {
|
||||||
var i = 0;
|
|
||||||
var selections = [];
|
var selections = [];
|
||||||
alert('query ' + JSON.stringify(query));
|
|
||||||
$.each(query, function(key, value) {
|
$.each(query, function(key, value) {
|
||||||
// Fetch the index from the key
|
// Fetch the index from the key
|
||||||
var id = key.match(/\[([0-9]+)\]/);
|
var id = key.match(/\[([0-9]+)\]/);
|
||||||
alert(id);
|
|
||||||
if (id) {
|
if (id) {
|
||||||
alert('extracted id ' + id[1]);
|
|
||||||
// Remove the index from the key
|
// Remove the index from the key
|
||||||
key = key.replace(/\[[0-9]+\]/,'');
|
key = key.replace(/\[[0-9]+\]/,'');
|
||||||
key = encodeURIComponent(key);
|
// Create an object that contains the queries for each index.
|
||||||
value = encodeURIComponent(value);
|
var i = id[1];
|
||||||
// Add it to the array representing this index
|
if (!selections[i]) {
|
||||||
if (id[1] !== i) {
|
selections[i] = [];
|
||||||
// begin a new index
|
|
||||||
selections[i] = [ key + '=' + value ];
|
|
||||||
i = id[1];
|
|
||||||
} else {
|
|
||||||
selections[i].push(key + '=' + value);
|
|
||||||
}
|
}
|
||||||
|
selections[i] = [ encodeURIComponent(key) + '=' + encodeURIComponent(value) ];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return selections;
|
return selections;
|
||||||
@ -176,8 +168,8 @@ function($, URI, Selectable) {
|
|||||||
}
|
}
|
||||||
var segments = url.segment();
|
var segments = url.segment();
|
||||||
var parts;
|
var parts;
|
||||||
if (segments.length > 2 && segments[1] === 'Multi') {
|
// TODO: Handle it for cases when there is no /icinga-web2/ in the path
|
||||||
alert('from multiselection');
|
if (segments.length > 2 && segments[2].toLowerCase() === 'multi') {
|
||||||
parts = selectionFromMultiQuery(url.query(true));
|
parts = selectionFromMultiQuery(url.query(true));
|
||||||
} else {
|
} else {
|
||||||
parts = selectionFromQuery(url.query(true));
|
parts = selectionFromQuery(url.query(true));
|
||||||
@ -212,8 +204,10 @@ function($, URI, Selectable) {
|
|||||||
var selected = restoreSelectionStateUrl(detailUrl);
|
var selected = restoreSelectionStateUrl(detailUrl);
|
||||||
var selection = {};
|
var selection = {};
|
||||||
$.each(selected, function(i, selectionId) {
|
$.each(selected, function(i, selectionId) {
|
||||||
if (selectables[selectionId]) {
|
var restored = selectables[selectionId];
|
||||||
selection[selectionId] = selectables[selectionId];
|
if (restored) {
|
||||||
|
selection[selectionId] = restored;
|
||||||
|
restored.setActive(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return selection;
|
return selection;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user