Skip to content

Commit

Permalink
Add multi-object detail views
Browse files Browse the repository at this point in the history
Add the controller to handle requests to the multi-detail view and fix some
bugs in the multiselection of the mainDetailGrid component

refs #3788
  • Loading branch information
majentsch committed Oct 17, 2013
1 parent 308a22f commit 3c0d8f0
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 17 deletions.
82 changes: 82 additions & 0 deletions modules/monitoring/application/controllers/MultiController.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= $this->render('multi/components/summary.phtml'); ?>
28 changes: 11 additions & 17 deletions public/js/icinga/selection/multiSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3c0d8f0

Please sign in to comment.