Add link to csv output to tabs

There is currently no controller implementing this output type
but the monitoring module will provide that.
This commit is contained in:
Eric Lippmann 2013-07-12 12:02:51 +02:00
parent 58ce815361
commit 7a075ca52a
4 changed files with 76 additions and 40 deletions

View File

@ -0,0 +1,46 @@
<?php
namespace Icinga\File;
use Icinga\Data\AbstractQuery;
class Csv
{
protected $query;
protected function __construct()
{
}
public static function fromQuery(AbstractQuery $query)
{
$csv = new Csv();
$csv->query = $query;
return $csv;
}
public function dump()
{
header('Content-type: text/csv');
echo (string) $this;
}
public function __toString()
{
$first = true;
$csv = '';
foreach ($this->query->fetchAll() as $row) {
if ($first) {
$csv .= implode(',', array_keys((array) $row)) . "\r\n";
$first = false;
}
$out = array();
foreach ($row as & $val) {
$out[] = '"' . $val . '"';
}
$csv .= implode(',', $out) . "\r\n";
}
return $csv;
}
}

View File

View File

@ -1,28 +1,8 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Icinga 2 Web - Head for multiple monitoring frontends
* 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>
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Web widget class
*/
namespace Icinga\Web;
use Icinga\Exception\ProgrammingError;
@ -45,16 +25,16 @@ use Icinga\Exception\ProgrammingError;
*/
class Widget
{
/**
* Create a new widget
*
* @param string $name Widget name
* @param array $options Widget constructor options
* @param array $options Widget constructor options
*
* @throws \Icinga\Exception\ProgrammingError
* @return Icinga\Web\Widget\AbstractWidget
*/
public static function create($name, $options = array())
public static function create($name, $options = array(), $module_name = null)
{
$class = 'Icinga\\Web\\Widget\\' . ucfirst($name);
@ -67,7 +47,7 @@ class Widget
);
}
$widget = new $class($options);
$widget = new $class($options, $module_name);
return $widget;
}
}

View File

@ -8,6 +8,8 @@ namespace Icinga\Web\Widget;
use Icinga\Exception\ProgrammingError;
use Icinga\Web\Url;
use Countable;
/**
* Navigation tab widget
*
@ -17,7 +19,7 @@ use Icinga\Web\Url;
* @author Icinga-Web Team <info@icinga.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
class Tabs extends AbstractWidget implements \Countable
class Tabs extends AbstractWidget implements Countable
{
/**
* This is where single tabs added to this container will be stored
@ -201,25 +203,37 @@ class Tabs extends AbstractWidget implements \Countable
$special = array();
$special[] = $this->view()->qlink(
'PDF',
$this->view()->img('img/classic/application-pdf.png') . ' PDF',
Url::current(),
array('filetype' => 'pdf'),
array('target' => '_blank')
array('target' => '_blank', 'quote' => false)
);
$special[] = $this->view()->qlink(
$this->view()->img('img/classic/application-csv.png') . ' CSV',
Url::current(),
array('format' => 'csv'),
array('target' => '_blank', 'quote' => false)
);
$special[] = $this->view()->qlink(
$this->view()->img('img/classic/application-json.png') . ' JSON',
Url::current(),
array('format' => 'json', 'quote' => false),
array('target' => '_blank', 'quote' => false)
);
$special[] = $this->view()->qlink(
'Basket',
$this->view()->img('img/classic/basket.png') . ' URL Basket',
Url::create('basket/add'),
array('url' => Url::current()->getRelative())
array('url' => Url::current()->getRelative()),
array('quote' => false)
);
$special[] = $this->view()->qlink(
'Dashboard',
$this->view()->img('img/classic/dashboard.png') . ' Dashboard',
Url::create('dashboard/addurl'),
array('url' => Url::current()->getRelative())
array('url' => Url::current()->getRelative()),
array('quote' => false)
);
// @todo rework auth
// $auth = Auth::getInstance();
// if ($this->specialActions && ! empty($special) && $auth->isAuthenticated() && $auth->getUsername() === 'admin') {
if ($this->specialActions) {
@ -241,10 +255,6 @@ class Tabs extends AbstractWidget implements \Countable
return $html;
}
/**
* Counting registered tabs
* @return int
*/
public function count()
{
return count($this->tabs);